eganwu 2 gadi atpakaļ
vecāks
revīzija
5cfaf25137

+ 125 - 0
src/custom/restcontroller/R.java

@@ -4603,18 +4603,22 @@ public class R {
         public static class v1 {
         }
     }
+
     public static class ID20230321153703 {
         public static class v1 {
         }
     }
+
     public static class ID20230321153803 {
         public static class v1 {
         }
     }
+
     public static class ID20230321153903 {
         public static class v1 {
         }
     }
+
     public static class ID20230321154003 {
         public static class v1 {
         }
@@ -4624,30 +4628,37 @@ public class R {
         public static class v1 {
         }
     }
+
     public static class ID20230321155603 {
         public static class v1 {
         }
     }
+
     public static class ID20230321155703 {
         public static class v1 {
         }
     }
+
     public static class ID20230324125803 {
         public static class v1 {
         }
     }
+
     public static class ID20230325133303 {
         public static class v1 {
         }
     }
+
     public static class ID20230331102503 {
         public static class v1 {
         }
     }
+
     public static class ID20230331152503 {
         public static class v1 {
         }
     }
+
     public static class ID20230404134703 {
         public static class v1 {
         }
@@ -4662,22 +4673,27 @@ public class R {
         public static class v1 {
         }
     }
+
     public static class ID20230408091703 {
         public static class v1 {
         }
     }
+
     public static class ID20230408101803 {
         public static class v1 {
         }
     }
+
     public static class ID20230413110103 {
         public static class v1 {
         }
     }
+
     public static class ID20230417141103 {
         public static class v1 {
         }
     }
+
     public static class ID20230427101303 {
         public static class v1 {
         }
@@ -4687,30 +4703,37 @@ public class R {
         public static class v1 {
         }
     }
+
     public static class ID20230506162603 {
         public static class v1 {
         }
     }
+
     public static class ID20230506162703 {
         public static class v1 {
         }
     }
+
     public static class ID20230508093003 {
         public static class v1 {
         }
     }
+
     public static class ID20230508101703 {
         public static class v1 {
         }
     }
+
     public static class ID20230508111703 {
         public static class v1 {
         }
     }
+
     public static class ID20230508113003 {
         public static class v1 {
         }
     }
+
     public static class ID20230509085703 {
         public static class v1 {
         }
@@ -4760,275 +4783,377 @@ public class R {
         public static class v1 {
         }
     }
+
     public static class ID20230518151803 {
         public static class v1 {
         }
     }
+
     public static class ID20230522090403 {
         public static class v1 {
         }
     }
+
     public static class ID20230522093703 {
         public static class v1 {
         }
     }
+
     public static class ID20230523085403 {
         public static class v1 {
         }
     }
+
     public static class ID20230524160003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627091003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627091503 {
         public static class v1 {
         }
     }
+
     public static class ID20230627091603 {
         public static class v1 {
         }
     }
+
     public static class ID20230627091703 {
         public static class v1 {
         }
     }
+
     public static class ID20230627091903 {
         public static class v1 {
         }
     }
+
     public static class ID20230627092003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627092103 {
         public static class v1 {
         }
     }
+
     public static class ID20230627095503 {
         public static class v1 {
         }
     }
+
     public static class ID20230627095603 {
         public static class v1 {
         }
     }
+
     public static class ID20230627102803 {
         public static class v1 {
         }
     }
+
     public static class ID20230627102903 {
         public static class v1 {
         }
     }
+
     public static class ID20230627103003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627103103 {
         public static class v1 {
         }
     }
+
     public static class ID20230627103903 {
         public static class v1 {
         }
     }
+
     public static class ID20230627104003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627104103 {
         public static class v1 {
         }
     }
+
     public static class ID20230627110303 {
         public static class v1 {
         }
     }
+
     public static class ID20230627110803 {
         public static class v1 {
         }
     }
+
     public static class ID20230627110903 {
         public static class v1 {
         }
     }
+
     public static class ID20230627111003 {
         public static class v1 {
         }
     }
+
     public static class ID20230627111103 {
         public static class v1 {
         }
     }
+
     public static class ID20230627135403 {
         public static class v1 {
         }
     }
+
     public static class ID20230627135503 {
         public static class v1 {
         }
     }
+
     public static class ID20230627135603 {
         public static class v1 {
         }
     }
+
     public static class ID20230627141203 {
         public static class v1 {
         }
     }
+
     public static class ID20230627141303 {
         public static class v1 {
         }
     }
+
     public static class ID20230627141403 {
         public static class v1 {
         }
     }
+
     public static class ID20230627142103 {
         public static class v1 {
         }
     }
+
     public static class ID20230629140803 {
         public static class v1 {
         }
     }
+
     public static class ID20230629141403 {
         public static class v1 {
         }
     }
+
     public static class ID20230629141503 {
         public static class v1 {
         }
     }
+
     public static class ID20230629141603 {
         public static class v1 {
         }
     }
+
     public static class ID20230707091503 {
         public static class v1 {
         }
     }
+
     public static class ID20230707091603 {
         public static class v1 {
         }
     }
+
     public static class ID20230707091703 {
         public static class v1 {
         }
     }
+
     public static class ID20230707091803 {
         public static class v1 {
         }
     }
+
     public static class ID20230707093103 {
         public static class v1 {
         }
     }
+
     public static class ID20230707093203 {
         public static class v1 {
         }
     }
+
     public static class ID20230707093303 {
         public static class v1 {
         }
     }
+
     public static class ID20230707111103 {
         public static class v1 {
         }
     }
+
     public static class ID20230711135303 {
         public static class v1 {
         }
     }
+
     public static class ID20230713101303 {
         public static class v1 {
         }
     }
+
     public static class ID20230626104003 {
         public static class v1 {
         }
     }
+
     public static class ID20230714164803 {
         public static class v1 {
         }
     }
+
     public static class ID20230714164903 {
         public static class v1 {
         }
     }
+
     public static class ID20230714165003 {
         public static class v1 {
         }
     }
+
     public static class ID20230715090203 {
         public static class v1 {
         }
     }
+
     public static class ID20230715090703 {
         public static class v1 {
         }
     }
+
     public static class ID20230715091603 {
         public static class v1 {
         }
     }
+
     public static class ID20230715091703 {
         public static class v1 {
         }
     }
+
     public static class ID20230715093903 {
         public static class v1 {
         }
     }
+
     public static class ID20230715094003 {
         public static class v1 {
         }
     }
+
     public static class ID20230715095103 {
         public static class v1 {
         }
     }
+
     public static class ID20230715111203 {
         public static class v1 {
         }
     }
+
     public static class ID20230715144203 {
         public static class v1 {
         }
     }
+
     public static class ID20230717144803 {
         public static class v1 {
         }
     }
+
     public static class ID20230719153803 {
         public static class v1 {
         }
     }
+
     public static class ID20230719153903 {
         public static class v1 {
         }
     }
+
     public static class ID20230719154003 {
         public static class v1 {
         }
     }
+
     public static class ID20230719154103 {
         public static class v1 {
         }
     }
+
     public static class ID20230719154203 {
         public static class v1 {
         }
     }
+
     public static class ID20230719154303 {
         public static class v1 {
         }
     }
 
+    public static class ID20230719165802 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720141602 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720141702 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720141802 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720141902 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720142002 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20230720142102 {
+        public static class v1 {
+        }
+    }
+
 }
 
 

+ 113 - 0
src/custom/restcontroller/webmanage/sale/logistics/LSALogistics.java

@@ -0,0 +1,113 @@
+package restcontroller.webmanage.sale.logistics;
+
+import beans.datacontrllog.DataContrlLog;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.data.Rows;
+import restcontroller.R;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+import static restcontroller.webmanage.sale.logistics.LSALogisticsHelper.*;
+
+/**
+ * 物流单(LSA)
+ */
+public class LSALogistics extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public LSALogistics(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "新增或更新", apiversion = R.ID20230719165802.v1.class)
+    public String insertOrUpdate() throws YosException {
+        //物流单ID
+        Long sa_logisticsid = content.getLongValue("sa_logisticsid");
+        //经销商编号(选择经销商)
+        Long sys_enterpriseid = content.getLong("sys_enterpriseid");
+        //出入库表货品明细
+        JSONArray items = content.getJSONArray("items");
+
+        ArrayList<String> sqlList = new ArrayList<>();
+        if (sys_enterpriseid <= 0 || isEnterpriseEmpty(this)) {
+            return getErrReturnObject().setErrMsg("未选择企业").toString();
+        }
+        Rows rows = LSALogisticsHelper.getLogisticsRows(this);
+
+        if (sa_logisticsid <= 0 || rows.isEmpty()) {
+            sa_logisticsid = createTableID("sa_logistics");
+            sqlList.add(insert(this, sa_logisticsid).getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_logistics", sa_logisticsid, "新增", "物流单-新增:" + sa_logisticsid).getSQL());
+            content.put("sa_logisticsid", sa_logisticsid);
+        } else {
+            if (!rows.get(0).getString("status").equals("新建")) {
+                return getErrReturnObject().setErrMsg("该物流单为非新建状态,无法更改").toString();
+            }
+            sqlList.add(update(this, sa_logisticsid).getSQL());
+            sqlList.add(DataContrlLog.createLog(this, "sa_logistics", sa_logisticsid, "更新", "物流单-更新:" + sa_logisticsid).getSQL());
+        }
+
+        //更新送货列表
+        ArrayList<Long> st_stockbill_itemsids = new ArrayList<>();
+        for (Object obj : items) {
+            JSONObject object = (JSONObject) obj;
+            Long st_stockbill_itemsid = object.getLongValue("st_stockbill_itemsid");
+            BigDecimal qty = object.getBigDecimalValue("qty");
+            if (isOut(this, st_stockbill_itemsid, qty)) {
+                return getErrReturnObject().setErrMsg("超出最大可送货数量").toString();
+            }
+            if (isLogisticsItemEmpty(this, st_stockbill_itemsid)) {
+                sqlList.add(insertLogisticsItem(this, object).getSQL());
+            } else {
+                sqlList.add(updateLogisticsItem(this, object).getSQL());
+            }
+            st_stockbill_itemsids.add(st_stockbill_itemsid);
+        }
+        dbConnect.runSqlUpdate(sqlList);
+        //删除送货
+        if (st_stockbill_itemsids.size() > 0) {
+            deleteLogisticsItem(this, st_stockbill_itemsids);
+        }
+        return getSucReturnObject().setData(sa_logisticsid).toString();
+    }
+
+    @API(title = "添加送货明细", apiversion = R.ID20230720141602.v1.class)
+    public String add() {
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "删除送货明细", apiversion = R.ID20230720141902.v1.class)
+    public String delete() {
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "送货明细列表", apiversion = R.ID20230720141702.v1.class)
+    public String selectMXList() {
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "选择送货明细列表", apiversion = R.ID20230720141802.v1.class)
+    public String selectChooseMXList() {
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "物流单详情", apiversion = R.ID20230720142002.v1.class)
+    public String detail() {
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "物流单列表", apiversion = R.ID20230720142102.v1.class)
+    public String selectList() {
+        return getSucReturnObject().toString();
+    }
+
+
+}

+ 154 - 0
src/custom/restcontroller/webmanage/sale/logistics/LSALogisticsHelper.java

@@ -0,0 +1,154 @@
+package restcontroller.webmanage.sale.logistics;
+
+import com.alibaba.fastjson.JSONObject;
+import common.BaseClass;
+import common.Controller;
+import common.YosException;
+import common.data.InsertSQL;
+import common.data.Rows;
+import common.data.SQLFactory;
+import common.data.UpdateSQL;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+public class LSALogisticsHelper extends BaseClass {
+
+    static String tablename = "sa_logistics";
+
+    /**
+     * 查询物流单sa_logisticsid
+     *
+     * @param controller
+     * @return
+     * @throws YosException
+     */
+    public static Rows getLogisticsRows(Controller controller) throws YosException {
+        return controller.dbConnect.runSqlQuery("select * from sa_logistics where siteid='" + controller.siteid + "' and sa_logisticsid=" + controller.content.getLongValue("sa_logisticsid"));
+    }
+
+    /**
+     * 企业是否存在
+     *
+     * @param controller
+     * @return
+     * @throws YosException
+     */
+    public static boolean isEnterpriseEmpty(Controller controller) throws YosException {
+        return controller.dbConnect.runSqlQuery("select sys_enterpriseid from sys_enterprise where siteid = '" + controller.siteid + "' and sys_enterpriseid = " + controller.content.getLongValue("sys_enterpriseid")).isEmpty();
+    }
+
+    /**
+     * 新增物流单
+     *
+     * @param controller
+     * @throws YosException
+     */
+    public static InsertSQL insert(Controller controller, Long sa_logisticsid) throws YosException {
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, tablename);
+        insertSQL.setValue("sa_logisticsid", sa_logisticsid);
+        insertSQL.setValue("siteid", controller.siteid);
+        insertSQL.setValue("status", "新建");
+        insertSQL.setValue("billno", controller.content.getString("billno"));
+        insertSQL.setValue("sys_enterpriseid", controller.content.getLongValue("sys_enterpriseid"));
+        insertSQL.setValue("sa_logiscompid", controller.content.getLong("sa_logiscompid"));
+        insertSQL.setValue("billdate", controller.content.getString("billdate"));
+        insertSQL.setValue("remarks", controller.content.getStringValue("remarks"));
+        return insertSQL;
+    }
+
+    /**
+     * 更新物流单
+     *
+     * @param controller
+     * @param sa_logisticsid
+     * @return
+     * @throws YosException
+     */
+    public static UpdateSQL update(Controller controller, Long sa_logisticsid) throws YosException {
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, tablename);
+        updateSQL.setValue("billno", controller.content.getString("billno"));
+        updateSQL.setValue("sa_logiscompid", controller.content.getLong("sa_logiscompid"));
+        updateSQL.setValue("billdate", controller.content.getString("billdate"));
+        updateSQL.setValue("remarks", controller.content.getStringValue("remarks"));
+        updateSQL.setWhere("sa_logisticsid", sa_logisticsid);
+        updateSQL.setWhere("siteid", controller.siteid);
+        return updateSQL;
+    }
+
+    /**
+     * 新增送货明细-sa_logistics_items
+     *
+     * @param controller
+     * @throws YosException
+     */
+    public static InsertSQL insertLogisticsItem(Controller controller, JSONObject object) throws YosException {
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sa_logistics_items");
+        insertSQL.setValue("sa_logistics_itemsid", controller.createTableID("sa_logistics_items"));
+        insertSQL.setValue("siteid", controller.siteid);
+        insertSQL.setValue("sa_logisticsid", controller.content.getLongValue("sa_logisticsid"));
+        insertSQL.setValue("sa_dispatchid", 0);
+        insertSQL.setValue("st_stockbill_itemsid", object.getLongValue("st_stockbill_itemsid"));
+        insertSQL.setValue("qty", object.getBigDecimalValue("qty"));
+        return insertSQL;
+    }
+
+    /**
+     * 更新送货明细-sa_logistics_items
+     *
+     * @param controller
+     * @throws YosException
+     */
+    public static UpdateSQL updateLogisticsItem(Controller controller, JSONObject object) throws YosException {
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, "sa_logistics_items");
+        updateSQL.setValue("qty", object.getBigDecimalValue("qty"));
+        updateSQL.setWhere("sa_logisticsid", controller.content.getLongValue("sa_logisticsid"));
+        updateSQL.setWhere("st_stockbill_itemsid", object.getLongValue("st_stockbill_itemsid"));
+        updateSQL.setWhere("siteid", controller.siteid);
+        return updateSQL;
+    }
+
+
+    /**
+     * 查询送货明细是否存在
+     *
+     * @param controller
+     * @param st_stockbill_itemsid
+     * @return
+     * @throws YosException
+     */
+    public static boolean isLogisticsItemEmpty(Controller controller, Long st_stockbill_itemsid) throws YosException {
+        return controller.dbConnect.runSqlQuery("SELECT * from sa_logistics_items where sa_logisticsid=" + controller.content.getLongValue("sa_logisticsid") + " and st_stockbill_itemsid=" + st_stockbill_itemsid + " and siteid='" + controller.siteid + "'").isEmpty();
+    }
+
+    /**
+     * 删除多余的送货明细
+     *
+     * @param controller
+     * @param st_stockbill_itemsids
+     * @return
+     * @throws YosException
+     */
+    public static void deleteLogisticsItem(Controller controller, ArrayList<Long> st_stockbill_itemsids) throws YosException {
+        String sql = "DELETE from sa_logistics_items where sa_logisticsid=" + controller.content.getLongValue("sa_logisticsid") + " and st_stockbill_itemsid not in " + st_stockbill_itemsids + " and siteid='" + controller.siteid + "'";
+        sql = sql.replace("[", "(").replace("]", ")");
+        controller.dbConnect.runSqlUpdate(sql);
+
+    }
+
+    /**
+     * 是否超出可送货数量
+     *
+     * @param controller
+     * @param st_stockbill_itemsid
+     * @param qty
+     * @return
+     * @throws YosException
+     */
+    public static boolean isOut(Controller controller, Long st_stockbill_itemsid, BigDecimal qty) throws YosException {
+        String sql = "SELECT " + qty + ">qty-transportqty isOut from st_stockbill_items WHERE st_stockbill_itemsid=" + st_stockbill_itemsid + " and siteid='" + controller.siteid + "'";
+
+        return controller.dbConnect.runSqlQuery(sql).get(0).getBoolean("isOut");
+    }
+
+}

+ 2 - 2
src/custom/restcontroller/webmanage/sale/logistics/SQL/物流单发货明细新增.sql

@@ -1,3 +1,3 @@
 insert into sa_logistics_items(sa_logistics_itemsid, siteid, sa_logisticsid, sa_dispatchid, changeuserid, changeby,
-                               changedate)
-values ($sa_logistics_itemsid$, $siteid$, $sa_logisticsid$, $sa_dispatchid$, $userid$, $username$, current_time)
+                               changedate,st_stockbill_itemsid,qty)
+values ($sa_logistics_itemsid$, $siteid$, $sa_logisticsid$, $sa_dispatchid$, $userid$, $username$, current_time,$st_stockbill_itemsid$,$qty$)