|
|
@@ -0,0 +1,294 @@
|
|
|
+package restcontroller.webmanage.sale.sendplan;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.annotation.CACHEING;
|
|
|
+import common.annotation.CACHEING_CLEAN;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@API(title = "发货计划明细")
|
|
|
+public class sendplandetail extends Controller {
|
|
|
+ public sendplandetail(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "订单信息刷新", apiversion = R.ID2025032709331803.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {sendplandetail.class})
|
|
|
+ public String orderRefresh() 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\tDATE_FORMAT(billdate, '%Y-%m-%d') = '"+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());
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+ //计划发货插入明细
|
|
|
+ for(Row row :rows){
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this,"sa_sendplandetail");
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_sendplandetail"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_sendplanid", sa_sendplanid);
|
|
|
+ insertSQL.setValue("sendqty", row.getBigDecimal("sendqty"));
|
|
|
+ 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"));
|
|
|
+ insertSQL.setValue("canuseqty", 0);
|
|
|
+
|
|
|
+ list.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(list);
|
|
|
+
|
|
|
+ //计划发货明细计算
|
|
|
+ list=new ArrayList<>();
|
|
|
+ Rows stockbillrows =dbConnect.runSqlQuery("\t\tselect itemid,sum(t2.qty) qty from st_stockbill t1\n" +
|
|
|
+ "\t\t\tinner join st_stockbill_items t2 on t1.st_stockbillid=t2.st_stockbillid\n" +
|
|
|
+ "\t\t\twhere t1.type='销售出库'and t1.status='新建' and t1.siteid='"+siteid+"'\n" +
|
|
|
+ "\t\t\tand DATE_FORMAT(billdate, '%Y-%m-%d')<='"+sendplanRows.get(0).getString("senddate")+"'\n" +
|
|
|
+ "\t\t\tgroup by itemid");
|
|
|
+ Rows invbalrows =dbConnect.runSqlQuery("select itemid,sum(qty) qty from st_invbal t1 group by itemid");
|
|
|
+ Rows sendplandetails = dbConnect.runSqlQuery("select * from sa_sendplandetail where sa_sendplanid="+sa_sendplanid+" and siteid='"+siteid+"'");
|
|
|
+ RowsMap stockbillrowsMap =stockbillrows.toRowsMap("itemid");
|
|
|
+ RowsMap invbalrowsMap =invbalrows.toRowsMap("itemid");
|
|
|
+ for(Row row:sendplandetails){
|
|
|
+ BigDecimal canuseqty=BigDecimal.ZERO;
|
|
|
+ BigDecimal willoutqty=BigDecimal.ZERO;
|
|
|
+ BigDecimal invbalqty=BigDecimal.ZERO;
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendplandetail");
|
|
|
+ updateSQL.setUniqueid(row.getLong("sa_sendplandetailid")).setSiteid(siteid);
|
|
|
+ if(stockbillrowsMap.containsKey(row.getString("itemid"))){
|
|
|
+ willoutqty=stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ if(invbalrowsMap.containsKey(row.getString("itemid"))){
|
|
|
+ invbalqty=stockbillrowsMap.get(row.getString("itemid")).get(0).getBigDecimal("qty");
|
|
|
+ }
|
|
|
+ canuseqty=invbalqty.subtract(willoutqty);
|
|
|
+ updateSQL.setValue("willoutqty",willoutqty);
|
|
|
+ updateSQL.setValue("willinqty",0);
|
|
|
+ updateSQL.setValue("canuseqty",canuseqty);
|
|
|
+ if(canuseqty.compareTo(BigDecimal.ZERO)<=0){
|
|
|
+ updateSQL.setValue("sendqty",0);
|
|
|
+ updateSQL.setValue("colorflag",0);
|
|
|
+ }else {
|
|
|
+ if(canuseqty.compareTo(row.getBigDecimal("sendqty"))>=0){
|
|
|
+ updateSQL.setValue("colorflag",2);
|
|
|
+ }else{
|
|
|
+ updateSQL.setValue("colorflag",3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.add(updateSQL.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"));
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(list);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "计划清空", apiversion = R.ID2025032709342503.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {sendplandetail.class})
|
|
|
+ public String clearPlan() throws YosException {
|
|
|
+ Long sa_sendplanid = content.getLongValue("sa_sendplanid");
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_sendplandetail where sa_sendplanid='"+sa_sendplanid+"' and siteid='"+siteid+"'");
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "生成销售出库单", apiversion = R.ID2025032709355603.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {sendplandetail.class})
|
|
|
+ public String createIcstockBill() throws YosException {
|
|
|
+ JSONArray detailarray = content.getJSONArray("details");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ HashMap<String, HashMap<String, List<JSONObject>>> agentmap = new HashMap<String, HashMap<String, List<JSONObject>>>();
|
|
|
+ for(Object object :detailarray){
|
|
|
+ JSONObject jsonObject =(JSONObject) object;
|
|
|
+ if (jsonObject.getDouble("sendqty") <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String key="";
|
|
|
+ String sys_enterpriseid = jsonObject.getString("sys_enterpriseid");
|
|
|
+ String outplace = jsonObject.getString("outplace");
|
|
|
+ key=sys_enterpriseid+outplace;
|
|
|
+ HashMap<String, List<JSONObject>> agent = null;
|
|
|
+ List<JSONObject> paolist = null;
|
|
|
+ if (agentmap.containsKey(sys_enterpriseid)) {
|
|
|
+ agent = agentmap.get(sys_enterpriseid);
|
|
|
+ if (agent.containsKey(key)) {
|
|
|
+ paolist = agent.get(key);
|
|
|
+ } else {
|
|
|
+ paolist = new ArrayList<JSONObject>();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ agent = new HashMap<String, List<JSONObject>>();
|
|
|
+ paolist = new ArrayList<JSONObject>();
|
|
|
+ }
|
|
|
+ paolist.add(jsonObject);
|
|
|
+ agent.put(key, paolist);
|
|
|
+ agentmap.put(sys_enterpriseid, agent);
|
|
|
+ }
|
|
|
+ Iterator<Map.Entry<String, HashMap<String, List<JSONObject>>>> iter = agentmap
|
|
|
+ .entrySet().iterator();
|
|
|
+
|
|
|
+
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ Map.Entry entry = (Map.Entry) iter.next();
|
|
|
+ String sys_enterpriseid = (String) entry.getKey();
|
|
|
+
|
|
|
+ HashMap<String, List<JSONObject>> keymap = (HashMap<String, List<JSONObject>>) entry
|
|
|
+ .getValue();
|
|
|
+ Iterator<Map.Entry<String, List<JSONObject>>> iter2 = keymap
|
|
|
+ .entrySet().iterator();
|
|
|
+ while (iter2.hasNext()) {
|
|
|
+ Map.Entry entry2 = (Map.Entry) iter2.next();
|
|
|
+ String key = (String) entry2.getKey();
|
|
|
+ List<JSONObject> paolist = (List<JSONObject>) entry2
|
|
|
+ .getValue();
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "销售出库单新增");
|
|
|
+ long st_stockbillid = createTableID("st_stockbill");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlFactory.addParameter("billno", createBillCode("stockbill"));
|
|
|
+ sqlFactory.addParameter("type", "销售出库");
|
|
|
+ sqlFactory.addParameter("rb", 1);
|
|
|
+ sqlFactory.addParameter("billdate", getDateTime_Str());
|
|
|
+ sqlFactory.addParameter("createby", username);
|
|
|
+ sqlFactory.addParameter("createdate", getDateTime_Str());
|
|
|
+ sqlFactory.addParameter("changeby", username);
|
|
|
+ sqlFactory.addParameter("changedate", getDateTime_Str());
|
|
|
+ sqlFactory.addParameter("checkby", username);
|
|
|
+ sqlFactory.addParameter("checkdate", getDateTime_Str());
|
|
|
+ sqlFactory.addParameter("remarks", "由发货计划自动生成"+key);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+
|
|
|
+ Iterator<JSONObject> senddetailpaoit = paolist.iterator();
|
|
|
+ int rowno=1;
|
|
|
+ while (senddetailpaoit.hasNext()) {
|
|
|
+ JSONObject jsonObject = senddetailpaoit.next();
|
|
|
+ BigDecimal qty = new BigDecimal(jsonObject.getString("sendqty"));
|
|
|
+ qty = qty.compareTo(BigDecimal.ZERO) < 0 ? qty.negate() : qty;
|
|
|
+ //String fdetailstockno = jsonObject.getString("fstockno");
|
|
|
+ //String fbatchno = jsonObject.getString("fbatchno");
|
|
|
+ SQLFactory sqlFactorydetail = new SQLFactory(this, "销售出库单明细新增");
|
|
|
+ sqlFactorydetail.addParameter("siteid", siteid);
|
|
|
+ sqlFactorydetail.addParameter("st_stockbill_itemsid", createTableID("st_stockbill_items"));
|
|
|
+ sqlFactorydetail.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+
|
|
|
+ Rows orderdetails = dbConnect.runSqlQuery("select * from sa_orderitems where sa_orderitemsid="+jsonObject.getLongValue("sa_orderitemsid"));
|
|
|
+ if(orderdetails.isNotEmpty()){
|
|
|
+ sqlFactorydetail.addParameter("remarks", orderdetails.get(0).getString("remarks"));
|
|
|
+ sqlFactorydetail.addParameter("price", orderdetails.get(0).getBigDecimal("price"));
|
|
|
+ sqlFactorydetail.addParameter("amount", orderdetails.get(0).getBigDecimal("price").multiply(qty));
|
|
|
+ }else{
|
|
|
+ sqlFactorydetail.addParameter("remarks", "");
|
|
|
+ sqlFactorydetail.addParameter("price", 0);
|
|
|
+ sqlFactorydetail.addParameter("amount", 0);
|
|
|
+ }
|
|
|
+ sqlFactorydetail.addParameter("itemid", jsonObject.getLongValue("itemid"));
|
|
|
+ sqlFactorydetail.addParameter("qty", qty);
|
|
|
+ sqlFactorydetail.addParameter("sa_dispatch_itemsid", 0);
|
|
|
+ sqlFactorydetail.addParameter("rowno", rowno);
|
|
|
+
|
|
|
+ sqlFactorydetail.addParameter("sa_orderitemsid", jsonObject.getLongValue("sa_orderitemsid"));
|
|
|
+ sqlFactorydetail.addParameter("sa_orderid", jsonObject.getLongValue("sa_orderid"));
|
|
|
+ sqlList.add(sqlFactorydetail.getSQL());
|
|
|
+ rowno++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "发货计划明细列表", apiversion = R.ID2025032709373303.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryList_sendplan() throws YosException {
|
|
|
+ Long sa_sendplanid = content.getLongValue("sa_sendplanid");
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.outplace like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.sonum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t4.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t5.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "发货计划订单未发货量(简略)");
|
|
|
+ sqlFactory.addParameter_SQL("where", "1=1");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendplandetail","sa_sendplandetailid","colorflag","topclassnum","outplace","sendqty","willoutqty","willinqty","canuseqty");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_order", "t2", "t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid","sonum","checkdate","sys_enterpriseid","sa_orderid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_orderitems", "t3", "t3.siteid = t1.siteid and t3.sa_orderitemsid = t1.sa_orderitemsid","rowno","remarks","sa_orderitemsid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t4.siteid = t1.siteid and t4.sa_agentsid = t1.sa_agentsid","agentnum");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t5", "t5.siteid = t4.siteid and t5.sys_enterpriseid = t4.sys_enterpriseid","abbreviation");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t6", "t6.siteid = t3.siteid and t6.itemid = t3.itemid","itemno","itemname","model","itemid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, sqlFactory , "t7", "t7.sa_orderitemsid = t3.sa_orderitemsid","undeliqty");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_invbal" , "t8", "t8.itemid = t3.itemid and stockid='101'");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_invbal" , "t9", "t9.itemid = t3.itemid and stockid='103'");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_invbal" , "t10", "t10.itemid = t3.itemid and stockid='109'");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.addQueryFields("willoutqty_jh", "t7.willoutqty");
|
|
|
+ querySQL.addQueryFields("qty_xs", "t8.qty");
|
|
|
+ querySQL.addQueryFields("qty_tq", "t9.qty");
|
|
|
+ querySQL.addQueryFields("qty_mq", "t10.qty");
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ querySQL.setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "删除明细", apiversion = R.ID2025032709370703.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {sendplandetail.class})
|
|
|
+ public String deletemx() throws YosException {
|
|
|
+ long sa_sendplandetailid = content.getLongValue("sa_sendplandetailid");
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+ list.add("delete from sa_sendplandetail where siteid='" + siteid
|
|
|
+ + "' and sa_sendplandetailid=" + sa_sendplandetailid);
|
|
|
+ dbConnect.runSqlUpdate(list);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|