Explorar o código

发货单经销商合作企业查询优化

hu %!s(int64=2) %!d(string=hai) anos
pai
achega
8db3b0598a

+ 7 - 17
src/custom/restcontroller/webmanage/sale/dispatch/SQL/经销商合作企业查询.sql

@@ -6,20 +6,10 @@ select t1.sys_enterpriseid,
        t3.city,
        t3.phonenumber,
        t3.county,
-       t4.agentnum
-from sa_order t1
-         inner join sys_enterprise t3
-                    on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
-         inner join sa_agents t4 on t3.siteid = t4.siteid and t3.sys_enterpriseid = t4.sys_enterpriseid
-where t1.siteid = $siteid$
-  and $where$
-  and exists(select 1 from  sa_orderitems where sa_orderid=t1.sa_orderid and undeliqty>0 )
-group by t1.sys_enterpriseid,
-         t3.enterprisename,
-         t3.contact,
-         t3.address,
-         t3.province,
-         t3.city,
-         t3.county,
-         t3.phonenumber,
-         t4.agentnum
+       t4.agentnum from (
+select distinct t2.sys_enterpriseid,t1.siteid from sa_orderitems t1
+inner join sa_order t2 on t1.siteid=t2.siteid and t1.sa_orderid=t2.sa_orderid
+where t1.siteid=$siteid$  and t2.status in ('审核','提交') and undeliqty>0
+)t1
+inner join sys_enterprise t3 on t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid
+inner join sa_agents t4 on t3.siteid = t4.siteid and t3.sys_enterpriseid = t4.sys_enterpriseid where $where$

+ 26 - 22
src/custom/restcontroller/webmanage/sale/dispatch/dispatch.java

@@ -303,28 +303,32 @@ public class dispatch extends Controller {
             }
         }
 
-        //SQLFactory sqlFactory = new SQLFactory(this, "经销商合作企业查询", pageSize, pageNumber, pageSorting);
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_order","sys_enterpriseid");
-        querySQL.setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.sys_enterpriseid = t1.sys_enterpriseid and t3.siteid = t1.siteid",
-                "enterprisename", "contact","address","province","city","phonenumber","county");
-        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t4", "t3.siteid = t4.siteid and t3.sys_enterpriseid = t4.sys_enterpriseid",
-                "agentnum");
-        querySQL.setWhere("t1.siteid", siteid);
-        querySQL.setWhere(where.toString());
-        querySQL.setWhere(" exists(select 1 from  sa_orderitems where sa_orderid=t1.sa_orderid and undeliqty>0 )");
-        querySQL.addGroupBy(" t1.sys_enterpriseid,\n" +
-                "         t3.enterprisename,\n" +
-                "         t3.contact,\n" +
-                "         t3.address,\n" +
-                "         t3.province,\n" +
-                "         t3.city,\n" +
-                "         t3.county,\n" +
-                "         t3.phonenumber,\n" +
-                "         t4.agentnum");
-        querySQL.setOrderBy(pageSorting);
-        querySQL.setPage(pageSize, pageNumber);
-        Rows rows = querySQL.query();
+        SQLFactory sqlFactory = new SQLFactory(this, "经销商合作企业查询", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+//        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "select distinct t2.sys_enterpriseid,t1.siteid from sa_orderitems t1\n" +
+//                "inner join sa_order t2 on t1.siteid=t2.siteid and t1.sa_orderid=t2.sa_orderid\n" +
+//                "where t1.siteid=$siteid$  and t2.status in ('审核','提交') and undeliqty>0","sys_enterpriseid");
+//        querySQL.setTableAlias("t1");
+//        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.sys_enterpriseid = t1.sys_enterpriseid and t3.siteid = t1.siteid",
+//                "enterprisename", "contact","address","province","city","phonenumber","county");
+//        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t4", "t3.siteid = t4.siteid and t3.sys_enterpriseid = t4.sys_enterpriseid",
+//                "agentnum");
+//        querySQL.setWhere("t1.siteid", siteid);
+//        querySQL.setWhere(where.toString());
+//        querySQL.setWhere(" exists(select 1 from  sa_orderitems where sa_orderid=t1.sa_orderid and undeliqty>0 )");
+//        querySQL.addGroupBy(" t1.sys_enterpriseid,\n" +
+//                "         t3.enterprisename,\n" +
+//                "         t3.contact,\n" +
+//                "         t3.address,\n" +
+//                "         t3.province,\n" +
+//                "         t3.city,\n" +
+//                "         t3.county,\n" +
+//                "         t3.phonenumber,\n" +
+//                "         t4.agentnum");
+//        querySQL.setOrderBy(pageSorting);
+//        querySQL.setPage(pageSize, pageNumber);
 
         return getSucReturnObject().setData(rows).toString();
     }