Преглед изворни кода

1、donenow采购入库功能测试,修复bug;
2、Donenow库存产品移库功能测试,修复bug;
3、donenow合同产品拣货功能开发;
4、Donenow合同产品上已拣货产品库存转移功能开发;

zhangyao пре 4 месеци
родитељ
комит
3fdcbb5926

+ 7 - 12
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/event/costCanclePickFormAfterSave.java

@@ -1,7 +1,5 @@
 package com.awspaas.user.apps.donenow_ctt.event;
 
-import com.actionsoft.bpms.bo.design.cache.BOCache;
-import com.actionsoft.bpms.bo.design.model.BOModel;
 import com.actionsoft.bpms.bo.engine.BO;
 import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
 import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
@@ -40,13 +38,10 @@ public class costCanclePickFormAfterSave extends ExecuteListener {
             if (QUANTITY - PICK_QUANTITY == 0) {
                 costProductBO.set("QUANTITY", 0);
                 costProductBO.set("CLOSED", 1);
+                costProductBO.set("SN", "");
                 //记录表单修改
                 dn.recordFormChanges.record(processExecutionContext.getUserContext(), costProductBO, "取消拣货", conn);
-
                 SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", costProductBO, conn);
-                //  SDK.getBOAPI().updateByBindId("BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN", costProductBO.getBindId(), "CLOSED", 1);
-                DBSql.update(conn, "UPDATE BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN SET CLOSED = 1 WHERE CONTRACT_COST_PRODUCT_ID =?", new Object[]{costProductBO.getId()});
-
             } else {
                 costProductBO.set("QUANTITY", QUANTITY - PICK_QUANTITY);
                 costProductBO.set("OLD_QUANTITY", costProductBO.get("QUANTITY"));//配送数量
@@ -54,19 +49,19 @@ public class costCanclePickFormAfterSave extends ExecuteListener {
                 //记录表单修改
                 dn.recordFormChanges.record(processExecutionContext.getUserContext(), costProductBO, "取消拣货", conn);
 
-                SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", costProductBO, conn);
-
+                //产品序列号更新
                 if (StringUtils.isNotBlank(canclePickBO.getString("SERIAL_NUMBERS"))) {
                     String[] serialNumbers = canclePickBO.getString("SERIAL_NUMBERS").split(",");
+                    String sns = costProductBO.getString("SN");//产品序列号
+                    sns = "," + sns + ",";
                     for (int i = 0; i < serialNumbers.length; i++) {
-                        BO costProductSerialBO = SDK.getBOAPI().query("BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN").connection(conn).addQuery("SN", serialNumbers[i]).addQuery("CONTRACT_COST_PRODUCT_ID", costProductBO.getId()).detail();
-                        costProductSerialBO.set("CLOSED", 1);
-                        SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN", costProductSerialBO, conn);
+                        sns = sns.replace("," + serialNumbers[i] + ",", ",");
                     }
+                    costProductBO.set("SN", sns.substring(1, sns.length() - 1));
                 }
+                SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", costProductBO, conn);
             }
 
-
             //修改采购合同状态
             if (DBSql.getInt(conn, "SELECT DOES_NOT_REQUIRE_PROCUREMENT FROM BO_EU_DNIVT_PRODUCT WHERE ID=?", new Object[]{canclePickBO.getString("PRODUCT_ID")}) == 1) {
 

+ 162 - 42
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/event/costPickFormAfterSave.java

@@ -10,8 +10,7 @@ import com.actionsoft.sdk.local.SDK;
 import org.apache.commons.lang3.StringUtils;
 
 import java.sql.Connection;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.*;
 
 public class costPickFormAfterSave extends ExecuteListener {
     public String getDescription() {
@@ -114,25 +113,13 @@ public class costPickFormAfterSave extends ExecuteListener {
             costProductBO.setBindId(processInstance.getId());
 
             // costProductBO.setBindId(SDK.getBOAPI().get("BO_EU_DNCTT_CONTRACT_COST", contractCostId, "BINDID").toString());
-
             costProductBO.set("WAREHOUSE_ID", WAREHOUSE_ID);
             costProductBO.set("CONTRACT_COST_ID", contractCostId);
             costProductBO.set("QUANTITY", pickBO.get("PICK_QUANTITY"));
             costProductBO.set("SN", pick_sns);
-
             costProductBO.set("STATUS_ID", STATUS_ID);
-
             costProductBO.set("OLD_QUANTITY", costProductBO.get("QUANTITY"));//配送数量
             SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", costProductBO, processExecutionContext.getUserContext(), conn);
-            if (StringUtils.isNotBlank(pick_sns)) {
-                for (String serialNumber : pickSerials) {
-                    BO snBO = new BO();
-                    snBO.setBindId(costProductBO.getBindId());
-                    snBO.set("CONTRACT_COST_PRODUCT_ID", costProductBO.getId());
-                    snBO.set("SN", serialNumber);
-                    SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN", snBO, processExecutionContext.getUserContext(), conn);
-                }
-            }
 
 
             //修改状态
@@ -176,16 +163,11 @@ public class costPickFormAfterSave extends ExecuteListener {
                 ivtTransfer.set("PRODUCT_ID", pickBO.getString("PRODUCT_ID"));
                 ivtTransfer.set("QUANTITY", pickBO.get("PICK_QUANTITY"));
                 ivtTransfer.set("TYPE_ID", 1481);  // 仓库间转移
+                if (pickSerials.size() > 0)
+                    ivtTransfer.set("SN", StringUtils.join(pickSerials, ","));//产品序列号
                 SDK.getBOAPI().create("BO_EU_DNIVT_TRANSFER", ivtTransfer, transfeProcessIns, processExecutionContext.getUserContext(), conn);
-                //BO_EU_DNIVT_TRANSFER_SN
-                for (String serialNumber : pickSerials) {
-                    BO snBO = new BO();
-                    snBO.setBindId(ivtTransfer.getBindId());
-                    snBO.set("TRANSFER_ID", ivtTransfer.getId());
-                    snBO.set("SN", serialNumber);
-                    SDK.getBOAPI().createDataBO("BO_EU_DNIVT_TRANSFER_SN", snBO, processExecutionContext.getUserContext(), conn);
-                }
 
+                //库存增加
                 BO toWarehouseProductBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", pickBO.getString("PRODUCT_ID")).addQuery("WAREHOUSE_ID=", WAREHOUSE_ID).detail();
                 if (toWarehouseProductBO != null) {
                     toWarehouseProductBO.set("QUANTITY", ObjToInt(toWarehouseProductBO.get("QUANTITY")) + ObjToInt(pickBO.get("PICK_QUANTITY")));
@@ -200,23 +182,119 @@ public class costPickFormAfterSave extends ExecuteListener {
                     SDK.getBOAPI().create("BO_EU_DNIVT_WAREHOUSE_PRODUCT", toWarehouseProductBO, twpProcessIns, processExecutionContext.getUserContext(), conn);
                 }
 
-                //库存转移
+                //库存减少
                 BO fromWarehouseProductBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", pickBO.getString("PRODUCT_ID")).addQuery("WAREHOUSE_ID=", pickBO.getString("WAREHOUSE_ID")).detail();
                 fromWarehouseProductBO.set("QUANTITY", ObjToInt(fromWarehouseProductBO.get("QUANTITY")) - ObjToInt(pickBO.get("PICK_QUANTITY")));
-                SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
 
-                //BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN
+                SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
 
-                for (String serialNumber : pickSerials) {
-                    DBSql.update(conn, "update BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN set WAREHOUSE_PRODUCT_ID=? where WAREHOUSE_PRODUCT_ID=? and SN=?", new Object[]{toWarehouseProductBO.getId(), fromWarehouseProductBO.getId(), serialNumber});
+                int pickQuantity = ObjToInt(pickBO.get("PICK_QUANTITY"));//拣货数量
+
+
+                //序列号减少  修改库存批次
+                List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>", 0).orderByCreated().list();
+                int cnt = 0;
+                for (BO lot : lots) {
+                    if (pickSerials.size() > 0) {
+                        //序列化产品
+                        boolean isIn = false;
+                        String lotSN = lot.getString("SN");
+                        lotSN = "," + lotSN + ",";
+                        List<String> toSN = new ArrayList<>();
+                        for (String sn : pickSerials) {
+                            if (lotSN.contains("," + sn + ",")) {
+                                isIn = true;
+                                lotSN = lotSN.replace("," + sn + ",", ",");
+                                toSN.add(sn);
+                                cnt++;
+                            }
+                            if (cnt >= pickSerials.size())
+                                break;
+                        }
+                        if (isIn) {
+                            if (StringUtils.isNotBlank(lotSN)) {
+                                lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
+                                        .replaceAll(",+", ",");     // 合并中间连续逗号
+                                int count = (int) lotSN.chars().filter(c -> c == ',').count();
+                                lot.set("SN", lotSN);
+                                lot.set("QUANTITY", count + 1);
+                            } else {
+                                lot.set("SN", "");
+                                lot.set("QUANTITY", 0);
+                            }
+
+                            //更新批次上序列号
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                            //目标 库存批次 增加
+                            BO toLot = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("LOT=", lot.get("LOT")).addQuery("ORDER_PRODUCT_ID=", lot.get("ORDER_PRODUCT_ID")).addQuery("BINDID=", toWarehouseProductBO.getBindId()).detail();
+                            if (toLot != null) {
+                                toLot.set("QUANTITY", Integer.parseInt(toLot.get("QUANTITY").toString()) + toSN.size());
+                                toLot.set("SN", toLot.get("SN") + "," + StringUtils.join(toSN, ","));
+                                SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, conn);
+                            } else {
+                                //新增 目标库批次
+                                toLot = new BO();
+                                toLot.setAll(lot.asMap());
+                                toLot.setId(null);
+                                toLot.setBindId(toWarehouseProductBO.getBindId());
+                                toLot.set("SN", StringUtils.join(toSN, ","));
+                                toLot.set("QUANTITY", toSN.size());
+                                toLot.set("ORDER_PRODUCT_ID", lot.get("ORDER_PRODUCT_ID"));
+                                toLot.set("WAREHOUSE_ID", toWarehouseProductBO.get("WAREHOUSE_ID"));
+                                toLot.set("PRODUCT_ID", toWarehouseProductBO.get("PRODUCT_ID"));
+                                SDK.getBOAPI().createDataBO("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, processExecutionContext.getUserContext(), conn);
+                            }
+                        }
+                        if (cnt >= pickSerials.size())
+                            break;
+                    } else {
+                        //无序列化产品
+                        int lotQuantity = Integer.parseInt(lot.get("QUANTITY").toString());
+                        int toQuantity = 0;
+                        if (lotQuantity > pickQuantity) {
+                            lot.set("QUANTITY", lotQuantity - pickQuantity);
+                            toQuantity = pickQuantity;
+                            pickQuantity = 0;
+
+                        } else {
+                            lot.set("QUANTITY", 0);
+                            toQuantity = lotQuantity;
+                            pickQuantity -= lotQuantity;
+                        }
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                        //目标 库存批次 增加
+                        BO toLot = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("LOT=", lot.get("LOT")).addQuery("ORDER_PRODUCT_ID=", lot.get("ORDER_PRODUCT_ID")).addQuery("BINDID=", toWarehouseProductBO.getBindId()).detail();
+                        if (toLot != null) {
+                            toLot.set("QUANTITY", Integer.parseInt(toLot.get("QUANTITY").toString()) + toQuantity);
+                            toLot.set("SN", "");
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, conn);
+                        } else {
+                            //新增 目标库批次
+                            toLot = new BO();
+                            toLot.setAll(lot.asMap());
+                            toLot.setId(null);
+                            toLot.setBindId(toWarehouseProductBO.getBindId());
+                            toLot.set("SN", "");
+                            toLot.set("QUANTITY", toQuantity);
+                            toLot.set("ORDER_PRODUCT_ID", lot.get("ORDER_PRODUCT_ID"));
+                            toLot.set("WAREHOUSE_ID", toWarehouseProductBO.get("WAREHOUSE_ID"));
+                            toLot.set("PRODUCT_ID", toWarehouseProductBO.get("PRODUCT_ID"));
+                            SDK.getBOAPI().createDataBO("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, processExecutionContext.getUserContext(), conn);
+                        }
+                        if (pickQuantity <= 0)
+                            break;
+
+                    }
                 }
 
             } else if (pickBO.getString("PICK_TYPE").equals("2"))//库存转移给客户
             {
-                //result = ccBll.TranToItem(product_id, pickNum, ware_id, serNumIds, cost_id, LoginUserId);
 
                 BO costBO = SDK.getBOAPI().query("BO_EU_DNCTT_CONTRACT_COST").connection(conn).addQuery("ID=", pickBO.getString("CONTRACT_COST_ID")).detail();
-//ivt_transfer
+
+                //移库记录
                 ProcessInstance transfeProcessIns = SDK.getProcessAPI().createBOProcessInstance("obj_e15a8fedeaeb43dc85aa258a7e1cffcf", processExecutionContext.getUserContext().getUID(), "库存转移");
                 BO ivtTransfer = new BO();
                 ivtTransfer.setBindId(transfeProcessIns.getId());
@@ -231,16 +309,8 @@ public class costPickFormAfterSave extends ExecuteListener {
                 ivtTransfer.set("TYPE_ID", 1482);
                 ivtTransfer.set("PRODUCT_ID", pickBO.getString("PRODUCT_ID"));
                 ivtTransfer.set("QUANTITY", pickBO.get("PICK_QUANTITY"));
+                ivtTransfer.set("SN", StringUtils.join(pickSerials, ","));//产品序列号
                 SDK.getBOAPI().create("BO_EU_DNIVT_TRANSFER", ivtTransfer, transfeProcessIns, processExecutionContext.getUserContext(), conn);
-                //BO_EU_DNIVT_TRANSFER_SN
-
-                for (String serialNumber : pickSerials) {
-                    BO snBO = new BO();
-                    snBO.setBindId(ivtTransfer.getBindId());
-                    snBO.set("TRANSFER_ID", ivtTransfer.getId());
-                    snBO.set("SN", serialNumber);
-                    SDK.getBOAPI().createDataBO("BO_EU_DNIVT_TRANSFER_SN", snBO, processExecutionContext.getUserContext(), conn);
-                }
 
 
                 //减少库存
@@ -248,10 +318,60 @@ public class costPickFormAfterSave extends ExecuteListener {
                 fromWarehouseProductBO.set("QUANTITY", ObjToInt(fromWarehouseProductBO.get("QUANTITY")) - ObjToInt(pickBO.get("PICK_QUANTITY")));
                 SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
 
-                //BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN
-
-                for (String serialNumber : pickSerials) {
-                    DBSql.update(conn, "delete from BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN where WAREHOUSE_PRODUCT_ID=? and SN=?", new Object[]{fromWarehouseProductBO.getId(), serialNumber});
+                int pickQuantity = ObjToInt(pickBO.get("PICK_QUANTITY"));//拣货数量
+                //减少批次
+                List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>", 0).orderByCreated().list();
+                int cnt = 0;
+                for (BO lot : lots) {
+                    if (pickSerials.size() > 0) {
+                        //序列化产品
+                        boolean isIn = false;
+                        String lotSN = lot.getString("SN");
+                        lotSN = "," + lotSN + ",";
+                        List<String> toSN = new ArrayList<>();
+                        for (String sn : pickSerials) {
+                            if (lotSN.contains("," + sn + ",")) {
+                                isIn = true;
+                                lotSN = lotSN.replace("," + sn + ",", ",");
+                                toSN.add(sn);
+                                cnt++;
+                            }
+                            if (cnt >= pickSerials.size())
+                                break;
+                        }
+                        if (isIn) {
+                            if (StringUtils.isNotBlank(lotSN)) {
+                                lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
+                                        .replaceAll(",+", ",");     // 合并中间连续逗号
+                                int count = (int) lotSN.chars().filter(c -> c == ',').count();
+                                lot.set("SN", lotSN);
+                                lot.set("QUANTITY", count + 1);
+                            } else {
+                                lot.set("SN", "");
+                                lot.set("QUANTITY", 0);
+                            }
+
+                            //更新批次上序列号
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                        }
+                        if (cnt >= pickSerials.size())
+                            break;
+                    } else {
+                        //无序列号产品
+                        int toQuantity = ObjToInt(lot.get("QUANTITY"));
+                        if (toQuantity >= pickQuantity) {
+                            lot.set("QUANTITY", pickQuantity);
+                            pickQuantity = 0;
+                        } else {
+                            lot.set("QUANTITY", 0);
+                            pickQuantity -= toQuantity;
+                        }
+                        //更新批次上序列号
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+                        if (pickQuantity <= 0)
+                            break;
+                    }
                 }
             }
 

+ 69 - 34
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/event/costProductShipFormAfterSave.java

@@ -11,6 +11,8 @@ import org.apache.commons.lang3.StringUtils;
 
 import java.sql.Connection;
 import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  *
@@ -36,24 +38,31 @@ public class costProductShipFormAfterSave extends ExecuteListener {
                 conn.setAutoCommit(false);
 
                 int shipQuantity = ObjToInt(productBO.get("QUANTITY"));
-                String SERIAL_NUMBERS = productBO.getString("SN");
+                // String SERIAL_NUMBERS = productBO.getString("SN");
+                int notShipQuantity = ObjToInt(productBO.get("OLD_QUANTITY")) - shipQuantity;//剩余数量;
+
+                String SN = productBO.getString("SN");//原产品序列号
+                String notShipSN = "," + SN + ",";
+                String SHIPPING_SN = productBO.getString("SHIPPING_SN");//配送产品序列号
+                for (String spsn : SHIPPING_SN.split(",")) {
+                    notShipSN = notShipSN.replaceAll("," + spsn + ",", ",");
+                }
+                notShipSN = notShipSN.substring(1, notShipSN.length() - 1);//未配送的产品序列号
+
 
                 //全部配送
                 if (ObjToInt(productBO.get("OLD_QUANTITY")) == shipQuantity) {
                     productBO.set("IS_SHIP", "2");
                     productBO.set("STATUS_ID", 2159);
                     SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
-
-
                 } else {
-
-                    int notShipQuantity = ObjToInt(productBO.get("OLD_QUANTITY")) - shipQuantity;//剩余数量;
-
                     //部分配送
+                    productBO.set("SN", SHIPPING_SN);
                     productBO.set("IS_SHIP", "2");
                     productBO.set("QUANTITY", shipQuantity);
                     productBO.set("OLD_QUANTITY", productBO.get("QUANTITY"));
                     productBO.set("STATUS_ID", 2159);//已配送
+
                     SDK.getBOAPI().update("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", productBO, conn);
 
                     //未配送的生成一个新的物流单
@@ -66,20 +75,8 @@ public class costProductShipFormAfterSave extends ExecuteListener {
                     toCostProductBO.set("QUANTITY", notShipQuantity);
                     toCostProductBO.set("STATUS_ID", 2157);//已拣货
                     toCostProductBO.set("OLD_QUANTITY", toCostProductBO.get("QUANTITY"));//配送数量
+                    productBO.set("SN", notShipSN);//未配送的产品序列号
                     SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", toCostProductBO, processExecutionContext.getUserContext(), conn);
-
-
-                    if (StringUtils.isNotBlank(SERIAL_NUMBERS)) {
-                        DBSql.update(conn, "update BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN set CONTRACT_COST_PRODUCT_ID=? where CONTRACT_COST_PRODUCT_ID=? and FIND_IN_SET(SN,?)=0", new Object[]{toCostProductBO.getId(), productBO.getId(), SERIAL_NUMBERS});
-
-                        String sn1 = DBSql.getString(conn, "select GROUP_CONCAT(SN) from BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN where CONTRACT_COST_PRODUCT_ID=?", new Object[]{toCostProductBO.getId()});
-
-                        DBSql.update(conn, "update BO_EU_DNCTT_CONTRACT_COST_PRODUCT set SN=? where ID=?", new Object[]{sn1, toCostProductBO.getId()});
-
-                        String sn2 = DBSql.getString(conn, "select GROUP_CONCAT(SN) from BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN where CONTRACT_COST_PRODUCT_ID=?", new Object[]{productBO.getId()});
-                        DBSql.update(conn, "update BO_EU_DNCTT_CONTRACT_COST_PRODUCT set SN=? where ID=?", new Object[]{sn2, productBO.getId()});
-                    }
-
                 }
 
                 BO costBO = SDK.getBOAPI().get("BO_EU_DNCTT_CONTRACT_COST", productBO.getString("CONTRACT_COST_ID"));//获取合同产品
@@ -98,17 +95,9 @@ public class costProductShipFormAfterSave extends ExecuteListener {
 
                 ivtTransfer.set("QUANTITY", shipQuantity);
                 ivtTransfer.set("TYPE_ID", 1482);  // 转移给客户
+                ivtTransfer.set("SN", SHIPPING_SN);
                 SDK.getBOAPI().create("BO_EU_DNIVT_TRANSFER", ivtTransfer, transfeProcessIns, processExecutionContext.getUserContext(), conn);
 
-                //BO_EU_DNIVT_TRANSFER_SN
-                if (StringUtils.isNotBlank(SERIAL_NUMBERS))
-                    for (String serialNumber : SERIAL_NUMBERS.split(",")) {
-                        BO snBO = new BO();
-                        snBO.setBindId(ivtTransfer.getBindId());
-                        snBO.set("TRANSFER_ID", ivtTransfer.getId());
-                        snBO.set("SN", serialNumber);
-                        SDK.getBOAPI().createDataBO("BO_EU_DNIVT_TRANSFER_SN", snBO, processExecutionContext.getUserContext(), conn);
-                    }
 
                 //减少库存
                 BO fromWarehouseProductBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", costBO.getString("PRODUCT_ID")).addQuery("WAREHOUSE_ID=", productBO.get("WAREHOUSE_ID")).detail();
@@ -116,13 +105,59 @@ public class costProductShipFormAfterSave extends ExecuteListener {
                 fromWarehouseProductBO.set("QUANTITY", ObjToInt(fromWarehouseProductBO.get("QUANTITY")) - ObjToInt(shipQuantity));
                 SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
 
-                //BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN
-                if (StringUtils.isNotBlank(SERIAL_NUMBERS))
-                    for (String serialNumber : SERIAL_NUMBERS.split(",")) {
-
-                        DBSql.update("delet from BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN where WAREHOUSE_PRODUCT_ID=? and SN=?", new Object[]{fromWarehouseProductBO.getId(), serialNumber});
+                //减少批次
+                List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>0", null).orderByCreated().list();
+                int cnt = 0;
+                String[] shipSerials = SHIPPING_SN.split(",");
+                for (BO lot : lots) {
+                    if (StringUtils.isNotBlank(SHIPPING_SN)) {
+                        boolean isIn = false;
+                        String lotSN = lot.getString("SN");
+                        lotSN = "," + lotSN + ",";
+                        List<String> toSN = new ArrayList<>();
+                        for (String sn : shipSerials) {
+                            if (lotSN.contains("," + sn + ",")) {
+                                isIn = true;
+                                lotSN = lotSN.replace("," + sn + ",", ",");
+                                toSN.add(sn);
+                                cnt++;
+                            }
+                            if (cnt >= shipSerials.length)
+                                break;
+                        }
+                        if (isIn) {
+                            if (StringUtils.isNotBlank(lotSN)) {
+                                lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
+                                        .replaceAll(",+", ",");     // 合并中间连续逗号
+                                int count = (int) lotSN.chars().filter(c -> c == ',').count();
+                                lot.set("SN", lotSN);
+                                lot.set("QUANTITY", count + 1);
+                            } else {
+                                lot.set("SN", "");
+                                lot.set("QUANTITY", 0);
+                            }
+
+                            //更新批次上序列号
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                        }
+                        if (cnt >= shipSerials.length)
+                            break;
+                    } else {
+                        //无序列号处理
+                        int QUANTITY = Integer.parseInt(lot.get("QUANTITY").toString());
+                        if (QUANTITY > shipQuantity) {
+                            lot.set("QUANTITY", QUANTITY - shipQuantity);
+                            shipQuantity=0;
+                        } else {
+                            lot.set("QUANTITY", 0);
+                            shipQuantity = shipQuantity - QUANTITY;
+                        }
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+                        if (shipQuantity<=0)
+                            break;
                     }
-
+                }
 
                 //生成运费成本
                 // 输入运费的物料计费代码,就会生成新的成本ctt_contract_cost

+ 124 - 31
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/event/costTransferProFromAfterSave.java

@@ -9,6 +9,8 @@ import com.actionsoft.sdk.local.SDK;
 import org.apache.commons.lang3.StringUtils;
 
 import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 库存转移修改相关库存
@@ -41,16 +43,19 @@ public class costTransferProFromAfterSave extends ExecuteListener {
                 throw new Exception("移库数量不能大于已拣货数量");
             }
             String FROM_WAREHOUSE_ID = costProductBO.getString("WAREHOUSE_ID");
-            String TO_WAREHOUSE_ID = costProductBO.getString("TO_WAREHOUSE_ID");
+
+            String TO_WAREHOUSE_ID = transferProBO.getString("TO_WAREHOUSE_ID");//转移到仓库
+
+
             if (transferProBO.getString("TYPE").equals("1"))//库存转移给我
             {
                 String resWareId = DBSql.getString(conn, "SELECT ID FROM BO_EU_DNIVT_WAREHOUSE WHERE RESOURCE_ID=? AND CLOSED=0 ", new Object[]{processExecutionContext.getUserContext().getUID()});
                 if (StringUtils.isNotBlank(resWareId)) {
                     TO_WAREHOUSE_ID = resWareId;
                 } else {
+                    //创建员工个人仓库
                     BO resWare = new BO();
                     resWare.set("NAME", "员工:" + processExecutionContext.getUserContext().getUserName());
-
                     ProcessInstance processInstance = SDK.getProcessAPI().createBOProcessInstance("obj_e10413dd6e034d22aac787a35917814c", processExecutionContext.getUserContext().getUID(), "创建员工仓库" + resWare.getString("NAME"));
                     resWare.setBindId(processInstance.getId());
                     resWare.set("IS_DEFAULT", 0);
@@ -70,19 +75,10 @@ public class costTransferProFromAfterSave extends ExecuteListener {
             ivtTransfer.set("PRODUCT_ID", transferProBO.getString("PRODUCT_ID"));
             ivtTransfer.set("QUANTITY", transferQUANTITY);
             ivtTransfer.set("TYPE_ID", 1481);  // 仓库间转移
+            ivtTransfer.set("SN", transferProBO.getString("SERIAL_NUMBER"));//序列号
+            ivtTransfer.set("LOT", null);//批次号
             SDK.getBOAPI().create("BO_EU_DNIVT_TRANSFER", ivtTransfer, transfeProcessIns, processExecutionContext.getUserContext(), conn);
 
-            //BO_EU_DNIVT_TRANSFER_SN
-            if (StringUtils.isNotBlank(SERIAL_NUMBERS))
-                for (String serialNumber : SERIAL_NUMBERS.split(",")) {
-                    BO snBO = new BO();
-                    snBO.setBindId(ivtTransfer.getBindId());
-                    snBO.set("TRANSFER_ID", ivtTransfer.getId());
-                    snBO.set("SN", serialNumber);
-                    SDK.getBOAPI().createDataBO("BO_EU_DNIVT_TRANSFER_SN", snBO, processExecutionContext.getUserContext(), conn);
-                }
-
-
             BO toWarehouseProductBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", transferProBO.getString("PRODUCT_ID")).addQuery("WAREHOUSE_ID=", TO_WAREHOUSE_ID).detail();
             if (toWarehouseProductBO != null) {
                 toWarehouseProductBO.set("QUANTITY", ObjToInt(toWarehouseProductBO.get("QUANTITY")) + ObjToInt(transferQUANTITY));
@@ -102,11 +98,106 @@ public class costTransferProFromAfterSave extends ExecuteListener {
             fromWarehouseProductBO.set("QUANTITY", ObjToInt(fromWarehouseProductBO.get("QUANTITY")) - ObjToInt(transferQUANTITY));
             SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", fromWarehouseProductBO, conn);
 
-            //BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN
-            if (StringUtils.isNotBlank(SERIAL_NUMBERS))
-                for (String serialNumber : SERIAL_NUMBERS.split(",")) {
-                    DBSql.update(conn, "update BO_EU_DNIVT_WAREHOUSE_PRODUCT_SN set WAREHOUSE_PRODUCT_ID=? where WAREHOUSE_PRODUCT_ID=? and SN=?", new Object[]{toWarehouseProductBO.getId(), fromWarehouseProductBO.getId(), serialNumber});
+
+            String[] transferSerials = SERIAL_NUMBERS.split(",");
+            int transferQuantity = transferQUANTITY;
+            //序列号减少  修改库存批次
+            List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromWarehouseProductBO.getBindId()).addQuery("QUANTITY>", 0).orderByCreated().list();
+            int cnt = 0;
+            for (BO lot : lots) {
+                if (transferSerials.length > 0) {
+                    //序列化产品
+                    boolean isIn = false;
+                    String lotSN = lot.getString("SN");
+                    lotSN = "," + lotSN + ",";
+                    List<String> toSN = new ArrayList<>();
+                    for (String sn : transferSerials) {
+                        if (lotSN.contains("," + sn + ",")) {
+                            isIn = true;
+                            lotSN = lotSN.replace("," + sn + ",", ",");
+                            toSN.add(sn);
+                            cnt++;
+                        }
+                        if (cnt >= transferSerials.length)
+                            break;
+                    }
+                    if (isIn) {
+                        if (StringUtils.isNotBlank(lotSN)) {
+                            lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
+                                    .replaceAll(",+", ",");     // 合并中间连续逗号
+                            int count = (int) lotSN.chars().filter(c -> c == ',').count();
+                            lot.set("SN", lotSN);
+                            lot.set("QUANTITY", count + 1);
+                        } else {
+                            lot.set("SN", "");
+                            lot.set("QUANTITY", 0);
+                        }
+
+                        //更新批次上序列号
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                        //目标 库存批次 增加
+                        BO toLot = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("LOT=", lot.get("LOT")).addQuery("ORDER_PRODUCT_ID=", lot.get("ORDER_PRODUCT_ID")).addQuery("BINDID=", toWarehouseProductBO.getBindId()).detail();
+                        if (toLot != null) {
+                            toLot.set("QUANTITY", Integer.parseInt(toLot.get("QUANTITY").toString()) + toSN.size());
+                            toLot.set("SN", toLot.get("SN") + "," + StringUtils.join(toSN, ","));
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, conn);
+                        } else {
+                            //新增 目标库批次
+                            toLot = new BO();
+                            toLot.setAll(lot.asMap());
+                            toLot.setId(null);
+                            toLot.setBindId(toWarehouseProductBO.getBindId());
+                            toLot.set("SN", StringUtils.join(toSN, ","));
+                            toLot.set("QUANTITY", toSN.size());
+                            toLot.set("ORDER_PRODUCT_ID", lot.get("ORDER_PRODUCT_ID"));
+                            toLot.set("WAREHOUSE_ID", toWarehouseProductBO.get("WAREHOUSE_ID"));
+                            toLot.set("PRODUCT_ID", toWarehouseProductBO.get("PRODUCT_ID"));
+                            SDK.getBOAPI().createDataBO("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, processExecutionContext.getUserContext(), conn);
+                        }
+                    }
+                    if (cnt >= transferSerials.length)
+                        break;
+                } else {
+                    //无序列化产品
+                    int lotQuantity = Integer.parseInt(lot.get("QUANTITY").toString());
+                    int toQuantity = 0;
+                    if (lotQuantity > transferQuantity) {
+                        lot.set("QUANTITY", lotQuantity - transferQuantity);
+                        toQuantity = transferQuantity;
+                        transferQuantity = 0;
+
+                    } else {
+                        lot.set("QUANTITY", 0);
+                        toQuantity = lotQuantity;
+                        transferQuantity -= lotQuantity;
+                    }
+                    SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+
+                    //目标 库存批次 增加
+                    BO toLot = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("LOT=", lot.get("LOT")).addQuery("ORDER_PRODUCT_ID=", lot.get("ORDER_PRODUCT_ID")).addQuery("BINDID=", toWarehouseProductBO.getBindId()).detail();
+                    if (toLot != null) {
+                        toLot.set("QUANTITY", Integer.parseInt(toLot.get("QUANTITY").toString()) + toQuantity);
+                        toLot.set("SN", "");
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, conn);
+                    } else {
+                        //新增 目标库批次
+                        toLot = new BO();
+                        toLot.setAll(lot.asMap());
+                        toLot.setId(null);
+                        toLot.setBindId(toWarehouseProductBO.getBindId());
+                        toLot.set("SN", "");
+                        toLot.set("QUANTITY", toQuantity);
+                        toLot.set("ORDER_PRODUCT_ID", lot.get("ORDER_PRODUCT_ID"));
+                        toLot.set("WAREHOUSE_ID", toWarehouseProductBO.get("WAREHOUSE_ID"));
+                        toLot.set("PRODUCT_ID", toWarehouseProductBO.get("PRODUCT_ID"));
+                        SDK.getBOAPI().createDataBO("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, processExecutionContext.getUserContext(), conn);
+                    }
+                    if (transferQuantity <= 0)
+                        break;
+
                 }
+            }
 
 
             //全部转移
@@ -114,6 +205,20 @@ public class costTransferProFromAfterSave extends ExecuteListener {
                 costProductBO.set("WAREHOUSE_ID", TO_WAREHOUSE_ID);
                 SDK.getBOAPI().update("BO_EU_DNIVT_COST_PRODUCT", costProductBO, conn);
             } else {
+                //部分转移
+                costProductBO.set("QUANTITY", ObjToInt(costProductBO.get("QUANTITY")) - transferQUANTITY);
+                if (StringUtils.isNotBlank(SERIAL_NUMBERS)) {
+                    String[] serialNumbers = SERIAL_NUMBERS.split(",");
+                    String sns = costProductBO.getString("SN");//产品序列号
+                    sns = "," + sns + ",";
+                    for (int i = 0; i < serialNumbers.length; i++) {
+                        sns = sns.replace("," + serialNumbers[i] + ",", ",");
+                    }
+                    costProductBO.set("SN", sns.substring(1, sns.length() - 1));
+                }
+                costProductBO.set("OLD_QUANTITY", costProductBO.get("QUANTITY"));//配送数量
+                SDK.getBOAPI().update("BO_EU_DNIVT_COST_PRODUCT", costProductBO, conn);
+
 
                 BO toCostProductBO = new BO();
                 ProcessInstance processInstance = SDK.getProcessAPI().createBOProcessInstance("obj_6bc913271069455abbd516c556b26d31", processExecutionContext.getUserContext().getUID(), "合同产品物流管理");
@@ -122,22 +227,10 @@ public class costTransferProFromAfterSave extends ExecuteListener {
                 toCostProductBO.set("CONTRACT_COST_ID", costProductBO.get("CONTRACT_COST_ID"));
                 toCostProductBO.set("QUANTITY", transferQUANTITY);
                 toCostProductBO.set("SN", SERIAL_NUMBERS);
-                toCostProductBO.set("STATUS_ID", 2157);
-
-                costProductBO.set("OLD_QUANTITY", costProductBO.get("QUANTITY"));//配送数量
+                toCostProductBO.set("STATUS_ID", 2157);//待出库
+                toCostProductBO.set("OLD_QUANTITY", toCostProductBO.get("QUANTITY"));//配送数量
                 SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT", toCostProductBO, processExecutionContext.getUserContext(), conn);
-                if (StringUtils.isNotBlank(SERIAL_NUMBERS)) {
-                    for (String serialNumber : SERIAL_NUMBERS.split(",")) {
-                        BO snBO = new BO();
-                        snBO.setBindId(toCostProductBO.getBindId());
-                        snBO.set("CONTRACT_COST_PRODUCT_ID", toCostProductBO.getId());
-                        snBO.set("SN", serialNumber);
-                        SDK.getBOAPI().createDataBO("BO_EU_DNCTT_CONTRACT_COST_PRODUCT_SN", snBO, processExecutionContext.getUserContext(), conn);
-                    }
-                }
             }
-
-
             conn.commit();
         } catch (Exception e) {
             conn.rollback();

BIN
com.awspaas.user.apps.donenow_ivt/lib/com.awspaas.user.apps.donenow_ivt.jar


+ 23 - 26
com.awspaas.user.apps.donenow_ivt/src/com/awspaas/user/apps/donenow_ivt/event/DoWorkThread.java

@@ -7,7 +7,6 @@ import com.actionsoft.bpms.commons.database.RowMap;
 import com.actionsoft.bpms.server.UserContext;
 import com.actionsoft.bpms.util.DBSql;
 import com.actionsoft.bpms.util.UUIDGener;
-import com.actionsoft.exception.BPMNError;
 import com.actionsoft.sdk.local.SDK;
 import com.awspaas.user.apps.donenow_ivt.constant.IVTConstant;
 import com.awspaas.user.apps.donenow_ivt.utils.BigDecimalUtil;
@@ -30,6 +29,9 @@ public class DoWorkThread extends Thread {
     }
 
     public String doWork(ProcessExecutionContext process) {
+
+        System.out.println("=========================BO_EU_DNIVT_RECEIVE_MAIN=================================");
+
         UserContext uc = process.getUserContext();
         BO formData = process.getFormData();
         String boName = process.getParameterOfString("$BONAME");
@@ -39,32 +41,13 @@ public class DoWorkThread extends Thread {
             String bindId = process.getProcessInstance().getId();
             List<BO> list = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_RECEIVE_SUB).bindId(bindId).list();
 
+            System.out.println("=========================BO_EU_DNIVT_RECEIVE_SUB=================================" + list.size());
 
-            //序列号不能重复
+            //循环开始
             for (BO bo : list) {
                 String BEN_RECEIVE = BigDecimalUtil.isNull(bo.getString("BEN_RECEIVE"));
-                int intBenReceive = Integer.valueOf(BEN_RECEIVE).intValue();
-                String sns = bo.getString("SN");
-                if (StringUtils.isNotBlank(sns)) {
-                    for (String sn : sns.split(",")) {
-                        List<RowMap> exitsLots = DBSql.getMaps("select * from BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT WHERE FIND_IN_SET(?,SN)", new Object[]{sn});
-                        if (exitsLots.size() > 0 && intBenReceive > 0) {
-                            //已存在,不能再新增
-                            throw new BPMNError("505", sn + "已存在此序列号,不能再新增!");
-
-                        } else {
-                            if (intBenReceive < 0) {
-                                //不存在,不能取消
-                                throw new BPMNError("505", sn + "不存在此序列号,不能取消接收!");
-                            }
-                        }
-                    }
-                }
-            }
+                int intBenReceive = Integer.valueOf(BEN_RECEIVE).intValue();//本次接收数量
 
-
-            //循环开始
-            for (BO bo : list) {
                 RowMap rowMap = DBSql.getMap("select ORDER_PRODUCT_ID,sum(QUANTITY_RECEIVED) QUANTITY_RECEIVED from BO_EU_DNIVT_RECEIVE WHERE  ORDER_PRODUCT_ID=? group by ORDER_PRODUCT_ID", new Object[]{bo.getString("ORDER_PRODUCT_ID")});
                 BO receiveBo = new BO();
                 receiveBo.set("ORDER_PRODUCT_ID", bo.get("ORDER_PRODUCT_ID"));
@@ -105,6 +88,7 @@ public class DoWorkThread extends Thread {
                 //多次接收是更新操作
                 BO warehouseProductLotBo = SDK.getBOAPI().query(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT).addQuery("ORDER_PRODUCT_ID=", bo.getString("ORDER_PRODUCT_ID")).detail();
                 if (warehouseProductLotBo == null || warehouseProductLotBo.isNew()) {
+                    warehouseProductLotBo = new BO();
                     warehouseProductLotBo.setBindId(wareHouseProductBINDID);
                     warehouseProductLotBo.set("PRODUCT_ID", bo.getString("PRODUCT_ID"));
                     warehouseProductLotBo.set("WAREHOUSE_ID", bo.getString("WAREHOUSE_ID"));
@@ -114,8 +98,22 @@ public class DoWorkThread extends Thread {
                     warehouseProductLotBo.set("ORDER_PRODUCT_ID", bo.getString("ORDER_PRODUCT_ID"));
                     SDK.getBOAPI().createDataBO(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT, warehouseProductLotBo, uc);
                 } else {
-                    warehouseProductLotBo.set("SN", warehouseProductLotBo.getString("SN") + "," + bo.getString("SN"));
+                    if(StringUtils.isNotBlank(bo.getString("SN"))) {
+                        if (intBenReceive > 0)
+                            warehouseProductLotBo.set("SN", warehouseProductLotBo.getString("SN") + "," + bo.getString("SN"));
+                        else {
+                            String sns = warehouseProductLotBo.getString("SN");
+                            sns = "," + sns + ",";
+                            for (String sn : bo.getString("SN").split(",")) {
+                                sns = sns.replaceAll("," + sn + ",", ",");
+                            }
+                            warehouseProductLotBo.set("SN", sns.substring(1, sns.length() - 1));
+                        }
+                    }
+                    //String sns = warehouseProductLotBo.getString("SN");
+                    //long count = StringUtils.isBlank(sns) ? 0 : sns.chars().filter(c -> c == ',').count()+1;
                     warehouseProductLotBo.set("QUANTITY", BigDecimalUtil.add(warehouseProductLotBo.getString("QUANTITY"), bo.getString("BEN_RECEIVE")));
+
                     SDK.getBOAPI().update(IVTConstant.BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT, warehouseProductLotBo);
                 }
 
@@ -142,8 +140,7 @@ public class DoWorkThread extends Thread {
                         //根据成本ID找到对应的所有成本产品
                         List<BO> costProductList = SDK.getBOAPI().query(IVTConstant.BO_EU_DNCTT_CONTRACT_COST_PRODUCT).addQuery("CONTRACT_COST_ID=", CONTRACT_COST_Detail.getId()).list();
                         //判断成本是否是采购中状态
-                        String BEN_RECEIVE = BigDecimalUtil.isNull(bo.getString("BEN_RECEIVE"));
-                        int intBenReceive = Integer.valueOf(BEN_RECEIVE).intValue();
+
                         //采购接收
                         if (intBenReceive > 0) {
                             for (BO costProductBo : costProductList) {

+ 56 - 24
com.awspaas.user.apps.donenow_ivt/src/com/awspaas/user/apps/donenow_ivt/event/ivtTransferFormSaveAfter.java

@@ -44,7 +44,9 @@ public class ivtTransferFormSaveAfter extends ExecuteListener {
 
             if (StringUtils.isNotBlank(TYPE_ID) && !TYPE_ID.equals("0")) {
                 BO fromBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", PRODUCT_ID).addQuery("WAREHOUSE_ID=", FROM_WAREHOUSE_ID).detail();
-                int fromQuantity = fromBO.get("QUANTITY", Integer.class) - rowMap.getInt("QUANTITY");
+
+                int transferQuantity = rowMap.getInt("QUANTITY");//转出数量
+                int fromQuantity = Integer.parseInt(fromBO.get("QUANTITY").toString()) - transferQuantity;
                 if (fromQuantity < 0) {
                     //报错
                     throw new RuntimeException("转出数量不能大于库存数量");
@@ -54,11 +56,13 @@ public class ivtTransferFormSaveAfter extends ExecuteListener {
 
                 List<Map<String, Object>> fromLosts = new ArrayList<>();
                 //更新出库的批次号
-                if (StringUtils.isNotBlank(sns)) {
-                    String[] asArr = sns.split(",");
-                    int cnt = 0;
-                    List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromBO.getBindId()).list();
-                    for (BO lot : lots) {
+
+                String[] asArr = sns.split(",");
+                int cnt = 0;
+                List<BO> lots = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("BINDID=", fromBO.getBindId()).addQuery("QUANTITY>0", null).orderByCreated().list();
+                for (BO lot : lots) {
+                    if (StringUtils.isNotBlank(sns)) {
+                        //序列化产品
                         boolean isIn = false;
                         String lotSN = lot.getString("SN");
                         lotSN = "," + lotSN + ",";
@@ -66,31 +70,57 @@ public class ivtTransferFormSaveAfter extends ExecuteListener {
                         for (String sn : asArr) {
                             if (lotSN.contains("," + sn + ",")) {
                                 isIn = true;
-                                lotSN = lotSN.replace("," + sn + ",", "");
+                                lotSN = lotSN.replace("," + sn + ",", ",");
                                 toSN.add(sn);
                                 cnt++;
                             }
                             if (cnt >= asArr.length) break;
                         }
                         if (isIn) {
+                            if (StringUtils.isNotBlank(lotSN)) {
+                                lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
+                                        .replaceAll(",+", ",");     // 合并中间连续逗号
+                                int count = (int) lotSN.chars().filter(c -> c == ',').count();
+                                lot.set("SN", lotSN);
+                                lot.set("QUANTITY", count + 1);
+                            } else {
+                                lot.set("SN", "");
+                                lot.set("QUANTITY", 0);
+                            }
 
+                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
                             Map<String, Object> map = lot.asMap();
-
                             map.remove("ID");
                             map.remove("BINDID");
-                            map.put("SN", StringUtils.join(lotSN, ","));
+                            map.put("SN", StringUtils.join(toSN, ","));
                             map.put("QUANTITY", toSN.size());
                             fromLosts.add(map);
-
-
-                            lotSN = lotSN.replaceAll("^,+|,+$", "") // 移除首尾一个或多个逗号
-                                    .replaceAll(",+", ",");     // 合并中间连续逗号
-                            int count = (int) lotSN.chars().filter(c -> c == ',').count();
-                            lot.set("SN", lotSN);
-                            lot.set("QUANTITY", count);
-                            SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
                         }
-                        if (cnt >= asArr.length) break;
+                        if (cnt >= asArr.length)
+                            break;
+                    } else {
+                        //无序列化
+                        int count = Integer.parseInt(lot.get("QUANTITY").toString());
+                        int toQuantity = 0;
+                        if (count > transferQuantity) {
+                            lot.set("QUANTITY", count - transferQuantity);
+                            toQuantity = transferQuantity;
+                            transferQuantity = 0;
+                        } else {
+                            lot.set("QUANTITY", 0);
+                            toQuantity = count;
+                            transferQuantity = transferQuantity - count;
+                        }
+
+                        SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", lot, conn);
+                        Map<String, Object> map = lot.asMap();
+                        map.remove("ID");
+                        map.remove("BINDID");
+                        map.put("SN", "");
+                        map.put("QUANTITY", toQuantity);
+                        fromLosts.add(map);
+                        if (transferQuantity <= 0)
+                            break;
                     }
                 }
 
@@ -105,17 +135,15 @@ public class ivtTransferFormSaveAfter extends ExecuteListener {
                     BO toBO = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT").connection(conn).addQuery("PRODUCT_ID=", PRODUCT_ID).addQuery("WAREHOUSE_ID=", TO_WAREHOUSE_ID).detail();
 
                     if (toBO == null) {
-
                         ProcessInstance processInstance = SDK.getProcessAPI().createBOProcessInstance("obj_41f06b1e807647db8a69dd10d4be5764", processExecutionContext.getUserContext().getUID(), "新增库存产品" + PRODUCT_ID + "仓库间转移" + TO_WAREHOUSE_ID);
-
                         toBO = new BO();
                         toBO.set("PRODUCT_ID", PRODUCT_ID);
                         toBO.set("WAREHOUSE_ID", TO_WAREHOUSE_ID);
                         toBO.set("QUANTITY", rowMap.getInt("QUANTITY"));
                         toBO.setBindId(processInstance.getId());
-                        SDK.getBOAPI().create("BO_EU_DNIVT_WAREHOUSE_PRODUCT", toBO, "", processExecutionContext.getUserContext().getUID(), conn);
+                        SDK.getBOAPI().create("BO_EU_DNIVT_WAREHOUSE_PRODUCT", toBO, processInstance.getId(), processExecutionContext.getUserContext().getUID(), conn);
                     } else {
-                        toBO.set("QUANTITY", toBO.get("QUANTITY", Integer.class) + rowMap.getInt("QUANTITY"));
+                        toBO.set("QUANTITY", Integer.parseInt(toBO.get("QUANTITY").toString()) + rowMap.getInt("QUANTITY"));
                         SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT", toBO, conn);
                     }
 
@@ -127,12 +155,16 @@ public class ivtTransferFormSaveAfter extends ExecuteListener {
                             BO toLot = SDK.getBOAPI().query("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT").addQuery("LOT=", lot.get("LOT")).addQuery("ORDER_PRODUCT_ID=", lot.get("ORDER_PRODUCT_ID")).addQuery("BINDID=", toBO.getBindId()).detail();
                             if (toLot != null) {
                                 toLot.set("QUANTITY", Integer.parseInt(toLot.get("QUANTITY").toString()) + Integer.parseInt(lot.get("QUANTITY").toString()));
-                                toLot.set("SN", toLot.get("SN") + "," + lot.get("SN"));
+                                if (StringUtils.isNotBlank(lot.get("SN").toString()))
+                                    toLot.set("SN", toLot.get("SN") + "," + lot.get("SN"));
                                 SDK.getBOAPI().update("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, conn);
                             } else {
                                 toLot = new BO();
-                                toBO.setAll(lot);
+                                toLot.setAll(lot);
                                 toLot.setBindId(toBO.getBindId());
+                                toLot.set("ORDER_PRODUCT_ID", lot.get("ORDER_PRODUCT_ID"));
+                                toLot.set("WAREHOUSE_ID", toBO.get("WAREHOUSE_ID"));
+                                toLot.set("PRODUCT_ID", toBO.get("PRODUCT_ID"));
                                 SDK.getBOAPI().createDataBO("BO_EU_DNIVT_WAREHOUSE_PRODUCT_LOT", toLot, processExecutionContext.getUserContext(), conn);
                             }
                         }

+ 1 - 1
com.awspaas.user.apps.donenow_ivt/src/com/awspaas/user/apps/donenow_ivt/event/reserveFormBeforeSave.java

@@ -16,7 +16,7 @@ import java.util.List;
 
 public class reserveFormBeforeSave extends InterruptListener {
     public String getDescription() {
-        return "合同产品拣货保存前,校验库存";
+        return "采购接收/取消接收保存前,校验库存";
     }
 
     /**