Selaa lähdekoodia

经销商管理

wu 2 kuukautta sitten
vanhempi
commit
fb547bb91e

+ 5 - 0
src/custom/restcontroller/ClientUserInfo.java

@@ -111,6 +111,11 @@ public class ClientUserInfo extends UserInfo {
         return rows.toArrayList("sa_saleareaid", new ArrayList<>());
     }
 
+    public ArrayList<Long> getHrSaleAreaIds(Long hrid) throws YosException {
+        Rows rows = controller.dbConnect.runSqlQuery("select distinct sa_saleareaid from sys_enterprise_tradefield where siteid='" + getSiteId() + "' and hrid=" + hrid);
+        return rows.toArrayList("sa_saleareaid", new ArrayList<>());
+    }
+
     public Row getReportHrRow() throws YosException {
         if (reportHrRow == null) {
             Rows hrRows = controller.dbConnect.runSqlQuery("SELECT t2.*FROM sys_hr t1 INNER JOIN sys_hr t2 ON t2.hrid=t1.reporthrid AND t2.siteid=t1.siteid WHERE t1.siteid='" + getSiteId() + "' AND t1.userid=" + getUserId());

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

@@ -7317,6 +7317,11 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025102310145302 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 13 - 21
src/custom/restcontroller/webmanage/sale/agents/SQL/经销商详情查询.sql

@@ -1,6 +1,5 @@
 select t1.sys_enterpriseid,
        t1.enterprisename,
-       t1.contact,
        t1.address,
        t1.phonenumber,
        t1.province,
@@ -8,36 +7,29 @@ select t1.sys_enterpriseid,
        t1.county,
        t2.sa_agentsid,
        t2.agentnum,
-       t2.type,
-       t1.industry,
-       t1.taxno,
-       t1.saleclassauth,
-       t1.standardsauth,
-       t2.signdate,
        t2.createby,
        t2.createdate,
+       t2.changeby,
+       t2.changedate,
        t2.status,
        t2.parentid,
+       t2.gmname,
+       t2.gmphonenumber,
+       t2.remarks,
+       t2.cooperatetype,
        (SELECT enterprisename
         FROM sys_enterprise
         WHERE sys_enterpriseid =
               (SELECT sys_enterpriseid FROM sa_agents WHERE sa_agentsid = t2.parentid)) parent_enterprisename,
-       t4.erpagentnum,
-       t2.isservice,
-       t1.limitreturnday,
-       t1.freefreightamount,
-       t1.invoicingpoint,
-       t2.cooperationstatus,
-       concat(t8.value, '-', t8.remarks)                                                gradereamarks,
-       t1.grade
+       t3.erpagentnum,
+       t4.deletereason,
+       t4.changedate                                              deletechangedate,
+       t4.changeby                                                deletechangeby
 from sys_enterprise t1
          inner join sa_agents t2 on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
+         LEFT JOIN sys_dataextend t3
+                   ON t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid
          LEFT JOIN sys_dataextend t4
-                   ON t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid
-         left join(select t7.value, siteid, t7.remarks
-                   from sys_optiontype t6
-                            inner join sys_optiontypemx t7
-                                       on t6.optiontypeid = t7.optiontypeid
-                   where t6.typename = 'agentgrade') t8 on t8.value = t1.grade
+                   ON t2.siteid = t4.siteid and t2.sa_agentsid = t4.ownerid and t4.ownertable = 'sa_agents'
 where t1.siteid = $siteid$
   and t2.sa_agentsid = $sa_agentsid$

+ 120 - 230
src/custom/restcontroller/webmanage/sale/agents/agents.java

@@ -100,257 +100,169 @@ public class agents extends Controller {
         SQLFactory sqlFactory = new SQLFactory(this, "经销商详情查询");
         sqlFactory.addParameter("sa_agentsid", sa_agentsid);
         sqlFactory.addParameter("siteid", siteid);
-        Rows agentRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
-        for (Row agentRow : agentRows) {
-            agentRow.put("hrs", getEnterpriseHrs(agentRow.getLong("sys_enterpriseid")));
-
-            SQLFactory salersql = new SQLFactory(this, "经销商详情查询_业务员查询");
-            salersql.addParameter("siteid", siteid);
-            salersql.addParameter_in("sa_saleareaid", SaleArea.getSaleAreaIds(this, agentRow.getLong("sys_enterpriseid")));
-            Rows salerrows = dbConnect.runSqlQuery(salersql.getSQL());
-            agentRow.put("salers", salerrows);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        RowsMap areaRowsMap = getAreaRowsMap(rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        RowsMap salerRowsMap = getSalerNameRowsMap(rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        for (Row row : rows) {
+            row.put("hrs", getEnterpriseHrs(row.getLong("sys_enterpriseid")));
+            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
+            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
+            row.putIfAbsent("scale", "");
+            row.putIfAbsent("mainproducts", "");
         }
-        return getSucReturnObject().setData(agentRows.isNotEmpty() ? agentRows.get(0) : new Row()).toString();
+        return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
+    }
+
+    public RowsMap getAreaRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
+
+        String sql = "SELECT DISTINCT t2.areaname,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
+                "INNER JOIN sa_salearea t2 ON t2.sa_saleareaid=t1.sa_saleareaid " +
+                "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
+        sql = sql.replace("[", "(").replace("]", ")");
+
+        return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
+    }
+
+    public RowsMap getSalerNameRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
+
+        String sql = "SELECT DISTINCT t2.name,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
+                "INNER JOIN sys_hr t2 ON t2.hrid=t1.hrid " +
+                "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
+        sql = sql.replace("[", "(").replace("]", ")");
+
+        return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
     }
 
 
-    @API(title = "经销商新增修改", intervaltime = 2000)
+    @API(title = "经销商新增修改", apiversion = R.ID2025102310145302.v1.class, intervaltime = 2000)
     @CACHEING_CLEAN(cms = {@cm(clazz = agents.class, method = {"query_agentList", "query_agentMain"}), @cm(clazz = salearea.class, method = {"query_agent"}), @cm(clazz = salearea.class, method = {"query_agent"})},
             apiversions = {R.ID20220920083901.v1.class, R.ID20221022165803.v1.class, R.ID20220920083901.v1.class, R.ID20221012164402.v1.class})
     public String insertormodify_agent() throws YosException {
-        long sa_agentsid = content.getLongValue("sa_agentsid");//新增时传0
-        long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
-        long parentid = content.getLongValue("parentid");
-        String agentnum = content.getString("agentnum", "sa_agents");
-        JSONArray type = content.getJSONArray("type");
-        String signdate = content.getStringValue("signdate");
-        String cooperationstatus = content.getStringValue("cooperationstatus");
-        long isallsale = content.getLongValue("isallsale");
 
+        Long sa_agentsid = content.getLongValue("sa_agentsid");
+        Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
+        String enterprisename = content.getStringValue("enterprisename");
+        String cooperatetype = content.getStringValue("cooperatetype");
+        String agentnum = content.getStringValue("agentnum");
+        String erpagentnum = content.getStringValue("erpagentnum");
+        String gmname = content.getStringValue("gmname");
+        String gmphonenumber = content.getStringValue("gmphonenumber");
+        String province = content.getStringValue("province");
+        String city = content.getStringValue("city");
+        String county = content.getStringValue("county");
+        String address = content.getStringValue("address");
+        Long parentid = content.getLongValue("parentid");
+        String remarks = content.getStringValue("remarks");
+
+        ArrayList<String> sqllist = new ArrayList<>();
         Boolean isadd = Boolean.FALSE;
 
         if (parentid != 0 && dbConnect.runSqlQuery("select * from sa_agents where siteid='" + siteid + "' and sa_agentsid=" + parentid).isEmpty()) {
-            return getReturnObject().setCode("0186",new String[0]).toString();//指定的上级商户不存在
-
+            return getReturnObject().setCode("0186").toString();//指定的上级商户不存在
         }
 
-        Row enterpriseRow = Enterprise.getEnterprise(this, sys_enterpriseid);
-        if (enterpriseRow.isEmpty()) {
-            return getReturnObject().setCode("0189",new String[0]).toString();//未选择企业
+        if (sys_enterpriseid <= 0) {
+            sys_enterpriseid = createTableID("sys_enterprise");
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise");
+            insertSQL.setSiteid(siteid);
+            insertSQL.setUniqueid(sys_enterpriseid);
+            insertSQL.setValue("enterprisename", enterprisename);
+            insertSQL.setValue("province", province);
+            insertSQL.setValue("city", city);
+            insertSQL.setValue("county", county);
+            insertSQL.setValue("address", address);
+            sqllist.add(insertSQL.getSQL());
+        } else {
+            UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_enterprise");
+            updateSQL.setSiteid(siteid);
+            updateSQL.setUniqueid(sys_enterpriseid);
+            updateSQL.setValue("enterprisename", enterprisename);
+            updateSQL.setValue("province", province);
+            updateSQL.setValue("city", city);
+            updateSQL.setValue("county", county);
+            updateSQL.setValue("address", address);
+            sqllist.add(updateSQL.getSQL());
         }
-        String enterprisename = enterpriseRow.getString("enterprisename");
-
-        ArrayList<String> sqllist = new ArrayList<>();
-        SQLFactory sqlFactory = new SQLFactory(this, "经销商新增");
-        if (sa_agentsid <= 0 || dbConnect.runSqlQuery("select sa_agentsid from sa_agents where sa_agentsid=" + sa_agentsid).isEmpty()) {
-            if (dbConnect.runSqlQuery("select sa_agentsid from sa_agents where sys_enterpriseid=" + sys_enterpriseid).isNotEmpty()) {
-                return getReturnObject().setCode("0187",new String[0]).toString();//当前商户已经创建经销商档案,不可重复创建
 
-            }
+        if (sa_agentsid <= 0) {
             isadd = Boolean.TRUE;
             sa_agentsid = createTableID("sa_agents");
-            addAccount(sys_enterpriseid);
-            Rows customersRows = dbConnect.runSqlQuery("SELECT sa_customersid from sa_customers WHERE sys_enterpriseid =" + sys_enterpriseid + " and siteid = '" + siteid + "'");
-            if (customersRows.isNotEmpty()) {
-                Long id = customersRows.get(0).getLong("sa_customersid");
-                ArrayList<Long> userids = DataTeam.queryTeamRowWithoutHeadpic(this, "sa_customers", id).toArrayList("userid", new ArrayList<>());
-                JSONObject extradata = new JSONObject();
-                extradata.put("extraUserList", userids);
-                Executor.sendEml_controller(this, "customers_agent_add", sa_agentsid, extradata);
-            }
-            sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "新建", "新建合作伙伴:" + enterprisename).getSQL());
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_agents");
+            insertSQL.setSiteid(siteid);
+            insertSQL.setUniqueid(sa_agentsid);
+            insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
+            insertSQL.setValue("cooperatetype", cooperatetype);
+            insertSQL.setValue("agentnum", agentnum);
+            insertSQL.setValue("gmname", gmname);
+            insertSQL.setValue("gmphonenumber", gmphonenumber);
+            insertSQL.setValue("parentid", parentid);
+            insertSQL.setValue("remarks", remarks);
+            insertSQL.setValue("status", "启用");
+            sqllist.add(insertSQL.getSQL());
+            sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "新建", "新建经销商:" + enterprisename).getSQL());
         } else {
-            sqlFactory = new SQLFactory(this, "经销商修改");
-            sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "编辑", "编辑合作伙伴:" + enterprisename).getSQL());
+            UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_agents");
+            updateSQL.setSiteid(siteid);
+            updateSQL.setUniqueid(sa_agentsid);
+            updateSQL.setValue("cooperatetype", cooperatetype);
+            updateSQL.setValue("agentnum", agentnum);
+            updateSQL.setValue("gmname", gmname);
+            updateSQL.setValue("gmphonenumber", gmphonenumber);
+            updateSQL.setValue("parentid", parentid);
+            updateSQL.setValue("remarks", remarks);
+            sqllist.add(updateSQL.getSQL());
+            sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "编辑", "编辑经销商:" + enterprisename).getSQL());
         }
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("sa_agentsid", sa_agentsid);
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        sqlFactory.addParameter("username", username);
-        sqlFactory.addParameter("changeuserid", userid);
-        sqlFactory.addParameter("agentnum", agentnum);
-        sqlFactory.addParameter("type", type);
-        sqlFactory.addParameter("cooperationstatus", cooperationstatus);
-        sqlFactory.addParameter("parentid", parentid == 0 ? "null" : String.valueOf(parentid));
-        sqlFactory.addParameter("signdate", signdate.equals("") ? "null" : signdate);
-        sqlFactory.addParameter("isservice", content.getLongValue("isservice", 0L));
-        sqllist.add(sqlFactory.getSQL());
+
 
         //扩展字段
-        String erpagentnum = content.getStringValue("erpagentnum");
         String sql = "SELECT * from sys_dataextend WHERE ownertable='sys_enterprise' and ownerid=" + sys_enterpriseid + " and siteid = '" + siteid + "'";
         Rows extendRows = dbConnect.runSqlQuery(sql);
         Long sys_dataextendid = 0L;
         if (extendRows.isEmpty()) {
             sys_dataextendid = createTableID("sys_dataextend");
-            sqlFactory = new SQLFactory(this, "经销商扩展字段新增");
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_dataextend");
+            insertSQL.setSiteid(siteid);
+            insertSQL.setUniqueid(sys_dataextendid);
+            insertSQL.setValue("ownerid", sys_enterpriseid);
+            insertSQL.setValue("ownertable", "sys_enterprise");
+            insertSQL.setValue("erpagentnum", erpagentnum);
+            sqllist.add(insertSQL.getSQL());
         } else {
             sys_dataextendid = extendRows.get(0).getLong("sys_dataextendid");
-            sqlFactory = new SQLFactory(this, "经销商扩展字段更新");
-
+            UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_dataextend");
+            updateSQL.setSiteid(siteid);
+            updateSQL.setUniqueid(sys_dataextendid);
+            updateSQL.setValue("ownerid", sys_enterpriseid);
+            updateSQL.setValue("ownertable", "sys_enterprise");
+            updateSQL.setValue("erpagentnum", erpagentnum);
+            sqllist.add(updateSQL.getSQL());
         }
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("username", username);
-        sqlFactory.addParameter("userid", userid);
-        sqlFactory.addParameter("sys_dataextendid", sys_dataextendid);
-        sqlFactory.addParameter("ownerid", sys_enterpriseid);
-        sqlFactory.addParameter("ownertable", "sys_enterprise");
-        sqlFactory.addParameter("erpagentnum", erpagentnum);
-        sqllist.add(sqlFactory.getSQL());
-
-
-        sqlFactory = new SQLFactory(this, "商户档案修改");
-        sqlFactory.addParameter("limitreturnday", content.getLongValue("limitreturnday"));
-        sqlFactory.addParameter("freefreightamount", content.getBigDecimalValue("freefreightamount"));
-        //开票节点(1:订单审核:2:发货)
-        sqlFactory.addParameter("invoicingpoint", content.getLongValue("invoicingpoint") == 0 ? 2 : content.getLongValue("invoicingpoint"));
-        //是否需要经营授权,默认1
-        sqlFactory.addParameter("saleclassauth", content.getBooleanValue("saleclassauth") == false ? 0 : 1);
-        //是否需要标准授权,默认1
-        sqlFactory.addParameter("standardsauth", content.getBooleanValue("standardsauth") == false ? 0 : 1);
-        sqlFactory.addParameter("grade", content.getLongValue("grade"));
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("username", username);
-        sqlFactory.addParameter("changeuserid", userid);
-        sqllist.add(sqlFactory.getSQL());
-
-
-        //企业信息同步到【我的客户】,并将该客户打上经销商标签,
-        Rows customersRows = dbConnect.runSqlQuery("SELECT sa_customersid,datastatus from sa_customers WHERE sys_enterpriseid =" + sys_enterpriseid + " and siteid = '" + siteid + "'");
-
-        String phonenumber = enterpriseRow.getString("phonenumber");
-        String taxno = enterpriseRow.getString("taxno");
-        String address = enterpriseRow.getString("address");
-        Long sa_customersid = 0L;
-        if (customersRows.isNotEmpty()) {
-            sa_customersid = customersRows.get(0).getLong("sa_customersid");
-            Long datastatus = customersRows.get(0).getLong("datastatus");
-            if (isadd && datastatus == 1) {
-                sqllist.add(DataContrlLog.createLog(this, "sa_customers", sa_customersid, "恢复", "从回收站内恢复").getSQL());
-                sqllist.add("update sa_customers set datastatus =0 where siteid='" + siteid + "' and sa_customersid=" + sa_customersid);
-            }
-            sqlFactory = new SQLFactory(this, "客户更新");
 
-        } else {
-            sa_customersid = createTableID("sa_customers");
-            sqlFactory = new SQLFactory(this, "客户新增");
-
-            //添加财务信息
-            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_finance");
-            Long sys_enterprise_financeid = createTableID("sys_enterprise_finance");
-            insertSQL.setSiteid(siteid);
-            insertSQL.setValue("sys_enterprise_financeid", sys_enterprise_financeid);
-            insertSQL.setValue("changeuserid", userid);
-            insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
-            insertSQL.setValue("enterprisename", enterprisename);
-            insertSQL.setValue("phonenumber", phonenumber);
-            insertSQL.setValue("taxno", taxno);
-            insertSQL.setValue("address", address);
-            insertSQL.setValue("isdefault", 1);
-            sqllist.add(insertSQL.getSQL());
-            sqllist.add(DataContrlLog.createLog(this, "sys_enterprise_finance", sys_enterprise_financeid, "新建开票信息", "新建开票信息" + enterprisename).getSQL());
-
-            //添加地址
+        //添加地址
+        if (isadd) {
             Long contactsid = createTableID("sys_enterprise_contacts");
-            insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_contacts");
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_contacts");
             insertSQL.setSiteid(siteid);
             insertSQL.setValue("contactsid", contactsid);
             insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
-            insertSQL.setValue("createuserid", userid);
-            insertSQL.setValue("createby", username);
-            insertSQL.setDateValue("createdate");
-            insertSQL.setValue("changeuserid", userid);
-            insertSQL.setValue("changeby", username);
-            insertSQL.setValue("name", enterpriseRow.getString("contact"));
-            insertSQL.setValue("province", enterpriseRow.getString("province"));
-            insertSQL.setValue("city", enterpriseRow.getString("city"));
-            insertSQL.setValue("county", enterpriseRow.getString("county"));
+            insertSQL.setValue("name", gmname);
+            insertSQL.setValue("province", province);
+            insertSQL.setValue("city", city);
+            insertSQL.setValue("county", county);
             insertSQL.setValue("address", address);
-            insertSQL.setValue("phonenumber", phonenumber);
-            insertSQL.setDateValue("changedate");
+            insertSQL.setValue("phonenumber", gmphonenumber);
             insertSQL.setValue("workaddress", 1);
             insertSQL.setValue("isdefault", 1);
             insertSQL.setValue("isprimary", 1);
             sqllist.add(insertSQL.getSQL());
         }
 
-        if (siteid.equals("HY")) {
-            sqlFactory.addParameter("reward_point", "[\"订单核销审核\", \"物流单审核\", \"开票审核\"]");
-            sqlFactory.addParameter("reward_rate", 0);
-        } else {
-            sqlFactory.addParameter("reward_point", "null");
-            sqlFactory.addParameter("reward_rate", "null");
-        }
-        long parent_sa_customersid = 0L;
-        Rows rows = dbConnect.runSqlQuery("SELECT sa_customersid from sa_customers WHERE sys_enterpriseid in (SELECT sys_enterpriseid from sa_agents WHERE sa_agentsid=" + parentid + ") and siteid='" + siteid + "'");
-        if (rows.isNotEmpty()) {
-            parent_sa_customersid = rows.get(0).getLong("sa_customersid");
-        }
-
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("userid", userid);
-        sqlFactory.addParameter("username", username);
-        sqlFactory.addParameter("sa_customersid", sa_customersid);
-        //上级客户ID
-        sqlFactory.addParameter("parentid", parent_sa_customersid);
-        //合作企业档案ID
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        //客户类型
-        sqlFactory.addParameter("type", "经销商");
-        //客户池(公海池)ID
-        sqlFactory.addParameter("sa_customerpoolid", 0);
-        //客户来源
-        sqlFactory.addParameter("source", "经销商同步");
-        sqlFactory.addParameter("customergrade", "null");
-        sqlFactory.addParameter("ispublic", 0);
-        sqlFactory.addParameter("name", enterpriseRow.getString("enterprisename"));
-        sqlFactory.addParameter("province", enterpriseRow.getString("province"));
-        sqlFactory.addParameter("city", enterpriseRow.getString("city"));
-        sqlFactory.addParameter("county", enterpriseRow.getString("county"));
-        sqlFactory.addParameter("address", enterpriseRow.getString("address"));
-        sqlFactory.addParameter("phonenumber", enterpriseRow.getString("phonenumber"));
-        sqllist.add(sqlFactory.getSQL());
-
-
-        String bank = content.getStringValue("bank");
-        String bankcardno = content.getStringValue("bankcardno");
-        String bankname = content.getStringValue("bankname");
-
-        if (StringUtils.isNotEmpty(bankname) && StringUtils.isNotEmpty(bankcardno) && StringUtils.isNotEmpty(bank)) {
-            long sys_enterprise_bankid = content.getLongValue("sys_enterprise_bankid");
-            if (sys_enterprise_bankid <= 0 || dbConnect.runSqlQuery("select 1 from sys_enterprise_bank where siteid='" + siteid + "' and sys_enterprise_bankid=" + sys_enterprise_bankid).isEmpty()) {
-                sys_enterprise_bankid = createTableID("sys_enterprise_bank");
-                sqlFactory = new SQLFactory(this, "银行卡信息新增");
-                sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "新建", "新建银行卡:" + bankcardno).getSQL());
-            } else {
-                sqlFactory = new SQLFactory(this, "银行卡信息修改");
-                sqllist.add(DataContrlLog.createLog(this, "sa_agents", sa_agentsid, "编辑", "编辑银行卡:" + bankcardno).getSQL());
-            }
-            sqlFactory.addParameter("siteid", siteid);
-            sqlFactory.addParameter("sys_enterprise_bankid", sys_enterprise_bankid);
-            sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-            sqlFactory.addParameter("name", bankname);
-            sqlFactory.addParameter("bankcardno", bankcardno);
-            sqlFactory.addParameter("bank", bank);
-            sqlFactory.addParameter("userid", userid);
-            sqlFactory.addParameter("username", username);
-            sqllist.add(sqlFactory.getSQL());
-        }
         dbConnect.runSqlUpdate(sqllist);
         content.put("sa_agentsid", sa_agentsid);
 
-        ArrayList<String> typeList = dbConnect.runSqlQuery("SELECT value from  sys_optiontypemx WHERE optiontypeid in (SELECT optiontypeid from sys_optiontype WHERE typename='agenttypemx')").toArrayList("value");
-        DataTag.deleteTag(this, "sa_customers", sa_customersid, typeList);
-        if (customersRows.isEmpty()) {
-            DataTag.createSystemTag(this, "sa_customers", sa_customersid, "潜在");
-        }
-        //打经销商标签
-        for (Object obj : type) {
-            DataTag.createSystemTag(this, "sa_customers", sa_customersid, obj.toString());
-        }
-
-        updateprojecttag(sys_enterpriseid);
         return query_agentMain();
     }
 
@@ -727,7 +639,7 @@ public class agents extends Controller {
             String addr = row.getString("province") + row.getString("city") + row.getString("county") + row.getString("address");
 
             if (row.getBoolean("isdefault")) {
-                batchDeleteErr.addErr(row.getLong("contactsid"), "0662",new String[]{row.getString("name")});
+                batchDeleteErr.addErr(row.getLong("contactsid"), "0662", new String[]{row.getString("name")});
                 continue;
             } else {
                 sqlList.add("update sys_enterprise_contacts set deleted=1 where contactsid =" + row.getLong("contactsid"));
@@ -1104,26 +1016,4 @@ public class agents extends Controller {
         }
         return sheet;
     }
-
-    public void updateprojecttag(Long sys_enterpriseid) throws YosException {
-        SQLFactory sqlFactory = new SQLFactory(this, "客户关联项目查询");
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        ArrayList<Long> projectidList = dbConnect.runSqlQuery(sqlFactory).toArrayList("sa_projectid", new ArrayList<Long>());
-        sqlFactory = new SQLFactory(this, "项目关联客户类型查询");
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter_in("sa_projectid", projectidList);
-        RowsMap cusTagRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_projectid");
-        HashMap<Long, ArrayList<String>> projectTagRowsMap = DataTag.queryTag(this, "sa_project", projectidList, true);
-        for (Long sa_projectid : projectTagRowsMap.keySet()) {
-            ArrayList<String> cusTagList = cusTagRowsMap.get(sa_projectid.toString()).toArrayList("tag");
-            if (cusTagList.contains("经销商") && !projectTagRowsMap.get(sa_projectid).contains("经销")) {
-                DataTag.deleteTag(this, "sa_project", sa_projectid, "直销");
-                DataTag.createSystemTag(this, "sa_project", sa_projectid, "经销");
-            } else if (!cusTagList.contains("经销商") && cusTagList.contains("直销客户") && !projectTagRowsMap.get(sa_projectid).contains("直销")) {
-                DataTag.deleteTag(this, "sa_project", sa_projectid, "经销");
-                DataTag.createSystemTag(this, "sa_project", sa_projectid, "直销");
-            }
-        }
-    }
 }

+ 0 - 3
src/custom/restcontroller/webmanage/sale/salearea/SQL/营销区域经销商查询.sql

@@ -11,15 +11,12 @@ from (select distinct t1.sa_agentsid,
                       t2.county,
                       t2.address,
                       t1.status,
-                      t1.isservice,
                       t2.limitreturnday,
                       t2.freefreightamount,
                       t2.invoicingpoint,
                       t3.userid,
                       t6.accountno,
                       t4.erpagentnum,
-                      t1.cooperationstatus,
-                      t1.type,
                       t7.deletereason,
                       t7.changedate                                              deletechangedate,
                       t7.changeby                                                deletechangeby

+ 0 - 125
src/custom/restcontroller/webmanage/sale/salearea/salearea.java

@@ -354,131 +354,6 @@ public class salearea extends Controller {
         return batchDeleteErr.getReturnObject().toString();
     }
 
-    @API(title = "营销区域查询经销商", apiversion = R.ID20221011144903.v1.class)
-    @CACHEING
-    public String query_agent() throws YosException, IOException {
-        /*
-          过滤条件设置
-         */
-        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(")");
-            }
-
-            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
-                where.append(" and ");
-                where.append("t1.status = '").append(whereObject.getString("status").equals("ACTIVE") ? "启用" : "禁用").append("' ");
-            }
-            if (whereObject.containsKey("cooperationstatus") && !"".equals(whereObject.getString("cooperationstatus"))) {
-                where.append(" and ");
-                where.append("t1.cooperationstatus = '").append(whereObject.getString("cooperationstatus")).append("' ");
-            }
-            if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
-                where.append(" and ");
-                where.append("t1.type like '%").append(whereObject.getString("type")).append("%' ");
-            }
-        }
-        boolean isdeleted = content.getBooleanValue("isdeleted");
-        if (isdeleted) {
-            where.append(" and t1.status ='作废' ");
-        } else {
-            where.append(" and t1.status !='作废' ");
-        }
-        boolean containssub = content.getBoolean("containssub");
-        JSONArray sa_saleareaidsArray = content.getJSONArray("sa_saleareaids");
-        ArrayList<Long> sa_saleareaidsList = new ArrayList<>();
-        for (Object o : sa_saleareaidsArray) {
-            String sa_saleareaid = o.toString();
-            sa_saleareaidsList.add(Long.parseLong(sa_saleareaid));
-            if (containssub) {
-                sa_saleareaidsList.addAll(SaleArea.getSubSaleAreaIds(this, Long.parseLong(sa_saleareaid)));
-            }
-        }
-        boolean isExport = content.getBooleanValue("isExport");
-        Boolean isAll = content.getBooleanValue("isAll");
-        if (isAll) {
-            sa_saleareaidsList = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea  WHERE siteid = '" + siteid + "' AND isused").toArrayList("sa_saleareaid", new ArrayList<>());
-        } else {
-            String sqlStr = "and t5.sa_saleareaid in " + sa_saleareaidsList;
-            sqlStr = sqlStr.replace("[", "(").replace("]", ")");
-            where.append(sqlStr);
-        }
-
-//        if (userInfo.isSaler()) {
-//            HashSet<Long> set = new HashSet<>();
-//            ArrayList<Long> hrids = Proxy.getProxyHrids(this);
-//            for (Long hrid : hrids) {
-//                set.addAll(Hr.getAgents(this, hrid, false));
-//                set.addAll(Hr.getCustomers(this, hrid, false));
-//            }
-//
-//            set.addAll(Hr.getAgents(this, hrid));
-//            set.addAll(Hr.getCustomers(this, hrid));
-//            hrids.add(hrid);
-//            String sql = " and (t1.sys_enterpriseid in " + set + "  )";
-//            sql = sql.replace("[", "(").replace("]", ")");
-//            where.append(sql);
-//        }
-
-
-        SQLFactory sqlFactory = new SQLFactory(this, "营销区域经销商查询", pageSize, pageNumber, pageSorting);
-        if (isExport) {
-            sqlFactory = new SQLFactory(this, "营销区域经销商查询");
-        }
-        sqlFactory.addParameter_in("sa_saleareaid", sa_saleareaidsList);
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter_SQL("where", where);
-        String sql = sqlFactory.getSQL();
-        Rows rows = dbConnect.runSqlQuery(sql);
-
-
-        for (Row row : rows) {
-            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
-            row.put("types", row.getJSONArray("type").toString().replace("[", "").replace("]", "").replace("\"", ""));
-        }
-//        if (isExport) {
-//            //去除不需要导出项
-//            String[] removeFieldList = {"sa_agentsid", "sys_enterpriseid", "createdate", "limitreturnday", "freefreightamount",
-//                    "invoicingpoint", "userid"};
-//            for (String key : removeFieldList) {
-//                rows.getFieldList().remove(key);
-//            }
-//
-//            Rows uploadRows = uploadExcelToObs("经销商档案", "经销商档案", rows, getTitleMap());
-//            return getSucReturnObject().setData(uploadRows).toString();
-//        }
-
-        return getSucReturnObject().setData(rows).toString();
-    }
-
-    //返回导出的标题
-    public HashMap<String, String> getTitleMap() {
-        //
-        HashMap<String, String> titleMap = new HashMap<>();
-        titleMap.put("agentnum", "经销商编号");
-        titleMap.put("erpagentnum", "ERP经销商编号");
-        titleMap.put("isservice", "是否服务经销商");
-        titleMap.put("accountno", "登录账号");
-        titleMap.put("enterprisename", "经销商名称");
-        titleMap.put("province", "省");
-        titleMap.put("city", "市");
-        titleMap.put("county", "县");
-        titleMap.put("address", "地址");
-        titleMap.put("contact", "经销商联系人");
-        titleMap.put("phonenumber", "联系人手机号码");
-        titleMap.put("status", "状态");
-
-
-        return titleMap;
-    }
-
 
     @API(title = "查询所有业务员", apiversion = R.ID20221122153902.v1.class)
     public String getSalers() throws YosException {

+ 153 - 0
src/custom/restcontroller/webmanage/sale/salearea/salearea2.java

@@ -0,0 +1,153 @@
+package restcontroller.webmanage.sale.salearea;
+
+import beans.salearea.SaleArea;
+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.data.*;
+import org.apache.commons.lang.StringUtils;
+import org.sqlite.core.DB;
+import restcontroller.R;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class salearea2 extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public salearea2(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "营销区域查询经销商", apiversion = R.ID20221011144903.v1.class)
+    public String query_agent() throws YosException, IOException {
+        /*
+          过滤条件设置
+         */
+        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.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.erpagentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
+                where.append(" and(");
+                where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
+                where.append(" and(");
+                where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
+                where.append(" and ");
+                where.append("t1.status = '").append(whereObject.getString("status")).append("' ");
+            }
+            if (whereObject.containsKey("cooperatetype") && !"".equals(whereObject.getString("cooperatetype"))) {
+                where.append(" and ");
+                where.append("t1.cooperatetype = '").append(whereObject.getString("cooperatetype")).append("' ");
+            }
+        }
+        boolean isdeleted = content.getBooleanValue("isdeleted");
+        if (isdeleted) {
+            where.append(" and t1.status ='作废' ");
+        } else {
+            where.append(" and t1.status !='作废' ");
+        }
+        JSONArray sa_saleareaidsArray = content.getJSONArray("sa_saleareaids");
+        ArrayList<Long> sa_saleareaidsList = new ArrayList<>();
+        for (Object o : sa_saleareaidsArray) {
+            String sa_saleareaid = o.toString();
+            sa_saleareaidsList.add(Long.parseLong(sa_saleareaid));
+            sa_saleareaidsList.addAll(SaleArea.getSubSaleAreaIds(this, Long.parseLong(sa_saleareaid)));
+        }
+        boolean isExport = content.getBooleanValue("isExport");
+
+        if (userInfo.isSaler()) {
+            ArrayList<Long> saleAreaids = SaleArea.getSubSaleAreaIds(this, userInfo.getHrSaleAreaIds(hrid));
+            saleAreaids.addAll(userInfo.getHrSaleAreaIds(hrid));
+            saleAreaids.add(-1L);
+            if (sa_saleareaidsList.size() > 0) {
+                String sqlStr = " and t1.sys_enterpriseid in (SELECT DISTINCT sys_enterpriseid from sys_enterprise_tradefield WHERE sa_saleareaid in " + saleAreaids + " )";
+                sqlStr = sqlStr.replace("[", "(").replace("]", ")");
+                where.append(sqlStr);
+            }
+        }
+        if (sa_saleareaidsList.size() > 0) {
+            String sqlStr = " and t1.sys_enterpriseid in (SELECT DISTINCT sys_enterpriseid from sys_enterprise_tradefield WHERE sa_saleareaid in " + sa_saleareaidsList + " )";
+            sqlStr = sqlStr.replace("[", "(").replace("]", ")");
+            where.append(sqlStr);
+        }
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents",
+                        "sa_agentsid", "sys_enterpriseid", "gmname", "gmphonenumber", "agentnum", "cooperatetype", "remarks", "status", "createdate").
+                setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "province", "city", "county", "address");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t3", "t1.sys_enterpriseid = t3.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t3.siteid",
+                "erpagentnum");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where);
+
+        if (!isExport) {
+            querySQL.setPage(pageSize, pageNumber);
+        }
+        querySQL.setOrderBy("t1.createdate desc");
+        System.err.println(querySQL.getSQL());
+        Rows rows = querySQL.query();
+
+        RowsMap areaRowsMap = getAreaRowsMap(rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        RowsMap salerRowsMap = getSalerNameRowsMap(rows.toArrayList("sa_agentsid", new ArrayList<>()));
+        for (Row row : rows) {
+            row.put("p_c_c", row.getString("province") + "-" + row.getString("city") + "-" + row.getString("county"));
+            Rows areaRows = areaRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("areanames", StringUtils.join(areaRows.toArrayList("areaname"), ","));
+            Rows salerRows = salerRowsMap.getOrDefault(row.getString("sa_agentsid"), new Rows());
+            row.put("salernames", StringUtils.join(salerRows.toArrayList("name"), ","));
+            row.putIfAbsent("scale", "");
+            row.putIfAbsent("mainproducts", "");
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    public RowsMap getAreaRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
+        if (sa_agentsids.size() == 0) {
+            return new RowsMap();
+        }
+
+        String sql = "SELECT DISTINCT t2.areaname,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
+                "INNER JOIN sa_salearea t2 ON t2.sa_saleareaid=t1.sa_saleareaid " +
+                "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
+        sql = sql.replace("[", "(").replace("]", ")");
+
+        return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
+    }
+
+    public RowsMap getSalerNameRowsMap(ArrayList<Long> sa_agentsids) throws YosException {
+        if (sa_agentsids.size() == 0) {
+            return new RowsMap();
+        }
+        String sql = "SELECT DISTINCT t2.name,t1.sa_agentsid from sys_enterprise_tradefield t1 " +
+                "INNER JOIN sys_hr t2 ON t2.hrid=t1.hrid " +
+                "WHERE t1.siteid='YOSTEST1' and t1.sa_agentsid in " + sa_agentsids;
+        sql = sql.replace("[", "(").replace("]", ")");
+
+        return dbConnect.runSqlQuery(sql).toRowsMap("sa_agentsid");
+    }
+
+}