|
|
@@ -306,6 +306,7 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
/**
|
|
|
* 获取当前企业推荐供应商
|
|
|
*
|
|
|
+ * @param enUU 当前企业UU
|
|
|
* @param productMatchCondition 物料模糊匹配条件
|
|
|
* @param enterpriseMatchCondition 企业搜索匹配条件
|
|
|
* @param page 页面
|
|
|
@@ -313,9 +314,9 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
* @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(Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
- final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+// final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
if (StringUtils.isEmpty(productMatchCondition)) {
|
|
|
productMatchCondition = " 1=1 ";
|
|
|
}
|
|
|
@@ -333,8 +334,7 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
// 查找非供应商的卖当前商品的企业UU
|
|
|
StringBuffer vendorRecommendUusSql = new StringBuffer();
|
|
|
vendorRecommendUusSql.append("select s.*,( select wm_concat(pr_title || (case when pr_brand is not null then '(' || pr_brand || ')' else ' ' end)) from v$products where pr_enuu=en_uu and ").append(productMatchCondition)
|
|
|
- .append(" and exists (select 1 from v$products B where B.pr_cmpcode = pr_cmpcode and B.pr_enuu = ").append(enUU)
|
|
|
- .append(" and B.pr_ispurchase = 1 and nvl(B.pr_issale, 0) <> 1) and rownum<5 ) productInfo, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ")
|
|
|
+ .append(" and rownum<5 ) productInfo, (select 1 from purc$vendors where ve_vendenuu = en_uu and ve_myenuu = ")
|
|
|
.append(enUU).append(") isVendor from (select t.*,rownum as r1 from (").append(enterpriseSql).append(rownumSql);
|
|
|
// 因为需求更改为所有有销售产品的企业都会被返回,所以total直接取除本企业外其他有销售产品的企业数即可,之前的匹配企业数不再返回
|
|
|
StringBuffer totalSql = new StringBuffer().append(" select count(1) from (select en_uu from sec$enterprises left join " +
|
|
|
@@ -451,55 +451,65 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long vendUU, String productMatchCondition, String whereCondition) {
|
|
|
- System.out.println("进入方法:" + System.currentTimeMillis());
|
|
|
+ public com.uas.account.support.Page<Product> getProductsByVendorRecommend(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
|
|
|
+ // 如果enUU不为空按之前的处理,为空另外处理
|
|
|
if (StringUtils.isEmpty(whereCondition)) {
|
|
|
whereCondition = " 1 = 1 ";
|
|
|
}
|
|
|
- long start = System.currentTimeMillis();
|
|
|
- // UAS企业UU
|
|
|
- Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- StringBuffer cmpCodesSql = new StringBuffer();
|
|
|
- cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
|
|
|
- .append(enUU).append(" and nvl(pr_issale,0) <> 1 and pr_ispurchase = 1 and pr_b2bdisabled <> 1 ");
|
|
|
- if (null != productMatchCondition) {
|
|
|
- cmpCodesSql.append(" and ").append(productMatchCondition);
|
|
|
+ List<Product> products = new ArrayList<>();
|
|
|
+ if (null != enUU) {
|
|
|
+ System.out.println("进入方法:" + System.currentTimeMillis());
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ // UAS企业UU
|
|
|
+// Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ StringBuffer cmpCodesSql = new StringBuffer();
|
|
|
+ cmpCodesSql.append("select 1 from v$products where pr_cmpcode = p1.pr_cmpcode and pr_enuu = ")
|
|
|
+ .append(enUU).append(" and nvl(pr_issale,0) <> 1 and pr_ispurchase = 1 and pr_b2bdisabled <> 1 ");
|
|
|
+// if (null != productMatchCondition) {
|
|
|
+// cmpCodesSql.append(" and ").append(productMatchCondition);
|
|
|
+// }
|
|
|
+ // 查找匹配在售物料的语句
|
|
|
+ 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_b2bdisabled <> 1 and ")
|
|
|
+ .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_b2bdisabled <> 1 and ")
|
|
|
+ .append(null != whereCondition ? whereCondition : "").append(" order by pr_code desc)");
|
|
|
+ // 物料id
|
|
|
+ StringBuffer idSql = new StringBuffer();
|
|
|
+ // 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)
|
|
|
+ .append(")").append(rownumSql);
|
|
|
+ List<Long> matchedIds = commonDao.queryForList(productsMatchSql.toString(), Long.class);
|
|
|
+ List<Long> ids = commonDao.queryForList(idSql.toString(), Long.class);
|
|
|
+// System.out.println("id:" + idSql);
|
|
|
+ for (Long id : ids) {
|
|
|
+ Product product = productDao.findOne(id);
|
|
|
+ if (matchedIds.contains(id)) {
|
|
|
+ StringBuffer matchCodeSql = new StringBuffer();
|
|
|
+ matchCodeSql.append("select wm_concat(pr_code) from v$products where pr_b2bdisabled <> 1 and pr_enuu = ")
|
|
|
+ .append(enUU).append(" and pr_cmpcode = '").append(product.getCmpCode()).append("'").append(" and rownum <= 5");
|
|
|
+ String matchCodes = commonDao.queryForObject(matchCodeSql.toString(), String.class);
|
|
|
+ product.setIfMatched(matchCodes);
|
|
|
+ }
|
|
|
+ products.add(product);
|
|
|
+ }
|
|
|
+ System.out.println("返回数据:" + (System.currentTimeMillis() - start));
|
|
|
+ } else {
|
|
|
+ String prodSql = "select a.* from (select t.*,rownum as r1 from (select pr_id id, pr_code code, pr_title title, pr_spec spec, pr_cmpcode cmpCode, pr_unit unit, pr_kind kind, " +
|
|
|
+ "pr_minpack minPack, pr_minOrder minOrder, pr_brand brand, pr_standard standard from v$products where pr_b2bdisabled <> 1 and pr_issale = 1 and pr_enuu = " + vendUU + " and " +
|
|
|
+ whereCondition + " order by pr_standard desc, pr_id desc) t where rownum <= " + page * size + ") a where r1 > " + (page - 1) * size;
|
|
|
+ System.out.println("无UU:" + prodSql);
|
|
|
+ products = commonDao.query(prodSql, Product.class);
|
|
|
+
|
|
|
}
|
|
|
- // 查找匹配在售物料的语句
|
|
|
- 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_b2bdisabled <> 1 and ")
|
|
|
- .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_b2bdisabled <> 1 and ")
|
|
|
- .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_b2bdisabled <> 1 and " + whereCondition;
|
|
|
- // 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)
|
|
|
- .append(")").append(rownumSql);
|
|
|
- List<Long> matchedIds = commonDao.queryForList(productsMatchSql.toString(), Long.class);
|
|
|
Integer count = commonDao.queryForObject(countSql, Integer.class);
|
|
|
- List<Long> ids = commonDao.queryForList(idSql.toString(), Long.class);
|
|
|
- System.out.println("count:" + countSql);
|
|
|
- System.out.println("id:" + idSql);
|
|
|
- List<Product> products = new ArrayList<>();
|
|
|
- for (Long id : ids) {
|
|
|
- Product product = productDao.findOne(id);
|
|
|
- if (matchedIds.contains(id)) {
|
|
|
- StringBuffer matchCodeSql = new StringBuffer();
|
|
|
- matchCodeSql.append("select wm_concat(pr_code) from v$products where pr_b2bdisabled <> 1 and pr_enuu = ")
|
|
|
- .append(enUU).append(" and pr_cmpcode = '").append(product.getCmpCode()).append("'").append(" and rownum <= 20");
|
|
|
- String matchCodes = commonDao.queryForObject(matchCodeSql.toString(), String.class);
|
|
|
- product.setIfMatched(matchCodes);
|
|
|
- }
|
|
|
- products.add(product);
|
|
|
- }
|
|
|
- System.out.println("返回数据:" + (System.currentTimeMillis() - start));
|
|
|
+// System.out.println("count:" + countSql);
|
|
|
return new com.uas.account.support.Page<>(page, size, products, count);
|
|
|
}
|
|
|
|