Browse Source

供应商资源企业列表接口修改

dongbw 7 years ago
parent
commit
cb0b778bad

+ 4 - 10
src/main/java/com/uas/platform/b2b/erp/controller/VendorRecommendController.java

@@ -15,7 +15,7 @@ import java.util.List;
 
 
 /**
 /**
  * 供应商推荐
  * 供应商推荐
- * Created by dongbw
+ * @author  dongbw
  * 18/01/18 14:00.
  * 18/01/18 14:00.
  */
  */
 @RestController
 @RestController
@@ -38,9 +38,7 @@ public class VendorRecommendController {
      */
      */
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     public Page<VendorRecommend> getVendorRecommend (Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
     public Page<VendorRecommend> getVendorRecommend (Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
-        Page<VendorRecommend> vendorRecommendPage = vendorService.getVendorRecommend(enUU, productMatchCondition, enterpriseMatchCondition, page, size);
-//        logger.log("供应商推荐","获取当前企业推荐供应商:" + enUU, vendorRecommendPage.getNumberOfElements());
-        return vendorRecommendPage;
+        return vendorService.getVendorRecommend(enUU, productMatchCondition, enterpriseMatchCondition, page, size);
     }
     }
 
 
     /**
     /**
@@ -52,9 +50,7 @@ public class VendorRecommendController {
      */
      */
     @RequestMapping(value = "/product/associate", method = RequestMethod.GET)
     @RequestMapping(value = "/product/associate", method = RequestMethod.GET)
     public List<Product> getProductAssociate (String field, String condition) {
     public List<Product> getProductAssociate (String field, String condition) {
-        List<Product> products = vendorService.getProductAssociate(field, condition);
-//        logger.log("供应商推荐","根据条件获取物料型号和品牌值对", products.size());
-        return products;
+        return vendorService.getProductAssociate(field, condition);
     }
     }
 
 
     /**
     /**
@@ -69,8 +65,6 @@ public class VendorRecommendController {
      */
      */
     @RequestMapping(value = "/detail", method = RequestMethod.GET)
     @RequestMapping(value = "/detail", method = RequestMethod.GET)
     public Page<Product> getVendorRecommendDetail(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
     public Page<Product> getVendorRecommendDetail(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
-        Page<Product> productPage = vendorService.getProductsByVendorRecommend(page, size, enUU, vendUU, productMatchCondition, whereCondition);
-//        logger.log("供应商推荐","获取当前企业推荐供应商:" + enUU, productPage.getNumberOfElements());
-        return productPage;
+        return vendorService.getProductsByVendorRecommend(page, size, enUU, vendUU, productMatchCondition, whereCondition);
     }
     }
 }
 }

+ 30 - 22
src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

@@ -317,38 +317,47 @@ public class VendorsServiceImpl implements VendorService {
 	@Override
 	@Override
 	public com.uas.sso.support.Page<VendorRecommend> getVendorRecommend(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
 	public com.uas.sso.support.Page<VendorRecommend> getVendorRecommend(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
 		long start = System.currentTimeMillis();
 		long start = System.currentTimeMillis();
-//		final Long enUU = SystemSession.getUser().getEnterprise().getUu();
         if (null == enUU) {
         if (null == enUU) {
             // 设置不存在的企业
             // 设置不存在的企业
             enUU = 0L;
             enUU = 0L;
         }
         }
-        if (StringUtils.isEmpty(productMatchCondition) || productMatchCondition.contains("1=1")) {
-			productMatchCondition = " 1=1 ";
-		} else {
-        	productMatchCondition = productMatchCondition + " and pr_issale = 1";
-		}
 		if (StringUtils.isEmpty(enterpriseMatchCondition)) {
 		if (StringUtils.isEmpty(enterpriseMatchCondition)) {
 			enterpriseMatchCondition = " 1=1 ";
 			enterpriseMatchCondition = " 1=1 ";
 		}
 		}
-		// 查询所有的企业信息
-		StringBuffer enterpriseSql = new StringBuffer();
-		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 left join products on en_uu = pr_enuu where ").append(productMatchCondition).append(" and en_uu <> ")
-				.append(enUU).append(" and en_name not like '%测试%' and lower(en_name) not like '%test%' and ").append(enterpriseMatchCondition).append(" group by en_uu order by count(1) desc" +
-				" ) a on en.en_uu = a.en_uu order by counts desc");
-		// rownum 控制
+        // 企业表过滤
+        String enterpriseFilterSql = "(select en_uu from sec$enterprises where " + enterpriseMatchCondition + " and  en_uu <> " + enUU + " and en_name not like '%测试%' and en_name not like '%test%') e";
+        // 查询所有的企业信息
+		StringBuilder enterpriseSql = new StringBuilder();
+        String productFilterSql;
+        StringBuilder totalSql = new StringBuilder();
+        // 物料无过滤条件时,直接关联速度更快, 而存在过滤条件时,先过滤在关联速度更快
+		if (StringUtils.isEmpty(productMatchCondition) || productMatchCondition.contains("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 ").append(enterpriseFilterSql)
+                    .append(" left join products on en_uu = pr_enuu group by en_uu order by count(1) desc" +
+                    " ) a on en.en_uu = a.en_uu order by counts desc");
+            // 因为需求更改为所有有销售产品的企业都会被返回,所以total直接取除本企业外其他有销售产品的企业数即可,之前的匹配企业数不再返回
+            totalSql.append(" select count(1) from (select 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 <> ")
+                    .append(enUU).append(" and ").append(productMatchCondition).append(" and ").append(enterpriseMatchCondition).append(" group by en_uu) a");
+        } 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(" 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");
+            totalSql.append(" select count(1) from ( select en_uu from ").append(enterpriseFilterSql).append(" left join ").append(productFilterSql)
+                    .append(" on e.en_uu = p.pr_enuu group by en_uu) a");
+        }
+		// 分页控制
 		String rownumSql = ") s limit " + (page - 1) * size + "," + size;
 		String rownumSql = ") s limit " + (page - 1) * size + "," + size;
 		// 查找非供应商的卖当前商品的企业UU
 		// 查找非供应商的卖当前商品的企业UU
-		StringBuffer vendorRecommendUusSql = new StringBuffer();
-		// and instr(Pr_Title,'测试')<1 and instr(lower(Pr_Title),'test')<1
+		StringBuilder vendorRecommendUusSql = new StringBuilder();
 		vendorRecommendUusSql.append("select s.*, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ").append(enUU)
 		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);
 				.append(") isVendor from (").append(enterpriseSql).append(rownumSql);
-		// 因为需求更改为所有有销售产品的企业都会被返回,所以total直接取除本企业外其他有销售产品的企业数即可,之前的匹配企业数不再返回
-		StringBuffer totalSql = new StringBuffer().append(" select count(1) from (select en_uu from sec$enterprises left join " +
-				" products on en_uu = pr_enuu where en_name not like '%测试%' and lower(en_name) not like '%test%' and en_uu <> ")
-				.append(enUU).append(" and ").append(productMatchCondition).append(" and ").append(enterpriseMatchCondition).append(" group by en_uu) a");
-		Integer total = commonDao.queryForObject(totalSql.toString(), Integer.class);
-		List<VendorRecommend> vendorRecommends = commonDao.query(vendorRecommendUusSql.toString(), VendorRecommend.class);
+        System.out.println("拼接完语句" + (System.currentTimeMillis() - start));
+        Integer total = commonDao.queryForObject(totalSql.toString(), Integer.class);
+        List<VendorRecommend> vendorRecommends = commonDao.query(vendorRecommendUusSql.toString(), VendorRecommend.class);
 		long start1 = System.currentTimeMillis();
 		long start1 = System.currentTimeMillis();
 		for (VendorRecommend vendorRecommend : vendorRecommends) {
 		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= "
 			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= "
@@ -383,7 +392,6 @@ public class VendorsServiceImpl implements VendorService {
 			System.out.println("进入方法:" + System.currentTimeMillis());
 			System.out.println("进入方法:" + System.currentTimeMillis());
 			long start = System.currentTimeMillis();
 			long start = System.currentTimeMillis();
 			// UAS企业UU
 			// UAS企业UU
-//		Long enUU = SystemSession.getUser().getEnterprise().getUu();
 			StringBuffer cmpCodesSql = new StringBuffer();
 			StringBuffer cmpCodesSql = new StringBuffer();
 			cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
 			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%' ");
 					.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%' ");