|
@@ -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();
|
|
|
+
|
|
|
+ }
|
|
|
+}
|