From fc8c86e7a365d5c6bdc37c2b05b9f83115ac2bc3 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 23 四月 2025 17:30:52 +0800
Subject: [PATCH] 巡检任务  设备维修新增是否生成工单

---
 platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceLeasingLedgerServiceImpl.java |  125 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceLeasingLedgerServiceImpl.java b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceLeasingLedgerServiceImpl.java
index 44c7d67..18f8ff2 100644
--- a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceLeasingLedgerServiceImpl.java
+++ b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceLeasingLedgerServiceImpl.java
@@ -2,12 +2,13 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.by4cloud.platformx.device.entity.Device;
-import com.by4cloud.platformx.device.entity.DeviceLeasingLedger;
-import com.by4cloud.platformx.device.mapper.DeviceLeasingLedgerMapper;
-import com.by4cloud.platformx.device.mapper.DeviceMapper;
+import com.by4cloud.platformx.common.core.util.R;
+import com.by4cloud.platformx.device.constant.CommonStatusContant;
+import com.by4cloud.platformx.device.entity.*;
+import com.by4cloud.platformx.device.mapper.*;
 import com.by4cloud.platformx.device.service.DeviceLeasingLedgerService;
 import lombok.AllArgsConstructor;
+import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -23,6 +24,11 @@
 public class DeviceLeasingLedgerServiceImpl extends ServiceImpl<DeviceLeasingLedgerMapper, DeviceLeasingLedger> implements DeviceLeasingLedgerService {
 
 	private final DeviceMapper deviceMapper;
+	private final DeviceLeasingLedgerItemMapper itemMapper;
+	private final ContractItemMapper contractItemMapper;
+	private final ContractMapper contractMapper;
+	private final DeviceInventoryMapper inventoryMapper;
+	private final InventoryFlowWaterMapper inventoryFlowWaterMapper;
 
 	@Override
 	public List<DeviceLeasingLedger> getSelectList() {
@@ -36,4 +42,115 @@
 		List<Device> list = deviceMapper.getDeviceSelectListByLedgerId(ledgerId);
 		return list;
 	}
+
+	@Override
+	public R saveDeep(DeviceLeasingLedger deviceLeasingLedger) {
+		//鏄庣粏璁惧鏁伴噺涓庡悎鍚屼腑绛捐鏁版嵁姣斿
+		QueryWrapper<Contract> contractQueryWrapper = new QueryWrapper<>();
+		contractQueryWrapper.eq("number",deviceLeasingLedger.getContractCode());
+		Contract contract = contractMapper.selectOne(contractQueryWrapper);
+		if (contract == null) {
+			return R.failed("鍚堝悓涓嶅瓨鍦�");
+		}
+
+		//鏌ヨ鍚堝悓鏄庣粏涓澶囨儏鍐�
+		QueryWrapper<ContractItem> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("contract_id",contract.getId());
+		List<ContractItem> list = contractItemMapper.selectList(queryWrapper);
+
+		//姣旇緝璁惧绉嶇被鏄惁涓�鑷�
+		if (list.size()!=deviceLeasingLedger.getLedgerItemList().size()){
+			return R.failed("鍚堝悓涓澶囩绫讳笌鍙拌处鏄庣粏涓笉涓�鑷�");
+		}
+
+		//姣旇緝鍗曚釜璁惧鍙拌处鏁伴噺鏄惁涓庡悎鍚屼腑涓�鑷�
+		for (ContractItem contractItem:list
+			 ) {
+			for (DeviceLeasingLedgerItem item:deviceLeasingLedger.getLedgerItemList()
+			) {
+				if (contractItem.getDeviceId().equals(item.getDeviceId())){
+					if (contractItem.getNum()<item.getNum()) {
+						return R.failed("鍚堝悓涓�"+item.getDeviceName()+"璁惧鏁伴噺涓庡彴璐︽槑缁嗕腑涓嶄竴鑷达紝鏃犳硶寤虹珛鍙拌处");
+					}
+					Integer deviceNum = itemMapper.selectDeviceNumByContractId(contract.getId(),contractItem.getDeviceId());
+					//鏌ヨ鏄惁鏈夊巻鍙插嚭璐�
+					if (contractItem.getNum()<(item.getNum()+deviceNum)) {
+						return R.failed("鍚堝悓涓�"+item.getDeviceName()+"璁惧鏁伴噺鍑虹鍙拌处宸茶秴鍑鸿澶囧疄闄呭簱瀛橈紝鏃犳硶寤虹珛鍙拌处");
+					}
+				}
+			}
+		}
+
+		//鍏ュ簱
+		baseMapper.insert(deviceLeasingLedger);
+		for (DeviceLeasingLedgerItem item:deviceLeasingLedger.getLedgerItemList()
+			 ) {
+			item.setLedgerId(deviceLeasingLedger.getId());
+			itemMapper.insert(item);
+			for (String serialNo:item.getSerialNos()
+			) {
+				Device device = deviceMapper.selectById(item.getDeviceId());
+				QueryWrapper<DeviceInventory> inventoryQueryWrapper = new QueryWrapper<>();
+				inventoryQueryWrapper.eq("device_id",item.getDeviceId());
+				inventoryQueryWrapper.eq("serial_no",serialNo);
+				DeviceInventory inventory = inventoryMapper.selectOne(inventoryQueryWrapper);
+				if (device!=null&&inventory!=null) {
+					inventory.setInventoryStatus(CommonStatusContant.DEVICE_INVENTORY_RENTING);
+					inventory.setLedgerItemId(item.getId());
+					//搴撳瓨璋冩暣
+					inventoryMapper.updateById(inventory);
+
+					//璁惧搴撳瓨娴佹按鍚屾鏂板
+					InventoryFlowWater flowWater = new InventoryFlowWater();
+					flowWater.setDeviceId(item.getDeviceId());
+					flowWater.setSerialNo(serialNo);
+					flowWater.setInventoryId(inventory.getId());
+					flowWater.setClassId(device.getClassId());
+					//鏍规嵁鍚堝悓绫诲瀷 璐拱 鎵跨 娴佹按鎿嶄綔绫诲瀷涓哄叆搴撴搷浣�
+					if (contract!=null&&(contract.getType()==1||contract.getType()==2)){
+						flowWater.setOperateType(CommonStatusContant.DEVICE_INVENTORY_FLOW_WATER_IN);
+					}
+					//鏍规嵁鍚堝悓绫诲瀷 绉熻祦 娴佹按鎿嶄綔绫诲瀷涓哄嚭搴撴搷浣�
+					if (contract!=null&&contract.getType()==0){
+						flowWater.setOperateType(CommonStatusContant.DEVICE_INVENTORY_FLOW_WATER_OUT);
+					}
+					//璁板綍搴撳瓨娴佹按
+					inventoryFlowWaterMapper.insert(flowWater);
+				}
+			}
+		}
+		//鍚堝悓鏄庣粏涓笌鍙拌处瀵规瘮
+		for (ContractItem contractItem:list
+		) {
+			Integer deviceNum = itemMapper.selectDeviceNumByContractId(contract.getId(),contractItem.getDeviceId());
+			//鏌ヨ鏄惁鏈夊巻鍙插嚭璐�
+			if (contractItem.getNum()!=deviceNum) {
+				return R.ok();
+			}
+		}
+		//鏇存柊鍚堝悓鐘舵�佷负瀹屾垚
+		contract.setStatus(2);
+		contractMapper.updateById(contract);
+
+		return R.ok();
+	}
+
+	@Override
+	public List<DeviceInventory> getLedgerDeviceList(Long deviceId) {
+		QueryWrapper<DeviceInventory> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("device_id",deviceId);
+		queryWrapper.eq("inventory_status",1);
+		List<DeviceInventory> list = inventoryMapper.selectList(queryWrapper);
+		return list;
+	}
+
+	@Override
+	public DeviceLeasingLedger getByIdDeep(Long id) {
+		DeviceLeasingLedger deviceLeasingLedger = baseMapper.selectById(id);
+		QueryWrapper<DeviceLeasingLedgerItem> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("ledger_id",id);
+		List<DeviceLeasingLedgerItem> itemList = itemMapper.selectList(queryWrapper);
+		deviceLeasingLedger.setLedgerItemList(itemList);
+		return deviceLeasingLedger;
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1