|
|
@@ -18,8 +18,107 @@ public class sendplandetail extends Controller {
|
|
|
public sendplandetail(JSONObject content) throws YosException {
|
|
|
super(content);
|
|
|
}
|
|
|
+ //ID2025120110193103
|
|
|
+ @API(title = "订单信息刷新(新)", apiversion = R.ID2025032709331803.v1.class)
|
|
|
+ public String orderRefresh_new() throws YosException {
|
|
|
+ long sa_sendplanid = content.getLongValue("sa_sendplanid");
|
|
|
+ Rows sendplanRows = dbConnect.runSqlQuery("select * from sa_sendplan where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
|
|
|
+ if (sendplanRows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("发货计划不存在,无法进行订单信息刷新").toString();
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_sendplandetail where sa_sendplanid='" + sa_sendplanid + "' and siteid='" + siteid + "'");
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 and t1.undeliqty>0 and t3.type='" + sendplanRows.get(0).getString("type")
|
|
|
+ + "' and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') >='" + sendplanRows.get(0).getString("begindate")
|
|
|
+ + "' and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') <='" + sendplanRows.get(0).getString("enddate")
|
|
|
+ + "' and ( \n" +
|
|
|
+ "\t\t(t3.type in('标准订单','网销订单')) or\n" +
|
|
|
+ "\t\t(\n" +
|
|
|
+ "\t\t\tt3.type='配件订单'\n" +
|
|
|
+ "\t\t\tand t3.sys_enterpriseid in (\n" +
|
|
|
+ "\t\t\tselect distinct sys_enterpriseid from st_stockbill \n" +
|
|
|
+ "\t\t\twhere type='销售出库' and status='审核' and \n" +
|
|
|
+ "\t\t\tbilldate= '" + sendplanRows.get(0).getString("senddate") + "'\n" +
|
|
|
+ "\t\t\t)\n" +
|
|
|
+ "\t\t))");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "发货计划订单未发货量");
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
|
|
|
- @API(title = "订单信息刷新", apiversion = R.ID2025032709331803.v1.class)
|
|
|
+ Rows stockbillrows = dbConnect.runSqlQuery("select t2.itemid,sum(t2.undeliqty) qty from sa_order t1 " +
|
|
|
+ " inner join sa_orderitems t2 on t1.sa_orderid=t2.sa_orderid " +
|
|
|
+ " where t1.status='审核' and t2.isclose=0 and t2.undeliqty>0 and t1.siteid='" + siteid + "' " +
|
|
|
+ " group by t2.itemid ");
|
|
|
+ Rows invbalrows = dbConnect.runSqlQuery("select itemid,sum(qty) qty from st_invbal t1 group by itemid");
|
|
|
+
|
|
|
+ RowsMap stockbillrowsMap = stockbillrows.toRowsMap("itemid");
|
|
|
+ RowsMap invbalrowsMap = invbalrows.toRowsMap("itemid");
|
|
|
+
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+ long olditemid=0;
|
|
|
+ BigDecimal oldcanuseqty=BigDecimal.ZERO;
|
|
|
+ BigDecimal oldsendqty=BigDecimal.ZERO;
|
|
|
+ for (Row row : rows) {
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendplandetail");
|
|
|
+ long sa_sendplandetailid=createTableID("sa_sendplandetailid");
|
|
|
+ insertSQL.setUniqueid(sa_sendplandetailid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_sendplanid", sa_sendplanid);
|
|
|
+ insertSQL.setValue("sa_orderid", row.getLong("sa_orderid"));
|
|
|
+ insertSQL.setValue("sa_orderitemsid", row.getLong("sa_orderitemsid"));
|
|
|
+ insertSQL.setValue("outplace", row.getString("outplace"));
|
|
|
+ insertSQL.setValue("sa_agentsid", row.getString("sa_agentsid"));
|
|
|
+
|
|
|
+ BigDecimal canuseqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal willoutqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal invbalqty = BigDecimal.ZERO;
|
|
|
+ BigDecimal sendqty = BigDecimal.ZERO;
|
|
|
+ if (stockbillrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ willoutqty = stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ if (invbalrowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ invbalqty = invbalrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ canuseqty = invbalqty.subtract(willoutqty);
|
|
|
+
|
|
|
+ insertSQL.setValue("willoutqty", willoutqty);
|
|
|
+ insertSQL.setValue("willinqty", 0);
|
|
|
+ insertSQL.setValue("canuseqty", canuseqty);
|
|
|
+ if (canuseqty.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ insertSQL.setValue("sendqty", 0);
|
|
|
+ insertSQL.setValue("colorflag", 0);
|
|
|
+ } else {
|
|
|
+ sendqty=row.getBigDecimal("sendqty");
|
|
|
+ insertSQL.setValue("sendqty", sendqty);
|
|
|
+ if (canuseqty.compareTo(row.getBigDecimal("sendqty")) >= 0) {
|
|
|
+ insertSQL.setValue("colorflag", 2);
|
|
|
+ } else {
|
|
|
+ insertSQL.setValue("colorflag", 3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(row.getLong("itemid")==olditemid){
|
|
|
+ insertSQL.setValue("canuseqty", oldcanuseqty.subtract(oldsendqty));
|
|
|
+ }
|
|
|
+ olditemid=row.getLong("itemid");
|
|
|
+ oldcanuseqty=oldcanuseqty.subtract(oldsendqty);
|
|
|
+ oldsendqty=sendqty;
|
|
|
+ list.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(list);
|
|
|
+ list = new ArrayList<>();
|
|
|
+ Rows rows1 = dbConnect.runSqlQuery("select t1.sa_orderid from (select sa_orderid,count(0)count from sa_sendplandetail where sa_sendplanid=" + sa_sendplanid + " group by sa_orderid) t1 inner join (select sa_orderid,count(0)count from sa_sendplandetail where colorflag='2' and sa_sendplanid=" + sa_sendplanid + " group by sa_orderid) t2 on t1.sa_orderid=t2.sa_orderid and t1.count=t2.count");
|
|
|
+ for (Row row : rows1) {
|
|
|
+ list.add("update sa_sendplandetail set colorflag=1 where sa_sendplanid=" + sa_sendplanid + " and sa_orderid =" + row.getLong("sa_orderid"));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+ //ID2025032709331803
|
|
|
+ @API(title = "订单信息刷新", apiversion = R.ID2025120110193103.v1.class)
|
|
|
@CACHEING_CLEAN(apiClass = {sendplandetail.class})
|
|
|
public String orderRefresh() throws YosException {
|
|
|
long sa_sendplanid = content.getLongValue("sa_sendplanid");
|