|
|
@@ -34,28 +34,72 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
private SearchService searchService;
|
|
|
|
|
|
/**
|
|
|
- * 获取供应商资源列表
|
|
|
- * @param page 页码
|
|
|
- * @param size 每页大小
|
|
|
- * @param keyword 关键词
|
|
|
- * @return 供应商资源page
|
|
|
- * @version 2018年5月15日 11:53:06 增加限制,要求营业执照号长度大于12才显示
|
|
|
+ * 类目
|
|
|
+ */
|
|
|
+ private static final String KIND_EQUAL = "kind";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 型号
|
|
|
+ */
|
|
|
+ private static final String PCMPCODE_EQUAL = "pCmpCode";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 品牌
|
|
|
+ */
|
|
|
+ private static final String PBRANDEN_EQUAL = "pBrandEn";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关键词(非必填)精确匹配来获取供应商资源列表
|
|
|
+ *
|
|
|
+ * @param size the params 一页的大小
|
|
|
+ * @param page 第几页
|
|
|
+ * @param keyword the keyword 搜索关键字
|
|
|
+ * @param field 字段 kind 类目 cmpCode 型号 brand 品牌
|
|
|
+ * @return the Page<VendorIntroduction> 返回一页的数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public Page<VendorIntroduction> getVendorIntroduction(int page, int size, String keyword) {
|
|
|
+ public Page<VendorIntroduction> getVendorIntroduction(int page, int size, String keyword, String field) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
+ String enterpriseCondition = " 1=1 ";
|
|
|
+ String productCondition = "";
|
|
|
+ // 拼接查询条件
|
|
|
if (!StringUtils.isEmpty(keyword)) {
|
|
|
keyword = keyword.trim();
|
|
|
+ if (!StringUtils.isEmpty(field)) {
|
|
|
+ switch (field) {
|
|
|
+ case KIND_EQUAL :
|
|
|
+ productCondition = "pr_kind = '" + keyword + "'";
|
|
|
+ break;
|
|
|
+ case PCMPCODE_EQUAL :
|
|
|
+ productCondition = "pr_pcmpcode = '" + keyword + "'";
|
|
|
+ break;
|
|
|
+ case PBRANDEN_EQUAL :
|
|
|
+ productCondition = "pr_pbranden = '" + keyword + "'";
|
|
|
+ break;
|
|
|
+ default :
|
|
|
+ enterpriseCondition = "(en_name like '%" + keyword + "%' or en_address like '%" + keyword + "%' or en_industry like '% "
|
|
|
+ + keyword + "%')";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ enterpriseCondition = "(en_name like '%" + keyword + "%' or en_address like '%" + keyword + "%' or en_industry like '% "
|
|
|
+ + keyword + "%')";
|
|
|
+ }
|
|
|
}
|
|
|
Long enUU = 0L;
|
|
|
if (null != SystemSession.getUser() && null != SystemSession.getUser().getEnterprise()) {
|
|
|
enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
}
|
|
|
// 查询所有企业个数
|
|
|
- Integer total = getTotalCount(enUU, keyword);
|
|
|
+ Integer total = getTotalCount(enUU, enterpriseCondition, productCondition);
|
|
|
// 查询企业
|
|
|
- List<VendorIntroduction> vendorIntroductions = getEnterpriseWithCondition(enUU, keyword, page, size);
|
|
|
-// System.out.println("查找完企业UU" + (System.currentTimeMillis() - start));
|
|
|
+ List<VendorIntroduction> vendorIntroductions;
|
|
|
+ if (!StringUtils.isEmpty(productCondition)) {
|
|
|
+ vendorIntroductions = getEnterpriseWithProductCondition(enUU, enterpriseCondition, productCondition, page, size);
|
|
|
+ } else {
|
|
|
+ vendorIntroductions = getEnterpriseWithoutProductCondition(enUU, enterpriseCondition, page, size);
|
|
|
+ }
|
|
|
+ System.out.println("查找完企业UU" + (System.currentTimeMillis() - start));
|
|
|
return new Page<VendorIntroduction>(page, size, vendorIntroductions, total);
|
|
|
}
|
|
|
|
|
|
@@ -103,91 +147,97 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
/**
|
|
|
* 获取供应商资源信息
|
|
|
* @param enUU 本企业UU
|
|
|
- * @param keyword 关键词
|
|
|
+ * @param enterpriseCondition 企业搜索条件
|
|
|
+ * @param productCondition 物料搜索条件
|
|
|
* @param page 页码
|
|
|
* @param size 尺寸
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<VendorIntroduction> getEnterpriseWithCondition(Long enUU, String keyword, int page, int size) {
|
|
|
+ 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);
|
|
|
+ // 获取企业sql
|
|
|
+ enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, 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");
|
|
|
+ // 查找非供应商的卖当前商品的企业UU
|
|
|
+ StringBuilder vendorIntroductionUusSql = new StringBuilder();
|
|
|
+ // 行数 控制
|
|
|
+ String rownumSql = ") s order by isStore desc,prodCounts desc,enUU asc limit " + (page - 1) * size + "," + size ;
|
|
|
+ vendorIntroductionUusSql.append("select s.*, if( st_uuid is not null and st_status = 'OPENED', 1, null) isStore");
|
|
|
+ vendorIntroductionUusSql.append(",(select count(1) from ( select pr_enuu from v$product$private where ").append(productCondition)
|
|
|
+ .append(" and ifnull(pr_b2cenabled, 1) = 1 and pr_pbranden is not null and pr_pcmpcode is not null) p1 where pr_enuu = enUU) prodCounts");
|
|
|
+ vendorIntroductionUusSql.append(" from (").append(enterpriseSql).append(rownumSql);
|
|
|
+ System.out.println("ens:" + vendorIntroductionUusSql);
|
|
|
+ return commonDao.query(vendorIntroductionUusSql.toString(), VendorIntroduction.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取供应商资源信息
|
|
|
+ * @param enUU 本企业UU
|
|
|
+ * @param enterpriseCondition 企业搜索条件
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 尺寸
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<VendorIntroduction> getEnterpriseWithoutProductCondition(Long enUU, String enterpriseCondition, int page, int size) {
|
|
|
StringBuilder enterpriseSql = new StringBuilder();
|
|
|
-// // 查询所有符合条件的enUU的语句,按待售物料数量排序
|
|
|
-// String enUUSql = getEnUUGroupByEnUUOrderByCount(enUU, keyword);
|
|
|
// 获取企业sql
|
|
|
enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, 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_enuu,st.st_status from sec$enterprises en left join store$info st on st.st_enuu = en.en_uu 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 en_uu <> ")
|
|
|
- .append(enUU);
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- enterpriseSql.append(" and (en_name like '%").append(keyword).append("%' or en_address like '%").append(keyword).append("%' or en_industry like '%").append(keyword)
|
|
|
- .append("%')");
|
|
|
- }
|
|
|
+ .append(enUU).append(" and ").append(enterpriseCondition);
|
|
|
// rownum 控制
|
|
|
String rownumSql = ") s order by isStore desc,enUU asc limit " + (page - 1) * size + "," + size ;
|
|
|
-// // 查询企业简要物料信息语句
|
|
|
-// String prodInfoSql = "select wm_concat(pr_title || (case when pr_brand is not null then '(' || pr_brand || ')' else ' ' end)) from v$product$private where pr_enuu=en_uu and "
|
|
|
-// + " and pr_issale = 1 and pr_b2cenabled = 1 and rownum<5 ";
|
|
|
// 查询企业是否开店语句
|
|
|
- // 查找非供应商的卖当前商品的企业UU
|
|
|
- // (select 1 from v$product$private where ifnull(pr_b2cenabled, 1) = 1 and pr_issale = 1 and pr_pbranden is not null and pr_pcmpcode is not null and pr_enuu = enUU limit 0,1) hasProduct
|
|
|
String vendorIntroductionUusSql = "select s.*, if( st_enuu is not null and st_status = 'OPENED', 1, 0) isStore from ("
|
|
|
+ enterpriseSql + rownumSql;
|
|
|
-// String vendorIntroductionUusSql = "select s.*,( " + prodInfoSql + ") productInfo, (" + storeSql +
|
|
|
-// ") isStore from (select t.*,rownum as r1 from (" + enterpriseSql + rownumSql;
|
|
|
-// System.out.println("ens:" + vendorIntroductionUusSql);
|
|
|
return commonDao.query(vendorIntroductionUusSql, VendorIntroduction.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取所有符合条件企业数量
|
|
|
* @param enUU 本企业UU
|
|
|
- * @param keyword 关键词
|
|
|
+ * @param enterpriseCondition 企业过滤条件
|
|
|
+ * @param productCondition 物料过滤条件
|
|
|
* @return
|
|
|
*/
|
|
|
- private Integer getTotalCount(Long enUU, String keyword) {
|
|
|
+ private Integer getTotalCount(Long enUU, String enterpriseCondition, String productCondition) {
|
|
|
StringBuilder enCountSql = new StringBuilder();
|
|
|
- // 含名称、地址、、行业、经营范围搜索 物料型号、名称
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- String keywordSql = getKeywordSql(enUU, keyword);
|
|
|
- enCountSql.append("select count(1) from (").append(keywordSql);
|
|
|
- } else {
|
|
|
- enCountSql.append("select count(1) from (select en_uu,count(1) 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 en_uu <> ").append(enUU);
|
|
|
+ enCountSql.append("select count(1) from (select en_uu,count(1) 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)) {
|
|
|
+ enCountSql.append("right join ( select pr_enuu from v$product$private where ").append(productCondition).append(") p on pr_enuu = en_uu");
|
|
|
}
|
|
|
enCountSql.append(" group by en_uu )a");
|
|
|
-// System.out.println("en_count:" + enCountSql.toString());
|
|
|
+ System.out.println("en_count:" + enCountSql.toString());
|
|
|
return commonDao.queryForObject(enCountSql.toString(), Integer.class);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 拼接关键词Sql
|
|
|
- * @param enUU
|
|
|
- * @param keyword
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getKeywordSql(Long enUU, String keyword) {
|
|
|
- return "select en_uu,count(1) as counts from sec$enterprises where en_name not like '%测试%' " +
|
|
|
- "and lower(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 like '%"
|
|
|
- + keyword + "%' or en_address like '%" + keyword + "%' or en_industry like '%" + keyword + "%') and en_uu <> " + enUU +
|
|
|
- " 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-\\u9fa5a-zA-Z0-9]'))";
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 拼接所有待售物料所属企业UU,按enUU分组,按物料数量倒序
|
|
|
* @param enUU 当前企业UU
|
|
|
- * @param keyword 搜索关键词
|
|
|
+ * @param enterpriseCondition 企业过滤条件
|
|
|
+ * @param productCondition 物料匹配条件
|
|
|
* @return
|
|
|
*/
|
|
|
- private String getEnUUGroupByEnUUOrderByCount(Long enUU, String keyword) {
|
|
|
+ private String getEnUUGroupByEnUUOrderByCount(Long enUU, String enterpriseCondition, String productCondition) {
|
|
|
StringBuilder enUUSql = new StringBuilder();
|
|
|
// 含名称、企业执照号、地址、邮箱、电话、行业、经营范围搜索
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- enUUSql.append(getKeywordSql(enUU, keyword));
|
|
|
- } else {
|
|
|
- enUUSql.append("select en_uu, count(1) as counts from (select * from sec$enterprises where en_name not like '%测试%' " +
|
|
|
- " and lower(en_name) not like '%test%') en where en.en_uu <> ").append(enUU);
|
|
|
+ enUUSql.append("select en_uu, count(1) as counts 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(" group by en_uu order by count(1) desc ");
|
|
|
return enUUSql.toString();
|