Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/develop-yellow' into develop2

eganwu 1 rok pred
rodič
commit
cd4bbe35df

+ 49 - 130
src/custom/restcontroller/webmanage/saletool/fad/FadGoods.java

@@ -37,111 +37,35 @@ public class FadGoods extends Controller {
     @API(title = "商品新增或编辑", apiversion = R.ID20240428154102.v1.class)
     public String insertOrUpdate() throws YosException {
         Long sa_fadid = content.getLongValue("sa_fadid");
-        boolean canadjust = content.getBooleanValue("canadjust");
-        String tag = content.getStringValue("tag");
-        Long parentid = 0L;
-        if (content.containsKey("sys_enterpriseid") && content.getLongValue("sys_enterpriseid") != 0) {
-            sys_enterpriseid = content.getLongValue("sys_enterpriseid");
-        }
-
-        Rows attachmentRows = Attachment.get(this, "sa_fad", sa_fadid);
 
         ArrayList<String> listSQL = new ArrayList<>();
-        ArrayList<Long> sa_fadids = new ArrayList<>();
 
-        Rows fadRows = dbConnect.runSqlQuery("SELECT * from sa_fad WHERE sa_fadid=" + sa_fadid + " and siteid='" + siteid + "'");
-        if (sa_fadid <= 0 || fadRows.isEmpty()) {
+        if (sa_fadid <= 0) {
             sa_fadid = createTableID(sa_fad);
-            InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid, parentid);
+            InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid);
             listSQL.add(sqlFactory.getSQL());
             content.put("sa_fadid", sa_fadid);
         } else {
-
-            boolean temp_canadjust = fadRows.get(0).getBoolean("canadjust");
-            long temp_sys_enterpriseid = fadRows.get(0).getLong("sys_enterpriseid");
-            //允许经销商调整,数据是总部的,修改方为总部
-            if (temp_canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid == 0) {
+            if (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 + "'");
-                //修改项为禁止经销商修改
-                if (!canadjust) {
-                    DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fad");
-                    deleteSQL.setSiteid(siteid);
-                    deleteSQL.setWhere("parentid", sa_fadid);
-                    deleteSQL.delete();
+            } else {
+                Rows rows = dbConnect.runSqlQuery("SELECT * from sa_fadadjust WHERE sys_enterpriseid=" + sys_enterpriseid + " and sa_fadid=" + sa_fadid + " and siteid='" + siteid + "'");
+                if (rows.isEmpty()) {
+                    InsertSQL sqlFactory = FadHelper.getFadAdjustInsertSQL(this, sa_fadid);
+                    listSQL.add(sqlFactory.getSQL());
                 } else {
-                    sa_fadids = rows.toArrayList("sa_fadid", new ArrayList<>());
-                    for (Row row : rows) {
-                        sqlFactory = FadHelper.getFadUpdateSQL(this, row.getLong("sa_fadid"));
-                        listSQL.add(sqlFactory.getSQL());
-                    }
+                    UpdateSQL sqlFactory = FadHelper.getFadAdjustUpdateSQL(this, sa_fadid);
+                    listSQL.add(sqlFactory.getSQL());
                 }
 
             }
-            //允许经销商调整,数据是总部的,修改方为经销商
-            else if (temp_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);
-                //修改
-                content.put("ownertable", "sa_fad");
-                content.put("ownerid", sa_fadid);
-                Long sys_dataauthid = createTableID("sys_dataauth");
-                listSQL.add(DataAuthHelper.getDataAuthInsertSQL(this, sys_dataauthid).getSQL());
-                listSQL.add(DataAuthHelper.getDataAuthsInsertSQL(this, "sys_enterpriseid", sys_enterpriseid).getSQL());
-
-//                for (Row attachmentRow : attachmentRows) {
-//                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
-//                    insertSQL.setSiteid(siteid);
-//                    insertSQL.setUniqueid(createTableID("sys_attachment_links"));
-//                    insertSQL.setValue("usetype", attachmentRow.getString("usetype"));
-//                    insertSQL.setValue("attachmentid", attachmentRow.getLong("attachmentid"));
-//                    insertSQL.setValue("sequence", 1);
-//                    insertSQL.setValue("ownertable", sa_fad);
-//                    insertSQL.setValue("ownerid", sa_fadid);
-//                    insertSQL.setWhere("not exists(select 1 from  sys_attachment_links where attachmentid=" + attachmentRow.getLong("attachmentid") + " and ownertable='sa_fad' and siteid='" + siteid + "' and ownerid=" + sa_fadid + " )");
-//                    listSQL.add(insertSQL.getSQL());
-//                }
-
-            } else {
-                UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
-                listSQL.add(sqlFactory.getSQL());
-            }
-
-
         }
 
-
-        sa_fadids.add(sa_fadid);
-        for (Long id : sa_fadids) {
-            listSQL.add(FadHelper.getIsOnSalesUpdateSQL(this, id).getSQL());
-            for (Row attachmentRow : attachmentRows) {
-                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
-                insertSQL.setSiteid(siteid);
-                insertSQL.setUniqueid(createTableID("sys_attachment_links"));
-                insertSQL.setValue("usetype", attachmentRow.getString("usetype"));
-                insertSQL.setValue("attachmentid", attachmentRow.getLong("attachmentid"));
-                insertSQL.setValue("sequence", 1);
-                insertSQL.setValue("ownertable", sa_fad);
-                insertSQL.setValue("ownerid", id);
-                insertSQL.setWhere("not exists(select 1 from  sys_attachment_links where attachmentid=" + attachmentRow.getLong("attachmentid") + " and ownertable='sa_fad' and siteid='" + siteid + "' and ownerid=" + id + " )");
-                listSQL.add(insertSQL.getSQL());
-            }
-        }
         //上下架
+        listSQL.add(FadHelper.getIsOnSalesUpdateSQL(this, sa_fadid).getSQL());
         dbConnect.runSqlUpdate(listSQL);
 
-        for (Long id : sa_fadids) {
-            DataTag.deleteTag(this, "sa_fad", id);
-            DataTag.createSystemTag(this, "sa_fad", id, tag);
-        }
-
 
         return detail();
     }
@@ -155,7 +79,6 @@ public class FadGoods extends Controller {
         if (fadrows.isNotEmpty()) {
             siteid = fadrows.get(0).getString("siteid");
         }
-
         dbConnect.runSqlUpdate("UPDATE sa_fad SET readcount=readcount+1 WHERE sa_fadid=" + sa_fadid);
 
         QuerySQL querySQ = SQLFactory.createQuerySQL(this, sa_fad)
@@ -201,21 +124,25 @@ 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"), ","));
 
-        //查询官方信息:价格。。。
-        Long parentid = detailRow.getLong("parentid");
-        if (parentid == 0) {
-            parentid = sa_fadid;
-        }
-        Rows officalrows = dbConnect.runSqlQuery("SELECT sa_fadid,price,price_store,price_rebate,price_deposit,price_original from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + parentid);
-        Row officalrow = officalrows.isNotEmpty() ? officalrows.get(0) : new Row();
-        ArrayList<String> officaltags = DataTag.queryTag(this, "sa_fad", parentid, true);
-        officalrow.putIfAbsent("tag", StringUtils.join(officaltags, ","));
+        Row officalrow = new Row();
+        officalrow.put("pricetype", detailRow.getString("pricetype"));
+        officalrow.put("price", detailRow.getBigDecimal("price"));
+        officalrow.put("price_store", detailRow.getBigDecimal("price_store"));
+        officalrow.put("price_rebate", detailRow.getBigDecimal("price_rebate"));
+        officalrow.put("price_deposit", detailRow.getBigDecimal("price_deposit"));
+        officalrow.put("price_original", detailRow.getBigDecimal("price_original"));
+        officalrow.put("tag", detailRow.getString("tag"));
         detailRow.put("officialinfo", officalrow);
 
+        if (sys_enterpriseid > 0) {
+            Rows adjustrows = dbConnect.runSqlQuery("SELECT pricetype, isonsale,price,price_store,price_rebate,price_deposit,price_original,tag from sa_fadadjust WHERE siteid='" + siteid + "' and sa_fadid=" + sa_fadid + " and sys_enterpriseid=" + sys_enterpriseid);
+            if (adjustrows.isNotEmpty()) {
+                detailRow.putAll(adjustrows.get(0));
+            }
+        }
+
 
         return getSucReturnObject().setData(detailRow).toString();
     }
@@ -275,7 +202,7 @@ public class FadGoods extends Controller {
                 where.append(" and (");
                 where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append(")");
             }
 
@@ -323,10 +250,8 @@ public class FadGoods extends Controller {
 
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
-                        "sa_fadid", "name", "isonsale", "canadjust", "model", "pricetype", "sequence", "createby", "createdate", "onsaledate", "class")
+                        "sa_fadid", "name", "isonsale", "canadjust", "model", "pricetype", "sequence", "createby", "createdate", "onsaledate", "class", "tag")
                 .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.setSiteid(siteid);
         querySQL.setWhere("classid", 2);
         querySQL.setWhere(where.toString());
@@ -343,9 +268,6 @@ public class FadGoods extends Controller {
             row.put("attinfos", attRows);
             row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadGoodsUrl") + row.getString("sa_fadid"));
             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"), ","));
         }
 
@@ -365,6 +287,7 @@ public class FadGoods extends Controller {
                 where.append(" and (");
                 where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append(")");
             }
@@ -375,7 +298,6 @@ public class FadGoods extends Controller {
                 where.append(")");
             }
 
-
             if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
                 where.append(" and (");
                 where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
@@ -394,28 +316,28 @@ public class FadGoods extends Controller {
 
         }
 
-        ArrayList<Long> sys_enterpriseids = new ArrayList<Long>();
+
         Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
-        if (sys_enterpriseid == -1) {
+        if (sys_enterpriseid < 0) {
             return getSucReturnObject().setData(new Rows()).toString();
         }
-        sys_enterpriseids.add(sys_enterpriseid);
-        sys_enterpriseids.add(0L);
+
 
         LinkedHashSet<Long> saleareaidsPath = userInfo.getSaleareaidsPath(this, sys_enterpriseid);
         String wheresql = "t1.sa_fadid in (SELECT ownerid from sys_dataauths WHERE ownertable='sa_fad' and (sys_enterpriseid =" + sys_enterpriseid + " or sa_saleareaid in " + saleareaidsPath + "))";
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
-                        "sa_fadid", "name", "pricetype", "price", "price_deposit", "unitname")
+                        "sa_fadid", "name", "unitname")
                 .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, "sa_fadadjust", "t2", "t2.sa_fadid=t1.sa_fadid and t2.siteid=t1.siteid and t2.sys_enterpriseid=" + sys_enterpriseid);
+        querySQL.addQueryFields("pricetype", "case when t2.sa_fadadjustid>0 then t2.pricetype else t1.pricetype end");
+        querySQL.addQueryFields("price", "case when t2.sa_fadadjustid>0 then t2.price else t1.price end");
+        querySQL.addQueryFields("price_deposit", "case when t2.sa_fadadjustid>0 then t2.price_deposit else t1.price_deposit end");
+        querySQL.addQueryFields("tag", "case when t2.sa_fadadjustid>0 then t2.tag else t1.tag end");
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t1.sa_fadid not in (SELECT parentid from sa_fad WHERE sys_enterpriseid=" + sys_enterpriseid + ")");
         querySQL.setWhere(wheresql.replace("[", "(").replace("]", ")"));
-        querySQL.setWhere("sys_enterpriseid", sys_enterpriseids);
         querySQL.setWhere("classid", 2);
-        querySQL.setWhere("isonsale", 1);
+        querySQL.setWhere("t1.isonsale=1 and (t2.isonsale=1 or t2.isonsale is null)");
         querySQL.setWhere(where.toString());
         querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();
@@ -428,8 +350,6 @@ public class FadGoods extends Controller {
             Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
             attRows.sortby("sequence", "linksid");
             row.put("attinfos", attRows);
-            ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", row.getLong("sa_fadid"), true);
-            row.putIfAbsent("tag", StringUtils.join(tags, ","));
 
         }
 
@@ -449,6 +369,7 @@ public class FadGoods extends Controller {
                 where.append(" and (");
                 where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append(")");
             }
@@ -462,28 +383,26 @@ public class FadGoods extends Controller {
 
         }
 
-        ArrayList<Long> sys_enterpriseids = new ArrayList<Long>();
-        Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
-        if (sys_enterpriseid == -1) {
+        if (sys_enterpriseid < 0) {
             return getSucReturnObject().setData(new Rows()).toString();
         }
-        sys_enterpriseids.add(sys_enterpriseid);
-        sys_enterpriseids.add(0L);
+
 
         LinkedHashSet<Long> saleareaidsPath = userInfo.getSaleareaidsPath(this, sys_enterpriseid);
         String wheresql = "t1.sa_fadid in (SELECT ownerid from sys_dataauths WHERE ownertable='sa_fad' and (sys_enterpriseid =" + sys_enterpriseid + " or sa_saleareaid in " + saleareaidsPath + "))";
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
-                        "sa_fadid", "name", "pricetype", "price", "price_deposit", "unitname")
+                        "sa_fadid", "name", "unitname")
                 .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, "sa_fadadjust", "t2", "t2.sa_fadid=t1.sa_fadid and t2.siteid=t1.siteid and t2.sys_enterpriseid=" + sys_enterpriseid);
+        querySQL.addQueryFields("pricetype", "case when t2.sa_fadadjustid>0 then t2.pricetype else t1.pricetype end");
+        querySQL.addQueryFields("price", "case when t2.sa_fadadjustid>0 then t2.price else t1.price end");
+        querySQL.addQueryFields("price_deposit", "case when t2.sa_fadadjustid>0 then t2.price_deposit else t1.price_deposit end");
+        querySQL.addQueryFields("tag", "case when t2.sa_fadadjustid>0 then t2.tag else t1.tag end");
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t1.sa_fadid not in (SELECT parentid from sa_fad WHERE sys_enterpriseid=" + sys_enterpriseid + ")");
         querySQL.setWhere(wheresql.replace("[", "(").replace("]", ")"));
-        querySQL.setWhere("sys_enterpriseid", sys_enterpriseids);
         querySQL.setWhere("classid", 2);
-        querySQL.setWhere("isonsale", 1);
+        querySQL.setWhere("t1.isonsale=1 and (t2.isonsale=1 or t2.isonsale is null)");
         querySQL.setWhere("canadjust", 1);
         querySQL.setWhere(where.toString());
         querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);

+ 40 - 3
src/custom/restcontroller/webmanage/saletool/fad/FadHelper.java

@@ -25,7 +25,7 @@ public class FadHelper extends BaseClass {
         }
     }
 
-    public static InsertSQL getFadInsertSQL(Controller controller, Long sa_fadid, Long parentid) throws YosException {
+    public static InsertSQL getFadInsertSQL(Controller controller, Long sa_fadid) throws YosException {
         InsertSQL sqlFactory = SQLFactory.createInsertSQL(controller, "sa_fad");
         sqlFactory.setSiteid(controller.siteid);
         sqlFactory.setUniqueid(sa_fadid);
@@ -46,9 +46,8 @@ public class FadHelper extends BaseClass {
         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);
+        sqlFactory.setValue("tag", controller.content.getStringValue("tag"));
 
         DataContrlLog.createLog(controller, "sa_fad", sa_fadid, "新建", "新建商品 " + controller.content.getStringValue("name")).insert();
         return sqlFactory;
@@ -75,10 +74,48 @@ public class FadHelper extends BaseClass {
         sqlFactory.setValue("sequence", controller.content.getLongValue("sequence"));
         sqlFactory.setValue("content", controller.content.getStringValue("contentstr", true));
         sqlFactory.setValue("canadjust", controller.content.getLongValue("canadjust"));
+        sqlFactory.setValue("tag", controller.content.getStringValue("tag"));
         DataContrlLog.createLog(controller, "sa_fad", sa_fadid, "编辑", "编辑商品 " + controller.content.getStringValue("name")).insert();
         return sqlFactory;
     }
 
+    public static InsertSQL getFadAdjustInsertSQL(Controller controller, Long sa_fadid) throws YosException {
+
+        InsertSQL sqlFactory = SQLFactory.createInsertSQL(controller, "sa_fadadjust");
+        sqlFactory.setUniqueid(controller.createTableID("sa_fadadjust"));
+        sqlFactory.setSiteid(controller.siteid);
+        sqlFactory.setValue("sa_fadid", sa_fadid);
+        sqlFactory.setValue("sys_enterpriseid", controller.sys_enterpriseid);
+        sqlFactory.setValue("pricetype", controller.content.getStringValue("pricetype"));
+        sqlFactory.setValue("price", controller.content.getBigDecimalValue("price"));
+        sqlFactory.setValue("price_original", controller.content.getBigDecimalValue("price_original"));
+        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("tag", controller.content.getStringValue("tag"));
+        sqlFactory.setValue("isonsale", controller.content.getIntValue("isonsale"));
+
+        DataContrlLog.createLog(controller, "sa_fad", sa_fadid, "编辑", "经销商【"+controller.sys_enterpriseid+"】编辑商品 " + controller.content.getStringValue("name")).insert();
+        return sqlFactory;
+    }
+
+    public static UpdateSQL getFadAdjustUpdateSQL(Controller controller, Long sa_fadid) throws YosException {
+        UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(controller, "sa_fadadjust");
+        sqlFactory.setSiteid(controller.siteid);
+        sqlFactory.setWhere("sa_fadid", sa_fadid);
+        sqlFactory.setWhere("sys_enterpriseid", controller.sys_enterpriseid);
+        sqlFactory.setValue("pricetype", controller.content.getStringValue("pricetype"));
+        sqlFactory.setValue("price", controller.content.getBigDecimalValue("price"));
+        sqlFactory.setValue("price_original", controller.content.getBigDecimalValue("price_original"));
+        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("tag", controller.content.getStringValue("tag"));
+        sqlFactory.setValue("isonsale", controller.content.getIntValue("isonsale"));
+        DataContrlLog.createLog(controller, "sa_fad", sa_fadid, "编辑", "经销商【"+controller.sys_enterpriseid+"】编辑商品 " + controller.content.getStringValue("name")).insert();
+        return sqlFactory;
+    }
+
     public static UpdateSQL getIsOnSalesUpdateSQL(Controller controller, long sa_fadid) throws YosException {
         int isonsale = controller.content.getIntValue("isonsale");
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, "sa_fad");