Browse Source

送修单

hu 2 months ago
parent
commit
b974124f6b

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

@@ -6002,6 +6002,51 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025070414202703 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414204203 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414205403 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414210803 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414582703 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414583703 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414584903 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070414590403 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025070415073603 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 1 - 1
src/custom/restcontroller/webmanage/sale/aftersalesmag/aftersalesmag.java

@@ -482,7 +482,7 @@ public class aftersalesmag extends Controller {
             insertSQL.setUniqueid(st_stockbillid);
             insertSQL.setSiteid(siteid);
             insertSQL.setValue("billno", createBillCode("stockbill"));
-            insertSQL.setValue("type", "返退入库");
+            insertSQL.setValue("type", "返入库");
 //            insertSQL.setValue("typemx", "");
             insertSQL.setValue("sys_enterpriseid",rows.get(0).getLong("sys_enterpriseid"));
             insertSQL.setValue("rb", 1);

+ 212 - 0
src/custom/restcontroller/webmanage/sale/sendrepair/sendrepair.java

@@ -0,0 +1,212 @@
+package restcontroller.webmanage.sale.sendrepair;
+
+import beans.data.BatchDeleteErr;
+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.annotation.CACHEING;
+import common.annotation.CACHEING_CLEAN;
+import common.data.*;
+import org.apache.commons.lang.StringUtils;
+import restcontroller.R;
+import restcontroller.webmanage.sale.sendrepair.sendrepair;
+
+import java.util.ArrayList;
+
+@API(title = "送修单")
+public class sendrepair extends Controller {
+    public sendrepair(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "送修单更新", apiversion = R.ID2025070414202703.v1.class, intervaltime = 200)
+    @CACHEING_CLEAN(apiClass = {sendrepair.class})
+    public String insertormodify_sendrepair() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        // 表名
+        String tableName = "sa_sendrepair";
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+//        String type = content.getString("type");
+//        String typemx = content.getStringValue("typemx");
+//        Long sa_orderid = content.getLong("sa_orderid");
+
+//        BigDecimal rebate_userate =content.getBigDecimalValue("rebate_userate");
+//	    BigDecimal returnamount = content.getBigDecimalValue("returnamount");
+//        Long sa_accountclassid = content.getLong("sa_accountclassid");
+//        String reason = content.getStringValue("reason");
+//        boolean isitemreturn = content.getBooleanValue("isitemreturn");
+////		String logisticno = content.getStringValue("logisticno");
+        if (sa_sendrepairid > 0 && dbConnect.runSqlQuery(
+                        "select sa_sendrepairid from sa_sendrepair where sa_sendrepairid=" + sa_sendrepairid)
+                .isNotEmpty()) {
+            Rows rows = dbConnect.runSqlQuery(
+                    "SELECT status from sa_sendrepair WHERE sa_sendrepairid = "
+                            + sa_sendrepairid);
+            if (rows.isNotEmpty()) {
+                if (rows.get(0).getString("status").equals("新建")) {
+
+                    UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
+                    updateSQL.setUniqueid(sa_sendrepairid);
+                    updateSQL.setSiteid(siteid);
+                    updateSQL.setValue("remarks", content.getStringValue("remarks"));
+                    updateSQL.setDateValue("changedate");
+                    sqlList.add(updateSQL.getSQL());
+
+                    sqlList.add(DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "更新", "送修单更新成功")
+                            .getSQL());
+                } else {
+                    return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                }
+
+            } else {
+                return getErrReturnObject().setErrMsg("该送修单不存在").toString();
+            }
+
+        }
+        Rows sendrepairdetailRows =dbConnect.runSqlQuery("select sa_sendrepair_detailid from sa_sendrepair_detail where siteid='"+siteid+"' and  sa_sendrepairid="+sa_sendrepairid);
+        if(sendrepairdetailRows.isEmpty()){
+            return getErrReturnObject().setErrMsg("该送修单表体不存在").toString();
+        }
+        UpdateSQL  UpdateSQLdetail = SQLFactory.createUpdateSQL(this, "sa_sendrepair_detail");
+        UpdateSQLdetail.setUniqueid(sendrepairdetailRows.get(0).getLong("sa_sendrepair_detailid"));
+        UpdateSQLdetail.setSiteid(siteid);
+        UpdateSQLdetail.setValue("duty", content.getStringValue("duty"));
+        UpdateSQLdetail.setValue("reason", content.getStringValue("reason"));
+        UpdateSQLdetail.setValue("demand", content.getStringValue("demand"));
+        UpdateSQLdetail.setValue("remarks",  content.getStringValue("remarks"));
+        UpdateSQLdetail.setValue("disposition", content.getStringValue("disposition"));
+        UpdateSQLdetail.setValue("idearemarks", content.getStringValue("idearemarks"));
+        UpdateSQLdetail.setValue("agentcost", content.getBigDecimal("agentcost"));
+        sqlList.add(UpdateSQLdetail.getSQL());
+
+        dbConnect.runSqlUpdate(sqlList);
+        content.put("sa_sendrepairid", sa_sendrepairid);
+
+        return querysendrepairMain();
+    }
+
+
+    @API(title = "送修单详情", apiversion = R.ID2025070414204203.v1.class)
+    @CACHEING
+    public String querysendrepairMain() throws YosException {
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair", "*");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid","enterprisename");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid","agentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_sendrepair_detail", "t4", "t1.sa_sendrepairid = t4.sa_sendrepairid AND t1.siteid = t4.siteid","newspec","newitemno","newitemname",
+                "newitemid","newsku","agentcost","practicalamount","instockdate","amount","logisticscost","logistics","idearemarks","disposition","demand","reason","duty",
+                "stockdate","enddate","phonenumber","name","qty","itemid","sku");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t5", "t5.itemid = t4.itemid AND t5.siteid = t4.siteid","itemname","itemno","spec","model");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t6", "t5.unitid = t6.unitid AND t5.siteid = t6.siteid","unitname");
+        querySQL.addQueryFields("remarksdetail","t4.remarks");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.sa_sendrepairid",sa_sendrepairid);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "查询送修单列表", apiversion = R.ID2025070414205403.v1.class)
+    @CACHEING
+    public String querysendrepairList() throws YosException {
+        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.billno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
+//				 if(content.getString("type").equals("借用归还单")) {
+//					 where.append(" and t1.createdate >='" + whereObject.getString("startdate")).append("' ");
+//				 }else if(content.getString("type").equals("退货单")) {
+//					 where.append(" and t1.checkdate >='" + whereObject.getString("startdate")).append("' ");
+//				}
+                where.append(" and t1.billdate >='" + whereObject.getString("begindate")).append("' ");
+            }
+            if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
+//	            	 if(content.getString("type").equals("借用归还单")) {
+//	            		 where.append(" and t1.createdate <='" + whereObject.getString("enddate")).append("' ");
+//					 }else if(content.getString("type").equals("退货单")) {
+//						 where.append(" and t1.checkdate <='" + whereObject.getString("enddate")).append("' ");
+//					}
+                where.append(" and t1.billdate <='" + whereObject.getString("enddate")).append(" 23:59:59'");
+            }
+            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
+                where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
+            }
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair", "*");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid","enterprisename");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid","agentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_sendrepair_detail", "t4", "t1.sa_sendrepairid = t4.sa_sendrepairid AND t1.siteid = t4.siteid","newspec","newitemno","newitemname",
+                "newitemid","newsku","agentcost","practicalamount","instockdate","amount","logisticscost","logistics","idearemarks","disposition","demand","reason","duty",
+                "stockdate","enddate","phonenumber","name","qty","itemid","sku");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t5", "t5.itemid = t4.itemid AND t5.siteid = t4.siteid","itemname","itemno","spec","model");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t6", "t5.unitid = t6.unitid AND t5.siteid = t6.siteid","unitname");
+        querySQL.addQueryFields("remarksdetail","t4.remarks");
+
+
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where.toString());
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        QuerySQL querySumSQL = SQLFactory.createQuerySQL(this, "sa_sendrepair_pj", "sa_sendrepairid");
+        querySumSQL.setTableAlias("t1");
+        querySumSQL.setSiteid(siteid);
+        querySumSQL.addQueryFields("amount", "sum(amount)");
+        querySumSQL.setWhere("t1.sa_sendrepairid",rows.toArrayList("sa_sendrepairid", new ArrayList<Long>()));
+        querySumSQL.addGroupBy("sa_sendrepairid");
+        RowsMap querySumRowsMap =querySumSQL.query().toRowsMap("sa_sendrepairid");
+        for (Row row :rows){
+            if(querySumRowsMap.containsKey(row.getString("sa_sendrepairid"))){
+                row.put("ysamount",querySumRowsMap.get(row.getString("sa_sendrepairid")).get(0).getBigDecimal("amount"));
+            }
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除", apiversion = R.ID2025070414210803.v1.class)
+    @CACHEING_CLEAN(apiClass = {sendrepair.class})
+    public String delete() throws YosException {
+
+        JSONArray sa_sendrepairids = content.getJSONArray("sa_sendrepairids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_sendrepairids.size());
+        for (Object o : sa_sendrepairids) {
+            long sa_sendrepairid = Long.parseLong(o.toString());
+            Rows RowsStatus = dbConnect
+                    .runSqlQuery("select sa_sendrepairid,status,sourceid from sa_sendrepair where siteid='" + siteid
+                            + "' and sa_sendrepairid='" + sa_sendrepairid + "'");
+
+            if (RowsStatus.isNotEmpty()) {
+                if (!RowsStatus.get(0).getString("status").equals("新建")) {
+                    batchDeleteErr.addErr(sa_sendrepairid, "非新建状态的送修单无法删除");
+                    continue;
+                }
+            }
+
+            dbConnect.runSqlUpdate("delete from sa_sendrepair where siteid='" + siteid + "' and sa_sendrepairid="
+                    + sa_sendrepairid);
+            dbConnect.runSqlUpdate("delete from sa_sendrepair_detail where siteid='" + siteid + "' and sa_sendrepairid="
+                    + sa_sendrepairid);
+            dbConnect.runSqlUpdate("delete from sa_sendrepair_pj where siteid='" + siteid + "' and sa_sendrepairid="
+                    + sa_sendrepairid);
+            dbConnect.runSqlUpdate("update st_stockbill set isrepair=0 where siteid='" + siteid + "' and st_stockbillid="
+                    + RowsStatus.get(0).getLong("sourceid"));
+            dbConnect.runSqlUpdate("update st_stockbill_items set isrepair=0 where siteid='" + siteid + "' and st_stockbillid="
+                    + sa_sendrepairid);
+        }
+        return batchDeleteErr.getReturnObject().toString();
+
+    }
+}

+ 183 - 0
src/custom/restcontroller/webmanage/sale/sendrepair/sendrepair_pj.java

@@ -0,0 +1,183 @@
+package restcontroller.webmanage.sale.sendrepair;
+
+import beans.data.BatchDeleteErr;
+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 restcontroller.webmanage.sale.sendrepair.sendrepair;
+import restcontroller.webmanage.sale.sendrepair.sendrepair_pj;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+@API(title = "送修单配件")
+public class sendrepair_pj extends Controller {
+    public sendrepair_pj(JSONObject content) throws YosException {
+        super(content);
+    }
+
+
+    @API(title = "送修配件列表查询", apiversion = R.ID2025070414582703.v1.class)
+    @CACHEING
+    public String queryOrderItemgList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        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.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item", "*");
+        querySQL.setTableAlias("t1");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("isused=1 and status='审核' and ismodule=1");
+        querySQL.setWhere("t1.itemid not in (select itemid from sa_sendrepair_pj where sa_sendrepairid='"+content.getLongValue("sa_sendrepairid")+"')");
+        querySQL.setWhere(where.toString());
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "送修单明细新增更新", apiversion = R.ID2025070414583703.v1.class)
+    @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
+    public String insertormodify_sendrepairpjs() throws YosException {
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+        JSONArray iteminfos = content.getJSONArray("iteminfos");
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows rowscount = dbConnect.runSqlQuery("select billno,status from sa_sendrepair where sa_sendrepairid=" + sa_sendrepairid);
+        if (!rowscount.isEmpty()) {
+            if (!rowscount.get(0).getString("status").equals("新建")) {
+                return getErrReturnObject().setErrMsg("非新建状态的送修单无法新增修改").toString();
+            }
+        }
+        int i = 0;
+        long maxid = 0;
+        long[] sa_sendrepair_pjid = createTableID("sa_sendrepair_pj", iteminfos.size());
+        for (Object obj : iteminfos) {
+            JSONObject iteminfo = (JSONObject) obj;
+            if (iteminfo.getLong("sa_sendrepair_pjid") <= 0 || dbConnect
+                    .runSqlQuery("select sa_sendrepair_pjid from sa_sendrepair_pj where sa_sendrepair_pjid="
+                            + iteminfo.getLong("sa_sendrepair_pjid"))
+                    .isEmpty()) {
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendrepair_pj");
+                insertSQL.setUniqueid(sa_sendrepair_pjid[i]);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("sa_sendrepairid", sa_sendrepairid);
+                insertSQL.setValue("itemid", iteminfo.getStringValue("itemid"));
+                insertSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
+                insertSQL.setValue("price", iteminfo.getBigDecimal("price"));
+                insertSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
+                i++;
+                sqlList.add(insertSQL.getSQL());
+            } else {
+                Rows rows = dbConnect.runSqlQuery(
+                        "SELECT status from sa_sendrepair WHERE sa_sendrepairid = "
+                                + sa_sendrepairid);
+                if (rows.isNotEmpty()) {
+                    if (rows.get(0).getString("status").equals("新建")) {
+
+                        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair_pj");
+                        updateSQL.setUniqueid(iteminfo.getLong("sa_sendrepair_pjid"));
+                        updateSQL.setSiteid(siteid);
+                        updateSQL.setValue("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
+                        updateSQL.setValue("itemid", iteminfo.getString("itemid"));
+                        updateSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
+                        updateSQL.setValue("price", iteminfo.getBigDecimal("price"));
+                        updateSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
+                        sqlList.add(updateSQL.getSQL());
+                    } else {
+                        return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                    }
+
+                } else {
+                    return getErrReturnObject().setErrMsg("该送修单不存在").toString();
+                }
+            }
+
+        }
+        dbConnect.runSqlUpdate(sqlList);
+        return quersendrepairpjsList();
+    }
+
+
+    @API(title = "送修单配件列表", apiversion = R.ID2025070414584903.v1.class)
+    @CACHEING
+    public String quersendrepairpjsList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        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("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair_pj",  "*");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid = t2.itemid AND t1.siteid = t2.siteid","itemname","itemno","spec","model");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t3", "t2.unitid = t3.unitid AND t2.siteid = t3.siteid","unitname");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.sa_sendrepairid",sa_sendrepairid);
+        querySQL.setWhere(where.toString());
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除明细", apiversion = R.ID2025070414590403.v1.class)
+    @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
+    public String deletemx() throws YosException {
+
+
+        JSONArray sa_sendrepair_pjids = content.getJSONArray("sa_sendrepair_pjids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_sendrepair_pjids.size());
+        long sa_sendrepairid = 0;
+        for (Object o : sa_sendrepair_pjids) {
+            long sa_sendrepair_pjid = Long.parseLong(o.toString());
+            Rows RowsStatus = dbConnect.runSqlQuery("select t1.sa_sendrepair_pjid,t2.status,t1.sa_sendrepairid from sa_sendrepair_pj t1 left join sa_sendrepair t2 on t1.sa_sendrepairid=t2.sa_sendrepairid and t1.siteid=t2.siteid where t1.siteid='"
+                    + siteid + "' and t1.sa_sendrepair_pjid='" + sa_sendrepair_pjid + "'");
+
+            if (RowsStatus.isNotEmpty()) {
+                sa_sendrepairid = RowsStatus.get(0).getLong("sa_sendrepairid");
+                if (!RowsStatus.get(0).getString("status").equals("新建")) {
+                    batchDeleteErr.addErr(sa_sendrepair_pjid, "非新建状态的送修单明细无法删除");
+                    continue;
+                }
+            }
+            ArrayList<String> list = new ArrayList<>();
+            list.add("delete from sa_sendrepair_pj where siteid='" + siteid
+                    + "' and sa_sendrepair_pjid=" + sa_sendrepair_pjid);
+
+            dbConnect.runSqlUpdate(list);
+        }
+
+        return batchDeleteErr.getReturnObject().toString();
+    }
+   
+}

+ 78 - 0
src/custom/restcontroller/webmanage/sale/stockbill/stockbill.java

@@ -19,6 +19,8 @@ import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 import restcontroller.webmanage.sale.order.Order;
 import restcontroller.webmanage.sale.order.OrderItems;
+import restcontroller.webmanage.sale.sendrepair.sendrepair;
+import restcontroller.webmanage.sale.sendrepair.sendrepair_pj;
 
 import javax.swing.text.StyledEditorKit;
 import java.math.BigDecimal;
@@ -409,6 +411,82 @@ public class stockbill extends Controller {
         return getSucReturnObject().toString();
     }
 
+    @API(title = "生成送修单", apiversion = R.ID2025070415073603.v1.class)
+    @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
+    public String sendrepair() throws YosException {
+        JSONArray st_stockbillids =content.getJSONArray("st_stockbillids");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill","st_stockbillid","status","type","typemx","remarks","sys_enterpriseid","isrepair");
+        querySQL.setTableAlias("t1");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.st_stockbillid",st_stockbillids.toJavaList(Long.class));
+        Rows rows = querySQL.query();
+
+        QuerySQL querySQLDetail = SQLFactory.createQuerySQL(this, "st_stockbill_items","*");
+        querySQLDetail.setTableAlias("t1");
+        querySQLDetail.addJoinTable(JOINTYPE.left, "sa_aftersalesmag_items", "t2", "t1.sourceobject ='sa_aftersalesmag_items' and t1.sourceid=t2.sa_aftersalesmag_itemsid AND t1.siteid = t2.siteid","name","phonenumber","address","stockdate","enddate","remarks","duty","demand","reason");
+        querySQLDetail.addQueryFields("sku","t2.machinecode");
+
+        querySQLDetail.setSiteid(siteid);
+        querySQLDetail.setWhere("t1.st_stockbillid",st_stockbillids.toJavaList(Long.class));
+
+        RowsMap rowsMapDetail = querySQLDetail.query().toRowsMap("st_stockbillid");
+
+        ArrayList<String> sqlList = new ArrayList<>();
+        for(Row row:rows){
+            if(!row.getString("type").equals("返修入库")){
+                return getErrReturnObject().setErrMsg("非返修入库单无法生成送修单").toString();
+            }
+            if(row.getBoolean("isrepair")){
+                return getErrReturnObject().setErrMsg("已生成送修单,无法再次生成").toString();
+            }
+            if(!row.getString("type").equals("返修入库")){
+                return getErrReturnObject().setErrMsg("非返修入库单无法生成送修单").toString();
+            }
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendrepair");
+            long sa_sendrepairid =  createTableID("sa_sendrepair");
+            insertSQL.setUniqueid(sa_sendrepairid);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("billno", createBillCode("sendrepair"));
+            insertSQL.setValue("remarks", row.getString("remarks"));
+            insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
+            insertSQL.setValue("sourcetable", "st_stockbill");
+            insertSQL.setValue("sourceid", row.getLong("st_stockbillid"));
+            insertSQL.setValue("status", "新建");
+            insertSQL.setValue("createby",username);
+            insertSQL.setDateValue("createdate");
+            insertSQL.setDateValue("billdate");
+            sqlList.add(insertSQL.getSQL());
+
+            for(Row rowdetail :rowsMapDetail.get(row.getString("st_stockbillid"))){
+                insertSQL = SQLFactory.createInsertSQL(this, "sa_sendrepair_detail");
+                long sa_sendrepair_detailid =  createTableID("sa_sendrepair_detail");
+                insertSQL.setUniqueid(sa_sendrepair_detailid);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("sa_sendrepairid",sa_sendrepairid);
+                insertSQL.setValue("name", rowdetail.getString("name"));
+                insertSQL.setValue("phonenumber",rowdetail.getString("phonenumber"));
+                insertSQL.setValue("address",rowdetail.getString("address"));
+                insertSQL.setValue("stockdate",rowdetail.getString("stockdate"));
+                insertSQL.setValue("enddate",rowdetail.getString("enddate"));
+                insertSQL.setValue("remarks",rowdetail.getString("remarks"));
+                insertSQL.setValue("duty",rowdetail.getString("duty"));
+                insertSQL.setValue("demand",rowdetail.getString("demand"));
+                insertSQL.setValue("reason",rowdetail.getString("reason"));
+                insertSQL.setValue("qty",rowdetail.getBigDecimal("qty"));
+                insertSQL.setValue("sku",rowdetail.getString("sku"));
+                insertSQL.setValue("itemid",rowdetail.getString("itemid"));
+                sqlList.add(insertSQL.getSQL());
+                sqlList.add("update st_stockbill_items set isrepair=1 where st_stockbill_itemsid="+rowdetail.getLong("st_stockbill_itemsid"));
+
+            }
+            sqlList.add("update st_stockbill set isrepair=1 where st_stockbillid="+row.getLong("st_stockbillid"));
+        }
+        dbConnect.runSqlUpdate(sqlList);
+
+        return getSucReturnObject().toString();
+    }
+
+
     public String xsckcheck(Long st_stockbillid,boolean isinstock) throws YosException {
         Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
                 + st_stockbillid + "' and  siteid='" + siteid + "'");