|
|
@@ -1,5 +1,7 @@
|
|
|
package com.uas.platform.b2b.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.account.util.AccountUtils;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
import com.uas.platform.b2b.dao.DistributeDao;
|
|
|
@@ -335,46 +337,113 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
/**
|
|
|
* 获取当前企业推荐供应商
|
|
|
*
|
|
|
- * @param productMatchCondition 企业匹配条件
|
|
|
- * @param enterpriseMatchCondition 物料匹配条件
|
|
|
+ * @param productMatchCondition 物料模糊匹配条件
|
|
|
+ * @param enterpriseMatchCondition 企业搜索匹配条件
|
|
|
+ * @param productCondition 物料精确匹配条件
|
|
|
* @param page 页面
|
|
|
* @param size 每页条数
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public com.uas.account.support.Page<VendorRecommend> getVendorRecommend(String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
|
|
|
+ public com.uas.account.support.Page<VendorRecommend> getVendorRecommend(String productMatchCondition, String enterpriseMatchCondition, String productCondition, int page, int size) {
|
|
|
final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- // 先查询当前企业的采购物料(待购&&不在售)的标准物料标准料号
|
|
|
- StringBuffer cmpCodesSql = new StringBuffer().append("select distinct(pr.pr_cmpcode) from products pr " +
|
|
|
- " where pr.pr_ispurchase = 1 and pr.pr_issale != 1 and pr.pr_standard = 1 and pr.pr_enuu = ").append(enUU);
|
|
|
- if (null != productMatchCondition && !"".equals(productMatchCondition)) {
|
|
|
- cmpCodesSql.append(" and ").append(productMatchCondition);
|
|
|
- }
|
|
|
-
|
|
|
+ String cmpCodesSql = concatProductCondition(enUU, productMatchCondition, productCondition);
|
|
|
// // 根据标准料号找出对应的供应商UU
|
|
|
-// String vendUUsSql = "select distinct(ve_vendenuu) from purc$vendors left join products on pr_enuu = ve_vendenuu" +
|
|
|
+// String vendUUsSql = "select distinct(ve_vendenuu) from purc$vendors left join v$products on pr_enuu = ve_vendenuu" +
|
|
|
// " where ve_myenuu = " + enUU + " and pr_issale = 1 and pr_standard = 1 and pr_cmpcode in (" + cmpCodesSql + ")";
|
|
|
// 采购物料原厂型号
|
|
|
System.out.println(cmpCodesSql);
|
|
|
- final List<String> cmpCodes = commonDao.queryForList(cmpCodesSql.toString(), String.class);
|
|
|
+// final List<String> cmpCodes = commonDao.queryForList(cmpCodesSql.toString(), String.class);
|
|
|
// rownum 控制
|
|
|
- String rownumSql = " group by en_uu order by count(en_uu) desc) t where rownum <= " + page * size + ") where r1 > " + (page - 1) * size;
|
|
|
+ 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 sec$enterprises left join products on en_uu = pr_enuu " +
|
|
|
- " where 1=1 and pr_issale = 1 and pr_standard = 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 products on en_uu = pr_enuu " +
|
|
|
- " where 1=1 and pr_issale = 1 and pr_standard = 1 and pr_cmpcode in (").append(cmpCodesSql).append(") and en_uu <> ").append(enUU);
|
|
|
+ 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 " +
|
|
|
+ " 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);
|
|
|
}
|
|
|
+ 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 (pr.pr_issale is null or pr.pr_issale = 0) 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");
|
|
|
+ vendorRecommendUusSql.append(" union all ").append(enterpriseProdSaleSql);
|
|
|
vendorRecommendUusSql.append(rownumSql);
|
|
|
System.out.println("SQL:" + vendorRecommendUusSql.toString());
|
|
|
System.out.println("NUM_SQL:" + vendorRecommendUuNumSql.toString());
|
|
|
- Integer total = commonDao.queryForObject(vendorRecommendUuNumSql.toString(), Integer.class);
|
|
|
+ // 因为需求更改为所有有销售产品的企业都会被返回,所以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)");
|
|
|
+ Integer total = commonDao.queryForObject(totalSql.toString(), Integer.class);
|
|
|
List<Long> vendUUs = commonDao.queryForList(vendorRecommendUusSql.toString(), Long.class);
|
|
|
+ return getVendorRecommendByVendUUs(enUU, vendUUs, page, size, total);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装物料匹配条件
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param productMatchCondition 物料模糊匹配条件
|
|
|
+ * @param productCondition 物料精确匹配条件
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String concatProductCondition(Long enUU, String productMatchCondition, String productCondition) {
|
|
|
+ // 先查询当前企业的采购物料(待购&&不在售)的标准物料标准料号
|
|
|
+ StringBuffer cmpCodesSql = new StringBuffer().append("select distinct(pr.pr_cmpcode) from v$products pr " +
|
|
|
+ " where pr.pr_ispurchase = 1 and (pr.pr_issale is null or pr.pr_issale = 0) and pr.pr_enuu = ").append(enUU);
|
|
|
+ if (null != productMatchCondition && !"".equals(productMatchCondition)) {
|
|
|
+ cmpCodesSql.append(" and ").append(productMatchCondition);
|
|
|
+ }
|
|
|
+ // productCondition 不为空时,使用其中条件进行精确匹配
|
|
|
+ if (null != productCondition && !"".equals(productCondition)) {
|
|
|
+ JSONObject prodCondition = JSON.parseObject(productCondition);
|
|
|
+ String code = (String) prodCondition.get("pr_code");
|
|
|
+ String title = (String) prodCondition.get("pr_title");
|
|
|
+ String spec = (String) prodCondition.get("pr_spec");
|
|
|
+ if (null != code && !"".equals(code)) {
|
|
|
+ List<Product> products = productDao.findByEnUUAndCode(enUU, code);
|
|
|
+ // 已上传的,标准物料使用原厂型号精确匹配,并根据物料名称模糊搜索, 非标物料使用物料名称模糊搜索
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
+ Product product = products.get(0);
|
|
|
+ cmpCodesSql.append(" and pr.pr_title like '%").append(product.getTitle()).append("%' ");
|
|
|
+ if (product.getStandard() == 1) {
|
|
|
+ cmpCodesSql.append(" and pr.pr_cmpcode = ").append(product.getCmpCode());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (null != title && !"".equals(title)) {
|
|
|
+ cmpCodesSql.append(" and pr.pr_title like '%").append(title).append("%' ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (null != title && !"".equals(title)) {
|
|
|
+ cmpCodesSql.append(" and pr.pr_title like '%").append(title).append("%' ");
|
|
|
+ } else if (null != spec && !"".equals(spec)) {
|
|
|
+ cmpCodesSql.append(" and pr.pr_spec like '%").append(spec).append("%' ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cmpCodesSql.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据供应商UU返回供应商推荐信息列表
|
|
|
+ * @param enUU 本企业UU
|
|
|
+ * @param vendUUs 供应商UU List
|
|
|
+ * @param page 页数
|
|
|
+ * @param size 每页条数
|
|
|
+ * @param total 总条数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private com.uas.account.support.Page<VendorRecommend> getVendorRecommendByVendUUs(Long enUU, List<Long> vendUUs, int page, int size, Integer total) {
|
|
|
List<VendorRecommend> content = new ArrayList<>();
|
|
|
for (final Long vendUU : vendUUs) {
|
|
|
Enterprise vendor = enterPriseDao.findOne(vendUU);
|
|
|
@@ -387,12 +456,12 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
StringBuffer productNumSql = new StringBuffer();
|
|
|
productIdsSql.append("select pr.pr_id from v$products pr where pr.pr_enuu = ").append(vendUU)
|
|
|
.append(" and pr.pr_issale =1 and pr.pr_standard =1 and exists (select 1 from v$products p1 " +
|
|
|
- "where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and p1.pr_issale != 1 " +
|
|
|
+ "where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and (p1.pr_issale is null or p1.pr_issale = 0) " +
|
|
|
"and p1.pr_standard = 1 and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
.append(enUU).append(") and rownum <= 5 order by 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_standard =1 and exists (select 1 from v$products p1 " +
|
|
|
- "where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and p1.pr_issale != 1 " +
|
|
|
+ "where p1.pr_cmpcode = pr.pr_cmpcode and p1.pr_ispurchase = 1 and (p1.pr_issale is null or p1.pr_issale = 0) " +
|
|
|
"and p1.pr_standard = 1 and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
|
|
|
.append(enUU).append(")");
|
|
|
List<Long> prodIds = commonDao.queryForList(productIdsSql.toString(), Long.class);
|
|
|
@@ -403,12 +472,12 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
vendorRecommend.setEnterprise(vendor);
|
|
|
vendorRecommend.setHitProds(hitsProducts);
|
|
|
vendorRecommend.setHitNums(hitNums);
|
|
|
- List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU ,vendUU);
|
|
|
- if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
- vendorRecommend.setIsVendor(Constant.YES);
|
|
|
- } else {
|
|
|
- vendorRecommend.setIsVendor(Constant.NO);
|
|
|
- }
|
|
|
+ List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU ,vendUU);
|
|
|
+ if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
+ vendorRecommend.setIsVendor(Constant.YES);
|
|
|
+ } else {
|
|
|
+ vendorRecommend.setIsVendor(Constant.NO);
|
|
|
+ }
|
|
|
content.add(vendorRecommend);
|
|
|
}
|
|
|
}
|
|
|
@@ -433,7 +502,7 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
// 先查询当前企业的采购物料(待购&&不在售)的标准物料标准料号
|
|
|
StringBuffer cmpCodesSql = new StringBuffer();
|
|
|
cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
|
|
|
- .append(enUU).append(" and pr_issale <> 1 and pr_ispurchase = 1 and pr_standard = 1 and pr_b2bdisabled <> 1 ");
|
|
|
+ .append(enUU).append(" and (pr_issale is null or pr_issale = 0) and pr_ispurchase = 1 and pr_b2bdisabled <> 1 ");
|
|
|
if (null != productMatchCondition) {
|
|
|
cmpCodesSql.append(" and ").append(productMatchCondition);
|
|
|
}
|
|
|
@@ -442,16 +511,16 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
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_standard = 1 and p1.pr_b2bdisabled <> 1 and ")
|
|
|
- .append(null != whereCondition ? whereCondition : "").append(" order by pr_id desc)");
|
|
|
+ .append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
|
|
|
// 查找不匹配但是在售物料的语句 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_standard = 1 and p1.pr_b2bdisabled <> 1 and ")
|
|
|
- .append(null != whereCondition ? whereCondition : "").append(" order by pr_id desc)");
|
|
|
+ .append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
|
|
|
// 物料id
|
|
|
StringBuffer idSql = new StringBuffer();
|
|
|
String countSql = "select count(1) from v$products where pr_enuu = " + vendUU
|
|
|
- + " and pr_issale = 1 and pr_standard = 1 and pr_b2bdisabled <> 1";
|
|
|
+ + " and pr_issale = 1 and pr_b2bdisabled <> 1";
|
|
|
// rownum 控制
|
|
|
String rownumSql = " t where rownum <= " + page * size + ") where r1 > " + (page - 1) * size;
|
|
|
idSql.append("select pr_id from (select t.*,rownum as r1 from (").append(productsMatchSql).append(" union all ").append(notMatchProductsSql)
|