|
|
@@ -22,89 +22,97 @@ public class GetOutCodeFromTQWms extends ServiceController {
|
|
|
}
|
|
|
|
|
|
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()) {
|
|
|
- logger.info("监测到有{}个出库序列号", rows.size());
|
|
|
+ Rows wmsrows = 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 (wmsrows.isNotEmpty()) {
|
|
|
+ logger.info("监测到有{}个出库序列号", wmsrows.size());
|
|
|
QuerySQL billCheckSQL = SQLFactory.createQuerySQL(dbConnect, "st_stockbill", "billno", "st_stockbillid", "sys_enterpriseid", "status", "iswx").setTableAlias("t1");
|
|
|
billCheckSQL.addJoinTable(JOINTYPE.left, "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"));
|
|
|
+ billCheckSQL.setWhere("t1.siteid", "MD").setWhere("t1.billno", wmsrows.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", new String[]{"101", "103"});
|
|
|
+ codeQuery.setWhere("t1.sku", wmsrows.toArrayList("serialno")).setWhere("t2.stockno", new String[]{"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");
|
|
|
- logger.info("开始处理单据{},序列号{}", billno, sku);
|
|
|
- if (!billRowsMap.containsKey(billno)) {
|
|
|
- //单据不存在
|
|
|
- TQWMS.runSqlUpdate("update TOutSerialnoDetail set status=-1 where BillNo='" + billno + "' and SerialNo='" + sku + "'");
|
|
|
- logger.info("E-订单单据{}不存在,将中间表状态改为-1", billno);
|
|
|
- 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 + "'");
|
|
|
- logger.info("E-订单单据{},序列号{}已存在,将中间表状态改为1", billno, sku);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!codeRowsMap.containsKey(sku)) {
|
|
|
- //序列号不存在或者不在101-103仓库中
|
|
|
- logger.info("E-订单序列号{}不存在于仓库101或103中", sku);
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
- Row coderow = codeRowsMap.get(sku).get(0);
|
|
|
+ RowsMap wmsbillnoMap = wmsrows.toRowsMap("billno");
|
|
|
+ for (String billno : wmsbillnoMap.keySet()) {
|
|
|
+ logger.info("开始处理单据{}", billno);
|
|
|
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");
|
|
|
- long itemid = coderow.getLong("itemid");
|
|
|
-
|
|
|
-
|
|
|
- ArrayList<Long> stockbill_itemsids = dbConnect.runSqlQuery("select t.st_stockbill_itemsid,sum(t.qty)as qty,sum(t.skucount)as skucount from (\n" +
|
|
|
- "select st_stockbill_itemsid,qty,0 as skucount from st_stockbill_items t1 where st_stockbillid=" + st_stockbillid + " and wmsuploadflag=2 and itemid=" + itemid + "\n" +
|
|
|
- "union all\n" +
|
|
|
- "select st_stockbill_itemsid,0,1 as skucount from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid + " and itemid=" + itemid + " and ifnull(st_stockbill_itemsid,0)>0 \n" +
|
|
|
- ")t group by t.st_stockbill_itemsid having sum(t.qty)>sum(t.skucount)").toArrayList("st_stockbill_itemsid", new ArrayList<>());
|
|
|
-
|
|
|
- SQLDump sqlDump = new SQLDump();
|
|
|
- //创建入库单序列号
|
|
|
- InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
|
|
|
- stStockbillItemsSku.setValue("siteid", "MD");
|
|
|
- stStockbillItemsSku.setValue("createby", "WMS");
|
|
|
- stStockbillItemsSku.setValue("itemid", itemid);
|
|
|
- stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
|
|
|
- if (!stockbill_itemsids.isEmpty()) {
|
|
|
- stStockbillItemsSku.setValue("st_stockbill_itemsid", stockbill_itemsids.get(0));
|
|
|
- }
|
|
|
- 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);
|
|
|
+
|
|
|
+
|
|
|
+ for (Row row : wmsbillnoMap.get(billno)) {
|
|
|
+ String sku = row.getString("serialno");
|
|
|
+ logger.info("开始处理序列号{}", sku);
|
|
|
+ if (!billRowsMap.containsKey(billno)) {
|
|
|
+ //单据不存在
|
|
|
+ TQWMS.runSqlUpdate("update TOutSerialnoDetail set status=-1 where BillNo='" + billno + "' and SerialNo='" + sku + "'");
|
|
|
+ logger.info("E-订单单据{}不存在,将中间表状态改为-1", billno);
|
|
|
+ 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 + "'");
|
|
|
+ logger.info("E-订单单据{},序列号{}已存在,将中间表状态改为1", billno, sku);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!codeRowsMap.containsKey(sku)) {
|
|
|
+ //序列号不存在或者不在101-103仓库中
|
|
|
+ logger.info("E-订单序列号{}不存在于仓库101或103中", sku);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Row coderow = codeRowsMap.get(sku).get(0);
|
|
|
+
|
|
|
+ long stockid = entity.equals("实业") ? stockRowsMap.get(coderow.getString("stockno")).get(0).getLong("stockid") : stockRowsMap.get("101").get(0).getLong("stockid");
|
|
|
+ long itemid = coderow.getLong("itemid");
|
|
|
+
|
|
|
+ ArrayList<Long> stockbill_itemsids = dbConnect.runSqlQuery("select t.st_stockbill_itemsid,sum(t.qty)as qty,sum(t.skucount)as skucount from (\n" +
|
|
|
+ "select st_stockbill_itemsid,qty,0 as skucount from st_stockbill_items t1 where st_stockbillid=" + st_stockbillid + " and wmsuploadflag=2 and itemid=" + itemid + "\n" +
|
|
|
+ "union all\n" +
|
|
|
+ "select st_stockbill_itemsid,0,1 as skucount from st_stockbill_items_sku where st_stockbillid=" + st_stockbillid + " and itemid=" + itemid + " and ifnull(st_stockbill_itemsid,0)>0 \n" +
|
|
|
+ ")t group by t.st_stockbill_itemsid having sum(t.qty)>sum(t.skucount)").toArrayList("st_stockbill_itemsid", new ArrayList<>());
|
|
|
+
|
|
|
+ SQLDump sqlDump = new SQLDump();
|
|
|
+ //创建入库单序列号
|
|
|
+ InsertSQL stStockbillItemsSku = SQLFactory.createInsertSQL(dbConnect, "st_stockbill_items_sku");
|
|
|
+ stStockbillItemsSku.setValue("siteid", "MD");
|
|
|
+ stStockbillItemsSku.setValue("createby", "WMS");
|
|
|
+ stStockbillItemsSku.setValue("itemid", itemid);
|
|
|
+ stStockbillItemsSku.setValue("st_stockbillid", st_stockbillid);
|
|
|
+ if (!stockbill_itemsids.isEmpty()) {
|
|
|
+ stStockbillItemsSku.setValue("st_stockbill_itemsid", stockbill_itemsids.get(0));
|
|
|
+ }
|
|
|
+ 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 + "'");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("处理单据{},序列号{}出错", billno, sku, e);
|
|
|
+ }
|
|
|
}
|
|
|
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 t1.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 t1.st_stockbillid=" + st_stockbillid);
|
|
|
if (skucountRows.isNotEmpty() && skuitemcountRows.isNotEmpty()) {
|
|
|
@@ -123,7 +131,7 @@ public class GetOutCodeFromTQWms extends ServiceController {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("处理单据{},序列号{}出错", billno, sku, e);
|
|
|
+ logger.error("关闭中间表状态{}出错", billno, e);
|
|
|
}
|
|
|
}
|
|
|
}
|