Browse Source

供应商物料列表接口修改,提速

dongbw 7 years ago
parent
commit
824944e7f6
1 changed files with 16 additions and 56 deletions
  1. 16 56
      src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

+ 16 - 56
src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

@@ -316,7 +316,6 @@ public class VendorsServiceImpl implements VendorService {
 	 */
 	@Override
 	public com.uas.sso.support.Page<VendorRecommend> getVendorRecommend(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
-		long start = System.currentTimeMillis();
         if (null == enUU) {
             // 设置不存在的企业
             enUU = 0L;
@@ -333,14 +332,14 @@ public class VendorsServiceImpl implements VendorService {
 		if (StringUtils.isEmpty(productMatchCondition) || productMatchCondition.contains("1=1")) {
 			productMatchCondition = " 1=1 ";
             enterpriseSql.append("select en.en_uu, en.en_name, en.en_shortname, en.en_address, en.en_tel, en.en_email, en.en_corporation, en.en_businesscode, en.en_profession, en.en_tags, en.en_contactman," +
-                    " en.en_contacttel from sec$enterprises en right join ( select en_uu, count(1) as counts from sec$enterprises  inner join products on en_uu = pr_enuu where en_uu <> "
-					+ enUU + " and en_name not like '%测试%' and en_name not like '%test%' group by en_uu order by count(1) desc" +
+                    " en.en_contacttel from sec$enterprises en right join ( select en_uu, count(1) as counts from sec$enterprises  left join products on en_uu = pr_enuu where en_uu <> "
+			).append(enUU).append(" and en_name not like '%测试%' and en_name not like '%test%' group by en_uu order by count(1) desc" +
                     " ) a on en.en_uu = a.en_uu order by counts desc");
         } else {
             // 物料过滤
             productFilterSql = "(select pr_enuu from products where " + productMatchCondition + ") p";
             enterpriseSql.append("select en.en_uu, en.en_name, en.en_shortname, en.en_address, en.en_tel, en.en_email, en.en_corporation, en.en_businesscode, en.en_profession, en.en_tags, en.en_contactman," +
-                    " en.en_contacttel from sec$enterprises en right join ( select en_uu, count(1) as counts from ").append(enterpriseFilterSql).append(" inner join ").append(productFilterSql)
+                    " en.en_contacttel from sec$enterprises en right join ( select en_uu, count(1) as counts from ").append(enterpriseFilterSql).append(" left join ").append(productFilterSql)
                     .append(" on e.en_uu = p.pr_enuu group by en_uu order by count(1) desc) a on en.en_uu = a.en_uu order by counts desc");
         }
 		// 分页控制
@@ -349,22 +348,18 @@ public class VendorsServiceImpl implements VendorService {
 		StringBuilder vendorRecommendUusSql = new StringBuilder();
 		vendorRecommendUusSql.append("select s.*, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ").append(enUU)
 				.append(") isVendor from (").append(enterpriseSql).append(rownumSql);
-        System.out.println("拼接完语句" + (System.currentTimeMillis() - start));
-		String totalSql = " select count(1) from (select distinct(en_uu) from sec$enterprises inner join " +
+		String totalSql = " select count(1) from (select distinct(en_uu) from sec$enterprises left join " +
 				" products on en_uu = pr_enuu where en_name not like '%测试%' and en_name not like '%test%' and en_uu <> " +
 				enUU + " and " + productMatchCondition + " and " + enterpriseMatchCondition + ") a";
 		Integer total = commonDao.queryForObject(totalSql, Integer.class);
         List<VendorRecommend> vendorRecommends = commonDao.query(vendorRecommendUusSql.toString(), VendorRecommend.class);
-		long start1 = System.currentTimeMillis();
 		for (VendorRecommend vendorRecommend : vendorRecommends) {
 			String prodSql = "select group_concat(pr_title , (case when pr_brand is not null then concat('(', pr_brand, ')') else ' ' end)) from (select pr_title, pr_brand from v$products where pr_enuu= "
-					+ vendorRecommend.getEn_uu() + " and pr_issale = 1 and pr_b2bdisabled <> 1 limit 0,5) p";
+					+ vendorRecommend.getEn_uu() + " and " + productMatchCondition + " and pr_b2bdisabled <> 1 limit 0,5) p";
 			String prodInfo = commonDao.queryForObject(prodSql, String.class);
 			vendorRecommend.setProductInfo(prodInfo);
 		}
-		System.out.println("循环完成" + (System.currentTimeMillis() - start1));
-		System.out.println("查找完企业UU" + (System.currentTimeMillis() - start));
-		return new com.uas.sso.support.Page<VendorRecommend>(page, size, vendorRecommends, total);
+		return new com.uas.sso.support.Page<>(page, size, vendorRecommends, total);
 	}
 
 
@@ -386,57 +381,22 @@ public class VendorsServiceImpl implements VendorService {
 		}
 		List<Product> products = new ArrayList<>();
 		if (null != enUU) {
-			System.out.println("进入方法:" + System.currentTimeMillis());
-			long start = System.currentTimeMillis();
-			// UAS企业UU
-			StringBuffer cmpCodesSql = new StringBuffer();
-			cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
-					.append(enUU).append(" and ifnull(pr_issale,0) <> 1 and pr_ispurchase = 1 and pr_b2bdisabled <> 1 and Pr_Title not like '%测试%' and Pr_Title not like '%test%' and Pr_code not like '%测试%' and Pr_code not like '%test%' ");
-			// 查找匹配在售物料的语句
-			StringBuffer productsMatchSql = new StringBuffer();
-			productsMatchSql.append("select pr_id from (select pr_id from v$products p1 where exists (").append(cmpCodesSql).append(") and p1.pr_enuu = ").append(vendUU)
-					.append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and p1.Pr_Title not like '%测试%' and p1.Pr_Title not like '%test%' and p1.Pr_code not like '%测试%' and p1.Pr_code not like '%test%' and ")
-					.append(whereCondition).append(" order by pr_standard desc, pr_id desc) a");
-			// 查找不匹配但是在售物料的语句  union all 方便排序
-			StringBuffer notMatchProductsSql = new StringBuffer();
-			notMatchProductsSql.append("select pr_id from (select pr_id from v$products p1 where not exists (").append(cmpCodesSql).append(") and p1.pr_enuu = ").append(vendUU)
-					.append(" and p1.pr_issale = 1 and p1.pr_b2bdisabled <> 1 and p1.Pr_Title not like '%测试%' and p1.Pr_Title not like '%test%' and p1.Pr_code not like '%测试%' and p1.Pr_code not like '%test%' and ")
-					.append(whereCondition).append(" order by pr_standard desc, pr_id desc)");
-			// 物料id
-			StringBuffer idSql = new StringBuffer();
-			// rownum 控制
-			String rownumSql = " ) t limit " + (page - 1) * size + "," + size;
-			idSql.append("select pr_id from (").append(productsMatchSql).append(" union all ").append(notMatchProductsSql)
-					.append(" b").append(rownumSql);
-			List<Long> matchedIds = commonDao.queryForList(productsMatchSql.toString(), Long.class);
-			List<Long> ids = commonDao.queryForList(idSql.toString(), Long.class);
-//			System.out.println("id:" + idSql);
-			for (Long id : ids) {
-				Product product = productDao.findOne(id);
-				if (matchedIds.contains(id)) {
-					StringBuffer matchCodeSql = new StringBuffer();
-					matchCodeSql.append("select group_concat(pr_code) from (select pr_code from v$products where pr_b2bdisabled <> 1 and pr_enuu = ")
-							.append(enUU).append(" and pr_cmpcode = '").append(product.getCmpCode()).append("'").append(" limit 0,5) p");
-					String matchCodes = commonDao.queryForObject(matchCodeSql.toString(), String.class);
-					product.setIfMatched(matchCodes);
-				}
-				products.add(product);
-			}
-			System.out.println("返回数据:" + (System.currentTimeMillis() - start));
+			String prodSql = "select t.*, (select pr_code from v$products where pr_b2bdisabled = 0 and pr_enuu = "
+					+ enUU + " and pr_cmpcode = t.cmpCode limit 1) as ifMatched  from (select pr_id id, pr_code code, pr_title title, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind,pr_minpack minPack, "
+					+ " pr_minOrder minOrder, pr_brand brand, pr_standard standard, pr_issale isSale, pr_ispurchase isPurchase from v$products p1 where p1.pr_enuu = "
+					+ vendUU + " and p1.pr_b2bdisabled = 0 and " + whereCondition + " order by pr_issale desc, pr_standard desc, pr_id desc ) t limit "
+					+ (page - 1) * size + "," + size;
+			products = commonDao.query(prodSql, Product.class);
 		} else {
-			String prodSql = "select a.* from (select t.*,rownum as r1 from (select pr_id id, pr_code code, pr_title title, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind, "
+			String prodSql = "select t.* from (select pr_id id, pr_code code, pr_title title, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind, "
 					+ "pr_minpack minPack, pr_minOrder minOrder, pr_brand brand, pr_standard standard, pr_issale isSale, pr_ispurchase isPurchase from v$products where pr_enuu = "
-					+ vendUU + " and pr_issale = 1 and pr_b2bdisabled <> 1 and Pr_Title not like '%测试%' and lower(Pr_Title) not like '%test%' and Pr_code not like '%测试%' and lower(Pr_code) not like '%test%' and "
-					+ whereCondition + " order by pr_issale desc, pr_standard desc, pr_id desc) t where rownum <= " + page * size + ") a where r1 > " + (page - 1) * size;
-			System.out.println("无UU:" + prodSql);
+					+ vendUU + " and pr_b2bdisabled = 0 and " + whereCondition + " order by pr_issale desc, pr_standard desc, pr_id desc) t limit "
+					+ (page - 1) * size + "," + size;
 			products = commonDao.query(prodSql, Product.class);
 
 		}
-		String countSql = "select count(1) from v$products where pr_enuu = " + vendUU
-				+ " and pr_issale = 1 and pr_b2bdisabled <> 1 and Pr_Title not like '%测试%' and lower(Pr_Title) not like '%test%' and Pr_code not like '%测试%' and lower(Pr_code) not like '%test%' and "
-				+ whereCondition;
+		String countSql = "select count(1) from v$products where pr_enuu = " + vendUU + " and pr_b2bdisabled = 0 and " + whereCondition;
 		Integer count = commonDao.queryForObject(countSql, Integer.class);
-//		System.out.println("count:" + countSql);
 		return new com.uas.sso.support.Page<>(page, size, products, count);
 	}