|
|
@@ -334,38 +334,38 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
String rownumSql = ") t where rownum <= " + page * size + ") where r1 > " + (page - 1) * size;
|
|
|
// 查找非供应商的卖当前商品的企业UU
|
|
|
StringBuffer vendorRecommendUusSql = new StringBuffer();
|
|
|
- StringBuffer vendorRecommendUuNumSql = new StringBuffer();
|
|
|
- vendorRecommendUusSql.append("select en_uu from (select t.*,rownum as r1 from (select en_uu from (select en_uu from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
- " where 1=1 and pr_issale = 1 and pr_b2bdisabled <> 1 and pr_cmpcode in (").append(cmpCodesSql).append(") and en_uu <> ").append(enUU);
|
|
|
- vendorRecommendUuNumSql.append("select count(distinct(en_uu)) from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
+// StringBuffer vendorRecommendUuNumSql = new StringBuffer();
|
|
|
+ vendorRecommendUusSql.append("select en_uu,hitNums from (select t.*,rownum as r1 from (select en_uu,hitNums from (select en_uu,count(en_uu) as hitNums from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
" where 1=1 and pr_issale = 1 and pr_b2bdisabled <> 1 and pr_cmpcode in (").append(cmpCodesSql).append(") and en_uu <> ").append(enUU);
|
|
|
+// vendorRecommendUuNumSql.append("select count(distinct(en_uu)) from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
+// " where 1=1 and pr_issale = 1 and pr_b2bdisabled <> 1 and pr_cmpcode in (").append(cmpCodesSql).append(") and en_uu <> ").append(enUU);
|
|
|
if (null != enterpriseMatchCondition && !"".equals(enterpriseMatchCondition)) {
|
|
|
vendorRecommendUusSql.append(" and ").append(enterpriseMatchCondition);
|
|
|
- vendorRecommendUuNumSql.append(" and ").append(enterpriseMatchCondition);
|
|
|
+// vendorRecommendUuNumSql.append(" and ").append(enterpriseMatchCondition);
|
|
|
}
|
|
|
vendorRecommendUusSql.append(" group by en_uu order by count(en_uu) desc) a");
|
|
|
// 拼接未匹配到物料的有可售产品的供应商
|
|
|
StringBuffer enterpriseProdSaleSql = new StringBuffer();
|
|
|
- // 匹配到的企业UU
|
|
|
- String enUUSql = "select distinct(en_uu) from sec$enterprises left join v$products on en_uu = pr_enuu where 1=1 and pr_issale = 1 and pr_b2bdisabled <> 1 and pr_cmpcode in (" +
|
|
|
- " select distinct(pr.pr_cmpcode) from v$products pr where pr.pr_ispurchase = 1 and nvl(pr_issale, 0) <> 1 and pr.pr_enuu = " + enUU + ") " +
|
|
|
+ // 匹配到的企业UU(包含自己企业UU)
|
|
|
+ String enUUSql = "select distinct(en_uu) from sec$enterprises left join v$products p on en_uu = p.pr_enuu where p.pr_issale = 1 and p.pr_b2bdisabled <> 1 and exists (" +
|
|
|
+ " select 1 from v$products pr where pr.pr_ispurchase = 1 and nvl(pr.pr_issale, 0) <> 1 and pr.pr_cmpcode = p.pr_cmpcode and pr.pr_enuu = " + enUU + ") " +
|
|
|
" and en_uu <> " + enUU;
|
|
|
enterpriseProdSaleSql.append(
|
|
|
- " select en_uu from (select en_uu from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
- " where pr_issale = 1 and pr_b2bdisabled <> 1 and en_uu <> ").append(enUU).append(" and en_uu not in (" +
|
|
|
- " select distinct(en_uu) from (").append(enUUSql).append(")) group by en_uu order by count(pr_issale) desc) b");
|
|
|
+ " select en_uu,0 as hitNums from (select en_uu from sec$enterprises left join v$products on en_uu = pr_enuu " +
|
|
|
+ " where pr_issale = 1 and pr_b2bdisabled <> 1 and en_uu <> ").append(enUU).append(" and en_uu not in (")
|
|
|
+ .append(enUUSql).append(") group by en_uu order by count(pr_issale) desc) b");
|
|
|
vendorRecommendUusSql.append(" union all ").append(enterpriseProdSaleSql);
|
|
|
vendorRecommendUusSql.append(rownumSql);
|
|
|
-// System.out.println("SQL:" + vendorRecommendUusSql.toString());
|
|
|
-// System.out.println("NUM_SQL:" + vendorRecommendUuNumSql.toString());
|
|
|
// 因为需求更改为所有有销售产品的企业都会被返回,所以total直接取除本企业外其他有销售产品的企业数即可,之前的匹配企业数不再返回
|
|
|
StringBuffer totalSql = new StringBuffer().append(" select count(1) from (select en_uu from sec$enterprises left join " +
|
|
|
" v$products on en_uu = pr_enuu where pr_issale = 1 and pr_b2bdisabled <> 1 and en_uu <> ")
|
|
|
.append(enUU).append(" group by en_uu)");
|
|
|
+// System.out.println("SQL:" + vendorRecommendUusSql.toString());
|
|
|
+// System.out.println("NUM_SQL:" + totalSql.toString());
|
|
|
Integer total = commonDao.queryForObject(totalSql.toString(), Integer.class);
|
|
|
- List<Long> vendUUs = commonDao.queryForList(vendorRecommendUusSql.toString(), Long.class);
|
|
|
+ List<VendorRecommend> vendorRecommends = commonDao.query(vendorRecommendUusSql.toString(), VendorRecommend.class);
|
|
|
System.out.println("查找完企业UU" + (System.currentTimeMillis() - start));
|
|
|
- return getVendorRecommendByVendUUs(enUU, vendUUs, page, size, total);
|
|
|
+ return getVendorRecommendByVendUUs(enUU, vendorRecommends, page, size, total);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -414,38 +414,43 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
/**
|
|
|
* 根据供应商UU返回供应商推荐信息列表
|
|
|
* @param enUU 本企业UU
|
|
|
- * @param vendUUs 供应商UU List
|
|
|
+ * @param vendorRecommends 供应商推荐实体 ,仅包含enuu和hitNums
|
|
|
* @param page 页数
|
|
|
* @param size 每页条数
|
|
|
* @param total 总条数
|
|
|
- * @return
|
|
|
+ * @return 供应商推荐page
|
|
|
*/
|
|
|
- private com.uas.account.support.Page<VendorRecommend> getVendorRecommendByVendUUs(Long enUU, List<Long> vendUUs, int page, int size, Integer total) {
|
|
|
+ private com.uas.account.support.Page<VendorRecommend> getVendorRecommendByVendUUs(Long enUU, List<VendorRecommend> vendorRecommends, int page, int size, Integer total) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
List<VendorRecommend> content = new ArrayList<>();
|
|
|
- for (Long vendUU : vendUUs) {
|
|
|
- Enterprise enterprise = enterPriseDao.findOne(vendUU);
|
|
|
+ for (VendorRecommend vendorRecommend : vendorRecommends) {
|
|
|
+// long start1 = System.currentTimeMillis();
|
|
|
+ Long vendUU = vendorRecommend.getEn_uu();
|
|
|
+ Enterprise enterprise = enterPriseDao.findOne(vendorRecommend.getEn_uu());
|
|
|
if (null != enterprise) {
|
|
|
- long start1 = System.currentTimeMillis();
|
|
|
- VendorRecommend vendorRecommend = covert(enterprise);
|
|
|
- StringBuffer productInfosSql = new StringBuffer();
|
|
|
- StringBuffer productNumSql = new StringBuffer();
|
|
|
- productInfosSql.append("select wm_concat(pr_title || '(' || pr_brand || ')') productInfo from v$products pr where pr.pr_enuu = ").append(vendUU)
|
|
|
- .append(" and pr.pr_issale =1 and pr.pr_cmpcode in (select pr_cmpcode from v$products p1 " +
|
|
|
- " where p1.pr_ispurchase = 1 and nvl(pr_issale, 0) <> 1 " +
|
|
|
- " and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
- .append(enUU).append(") and rownum <= 5 order by pr_standard,pr_id desc");
|
|
|
- productNumSql.append("select count(1) from v$products pr where pr.pr_enuu = ").append(vendUU)
|
|
|
- .append(" and pr.pr_issale =1 and pr.pr_cmpcode in (select pr_cmpcode from v$products p1 " +
|
|
|
- " where p1.pr_ispurchase = 1 and nvl(pr_issale, 0) <> 1 " +
|
|
|
- " and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
- .append(enUU).append(")");
|
|
|
- // 获取前五条匹配物料
|
|
|
- String productInfo = commonDao.queryForObject(productInfosSql.toString(), String.class);
|
|
|
- Integer hitNums = commonDao.queryForObject(productNumSql.toString(), Integer.class);
|
|
|
- vendorRecommend.setProductInfo(productInfo);
|
|
|
- vendorRecommend.setHitNums(hitNums);
|
|
|
- List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU ,vendUU);
|
|
|
+ vendorRecommend = covert(enterprise, vendorRecommend);
|
|
|
+ if (null != vendorRecommend.getHitNums() && vendorRecommend.getHitNums() > 0) {
|
|
|
+ StringBuffer productInfosSql = new StringBuffer();
|
|
|
+// StringBuffer productNumSql = new StringBuffer();
|
|
|
+ productInfosSql.append("select wm_concat(pr_title || '(' || pr_brand || ')') productInfo from v$products pr where pr.pr_enuu = ").append(vendUU)
|
|
|
+ .append(" and pr.pr_issale =1 and exists (select 1 from v$products p1 " +
|
|
|
+ " where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and nvl(pr_issale, 0) <> 1 " +
|
|
|
+ " and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
+ .append(enUU).append(") and rownum <= 5 order by pr_standard,pr_id desc");
|
|
|
+// productNumSql.append("select count(1) from v$products pr where pr.pr_enuu = ").append(vendUU)
|
|
|
+// .append(" and pr.pr_issale =1 and exists (select 1 from v$products p1 " +
|
|
|
+// " where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and nvl(pr_issale, 0) <> 1 " +
|
|
|
+// " and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
+// .append(enUU).append(")");
|
|
|
+// System.out.println(productInfosSql.toString() + ";");
|
|
|
+// System.out.println(productNumSql.toString() + ";");
|
|
|
+ // 获取前五条匹配物料
|
|
|
+ String productInfo = commonDao.queryForObject(productInfosSql.toString(), String.class);
|
|
|
+// Integer hitNums = commonDao.queryForObject(productNumSql.toString(), Integer.class);
|
|
|
+ vendorRecommend.setProductInfo(productInfo);
|
|
|
+// vendorRecommend.setHitNums(hitNums);
|
|
|
+ }
|
|
|
+ List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU, vendUU);
|
|
|
if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
vendorRecommend.setIsVendor(Constant.YES);
|
|
|
} else {
|
|
|
@@ -462,11 +467,11 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
|
|
|
/**
|
|
|
* 企业信息转换为推荐供应商信息
|
|
|
- * @param enterprise
|
|
|
+ * @param enterprise 企业信息
|
|
|
+ * @param vendorRecommend 包含enuu 和hitNums 的供应商推荐信息
|
|
|
* @return
|
|
|
*/
|
|
|
- private VendorRecommend covert(Enterprise enterprise) {
|
|
|
- VendorRecommend vendorRecommend = new VendorRecommend();
|
|
|
+ private VendorRecommend covert(Enterprise enterprise, VendorRecommend vendorRecommend) {
|
|
|
vendorRecommend.setEn_address(enterprise.getEnAddress());
|
|
|
vendorRecommend.setEn_businesscode(enterprise.getEnBussinessCode());
|
|
|
vendorRecommend.setEn_contactman(enterprise.getContactMan());
|