|
|
@@ -28,7 +28,9 @@ import java.util.*;
|
|
|
public class StockAutoDockDispatchService extends ServiceController {
|
|
|
|
|
|
private static Logger logger = Logger.getLogger(DispatchAutoCloseService.class);
|
|
|
- String siteid="CCYOSG";
|
|
|
+ // String siteid="CCYOSG";
|
|
|
+ String siteid = "DLB";
|
|
|
+
|
|
|
@Override
|
|
|
public void serviceRun() throws YosException {
|
|
|
//
|
|
|
@@ -38,19 +40,19 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
ERPDocking erpDocking = new ERPDocking();
|
|
|
- JSONArray ErpSainvoices = erpDocking.queryErpStockBill(500, 1,"销售出库");
|
|
|
- JSONArray flags=new JSONArray();
|
|
|
+ JSONArray ErpSainvoices = erpDocking.queryErpStockBill(500, 1, "销售出库");
|
|
|
+ JSONArray flags = new JSONArray();
|
|
|
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='"+siteid+"' and agentnum='" + fagentnum + "'").isNotEmpty()) {
|
|
|
- sys_enterpriseid = dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='"+siteid+"' and agentnum='" + fagentnum + "'").get(0).getLong("sys_enterpriseid");
|
|
|
+ if (dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='" + siteid + "' and agentnum='" + fagentnum + "'").isNotEmpty()) {
|
|
|
+ sys_enterpriseid = dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='" + siteid + "' and agentnum='" + fagentnum + "'").get(0).getLong("sys_enterpriseid");
|
|
|
} else {
|
|
|
- JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "4");
|
|
|
flag.put("fupdatewarnlog", "yos中不存在【" + fagentnum + "】经销商");
|
|
|
flags.add(flag);
|
|
|
@@ -82,21 +84,21 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
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='"+siteid+"' and billno='" + fsourcebillno + "'").isNotEmpty()) {
|
|
|
- sa_dispatchid = dbConnect.runSqlQuery("select sa_dispatchid from sa_dispatch where siteid='"+siteid+"' and billno='" + fsourcebillno + "'").get(0).getLong("sa_dispatchid");
|
|
|
+ long sa_dispatchid = 0;
|
|
|
+ if (StringUtils.isNotBlank(fsourcebillno)) {
|
|
|
+ if (dbConnect.runSqlQuery("select sa_dispatchid from sa_dispatch where siteid='" + siteid + "' and billno='" + fsourcebillno + "'").isNotEmpty()) {
|
|
|
+ sa_dispatchid = dbConnect.runSqlQuery("select sa_dispatchid from sa_dispatch where siteid='" + siteid + "' and billno='" + fsourcebillno + "'").get(0).getLong("sa_dispatchid");
|
|
|
} else {
|
|
|
- JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "4");
|
|
|
flag.put("fupdatewarnlog", "yos中不存在对应的发货单");
|
|
|
flags.add(flag);
|
|
|
continue;
|
|
|
}
|
|
|
- }else {
|
|
|
- JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ } else {
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "4");
|
|
|
flag.put("fupdatewarnlog", "yos中不存在对应的发货单");
|
|
|
flags.add(flag);
|
|
|
@@ -106,7 +108,7 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
|
|
|
Long sa_cashbillid = 0L;
|
|
|
|
|
|
- Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='"+siteid+"' and status='审核' and billno='" + fbillnum + "'");
|
|
|
+ Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='" + siteid + "' and status='审核' and billno='" + fbillnum + "'");
|
|
|
Long st_stockbillid = 0L;
|
|
|
if (stockbillRows.isEmpty() && "审核".equals(fstatus)) {
|
|
|
/**
|
|
|
@@ -143,12 +145,12 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
}
|
|
|
Rows rows;
|
|
|
if (!str.toString().equals("")) {
|
|
|
- rows = dbConnect.runSqlQuery("select * from plm_item where siteid='"+siteid+"' and itemno in " + "(" + str.toString() + ")");
|
|
|
+ rows = dbConnect.runSqlQuery("select * from plm_item where siteid='" + siteid + "' and itemno in " + "(" + str.toString() + ")");
|
|
|
} else {
|
|
|
- rows = dbConnect.runSqlQuery("select * from plm_item where siteid='"+siteid+"' and itemno in('')");
|
|
|
+ rows = dbConnect.runSqlQuery("select * from plm_item where siteid='" + siteid + "' 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='"+siteid+"' and t1.sa_dispatchid = " + sa_dispatchid);
|
|
|
+ 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='" + siteid + "' 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='"+siteid+"' and t1.sa_aftersalesmag_itemsid in " + sa_dispatch_itemsids.toString().replace("[", "(").replace("]", ")"));
|
|
|
@@ -182,7 +184,7 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
|
|
|
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("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")));
|
|
|
@@ -219,8 +221,9 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
|
|
|
sqlList.add(sqlFactorydetail.getSQL());
|
|
|
}
|
|
|
- sqlList.add("update st_stockbill set status='审核',checkby='" + createby + "',checkdate=CURRENT_TIMESTAMP where st_stockbillid = " + st_stockbillid + " and siteid='"+siteid+"'"); JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ sqlList.add("update st_stockbill set status='审核',checkby='" + createby + "',checkdate=CURRENT_TIMESTAMP where st_stockbillid = " + st_stockbillid + " and siteid='" + siteid + "'");
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "1");
|
|
|
flag.put("fupdatewarnlog", "");
|
|
|
flags.add(flag);
|
|
|
@@ -229,9 +232,9 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
/**
|
|
|
* DRP存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需将当前销售出库单先反审核,修改内容后再进行审核
|
|
|
*/
|
|
|
- sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='"+siteid+"'");
|
|
|
- JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='" + siteid + "'");
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "99");
|
|
|
flag.put("fupdatewarnlog", "");
|
|
|
flags.add(flag);
|
|
|
@@ -240,16 +243,16 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
/**
|
|
|
* DRP存在收入凭证,且中间表状态为新建或在删除状态时,DRP中需将当前收入销售出库单先反审核
|
|
|
*/
|
|
|
- sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='"+siteid+"'");
|
|
|
- JSONObject flag =new JSONObject();
|
|
|
- flag.put("syncyosid",erpSainvoice.getStringValue("syncyosid"));
|
|
|
+ sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = " + stockbillRows.get(0).getLong("st_stockbillid") + " and siteid='" + siteid + "'");
|
|
|
+ JSONObject flag = new JSONObject();
|
|
|
+ flag.put("syncyosid", erpSainvoice.getStringValue("syncyosid"));
|
|
|
flag.put("fupdateflag", "1");
|
|
|
flag.put("fupdatewarnlog", "");
|
|
|
flags.add(flag);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(erpDocking.updateErpupdateFlag(flags).equals("true")){
|
|
|
+ if (erpDocking.updateErpupdateFlag(flags).equals("true")) {
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
/**
|
|
|
* 如单据为新建状态,则,先把单据强行删除掉
|
|
|
@@ -271,9 +274,10 @@ public class StockAutoDockDispatchService extends ServiceController {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
public void sendMsg(String content, Long st_stockbillid, Long sys_enterpriseid) throws YosException {
|
|
|
|
|
|
- ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid,siteid).toArrayList("userid", new ArrayList<>());
|
|
|
+ ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid, siteid).toArrayList("userid", new ArrayList<>());
|
|
|
Remind remind = new Remind(new Controller(new JSONObject()));
|
|
|
remind.setTitle("销售出库单消息");
|
|
|
remind.setContent(content);
|