eganwu преди 1 година
родител
ревизия
2399d2b149
променени са 2 файла, в които са добавени 96 реда и са изтрити 56 реда
  1. 43 56
      src/custom/restcontroller/webmanage/saletool/fad/FadGoods.java
  2. 53 0
      src/custom/restcontroller/webmanage/saletool/fad/FadHelper.java

+ 43 - 56
src/custom/restcontroller/webmanage/saletool/fad/FadGoods.java

@@ -33,59 +33,45 @@ public class FadGoods extends Controller {
     public String insertOrUpdate() throws YosException {
         Long sa_fadid = content.getLongValue("sa_fadid");
         int isonsale = content.getIntValue("isonsale");
-
         String tag = content.getStringValue("tag");
+        Long parentid = 0L;
 
-        if (sa_fadid <= 0) {
+        ArrayList<String> listSQL = new ArrayList<>();
+        Rows fadRows = dbConnect.runSqlQuery("SELECT * from sa_fad WHERE sa_fadid=" + sa_fadid + " and siteid='" + siteid + "'");
+        if (sa_fadid <= 0 || fadRows.isEmpty()) {
             sa_fadid = createTableID(sa_fad);
-            InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sa_fad);
-            sqlFactory.setSiteid(siteid);
-            sqlFactory.setUniqueid(sa_fadid);
-            sqlFactory.setValue("itemid", content.getLongValue("itemid"));
-            sqlFactory.setValue("itemno", content.getStringValue("itemno"));
-            sqlFactory.setValue("name", content.getStringValue("name"));
-            sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
-            sqlFactory.setValue("model", content.getStringValue("model"));
-            sqlFactory.setValue("class", content.getJSONArray("class"));
-            sqlFactory.setValue("pricetype", content.getStringValue("pricetype"));
-            sqlFactory.setValue("price", content.getBigDecimalValue("price"));
-            sqlFactory.setValue("price_deposit", content.getBigDecimalValue("price_deposit"));
-            sqlFactory.setValue("price_store", content.getBigDecimalValue("price_store"));
-            sqlFactory.setValue("price_rebate", content.getBigDecimalValue("price_rebate"));
-            sqlFactory.setValue("unitname", content.getStringValue("unitname"));
-            sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
-            sqlFactory.setValue("sequence", content.getLongValue("sequence"));
-            sqlFactory.setValue("content", content.getStringValue("contentstr", true));
-            sqlFactory.setValue("classid", 2);
-            sqlFactory.setValue("parentid", content.getLongValue("parentid"));
-            sqlFactory.setValue("canadjust", content.getLongValue("canadjust"));
-            sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
-
-            sqlFactory.insert();
+            InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid, parentid);
+            listSQL.add(sqlFactory.getSQL());
             content.put("sa_fadid", sa_fadid);
         } else {
-            UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sa_fad);
-            sqlFactory.setUniqueid(sa_fadid);
-            sqlFactory.setSiteid(siteid);
-            sqlFactory.setValue("itemid", content.getLongValue("itemid"));
-            sqlFactory.setValue("itemno", content.getStringValue("itemno"));
-            sqlFactory.setValue("name", content.getStringValue("name"));
-            sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
-            sqlFactory.setValue("model", content.getStringValue("model"));
-            sqlFactory.setValue("class", content.getJSONArray("class"));
-            sqlFactory.setValue("pricetype", content.getStringValue("pricetype"));
-            sqlFactory.setValue("price", content.getBigDecimalValue("price"));
-            sqlFactory.setValue("price_deposit", content.getBigDecimalValue("price_deposit"));
-            sqlFactory.setValue("price_store", content.getBigDecimalValue("price_store"));
-            sqlFactory.setValue("price_rebate", content.getBigDecimalValue("price_rebate"));
-            sqlFactory.setValue("unitname", content.getStringValue("unitname"));
-            sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
-            sqlFactory.setValue("sequence", content.getLongValue("sequence"));
-            sqlFactory.setValue("content", content.getStringValue("contentstr", true));
-            sqlFactory.setValue("parentid", content.getLongValue("parentid"));
-            sqlFactory.setValue("canadjust", content.getLongValue("canadjust"));
-            sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
-            sqlFactory.update();
+
+            boolean canadjust = fadRows.get(0).getBoolean("canadjust");
+            long temp_sys_enterpriseid = fadRows.get(0).getLong("sys_enterpriseid");
+            //允许经销商调整,数据是总部的,修改方为总部
+            if (canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid == 0) {
+                UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
+                listSQL.add(sqlFactory.getSQL());
+                //更新parentid为sa_fadid的数据
+                Rows rows = dbConnect.runSqlQuery("SELECT sa_fadid from sa_fad WHERE parentid=" + sa_fadid + " and siteid='" + siteid + "'");
+                for (Row row : rows) {
+                    sqlFactory = FadHelper.getFadUpdateSQL(this, row.getLong("sa_fadid"));
+                    listSQL.add(sqlFactory.getSQL());
+                }
+
+            }
+            //允许经销商调整,数据是总部的,修改方为经销商
+            else if (canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid > 0) {
+                parentid = sa_fadid;
+                sa_fadid = createTableID(sa_fad);
+                InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid, parentid);
+                listSQL.add(sqlFactory.getSQL());
+                content.put("sa_fadid", sa_fadid);
+            } else {
+                UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
+                listSQL.add(sqlFactory.getSQL());
+            }
+
+
         }
 
         //上下架
@@ -95,7 +81,8 @@ public class FadGoods extends Controller {
         updateSQL.setValue("isonsale", isonsale);
         updateSQL.setValue("onsaledate", isonsale == 1 ? Time.getDateTime_Str() : "null");
         updateSQL.setValue("onsaleby", isonsale == 1 ? username : "null");
-        updateSQL.update();
+        listSQL.add(updateSQL.getSQL());
+        dbConnect.runSqlUpdate(listSQL);
 
         DataTag.deleteTag(this, "sa_fad", sa_fadid);
         DataTag.createSystemTag(this, "sa_fad", sa_fadid, tag);
@@ -158,8 +145,8 @@ public class FadGoods extends Controller {
         detailRow.put("attinfos_pic", attachmentRows);
         detailRow.putIfAbsent("onsaledate", "");
         ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", detailRow.getLong("sa_fadid"), true);
-        detailRow.putIfAbsent("tag", StringUtils.join(tags,","));
-        detailRow.putIfAbsent("classnames", StringUtils.join(detailRow.getJSONArray("class"),","));
+        detailRow.putIfAbsent("tag", StringUtils.join(tags, ","));
+        detailRow.putIfAbsent("classnames", StringUtils.join(detailRow.getJSONArray("class"), ","));
 
 
         return getSucReturnObject().setData(detailRow).toString();
@@ -195,7 +182,7 @@ public class FadGoods extends Controller {
         return getSucReturnObject().toString();
     }
 
-    @API(title = "品列表", apiversion = R.ID20240428154002.v1.class)
+    @API(title = "品列表", apiversion = R.ID20240428154002.v1.class)
     public String list() throws YosException {
         /*
           过滤条件设置
@@ -255,10 +242,10 @@ public class FadGoods extends Controller {
 
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
-                        "sa_fadid", "name", "isonsale", "model", "pricetype","sequence", "createby", "createdate", "onsaledate","class")
+                        "sa_fadid", "name", "isonsale", "canadjust", "model", "pricetype", "sequence", "createby", "createdate", "onsaledate", "class")
                 .setTableAlias("t1");
 
-        querySQL.addJoinTable(JOINTYPE.left,"sys_datatag","t2","t2.ownertable='sa_fad' and t2.ownerid=t1.sa_fadid and t2.siteid=t1.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_datatag", "t2", "t2.ownertable='sa_fad' and t2.ownerid=t1.sa_fadid and t2.siteid=t1.siteid");
         querySQL.setSiteid(siteid);
         querySQL.setWhere("classid", 2);
         querySQL.setWhere(where.toString());
@@ -277,8 +264,8 @@ public class FadGoods extends Controller {
             row.putIfAbsent("onsaledate", "");
 
             ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", row.getLong("sa_fadid"), true);
-            row.putIfAbsent("tag", StringUtils.join(tags,","));
-            row.putIfAbsent("classnames", StringUtils.join(row.getJSONArray("class"),","));
+            row.putIfAbsent("tag", StringUtils.join(tags, ","));
+            row.putIfAbsent("classnames", StringUtils.join(row.getJSONArray("class"), ","));
         }
 
 

+ 53 - 0
src/custom/restcontroller/webmanage/saletool/fad/FadHelper.java

@@ -4,7 +4,10 @@ import beans.parameter.Parameter;
 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 common.data.db.DBConnect;
 import org.apache.commons.lang.StringUtils;
 
@@ -19,4 +22,54 @@ public class FadHelper extends BaseClass {
             return Parameter.get(paramname);
         }
     }
+
+    public static InsertSQL getFadInsertSQL(Controller controller, Long sa_fadid,Long parentid) throws YosException {
+        InsertSQL sqlFactory = SQLFactory.createInsertSQL(controller, "sa_fad");
+        sqlFactory.setSiteid(controller.siteid);
+        sqlFactory.setUniqueid(sa_fadid);
+        sqlFactory.setValue("itemid", controller.content.getLongValue("itemid"));
+        sqlFactory.setValue("itemno", controller.content.getStringValue("itemno"));
+        sqlFactory.setValue("name", controller.content.getStringValue("name"));
+        sqlFactory.setValue("subtitle", controller.content.getStringValue("subtitle"));
+        sqlFactory.setValue("model", controller.content.getStringValue("model"));
+        sqlFactory.setValue("class", controller.content.getJSONArray("class"));
+        sqlFactory.setValue("pricetype", controller.content.getStringValue("pricetype"));
+        sqlFactory.setValue("price", controller.content.getBigDecimalValue("price"));
+        sqlFactory.setValue("price_deposit", controller.content.getBigDecimalValue("price_deposit"));
+        sqlFactory.setValue("price_store", controller.content.getBigDecimalValue("price_store"));
+        sqlFactory.setValue("price_rebate", controller.content.getBigDecimalValue("price_rebate"));
+        sqlFactory.setValue("unitname", controller.content.getStringValue("unitname"));
+        sqlFactory.setValue("isnew", controller.content.getBooleanValue("isnew"));
+        sqlFactory.setValue("sequence", controller.content.getLongValue("sequence"));
+        sqlFactory.setValue("content", controller.content.getStringValue("contentstr", true));
+        sqlFactory.setValue("classid", 2);
+        sqlFactory.setValue("parentid",parentid);
+        sqlFactory.setValue("canadjust", controller.content.getLongValue("canadjust"));
+        sqlFactory.setValue("sys_enterpriseid", controller.sys_enterpriseid);
+        return sqlFactory;
+    }
+
+    public static UpdateSQL getFadUpdateSQL(Controller controller, Long sa_fadid) throws YosException {
+        UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(controller, "sa_fad");
+        sqlFactory.setUniqueid(sa_fadid);
+        sqlFactory.setSiteid(controller.siteid);
+        sqlFactory.setValue("itemid", controller.content.getLongValue("itemid"));
+        sqlFactory.setValue("itemno", controller.content.getStringValue("itemno"));
+        sqlFactory.setValue("name", controller.content.getStringValue("name"));
+        sqlFactory.setValue("subtitle", controller.content.getStringValue("subtitle"));
+        sqlFactory.setValue("model", controller.content.getStringValue("model"));
+        sqlFactory.setValue("class", controller.content.getJSONArray("class"));
+        sqlFactory.setValue("pricetype", controller.content.getStringValue("pricetype"));
+        sqlFactory.setValue("price", controller.content.getBigDecimalValue("price"));
+        sqlFactory.setValue("price_deposit", controller.content.getBigDecimalValue("price_deposit"));
+        sqlFactory.setValue("price_store", controller.content.getBigDecimalValue("price_store"));
+        sqlFactory.setValue("price_rebate", controller.content.getBigDecimalValue("price_rebate"));
+        sqlFactory.setValue("unitname", controller.content.getStringValue("unitname"));
+        sqlFactory.setValue("isnew", controller.content.getBooleanValue("isnew"));
+        sqlFactory.setValue("sequence", controller.content.getLongValue("sequence"));
+        sqlFactory.setValue("content", controller.content.getStringValue("contentstr", true));
+        sqlFactory.setValue("canadjust", controller.content.getLongValue("canadjust"));
+        return sqlFactory;
+    }
+
 }