From b42a1d670e2989f50f3b6a79b4c925e567fe5298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?= <2671189764@qq.com> Date: Wed, 28 May 2025 10:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=98=AF=E5=90=A6=E6=95=B4?= =?UTF-8?q?=E8=BD=A6=E7=BB=91=E5=AE=9A=E5=92=8C=E5=87=BA=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=AE=BE=E7=BD=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/EbikeComponentServiceImpl.java | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/ebike-operate/src/main/java/com/cdzy/ebikeoperate/service/impl/EbikeComponentServiceImpl.java b/ebike-operate/src/main/java/com/cdzy/ebikeoperate/service/impl/EbikeComponentServiceImpl.java index 7a6d1969..23842ee9 100644 --- a/ebike-operate/src/main/java/com/cdzy/ebikeoperate/service/impl/EbikeComponentServiceImpl.java +++ b/ebike-operate/src/main/java/com/cdzy/ebikeoperate/service/impl/EbikeComponentServiceImpl.java @@ -79,43 +79,19 @@ public class EbikeComponentServiceImpl implements EbikeComponentService { saveOrUpdateEnterRecord(ebikeComponentEnterRecords, params.getComponentEnterRecordId(), userId); String componentEnterRecordId = ebikeComponentEnterRecords.getComponentEnterRecordId(); - // 用于存储重复部件名称的集合 - List duplicatePartNames = new ArrayList<>(); if (params.getEbikeEcuEnterRecords() != null && !params.getEbikeEcuEnterRecords().isEmpty()) { - // 遍历所有的EbikeEcuEnterRecords记录 - for (EbikeEcuEnterRecords res : params.getEbikeEcuEnterRecords()) { - boolean isDuplicate = isDuplicateEntry(res.getEcuSn(),res.getEcuCode()); - if (isDuplicate) { - // 如果是重复部件,则将部件名称添加到重复部件名称记录中 - duplicatePartNames.add(res.getEcuSn()); // 假设 EcuSn 是部件名称 - } - } // 删除原有的ECU入库记录并保存新的记录 deleteAndInsertEcuEnterRecords(componentEnterRecordId, params.getEbikeEcuEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId); if (stockInType == 1) { updateInventoryCount(ebikeComponentTypeInfo, orgId, params.getEbikeEcuEnterRecords().size(), 1); } } else if (params.getEbikeBatteryEnterRecords() != null && !params.getEbikeBatteryEnterRecords().isEmpty()) { - for (EbikeBatteryEnterRecords res : params.getEbikeBatteryEnterRecords()) { - boolean isDuplicate = isDuplicateEntry(res.getBatteryCode(),""); - if (isDuplicate) { - // 如果是重复部件,则将部件名称添加到重复部件名称记录中 - duplicatePartNames.add(res.getBatteryCode()); // 假设 EcuSn 是部件名称 - } - } // 删除原有的电池入库记录并保存新的记录 deleteAndInsertBatteryRecords(componentEnterRecordId, params.getEbikeBatteryEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId); if (stockInType == 1) { updateInventoryCount(ebikeComponentTypeInfo, orgId, params.getEbikeBatteryEnterRecords().size(), 1); } } else if (params.getEbikeHelmetEnterRecords() != null && !params.getEbikeHelmetEnterRecords().isEmpty()) { - for (EbikeHelmetEnterRecords res : params.getEbikeHelmetEnterRecords()) { - boolean isDuplicate = isDuplicateEntry(res.getHelmetCode(),""); - if (isDuplicate) { - // 如果是重复部件,则将部件名称添加到重复部件名称记录中 - duplicatePartNames.add(res.getHelmetCode()); // 假设 EcuSn 是部件名称 - } - } // 删除原有的头盔入库记录并保存新的记录 deleteAndInsertHelmetEnterRecords(componentEnterRecordId, params.getEbikeHelmetEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId); if (stockInType == 1) { @@ -128,12 +104,6 @@ public class EbikeComponentServiceImpl implements EbikeComponentService { updateInventoryCount(ebikeComponentTypeInfo, orgId, enterQuantity, 1); } } - // 如果有重复部件名称记录,则返回错误信息 - if (!duplicatePartNames.isEmpty()) { - // 可以在错误信息中添加重复的部件名称 - String duplicateParts = String.join(", ", duplicatePartNames); - return JsonResult.failed("以下部件已存在,不能重复入库: " + duplicateParts); - } String componentOutRecordId = params.getComponentOutRecordId(); if(componentOutRecordId != null && !componentOutRecordId.isEmpty() && stockInType == 1 ){ // 更新出库记录状态为 已归还 @@ -576,6 +546,21 @@ public class EbikeComponentServiceImpl implements EbikeComponentService { return JsonResult.success(resComponentOutRecordInfoDto); } + @Override + public JsonResult validateComponentExistence(ReqValidateComponentExistenceDto params) { + try { + String componentCode = params.getComponentCode(); + String componentType = params.getComponentType(); + // 检查是否存在重复记录 + boolean duplicateEntry = isDuplicateEntry(componentCode, componentType); + // 返回成功响应 + return JsonResult.success(duplicateEntry); + } catch (Exception e) { + // 返回错误响应 + return JsonResult.failed("验证过程发生异常,请稍后再试"); + } + } + // 方法实现 private void updateBatteryDetails(String componentEnterRecordId, String componentType, Integer state) { @@ -646,7 +631,9 @@ public class EbikeComponentServiceImpl implements EbikeComponentService { ebikeComponentOutRecords.setOutQuantity(params.getOutQuantity()); ebikeComponentOutRecords.setOldComponentHandleOption(params.getOldComponentHandleOption()); ebikeComponentOutRecords.setEnterQuantity(params.getEnterQuantity()); - ebikeComponentOutRecords.setState(stockInType == 1 ? "1" : "0"); // 暂存为 0 出库库为1 + // 根据是否整车绑定和出库类型设置状态 + String state = params.getIsWholeBinding() ? "3" : (stockInType == 1 ? "1" : "0"); + ebikeComponentOutRecords.setState(state); return ebikeComponentOutRecords; } @@ -821,10 +808,10 @@ public class EbikeComponentServiceImpl implements EbikeComponentService { ebikeComponentOutRecords.setState("2"); ebikeComponentOutRecordsMapper.update(ebikeComponentOutRecords); } - public boolean isDuplicateEntry(String itemCode, String serialNumber) { + public boolean isDuplicateEntry(String itemCode,String componentType) { QueryWrapper query = new QueryWrapper(); query.eq("item_code", itemCode); - query.eq("serial_number", serialNumber); + query.eq("component_type", componentType); query.eq("state", 1); // 假设 1 表示已已入库 long count = ebikeComponentInventoryMapper.selectCountByQuery(query); // 查询符合条件的记录数 return count > 0; // 如果记录数大于 0,说明已经存在重复入库