Browse Source

出入库单代码整理

shenjingwei 2 months ago
parent
commit
ddad424750

+ 1 - 1
pom.xml

@@ -61,7 +61,7 @@
         <dependency>
             <groupId>com.yunlian.yos</groupId>
             <artifactId>yos-core</artifactId>
-            <version>3.2.12</version>
+            <version>3.2.13</version>
         </dependency>
         <dependency>
             <groupId>com.microsoft.sqlserver</groupId>

+ 58 - 50
src/custom/beans/accountbalance/Accountbalance.java

@@ -4,10 +4,13 @@ import beans.remind.Remind;
 import com.alibaba.fastjson.JSONObject;
 import common.BaseClass;
 import common.Controller;
+import common.UserInfo;
 import common.YosException;
 import common.data.Rows;
 import common.data.SQLFactory;
+import common.data.db.DBConnect;
 import org.apache.commons.lang.StringUtils;
+import org.sqlite.core.DB;
 import restcontroller.webmanage.executorService.Executor;
 
 import java.math.BigDecimal;
@@ -24,11 +27,14 @@ public class Accountbalance extends BaseClass {
      * @throws YosException
      */
     public static AccountbalanceEntity getAccountbalance(Controller controller, long sys_enterpriseid, long sa_accountclassid) throws YosException {
+        return getAccountbalance(controller.dbConnect, sys_enterpriseid, sa_accountclassid);
+    }
+
+    public static AccountbalanceEntity getAccountbalance(DBConnect dbConnect, long sys_enterpriseid, long sa_accountclassid) throws YosException {
         SQLFactory sqlFactory = new SQLFactory(new Accountbalance(), "账户余额查询");
         sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
         sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
-        sqlFactory.addParameter("siteid", controller.siteid);
-        Rows rows = controller.dbConnect.runSqlQuery(sqlFactory.getSQL());
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
         AccountbalanceEntity accountbalanceEntity = new AccountbalanceEntity();
         if (!rows.isEmpty()) {
             accountbalanceEntity.setBalance(rows.get(0).getBigDecimal("balance"));
@@ -51,7 +57,11 @@ public class Accountbalance extends BaseClass {
      * @throws YosException
      */
     public static boolean judgeBalance(Controller controller, long sys_enterpriseid, long sa_accountclassid, BigDecimal amount) throws YosException {
-        AccountbalanceEntity accountbalanceEntity = getAccountbalance(controller, sys_enterpriseid, sa_accountclassid);
+        return judgeBalance(controller.dbConnect, sys_enterpriseid, sa_accountclassid, amount);
+    }
+
+    public static boolean judgeBalance(DBConnect dbConnect, long sys_enterpriseid, long sa_accountclassid, BigDecimal amount) throws YosException {
+        AccountbalanceEntity accountbalanceEntity = getAccountbalance(dbConnect, sys_enterpriseid, sa_accountclassid);
         BigDecimal canuseamount = accountbalanceEntity.getCanuseamount();
         if (canuseamount != null) {
             if (canuseamount.compareTo(amount) == 1 || canuseamount.compareTo(amount) == 0) {
@@ -62,21 +72,24 @@ public class Accountbalance extends BaseClass {
         } else {
             return false;
         }
+    }
 
+    public static BigDecimal InsufficientBalance(Controller controller, long sys_enterpriseid, long sa_accountclassid, BigDecimal amount) throws YosException {
+        return InsufficientBalance(controller.dbConnect, sys_enterpriseid, sa_accountclassid, amount);
     }
 
     /**
      * 返回不足金额
      *
-     * @param controller
+     * @param dbConnect
      * @param sys_enterpriseid
      * @param sa_accountclassid
      * @param amount
      * @return
      * @throws YosException
      */
-    public static BigDecimal InsufficientBalance(Controller controller, long sys_enterpriseid, long sa_accountclassid, BigDecimal amount) throws YosException {
-        AccountbalanceEntity accountbalanceEntity = getAccountbalance(controller, sys_enterpriseid, sa_accountclassid);
+    public static BigDecimal InsufficientBalance(DBConnect dbConnect, long sys_enterpriseid, long sa_accountclassid, BigDecimal amount) throws YosException {
+        AccountbalanceEntity accountbalanceEntity = getAccountbalance(dbConnect, sys_enterpriseid, sa_accountclassid);
         BigDecimal canuseamount = accountbalanceEntity.getCanuseamount();
         if (canuseamount != null) {
             if (canuseamount.compareTo(amount) == 1 || canuseamount.compareTo(amount) == 0) {
@@ -137,15 +150,11 @@ public class Accountbalance extends BaseClass {
             sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
 
             // 审核逻辑判断
-            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='"
-                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
-                            + controller.siteid + "'");
+            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
 
             if (rowsaccountbalance.isEmpty()) {
                 SQLFactory accountbalanceaddSqlFactory = new SQLFactory(new Accountbalance(), "营销账户余额新增");
-                accountbalanceaddSqlFactory.addParameter("sa_accountbalanceid",
-                        controller.createTableID("sa_accountbalance"));
+                accountbalanceaddSqlFactory.addParameter("sa_accountbalanceid", controller.createTableID("sa_accountbalance"));
                 accountbalanceaddSqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
                 accountbalanceaddSqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
                 accountbalanceaddSqlFactory.addParameter("siteid", controller.siteid);
@@ -158,11 +167,7 @@ public class Accountbalance extends BaseClass {
             } else {
                 BigDecimal newbalance = cashbillEntity.getAmount().add(rowsaccountbalance.get(0).getBigDecimal("balance"));
                 BigDecimal newdiscountamount = cashbillEntity.getDiscountamountamount().add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
-                sqlList.add("update sa_accountbalance set balance='" + newbalance
-                        + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='"
-                        + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid
-                        + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid
-                        + "'");
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='" + newdiscountamount + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
@@ -187,10 +192,14 @@ public class Accountbalance extends BaseClass {
         return jsonObject;
     }
 
+    public static JSONObject createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck) throws YosException {
+        return createCashbillPay(controller.dbConnect, controller.userInfo, sys_enterpriseid, sa_accountclassid, cashbillEntity, ischeck);
+    }
+
     /**
      * 创建支出凭证(返回SQL)
      *
-     * @param controller
+     * @param dbConnect
      * @param sys_enterpriseid  企业id
      * @param sa_accountclassid 账户id
      * @param cashbillEntity    收支凭证实体
@@ -198,22 +207,22 @@ public class Accountbalance extends BaseClass {
      * @return
      * @throws YosException
      */
-    public static JSONObject createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck) throws YosException {
+    public static JSONObject createCashbillPay(DBConnect dbConnect, UserInfo userInfo, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck) throws YosException {
         ArrayList<String> sqlList = new ArrayList<>();
-        long sa_cashbillid = controller.createTableID("sa_cashbill");
-        String billcode = controller.createBillCode("cashbill");
+        long sa_cashbillid = new BaseClass().createTableID("sa_cashbill");
+        String billcode = new BaseClass().createBillCode(userInfo.getSiteId(), "cashbill");
         SQLFactory sqlFactory = new SQLFactory(new Accountbalance(), "收支凭证新增");
         sqlFactory.addParameter("billno", billcode);
         sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
         sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
         sqlFactory.addParameter("type", 0);
-        sqlFactory.addParameter("siteid", controller.siteid);
+        sqlFactory.addParameter("siteid", userInfo.getSiteId());
         sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
         sqlFactory.addParameter("amount", cashbillEntity.getAmount());
         sqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
         sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
-        sqlFactory.addParameter("userid", controller.userid);
-        sqlFactory.addParameter("username", controller.username);
+        sqlFactory.addParameter("userid", userInfo.getUserId());
+        sqlFactory.addParameter("username", userInfo.getUserName());
         sqlFactory.addParameter("ownertable", cashbillEntity.getOwnertable());
         sqlFactory.addParameter("ownerid", cashbillEntity.getOwnerid());
         sqlFactory.addParameter("source", cashbillEntity.getSource());
@@ -226,14 +235,11 @@ public class Accountbalance extends BaseClass {
         if (ischeck) {
             BigDecimal balance = BigDecimal.ZERO;  //当前账户余额
             sqlFactory.addParameter("status", "审核");
-            sqlFactory.addParameter("checkby", controller.username);
+            sqlFactory.addParameter("checkby", userInfo.getUserName());
             sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
 
             // 审核逻辑判断
-            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='"
-                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
-                            + controller.siteid + "'");
+            Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + userInfo.getSiteId() + "'");
             if (rowsaccountbalance.isEmpty()) {
 //				SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
 //				sqlFactory.addParameter("sa_accountbalanceid",  createTableID("sa_accountbalance"));
@@ -252,14 +258,14 @@ public class Accountbalance extends BaseClass {
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
                 BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='" + newdiscountamount + "',changedate=CURRENT_TIME,changeby ='" + userInfo.getUserName() + "',changeuserid='" + userInfo.getUserId() + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + userInfo.getSiteId() + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
-            Rows accountclassrows = controller.dbConnect.runSqlQuery("select * from sa_accountclass where siteid='" + controller.siteid + "' and  sa_accountclassid=" + sa_accountclassid);
+            Rows accountclassrows = dbConnect.runSqlQuery("select * from sa_accountclass where siteid='" + userInfo.getSiteId() + "' and  sa_accountclassid=" + sa_accountclassid);
             if (!accountclassrows.isEmpty()) {
                 String content = "您的" + accountclassrows.get(0).getString("accountname") + "已支出【" + cashbillEntity.getAmount() + "】元";
-                new Accountbalance().sendMsg(controller, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
+                new Accountbalance().sendMsg(dbConnect, userInfo, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
             }
         } else {
             sqlFactory.addParameter("status", "新建");
@@ -309,10 +315,7 @@ public class Accountbalance extends BaseClass {
             sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
 
             // 审核逻辑判断
-            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
-                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
-                            + controller.siteid + "'");
+            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
             if (rowsaccountbalance.isEmpty()) {
 //				SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
 //				sqlFactory.addParameter("sa_accountbalanceid",  createTableID("sa_accountbalance"));
@@ -331,7 +334,7 @@ public class Accountbalance extends BaseClass {
 //                }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
                 BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='" + newdiscountamount + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
@@ -356,7 +359,6 @@ public class Accountbalance extends BaseClass {
     }
 
 
-
     public static JSONObject createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, Long sa_cashbillid_rebate) throws YosException {
         ArrayList<String> sqlList = new ArrayList<>();
         long sa_cashbillid = controller.createTableID("sa_cashbill");
@@ -388,20 +390,17 @@ public class Accountbalance extends BaseClass {
             sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
 
             // 审核逻辑判断
-            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
-                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
-                            + controller.siteid + "'");
+            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
             if (rowsaccountbalance.isEmpty()) {
                 throw new YosException(false, "该营销账户不存在,支出凭证无法审核");
             } else {
                 BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1 ) {
+                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1) {
                     throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
                 BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='" + newdiscountamount + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
@@ -434,9 +433,7 @@ public class Accountbalance extends BaseClass {
      * @param ischeck           是否审核
      * @throws YosException
      */
-    public static void createCashbillIncomeWithoutSQL(Controller controller, long sys_enterpriseid, long sa_accountclassid,
-                                                      CashbillEntity cashbillEntity,
-                                                      boolean ischeck, boolean isupdatek3flag) throws YosException {
+    public static void createCashbillIncomeWithoutSQL(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, boolean isupdatek3flag) throws YosException {
         JSONObject jsonObject = createCashbillIncome(controller, sys_enterpriseid, sa_accountclassid, cashbillEntity, ischeck, isupdatek3flag);
         controller.dbConnect.runSqlUpdate(new ArrayList<>(jsonObject.getJSONArray("sqlList").toJavaList(String.class)));
 
@@ -456,9 +453,7 @@ public class Accountbalance extends BaseClass {
      * @param ischeck           是否审核
      * @throws YosException
      */
-    public static void createCashbillPayWithoutSQL(Controller controller, long sys_enterpriseid, long sa_accountclassid,
-                                                   CashbillEntity cashbillEntity,
-                                                   boolean ischeck) throws YosException {
+    public static void createCashbillPayWithoutSQL(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck) throws YosException {
         JSONObject jsonObject = createCashbillPay(controller, sys_enterpriseid, sa_accountclassid, cashbillEntity, ischeck);
         controller.dbConnect.runSqlUpdate(new ArrayList<>(jsonObject.getJSONArray("sqlList").toJavaList(String.class)));
 
@@ -518,6 +513,19 @@ public class Accountbalance extends BaseClass {
         remind.createSys_message();
     }
 
+    public void sendMsg(DBConnect dbConnect, UserInfo userInfo, String content, Long sa_orderid, Long sys_enterpriseid) throws YosException {
+
+        ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid, userInfo.getSiteId()).toArrayList("userid", new ArrayList<>());
+        Remind remind = new Remind(userInfo.getSiteId());
+        remind.setTitle("凭证消息");
+        remind.setContent(content);
+        remind.setType("应用");
+        remind.setObjectid(sa_orderid);
+        remind.setObjectname("sa_order");
+        remind.setTouserid(userList);
+        remind.createSys_message();
+    }
+
     public void sendMsg(String siteid, String content, Long sa_orderid, Long sys_enterpriseid) throws YosException {
 
         ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid, siteid).toArrayList("userid", new ArrayList<>());

+ 0 - 1
src/custom/beans/accountbalance/SQL/账户余额查询.sql

@@ -11,4 +11,3 @@ FROM sa_accountclass t1
          LEFT JOIN sa_accountbalance t2 ON t1.sa_accountclassid = t2.sa_accountclassid
     AND t1.siteid = t2.siteid and t2.sys_enterpriseid = $sys_enterpriseid$
 WHERE t1.sa_accountclassid = $sa_accountclassid$
-  and t1.siteid = $siteid$

+ 8 - 544
src/custom/beans/stockbill/Stockbill.java

@@ -1,560 +1,24 @@
 package beans.stockbill;
 
-import beans.accountbalance.Accountbalance;
-import beans.accountbalance.CashbillEntity;
-import beans.datacontrllog.DataContrlLog;
-import beans.invbal.Invbal;
-import beans.parameter.Parameter;
-import com.alibaba.fastjson.JSONObject;
+import beans.stockbill.bills.BasicBill;
 import common.BaseClass;
 import common.Controller;
+import common.UserInfo;
 import common.YosException;
-import common.data.*;
-import org.apache.commons.lang.StringUtils;
+import common.data.db.DBConnect;
+import org.apache.poi.ss.formula.functions.T;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 
 public class Stockbill extends BaseClass {
-    private static void checkValidate(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
-        Rows rows = controller.dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
-                + st_stockbillid + "' and  siteid='" + controller.siteid + "'");
-        Rows rowsdetail = controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
-                + st_stockbillid + "' and  t1.siteid='" + controller.siteid + "'");
-        String type=rows.get(0).getString("type");
-        String str="success";
-        if(type.equals("销售出库")){
-            if(ischeck){
-                str=xsckcheckValidate(controller,rows,rowsdetail);
-            }else{
-                str =unxsckcheckValidate(controller,rows,rowsdetail);
-            }
-        }else if (type.equals("外购入库")) {
 
-        } else if (type.equals("生产领料出库")) {
-
-        } else if (type.equals("委外领料出库")) {
-
-        } else if (type.equals("生产入库") || type.equals("委外入库")) {
-
-        } else if (type.equals("其他入库")) {
-
-        } else if (type.equals("返修入库")) {// 云链
-
-        } else if (type.equals("返修出库")) {// 云链
-
-        }
-        if(!str.equals("success")){
-            throw new YosException(str);
-        }
-    }
     public static ArrayList<String> getCheckSql(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
-        Rows rows = controller.dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
-                + st_stockbillid + "' and  siteid='" + controller.siteid + "'");
-        Rows rowsdetail = controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
-                + st_stockbillid + "' and  t1.siteid='" + controller.siteid + "'");
-        ArrayList<String> sqlList = new ArrayList<>();
-        String type=rows.get(0).getString("type");
-        boolean isinstock = isinstock(type,rows.get(0).getString("rb"),ischeck);
-        checkValidate(controller,st_stockbillid,ischeck);
-        if(type.equals("销售出库")){
-            if(ischeck){
-                sqlList.addAll(xsckcheck(controller,rows,rowsdetail,isinstock));
-            }else{
-                sqlList.addAll(unxsckcheck(controller,rows,rowsdetail,isinstock));
-            }
-
-        }else if (type.equals("外购入库")) {
-
-        } else if (type.equals("生产领料出库")) {
-
-        } else if (type.equals("委外领料出库")) {
-
-        } else if (type.equals("生产入库") || type.equals("委外入库")) {
-
-        } else if (type.equals("其他入库")) {
-
-        } else if (type.equals("返修入库")) {// 云链
-
-        } else if (type.equals("返修出库")) {// 云链
-
-        }
-        sqlList.addAll(updateIcinvbal(controller,isinstock,0,st_stockbillid));// 即时库存计算
-        if(ischeck){
-            SQLFactory sqlFactoryupdate = new SQLFactory(controller, "出入库单审核");
-            sqlFactoryupdate.addParameter("siteid", controller.siteid);
-            sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
-            sqlFactoryupdate.addParameter("checkby", controller.username);
-            sqlList.add(sqlFactoryupdate.getSQL());
-            sqlList.add(DataContrlLog.createLog(controller, "st_stockbill", st_stockbillid, "审核", "出入库单审核成功").getSQL());
-        }else{
-            SQLFactory sqlFactoryupdate = new SQLFactory(controller, "出入库单反审核");
-            sqlFactoryupdate.addParameter("siteid", controller.siteid);
-            sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
-            sqlFactoryupdate.addParameter("checkby", controller.username);
-            sqlList.add(sqlFactoryupdate.getSQL());
-            sqlList.add(DataContrlLog.createLog(controller, "st_stockbill", st_stockbillid, "反审核", "出入库单反审核成功").getSQL());
-        }
-        return sqlList;
+        BasicBill basicBill = BasicBill.getBill(controller, st_stockbillid);
+        basicBill.checkValidate(ischeck);
+        return basicBill.getCheckSql(ischeck);
     }
 
     public static void check(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
-        controller.dbConnect.runSqlUpdate(getCheckSql(controller,st_stockbillid,ischeck));
-    }
-
-
-    public static String xsckcheckValidate(Controller controller, Rows rows, Rows rowsdetail) throws YosException {
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-        if (rows.isEmpty()) {
-            return "该出入库单不存在";
-        } else {
-            if (!rows.get(0).getString("status").equals("新建")) {
-                return "单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非新建状态,无法审核";
-            }
-        }
-        for(Row row : rowsdetail){
-            if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
-                return "表体数量不能小于0";
-            }
-        }
-        if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
-            return "扣款金额需大于0";
-        }
-        if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
-            return "发货地不可为空";
-        }
-        if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
-            return "扣款金额与应扣金额不符,不能审核";
-        }
-        Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
-        if (accountbalancerows.isNotEmpty()) {
-            BigDecimal discountamount = accountbalancerows.get(0).getBigDecimal("discountamount");
-            if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(discountamount)>0) {
-                return "优惠金额不能大于可用优惠金额";
-            }
-        }else{
-            return "账户不存在";
-        }
-        ArrayList<String> sqlList = new ArrayList<>();
-//        Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
-//        RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
-
-        String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
-        if(rows.get(0).getBoolean("rb")){
-            if(rows.get(0).getString("type").equals("销售出库")){
-                if (order_paymentnode.equals("3")) {
-                    if (Accountbalance.judgeBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount"))) {
-//                        CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount"),rows.get(0).getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "审核时生成");
-//                        JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
-//                        sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
-                    } else {
-                        return "账户余额不足,还差" + Accountbalance.InsufficientBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!";
-                    }
-                }
-//                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
-//                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-//                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
-                Rows rowsjudge =controller.dbConnect.runSqlQuery("select * from (select sa_orderitemsid,sum(qty) qty from st_stockbill_items where st_stockbillid ='"+rows.get(0).getLong("st_stockbillid")+"' group by sa_orderitemsid) t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid where t1.qty>t2.undeliqty");
-                if(rowsjudge.isNotEmpty()){
-                    return "存在商品已完全出库,无法审核";
-                }
-//                for (Row row : rowsDispatchDetailGroup) {
-//                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").subtract(row.getBigDecimal("qty")) + ",deliedqty=" + (row.getBigDecimal("qty").add(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
-//                }
-//                for(Row row :rowsdetail){
-//                    if(row.getBoolean("skucontrol")){
-//                        sqlList.add("update st_stockbill_items set wmsuploadflag2=1 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
-//                    }
-//
-//                }
-            }
-//            for(Row row :rowsdetail){
-//                String itemid= row.getString("itemid");
-//                long stockid=row.getLong("stockid");
-//                if(stockRowsMap.containsKey(itemid)){
-//                    for(Row row1 :stockRowsMap.get(itemid)){
-//                        if(row1.getLong("stockid")==stockid){
-//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
-//                        }
-//                    }
-//                }
-//                // String batchno = row.getString("batchno");
-//            }
-        }else{
-//            for(Row row :rowsdetail){
-//                String itemid= row.getString("itemid");
-//                long stockid=row.getLong("stockid");
-//                if(stockRowsMap.containsKey(itemid)){
-//                    for(Row row1 :stockRowsMap.get(itemid)){
-//                        if(row1.getLong("stockid")==stockid){
-//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
-//                        }
-//                    }
-//                }
-//                // String batchno = row.getString("batchno");
-//            }
-        }
-//            Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
-//            Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
-//            RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
-
-//        sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
-//
-//        dbConnect.runSqlUpdate(sqlList);
-//        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
-        return "success";
-
-    }
-
-    public static String unxsckcheckValidate(Controller controller,Rows rows,Rows rowsdetail) throws YosException {
-
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-
-        if (rows.isEmpty()) {
-            return "该出入库单不存在";
-        } else {
-            if (!rows.get(0).getString("status").equals("审核")) {
-                return "单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非审核状态,无法反审核";
-            }
-        }
-        for(Row row : rowsdetail){
-            if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
-                return "表体数量不能小于0";
-            }
-        }
-        if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(BigDecimal.ZERO)<0) {
-            return "优惠金额不能小于0";
-        }
-        if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
-            return "扣款金额需大于0";
-        }
-        if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
-            return "发货地不可为空";
-        }
-        if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
-            return "扣款金额与应扣金额不符,不能反审核";
-        }
-        Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
-        if (accountbalancerows.isEmpty()) {
-            return "账户不存在";
-        }
-        if (rows.get(0).getString("type").equals("销售出库") && rows.get(0).getBoolean("isreceiver")) {
-            return "经销商已经确认收货,不可进行反审核";
-        }
-//        Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
-//        RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
-
-        String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
-        if(rows.get(0).getBoolean("rb")){
-            if(rows.get(0).getString("type").equals("销售出库")){
-                if (order_paymentnode.equals("3")) {
-                    if (Accountbalance.judgeBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount").negate())) {
-//                        CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount").negate(),rows.get(0).getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单反审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "反审核时生成");
-//                        JSONObject createCashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
-//                        sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
-                    } else {
-                        return "账户余额不足,还差" + Accountbalance.InsufficientBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!";
-                    }
-                }
-//                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
-//                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-//                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
-//                for (Row row : rowsDispatchDetailGroup) {
-//                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
-//                }
-//                for(Row row :rowsdetail){
-//                    if(row.getBoolean("skucontrol")){
-//                        sqlList.add("update st_stockbill_items set wmsuploadflag2=0 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
-//                    }
-//
-//                }
-            }
-//            for(Row row :rowsdetail){
-//                String itemid= row.getString("itemid");
-//                long stockid=row.getLong("stockid");
-//                if(stockRowsMap.containsKey(itemid)){
-//                    for(Row row1 :stockRowsMap.get(itemid)){
-//                        if(row1.getLong("stockid")==stockid){
-//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
-//                        }
-//                    }
-//                }
-//                // String batchno = row.getString("batchno");
-//            }
-        }else{
-//            for(Row row :rowsdetail){
-//                String itemid= row.getString("itemid");
-//                long stockid=row.getLong("stockid");
-//                if(stockRowsMap.containsKey(itemid)){
-//                    for(Row row1 :stockRowsMap.get(itemid)){
-//                        if(row1.getLong("stockid")==stockid){
-//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
-//                        }
-//                    }
-//                }
-//                // String batchno = row.getString("batchno");
-//            }
-        }
-//            Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
-//            Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
-//            RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
-//        sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
-//        dbConnect.runSqlUpdate(sqlList);
-
-//        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
-        return "success";
-    }
-
-    public static ArrayList<String> xsckcheck(Controller controller,Rows rows,Rows rowsdetail,boolean isinstock) throws YosException {
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-
-        Rows accountbalancerows =controller.dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
-        ArrayList<String> sqlList = new ArrayList<>();
-        String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
-        if(rows.get(0).getBoolean("rb")){
-            if(rows.get(0).getString("type").equals("销售出库")){
-                if (order_paymentnode.equals("3")) {
-                    CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount"),rows.get(0).getBigDecimal("paydiscountamount"), rows.get(0).getLong("st_stockbillid"), "销售出库单审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "审核时生成");
-                    JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
-                    sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
-                }
-                Rows rowsOrderDetail = controller.dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + ")");
-                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-                Rows rowsDispatchDetailGroup = controller.dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + " group by t1.sa_orderitemsid,t1.siteid");
-                for (Row row : rowsDispatchDetailGroup) {
-                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").subtract(row.getBigDecimal("qty")) + ",deliedqty=" + (row.getBigDecimal("qty").add(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
-                }
-                for(Row row :rowsdetail){
-                    if(row.getBoolean("skucontrol")){
-                        sqlList.add("update st_stockbill_items set wmsuploadflag2=1 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
-                    }
-
-                }
-            }
-        }else{
-//            for(Row row :rowsdetail){
-//                String itemid= row.getString("itemid");
-//                long stockid=row.getLong("stockid");
-//                if(stockRowsMap.containsKey(itemid)){
-//                    for(Row row1 :stockRowsMap.get(itemid)){
-//                        if(row1.getLong("stockid")==stockid){
-//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
-//                        }
-//                    }
-//                }
-//                // String batchno = row.getString("batchno");
-//            }
-        }
-        sqlList.addAll(updateAccountbalance_freez(controller,rows.get(0).getLong("st_stockbillid"),isinstock));
-
-        return sqlList;
-    }
-
-    public static  ArrayList<String> unxsckcheck(Controller controller,Rows rows,Rows rowsdetail,boolean isinstock) throws YosException {
-
-
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-
-        Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
-        ArrayList<String> sqlList = new ArrayList<>();
-        String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
-        if(rows.get(0).getBoolean("rb")){
-            if(rows.get(0).getString("type").equals("销售出库")){
-                if (order_paymentnode.equals("3")) {
-                    CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount").negate(),rows.get(0).getBigDecimal("paydiscountamount").negate(), rows.get(0).getLong("st_stockbillid"), "销售出库单反审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "反审核时生成");
-                    JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
-                    sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
-                }
-                Rows rowsOrderDetail = controller.dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + ")");
-                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-                Rows rowsDispatchDetailGroup = controller.dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + " group by t1.sa_orderitemsid,t1.siteid");
-                for (Row row : rowsDispatchDetailGroup) {
-                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
-                }
-                for(Row row :rowsdetail){
-                    if(row.getBoolean("skucontrol")){
-                        sqlList.add("update st_stockbill_items set wmsuploadflag2=0 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
-                    }
-
-                }
-            }
-        }else{
-
-        }
-
-        sqlList.addAll(updateAccountbalance_freez(controller,rows.get(0).getLong("st_stockbillid"),isinstock));
-        return sqlList;
-    }
-
-
-
-    public static boolean isinstock(String type,String rb,boolean fischeck){
-        if (type.equals("其他出库") || type.equals("销售出库")
-                || type.equals("生产领料出库") || type.equals("委外领料出库")
-                || type.equals("返修出库")) {
-            if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
-                return false;
-            } else {
-                return true;
-            }
-
-        } else if (type.equals("其他入库") || type.equals("外购入库")
-                || type.equals("生产入库") || type.equals("委外入库")
-                || type.equals("返修入库")) {
-            if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
-                return true;
-            } else {
-                return false;
-            }
-        }
-        return false;
-    }
-
-    public static CashbillEntity getCashbillEntity(BigDecimal amount,BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks) throws YosException {
-        CashbillEntity entity = new CashbillEntity();
-        entity.setAmount(amount);
-        entity.setDiscountamountamount(discountamount);
-        entity.setOwnerid(ownerid);
-        entity.setOwnertable("st_stockbill");
-        entity.setSource(source);
-        entity.setRemarks(remarks);
-        entity.setSourcenote(sourcenotes);
-        return entity;
-
-    }
-
-
-    /**
-     * @param isinstock 是否增加库存
-     * @param type      库存更新类型 0为默认形式。1表示生产领料更新现场仓 2表示委外领料更新现场仓
-     * @throws YosException
-     */
-    public static ArrayList<String> updateIcinvbal(Controller controller,boolean isinstock, int type,Long st_stockbillid) throws YosException {
-        ArrayList<String> sqlList =new ArrayList();
-        Rows icstockbilldetail =controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
-                + st_stockbillid + "' and  t1.siteid='" + controller.siteid + "'");// 出入库表体
-        ArrayList<Long> itemids = new ArrayList<Long>();
-        itemids = icstockbilldetail.toArrayList("itemid",new ArrayList<>());
-        itemids.add((long) 0);
-        int i = 0;
-        String sql="select * from st_invbal where itemid in"+itemids;
-        sql = sql.replace("[", "(").replace("]", ")");
-        Rows invbals =  controller.dbConnect.runSqlQuery(sql);
-        RowsMap invbalsRowsMap=invbals.toRowsMap("itemid");
-        for(Row row : icstockbilldetail){
-            String itemid = row.getString("itemid");
-            //String batchno = row.getString("batchno");
-            //String fdcspno = row.getString("fdcspno");
-            String stockid = row.getString("stockid");
-
-//             if (type == 1 && !getSysVars().getBoolean("FISBATCHFORXC")) {
-//                 fdcspno = "**********";
-//                 fbatchno = "**********";
-//                 fstockno = getPaoSet("TDEPARTMENT").getPao(0)
-//                         .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
-//                 icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
-//                         "fitemno='" + fitemno + "' and fstockno='" + fstockno
-//                                 + "' and fdcspno='" + fdcspno
-//                                 + "' and fbatchno='" + fbatchno + "'");
-//             } else if (type == 2 && !getSysVars().getBoolean("FISBATCHFORXC")) {
-//                 fdcspno = "**********";
-//                 fbatchno = "**********";
-//                 fstockno = getPaoSet("TSUPPLIER").getPao(0)
-//                         .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
-//                 icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
-//                         "fitemno='" + fitemno + "' and fstockno='" + fstockno
-//                                 + "' and fdcspno='" + fdcspno
-//                                 + "' and fbatchno='" + fbatchno + "'");
-//             }
-            BigDecimal qty = isinstock ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
-            if(!invbalsRowsMap.containsKey(itemid)){
-                SQLFactory sqlFactory = new SQLFactory(controller, "即时库存新增");
-                sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
-                sqlFactory.addParameter("qty", qty);
-                sqlFactory.addParameter("itemid", itemid);
-                sqlFactory.addParameter("stockid", stockid);
-                sqlFactory.addParameter("siteid",controller.siteid);
-                sqlFactory.addParameter("userid", controller.userid);
-                sqlFactory.addParameter("username", controller.username);
-                sqlList.add(sqlFactory.getSQL());
-            }else{
-                if(invbalsRowsMap.get(itemid).toRowsMap("stockid").containsKey(stockid)){
-                    SQLFactory sqlFactory = new SQLFactory(controller, "即时库存更新");
-                    sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
-                    sqlFactory.addParameter("qty", invbalsRowsMap.get(itemid).toRowsMap("stockid").get(stockid).get(0).getBigDecimal("qty").add(qty));
-                    sqlFactory.addParameter("itemid", itemid);
-                    sqlFactory.addParameter("stockid", stockid);
-                    sqlFactory.addParameter("siteid",controller.siteid);
-                    sqlFactory.addParameter("userid", controller.userid);
-                    sqlFactory.addParameter("username", controller.username);
-                    sqlList.add(sqlFactory.getSQL());
-                }else{
-                    SQLFactory sqlFactory = new SQLFactory(new Invbal(), "即时库存新增");
-                    sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
-                    sqlFactory.addParameter("qty", qty);
-                    sqlFactory.addParameter("itemid", itemid);
-                    sqlFactory.addParameter("stockid", stockid);
-                    sqlFactory.addParameter("siteid",controller.siteid);
-                    sqlFactory.addParameter("userid", controller.userid);
-                    sqlFactory.addParameter("username", controller.username);
-                    sqlList.add(sqlFactory.getSQL());
-                }
-            }
-        }
-        return sqlList;
-    }
-
-    /**
-     * 账户余额冻结
-     * @param addorsub
-     */
-    public static ArrayList<String> updateAccountbalance_freez(Controller controller,long st_stockbillid,boolean addorsub) throws YosException {
-        ArrayList<String> sqllist= new ArrayList<>();
-        /******** 冻结数据 ********/
-        Rows rows = controller.dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,ROUND(sum(t1.qty*t2.price*ifnull(t2.pricerate,1)*ifnull(t2.rwpricerate,1)), 2) amount from st_stockbill_items t1 \n" +
-                "                   inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid\n" +
-                "                  inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid\n" +
-                "\t\t\t\t\t\t\t\t\tleft join sa_accountbalance t4 on t4.sa_accountclassid=t3.sa_accountclassid and t4.sys_enterpriseid=t3.sys_enterpriseid and t4.siteid=t3.siteid\n" +
-                "                where t1.st_stockbillid="+st_stockbillid+" group by t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum");
-        if (addorsub) {
-            for(Row row :rows) {
-                String sonum = row.getString("sonum");
-                long sa_orderid = row.getLong("sa_orderid");
-                long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
-                BigDecimal amount = row.getBigDecimal("amount");
-                Rows accountbalancefreezrows = controller.dbConnect.runSqlQuery("select sa_accountbalance_freezid from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + controller.siteid + "'");
-
-                sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)+" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid + " and siteid='" + controller.siteid + "'");
-
-                if (accountbalancefreezrows.isNotEmpty()) {
-                    sqllist.add("update sa_accountbalance_freez set amount=amount+" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
-                } else {
-                    long sa_accountbalance_freezid = controller.createTableID("sa_accountbalance_freez");
-                    InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sa_accountbalance_freez");
-                    insertSQL.setUniqueid(sa_accountbalance_freezid);
-                    insertSQL.setSiteid(controller.siteid);
-                    insertSQL.setValue("sa_accountbalanceid", sa_accountbalanceid);
-                    insertSQL.setValue("sourcetable", "sa_order");
-                    insertSQL.setValue("sourceid", sa_orderid);
-                    insertSQL.setValue("amount", amount);
-                    insertSQL.setValue("remarks", "由销售订单" + sonum + "审核时冻结");
-                    insertSQL.setValue("createby", controller.username);
-                    insertSQL.setDateValue("createdate");
-                    sqllist.add(insertSQL.getSQL());
-                }
-            }
-        } else {
-            for(Row row : rows){
-                long sa_orderid = row.getLong("sa_orderid");
-                long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
-                BigDecimal amount = row.getBigDecimal("amount");
-                Rows accountbalancefreezrows = controller.dbConnect.runSqlQuery("select sa_accountbalance_freezid,amount from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + controller.siteid + "'");
-                if (accountbalancefreezrows.size() > 0) {
-                    sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-"+amount+" where sa_accountbalanceid="+sa_accountbalanceid);
-                    sqllist.add("update sa_accountbalance_freez set amount=amount-"+amount+" where sa_accountbalance_freezid="+accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
-                }
-            }
-        }
-        return sqllist;
+        controller.dbConnect.runSqlUpdate(getCheckSql(controller, st_stockbillid, ischeck));
     }
 }

+ 223 - 0
src/custom/beans/stockbill/bills/BasicBill.java

@@ -0,0 +1,223 @@
+package beans.stockbill.bills;
+
+import common.Controller;
+import common.UserInfo;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+public abstract class BasicBill {
+    Controller controller;
+    DBConnect dbConnect;
+    UserInfo userInfo;
+    long st_stockbillid;
+    boolean issale;//是否销售出库
+    String billType;//单据类型
+    String billTypeMX;//单据类型
+    String billno;
+    String siteid;
+    String status;
+    int rb;
+    Row billRow;
+    Rows itemRows;
+    Rows codeRows;
+
+    public static BasicBill getBill(Controller controller, long st_stockbillid) throws YosException {
+        Rows billRows = controller.dbConnect.runSqlQuery("select type from st_stockbill where st_stockbillid ='" + st_stockbillid + "'");
+        if (billRows.isEmpty()) {
+            throw new YosException("该出入库单不存在");
+        }
+        String type = billRows.get(0).getString("type");
+        switch (type) {
+            case "销售出库":
+                return new XSCK(controller, st_stockbillid);
+            case "返修出库":
+            case "生产领料出库":
+            case "委外领料出库":
+            case "其他出库":
+                return new QTCK(controller, st_stockbillid);
+            case "外购入库":
+            case "生产入库":
+            case "委外入库":
+            case "返修入库":
+            case "其他入库":
+                return new QTRK(controller, st_stockbillid);
+            default: {
+                throw new YosException("不支持的出入库单类型");
+            }
+        }
+    }
+
+    /**
+     * 构造函数
+     *
+     * @param controller
+     * @param st_stockbillid 出入库单ID
+     * @throws YosException
+     */
+    public BasicBill(Controller controller, long st_stockbillid) throws YosException {
+        this.controller = controller;
+        this.dbConnect = this.controller.dbConnect;
+        this.userInfo = controller.userInfo;
+        this.st_stockbillid = st_stockbillid;
+        queryBills();
+    }
+
+    /**
+     * 单据审核校验
+     *
+     * @param ischeck
+     * @throws YosException
+     */
+    public void checkValidate(boolean ischeck) throws YosException {
+        /*
+        通用校验
+         */
+        if (ischeck) {
+            if (!status.equals("新建")) {
+                throw new YosException("单号为:【" + billno + "】的出入库单为非新建状态,无法审核");
+            }
+            if (itemRows.isEmpty()) {
+                throw new YosException("表体为空");
+            }
+            if (itemRows.min("qty").doubleValue() < 0) {
+                throw new YosException("表体数量不能小于0");
+            }
+        } else {
+            if (!status.equals("审核")) {
+                throw new YosException("单号为:【" + billno + "】的出入库单为非审核状态,无法反审核");
+            }
+        }
+    }
+
+    public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        sqlList.addAll(updateInvbal(ischeck));//更新库存
+        sqlList.addAll(updateMCode(ischeck));//更新序列号
+        return sqlList;
+    }
+
+    /**
+     * 更新库存
+     *
+     * @param ischeck
+     * @return
+     * @throws YosException
+     */
+
+    private ArrayList<String> updateInvbal(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid", itemRows.toArrayList("itemid")).query().toRowsMap("itemid");
+        RowsMap invbalsSaleRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal_sale").setWhere("siteid", siteid).setWhere("itemid", itemRows.toArrayList("itemid")).query().toRowsMap("itemid");
+        for (Row row : itemRows) {
+            long itemid = row.getLong("itemid");
+            long stockid = row.getLong("stockid");
+            BigDecimal qty = isInStock(ischeck) ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
+            if (!invbalsRowsMap.containsKey(String.valueOf(itemid)) || !invbalsRowsMap.get(String.valueOf(itemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
+                InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "st_invbal");
+                invbalInsert.setValue("siteid", siteid);
+                invbalInsert.setValue("stockid", stockid);
+                invbalInsert.setValue("itemid", itemid);
+                invbalInsert.setValue("qty", qty.doubleValue());
+                sqlList.add(invbalInsert.getSQL());
+            } else {
+                UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "st_invbal");
+                invbalUpdate.addValue("qty", qty);
+                invbalUpdate.setWhere("itemid", itemid);
+                invbalUpdate.setWhere("stockid", stockid);
+                invbalUpdate.setWhere("siteid", siteid);
+                sqlList.add(invbalUpdate.getSQL());
+            }
+            //是否为销售仓库
+            if (SQLFactory.getRow(controller, "st_stock", stockid).getBoolean("issalestock")) {
+                if (!invbalsSaleRowsMap.containsKey(String.valueOf(itemid))) {
+                    InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "st_invbal_sale");
+                    invbalInsert.setValue("siteid", siteid);
+                    invbalInsert.setValue("itemid", itemid);
+                    if (!issale) {
+                        invbalInsert.setValue("cansaleqty", qty.doubleValue());//可销售数量
+                        invbalInsert.setValue("candispatchqty", qty.doubleValue());//可发货数量
+                    }
+                    invbalInsert.setValue("qty", qty.doubleValue());//库存数量
+                    sqlList.add(invbalInsert.getSQL());
+                } else {
+                    UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "st_invbal_sale");
+                    if (!issale) {
+                        invbalUpdate.addValue("cansaleqty", qty.doubleValue());//可销售数量
+                        invbalUpdate.addValue("candispatchqty", qty.doubleValue());//可发货数量
+                    }
+                    invbalUpdate.addValue("qty", qty.doubleValue());//库存数量
+                    invbalUpdate.setWhere("itemid", itemid);
+                    invbalUpdate.setWhere("siteid", siteid);
+                    sqlList.add(invbalUpdate.getSQL());
+                }
+            }
+        }
+        return sqlList;
+    }
+
+    /**
+     * 更新序列号
+     *
+     * @param ischeck
+     * @return
+     * @throws YosException
+     */
+    public ArrayList<String> updateMCode(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        for (Row row : codeRows) {
+            long itemid = row.getLong("itemid");
+            long stockid = row.getLong("stockid");
+            String sku = row.getString("sku");
+            UpdateSQL saItemsku = SQLFactory.createUpdateSQL(controller, "sa_itemsku");
+            if (isInStock(ischeck)) {
+                saItemsku.setValue("stockid", stockid);
+                saItemsku.setValue("status", "在库");
+                if (issale) {
+                    saItemsku.setValue("sys_enterpriseid", null);
+                }
+            } else {
+                saItemsku.setValue("stockid", "");
+                if (issale) {
+                    saItemsku.setValue("status", "售出");
+                    saItemsku.setValue("sys_enterpriseid", billRow.getLong("sys_enterpriseid"));
+                }
+            }
+            saItemsku.setWhere("itemid", itemid);
+            saItemsku.setWhere("sku", sku);
+
+            sqlList.add(saItemsku.getSQL());
+        }
+        return sqlList;
+    }
+
+    /**
+     * 单据查询
+     *
+     * @throws YosException
+     */
+    private void queryBills() throws YosException {
+        Rows billRows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='" + st_stockbillid + "'");
+        if (billRows.isNotEmpty()) {
+            billRow = billRows.get(0);
+        } else {
+            throw new YosException("该出入库单不存在");
+        }
+        this.billno = billRow.getString("billno");
+        this.issale = billRow.getString("type").equals("销售出库");
+        this.billType = billRow.getString("type");
+        this.billTypeMX = billRow.getString("typemx");
+        this.rb = billRow.getInteger("rb");
+        this.siteid = billRow.getString("siteid");
+        this.status = billRow.getString("status");
+        itemRows = dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='" + st_stockbillid + "'");
+        codeRows = dbConnect.runSqlQuery("select t1.* from st_stockbill_items_sku  where t1.st_stockbillid ='" + st_stockbillid + "'");
+    }
+
+
+    public abstract boolean isInStock(boolean fischeck);
+
+}

+ 41 - 0
src/custom/beans/stockbill/bills/QTCK.java

@@ -0,0 +1,41 @@
+package beans.stockbill.bills;
+
+import beans.accountbalance.Accountbalance;
+import beans.accountbalance.CashbillEntity;
+import beans.parameter.Parameter;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.data.*;
+import org.apache.commons.lang.StringUtils;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+public class QTCK extends BasicBill {
+    long sys_enterpriseid;
+
+    public QTCK(Controller controller, long st_stockbillid) throws YosException {
+        super(controller, st_stockbillid);
+        sys_enterpriseid = billRow.getLong("sys_enterpriseid");
+    }
+
+    @Override
+    public void checkValidate(boolean ischeck) throws YosException {
+        super.checkValidate(ischeck);
+
+    }
+
+    @Override
+    public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
+        return super.getCheckSql(ischeck);
+    }
+
+    @Override
+    public boolean isInStock(boolean fischeck) {
+        if (fischeck && rb == 0 || !fischeck && rb == 1) {
+            return true;
+        }
+        return false;
+    }
+}

+ 32 - 0
src/custom/beans/stockbill/bills/QTRK.java

@@ -0,0 +1,32 @@
+package beans.stockbill.bills;
+
+import common.Controller;
+import common.YosException;
+
+import java.util.ArrayList;
+
+public class QTRK extends BasicBill {
+
+    public QTRK(Controller controller, long st_stockbillid) throws YosException {
+        super(controller, st_stockbillid);
+    }
+
+    @Override
+    public void checkValidate(boolean ischeck) throws YosException {
+        super.checkValidate(ischeck);
+    }
+
+    @Override
+    public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
+        return super.getCheckSql(ischeck);
+    }
+
+
+    @Override
+    public boolean isInStock(boolean fischeck) {
+        if (fischeck && rb == 1 || !fischeck && rb == 0) {
+            return true;
+        }
+        return false;
+    }
+}

+ 216 - 0
src/custom/beans/stockbill/bills/XSCK.java

@@ -0,0 +1,216 @@
+package beans.stockbill.bills;
+
+import beans.accountbalance.Accountbalance;
+import beans.accountbalance.CashbillEntity;
+import beans.parameter.Parameter;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.data.*;
+import org.apache.commons.lang.StringUtils;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+public class XSCK extends BasicBill {
+    long sys_enterpriseid;
+
+    public XSCK(Controller controller, long st_stockbillid) throws YosException {
+        super(controller, st_stockbillid);
+        sys_enterpriseid = billRow.getLong("sys_enterpriseid");
+    }
+
+    @Override
+    public void checkValidate(boolean ischeck) throws YosException {
+        super.checkValidate(ischeck);
+
+        Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
+        if (accountbalancerows.isEmpty()) {
+            throw new YosException("账户不存在");
+        }
+        String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
+        if (ischeck) {
+            if (itemRows.min("payamount").doubleValue() < 0) {
+                throw new YosException("扣款金额需大于0");
+            }
+            if (StringUtils.isBlank(billRow.getString("outplace"))) {
+                throw new YosException("发货地不可为空");
+            }
+            if ((billRow.getBigDecimal("payamount").add(billRow.getBigDecimal("paydiscountamount"))).compareTo(itemRows.sum("amount")) != 0) {
+                throw new YosException("扣款金额与应扣金额不符,不能审核");
+            }
+            BigDecimal discountamount = accountbalancerows.get(0).getBigDecimal("discountamount");
+            if (billRow.getBigDecimal("paydiscountamount").compareTo(discountamount) > 0) {
+                throw new YosException("优惠金额不能大于可用优惠金额");
+            }
+            /*
+              库存校验
+             */
+            /*
+            其他校验
+             */
+        } else {
+            if (billRow.getBoolean("isreceiver")) {
+                throw new YosException("经销商已经确认收货,不可进行反审核");
+            }
+            /*
+              库存校验
+             */
+             /*
+            其他校验
+             */
+        }
+        if ((ischeck && rb == 1) || (!ischeck && rb == 0)) {
+            if (order_paymentnode.equals("3") && !Accountbalance.judgeBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.sum("amount"))) {
+                throw new YosException("账户余额不足,还差" + Accountbalance.InsufficientBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.sum("amount")) + "元!");
+            }
+            Rows rowsjudge = dbConnect.runSqlQuery("select * from (select sa_orderitemsid,sum(qty) qty from st_stockbill_items where st_stockbillid ='" + st_stockbillid + "' group by sa_orderitemsid) t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid where t1.qty>t2.undeliqty");
+            if (rowsjudge.isNotEmpty()) {
+                throw new YosException("存在商品已完全出库,无法反审核");
+            }
+        }
+    }
+
+    @Override
+    public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = super.getCheckSql(ischeck);
+        if (ischeck) {
+            Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
+
+            String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
+            if (rb == 1) {
+                if (order_paymentnode.equals("3")) {
+                    CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount"), billRow.getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成");
+                    JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
+                    sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                }
+                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
+                for (Row row : rowsDispatchDetailGroup) {
+                    sqlList.add("update sa_orderitems set undeliqty=undeliqty-" + row.getDouble("qty") + ",deliedqty=deliedqty+" + row.getDouble("qty") + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
+                }
+                for (Row row : itemRows) {
+                    if (row.getRow("plm_item", "itemid=:itemid").getBoolean("skucontrol")) {
+                        sqlList.add("update st_stockbill_items set wmsuploadflag2=1 where st_stockbill_itemsid=" + row.getLong("st_stockbill_itemsid"));
+                    }
+                }
+            } else {
+//            for(Row row :rowsdetail){
+//                String itemid= row.getString("itemid");
+//                long stockid=row.getLong("stockid");
+//                if(stockRowsMap.containsKey(itemid)){
+//                    for(Row row1 :stockRowsMap.get(itemid)){
+//                        if(row1.getLong("stockid")==stockid){
+//                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
+//                        }
+//                    }
+//                }
+//                // String batchno = row.getString("batchno");
+//            }
+            }
+            sqlList.addAll(updateAccountbalance_freez(isInStock(ischeck)));
+
+        } else {
+            Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
+            String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
+            if (rb == 1) {
+                if (order_paymentnode.equals("3")) {
+                    CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount").negate(), billRow.getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成");
+                    JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
+                    sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                }
+                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
+                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
+                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
+                for (Row row : rowsDispatchDetailGroup) {
+                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
+                }
+                for (Row row : itemRows) {
+                    if (row.getRow("plm_item", "itemid=:itemid").getBoolean("skucontrol")) {
+                        sqlList.add("update st_stockbill_items set wmsuploadflag2=0 where st_stockbill_itemsid=" + row.getLong("st_stockbill_itemsid"));
+                    }
+                }
+            } else {
+
+            }
+            sqlList.addAll(updateAccountbalance_freez(isInStock(ischeck)));
+        }
+        return sqlList;
+    }
+
+
+    /**
+     * 账户余额冻结
+     *
+     * @param addorsub
+     */
+    public ArrayList<String> updateAccountbalance_freez(boolean addorsub) throws YosException {
+        ArrayList<String> sqllist = new ArrayList<>();
+        /******** 冻结数据 ********/
+        Rows rows = dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,ROUND(sum(t1.qty*t2.price*ifnull(t2.pricerate,1)*ifnull(t2.rwpricerate,1)), 2) amount from st_stockbill_items t1 \n" +
+                "                   inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid\n" +
+                "                  inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid\n" +
+                "\t\t\t\t\t\t\t\t\tleft join sa_accountbalance t4 on t4.sa_accountclassid=t3.sa_accountclassid and t4.sys_enterpriseid=t3.sys_enterpriseid and t4.siteid=t3.siteid\n" +
+                "                where t1.st_stockbillid=" + st_stockbillid + " group by t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum");
+        if (addorsub) {
+            for (Row row : rows) {
+                String sonum = row.getString("sonum");
+                long sa_orderid = row.getLong("sa_orderid");
+                long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
+                BigDecimal amount = row.getBigDecimal("amount");
+                Rows accountbalancefreezrows = dbConnect.runSqlQuery("select sa_accountbalance_freezid from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + siteid + "'");
+
+                sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)+" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid + " and siteid='" + siteid + "'");
+
+                if (accountbalancefreezrows.isNotEmpty()) {
+                    sqllist.add("update sa_accountbalance_freez set amount=amount+" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
+                } else {
+
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(dbConnect, "sa_accountbalance_freez");
+                    insertSQL.setSiteid(siteid);
+                    insertSQL.setValue("sa_accountbalanceid", sa_accountbalanceid);
+                    insertSQL.setValue("sourcetable", "sa_order");
+                    insertSQL.setValue("sourceid", sa_orderid);
+                    insertSQL.setValue("amount", amount);
+                    insertSQL.setValue("remarks", "由销售订单" + sonum + "审核时冻结");
+                    insertSQL.setValue("createby", userInfo.getUserName());
+                    insertSQL.setDateValue("createdate");
+                    sqllist.add(insertSQL.getSQL());
+                }
+            }
+        } else {
+            for (Row row : rows) {
+                long sa_orderid = row.getLong("sa_orderid");
+                long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
+                BigDecimal amount = row.getBigDecimal("amount");
+                Rows accountbalancefreezrows = dbConnect.runSqlQuery("select sa_accountbalance_freezid,amount from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + siteid + "'");
+                if (accountbalancefreezrows.size() > 0) {
+                    sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid);
+                    sqllist.add("update sa_accountbalance_freez set amount=amount-" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
+                }
+            }
+        }
+        return sqllist;
+    }
+
+
+    public static CashbillEntity getCashbillEntity(BigDecimal amount, BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks) throws YosException {
+        CashbillEntity entity = new CashbillEntity();
+        entity.setAmount(amount);
+        entity.setDiscountamountamount(discountamount);
+        entity.setOwnerid(ownerid);
+        entity.setOwnertable("st_stockbill");
+        entity.setSource(source);
+        entity.setRemarks(remarks);
+        entity.setSourcenote(sourcenotes);
+        return entity;
+
+    }
+
+    @Override
+    public boolean isInStock(boolean fischeck) {
+        if (fischeck && rb == 0 || !fischeck && rb == 1) {
+            return true;
+        }
+        return false;
+    }
+}

+ 151 - 0
src/custom/beans/wms/Wms.java

@@ -0,0 +1,151 @@
+package beans.wms;
+
+import common.BaseClass;
+import common.Controller;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+
+import java.util.ArrayList;
+
+/**
+ * 立体仓库对接
+ */
+public class Wms {
+
+    /**
+     * 下达出库指令
+     *
+     * @param controller
+     * @param st_stockbill_itemsids 出库单表体ID
+     */
+    public static void sendOutOrder(Controller controller, ArrayList<Long> st_stockbill_itemsids) throws YosException {
+        sendOutOrder(controller, st_stockbill_itemsids.toArray(new Long[0]));
+    }
+
+    /**
+     * 下达出库指令
+     *
+     * @param controller
+     * @param st_stockbill_itemsid 出库单表体ID
+     */
+    public static void sendOutOrder(Controller controller, Long... st_stockbill_itemsid) throws YosException {
+        if (st_stockbill_itemsid.length > 0) {
+            QuerySQL stockbillitemsQuery = SQLFactory.createQuerySQL(controller, "st_stockbill_items");
+            stockbillitemsQuery.setWhere("st_stockbill_itemsid", st_stockbill_itemsid);
+            //出库商品明细
+            Rows stockbillitemsRows = stockbillitemsQuery.query();
+
+            //出库单明细
+            QuerySQL stockbillQuery = SQLFactory.createQuerySQL(controller, "st_stockbill");
+            stockbillQuery.setWhere("st_stockbillid", stockbillitemsRows.toArrayList("st_stockbillid"));
+            Rows stockbillRows = stockbillQuery.query();
+            ArrayList<String> outplaceList = stockbillRows.toArrayList("outplace");
+            for (String outplace : outplaceList) {
+                if (outplace.isEmpty()) {
+                    throw new YosException("发货地不可为空");
+                }
+            }
+            if (outplaceList.size() > 1) {
+                throw new YosException("不可同时选择两个发货地");
+            }
+            RowsMap stockbillitemsRowsMap = stockbillitemsRows.toRowsMap("st_stockbillid");
+
+
+            for (Row stockbillRow : stockbillRows) {
+                String outplace = stockbillRow.getString("outplace");
+                if (outplace.equals("谈桥")) {
+                    sendToTQ(controller, stockbillRow, stockbillitemsRowsMap.get(stockbillRow.getString("st_stockbillid")));
+                } else if (outplace.equals("马桥")) {
+                    sendToMQ(controller, stockbillRow, stockbillitemsRowsMap.get(stockbillRow.getString("st_stockbillid")));
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 谈桥立体仓库指令下发
+     *
+     * @param controller
+     * @param stockbillRow
+     * @param stockbillitemsRows
+     */
+    private static void sendToTQ(Controller controller, Row stockbillRow, Rows stockbillitemsRows) throws YosException {
+        String billno = stockbillRow.getString("billno");
+        String billdate = BaseClass.getDateTime_Str(stockbillRow.getDate("billdate"));
+        Row enterpriseRow = stockbillRow.getRow("sys_enterprise", "sys_enterpriseid=:sys_enterpriseid");
+        Row contactsRow = stockbillRow.getRow("sys_enterprise_contacts", "contactsid=:rec_contactsid");
+
+        DBConnect tqwms = new DBConnect("TQWMS");
+        String SQL = "";
+        SQL = "insert into TOutInt(BillNo,BillType,CreateDate,IsDeleted,OutDate,SellCompany,SellPerson,Selladdress,Sellphone,Status,createby,ShortName) ";
+        SQL = SQL + "values(";
+        SQL = SQL + "'" + billno + "',";// 出库单号
+        SQL = SQL + "'" + 1 + "',";// 出库类型,1:销售出库 2:调拨出库 3:送件单 4:借出
+        SQL = SQL + "GETDATE(),";// 创建日期
+        SQL = SQL + "0,";// 是否已删除
+        SQL = SQL + "'" + billdate + "',";// 出库日期,单据日期
+        SQL = SQL + "'" + enterpriseRow.getString("enterprisename") + "',";// 经销商名称
+        SQL = SQL + "'" + contactsRow.getString("name") + "',";// 经销商联系人
+        SQL = SQL + "'" + contactsRow.getString("address") + "',";// 经销商地址
+        SQL = SQL + "'" + contactsRow.getString("phonenumber") + "',";// 联系方式
+        SQL = SQL + "0,";// 状态:0:WMS未处理 1:WMS正在出库 2:WMS出库完成 10:ERP出库完成
+        SQL = SQL + "'" + controller.username + "',";
+        SQL = SQL + "'" + enterpriseRow.getString("abbreviation") + "')";// 经销商简称
+        tqwms.runSqlUpdate(SQL);
+        Rows rows = tqwms.runSqlQuery("select top(1) OutPlanID from TOutInt where BillNo='" + billno + "' order by CreateDate desc ");
+        long OutPlanID = rows.get(0).getLong("OutPlanID");
+
+        ArrayList<String> sqlist = new ArrayList<>();
+        for (Row stockbillitemsRow : stockbillitemsRows) {
+            SQL = "insert into TOutDetailInt(OutPlanID,BillNo,CreateDate,IsDeleted,OutDate,MaterialCode,PlanOutQuantity,OutQuantity,Status)";
+            SQL = SQL + " select ";
+            SQL = SQL + " '" + OutPlanID + "',";// 对应出库通知单主表ID
+            SQL = SQL + " '" + billno + "',";// 单据编号
+            SQL = SQL + " GETDATE(),";// 创建日期
+            SQL = SQL + " 0,";// 是否删除
+            SQL = SQL + " '" + billdate + "',";// 出库日期
+            SQL = SQL + " '" + stockbillitemsRow.getString("itemno") + "',";// 品号
+            SQL = SQL + " " + stockbillitemsRow.getString("qty") + ",";// 出库数量
+            SQL = SQL + " 0,";// 已出库数量
+            SQL = SQL + " 0";// 状态:0:WMS未处理 1:WMS正在出库 2:WMS出库完成 10:ERP出库完成
+            sqlist.add(SQL);
+        }
+        tqwms.runSqlUpdate(sqlist);
+        SQLFactory.createUpdateSQL(controller, "st_stockbill_items").setValue("wmsuploadflag", 2).setWhere("st_stockbill_itemsid", stockbillitemsRows.toArrayList("st_stockbill_itemsid"));
+    }
+
+    /**
+     * 马桥立体仓库出库
+     */
+    private static void sendToMQ(Controller controller, Row stockbillRow, Rows stockbillitemsRows) throws YosException {
+        DBConnect mqwms = new DBConnect("U8-YUNl_DB");
+        String billno = stockbillRow.getString("billno");
+        Row enterpriseRow = stockbillRow.getRow("sys_enterprise", "sys_enterpriseid=:sys_enterpriseid");
+        Row agentsRow = stockbillRow.getRow("sa_agents", "sys_enterpriseid=:sys_enterpriseid");
+        Row contactsRow = stockbillRow.getRow("sys_enterprise_contacts", "contactsid=:rec_contactsid");
+
+        ArrayList<String> sqlist = new ArrayList<>();
+        for (Row stockbillitemsRow : stockbillitemsRows) {
+            String SQL = "";
+            SQL = "insert into Wms_Rdrecord32(cCode,rowno,cInvCode,iQuantity,dDate,fagentnum,fagentname,fcontact,fphonenumber,faddress,WMSstatus)";
+            SQL = SQL + " select ";
+            SQL = SQL + " '" + billno + "',";// 单据编号
+            SQL = SQL + " '" + stockbillitemsRow.getInteger("rowno") + "',";// 行号
+            SQL = SQL + " '" + stockbillitemsRow.getString("itemno") + "',";// 品号
+            SQL = SQL + " " + stockbillitemsRow.getString("qty") + ",";// 出库数量
+            SQL = SQL + " GETDATE(),";// 创建日期
+            SQL = SQL + " '" + agentsRow.getString("agentnum") + "',";
+            SQL = SQL + " '" + enterpriseRow.getString("abbreviation") + "',";
+            SQL = SQL + " '" + contactsRow.getString("name") + "',";
+            SQL = SQL + " '" + contactsRow.getString("phonenumber") + "',";
+            SQL = SQL + " '" + contactsRow.getString("address") + "',";
+            SQL = SQL + " 0 ";
+            sqlist.add(SQL);
+        }
+        mqwms.runSqlUpdate(sqlist);
+        SQLFactory.createUpdateSQL(controller, "st_stockbill_items").setValue("wmsuploadflag", 2).setWhere("st_stockbill_itemsid", stockbillitemsRows.toArrayList("st_stockbill_itemsid"));
+    }
+
+}

+ 148 - 0
src/custom/service/GetBasicDataFromU8.java

@@ -0,0 +1,148 @@
+package service;
+
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+import common.data.db.QueryCallBack;
+
+import java.util.ArrayList;
+
+/**
+ * 美大U8erp数据传输自动任务
+ */
+
+public class GetBasicDataFromU8 extends ServiceController {
+    private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取U8基础资料(计量单位-商品档案-序列号)", 1, RunType.minute);
+    }
+
+    /**
+     * 计量单位
+     */
+    public void getUnit() throws YosException {
+        YUNl_DB.runSqlQuery("select distinct cComUnitName from ComputationUnit where status=0 and accid in('666','888')", new QueryCallBack() {
+            @Override
+            public void onRowLoaded(long rowindex, Row row) throws YosException {
+                try {
+                    String cComUnitName = row.getString("cComUnitName");
+                    InsertSQL unitInsert = SQLFactory.createInsertSQL(dbConnect, "plm_unit");
+                    unitInsert.setValue("siteid", "MD");
+                    unitInsert.setValue("unitname", cComUnitName);
+                    unitInsert.setWhere("not exists(select * from plm_unit where siteid='MD' and unitname='" + cComUnitName + "')");
+                    unitInsert.insert();
+                    YUNl_DB.runSqlUpdate("update ComputationUnit set status=1 where cComUnitName='" + cComUnitName + "' and accid in('666','888')");
+                } catch (Exception e) {
+                    logger.error("U8计量单位同步DRP失败", row.toJsonObject(), e);
+                }
+            }
+        });
+    }
+
+    /**
+     * 商品档案
+     */
+    public void getItem() throws YosException {
+        RowsMap unitMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid,unitname").setWhere("siteid", "MD").query().toRowsMap("unitname");
+        Rows cInvCodeRows = YUNl_DB.runSqlQuery("select " + "cInvCode," +//--存货编码
+                "cInvName," +//存货名称
+                "cInvStd," +//规格型号
+                "cComUnitName," +//主计量单位名称
+                "isnull(bSerial,0)as bSerial " +//是否序列号管理
+                "from Inventory where status=0 and accid in('666','888')");
+
+        ArrayList<String> itemnoList = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemno").setWhere("siteid", "MD").setWhere("itemno", cInvCodeRows.toArrayList("cInvCode")).query().toArrayList("itemno");
+        for (Row cInvCodeRow : cInvCodeRows) {
+            try {
+                String cComUnitName = cInvCodeRow.getString("cComUnitName");
+                if (!unitMap.containsKey(cComUnitName)) {
+                    continue;//计量单位不存在
+                }
+                String cInvCode = cInvCodeRow.getString("cInvCode");
+                String cInvName = cInvCodeRow.getString("cInvName");
+                String cInvStd = cInvCodeRow.getString("cInvStd");
+                boolean bSerial = cInvCodeRow.getBoolean("bSerial");
+                if (itemnoList.contains(cInvCode)) {
+                    UpdateSQL plmItem = SQLFactory.createUpdateSQL(dbConnect, "plm_item");
+                    plmItem.setValue("itemname", cInvName);
+                    plmItem.setValue("model", cInvStd);
+                    plmItem.setValue("unitid", unitMap.get(cComUnitName).get(0).getLong("unitid"));
+                    plmItem.setValue("skucontrol", bSerial);
+                    plmItem.setValue("changeby", "U8");
+                    plmItem.setValue("WMSUPLOADFLAG", 2);
+                    plmItem.setWhere("siteid", "MD").setWhere("itemno", cInvCode);
+                    plmItem.update();
+                } else {
+                    InsertSQL plmItem = SQLFactory.createInsertSQL(dbConnect, "plm_item");
+                    plmItem.setValue("itemno", cInvCode);
+                    plmItem.setValue("itemname", cInvName);
+                    plmItem.setValue("model", cInvStd);
+                    plmItem.setValue("unitid", unitMap.get(cComUnitName).get(0).getLong("unitid"));
+                    plmItem.setValue("skucontrol", bSerial);
+                    plmItem.setValue("createby", "U8");
+                    plmItem.setValue("WMSUPLOADFLAG", 2);
+                    plmItem.setValue("siteid", "MD");
+                    plmItem.insert();
+                }
+                YUNl_DB.runSqlUpdate("update Inventory set status=1 where cInvCode='" + cInvCode + "' and accid in('666','888')");
+            } catch (Exception e) {
+                logger.error("U8货品档案同步DRP失败", cInvCodeRow.toJsonObject(), e);
+            }
+        }
+    }
+
+    /**
+     * 序列号
+     */
+    public void getMcode() throws YosException {
+        Rows codeRows = YUNl_DB.runSqlQuery("SELECT cInvCode,cInvSN FROM ST_SNState where status=0 and accid in('666','888')");
+        Rows itemrows = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemid", "itemno").setWhere("siteid", "MD").setWhere("itemno", codeRows.toArrayList("cInvCode")).query();
+
+        RowsMap itemMap = itemrows.toRowsMap("itemno");
+
+        //已存在的序列号
+        ArrayList<String> codeList = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku").setWhere("siteid", "MD").setWhere("sku", codeRows.toArrayList("cInvSN")).query().toArrayList("sku");
+
+        for (Row codeRow : codeRows) {
+            String cInvCode = codeRow.getString("cInvCode");
+            String cInvSN = codeRow.getString("cInvSN");
+            if (itemMap.containsKey(cInvCode)) {
+                if (codeList.contains(cInvSN)) {
+                    UpdateSQL sku = SQLFactory.createUpdateSQL(dbConnect, "sa_itemsku");
+                    sku.setValue("itemid", itemMap.get(cInvCode).get(0).getLong("itemid"));
+                    sku.setValue("changeby", "U8");
+                    sku.setWhere("siteid", "MD").setWhere("sku", cInvSN);
+                    sku.setValue("WMSUPLOADFLAG", 2);
+                    sku.update();
+                } else {
+                    InsertSQL sku = SQLFactory.createInsertSQL(dbConnect, "sa_itemsku");
+                    sku.setValue("itemid", itemMap.get(cInvCode).get(0).getLong("itemid"));
+                    sku.setValue("sku", cInvSN);
+                    sku.setValue("status", "");
+                    sku.setValue("createby", "U8");
+                    sku.setValue("siteid", "MD");
+                    sku.setValue("WMSUPLOADFLAG", 2);
+                    sku.insert();
+                }
+                YUNl_DB.runSqlUpdate("update ST_SNState set status=1 where cInvCode='" + cInvCode + "' and cInvSN='" + cInvSN + "' and accid in('666','888')");
+            } else {
+                YUNl_DB.runSqlUpdate("update ST_SNState set status=2 where cInvCode='" + cInvCode + "' and cInvSN='" + cInvSN + "' and accid in('666','888')");
+            }
+        }
+    }
+
+    /**
+     * 计算经销商首批提货日期
+     */
+    public void caculateStartDate() {
+
+    }
+}

+ 102 - 0
src/custom/service/GetOutCodeFromMQWms.java

@@ -0,0 +1,102 @@
+package service;
+
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+
+import java.util.Calendar;
+
+public class GetOutCodeFromMQWms extends ServiceController {
+    private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取马桥WMS出库单序列号", 1, RunType.minute);
+    }
+
+    /**
+     * 生成立体仓库入库
+     *
+     * @throws YosException
+     */
+    public void getOutCode() throws YosException {
+        Rows rows = YUNl_DB.runSqlQuery("select ccode,cinvcode,cinvsn from Wms_Rdrecord32SN where year(ddate)>=" + (Calendar.getInstance().get(Calendar.YEAR) - 1) + " and DRPstatus=0 and ccode not like'TN%' order by ccode,rowno");
+        if (rows.isNotEmpty()) {
+            //E-订单单据查询
+            QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno", "st_stockbillid", "sys_enterpriseid", "status", "iswx").setTableAlias("t1");
+            billCheckSQL.addJoinTable(JOINTYPE.inner, "st_stockbill_items_sku", "t2", "t1.st_stockbillid=t2.st_stockbillid", "sku");
+            billCheckSQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid=t3.sys_enterpriseid", "entity");
+            billCheckSQL.setWhere("t1.siteid", "MD").setWhere("t1.billno", rows.toArrayList("ccode"));
+            RowsMap billRowsMap = billCheckSQL.query().toRowsMap("billno");
+
+            QuerySQL codeQuery = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku", "stockid", "itemid").setTableAlias("t1");
+            codeQuery.addJoinTable(JOINTYPE.inner, "st_stock", "t2", "stockid=:stockid");
+            codeQuery.addJoinTable(JOINTYPE.inner, "plm_item", "t3", "t1.itemid=t3.itemid", "stockno");
+            codeQuery.setWhere("t1.sku", rows.toArrayList("cinvsn")).setWhere("t2.stockno", "101,109");
+            RowsMap codeRowsMap = codeQuery.query().toRowsMap("sku");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            for (Row row : rows) {
+                String billno = row.getString("ccode");
+                String sku = row.getString("cinvsn");
+
+                if (!billRowsMap.containsKey(billno)) {
+                    //单据不存在
+                    YUNl_DB.runSqlUpdate("update Wms_Rdrecord32SN set drpstatus=-1 where ccode='" + billno + "' and cinvsn='" + sku + "'");
+                    continue;
+                }
+                if (billRowsMap.containsKey(billno) && billRowsMap.get(billno).toArrayList("sku").contains(sku)) {
+                    //出库单序列号已存在
+                    YUNl_DB.runSqlUpdate("update Wms_Rdrecord32SN set drpstatus=1 where ccode='" + billno + "' and cinvsn='" + sku + "'");
+                    continue;
+                }
+                if (!codeRowsMap.containsKey(sku)) {
+                    //序列号不存在或者不在101-109仓库中
+                    continue;
+                }
+
+                Row coderow = codeRowsMap.get(sku).get(0);
+                Row billrow = billRowsMap.get(billno).get(0);
+
+                long st_stockbillid = billrow.getLong("st_stockbillid");
+                long sys_enterpriseid = billrow.getLong("sys_enterpriseid");
+                String entity = billrow.getString("entity");
+                String status = billrow.getString("status");
+                boolean iswx = billrow.getBoolean("iswx");
+                long stockid = entity.equals("实业") ? stockRowsMap.get(coderow.getString("stockno")).get(0).getLong("stockid") : stockRowsMap.get("101").get(0).getLong("stockid");
+
+                SQLDump sqlDump = new SQLDump();
+                //创建入库单序列号
+                InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                stStockbillItemsSku.setValue("siteid", "MD");
+                stStockbillItemsSku.setValue("createby", "wms");
+                stStockbillItemsSku.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                stStockbillItemsSku.setValue("stockid", stockid);
+                stStockbillItemsSku.setValue("sku", sku);
+                sqlDump.add(stStockbillItemsSku);
+                if (status.equals("审核")) {
+                    //如果表单状态是审核的,则更新序列号表
+                    UpdateSQL saItemsku = SQLFactory.createUpdateSQL(dbConnect, "sa_itemsku");
+                    saItemsku.setValue("stockid", iswx ? stockRowsMap.get("00").get(0).getLong("stockid") : "null");//如果是网销销售出库单,则仓库置为00
+                    saItemsku.setValue("sys_enterpriseid", sys_enterpriseid > 0 ? sys_enterpriseid : "null");
+                    saItemsku.setWhere("sku", sku).setWhere("ifnull(stockid,0)>0");
+                    sqlDump.add(saItemsku);
+                }
+                try {
+                    sqlDump.commit();
+                    YUNl_DB.runSqlUpdate("update Wms_Rdrecord32SN set drpstatus=1 where ccode='" + billno + "' and cinvsn='" + sku + "'");
+                } catch (Exception e) {
+
+                }
+            }
+        }
+    }
+}

+ 115 - 0
src/custom/service/GetOutCodeFromTQWms.java

@@ -0,0 +1,115 @@
+package service;
+
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+
+public class GetOutCodeFromTQWms extends ServiceController {
+    private DBConnect TQWMS = new DBConnect("TQWMS");//谈桥立体仓库中间服务
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取谈桥WMS出库单序列号", 1, RunType.minute);
+    }
+
+    public void getOutCode() throws YosException {
+        Rows rows = TQWMS.runSqlQuery("select distinct t1.billno,t2.materialcode,t3.serialno from TOutInt t1 inner join TOutDetailInt t2 on t1.OutPlanID=t2.OutPlanID inner join TOutSerialnoDetail t3 on t2.DetailID=t3.DetailID where t2.Status=2 and t2.IsDeleted=0and t1.IsDeleted=0 and year(t3.CreateDate)>=" + (Calendar.getInstance().get(Calendar.YEAR) - 1) + " and isnull(t3.status,0)=0");
+        if (rows.isNotEmpty()) {
+            QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno", "st_stockbillid", "sys_enterpriseid", "status", "iswx").setTableAlias("t1");
+            billCheckSQL.addJoinTable(JOINTYPE.inner, "st_stockbill_items_sku", "t2", "t1.st_stockbillid=t2.st_stockbillid", "sku");
+            billCheckSQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid=t3.sys_enterpriseid", "entity");
+            billCheckSQL.setWhere("t1.siteid", "MD").setWhere("t1.billno", rows.toArrayList("billno"));
+            RowsMap billRowsMap = billCheckSQL.query().toRowsMap("billno");
+
+            QuerySQL codeQuery = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku", "stockid", "itemid").setTableAlias("t1");
+            codeQuery.addJoinTable(JOINTYPE.inner, "st_stock", "t2", "stockid=:stockid");
+            codeQuery.addJoinTable(JOINTYPE.inner, "plm_item", "t3", "t1.itemid=t3.itemid", "stockno");
+            codeQuery.setWhere("t1.sku", rows.toArrayList("serialno")).setWhere("t2.stockno", "101,103");
+            RowsMap codeRowsMap = codeQuery.query().toRowsMap("sku");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            for (Row row : rows) {
+                String billno = row.getString("billno");
+                String sku = row.getString("serialno");
+
+                if (!billRowsMap.containsKey(billno)) {
+                    //单据不存在
+                    TQWMS.runSqlUpdate("update TOutSerialnoDetail set status=-1 where BillNo='" + billno + "' and SerialNo='" + sku + "'");
+                    continue;
+                }
+                if (billRowsMap.containsKey(billno) && billRowsMap.get(billno).toArrayList("sku").contains(sku)) {
+                    //出库单序列号已存在
+                    TQWMS.runSqlUpdate("update TOutSerialnoDetail set status=1 where BillNo='" + billno + "' and SerialNo='" + sku + "'");
+                    continue;
+                }
+                if (!codeRowsMap.containsKey(sku)) {
+                    //序列号不存在或者不在101-103仓库中
+                    continue;
+                }
+
+                Row coderow = codeRowsMap.get(sku).get(0);
+                Row billrow = billRowsMap.get(billno).get(0);
+
+                long st_stockbillid = billrow.getLong("st_stockbillid");
+                long sys_enterpriseid = billrow.getLong("sys_enterpriseid");
+                String entity = billrow.getString("entity");
+                String status = billrow.getString("status");
+                boolean iswx = billrow.getBoolean("iswx");
+                long stockid = entity.equals("实业") ? stockRowsMap.get(coderow.getString("stockno")).get(0).getLong("stockid") : stockRowsMap.get("101").get(0).getLong("stockid");
+
+                SQLDump sqlDump = new SQLDump();
+                //创建入库单序列号
+                InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                stStockbillItemsSku.setValue("siteid", "MD");
+                stStockbillItemsSku.setValue("createby", "wms");
+                stStockbillItemsSku.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                stStockbillItemsSku.setValue("stockid", stockid);
+                stStockbillItemsSku.setValue("sku", sku);
+                sqlDump.add(stStockbillItemsSku);
+                if (status.equals("审核")) {
+                    //如果表单状态是审核的,则更新序列号表
+                    UpdateSQL saItemsku = SQLFactory.createUpdateSQL(dbConnect, "sa_itemsku");
+                    saItemsku.setValue("stockid", iswx ? stockRowsMap.get("00").get(0).getLong("stockid") : "null");//如果是网销销售出库单,则仓库置为00
+                    saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
+                    saItemsku.setWhere("sku", sku).setWhere("ifnull(stockid,0)>0");
+                    sqlDump.add(saItemsku);
+                }
+                try {
+                    sqlDump.commit();
+                    TQWMS.runSqlUpdate("update TOutSerialnoDetail set status=1 where BillNo='" + billno + "' and SerialNo='" + sku + "'");
+                    //判断关闭中间表状态
+
+                    Rows skucountRows = dbConnect.runSqlQuery("select sum(1) as skucount,sum(case when createby='wms' then 1 else 0 end ) as wmsskucount from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid);
+                    Rows skuitemcountRows = dbConnect.runSqlQuery("select sum(qty) as totalcount,sum(case when wmsuploadflag=2 then qty else 0 end ) as wmscount from st_stockbill_items t1 inner join plm_item t2 on t1.itemid=t2.itemid and t2.skucontrol=1 where  st_stockbillid=" + st_stockbillid);
+                    if (skucountRows.isNotEmpty() && skuitemcountRows.isNotEmpty()) {
+                        int skucount = skucountRows.get(0).getInteger("skucount");
+                        int wmsskucount = skucountRows.get(0).getInteger("wmsskucount");
+                        int totalcount = skuitemcountRows.get(0).getInteger("totalcount");
+                        int wmscount = skuitemcountRows.get(0).getInteger("wmscount");
+                        if (wmsskucount >= wmscount || totalcount >= skucount) {
+                            ArrayList<String> sqlist = new ArrayList<>();
+                            sqlist.add("update TOutInt set status=10 ,ModifyDate=getdate() where BillNo='" + billno + "'");
+                            sqlist.add("update TOutDetailInt set status=10,ModifyDate=getdate() where BillNo='" + billno + "'");
+                            sqlist.add("update TOutInt set Status=10 where OutPlanID in (select OutPlanID  from TOutDetailInt where Status=2 group by OutPlanID having sum(PlanOutQuantity)=0)");
+                            sqlist.add("update TOutDetailInt set Status=10 where OutPlanID in (select OutPlanID  from TOutDetailInt where Status=2 group by OutPlanID having sum(PlanOutQuantity)=0)");
+                            TQWMS.runSqlUpdate(sqlist);
+                        }
+                    }
+                } catch (Exception e) {
+
+                }
+            }
+        }
+    }
+}

+ 155 - 0
src/custom/service/GetStockBillFromMQWms.java

@@ -0,0 +1,155 @@
+package service;
+
+import beans.stockbill.Stockbill;
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+public class GetStockBillFromMQWms extends ServiceController {
+    private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取马桥WMS出入库单(立体仓库入库)", 1, RunType.minute);
+    }
+
+    /**
+     * 生成立体仓库入库
+     *
+     * @throws YosException
+     */
+    public void stockIn() throws YosException {
+        Rows rows = YUNl_DB.runSqlQuery("select cinvcode,cinvsn,ddate,id from Wms_Rdrecordother where drpstatus=0");
+        if (rows.isNotEmpty()) {
+            QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno").setTableAlias("t1");
+            billCheckSQL.addJoinTable(JOINTYPE.inner, "st_stockbill_items_sku", "t2", "t1.st_stockbillid=t2.st_stockbillid", "sku");
+            billCheckSQL.setWhere("siteid", "MD").setWhere("t1.type in ('返修入库','销售出库')");
+            billCheckSQL.setWhere("t2.sku", rows.toArrayList("cinvsn"));
+            ArrayList<String> billCodeList = billCheckSQL.query().toArrayList("sku");
+
+            QuerySQL codeQuery = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku", "stockid", "itemid");
+            codeQuery.addJoinTable(JOINTYPE.inner, "plm_item", "t2", "t1.itemid=t2.itemid", "itemno", "itemname", "stockno", "model", "unitid");
+            codeQuery.setWhere("siteid", "MD");
+            codeQuery.setWhere("sku", rows.toArrayList("cinvsn"));
+            RowsMap codeRowsMap = codeQuery.query().toRowsMap("sku");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            RowsMap unitRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid", "unitname").query().toRowsMap("unitid");
+
+            for (Row row : rows) {
+                long id = row.getLong("id");
+                String sku = row.getString("cinvsn");
+                String itemno = row.getString("cinvcode");
+                Date createdate = row.getDate("ddate");
+
+                if (billCodeList.contains(sku)) {
+                    //如果序列号已经存在返修入库、或者销售出库,则将状态改为11
+                    YUNl_DB.runSqlUpdate("update Wms_Rdrecordother set drpstatus=11  where ID=" + id);
+                    continue;
+                }
+                Calendar calendar = Calendar.getInstance();
+                calendar.add(Calendar.MONTH, -2);
+                if (createdate.before(calendar.getTime())) {
+                    //超过时间未能处理,则将状态改为12
+                    YUNl_DB.runSqlUpdate("update Wms_Rdrecordother set drpstatus=12 where ID=" + id);
+                    continue;
+                }
+                if (!codeRowsMap.containsKey(sku)) {
+                    //序列号不存在,则跳过
+                    continue;
+                }
+                if (!codeRowsMap.get(sku).getRow(0).getString("itemno").equals(itemno)) {
+                    //商品编号不匹配,则跳过
+                    continue;
+                }
+                if (codeRowsMap.get(sku).getRow(0).getInteger("stockid") > 0) {
+                    //序列号仓库不为空,则跳过
+                    continue;
+                }
+                String instockno = codeRowsMap.get(sku).getRow(0).getString("stockno");
+                if (instockno.isEmpty()) {
+                    //商品默认仓库为空,则跳过
+                    continue;
+                }
+                if (stockRowsMap.get(instockno).isEmpty()) {
+                    //仓库不存在,跳过
+                    continue;
+                }
+
+                long stockid = stockRowsMap.get(instockno).get(0).getLong("stockid");
+                String billno = createBillCode("MD", "warehouseReceipt");//单据编号规则需统一
+                //创建入库单表头
+                SQLDump sqlDump = new SQLDump();
+                long st_stockbillid = createTableID("st_stockbill");
+                InsertSQL stStockbill = SQLFactory.createInsertSQL(dbConnect, "st_stockbill");
+                stStockbill.setValue("st_stockbillid", st_stockbillid);
+                stStockbill.setValue("type", "其他入库");
+                stStockbill.setValue("typemx", "立体仓库入库");
+                stStockbill.setValue("billno", billno);
+                stStockbill.setValue("siteid", "MD");
+                stStockbill.setDateValue("billdate");
+                stStockbill.setValue("stockid", stockid);
+                stStockbill.setValue("remarks", "谈桥立仓入库生成");
+                stStockbill.setValue("createby", "u8");
+                stStockbill.setValue("status", "新建");
+                stStockbill.setValue("rb", 1);
+                sqlDump.add(stStockbill);
+
+                //创建入库单表体
+                Row coderow = codeRowsMap.get(sku).get(0);
+                long st_stockbill_itemsid = createTableID("st_stockbill_items");
+                InsertSQL stStockbillitems = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items");
+                stStockbillitems.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillitems.setValue("st_stockbillid", st_stockbillid);
+                stStockbillitems.setValue("siteid", "MD");
+                stStockbillitems.setValue("rowno", 1);
+                stStockbillitems.setValue("createby", "u8");
+                stStockbillitems.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillitems.setValue("itemno", coderow.getString("itemno"));
+                stStockbillitems.setValue("itemname", coderow.getString("itemname"));
+                stStockbillitems.setValue("model", coderow.getString("model"));
+                if (unitRowsMap.get(coderow.getString("unitid")).isNotEmpty()) {
+                    stStockbillitems.setValue("unit", unitRowsMap.get(coderow.getString("unitid")).get(0).getString("unitname"));
+                }
+                stStockbillitems.setValue("qty", 1);
+                stStockbillitems.setValue("stockid", stockid);
+                sqlDump.add(stStockbillitems);
+
+                //创建入库单序列号
+                InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                stStockbillItemsSku.setValue("siteid", "MD");
+                stStockbillItemsSku.setValue("createby", "u8");
+                stStockbillItemsSku.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                stStockbillItemsSku.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillItemsSku.setValue("stockid", stockid);
+                stStockbillItemsSku.setValue("sku", sku);
+                sqlDump.add(stStockbillItemsSku);
+
+                sqlDump.commit();
+                try {
+                    Stockbill.check(getSysController("MD"), st_stockbillid, true);
+
+                    ArrayList<String> sqlist = new ArrayList<>();
+                    sqlist.add("update Wms_Rdrecordother set drpstatus=1 where ID=" + id);
+                    YUNl_DB.runSqlUpdate(sqlist);
+                } catch (Exception e) {
+                    dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid);
+                }
+            }
+        }
+    }
+}

+ 296 - 0
src/custom/service/GetStockBillFromTQWms.java

@@ -0,0 +1,296 @@
+package service;
+
+import beans.stockbill.Stockbill;
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+import org.apache.ibatis.jdbc.SQL;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 美大U8erp出入库单同步
+ */
+
+public class GetStockBillFromTQWms extends ServiceController {
+    private DBConnect TQWMS = new DBConnect("TQWMS");//谈桥立体仓库中间服务
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取谈桥WMS入库单(立体仓库入库、外购入库wms)", 1, RunType.minute);
+    }
+
+    /**
+     * 生成立体仓库入库
+     *
+     * @throws YosException
+     */
+    public void stockIn() throws YosException {
+        Rows rows = TQWMS.runSqlQuery("SELECT t1.DetailID,t1.SerialNo,t1.MaterialCode,t1.CreateDate FROM TInDetailInt t1 INNER JOIN TMaterialsSerialNo t2 on t1.SerialNo=t2.SerialNo WHERE year(t1.CreateDate)>=2018 and t1.Status=0 and t1.IsDeleted=0 and t2.sysfrom='DRP'");
+
+        if (rows.isNotEmpty()) {
+            QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno").setTableAlias("t1");
+            billCheckSQL.addJoinTable(JOINTYPE.inner, "st_stockbill_items_sku", "t2", "t1.st_stockbillid=t2.st_stockbillid", "sku");
+            billCheckSQL.setWhere("siteid", "MD").setWhere("t1.type in ('返修入库','销售出库')");
+            billCheckSQL.setWhere("t2.sku", rows.toArrayList("cinvsn"));
+            ArrayList<String> billCodeList = billCheckSQL.query().toArrayList("sku");
+
+            QuerySQL codeQuery = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku", "stockid", "itemid");
+            codeQuery.addJoinTable(JOINTYPE.inner, "plm_item", "t2", "t1.itemid=t2.itemid", "itemno", "itemname", "stockno", "model", "unitid");
+            codeQuery.setWhere("siteid", "MD");
+            codeQuery.setWhere("sku", rows.toArrayList("SerialNo"));
+            RowsMap codeRowsMap = codeQuery.query().toRowsMap("sku");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            RowsMap unitRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid", "unitname").query().toRowsMap("unitid");
+
+
+            for (Row row : rows) {
+                long DetailID = row.getLong("DetailID");
+                String sku = row.getString("SerialNo");
+                String itemno = row.getString("MaterialCode");
+                Date createdate = row.getDate("CreateDate");
+
+                if (billCodeList.contains(sku)) {
+                    //如果序列号已经存在返修入库、或者销售出库,则将状态改为11
+                    TQWMS.runSqlUpdate("update TInDetailInt set status=11,ModifyDate=GETDATE() where DetailID=" + DetailID);
+                    continue;
+                }
+                Calendar calendar = Calendar.getInstance();
+                calendar.add(Calendar.MONTH, -2);
+                if (createdate.before(calendar.getTime())) {
+                    //超过时间未能处理,则将状态改为12
+                    TQWMS.runSqlUpdate("update TInDetailInt set status=12,ModifyDate=GETDATE() where DetailID=" + DetailID);
+                    continue;
+                }
+                if (!codeRowsMap.containsKey(sku)) {
+                    //序列号不存在,则跳过
+                    continue;
+                }
+                if (!codeRowsMap.get(sku).getRow(0).getString("itemno").equals(itemno)) {
+                    //商品编号不匹配,则跳过
+                    continue;
+                }
+                if (codeRowsMap.get(sku).getRow(0).getInteger("stockid") > 0) {
+                    //序列号仓库不为空,则跳过
+                    continue;
+                }
+                String instockno = codeRowsMap.get(sku).getRow(0).getString("stockno");
+                if (instockno.isEmpty()) {
+                    //商品默认仓库为空,则跳过
+                    continue;
+                }
+                if (stockRowsMap.get(instockno).isEmpty()) {
+                    //仓库不存在,跳过
+                    continue;
+                }
+
+                long stockid = stockRowsMap.get(instockno).get(0).getLong("stockid");
+                String billno = createBillCode("MD", "warehouseReceipt");//单据编号规则需统一
+                //创建入库单表头
+                SQLDump sqlDump = new SQLDump();
+                long st_stockbillid = createTableID("st_stockbill");
+                InsertSQL stStockbill = SQLFactory.createInsertSQL(dbConnect, "st_stockbill");
+                stStockbill.setValue("st_stockbillid", st_stockbillid);
+                stStockbill.setValue("type", "其他入库");
+                stStockbill.setValue("typemx", "立体仓库入库");
+                stStockbill.setValue("billno", billno);
+                stStockbill.setValue("siteid", "MD");
+                stStockbill.setDateValue("billdate");
+                stStockbill.setValue("stockid", stockid);
+                stStockbill.setValue("remarks", "谈桥立仓入库生成");
+                stStockbill.setValue("createby", "wms");
+                stStockbill.setValue("status", "新建");
+                stStockbill.setValue("rb", 1);
+                sqlDump.add(stStockbill);
+
+                //创建入库单表体
+                Row coderow = codeRowsMap.get(sku).get(0);
+                long st_stockbill_itemsid = createTableID("st_stockbill_items");
+                InsertSQL stStockbillitems = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items");
+                stStockbillitems.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillitems.setValue("st_stockbillid", st_stockbillid);
+                stStockbillitems.setValue("siteid", "MD");
+                stStockbillitems.setValue("rowno", 1);
+                stStockbillitems.setValue("createby", "wms");
+                stStockbillitems.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillitems.setValue("itemno", coderow.getString("itemno"));
+                stStockbillitems.setValue("itemname", coderow.getString("itemname"));
+                stStockbillitems.setValue("model", coderow.getString("model"));
+                if (unitRowsMap.get(coderow.getString("unitid")).isNotEmpty()) {
+                    stStockbillitems.setValue("unit", unitRowsMap.get(coderow.getString("unitid")).get(0).getString("unitname"));
+                }
+                stStockbillitems.setValue("qty", 1);
+                stStockbillitems.setValue("stockid", stockid);
+                sqlDump.add(stStockbillitems);
+
+                //创建入库单序列号
+                InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                stStockbillItemsSku.setValue("siteid", "MD");
+                stStockbillItemsSku.setValue("createby", "wms");
+                stStockbillItemsSku.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                stStockbillItemsSku.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillItemsSku.setValue("stockid", stockid);
+                stStockbillItemsSku.setValue("sku", sku);
+                sqlDump.add(stStockbillItemsSku);
+
+                sqlDump.commit();
+                try {
+                    Stockbill.check(getSysController("MD"), st_stockbillid, true);
+
+                    ArrayList<String> sqlist = new ArrayList<>();
+                    sqlist.add("update TInDetailInt set status=1 where DetailID=" + DetailID);
+                    sqlist.add("insert into TInDetailLog(SerialNo,CreateDate,IsDeleted,MaterialCode,BillNo,BillType) values('" + sku + "',GETDATE(),0,'" + itemno + "','" + billno + "',1)");
+                    TQWMS.runSqlUpdate(sqlist);
+                } catch (Exception e) {
+                    dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid);
+                }
+            }
+        }
+    }
+
+    /**
+     * 创新外购入库
+     */
+    public void cxwgIn() throws YosException {
+        Rows rows = TQWMS.runSqlQuery("SELECT DetailID,T1.SerialNo,T1.CreateDate,T1.MaterialCode FROM TInDetailInt T1 INNER JOIN TMaterialsSerialNo T2 ON T1.SerialNo=T2.SerialNo WHERE T2.sysfrom='U8_888' AND T1.Status=0");
+        if (rows.isNotEmpty()) {
+            QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno").setTableAlias("t1");
+            billCheckSQL.addJoinTable(JOINTYPE.inner, "st_stockbill_items_sku", "t2", "t1.st_stockbillid=t2.st_stockbillid", "sku");
+            billCheckSQL.setWhere("siteid", "MD").setWhere("t2.sku", rows.toArrayList("cinvsn"));
+            ArrayList<String> billCodeList = billCheckSQL.query().toArrayList("sku");
+
+            QuerySQL codeQuery = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sku", "stockid", "itemid");
+            codeQuery.addJoinTable(JOINTYPE.inner, "plm_item", "t2", "t1.itemid=t2.itemid", "itemno", "itemname", "stockno", "model", "unitid");
+            codeQuery.setWhere("siteid", "MD");
+            codeQuery.setWhere("sku", rows.toArrayList("SerialNo"));
+            RowsMap codeRowsMap = codeQuery.query().toRowsMap("sku");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            RowsMap unitRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid", "unitname").query().toRowsMap("unitid");
+
+            RowsMap depRowsMap = SQLFactory.createQuerySQL(dbConnect, "sys_department", "departmentid", "depno").query().toRowsMap("depno");
+
+            RowsMap suppRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_supplier", "sa_supplierid", "suppno").query().toRowsMap("suppno");
+
+
+            QuerySQL querySQL = SQLFactory.createQuerySQL(new DBConnect("U8-YUNl_DB"), "inventory");
+            querySQL.setWhere("ACCID", "888").setWhere("isnull(cInvDefine1,'0')='0'").setWhere("cInvCode", rows.toArrayList("MaterialCode"));
+            ArrayList<String> codeCheckList = querySQL.query().toArrayList("cInvCode");
+
+            for (Row row : rows) {
+                long DetailID = row.getLong("DetailID");
+                String sku = row.getString("SerialNo");
+                String itemno = row.getString("MaterialCode");
+                Date createdate = row.getDate("CreateDate");
+
+                if (!codeCheckList.contains(itemno)) {
+                    continue;
+                }
+                if (billCodeList.contains(sku)) {
+                    //如果序列号已经出入库记录
+                    TQWMS.runSqlUpdate("update TInDetailInt set status=11,ModifyDate=GETDATE() where DetailID=" + DetailID);
+                    continue;
+                }
+                Calendar calendar = Calendar.getInstance();
+                calendar.add(Calendar.MONTH, -2);
+                if (createdate.before(calendar.getTime())) {
+                    //超过时间未能处理,则将状态改为12
+                    TQWMS.runSqlUpdate("update TInDetailInt set status=12,ModifyDate=GETDATE() where DetailID=" + DetailID);
+                    continue;
+                }
+                if (!codeRowsMap.containsKey(sku)) {
+                    //序列号不存在,则跳过
+                    continue;
+                }
+                if (!codeRowsMap.get(sku).getRow(0).getString("itemno").equals(itemno)) {
+                    //商品编号不匹配,则跳过
+                    continue;
+                }
+                if (codeRowsMap.get(sku).getRow(0).getInteger("stockid") > 0) {
+                    //序列号仓库不为空,则跳过
+                    continue;
+                }
+
+                long stockid = stockRowsMap.get("101").get(0).getLong("stockid");
+                String billno = createBillCode("MD", "warehouseReceipt");//单据编号规则需统一
+                //创建入库单表头
+                SQLDump sqlDump = new SQLDump();
+                long st_stockbillid = createTableID("st_stockbill");
+                InsertSQL stStockbill = SQLFactory.createInsertSQL(dbConnect, "st_stockbill");
+                stStockbill.setValue("st_stockbillid", st_stockbillid);
+                stStockbill.setValue("type", "其他入库");
+                stStockbill.setValue("typemx", "外购入库wms");
+                stStockbill.setValue("billno", billno);
+                stStockbill.setValue("siteid", "MD");
+                stStockbill.setValue("departmentid", depRowsMap.get("101").get(0).getLong("departmentid"));
+                stStockbill.setValue("sa_supplierid", suppRowsMap.get("MDCXP-013").get(0).getLong("sa_supplierid"));
+                stStockbill.setValue("billdate", createdate);
+                stStockbill.setValue("stockid", stockid);
+                stStockbill.setValue("remarks", "wms入库");
+                stStockbill.setValue("createby", "wms");
+                stStockbill.setValue("status", "新建");
+                stStockbill.setValue("rb", 1);
+                sqlDump.add(stStockbill);
+
+                //创建入库单表体
+                Row coderow = codeRowsMap.get(sku).get(0);
+                long st_stockbill_itemsid = createTableID("st_stockbill_items");
+                InsertSQL stStockbillitems = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items");
+                stStockbillitems.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillitems.setValue("st_stockbillid", st_stockbillid);
+                stStockbillitems.setValue("siteid", "MD");
+                stStockbillitems.setValue("rowno", 1);
+                stStockbillitems.setValue("createby", "wms");
+                stStockbillitems.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillitems.setValue("itemno", coderow.getString("itemno"));
+                stStockbillitems.setValue("itemname", coderow.getString("itemname"));
+                stStockbillitems.setValue("model", coderow.getString("model"));
+                if (unitRowsMap.get(coderow.getString("unitid")).isNotEmpty()) {
+                    stStockbillitems.setValue("unit", unitRowsMap.get(coderow.getString("unitid")).get(0).getString("unitname"));
+                }
+                stStockbillitems.setValue("qty", 1);
+                stStockbillitems.setValue("stockid", stockid);
+                sqlDump.add(stStockbillitems);
+
+                //创建入库单序列号
+                InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                stStockbillItemsSku.setValue("siteid", "MD");
+                stStockbillItemsSku.setValue("createby", "wms");
+                stStockbillItemsSku.setValue("itemid", coderow.getLong("itemid"));
+                stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                stStockbillItemsSku.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                stStockbillItemsSku.setValue("stockid", stockid);
+                stStockbillItemsSku.setValue("sku", sku);
+                sqlDump.add(stStockbillItemsSku);
+
+                sqlDump.commit();
+                try {
+                    Stockbill.check(getSysController("MD"), st_stockbillid, true);
+
+                    ArrayList<String> sqlist = new ArrayList<>();
+                    sqlist.add("update TInDetailInt set status=1 where DetailID=" + DetailID);
+                    sqlist.add("insert into TInDetailLog(SerialNo,CreateDate,IsDeleted,MaterialCode,BillNo,BillType) values('" + sku + "',GETDATE(),0,'" + itemno + "','" + billno + "',1)");
+                    TQWMS.runSqlUpdate(sqlist);
+                } catch (Exception e) {
+                    dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+                    dbConnect.runSqlUpdate("delete from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid);
+                }
+            }
+        }
+    }
+}

+ 185 - 0
src/custom/service/GetStockBillFromU8.java

@@ -0,0 +1,185 @@
+package service;
+
+import beans.stockbill.Stockbill;
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+import common.data.db.QueryCallBack;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 美大U8erp出入库单同步
+ */
+
+public class GetStockBillFromU8 extends ServiceController {
+    private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("获取U8入库单(产品入库)", 1, RunType.minute);
+    }
+
+    /**
+     * 产品入库单
+     */
+    public void getProdIN() throws YosException {
+        //产品入库表头
+        Rows u8billRows = YUNl_DB.runSqlQuery("select top(50) cvencode,ccode,ddate,cwhcode,cmemo,id,dnverifytime,chandler from rdrecord where status=0 and billtype='10' and dnverifytime is not null and accid in('666','888') and  isnull(errtimes,0)<=5 order by errtimes");
+        if (u8billRows.isNotEmpty()) {
+            //产品入库表体
+            Rows u8billmxAllRows = SQLFactory.createQuerySQL(YUNl_DB, "RdRecords", "autoid,cinvcode,iquantity,iunitcost,iprice,cbmemo,cbatch").setWhere("billtype", "10").setWhere("accid in('666','888')").setWhere("id", u8billRows.toArrayList("id")).query();
+            RowsMap u8billmxRowsMap = u8billmxAllRows.toRowsMap("id");
+            //产品入库序列号
+            RowsMap u8billmxCodeRowsMap = SQLFactory.createQuerySQL(YUNl_DB, "ST_SNDetail", "autoid,ivouchsid,ivouchid,irowno,cinvcode,cwhcode,cposition,cinvsn,cbatch").setWhere("billtype", "10").setWhere("accid in('666','888')").setWhere("ivouchid", u8billRows.toArrayList("id")).setWhere("ivouchsid", u8billmxAllRows.toArrayList("autoid")).query().toRowsMap("ivouchid");
+
+            RowsMap stockRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
+
+            RowsMap itemRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemid", "itemno").setWhere("itemno", u8billmxAllRows.toArrayList("cinvcode")).query().toRowsMap("itemno");
+
+            RowsMap unitRowsMap = SQLFactory.createQuerySQL(dbConnect, "plm_unit", "unitid", "unitname").query().toRowsMap("unitid");
+
+
+            ArrayList<String> drpbillList = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno").setWhere("siteid", "MD").setWhere("status", "审核").setWhere("typemx", "生产入库u8").setWhere("billno", u8billRows.toArrayList("ccode")).query().toArrayList("billno");
+
+            foreachbill:
+            for (Row cInvCodeRow : u8billRows) {
+                String id = cInvCodeRow.getString("id");
+                try {
+                    String ccode = cInvCodeRow.getString("ccode");
+
+                    if (drpbillList.contains(ccode)) {
+                        //已存在审核状态的单据,则直接判定成功
+                        YUNl_DB.runSqlUpdate("update RdRecord set status=1  where ID ='" + id + "' and billtype='10'");
+                        continue;
+                    }
+                    String ddate = getDate_Str(cInvCodeRow.getDate("ddate"));
+                    if (dbConnect.runSqlQuery("select * from st_period where isclose=0 and begdate<='" + ddate + "' and enddate>='" + ddate + "'").isEmpty()) {
+                        //会计期间不存在,直接判定失败
+                        YUNl_DB.runSqlUpdate("update RdRecord set ErrTimes=10,failreason='找不到有效的会计期间' where ID ='" + id + " and billtype='10' ");
+                        continue;
+                    }
+                    String cwhcode = cInvCodeRow.getString("cwhcode");
+                    if (stockRowsMap.get(cwhcode).isEmpty()) {
+                        //仓库不存在,失败次数+1
+                        YUNl_DB.runSqlUpdate("update RdRecord set ErrTimes=isnull(ErrTimes,0)+1,failreason='仓库不存在' where ID ='" + id + " and billtype='10' ");
+                        continue;
+                    }
+                    Rows u8billmxRows = u8billmxRowsMap.get(id);//获取表体
+
+                    for (Row u8billmxRow : u8billmxRows) {
+                        String cinvcode = u8billmxRow.getString("cinvcode");
+                        if (itemRowsMap.get(cinvcode).isEmpty()) {
+                            //商品编号不存在,失败次数+1
+                            YUNl_DB.runSqlUpdate("update RdRecord set ErrTimes=isnull(ErrTimes,0)+1,failreason='商品不存在' where ID ='" + id + " and billtype='10' ");
+                            continue foreachbill;
+                        }
+
+                    }
+
+                    RowsMap u8billmxCodeMXRowsMap = u8billmxCodeRowsMap.get(id).toRowsMap("ivouchsid");//获取表体序列号
+
+
+                    String cmemo = cInvCodeRow.getString("cmemo");
+                    String dnverifytime = cInvCodeRow.getString("dnverifytime");
+                    String chandler = cInvCodeRow.getString("chandler");
+
+                    long stockid = stockRowsMap.get(cwhcode).get(0).getLong("stockid");
+
+                    SQLDump sqlDump = new SQLDump();
+
+                    long st_stockbillid = createTableID("st_stockbill");
+                    InsertSQL stStockbill = SQLFactory.createInsertSQL(dbConnect, "st_stockbill");
+                    stStockbill.setValue("st_stockbillid", st_stockbillid);
+                    stStockbill.setValue("type", "其他入库");
+                    stStockbill.setValue("typemx", "生产入库u8");
+                    stStockbill.setValue("billno", ccode);
+                    stStockbill.setValue("siteid", "MD");
+                    stStockbill.setValue("fdepno", "103");
+                    stStockbill.setValue("billdate", ddate);
+                    stStockbill.setValue("stockid", stockid);
+                    stStockbill.setValue("remarks", cmemo);
+                    stStockbill.setValue("createby", "u8");
+                    stStockbill.setValue("status", "新建");
+                    stStockbill.setValue("rb", 1);
+
+
+                    for (Row u8billmxRow : u8billmxRows) {
+                        String cinvcode = u8billmxRow.getString("cinvcode");
+                        String autoid = u8billmxRow.getString("autoid");
+                        double iquantity = u8billmxRow.getDouble("iquantity");
+//                        String iunitcost = u8billmxRow.getString("iunitcost");
+//                        String iprice = u8billmxRow.getString("iprice");
+                        String cbmemo = u8billmxRow.getString("cbmemo");
+                        String cbatch = u8billmxRow.getString("cbatch");
+                        String rowindex = u8billmxRow.getString("rowindex");
+
+                        Row itemrow = itemRowsMap.get(cinvcode).get(0);
+
+
+                        long st_stockbill_itemsid = createTableID("st_stockbill_items");
+                        InsertSQL stStockbillitems = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items");
+                        stStockbillitems.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                        stStockbillitems.setValue("st_stockbillid", st_stockbillid);
+                        stStockbillitems.setValue("siteid", "MD");
+                        stStockbillitems.setValue("rowno", rowindex);
+                        stStockbillitems.setValue("itemid", itemrow.getLong("itemid"));
+                        stStockbillitems.setValue("itemno", itemrow.getString("itemno"));
+                        stStockbillitems.setValue("itemname", itemrow.getString("itemname"));
+                        stStockbillitems.setValue("model", itemrow.getString("model"));
+                        if (unitRowsMap.get(itemrow.getString("unitid")).isNotEmpty()) {
+                            stStockbillitems.setValue("unit", unitRowsMap.get(itemrow.getString("unitid")).get(0).getString("unitname"));
+                        }
+                        stStockbillitems.setValue("qty", iquantity < 0 ? -iquantity : iquantity);
+                        if (!cbatch.isEmpty()) {
+                            stStockbillitems.setValue("batchno", cbatch);
+                        }
+                        stStockbillitems.setValue("stockid", stockid);
+                        stStockbillitems.setValue("remarks", cbmemo);
+
+                        stStockbill.setValue("rb", iquantity < 0 ? "0" : "1");
+
+                        sqlDump.add(stStockbillitems);
+
+                        for (Row codeRow : u8billmxCodeMXRowsMap.get(autoid)) {
+                            String cinvsn = codeRow.getString("cinvsn");
+                            InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
+                            stStockbillItemsSku.setValue("siteid", "MD");
+                            stStockbillItemsSku.setValue("createby", "u8");
+                            stStockbillItemsSku.setValue("itemid", itemrow.getLong("itemid"));
+                            stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
+                            stStockbillItemsSku.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                            stStockbillItemsSku.setValue("stockid", stockid);
+                            stStockbillItemsSku.setValue("sku", cinvsn);
+                            sqlDump.add(stStockbillItemsSku);
+                        }
+                    }
+                    sqlDump.add(stStockbill);
+
+                    sqlDump.commit();
+                    try {
+                        Stockbill.check(getSysController("MD"), st_stockbillid, true);
+                        YUNl_DB.runSqlUpdate("update RdRecord set status=1,failreason='' where ID =" + id + " and billtype='10'");
+                    } catch (Exception e) {
+                        dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid=" + st_stockbillid);
+                        dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+                        dbConnect.runSqlUpdate("delete from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid);
+                        YUNl_DB.runSqlUpdate("update RdRecord set ErrTimes=isnull(ErrTimes,0)+1,failreason='" + e.getMessage() + "' where ID ='" + id + " and billtype='10' ");
+                    }
+                } catch (Exception e) {
+                    logger.error("U8货品档案同步DRP失败", cInvCodeRow.toJsonObject(), e);
+                    YUNl_DB.runSqlUpdate("update RdRecord set ErrTimes=isnull(ErrTimes,0)+1,failreason='" + e.getMessage() + "' where ID ='" + id + " and billtype='10' ");
+                }
+            }
+        }
+    }
+
+}

+ 99 - 0
src/custom/service/UpdateBasicDataToWms.java

@@ -0,0 +1,99 @@
+package service;
+
+import common.ServiceController;
+import common.YosException;
+import common.data.*;
+import common.data.db.DBConnect;
+import common.data.db.QueryCallBack;
+
+import java.util.ArrayList;
+
+/**
+ * DRP基础资料传输WMS立体仓库
+ */
+
+public class UpdateBasicDataToWms extends ServiceController {
+    private DBConnect YUNl_DB = new DBConnect("U8-YUNl_DB");
+    private DBConnect TQWMS = new DBConnect("TQWMS");
+
+    @Override
+    public void serviceRun() throws Exception {
+
+    }
+
+    @Override
+    public ServiceParam paramSet() {
+        return new ServiceParam("更新马桥、谈桥WMS基础资料(商品档案-序列号)", 1, RunType.minute);
+    }
+
+
+    public void getItem() throws YosException {
+        QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "plm_item", "itemno", "itemname", "subString(model,0,50)model", "spec", "stockno", "shapesize").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "unitid=:unitid", "unitname");
+        querySQL.setWhere("siteid", "MD").setWhere("(t1.WMSUPLOADFLAG<2) and (t1.stockno='101' or t1.createby!='U8')");
+        Rows itemRows = querySQL.query();
+
+        if (itemRows.isNotEmpty()) {
+            ArrayList<String> tqitems = SQLFactory.createQuerySQL(TQWMS, "TMaterialsInt", "MaterialCode").setWhere("MaterialCode", itemRows.toArrayList("itemno")).query().toArrayList("MaterialCode");
+
+            ArrayList<String> TQSqlist = new ArrayList<>();
+            ArrayList<String> MQSqlist = new ArrayList<>();
+
+            for (Row itemRow : itemRows) {
+                String itemno = itemRow.getString("itemno");
+                String itemname = itemRow.getString("itemname");
+                String model = itemRow.getString("model");
+                String spec = itemRow.getString("spec");
+                String unitname = itemRow.getString("unitname");
+                String shapesize = itemRow.getString("shapesize");
+
+                String Standard = model + ";" + spec;
+
+                if (tqitems.contains(itemno)) {
+                    TQSqlist.add("update TMaterialsInt set ModifyDate=getDate(),StoreNo='101',Status=0, MaterialCNName='" + itemname + "',Mode='" + Standard + "',Unit='" + unitname + "',Standard='" + Standard + "',UnitName='" + unitname + "' where MaterialCode='" + itemno + "' and  (MaterialCNName!='" + itemname + "' or Mode!='" + Standard + "' or Unit!='" + unitname + "' or Standard!='" + Standard + "')");
+                } else {
+                    TQSqlist.add("insert into TMaterialsInt(MaterialCode,MaterialCNName,CreateDate,ModifyDate,IsDeleted,Mode,Unit,Standard,StoreNo,Status) values('" + itemno + "','" + itemname + "',getDate(),getDate(),0,'" + Standard + "','" + unitname + "','" + Standard + "','101',0 )");
+                }
+
+                MQSqlist.add("update inventory set fshapesize='" + shapesize + " where cinvcode='" + itemno + "'and fshapesize!='" + shapesize + "'");
+            }
+
+            TQWMS.runSqlUpdate(TQSqlist);
+            YUNl_DB.runSqlUpdate(MQSqlist);
+            SQLFactory.createUpdateSQL(dbConnect, "plm_item").setValue("WMSUPLOADFLAG", 2).setWhere("siteid", "MD").setWhere("itemno", itemRows.toArrayList("itemno")).update();
+        }
+    }
+
+    public void getMcode() throws YosException {
+        Rows skuRows = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "itemno", "sku").setWhere("siteid", "MD").setWhere("wmsuploadflag<2").query();
+        if (skuRows.isNotEmpty()) {
+            ArrayList<String> tqskus = SQLFactory.createQuerySQL(TQWMS, "TMaterialsSerialNo", "SerialNo").setWhere("SerialNo", skuRows.toArrayList("sku")).query().toArrayList("SerialNo");
+            ArrayList<String> mqskus = SQLFactory.createQuerySQL(TQWMS, "ST_SNState", "cInvSN").setWhere("cInvSN", skuRows.toArrayList("sku")).query().toArrayList("cInvSN");
+
+            ArrayList<String> TQSqlist = new ArrayList<>();
+            ArrayList<String> MQSqlist = new ArrayList<>();
+
+            for (Row skuRow : skuRows) {
+                String itemno = skuRow.getString("itemno");
+                String sku = skuRow.getString("sku");
+
+                if (tqskus.contains(sku)) {
+                    TQSqlist.add("update TMaterialsSerialNo set ModifyDate=getDate(),Status=3, MaterialCode='" + itemno + "' where SerialNo='" + sku + "' and  MaterialCode!='" + itemno + "'");
+                } else {
+                    TQSqlist.add("insert into TMaterialsSerialNo(SerialNo,MaterialCode,CreateDate,ModifyDate,IsDeleted,Status,sysfrom) values('" + sku + "','" + itemno + "',getDate(),getDate(),0,0,'DRP' )");
+                }
+
+                if (mqskus.contains(sku)) {
+                    MQSqlist.add("update ST_SNState set mqwmsstatus=0, cInvCode='" + itemno + "' where cInvSN='" + sku + "' and  cInvCode!='" + itemno + "'");
+                } else {
+                    MQSqlist.add("insert into ST_SNState(cInvCode,cInvSN,status,wmsstatus,ACCID,mqwmsstatus) values('" + itemno + "','" + sku + "',1,1,'DRP',0 )");
+                }
+            }
+
+            TQWMS.runSqlUpdate(TQSqlist);
+            YUNl_DB.runSqlUpdate(MQSqlist);
+            SQLFactory.createUpdateSQL(dbConnect, "sa_itemsku").setValue("WMSUPLOADFLAG", 2).setWhere("siteid", "MD").setWhere("sku", skuRows.toArrayList("sku")).update();
+        }
+    }
+
+}

+ 2 - 2
src/resources/application.yaml

@@ -11,7 +11,7 @@ system:
   db:
     driver: "com.mysql.cj.jdbc.Driver"
     username: "root"
-    password: "123456"
-    url: "jdbc:mysql://127.0.0.1:3306/yos3"
+    password: "rootroot"
+    url: "jdbc:mysql://127.0.0.1:3306/mdyos"
     #url: jdbc:mysql://host.docker.internal:3306/yos3
     servicename: "mysql80"

+ 1 - 1
src/resources/log4j2.xml

@@ -8,7 +8,7 @@
                      fileName="c://yos/yoslog.log"
                      filePattern="c://yos/logs/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH-mm-ss}-%i.log.gz"
                      append="true"
-                     immediateFlush="true">
+                     immediateFlush="false">
             <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
             <Policies>
                 <SizeBasedTriggeringPolicy size="10MB"/>