Browse Source

供应商资源库过滤sql优化,速度提升;复制物料时,清空sourceid,并修改物料useruu为对应业务员useruu

dongbw 8 years ago
parent
commit
2f897b7a1b

+ 1 - 1
src/main/java/com/uas/platform/b2b/dao/ProductTempDao.java

@@ -56,7 +56,7 @@ public class ProductTempDao {
 
     public void matchExists(String importId) {
         jdbcTemplate.update("Merge Into (Select * From Products_Temp Where Pr_Import_Id=? And Pr_Exist_Id Is Null) T " +
-                "Using Products P On ((T.pr_code = P.pr_code Or (T.Pr_Title=P.Pr_Title And T.Pr_Cmpcode=P.Pr_Cmpcode And T.Pr_Brand=P.Pr_Brand And T.Pr_Spec=P.Pr_Spec And (P.pr_standard <> 1 or P.pr_standard is null)) " +
+                "Using Products P On ((T.pr_code = P.pr_code Or (T.Pr_Title=P.Pr_Title And T.Pr_Cmpcode=P.Pr_Cmpcode And T.Pr_Brand=P.Pr_Brand And T.Pr_Spec=P.Pr_Spec And nvl(P.pr_standard, 0) <> 1) " +
                 "Or (T.Pr_Title=P.Pr_Kind And T.Pr_Cmpcode=P.Pr_Pcmpcode And T.Pr_Brand=P.Pr_Pbrand  And P.pr_standard = 1)) " +
                 "and t.pr_enuu=p.pr_enuu) when matched then update set t.pr_exist_id=p.pr_id", importId);
     }

+ 2 - 0
src/main/java/com/uas/platform/b2b/service/impl/ProductUsersServiceImpl.java

@@ -480,6 +480,8 @@ public class ProductUsersServiceImpl implements ProductUsersService {
                         List<Product> products = productDao.findByEnUUAndCode(enuu, product.getCode());
                         if (CollectionUtils.isEmpty(products)) {
                             newProduct.setId(null);
+                            newProduct.setSourceId(null);
+                            newProduct.setUserUU(useruu);
                             newProduct.setEnUU(enuu);
                             prId = ProductUtils.updateOne(newProduct);
                         } else {

+ 34 - 28
src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -335,7 +336,10 @@ public class VendorsServiceImpl implements VendorService {
 		// 查找非供应商的卖当前商品的企业UU
 		StringBuffer vendorRecommendUusSql = new StringBuffer();
 //		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 " +
+		vendorRecommendUusSql.append("select en_uu,hitNums,(select wm_concat(pr_title || '(' || pr_brand || ')') from v$products where pr_enuu=en_uu 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(enUU).append(") isVendor 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);
@@ -356,7 +360,6 @@ public class VendorsServiceImpl implements VendorService {
                 .append(enUUSql).append(")");
 		if (null != enterpriseMatchCondition && !"".equals(enterpriseMatchCondition)) {
 			enterpriseProdSaleSql.append(" and ").append(enterpriseMatchCondition);
-//			vendorRecommendUuNumSql.append(" and ").append(enterpriseMatchCondition);
 		}
 		enterpriseProdSaleSql.append(" group by en_uu order by count(pr_issale) desc) b");
 		vendorRecommendUusSql.append(" union all ").append(enterpriseProdSaleSql);
@@ -434,32 +437,32 @@ public class VendorsServiceImpl implements VendorService {
             Enterprise enterprise = enterPriseDao.findOne(vendorRecommend.getEn_uu());
 		    if (null != enterprise) {
                 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 (select pr_title,pr_brand 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(") order by pr_standard desc,pr_id desc) where rownum <= 5");
-					System.out.println("wm_concat:" + productInfosSql.toString());
-//                    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.replace("()", ""));
-//                    vendorRecommend.setHitNums(hitNums);
-                }
-                List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU, vendUU);
-                if (!CollectionUtils.isEmpty(vendors)) {
-                    vendorRecommend.setIsVendor(Constant.YES);
-                } else {
-                    vendorRecommend.setIsVendor(Constant.NO);
-                }
+//                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 (select pr_title,pr_brand 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(") order by pr_standard desc,pr_id desc) where rownum <= 5");
+//					System.out.println(productInfosSql.toString() + ";");
+////                    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.replace("()", ""));
+////                    vendorRecommend.setHitNums(hitNums);
+//                }
+//                List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(enUU, vendUU);
+//                if (!CollectionUtils.isEmpty(vendors)) {
+//                    vendorRecommend.setIsVendor(Constant.YES);
+//                } else {
+//                    vendorRecommend.setIsVendor(Constant.NO);
+//                }
                 content.add(vendorRecommend);
 //                System.out.println("处理完一条数据:" + (System.currentTimeMillis() - start1));
             }
@@ -488,6 +491,9 @@ public class VendorsServiceImpl implements VendorService {
 		vendorRecommend.setEn_tags(enterprise.getTags());
 		vendorRecommend.setEn_tel(enterprise.getEnTel());
 		vendorRecommend.setEn_uu(enterprise.getUu());
+		if (!StringUtils.isEmpty(vendorRecommend.getProductInfo())) {
+			vendorRecommend.setProductInfo(vendorRecommend.getProductInfo().replace("()", " "));
+		}
 		return vendorRecommend;
 	}