浏览代码

商品组查询优化

shenjingwei 1 周之前
父节点
当前提交
055af812ab

+ 8 - 19
src/custom/restcontroller/sale/itemgroup/itemgroup.java

@@ -97,7 +97,6 @@ public class itemgroup extends Controller {
         String where = " 1=1 ";
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
-
             if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
                 where = where + " and (t1.groupname like'%" + whereObject.getString("condition")
                         + "%' or t1.groupnum like'%" + whereObject.getString("condition")
@@ -112,10 +111,9 @@ public class itemgroup extends Controller {
                 pageSorting = "t1.groupname like'%" + whereObject.getString("condition") + "%' desc,exists(select 1 from sa_itemgroupmx s1 " +
                         " LEFT JOIN plm_item s2 ON s1.itemid = s2.itemid AND s1.siteid = s2.siteid  where s2.itemname like'%" + whereObject.getString("condition") + "%') desc,exists(select 1 from sa_itemgroupmx s1 " +
                         " LEFT JOIN plm_item s2 ON s1.itemid = s2.itemid AND s1.siteid = s2.siteid  where s2.itemno like'%" + whereObject.getString("condition") + "%') desc,t1.groupnum like'%" + whereObject.getString("condition") + "%' desc";
-
             }
             if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
-                where = where + " and (t1.tradefield like'%" + whereObject.getString("tradefield") + "%') ";
+                where = where + " and (t1.tradefield ='" + whereObject.getString("tradefield") + "') ";
             }
             if (whereObject.containsKey("standards") && !"".equals(whereObject.getString("standards"))) {
                 where = where
@@ -132,21 +130,17 @@ public class itemgroup extends Controller {
             }
         }
 
-
         itemclassList.add(0l);
         itemList.add(0l);
-        String sql;
+        Rows rowsgroupids = null;
         if (saleclassauth) {
-            sql = "select t1.sa_itemgroupid from sa_itemgroup t1 inner join  sa_itemgroupmx t2 on t1.sa_itemgroupid=t2.sa_itemgroupid and t1.siteid=t2.siteid" +
+            String sql = "select distinct t1.sa_itemgroupid from sa_itemgroup t1 inner join  sa_itemgroupmx t2 on t1.sa_itemgroupid=t2.sa_itemgroupid and t1.siteid=t2.siteid" +
                     "  LEFT JOIN sa_itemsaleclass t4 ON t2.itemid = t4.itemid AND t2.siteid = t4.siteid and t4.classtype='营销'" +
                     "  where t1.siteid='" + siteid + "' and (t2.itemid in " + itemList + " or t4.itemclassid in " + itemclassList + ")";
             sql = sql.replace("[", "(").replace("]", ")");
-        } else {
-            sql = "select t1.sa_itemgroupid from sa_itemgroup t1 inner join  sa_itemgroupmx t2 on t1.sa_itemgroupid=t2.sa_itemgroupid and t1.siteid=t2.siteid" +
-                    "  LEFT JOIN sa_itemsaleclass t4 ON t2.itemid = t4.itemid AND t2.siteid = t4.siteid and t4.classtype='营销'" +
-                    "  where t1.siteid='" + siteid + "'";
+            rowsgroupids = dbConnect.runSqlQuery(sql);
         }
-        Rows rowsgroupids = dbConnect.runSqlQuery(sql);
+
 
         //品牌过滤
         JSONArray brandids = content.getJSONArray("brandids");
@@ -172,14 +166,9 @@ public class itemgroup extends Controller {
         itemGroupQuery.setWhere("t2.ismodule", content.getLongValue("ismodule"));
         itemGroupQuery.setWhere("t1.sa_brandid", brandids.toArray());
         itemGroupQuery.setWhere(where);
-//        if (saleclassauth) {
-//            if (itemclassList.isEmpty()) {
-//                itemGroupQuery.setWhere("1=2");
-//            } else {
-//                itemGroupQuery.setWhere("exists(select * from sa_itemgroupmx inner join sa_itemsaleclass on sa_itemgroupmx.itemid=sa_itemsaleclass.itemid where sa_itemgroupmx.sa_itemgroupid=t1.sa_itemgroupid and sa_itemsaleclass.itemclassid in $itemclassid$)");
-//            }
-//        }
-        itemGroupQuery.setWhere("sa_itemgroupid", rowsgroupids.toArrayList("sa_itemgroupid"));
+        if (saleclassauth) {
+            itemGroupQuery.setWhere("sa_itemgroupid", rowsgroupids.toArrayList("sa_itemgroupid"));
+        }
         itemGroupQuery.setPage(pageSize, pageNumber);
         Rows itemGroupRows = itemGroupQuery.query();
 

+ 2 - 13
src/custom/restcontroller/webmanage/sale/workorder/workorder.java

@@ -1083,13 +1083,7 @@ public class workorder extends Controller {
 
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
-                where.append(" and(");
-                where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t1.sku like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append(")");
-            }
+
             if (whereObject.containsKey("phonenumber") && !"".equals(whereObject.getString("phonenumber"))) {
                 where.append(" and(");
                 where.append("t6.phonenumber ='").append(whereObject.getString("phonenumber")).append("' ");
@@ -1106,12 +1100,6 @@ public class workorder extends Controller {
                 where.append(")");
             }
         }
-//		String hrid = content.getString("hrid");
-//        SQLFactory sqlFactory = new SQLFactory(this, "审核订单列表查询", pageSize, pageNumber, pageSorting);
-//        sqlFactory.addParameter_SQL("where", where);
-//        sqlFactory.addParameter("siteid", siteid);
-//        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-//        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_itemsku", "sku");
         querySQL.setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid=t2.itemid and t1.siteid=t2.siteid","itemid","itemno","itemname","model","spec");
@@ -1123,6 +1111,7 @@ public class workorder extends Controller {
         querySQL.addQueryFields("customername","t7.name");
         querySQL.addQueryFields("customerphonenumber","t7.phonenumber");
         querySQL.setSiteid(siteid);
+        querySQL.setCondition("t2.itemname","t2.itemno","t1.sku");
         querySQL.setWhere(where.toString());
         querySQL.setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();