Explorar el Código

Merge remote-tracking branch 'origin/matser' into matser

WuYi hace 1 día
padre
commit
34dd9034d1

+ 0 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/provider/LingYongProvider.java

@@ -110,14 +110,12 @@ public class LingYongProvider extends GenericProvider implements ILingYongServic
 				result.setMessage("更新失败!服务返回为空");
 				return result;
 			}
-			// 【优化点】使用 indexOf 查找分隔符,避免 split 的正则问题
 			int separatorIndex = retVal.indexOf('^');
 			if (separatorIndex > 0) {
 				String codePart = retVal.substring(0, separatorIndex).trim(); // 提取 ^ 前的部分并去空格
 				String msgPart = retVal.substring(separatorIndex + 1);        // 提取 ^ 后的部分
 				if ("1".equals(codePart)) {
 					result.setMessage("更新成功!");
-					// 如果需要,可以在这里设置 result.setCode(StateEnum.SUCCESS.getCode());
 				} else {
 					// 拼接自定义错误消息
 					result.setMessage("更新失败!" + msgPart);

+ 0 - 4
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/provider/ReagentConsumablesInventoryProvider.java

@@ -263,20 +263,16 @@ public class ReagentConsumablesInventoryProvider extends GenericProvider impleme
 				result.setMessage("更新失败!服务返回为空");
 				return result;
 			}
-			// 【优化点】使用 indexOf 查找分隔符,避免 split 的正则问题
 			int separatorIndex = retVal.indexOf('^');
 			if (separatorIndex > 0) {
 				String codePart = retVal.substring(0, separatorIndex).trim(); // 提取 ^ 前的部分并去空格
 				String msgPart = retVal.substring(separatorIndex + 1);        // 提取 ^ 后的部分
 				if ("1".equals(codePart)) {
 					result.setMessage("更新成功!");
-					// 如果需要,可以在这里设置 result.setCode(StateEnum.SUCCESS.getCode());
 				} else {
-					// 拼接自定义错误消息
 					result.setMessage("更新失败!" + msgPart);
 				}
 			} else {
-				// 如果没有找到 ^,说明返回格式不对,直接将整个返回值当作错误信息
 				logger.error("服务返回格式错误,未找到分隔符 '^': {}", retVal);
 				result.setMessage("更新失败!系统返回格式异常:" + retVal);
 			}

+ 35 - 27
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/service/InventoryService.java

@@ -176,12 +176,21 @@ public class InventoryService extends GenericProvider {
                 errorMsg = "数量格式错误:" + shuLiangStr;
                 break;
             }
-            if (shuLiang <= 0) {
+            if (shuLiang == 0) {
                 checkFlag = false;
-                errorMsg = "数量必须大于0";
+                errorMsg = "数量不能为0";
                 break;
             }
 
+            // 标记是否为负数及绝对值,供后续分支使用
+            boolean isNegative = shuLiang < 0;
+            int absShuLiang = Math.abs(shuLiang);
+
+            // 负数在 start/back 阶段不涉及预扣,静默跳过本条记录
+            if (isNegative && ("start".equals(operate) || "back".equals(operate))) {
+                continue;
+            }
+
             // 2. 查询库存
             String inventoryId = StrUtil.str(detail.get("inventory_id"));
             String batchNum = StrUtil.str(detail.get("pi_hao_"));
@@ -208,14 +217,13 @@ public class InventoryService extends GenericProvider {
 
             // 手动判断空值:检查是否为 null 或者 去除空格后长度为0
             if (rawRemain == null || rawRemain.trim().isEmpty()) {
-                // 情况1:为空时,直接赋值为当前库存数量 quantity
+                // 情况1:为空时,直接赋值为当前数量(负数时自动为负值字符串,代数语义正确)
                 remainAmount = shuLiangStr;
             } else {
-                // 情况2:不为空时,解析为整数,加上当前库存数量 quantity
+                // 情况2:不为空时,解析为整数,加上当前数量(负数时代数运算自动做减法)
                 try {
-                    // 去除首尾空格并转为整数
                     int currentVal = Integer.parseInt(rawRemain.trim());
-                    int newVal = currentVal + Integer.parseInt(shuLiangStr);
+                    int newVal = currentVal + shuLiang;
                     remainAmount = String.valueOf(newVal);
                 } catch (NumberFormatException e) {
                     remainAmount = shuLiangStr;
@@ -238,27 +246,34 @@ public class InventoryService extends GenericProvider {
 
             // 3. 逻辑判断
             if ("start".equals(operate)) {
-                if ((quantity - withhold) < shuLiang) {
+                if ((quantity - withhold) < absShuLiang) {
                     checkFlag = false;
-                    errorMsg = name + " 可用库存不足 (可用:" + (quantity - withhold) + ", 需:" + shuLiang + ")";
+                    errorMsg = name + " 可用库存不足 (可用:" + (quantity - withhold) + ", 需:" + absShuLiang + ")";
                     break;
                 }
-                newWithhold = withhold + shuLiang;
+                newWithhold = withhold + absShuLiang;
             } else if ("back".equals(operate)) {
-                if (withhold < shuLiang) {
+                if (withhold < absShuLiang) {
                     checkFlag = false;
-                    errorMsg = name + " 预扣数量不足 (预扣:" + withhold + ", 需:" + shuLiang + ")";
+                    errorMsg = name + " 预扣数量不足 (预扣:" + withhold + ", 需:" + absShuLiang + ")";
                     break;
                 }
-                newWithhold = withhold - shuLiang;
+                newWithhold = withhold - absShuLiang;
             } else if ("end".equals(operate)) {
-                if (quantity < shuLiang || withhold < shuLiang) {
-                    checkFlag = false;
-                    errorMsg = name + " 库存或预扣不足 (库存:" + quantity + ", 预扣:" + withhold + ", 需:" + shuLiang + ")";
-                    break;
+                if (isNegative) {
+                    // 负数 end:直接加库存,预扣不变,无需校验
+                    newQuantity = quantity + absShuLiang;
+                    newWithhold = withhold;
+                } else {
+                    // 正数 end:
+                    if (quantity < absShuLiang || withhold < absShuLiang) {
+                        checkFlag = false;
+                        errorMsg = name + " 库存或预扣不足 (库存:" + quantity + ", 预扣:" + withhold + ", 需:" + absShuLiang + ")";
+                        break;
+                    }
+                    newQuantity = quantity - absShuLiang;
+                    newWithhold = withhold - absShuLiang;
                 }
-                newQuantity = quantity - shuLiang;
-                newWithhold = withhold - shuLiang;
                 isEnd = true;
             } else {
                 checkFlag = false;
@@ -486,30 +501,23 @@ public class InventoryService extends GenericProvider {
         if ("y".equals(deleteRecord) && retVal != null && retVal.startsWith("-1^")) {
             logger.warn("业务校验失败且开启自动清理模式 (deleteRecord=y)。开始删除入库记录主子表脏数据,ID: {}", id);
             try {
-                // 调用删除方法
                 orderService.deleteErrorRecord(id);
-
-                // 可选:在返回信息中追加提示,告知用户已执行清理
                 retVal = retVal + " (系统已自动撤销并删除无效申请记录)";
-
             } catch (Exception e) {
                 logger.error("自动清理失败! ID: {}, 错误: {}", id, e.getMessage(), e);
                 // 如果清理本身也报错,追加警告信息到返回值,但不中断流程(因为业务本来就失败了)
                 retVal = retVal + " (警告:自动清理执行异常,请手动检查数据!)" ;
-                // 如果希望清理失败时向上抛出异常,可以取消下面这行的注释
-                // throw new Exception("业务失败且自动清理也失败", e);
             }
         }
         return retVal;
     }
 
-    // 辅助方法:安全转 Integer
+    // 安全转 Integer
     private int parseInteger(Object obj) {
         if (obj == null) {
             return 0;
         }
-        String s = String.valueOf(obj).trim(); // 使用原生 String.valueOf
-        // 原生判断空
+        String s = String.valueOf(obj).trim();
         if (s == null || s.length() == 0) {
             return 0;
         }

+ 25 - 19
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/service/OrderService.java

@@ -31,12 +31,9 @@ public class OrderService extends GenericProvider {
         if (!Arrays.asList("start", "back", "end").contains(operate)) {
             return "-1^非法的操作类型: " + operate;
         }
-
-        // ================= 1. 基础校验与主表查询 (公共逻辑) =================
         if (id == null || id.trim().isEmpty()) {
             return "-1^id为空";
         }
-
         List<String> idList = Arrays.stream(id.split(","))
                 .map(String::trim)
                 .filter(s -> !s.isEmpty())
@@ -45,12 +42,10 @@ public class OrderService extends GenericProvider {
         if (idList.isEmpty()) {
             return "-1^id非法";
         }
-
         String safeIdStr = idList.stream()
                 .map(s -> s.replace("'", "''"))
                 .collect(Collectors.joining("','"));
 
-        // 查询入库登记子表
         String sqlMain = "SELECT * from t_sjhxhclrkysdjbzb where parent_id_ in('" + safeIdStr + "')";
         List<Map<String, Object>> inSubList = commonDao.query(sqlMain);
 
@@ -58,7 +53,6 @@ public class OrderService extends GenericProvider {
             return "-1^未找到入库登记子表记录";
         }
 
-        // ================= 2. 查询订单子表 (公共逻辑) =================
         List<String> ddzIdList = inSubList.stream()
                 .map(m -> {
                     Object val = m.get("ding_dan_zi_id_");
@@ -84,7 +78,6 @@ public class OrderService extends GenericProvider {
                         (v1, v2) -> v1
                 ));
 
-        // ================= 3. 【第一阶段】全量预校验与SQL构造 (核心差异点) =================
         List<String> updateSqls = new ArrayList<>();
 
         for (Map<String, Object> inSub : inSubList) {
@@ -96,25 +89,23 @@ public class OrderService extends GenericProvider {
 
             Map<String, Object> orderSub = orderSubMap.get(ddzId);
 
-            // 获取数值
-            double inQty = getDoubleValue(inSub.get("shu_liang_"));
-            double currentYuLing = getDoubleValue(orderSub.get("yu_ling_liang_"));
-            double currentDaiRuKu = getDoubleValue(orderSub.get("dai_ru_ku_shu_lia"));
-            double orderQty = getDoubleValue(orderSub.get("shu_liang_")); // 订单总量,start时用
+            int inQty = getIntValue(inSub.get("shu_liang_"));
+            int currentYuLing = getIntValue(orderSub.get("yu_ling_liang_"));
+            int currentDaiRuKu = getIntValue(orderSub.get("dai_ru_ku_shu_lia"));
+            int orderQty = getIntValue(orderSub.get("shu_liang_")); // 订单总量,start时用
 
             if (inQty < 0) {
                 return "-1^数量必须为正数 (当前值:" + inQty + ")";
             }
 
-            // --- 根据 operate 计算新值和校验 ---
-            double newYuLing = 0.0;
-            Double newDaiRuKu = null; // null 表示该操作不更新此字段
+            int newYuLing = 0;
+            Integer newDaiRuKu = null; // null 表示该操作不更新此字段
             boolean checkPassed = false;
             String errorMsg = "";
 
             if ("start".equals(operate)) {
                 // [START] 占用预留,减少待入库
-                double availableQty = orderQty - currentYuLing;
+                int availableQty = orderQty - currentYuLing;
                 if (availableQty < inQty) {
                     errorMsg = "已超过可入库数量! (可用:" + availableQty + ", 申请:" + inQty + ")";
                 } else {
@@ -149,11 +140,11 @@ public class OrderService extends GenericProvider {
                 String mingCheng = Objects.toString(orderSub.get("ming_cheng_"), "");
                 String bianMa = Objects.toString(orderSub.get("bian_ma_"), "");
                 String operateStr = "";
-                if(operate.equals("start")){
+                if ("start".equals(operate)) {
                     operateStr = "启动";
-                } else if (operate.equals("back")){
+                } else if ("back".equals(operate)) {
                     operateStr = "撤回";
-                } else if (operate.equals("end")){
+                } else if ("end".equals(operate)) {
                     operateStr = "结束";
                 }
                 // 统一错误消息格式
@@ -194,6 +185,21 @@ public class OrderService extends GenericProvider {
         return "1^success!";
     }
 
+    private int getIntValue(Object obj) {
+        if (obj == null) {
+            return 0;
+        }
+        if (obj instanceof Number) {
+            return ((Number) obj).intValue();
+        }
+        try {
+            return Integer.parseInt(obj.toString().trim());
+        } catch (NumberFormatException e) {
+            logger.warn("getIntValue parse failed, obj={}", obj, e);
+            return 0;
+        }
+    }
+
     public void deleteErrorRecord(String id) throws Exception {
         if (id == null || id.trim().isEmpty()) {
             return;

+ 0 - 1
ibps-provider-root/modules/provider-platform/src/main/java/com/lc/ibps/platform/plan/job/EquipmentMaintenancePlanJob.java

@@ -375,7 +375,6 @@ public class EquipmentMaintenancePlanJob  extends AbstractJob {
         }
         return list;
     }
-    //搜索冰箱里可以吃的食物,
     @NotNull
     private  String[] buildQueryParam(JobExecutionContext context) {
         JobDataMap dataMap = context.getMergedJobDataMap();