Просмотр исходного кода

8703 子 营销类别管理增加经销商授权/取消授权功能

wu 2 месяцев назад
Родитель
Сommit
fb26162c66

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

@@ -7035,6 +7035,26 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2026022713381602 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026022713383702 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026022713391402 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026022714150802 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 167 - 19
src/custom/restcontroller/webmanage/sale/enterprisesaleclass/EnterpriseSaleClass.java

@@ -1,15 +1,13 @@
 package restcontroller.webmanage.sale.enterprisesaleclass;
 
 import beans.itemclass.ItemClass;
+import beans.salearea.SaleArea;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import common.Controller;
 import common.YosException;
 import common.annotation.API;
-import common.data.QuerySQL;
-import common.data.Row;
-import common.data.Rows;
-import common.data.SQLFactory;
+import common.data.*;
 import restcontroller.R;
 
 import java.util.ArrayList;
@@ -25,7 +23,7 @@ public class EnterpriseSaleClass extends Controller {
         super(content);
     }
 
-    @API(title = "新增", apiversion = R.ID20220924134302.v1.class,intervaltime = 200)
+    @API(title = "新增", apiversion = R.ID20220924134302.v1.class, intervaltime = 200)
     public String insert() throws YosException {
         Long sys_enterpriseid = content.getLong("sys_enterpriseid");
         JSONArray itemclassids = content.getJSONArray("itemclassid");
@@ -65,7 +63,7 @@ public class EnterpriseSaleClass extends Controller {
         Rows rows = dbConnect.runSqlQuery(sqlFactoryquery);
 
         ArrayList<Long> itemclassids = rows.toArrayList("itemclassid", new ArrayList<>());
-        ArrayList<Long> needitemclassids= ItemClass.getSubItemClassIds(this, itemclassids);
+        ArrayList<Long> needitemclassids = ItemClass.getSubItemClassIds(this, itemclassids);
         needitemclassids.addAll(itemclassids);
         long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
         SQLFactory sqlFactory = new SQLFactory(this, "合作企业营销类别删除");
@@ -79,8 +77,8 @@ public class EnterpriseSaleClass extends Controller {
                 + siteid + "'";
         sql = sql.replace("[", "(").replace("]", ")");
         Rows rows1 = dbConnect.runSqlQuery(sql);
-        for (Row row:rows1) {
-            DeleteItemclass(row.getLong("parentid"),sys_enterpriseid);
+        for (Row row : rows1) {
+            DeleteItemclass(row.getLong("parentid"), sys_enterpriseid);
         }
 
         return getSucReturnObject().toString();
@@ -96,12 +94,12 @@ public class EnterpriseSaleClass extends Controller {
 //        Rows rows = dbConnect.runSqlQuery(sql);
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_saleclass", "sys_enterprise_saleclassid", "itemclassid"
-               );
+        );
         querySQL.setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.inner, "plm_itemclass", "t3", "t3.itemclassid = t1.itemclassid and t3.siteid = t1.siteid","itemclassname","itemclassfullname");
-        querySQL.addJoinTable(JOINTYPE.left, "sa_brand", "t2", "t2.sa_brandid=t3.sa_brandid and t2.siteid=t3.siteid","brandname");
+        querySQL.addJoinTable(JOINTYPE.inner, "plm_itemclass", "t3", "t3.itemclassid = t1.itemclassid and t3.siteid = t1.siteid", "itemclassname", "itemclassfullname");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_brand", "t2", "t2.sa_brandid=t3.sa_brandid and t2.siteid=t3.siteid", "brandname");
         querySQL.setSiteid(siteid);
-        querySQL.setWhere("t1.sys_enterpriseid",sys_enterpriseid);
+        querySQL.setWhere("t1.sys_enterpriseid", sys_enterpriseid);
         querySQL.setWhere("ifnull(t1.itemclassid,0)!=0");
         querySQL.setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();
@@ -110,18 +108,18 @@ public class EnterpriseSaleClass extends Controller {
     }
 
 
-    private void DeleteItemclass( long parentid,long sys_enterpriseid)
+    private void DeleteItemclass(long parentid, long sys_enterpriseid)
             throws YosException {
         if (parentid > 0) {
             Rows rows = dbConnect.runSqlQuery(
-                    "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='"+sys_enterpriseid+"' and t1.siteid='"+siteid+"' and t1.itemclassid= '"
+                    "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='" + sys_enterpriseid + "' and t1.siteid='" + siteid + "' and t1.itemclassid= '"
                             + parentid + "'");
             if (!rows.isEmpty()) {
-                if(dbConnect.runSqlQuery(
-                        "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='"+sys_enterpriseid+"' and t1.siteid='"+siteid+"' and t2.parentid= '"
-                                + rows.get(0).getLong("itemclassid") + "'").isEmpty()){
-                    dbConnect.runSqlUpdate("delete from  sys_enterprise_saleclass  where itemclassid= '" + rows.get(0).getLong("itemclassid") + "' and sys_enterpriseid='"+sys_enterpriseid+"' and siteid='"+siteid+"'");
-                    DeleteItemclass( rows.get(0).getLong("parentid"),sys_enterpriseid);
+                if (dbConnect.runSqlQuery(
+                        "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='" + sys_enterpriseid + "' and t1.siteid='" + siteid + "' and t2.parentid= '"
+                                + rows.get(0).getLong("itemclassid") + "'").isEmpty()) {
+                    dbConnect.runSqlUpdate("delete from  sys_enterprise_saleclass  where itemclassid= '" + rows.get(0).getLong("itemclassid") + "' and sys_enterpriseid='" + sys_enterpriseid + "' and siteid='" + siteid + "'");
+                    DeleteItemclass(rows.get(0).getLong("parentid"), sys_enterpriseid);
                 }
 
             }
@@ -129,5 +127,155 @@ public class EnterpriseSaleClass extends Controller {
         }
     }
 
+    @API(title = "新增授权经销商", apiversion = R.ID2026022713381602.v1.class)
+    public String inertAgents() throws YosException {
+        Long itemclassid = content.getLongValue("itemclassid");
+        JSONArray sys_enterpriseids = content.getJSONArray("sys_enterpriseids");
+        ArrayList<String> sqlList = new ArrayList<>();
+        for (Object obj : sys_enterpriseids) {
+            String id = String.valueOf(obj);
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_saleclass");
+            insertSQL.setSiteid(siteid);
+            insertSQL.setUniqueid(createTableID("sys_enterprise_saleclass"));
+            insertSQL.setValue("sys_enterpriseid", id);
+            insertSQL.setValue("itemclassid", itemclassid);
+            sqlList.add(insertSQL.getSQL());
+        }
+        dbConnect.runSqlUpdate(sqlList);
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "删除授权经销商", apiversion = R.ID2026022713383702.v1.class)
+    public String deleteAgents() throws YosException {
+
+        JSONArray sys_enterprise_saleclassids = content.getJSONArray("sys_enterprise_saleclassids");
+
+        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_enterprise_saleclass");
+        deleteSQL.setSiteid(siteid);
+        deleteSQL.setWhere("sys_enterprise_saleclassid", sys_enterprise_saleclassids.toArray());
+        deleteSQL.delete();
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "查询授权经销商", apiversion = R.ID2026022713391402.v1.class)
+    public String queryAgents() 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.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t4.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+
+        }
+
+        Long itemclassid = content.getLongValue("itemclassid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents", "sys_enterpriseid",
+                "sa_agentsid", "agentnum",  "type", "signdate",   "signingstate",  "signdate");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "abbreviation");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t4", "t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid",
+                "erpagentnum");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_saleclass", "t5", "t1.sys_enterpriseid = t5.sys_enterpriseid ","sys_enterprise_saleclassid");
+        querySQL.addQueryFields("status", "case when t1.status='1' then '审核' else '新建' end");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere("t5.itemclassid", itemclassid);
+        querySQL.setWhere(where);
+
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+        ArrayList<Long> ids = rows.toArrayList("sys_enterpriseid", new ArrayList<>());
+        ids.add(0l);
+
+        String sql = "select t1.sys_enterpriseid,t2.areaname from sys_enterprise_tradefield t1 inner join sa_salearea t2 on t1.sa_saleareaid=t2.sa_saleareaid and t1.siteid=t2.siteid  where t1.siteid='" + siteid + "' and t1.sys_enterpriseid in" + ids;
+        sql = sql.replace("[", "(").replace("]", ")");
+        Rows enterpriseSaleareaRows = dbConnect.runSqlQuery(sql);
+        RowsMap enterpriseSaleareaRowsMap = enterpriseSaleareaRows.toRowsMap("sys_enterpriseid");
+
+        for (Row row : rows) {
+
+
+            if (enterpriseSaleareaRowsMap.containsKey(row.getString("sys_enterpriseid"))) {
+                row.put("areaname", enterpriseSaleareaRowsMap.get(row.getString("sys_enterpriseid")).get(0).getString("areaname"));
+            } else {
+                row.put("areaname", "");
+            }
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "查询可添加的经销商列表", apiversion = R.ID2026022714150802.v1.class)
+    public String newApiMethod() 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.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t4.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+
+        }
+
+        Long itemclassid = content.getLongValue("itemclassid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents", "sys_enterpriseid",
+                "sa_agentsid", "agentnum",  "type", "signdate",   "signingstate",  "signdate");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "abbreviation");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t4", "t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid",
+                "erpagentnum");
+//        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise_saleclass", "t5", "t1.sys_enterpriseid = t5.sys_enterpriseid ","sys_enterprise_saleclassid");
+        querySQL.addQueryFields("status", "case when t1.status='1' then '审核' else '新建' end");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere("not EXISTS(SELECT 1 from sys_enterprise_saleclass WHERE sys_enterpriseid=t1.sys_enterpriseid and itemclassid="+itemclassid+" )");
+        querySQL.setWhere(where);
+
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+        ArrayList<Long> ids = rows.toArrayList("sys_enterpriseid", new ArrayList<>());
+        ids.add(0l);
+
+        String sql = "select t1.sys_enterpriseid,t2.areaname from sys_enterprise_tradefield t1 inner join sa_salearea t2 on t1.sa_saleareaid=t2.sa_saleareaid and t1.siteid=t2.siteid  where t1.siteid='" + siteid + "' and t1.sys_enterpriseid in" + ids;
+        sql = sql.replace("[", "(").replace("]", ")");
+        Rows enterpriseSaleareaRows = dbConnect.runSqlQuery(sql);
+        RowsMap enterpriseSaleareaRowsMap = enterpriseSaleareaRows.toRowsMap("sys_enterpriseid");
+
+        for (Row row : rows) {
+
+
+            if (enterpriseSaleareaRowsMap.containsKey(row.getString("sys_enterpriseid"))) {
+                row.put("areaname", enterpriseSaleareaRowsMap.get(row.getString("sys_enterpriseid")).get(0).getString("areaname"));
+            } else {
+                row.put("areaname", "");
+            }
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
 
 }