소스 검색

经销商列表支持QuerySQL

eganwu 2 년 전
부모
커밋
b4adda4cd1

+ 2 - 4
src/custom/restcontroller/webmanage/sale/agents/agents.java

@@ -12,10 +12,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
 import common.YosException;
-import common.annotation.API;
-import common.annotation.CACHEING;
-import common.annotation.CACHEING_CLEAN;
-import common.annotation.cm;
+import common.annotation.*;
 import common.data.*;
 import org.apache.commons.lang.StringUtils;
 import org.apache.poi.ss.usermodel.CellStyle;
@@ -67,6 +64,7 @@ public class agents extends Controller {
 
     @API(title = "经销商详情查询")
     @CACHEING
+    @QUERYBYROWINDEX(uniquecolumnname = "sa_agentsid",listapiversion = {R.ID20221011144903.v1.class})
     public String query_agentMain() throws YosException {
         long sa_agentsid = content.getLongValue("sa_agentsid");
         SQLFactory sqlFactory = new SQLFactory(this, "经销商详情查询");

+ 6 - 0
src/custom/restcontroller/webmanage/sale/salearea/SQL/查询经销商主账号信息.sql

@@ -0,0 +1,6 @@
+SELECT t1.sys_enterpriseid, t1.userid, t2.accountno
+from sys_enterprise_hr t1
+         INNER JOIN sys_users t2 ON t2.userid = t1.userid
+WHERE t1.isleader = 1
+  and t1.siteid = $siteid$
+  and t1.sys_enterpriseid in $sys_enterpriseid$

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

@@ -1,37 +1,25 @@
-select t1.*
-from (select distinct t1.sa_agentsid,
-                      t1.sys_enterpriseid,
-                      t1.agentnum,
-                      t1.createdate,
-                      t2.enterprisename,
-                      t2.phonenumber,
-                      t2.contact,
-                      t2.province,
-                      t2.city,
-                      t2.county,
-                      t2.address,
-                      t1.status,
-                      t1.isservice,
-                      t2.limitreturnday,
-                      t2.freefreightamount,
-                      t2.invoicingpoint,
-                      t3.userid,
-                      t6.accountno,
-                      t4.erpagentnum
-      from sa_agents t1
-               inner join sys_enterprise t2 on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
-               left JOIN (SELECT siteid, sys_enterpriseid, max(userid) userid
-                          from sys_enterprise_hr
-                          WHERE isleader = 1
-                            and siteid = $siteid$
-                          GROUP BY siteid, sys_enterpriseid) t3
-                         ON t3.sys_enterpriseid = t2.sys_enterpriseid and t3.siteid = t2.siteid
-               left join sys_users t6 on t6.userid = t3.userid
-               LEFT JOIN sys_dataextend t4
-                         ON t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid
-               LEFT JOIN sys_enterprise_tradefield t5
-                         on t5.sys_enterpriseid = t1.sys_enterpriseid and t5.siteid = t1.siteid
-      where t1.siteid = $siteid$
-        and $where$
-     ) t1
+select t1.sa_agentsid,
+       t1.sys_enterpriseid,
+       t1.agentnum,
+       t1.createdate,
+       t2.enterprisename,
+       t2.phonenumber,
+       t2.contact,
+       t2.province,
+       t2.city,
+       t2.county,
+       t2.address,
+       t1.status,
+       t1.isservice,
+       t2.limitreturnday,
+       t2.freefreightamount,
+       t2.invoicingpoint,
+       t4.erpagentnum
+from sa_agents t1
+         inner join sys_enterprise t2 on t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid
+         LEFT JOIN sys_dataextend t4
+                   ON t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid
+where t1.siteid = $siteid$
+  and $where$
+
 

+ 47 - 17
src/custom/restcontroller/webmanage/sale/salearea/salearea.java

@@ -10,10 +10,7 @@ import common.annotation.API;
 import common.annotation.CACHEING;
 import common.annotation.CACHEING_CLEAN;
 import common.annotation.cm;
-import common.data.Row;
-import common.data.Rows;
-import common.data.RowsMap;
-import common.data.SQLFactory;
+import common.data.*;
 import restcontroller.R;
 
 import java.io.IOException;
@@ -354,25 +351,45 @@ public class salearea extends Controller {
         }
         boolean isExport = content.getBooleanValue("isExport");
         Boolean isAll = content.getBooleanValue("isAll");
-        if (sa_saleareaidsList.isEmpty()) isAll = true;
-        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;
+        if (sa_saleareaidsList.isEmpty()) {
+            isAll = true;
+        }
+        if (!isAll) {
+            String sqlStr = "and t1.sys_enterpriseid in (SELECT sys_enterpriseid from sys_enterprise_tradefield WHERE sa_saleareaid in " + sa_saleareaidsList + ")";
             sqlStr = sqlStr.replace("[", "(").replace("]", ")");
             where.append(sqlStr);
         }
 
 
-        SQLFactory sqlFactory = new SQLFactory(this, "营销区域经销商查询", pageSize, pageNumber, pageSorting);
-        if (isExport) {
-            sqlFactory = new SQLFactory(this, "营销区域经销商查询");
-        }
-        sqlFactory.addParameter_in("sa_saleareaid", sa_saleareaidsList);
+//        SQLFactory sqlFactory = new SQLFactory(this, "营销区域经销商查询", pageSize, pageNumber, pageSorting);
+//        if (isExport) {
+//            sqlFactory = new SQLFactory(this, "营销区域经销商查询");
+//        }
+//        sqlFactory.addParameter("siteid", siteid);
+//        sqlFactory.addParameter_SQL("where", where);
+//        String sql = sqlFactory.getSQL();
+//        Rows rows = dbConnect.runSqlQuery(sql);
+        QuerySQL querySQL = getAgentList(where.toString());
+        querySQL.setOrderBy(pageSorting);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+        ArrayList<Long> ids = rows.toArrayList("sys_enterpriseid", new ArrayList<>());
+
+        SQLFactory sqlFactory = new SQLFactory(this, "查询经销商主账号信息");
         sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter_SQL("where", where);
-        String sql = sqlFactory.getSQL();
-        Rows rows = dbConnect.runSqlQuery(sql);
+        sqlFactory.addParameter_in("sys_enterpriseid", ids);
+        RowsMap rowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sys_enterpriseid");
+        for (Row row : rows) {
+            Rows tempRows = rowsMap.getOrDefault(row.getString("sys_enterpriseid"), new Rows());
+            if (tempRows.isNotEmpty()) {
+                row.put("userid", tempRows.get(0).getLong("userid"));
+                row.put("accountno", tempRows.get(0).getLong("accountno"));
+            } else {
+                row.put("userid", 0);
+                row.put("accountno", "");
+            }
+        }
+
 
         if (isExport) {
             //去除不需要导出项
@@ -389,6 +406,19 @@ public class salearea extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+
+    public QuerySQL getAgentList(String where) throws YosException {
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
+                "enterprisename", "phonenumber", "contact", "province", "city", "county", "address", "limitreturnday", "freefreightamount", "invoicingpoint");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_dataextend", "t4", "t1.sys_enterpriseid = t4.ownerid and ownertable = 'sys_enterprise' and t1.siteid = t4.siteid",
+                "erpagentnum");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere(where);
+        return querySQL;
+    }
+
     //返回导出的标题
     public HashMap<String, String> getTitleMap() {
         //