Browse Source

同步出库单

hu 1 năm trước cách đây
mục cha
commit
2220f294ab

BIN
out/artifacts/yos/yos.war


+ 1 - 1
src/custom/service/AftersalesmagAutoRecheckService.java

@@ -65,7 +65,7 @@ public class AftersalesmagAutoRecheckService extends ServiceController {
 
                     HashMap<String, String> map = new HashMap<>();
                     map.put("content-Type", "application/json");
-                    String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+                    String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
 
                     JSONObject resultobject = JSONObject.parseObject(result);
                     try {

+ 2 - 2
src/custom/service/DispatchAutoCloseService.java

@@ -74,7 +74,7 @@ public class DispatchAutoCloseService extends ServiceController {
 
                     HashMap<String, String> map = new HashMap<>();
                     map.put("content-Type", "application/json");
-                    String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+                    String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
                     JSONObject resultobject = JSONObject.parseObject(result);
 
                     try {
@@ -200,7 +200,7 @@ public class DispatchAutoCloseService extends ServiceController {
 
                     HashMap<String, String> map = new HashMap<>();
                     map.put("content-Type", "application/json");
-                    String result = new WebRequest().doPost(jsonobject.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+                    String result = new WebRequest().doPost(jsonobject.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
                     JSONObject resultobject = JSONObject.parseObject(result);
                     if (resultobject.getString("errcode").equals("0")) {
                         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 sa_dispatch_items where sa_dispatchid=" + sa_dispatchid + ")");

+ 2 - 0
src/custom/service/SQL/数据操作日志新增.sql

@@ -0,0 +1,2 @@
+insert into sys_contrllog (siteid, sys_contrllogid,ownertable,ownerid,action, remarks,actionuserid,actionby)
+values ($siteid$, $sys_contrllogid$,$ownertable$,$ownerid$, $action$, $remarks$,$actionuserid$, $actionby$);

+ 2 - 0
src/custom/service/SQL/销售出库单新增.sql

@@ -0,0 +1,2 @@
+insert into st_stockbill (siteid, st_stockbillid,createby, createdate, billno,billdate,changeby, changedate,checkby,checkdate,sys_enterpriseid, rb,type,remarks)
+values ($siteid$, $st_stockbillid$,$createby$, $createdate$, $billno$,$billdate$, $changeby$, $changedate$,$checkby$,$checkdate$,$sys_enterpriseid$,$rb$,$type$,$remarks$);

+ 13 - 0
src/custom/service/SQL/销售出库单明细新增.sql

@@ -0,0 +1,13 @@
+insert into st_stockbill_items (siteid, st_stockbill_itemsid,st_stockbillid, sa_dispatch_itemsid, rowno, itemid, qty,amount,remarks,price,sa_orderitemsid,sa_orderid)
+select $siteid$,
+       $st_stockbill_itemsid$,
+       $st_stockbillid$,
+       $sa_dispatch_itemsid$,
+       $rowno$,
+       $itemid$,
+       $qty$,
+       $amount$,
+       $remarks$,
+       $price$,
+       $sa_orderitemsid$,
+       $sa_orderid$

+ 278 - 0
src/custom/service/StockAutoDockAftersalesmagService.java

@@ -0,0 +1,278 @@
+package service;
+
+import beans.remind.Remind;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.ServiceController;
+import common.YosException;
+import common.data.Rows;
+import common.data.RowsMap;
+import common.data.SQLFactory;
+import common.parameter.properties;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import utility.ERPDocking;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Properties;
+
+public class StockAutoDockAftersalesmagService extends ServiceController {
+
+    private static Logger logger = Logger.getLogger(DispatchAutoCloseService.class);
+
+    @Override
+    public void serviceRun() throws YosException {
+        //
+        Properties yosProperties = properties.getYosProperties();
+        if (yosProperties.getProperty("system.runmode.debug").equalsIgnoreCase("false")) {
+
+            ArrayList<String> sqlList = new ArrayList<>();
+            ERPDocking erpDocking = new ERPDocking();
+            JSONArray ErpSainvoices = erpDocking.queryErpStockBill(10000, 1,"销售退货");
+            JSONArray flags=new JSONArray();
+            String siteid = "ccyosg";
+            if (!ErpSainvoices.isEmpty()) {
+                for (Object ErpSainvoice : ErpSainvoices) {
+                    JSONObject erpSainvoice = (JSONObject) ErpSainvoice;
+                    // 经销商编号
+                    String fagentnum = erpSainvoice.getString("fagentnum");
+                    long sys_enterpriseid = 0;
+                    if (dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='ccyosg' and  agentnum='" + fagentnum + "'").isNotEmpty()) {
+                        sys_enterpriseid = dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='ccyosg' and  agentnum='" + fagentnum + "'").get(0).getLong("sys_enterpriseid");
+                    } else {
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "4");
+                        flag.put("fupdatewarnlog", "yos中不存在【" + fagentnum + "】经销商");
+                        flags.add(flag);
+                        continue;
+                    }
+                    //单号
+                    String fbillnum = erpSainvoice.getString("fbillnum");
+                    // 单据日期
+                    String fdate = erpSainvoice.getString("fdate");
+                    // 会计期间
+                    //  String fperiod = content.getString("fperiod");
+                    // 红蓝字
+                    String frb = erpSainvoice.getString("frb");
+                    // 表头仓库
+                    // String fstockno = content.getString("fstockno");
+                    // 单据类型明细
+                    //String ftypemx = content.getString("ftypemx");
+                    // 单据状态
+                    String fstatus = erpSainvoice.getString("fstatus");
+                    // 制单人
+                    String createby = erpSainvoice.getString("createby");
+                    // 制单日期
+                    String createdate = erpSainvoice.getString("createdate");
+//                    // 审核人
+//                    String checkby = erpSainvoice.getString("checkby");
+//                    // 审核日期
+//                    String checkdate = erpSainvoice.getString("checkdate");
+                    // 备注
+                    String fnotes = erpSainvoice.getString("fnote");
+                    String fsourcebillno = erpSainvoice.getString("fsourcebillno");
+                    long sa_aftersalesmagid=0;
+                    if(StringUtils.isNotBlank(fsourcebillno)){
+                        if (dbConnect.runSqlQuery("select sa_aftersalesmagid from sa_aftersalesmag where siteid='ccyosg' and  billno='" + fsourcebillno + "'").isNotEmpty()) {
+                            sa_aftersalesmagid = dbConnect.runSqlQuery("select sa_aftersalesmagid from sa_aftersalesmag where siteid='ccyosg' and  billno='" + fsourcebillno + "'").get(0).getLong("sa_aftersalesmagid");
+                        } else {
+                            JSONObject flag =new JSONObject();
+                            flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                            flag.put("fupdateflag", "4");
+                            flag.put("fupdatewarnlog", "yos中不存在对应的退货单");
+                            flags.add(flag);
+                            continue;
+                        }
+                    }else {
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "4");
+                        flag.put("fupdatewarnlog", "yos中不存在对应的退货单");
+                        flags.add(flag);
+                        continue;
+                    }
+
+
+                    Long sa_cashbillid = 0L;
+
+                    Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='ccyosg' and status='审核' and billno='" + fbillnum + "'");
+                    Long st_stockbillid = 0L;
+                    if (stockbillRows.isEmpty() && "审核".equals(fstatus)) {
+                        /**
+                         * DRP不存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需新增该销售出库单
+                         */
+                        SQLFactory sqlFactory = new SQLFactory(this, "销售出库单新增");
+                        st_stockbillid = createTableID("st_stockbill");
+                        sqlFactory.addParameter("siteid", "ccyosg");
+                        sqlFactory.addParameter("st_stockbillid", st_stockbillid);
+                        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+                        sqlFactory.addParameter("billno", fbillnum);
+                        sqlFactory.addParameter("type", "销售退货");
+                        sqlFactory.addParameter("rb", frb.equals("蓝") ? 1 : 0);
+                        sqlFactory.addParameter("billdate", fdate);
+                        sqlFactory.addParameter("createby", createby);
+                        sqlFactory.addParameter("createdate", getDate(createdate));
+                        sqlFactory.addParameter("changeby", createby);
+                        sqlFactory.addParameter("changedate", getDate(createdate));
+                        sqlFactory.addParameter("checkby", createby);
+                        sqlFactory.addParameter("checkdate", getDate(createdate));
+                        sqlFactory.addParameter("remarks", fnotes);
+                        sqlList.add(sqlFactory.getSQL());
+
+                        JSONArray detailarray = erpSainvoice.getJSONArray("details");
+                        StringBuffer str = new StringBuffer();
+
+                        for (Object object : detailarray) {
+                            JSONObject jsonObject = (JSONObject) object;
+                            if (str.toString().equals("")) {
+                                str.append("'" + jsonObject.getString("fitemno") + "'");
+                            } else {
+                                str.append(",'" + jsonObject.getString("fitemno") + "'");
+                            }
+                        }
+                        Rows rows;
+                        if (!str.toString().equals("")) {
+                            rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='ccyosg' and itemno in " + "(" + str.toString() + ")");
+                        } else {
+                            rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='ccyosg' and itemno in('')");
+                        }
+                        RowsMap itemRowsMap = rows.toRowsMap("itemno");
+//                        Rows distiptchRows = dbConnect.runSqlQuery("select t2.price,t1.sa_dispatch_itemsid,t1.rowno,t1.sa_orderitemsid,t2.sa_orderid,t3.sys_enterpriseid,t4.sonum,t5.itemno,t5.itemname from sa_dispatch_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid inner join sa_dispatch t3 on t1.sa_dispatchid=t3.sa_dispatchid and t1.siteid=t3.siteid left join sa_order t4 on t2.sa_orderid=t4.sa_orderid and t2.siteid=t4.siteid left join plm_item t5 on t1.itemid=t5.itemid and t1.siteid=t5.siteid where t3.status in('审核','复核','关闭') and  t1.siteid='ccyosg' and  t1.sa_dispatchid = " + sa_dispatchid);
+//                        RowsMap distiptchRowsMap = distiptchRows.toRowsMap("rowno");
+
+                        Rows aftersalesmagRows = dbConnect.runSqlQuery("select t1.price,t1.sa_aftersalesmag_itemsid,t1.rowno,t1.sa_orderitemsid,t2.sa_orderid from sa_aftersalesmag_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid  where  t1.siteid='ccyosg' and  t1.sa_aftersalesmagid in " +sa_aftersalesmagid);
+                        RowsMap aftersalesmagRowsMap = aftersalesmagRows.toRowsMap("rowno");
+                        BigDecimal amountTotal = BigDecimal.ZERO;
+                        for (Object object : detailarray) {
+                            JSONObject jsonObject = (JSONObject) object;
+                            String frownum = jsonObject.getString("fentryno");
+                            String fitemno = jsonObject.getString("fitemno");
+                            String fbatchno = jsonObject.getString("fbatchno");
+
+                            System.err.println(frownum + ":" + fitemno);
+                            BigDecimal fqty = new BigDecimal(jsonObject.getString("fqty"));
+                            fqty = fqty.compareTo(BigDecimal.ZERO) < 0 ? fqty.negate() : fqty;
+                            //String fdetailstockno = jsonObject.getString("fstockno");
+                            //String fbatchno = jsonObject.getString("fbatchno");
+                            String fdetailnotes = jsonObject.getString("fnote");
+                            SQLFactory sqlFactorydetail = new SQLFactory(this, "销售出库单明细新增");
+                            sqlFactorydetail.addParameter("siteid", "ccyosg");
+                            sqlFactorydetail.addParameter("st_stockbill_itemsid", createTableID("st_stockbill_items"));
+                            sqlFactorydetail.addParameter("st_stockbillid", st_stockbillid);
+                            sqlFactorydetail.addParameter("rowno", frownum);
+                            sqlFactorydetail.addParameter("remarks", fnotes);
+                            if (itemRowsMap.containsKey(fitemno) && itemRowsMap.get(fitemno).isNotEmpty()) {
+                                sqlFactorydetail.addParameter("itemid", itemRowsMap.get(fitemno).get(0).getLong("itemid"));
+                            } else {
+                                sqlFactorydetail.addParameter("itemid", 0);
+                            }
+                            sqlFactorydetail.addParameter("remarks", fdetailnotes);
+                            sqlFactorydetail.addParameter("qty", fqty);
+
+//                            if (frb.equals("蓝")) {
+//                                if (aftersalesmagRows.containsKey(String.valueOf(frownum)) && aftersalesmagRows.get(frownum).isNotEmpty()) {
+//                                    sqlFactorydetail.addParameter("sa_dispatch_itemsid",  distiptchRowsMap.get(frownum).get(0).getLong("sa_dispatch_itemsid"));
+//                                    sqlFactorydetail.addParameter("price", distiptchRowsMap.get(frownum).get(0).getBigDecimal("price"));
+//                                    amountTotal = amountTotal.add(fqty.multiply(distiptchRowsMap.get(frownum).get(0).getBigDecimal("price")));
+//                                    sqlFactorydetail.addParameter("amount", fqty.multiply(distiptchRowsMap.get(frownum).get(0).getBigDecimal("price")));
+//                                    sqlFactorydetail.addParameter("sa_orderitemsid", distiptchRowsMap.get(frownum).get(0).getLong("sa_orderitemsid"));
+//                                    sqlFactorydetail.addParameter("sa_orderid", distiptchRowsMap.get(frownum).get(0).getLong("sa_orderid"));
+//                                    System.out.println(amountTotal);
+//                                    //您的订单【XXX】商品【XXX】工厂已发货,出库单号【XXX】
+//                                    String message = "您的订单【" + distiptchRowsMap.get(frownum).get(0).getString("sonum") + "】商品【" + distiptchRowsMap.get(frownum).get(0).getString("itemname") + "】工厂已发货,出库单号【" + fbillnum + "】!";
+//                                    sendMsg(message, st_stockbillid, distiptchRowsMap.get(frownum).get(0).getLong("sys_enterpriseid"));
+//                                } else {
+//                                    sqlFactorydetail.addParameter("price", 0);
+//                                    sqlFactorydetail.addParameter("amount", 0);
+//                                    sqlFactorydetail.addParameter("sa_orderitemsid", 0);
+//                                    sqlFactorydetail.addParameter("sa_orderid", 0);
+//                                }
+//                            }
+                            if (frb.equals("红")) {
+                                if (aftersalesmagRowsMap.containsKey(String.valueOf(frownum)) && aftersalesmagRowsMap.get(frownum).isNotEmpty()) {
+                                    logger.info(aftersalesmagRowsMap.get(frownum).get(0).toJsonObject().toString());
+                                    sqlFactorydetail.addParameter("price", aftersalesmagRowsMap.get(frownum).get(0).getBigDecimal("price"));
+                                    sqlFactorydetail.addParameter("amount", fqty.multiply(aftersalesmagRowsMap.get(frownum).get(0).getBigDecimal("price")));
+                                    logger.info(aftersalesmagRowsMap.get(frownum).get(0).getBigDecimal("sa_orderitemsid"));
+                                    logger.info(aftersalesmagRowsMap.get(frownum).get(0).getBigDecimal("sa_orderid"));
+                                    sqlFactorydetail.addParameter("sa_orderitemsid", aftersalesmagRowsMap.get(frownum).get(0).getLong("sa_orderitemsid"));
+                                    sqlFactorydetail.addParameter("sa_orderid", aftersalesmagRowsMap.get(frownum).get(0).getLong("sa_orderid"));
+                                } else {
+                                    sqlFactorydetail.addParameter("price", 0);
+                                    sqlFactorydetail.addParameter("amount", 0);
+                                    sqlFactorydetail.addParameter("sa_orderitemsid", 0);
+                                    sqlFactorydetail.addParameter("sa_orderid", 0);
+                                }
+                            }
+
+                            sqlList.add(sqlFactorydetail.getSQL());
+                        }
+                        sqlList.add("update st_stockbill set status='审核',checkby='" + createby + "',checkdate=CURRENT_TIMESTAMP where st_stockbillid = " + st_stockbillid + " and siteid='ccyosg'");  JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "1");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+
+                    } else if (!stockbillRows.isEmpty() && "审核".equals(fstatus)) {
+                        /**
+                         * DRP存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需将当前销售出库单先反审核,修改内容后再进行审核
+                         */
+                        sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='ccyosg'");
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "99");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+                        continue;
+                    } else if (!stockbillRows.isEmpty() && "新建".equals(fstatus)) {
+                        /**
+                         * DRP存在收入凭证,且中间表状态为新建或在删除状态时,DRP中需将当前收入销售出库单先反审核
+                         */
+                        sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='ccyosg'");
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "1");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+                    }
+                }
+            }
+            if(erpDocking.updateErpupdateFlag(flags).equals("true")){
+                dbConnect.runSqlUpdate(sqlList);
+                /**
+                 * 如单据为新建状态,则,先把单据强行删除掉
+                 */
+                dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
+            }
+
+
+        }
+    }
+
+    public String getDate(String date) {
+        try {
+            Date a = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(date);
+            return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(a);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    public void sendMsg(String content, Long st_stockbillid, Long sys_enterpriseid) throws YosException {
+
+        ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid,"ccyosg").toArrayList("userid", new ArrayList<>());
+        Remind remind = new Remind(new Controller(new JSONObject()));
+        remind.setTitle("销售出库单消息");
+        remind.setContent(content);
+        remind.setType("应用");
+        remind.setObjectid(st_stockbillid);
+        remind.setObjectname("st_stockbill");
+        remind.setTouserid(userList);
+        remind.sendByDialogMsg().createSys_message();
+    }
+}

+ 286 - 0
src/custom/service/StockAutoDockDispatchService.java

@@ -0,0 +1,286 @@
+package service;
+
+import beans.accountbalance.Accountbalance;
+import beans.accountbalance.CashbillEntity;
+import beans.parameter.Parameter;
+import beans.remind.Remind;
+import beans.uploaderpdata.UploadDataToERP_HY;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.ServiceController;
+import common.YosException;
+import common.data.Row;
+import common.data.Rows;
+import common.data.RowsMap;
+import common.data.SQLFactory;
+import common.parameter.properties;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import restcontroller.webmanage.executorService.Executor;
+import utility.ERPDocking;
+import utility.tools.WebRequest;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class StockAutoDockDispatchService extends ServiceController {
+
+    private static Logger logger = Logger.getLogger(DispatchAutoCloseService.class);
+
+    @Override
+    public void serviceRun() throws YosException {
+        //
+        System.out.println("销售出库单自动同步任务");
+        Properties yosProperties = properties.getYosProperties();
+        if (yosProperties.getProperty("system.runmode.debug").equalsIgnoreCase("false")) {
+
+            ArrayList<String> sqlList = new ArrayList<>();
+            ERPDocking erpDocking = new ERPDocking();
+            JSONArray ErpSainvoices = erpDocking.queryErpStockBill(10000, 1,"销售出库");
+            JSONArray flags=new JSONArray();
+            String siteid = "ccyosg";
+            if (!ErpSainvoices.isEmpty()) {
+                for (Object ErpSainvoice : ErpSainvoices) {
+                    JSONObject erpSainvoice = (JSONObject) ErpSainvoice;
+                    // 经销商编号
+                    String fagentnum = erpSainvoice.getString("fagentnum");
+                    long sys_enterpriseid = 0;
+                    if (dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='ccyosg' and  agentnum='" + fagentnum + "'").isNotEmpty()) {
+                        sys_enterpriseid = dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='ccyosg' and  agentnum='" + fagentnum + "'").get(0).getLong("sys_enterpriseid");
+                    } else {
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "4");
+                        flag.put("fupdatewarnlog", "yos中不存在【" + fagentnum + "】经销商");
+                        flags.add(flag);
+                        continue;
+                    }
+                    //单号
+                    String fbillnum = erpSainvoice.getString("fbillnum");
+                    // 单据日期
+                    String fdate = erpSainvoice.getString("fdate");
+                    // 会计期间
+                    //  String fperiod = content.getString("fperiod");
+                    // 红蓝字
+                    String frb = erpSainvoice.getString("frb");
+                    // 表头仓库
+                    // String fstockno = content.getString("fstockno");
+                    // 单据类型明细
+                    //String ftypemx = content.getString("ftypemx");
+                    // 单据状态
+                    String fstatus = erpSainvoice.getString("fstatus");
+                    // 制单人
+                    String createby = erpSainvoice.getString("createby");
+                    // 制单日期
+                    String createdate = erpSainvoice.getString("createdate");
+//                    // 审核人
+//                    String checkby = erpSainvoice.getString("checkby");
+//                    // 审核日期
+//                    String checkdate = erpSainvoice.getString("checkdate");
+                    // 备注
+                    String fnotes = erpSainvoice.getString("fnote");
+                    String fsourcebillno = erpSainvoice.getString("fsourcebillno");
+                    String fsourcetype = erpSainvoice.getString("fsourcetype");
+                    long sa_dispatchid=0;
+                    if(StringUtils.isNotBlank(fsourcebillno)){
+                        if (dbConnect.runSqlQuery("select sa_dispatchid from sa_dispatch where siteid='ccyosg' and  billno='" + fsourcebillno + "'").isNotEmpty()) {
+                            sa_dispatchid = dbConnect.runSqlQuery("select sa_dispatchid from sa_dispatch where siteid='ccyosg' and  billno='" + fsourcebillno + "'").get(0).getLong("sa_dispatchid");
+                        } else {
+                            JSONObject flag =new JSONObject();
+                            flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                            flag.put("fupdateflag", "4");
+                            flag.put("fupdatewarnlog", "yos中不存在对应的发货单");
+                            flags.add(flag);
+                            continue;
+                        }
+                    }else {
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "4");
+                        flag.put("fupdatewarnlog", "yos中不存在对应的发货单");
+                        flags.add(flag);
+                        continue;
+                    }
+
+
+                    Long sa_cashbillid = 0L;
+
+                    Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='ccyosg' and status='审核' and billno='" + fbillnum + "'");
+                    Long st_stockbillid = 0L;
+                    if (stockbillRows.isEmpty() && "审核".equals(fstatus)) {
+                        /**
+                         * DRP不存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需新增该销售出库单
+                         */
+                        SQLFactory sqlFactory = new SQLFactory(this, "销售出库单新增");
+                        st_stockbillid = createTableID("st_stockbill");
+                        sqlFactory.addParameter("siteid", "ccyosg");
+                        sqlFactory.addParameter("st_stockbillid", st_stockbillid);
+                        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+                        sqlFactory.addParameter("billno", fbillnum);
+                        sqlFactory.addParameter("type", "销售出库");
+                        sqlFactory.addParameter("rb", frb.equals("蓝") ? 1 : 0);
+                        sqlFactory.addParameter("billdate", fdate);
+                        sqlFactory.addParameter("createby", createby);
+                        sqlFactory.addParameter("createdate", getDate(createdate));
+                        sqlFactory.addParameter("changeby", createby);
+                        sqlFactory.addParameter("changedate", getDate(createdate));
+                        sqlFactory.addParameter("checkby", createby);
+                        sqlFactory.addParameter("checkdate", getDate(createdate));
+                        sqlFactory.addParameter("remarks", fnotes);
+                        sqlList.add(sqlFactory.getSQL());
+
+                        JSONArray detailarray = erpSainvoice.getJSONArray("details");
+                        StringBuffer str = new StringBuffer();
+
+                        for (Object object : detailarray) {
+                            JSONObject jsonObject = (JSONObject) object;
+                            if (str.toString().equals("")) {
+                                str.append("'" + jsonObject.getString("fitemno") + "'");
+                            } else {
+                                str.append(",'" + jsonObject.getString("fitemno") + "'");
+                            }
+                        }
+                        Rows rows;
+                        if (!str.toString().equals("")) {
+                            rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='ccyosg' and itemno in " + "(" + str.toString() + ")");
+                        } else {
+                            rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='ccyosg' and itemno in('')");
+                        }
+                        RowsMap itemRowsMap = rows.toRowsMap("itemno");
+                        Rows distiptchRows = dbConnect.runSqlQuery("select t2.price,t1.sa_dispatch_itemsid,t1.rowno,t1.sa_orderitemsid,t2.sa_orderid,t3.sys_enterpriseid,t4.sonum,t5.itemno,t5.itemname from sa_dispatch_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid inner join sa_dispatch t3 on t1.sa_dispatchid=t3.sa_dispatchid and t1.siteid=t3.siteid left join sa_order t4 on t2.sa_orderid=t4.sa_orderid and t2.siteid=t4.siteid left join plm_item t5 on t1.itemid=t5.itemid and t1.siteid=t5.siteid where t3.status in('审核','复核','关闭') and  t1.siteid='ccyosg' and  t1.sa_dispatchid = " + sa_dispatchid);
+                        RowsMap distiptchRowsMap = distiptchRows.toRowsMap("rowno");
+
+//                        Rows aftersalesmagRows = dbConnect.runSqlQuery("select t1.price,t1.sa_aftersalesmag_itemsid,t1.sa_orderitemsid,t2.sa_orderid from sa_aftersalesmag_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid  where  t1.siteid='ccyosg' and  t1.sa_aftersalesmag_itemsid in " + sa_dispatch_itemsids.toString().replace("[", "(").replace("]", ")"));
+//                        RowsMap aftersalesmagRowsMap = aftersalesmagRows.toRowsMap("rowno");
+                        BigDecimal amountTotal = BigDecimal.ZERO;
+                        for (Object object : detailarray) {
+                            JSONObject jsonObject = (JSONObject) object;
+                            String frownum = jsonObject.getString("fentryno");
+                            String fitemno = jsonObject.getString("fitemno");
+                            String fbatchno = jsonObject.getString("fbatchno");
+
+                            System.err.println(frownum + ":" + fitemno);
+                            BigDecimal fqty = new BigDecimal(jsonObject.getString("fqty"));
+                            fqty = fqty.compareTo(BigDecimal.ZERO) < 0 ? fqty.negate() : fqty;
+                            //String fdetailstockno = jsonObject.getString("fstockno");
+                            //String fbatchno = jsonObject.getString("fbatchno");
+                            String fdetailnotes = jsonObject.getString("fnote");
+                            SQLFactory sqlFactorydetail = new SQLFactory(this, "销售出库单明细新增");
+                            sqlFactorydetail.addParameter("siteid", "ccyosg");
+                            sqlFactorydetail.addParameter("st_stockbill_itemsid", createTableID("st_stockbill_items"));
+                            sqlFactorydetail.addParameter("st_stockbillid", st_stockbillid);
+                            sqlFactorydetail.addParameter("rowno", frownum);
+                            sqlFactorydetail.addParameter("remarks", fnotes);
+                            if (itemRowsMap.containsKey(fitemno) && itemRowsMap.get(fitemno).isNotEmpty()) {
+                                sqlFactorydetail.addParameter("itemid", itemRowsMap.get(fitemno).get(0).getLong("itemid"));
+                            } else {
+                                sqlFactorydetail.addParameter("itemid", 0);
+                            }
+                            sqlFactorydetail.addParameter("remarks", fdetailnotes);
+                            sqlFactorydetail.addParameter("qty", fqty);
+
+                            if (frb.equals("蓝")) {
+                                if (distiptchRowsMap.containsKey(String.valueOf(frownum)) && distiptchRowsMap.get(frownum).isNotEmpty()) {
+                                    sqlFactorydetail.addParameter("sa_dispatch_itemsid",  distiptchRowsMap.get(frownum).get(0).getLong("sa_dispatch_itemsid"));
+                                    sqlFactorydetail.addParameter("price", distiptchRowsMap.get(frownum).get(0).getBigDecimal("price"));
+                                    amountTotal = amountTotal.add(fqty.multiply(distiptchRowsMap.get(frownum).get(0).getBigDecimal("price")));
+                                    sqlFactorydetail.addParameter("amount", fqty.multiply(distiptchRowsMap.get(frownum).get(0).getBigDecimal("price")));
+                                    sqlFactorydetail.addParameter("sa_orderitemsid", distiptchRowsMap.get(frownum).get(0).getLong("sa_orderitemsid"));
+                                    sqlFactorydetail.addParameter("sa_orderid", distiptchRowsMap.get(frownum).get(0).getLong("sa_orderid"));
+                                    System.out.println(amountTotal);
+                                    //您的订单【XXX】商品【XXX】工厂已发货,出库单号【XXX】
+                                    String message = "您的订单【" + distiptchRowsMap.get(frownum).get(0).getString("sonum") + "】商品【" + distiptchRowsMap.get(frownum).get(0).getString("itemname") + "】工厂已发货,出库单号【" + fbillnum + "】!";
+                                    sendMsg(message, st_stockbillid, distiptchRowsMap.get(frownum).get(0).getLong("sys_enterpriseid"));
+                                } else {
+                                    sqlFactorydetail.addParameter("price", 0);
+                                    sqlFactorydetail.addParameter("amount", 0);
+                                    sqlFactorydetail.addParameter("sa_orderitemsid", 0);
+                                    sqlFactorydetail.addParameter("sa_orderid", 0);
+                                }
+                            }
+//                            else {
+//                                if (aftersalesmagRowsMap.containsKey(String.valueOf(sainvoicedetailid)) && aftersalesmagRowsMap.get(sainvoicedetailid).isNotEmpty()) {
+//                                    logger.info(aftersalesmagRowsMap.get(sainvoicedetailid).get(0).toJsonObject().toString());
+//                                    sqlFactorydetail.addParameter("price", aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getBigDecimal("price"));
+//                                    sqlFactorydetail.addParameter("amount", fqty.multiply(aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getBigDecimal("price")));
+//                                    logger.info(aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getBigDecimal("sa_orderitemsid"));
+//                                    logger.info(aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getBigDecimal("sa_orderid"));
+//                                    sqlFactorydetail.addParameter("sa_orderitemsid", aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getLong("sa_orderitemsid"));
+//                                    sqlFactorydetail.addParameter("sa_orderid", aftersalesmagRowsMap.get(sainvoicedetailid).get(0).getLong("sa_orderid"));
+//                                } else {
+//                                    sqlFactorydetail.addParameter("price", 0);
+//                                    sqlFactorydetail.addParameter("amount", 0);
+//                                    sqlFactorydetail.addParameter("sa_orderitemsid", 0);
+//                                    sqlFactorydetail.addParameter("sa_orderid", 0);
+//                                }
+//                            }
+
+                            sqlList.add(sqlFactorydetail.getSQL());
+                        }
+                        sqlList.add("update st_stockbill set status='审核',checkby='" + createby + "',checkdate=CURRENT_TIMESTAMP where st_stockbillid = " + st_stockbillid + " and siteid='ccyosg'");  JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "1");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+
+                    } else if (!stockbillRows.isEmpty() && "审核".equals(fstatus)) {
+                        /**
+                         * DRP存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需将当前销售出库单先反审核,修改内容后再进行审核
+                         */
+                        sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='ccyosg'");
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "99");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+                        continue;
+                    } else if (!stockbillRows.isEmpty() && "新建".equals(fstatus)) {
+                        /**
+                         * DRP存在收入凭证,且中间表状态为新建或在删除状态时,DRP中需将当前收入销售出库单先反审核
+                         */
+                        sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='ccyosg'");
+                        JSONObject flag =new JSONObject();
+                        flag.put("syncyosid",erpSainvoice.getStringValue("tstockbillid"));
+                        flag.put("fupdateflag", "1");
+                        flag.put("fupdatewarnlog", "");
+                        flags.add(flag);
+                    }
+                }
+            }
+            if(erpDocking.updateErpupdateFlag(flags).equals("true")){
+                dbConnect.runSqlUpdate(sqlList);
+                /**
+                 * 如单据为新建状态,则,先把单据强行删除掉
+                 */
+                dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid in(select st_stockbillid from st_stockbill where status='新建')");
+                dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
+            }
+
+
+        }
+    }
+
+    public String getDate(String date) {
+        try {
+            Date a = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(date);
+            return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(a);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    public void sendMsg(String content, Long st_stockbillid, Long sys_enterpriseid) throws YosException {
+
+        ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid,"ccyosg").toArrayList("userid", new ArrayList<>());
+        Remind remind = new Remind(new Controller(new JSONObject()));
+        remind.setTitle("销售出库单消息");
+        remind.setContent(content);
+        remind.setType("应用");
+        remind.setObjectid(st_stockbillid);
+        remind.setObjectname("st_stockbill");
+        remind.setTouserid(userList);
+        remind.sendByDialogMsg().createSys_message();
+    }
+}

+ 86 - 12
src/custom/utility/ERPDocking.java

@@ -80,7 +80,7 @@ public class ERPDocking {
 
         HashMap<String, String> map = new HashMap<>();
         map.put("content-Type", "application/json");
-        String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+        String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
         JSONObject resultobject = JSONObject.parseObject(result);
         System.out.println(object.toString());
         System.out.println(resultobject.toJSONString());
@@ -118,7 +118,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             if(resultobject.getString("errcode").equals("0")){
                 return resultobject.getJSONObject("results").getJSONArray("list");
@@ -158,7 +158,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             if(resultobject.getString("errcode").equals("0")){
                 return resultobject.getJSONObject("results").getJSONArray("list");
@@ -214,7 +214,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
 
             saveLog(controller,"sa_dispatch",sa_dispatchid,"创建erp发货单",object.toString(),resultobject,dispatchRow.getString("billno"));
@@ -246,7 +246,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             System.out.println(resultobject);
             if(resultobject.getString("errcode").equals("error")){
@@ -291,7 +291,7 @@ public class ERPDocking {
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
             System.out.println(object.toString());
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             System.out.println(resultobject);
             if(resultobject.getString("errcode").equals("error")){
@@ -322,7 +322,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
 
             saveLog(controller,"sa_dispatch",sa_dispatchid,"关闭发货单",object.toString(),resultobject,billno);
@@ -360,7 +360,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
 
             saveLog(controller,"sa_dispatch",sa_dispatchid,"发货单行关闭",object.toString(),resultobject,billno);
@@ -419,7 +419,7 @@ public class ERPDocking {
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
             System.out.println(object.toString());
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
 
             saveLog(controller,"sa_aftersalesmag",sa_aftersalesmagid,"创建erp退/换货单",object.toString(),resultobject,aftersalesmagRow.getString("billno"));
@@ -451,7 +451,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             System.out.println(resultobject);
             if(resultobject.getString("errcode").equals("error")){
@@ -494,7 +494,7 @@ public class ERPDocking {
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
             System.out.println(object.toString());
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
             System.out.println(resultobject);
             if(resultobject.getString("errcode").equals("error")){
@@ -525,7 +525,7 @@ public class ERPDocking {
 
             HashMap<String, String> map = new HashMap<>();
             map.put("content-Type", "application/json");
-            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8001/rest/ws_v2/basicDrp", map);
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
             JSONObject resultobject = JSONObject.parseObject(result);
 
             saveLog(controller,"sa_aftersalesmag",sa_aftersalesmagid,"复核erp退/换货单",object.toString(),resultobject,billno);
@@ -589,6 +589,80 @@ public class ERPDocking {
         }
         return issuccess;
     }
+
+    /**
+     * 查询销售出库单
+     * @param pagerows
+     * @param pagenum
+     * @return
+     * @throws YosException
+     */
+    public JSONArray queryErpStockBill(int pagerows, int pagenum,String fbtname) throws YosException {
+        {
+            JSONArray fupdateFlags=new JSONArray();
+            fupdateFlags.add(0);
+            fupdateFlags.add(99);
+            fupdateFlags.add(2);
+            JSONObject object= new JSONObject();
+            JSONObject objectdetail= new JSONObject();
+            object.put("access_token","basicDrp");
+            object.put("classname","TstockbillOuts");
+            object.put("method","queryPageForSyncYos");
+            objectdetail.put("pagenum",pagenum);
+            objectdetail.put("pagerows",pagerows);
+            objectdetail.put("fbillnums",new JSONArray());
+            objectdetail.put("fagentnum","");
+            objectdetail.put("fstatus","审核");
+            objectdetail.put("frb","");
+            objectdetail.put("fstockno","");
+            objectdetail.put("fbtname",fbtname);
+            objectdetail.put("fminperiod","");
+            objectdetail.put("fupdateFlags",fupdateFlags);
+
+            object.put("content",objectdetail);
+
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            System.out.println(object.toString());
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
+            JSONObject resultobject = JSONObject.parseObject(result);
+            System.out.println(resultobject);
+            if(resultobject.getString("errcode").equals("error")){
+                return new JSONArray();
+            }else {
+                return resultobject.getJSONObject("results").getJSONArray("list");
+            }
+        }
+    }
+
+    /**
+     * 更新erp出库单标志
+     * @return
+     * @throws YosException
+     */
+    public String updateErpupdateFlag(JSONArray flags) throws YosException {
+        {
+
+            JSONObject object= new JSONObject();
+            JSONObject objectdetail= new JSONObject();
+            object.put("access_token","basicDrp");
+            object.put("classname","TstockbillOuts");
+            object.put("method","syncFupdateFlags");
+            objectdetail.put("flags",flags);
+            object.put("content",objectdetail);
+
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            String result = new WebRequest().doPost(object.toString(), "http://124.71.196.182:8101/rest/ws_v2/basicDrp", map);
+            JSONObject resultobject = JSONObject.parseObject(result);
+
+            if(resultobject.getString("errcode").equals("0")){
+                return "true";
+            }else {
+                return resultobject.getString("errmsg");
+            }
+        }
+    }
 //    /**
 //     * crm账号同步反馈
 //     *