|
|
@@ -35,6 +35,7 @@ public class DispatchAutoCloseService extends ServiceController {
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
ERPDocking erpDocking =new ERPDocking();
|
|
|
JSONArray ErpSainvoices = erpDocking.queryErpSainvoices(10000, 1, new JSONArray(), "", "", "", true);
|
|
|
+ JSONArray dispatchids =new JSONArray();
|
|
|
if(!ErpSainvoices.isEmpty()){
|
|
|
for (Object ErpSainvoice:ErpSainvoices) {
|
|
|
JSONObject erpSainvoice = (JSONObject) ErpSainvoice;
|
|
|
@@ -43,6 +44,7 @@ public class DispatchAutoCloseService extends ServiceController {
|
|
|
if(rowsMap1.containsKey(billno)){
|
|
|
if(rowsMap1.get(billno).isNotEmpty()){
|
|
|
sa_dispatchid=rowsMap1.get(billno).get(0).getLong("sa_dispatchid");
|
|
|
+ dispatchids.add(sa_dispatchid);
|
|
|
}else{
|
|
|
logger.info("发货单【"+billno+"】不存在:");
|
|
|
continue;
|
|
|
@@ -125,6 +127,34 @@ public class DispatchAutoCloseService extends ServiceController {
|
|
|
}
|
|
|
}
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+
|
|
|
+ //判断当前单据是否已实际发完货,如果发完,则生把订单变为关闭状态
|
|
|
+ Rows orderRows =new Rows();
|
|
|
+ if(dispatchids.size()>0){
|
|
|
+ String sql ="select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='CCYOSG' and t2.sa_dispatchid in" + dispatchids.toJSONString();
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ logger.info("sql:"+sql);
|
|
|
+ orderRows =dbConnect.runSqlQuery(sql);
|
|
|
+ }
|
|
|
+ //总数量
|
|
|
+ Rows totalRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems where siteid='CCYOSG' group by sa_orderid");
|
|
|
+ RowsMap totalRowsMap=totalRows.toRowsMap("sa_orderid");
|
|
|
+ //已发完数量
|
|
|
+ Rows deliRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems t1 inner join (SELECT t1.sa_orderitemsid,t1.siteid,SUM(ifnull(t1.outwarehouseqty,0)) outwarehouseqty FROM sa_dispatch_items t1 WHERE t1.siteid='CCYOSG' group by t1.sa_orderitemsid,t1.siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.qty=t2.outwarehouseqty and t1.siteid='CCYOSG' group by sa_orderid");
|
|
|
+ RowsMap deliRowsMap=deliRows.toRowsMap("sa_orderid");
|
|
|
+ if(orderRows.size()>0){
|
|
|
+ for (Row row:orderRows) {
|
|
|
+ logger.info("订单id:"+row.getString("sa_orderid"));
|
|
|
+ if(totalRowsMap.containsKey(row.getString("sa_orderid")) && deliRowsMap.containsKey(row.getString("sa_orderid"))){
|
|
|
+ if (totalRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count") ==deliRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count")) {
|
|
|
+ logger.info("订单关闭:update sa_order set status='关闭' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='CCYOSG'");
|
|
|
+ dbConnect.runSqlUpdate("update sa_order set status='关闭' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='CCYOSG'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|