Browse Source

供应商列表获取修改

dongbw 7 years ago
parent
commit
cf77954600

+ 19 - 11
src/main/java/com/uas/platform/b2c/trade/vendor/service/impl/VendorIntroductionServiceImpl.java

@@ -22,6 +22,7 @@ import java.util.List;
 
 /**
  * The type VendorIntroductionService.
+ * @author dongbw
  * @version  2018年4月26日 17:25:03
  */
 @Service
@@ -99,12 +100,16 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
             enUU = SystemSession.getUser().getEnterprise().getUu();
         }
 		// 查询所有企业个数
-		Integer total = getTotalCount(enUU, enterpriseCondition, productCondition);
+		Integer total;
 		// 查询企业
 		List<VendorIntroduction> vendorIntroductions;
 		if (!StringUtils.isEmpty(productCondition)) {
+			enterpriseCondition = "(en_name like '%" + keyword + "%' or en_address like '%" + keyword + "%' or en_industry like '% "
+					+ keyword + "%')";
+			total = getTotalCount(enUU, enterpriseCondition, productCondition);
 			vendorIntroductions = getEnterpriseWithProductCondition(enUU, enterpriseCondition, productCondition,  page, size);
 		} else {
+			total = getTotalCount(enUU, enterpriseCondition, productCondition);
 			vendorIntroductions = getEnterpriseWithoutProductCondition(enUU, enterpriseCondition,  page, size);
 		}
 		return new Page<VendorIntroduction>(page, size, vendorIntroductions, total);
@@ -181,12 +186,14 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
 	private List<VendorIntroduction> getEnterpriseWithProductCondition(Long enUU, String enterpriseCondition, String productCondition, int page, int size) {
 		StringBuilder enterpriseSql = new StringBuilder();
 		// 查询所有符合条件的enUU的语句,按待售物料数量排序
-		String enUUSql = getEnUUGroupByEnUUOrderByCount(enUU, enterpriseCondition, productCondition);
+		String enUUSql = getEnUUGroupByEnUUOrderByCount(enUU, " 1 = 1 ", productCondition);
+		String noProductenUUSql = getEnUUGroupByEnUUOrderByCount(enUU, enterpriseCondition, null);
 		// 获取企业sql
 		enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, st.st_logo_url storeLogoUrl, en.en_logurl enLogoUrl, en.en_address enAddress, en.en_tel enTel, " +
 				" en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_industry enIndustry, en.en_Businessscope enBusinessScope " +
-				",st.st_uuid,st.st_status from sec$enterprises en left join store$info st on st.st_enuu = en.en_uu right join (").append(enUUSql)
-				.append(" ) a on en.en_uu = a.en_uu order by en.en_weight desc, counts desc");
+				",st.st_uuid,st.st_status from sec$enterprises en left join store$info st on st.st_enuu = en.en_uu right join (")
+				.append(enUUSql).append(" union ").append(noProductenUUSql)
+				.append(" ) a on en.en_uu = a.en_uu order by en.en_weight desc");
 		// 查找非供应商的卖当前商品的企业UU
 		StringBuilder vendorIntroductionUusSql = new StringBuilder();
 		// 行数 控制
@@ -230,15 +237,17 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
 	 */
 	private Integer getTotalCount(Long enUU, String enterpriseCondition, String productCondition) {
 		StringBuilder enCountSql = new StringBuilder();
-		enCountSql.append("select count(1) from (select en_uu,count(1) from (select en_uu from sec$enterprises where en_name not like '%测试%' " +
+		enCountSql.append("select count(1) from (select distinct(en_uu) from (select en_uu from sec$enterprises where en_name not like '%测试%' " +
 				" and en_name not like '%test%' and (length(en_businesscode) > 12 or en_name like '%香港%' or en_name like '%HONG KONG%' " +
 				" or en_area like '%香港%')and (en_name not REGEXP '^[0-9]*$' and (en_name like '%ltd%' or en_name like '%limited%' or " +
-				" en_name like '%tcl%' or en_name not regexp '[\\u4e00-\\u9fa5_a-zA-Z0-9]') and ").append(enterpriseCondition).append(") and en_uu <> ")
+				" en_name like '%tcl%' or en_name not regexp '[\\u4e00-\\u9fa5_a-zA-Z0-9]') ) and en_uu <> ")
 				.append(enUU).append(") e ");
 		if (!StringUtils.isEmpty(productCondition)) {
-			enCountSql.append("right join ( select pr_enuu from v$product$private where ").append(productCondition).append(") p on pr_enuu = en_uu");
+			enCountSql.append("right join ( select pr_enuu from products where ").append(productCondition).append(") p on pr_enuu = en_uu");
+			enCountSql.append(" union select en_uu from sec$enterprises where en_name not like '%测试%'  and en_name not like '%test%' and (length(en_businesscode) > 12 or en_name like '%香港%' or en_name like '%HONG KONG%'  or en_area like '%香港%')and (en_name not REGEXP '^[0-9]*$' and (en_name like '%ltd%' or en_name like '%limited%' or  en_name like '%tcl%' or en_name not regexp '[\\u4e00-\\u9fa5_a-zA-Z0-9]') and ")
+					.append(enterpriseCondition).append(" and en_uu <> ").append(enUU).append(")");
 		}
-		enCountSql.append(" group by en_uu )a");
+		enCountSql.append(")a");
 		return commonDao.queryForObject(enCountSql.toString(), Integer.class);
 	}
 
@@ -252,15 +261,14 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
 	private String getEnUUGroupByEnUUOrderByCount(Long enUU, String enterpriseCondition, String productCondition) {
 		StringBuilder enUUSql = new StringBuilder();
 		// 含名称、企业执照号、地址、邮箱、电话、行业、经营范围搜索
-		enUUSql.append("select en_uu, count(1) as counts from (select en_uu from sec$enterprises where en_name not like '%测试%' " +
+		enUUSql.append("select distinct(en_uu) from (select en_uu from sec$enterprises where en_name not like '%测试%' " +
 				" and en_name not like '%test%' and (length(en_businesscode) > 12 or en_name like '%香港%' or en_name like '%HONG KONG%' " +
 				" or en_area like '%香港%')and (en_name not REGEXP '^[0-9]*$' and (en_name like '%ltd%' or en_name like '%limited%' or " +
 				" en_name like '%tcl%' or en_name not regexp '[\\u4e00-\\u9fa5_a-zA-Z0-9]')) and ").append(enterpriseCondition).append(" and en_uu <> ").append(enUU)
 				.append(") e");
 		if (!StringUtils.isEmpty(productCondition)) {
-			enUUSql.append(" right join ( select pr_enuu from v$product$private where ").append(productCondition).append(") p on pr_enuu = en_uu where en_uu is not null ");
+			enUUSql.append(" right join ( select pr_enuu from products where ").append(productCondition).append(") p on pr_enuu = en_uu ");
 		}
-		enUUSql.append(" group by en_uu order by count(1) desc ");
 		return enUUSql.toString();
 	}
 }