Procházet zdrojové kódy

供应商推荐接口优化sql语句;个人物料批量导入重复插入问题处理

dongbw před 8 roky
rodič
revize
31f69f18b4

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

@@ -161,6 +161,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
         ModelMap modelMap = new ModelMap();
         List<ProductUsers> productUsers = new ArrayList<ProductUsers>();
         List<String> alters = new ArrayList<String>();
+        List<String> existedProducts = new ArrayList<>();
         Long enuu = SystemSession.getUser().getEnterprise().getUu();
         Long useruu = SystemSession.getUser().getUserUU();
         Sheet sheet = workbook.getSheetAt(0);
@@ -255,8 +256,11 @@ public class ProductUsersServiceImpl implements ProductUsersService {
                     List<ProductUsers> existProds = productUsersDao.findByEnuuAndUseruuAndTitleAndCmpCodeAndBrand
                             (enuu, useruu, product.getTitle(), product.getCmpCode(), product.getBrand());
                     if(CollectionUtils.isEmpty(existProds)) {
-                        List<Product> prods = productDao.findByTitleAndCmpCodeAndBrandAndEnUU(
-                                product.getTitle(), product.getCmpCode(), product.getBrand(), enuu);
+                        List<Product> prods = productDao.findByEnUUAndCode(product.getEnUU(), product.getCode());
+                        if (CollectionUtils.isEmpty(prods)) {
+                            prods = productDao.findByTitleAndCmpCodeAndBrandAndEnUU(
+                                    product.getTitle(), product.getCmpCode(), product.getBrand(), enuu);
+                        }
                         if(CollectionUtils.isEmpty(prods)) {// 如果非标不存在再查询标准
                             prods = productDao.findByTitleAndPcmpcodeAndPbrandAndEnUU(product.getTitle(), product.getCmpCode(), product.getBrand(), SystemSession.getUser().getEnterprise().getUu());
                         }
@@ -285,7 +289,18 @@ public class ProductUsersServiceImpl implements ProductUsersService {
                             prod.setPrid(proId);
                             prod.setUseruu(useruu);
                         } else {
+                            // 已存在,直接更新
                             Product oldProd = prods.get(0);
+                            oldProd.setCode(product.getCode());
+                            oldProd.setCmpCode(product.getCmpCode());
+                            oldProd.setBrand(product.getBrand());
+                            oldProd.setTitle(product.getTitle());
+                            oldProd.setUnit(product.getUnit());
+                            oldProd.setMinOrder(product.getMinOrder());
+                            oldProd.setMinPack(product.getMinPack());
+                            oldProd.setLeadtime(product.getLeadtime());
+                            oldProd.setLtinstock(product.getLtinstock());
+                            ProductUtils.updateOne(oldProd);
                             prod.setDate(new Date());
                             prod.setEnuu(enuu);
                             prod.setPrid(oldProd.getId());
@@ -297,6 +312,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
                                 status.setB2bDisabled(Constant.NO);
                                 productStatusDao.save(status);
                             }
+                            existedProducts.add(prods.get(0).getCode());
                         }
                         productUsers.add(prod);
                     } else {
@@ -312,11 +328,17 @@ public class ProductUsersServiceImpl implements ProductUsersService {
                     modelMap.put("success", productUsers.size());
                     if(alters.size() > 0)
                     	modelMap.put("alters", alters);
+                    if (existedProducts.size() > 0) {
+                        modelMap.put("existed", existedProducts);
+                    }
                 } catch (Exception e) {
                     modelMap.put("error", "物料添加失败");
                 }
             } else {
                 modelMap.put("success", 0);
+                if (existedProducts.size() > 0) {
+                    modelMap.put("existed", existedProducts);
+                }
 	            if(alters.size() > 0)
 		            modelMap.put("alters", alters);
             }

+ 22 - 10
src/main/java/com/uas/platform/b2b/service/impl/VendorsServiceImpl.java

@@ -346,11 +346,13 @@ public class VendorsServiceImpl implements VendorService {
 	 */
 	@Override
 	public com.uas.account.support.Page<VendorRecommend> getVendorRecommend(String productMatchCondition, String enterpriseMatchCondition, String productCondition, int page, int size) {
+		System.out.println("进入方法:" + System.currentTimeMillis());
 		final Long enUU = SystemSession.getUser().getEnterprise().getUu();
 		String cmpCodesSql = concatProductCondition(enUU, productMatchCondition, productCondition);
+		System.out.println("查找物料语句拼接完成:" + System.currentTimeMillis());
 //		// 根据标准料号找出对应的供应商UU
 //		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 + ")";
+//				" where ve_myenuu = " + enUU + " and pr_issale = 1 and pr_cmpcode in (" + cmpCodesSql + ")";
 		// 采购物料原厂型号
 		System.out.println(cmpCodesSql);
 //		final List<String> cmpCodes = commonDao.queryForList(cmpCodesSql.toString(), String.class);
@@ -386,8 +388,10 @@ public class VendorsServiceImpl implements VendorService {
 		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("所有语句拼接完成:" + System.currentTimeMillis());
 		Integer total = commonDao.queryForObject(totalSql.toString(), Integer.class);
 		List<Long> vendUUs = commonDao.queryForList(vendorRecommendUusSql.toString(), Long.class);
+		System.out.println("查找出所有推荐企业UU:" + System.currentTimeMillis());
 		return getVendorRecommendByVendUUs(enUU, vendUUs, page, size, total);
 	}
 
@@ -445,7 +449,10 @@ public class VendorsServiceImpl implements VendorService {
 	 */
 	private com.uas.account.support.Page<VendorRecommend> getVendorRecommendByVendUUs(Long enUU, List<Long> vendUUs, int page, int size, Integer total) {
 		List<VendorRecommend> content = new ArrayList<>();
+		int i = 0;
 		for (final Long vendUU : vendUUs) {
+			i = i+ 1;
+			System.out.println("开始处理第" + i + "条数据:" + System.currentTimeMillis());
 			Enterprise vendor = enterPriseDao.findOne(vendUU);
 			if (null != vendor) {
 //				if (null != vendor.getEnAdminuu()) {
@@ -455,17 +462,21 @@ public class VendorsServiceImpl implements VendorService {
 				StringBuffer productIdsSql = new StringBuffer();
 				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 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");
+						.append(" and pr.pr_issale =1 and pr.pr_cmpcode in (select pr_cmpcode from v$products p1 " +
+								" where p1.pr_ispurchase = 1 and (p1.pr_issale is null or p1.pr_issale = 0) " +
+								" 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_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 is null or p1.pr_issale = 0) " +
-								"and p1.pr_standard = 1 and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
+						.append(" and pr.pr_issale =1 and pr.pr_cmpcode in (select pr_cmpcode from v$products p1 " +
+								" where p1.pr_ispurchase = 1 and (p1.pr_issale is null or p1.pr_issale = 0) " +
+								" and p1.pr_b2bdisabled <> 1 and p1.pr_enuu = ")
 						.append(enUU).append(")");
+				System.out.println("第" + i + "条数据物料查找语句拼接完成:" + System.currentTimeMillis());
+				System.out.println(productIdsSql.toString());
+				System.out.println(productNumSql.toString());
 				List<Long> prodIds = commonDao.queryForList(productIdsSql.toString(), Long.class);
 				Integer hitNums = commonDao.queryForObject(productNumSql.toString(), Integer.class);
+				System.out.println("第" + i + "条数据匹配物料id及数量查找完成:" + System.currentTimeMillis());
 				// 获取前五条匹配物料
 				List<Product> hitsProducts = productDao.findAll(prodIds);
 				VendorRecommend vendorRecommend = new VendorRecommend();
@@ -478,6 +489,7 @@ public class VendorsServiceImpl implements VendorService {
 				} else {
 					vendorRecommend.setIsVendor(Constant.NO);
 				}
+				System.out.println("第" + i + "条数据处理完毕,添加到content:" + System.currentTimeMillis());
 				content.add(vendorRecommend);
 			}
 		}
@@ -510,12 +522,12 @@ 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(") 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_standard = 1 and p1.pr_b2bdisabled <> 1 and ")
+				.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();

+ 4 - 1
src/main/webapp/resources/tpl/index/approvalFlow/modal/uplodaByBatch.html

@@ -61,8 +61,11 @@
 		<p ng-if="result.total">
 			<span>总共上传{{result.total}}个,成功{{result.success}}个</span>
 		</p>
+		<p ng-if="result.existed.length > 0">
+			产品<span class="text-inverse" ng-repeat="existed in result.existed">"{{existed}}", </span>已存在,已更新
+		</p>
         <p ng-if="result.alters.length > 0">
-            产品<span class="text-inverse" ng-repeat="alert in result.alters">"{{alert}}", </span>已存在,上传失败
+            个人产品<span class="text-inverse" ng-repeat="alert in result.alters">"{{alert}}", </span>已存在,上传失败
         </p>
 	</div>
 </div>