|
@@ -0,0 +1,256 @@
|
|
|
+package restcontroller.webmanage.sale.aftersalesbomchange;
|
|
|
+
|
|
|
+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 java.util.ArrayList;
|
|
|
+
|
|
|
+@API(title = "售后bom变更单")
|
|
|
+public class aftersalesbomchange extends Controller {
|
|
|
+ public aftersalesbomchange(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "售后bom变更单新增更新", apiversion = R.ID2025071511171103.v1.class, intervaltime = 200)
|
|
|
+ @CACHEING_CLEAN(apiClass = {aftersalesbomchange.class})
|
|
|
+ public String insertormodify_aftersalesbomchange() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ // 表名
|
|
|
+ String tableName = "sa_aftersalesbomchange";
|
|
|
+ Long sa_aftersalesbomchangeid = content.getLong("sa_aftersalesbomchangeid");
|
|
|
+ String type = content.getString("type");
|
|
|
+
|
|
|
+ if (sa_aftersalesbomchangeid > 0 && dbConnect.runSqlQuery(
|
|
|
+ "select sa_aftersalesbomchangeid from sa_aftersalesbomchange where sa_aftersalesbomchangeid=" + sa_aftersalesbomchangeid)
|
|
|
+ .isNotEmpty()) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery(
|
|
|
+ "SELECT status from sa_aftersalesbomchange WHERE sa_aftersalesbomchangeid = "
|
|
|
+ + sa_aftersalesbomchangeid);
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ if (rows.get(0).getString("status").equals("新建")) {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
|
|
|
+ updateSQL.setUniqueid(sa_aftersalesbomchangeid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("type", type);
|
|
|
+ updateSQL.setDateValue("changedate");
|
|
|
+ updateSQL.setValue("changeby", username);
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_aftersalesbomchange", sa_aftersalesbomchangeid, "更新", "售后bom变更单更新成功")
|
|
|
+ .getSQL());
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("该售后bom变更单不存在").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
|
|
|
+ sa_aftersalesbomchangeid=createTableID(tableName);
|
|
|
+ insertSQL.setUniqueid(sa_aftersalesbomchangeid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("type", type);
|
|
|
+ insertSQL.setValue("billno", createBillCode("aftersalesbomchange"));
|
|
|
+ insertSQL.setValue("createby", username);
|
|
|
+ insertSQL.setDateValue("createdate");
|
|
|
+ insertSQL.setValue("changeby", username);
|
|
|
+ insertSQL.setDateValue("changedate");
|
|
|
+ insertSQL.setValue("status", "新建");
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ content.put("sa_aftersalesbomchangeid", sa_aftersalesbomchangeid);
|
|
|
+
|
|
|
+ return queryaftersalesbomchangeMain();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "售后bom变更单详情", apiversion = R.ID2025071511172503.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryaftersalesbomchangeMain() throws YosException {
|
|
|
+ Long sa_aftersalesbomchangeid = content.getLong("sa_aftersalesbomchangeid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_aftersalesbomchange", "*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("t1.sa_aftersalesbomchangeid",sa_aftersalesbomchangeid);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "查询售后bom变更单列表", apiversion = R.ID2025071511173303.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryaftersalesbomchangeList() 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 t1.type like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+
|
|
|
+ where.append(" and t1.createdate >='" + whereObject.getString("begindate")).append("' ");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and t1.createdate <='" + 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_aftersalesbomchange", "*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID2025071511174303.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {aftersalesbomchange.class})
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sa_aftersalesbomchangeids = content.getJSONArray("sa_aftersalesbomchangeids");
|
|
|
+ BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_aftersalesbomchangeids.size());
|
|
|
+ for (Object o : sa_aftersalesbomchangeids) {
|
|
|
+ long sa_aftersalesbomchangeid = Long.parseLong(o.toString());
|
|
|
+ Rows RowsStatus = dbConnect
|
|
|
+ .runSqlQuery("select sa_aftersalesbomchangeid,status from sa_aftersalesbomchange where siteid='" + siteid
|
|
|
+ + "' and sa_aftersalesbomchangeid='" + sa_aftersalesbomchangeid + "'");
|
|
|
+
|
|
|
+ if (RowsStatus.isNotEmpty()) {
|
|
|
+ if (!RowsStatus.get(0).getString("status").equals("新建")) {
|
|
|
+ batchDeleteErr.addErr(sa_aftersalesbomchangeid, "非新建状态的售后bom变更单无法删除");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_aftersalesbomchange where siteid='" + siteid + "' and sa_aftersalesbomchangeid="
|
|
|
+ + sa_aftersalesbomchangeid);
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_aftersalesbomchange_items where siteid='" + siteid + "' and sa_aftersalesbomchangeid="
|
|
|
+ + sa_aftersalesbomchangeid);
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_aftersalesbomchange_pjs where siteid='" + siteid + "' and sa_aftersalesbomchangeid="
|
|
|
+ + sa_aftersalesbomchangeid);
|
|
|
+ }
|
|
|
+ return batchDeleteErr.getReturnObject().toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "审核", apiversion = R.ID2025071511175303.v1.class)
|
|
|
+ @CACHEING_CLEAN( apiClass = {aftersalesbomchange.class})
|
|
|
+ public String check() throws YosException {
|
|
|
+ Long sa_aftersalesbomchangeid = content.getLong("sa_aftersalesbomchangeid");
|
|
|
+ boolean ischeck =true;
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select t1.sa_aftersalesbomchangeid,t1.status,t1.billno,t1.type from sa_aftersalesbomchange t1 where t1.sa_aftersalesbomchangeid ='"
|
|
|
+ + sa_aftersalesbomchangeid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ for (Row row : rows) {
|
|
|
+ if(ischeck){
|
|
|
+ if (!row.getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态的【"+row.getString("billno")+"】售后bom变更单无法审核")
|
|
|
+ .toString();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (!row.getString("status").equals("审核")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非审核状态的【"+row.getString("billno")+"】售后bom变更单无法反审核")
|
|
|
+ .toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_aftersalesbomchange");
|
|
|
+ updateSQL.setUniqueid(sa_aftersalesbomchangeid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("status", ischeck?"审核":"新建");
|
|
|
+ updateSQL.setValue("checkby", ischeck?username:"null");
|
|
|
+ if(ischeck){
|
|
|
+ updateSQL.setDateValue("checkdate");
|
|
|
+ }else{
|
|
|
+ updateSQL.setValue("checkdate","null");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ if(ischeck){
|
|
|
+ Rows rowsdetail;
|
|
|
+ if(rows.get(0).getString("type").equals("产品变更")){
|
|
|
+ rowsdetail=dbConnect.runSqlQuery("select * from sa_aftersalesbomchange_items t1 where t1.sa_aftersalesbomchangeid ='"
|
|
|
+ + sa_aftersalesbomchangeid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ for(Row row :rowsdetail){
|
|
|
+ if(row.getString("type").equals("新增")){
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_aftersalesbom_items");
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_aftersalesbom_items"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_aftersalesbomid", row.getLong("sa_aftersalesbomid"));
|
|
|
+ insertSQL.setValue("itemid", row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("itemname", row.getString("itemname"));
|
|
|
+ insertSQL.setValue("itemno", row.getString("itemno"));
|
|
|
+ insertSQL.setValue("spec", row.getString("spec"));
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }else if(row.getString("type").equals("删除")){
|
|
|
+ sqlList.add("delete from sa_aftersalesbom_items where sa_aftersalesbomid="+row.getLong("sa_aftersalesbomid")+" and itemid="+row.getLong("itemid")+" and siteid='"+siteid+"'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(rows.get(0).getString("type").equals("配件变更")){
|
|
|
+ rowsdetail=dbConnect.runSqlQuery("select * from sa_aftersalesbomchange_pjs t1 where t1.sa_aftersalesbomchangeid ='"
|
|
|
+ + sa_aftersalesbomchangeid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ for(Row row :rowsdetail){
|
|
|
+ if(row.getString("type").equals("新增")){
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_aftersalesbom_pjs");
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_aftersalesbom_pjs"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_aftersalesbomid", row.getLong("sa_aftersalesbomid"));
|
|
|
+ insertSQL.setValue("module", row.getString("module"));
|
|
|
+ insertSQL.setValue("component", row.getString("component"));
|
|
|
+ insertSQL.setValue("accessorie", row.getString("accessorie"));
|
|
|
+ insertSQL.setValue("itemid", row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("itemname", row.getString("itemname"));
|
|
|
+ insertSQL.setValue("itemno", row.getString("itemno"));
|
|
|
+ insertSQL.setValue("begindate", StringUtils.isBlank(row.getString("begindate")) ?"null":row.getString("begindate"));
|
|
|
+ insertSQL.setValue("enddate", StringUtils.isBlank(row.getString("enddate")) ?"null":row.getString("enddate"));
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }else if(row.getString("type").equals("停用")){
|
|
|
+ sqlList.add("update sa_aftersalesbom_pjs set enddate='"+(StringUtils.isBlank(row.getString("enddate")) ?"null":row.getString("enddate"))+"' where sa_aftersalesbomid="+row.getLong("sa_aftersalesbomid")+" and itemid="+row.getLong("itemid"));
|
|
|
+ }
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_aftersalesbom", row.getLong("sa_aftersalesbomid"), row.getString("type"), "售后bom变更单审核成功,"+row.getString("itemno")+row.getString("type")).getSQL());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return getErrReturnObject().setErrMsg("售后bom变更单变更类型不符无法审核").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (ischeck) {
|
|
|
+ sqlList.add(
|
|
|
+ DataContrlLog.createLog(this, "sa_aftersalesbomchange", sa_aftersalesbomchangeid, "审核", "售后bom变更单审核成功").getSQL());
|
|
|
+ } else {
|
|
|
+ sqlList.add(
|
|
|
+ DataContrlLog.createLog(this, "sa_aftersalesbomchange", sa_aftersalesbomchangeid, "反审核", "售后bom变更单反审核成功").getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+}
|