Procházet zdrojové kódy

保存到个人物料时,增加是否在物料库的判断。

yuj před 7 roky
rodič
revize
05e5623b42

+ 8 - 0
src/main/java/com/uas/ps/product/repository/ProductDao.java

@@ -279,4 +279,12 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     @Query("from Product p where p.id in :idSet")
     List<Product> findByIdList(@Param("idSet") List<Long> idSet);
+
+    /**
+     * 判断是否存在物料信息
+     * @param prids
+     * @return
+     */
+    @Query(value = "select p.id from Product p where p.id in (:prids)")
+    List<Long> findProductIdInProductUsers(@Param("prids") List<Long> prids);
 }

+ 6 - 7
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -1054,27 +1054,26 @@ public class ProductServiceImpl implements ProductService {
             return  map;
         }
         Long enuu = null;
-        for (Long id : productIds) {
+        List<Long> pids = productDao.findProductIdInProductUsers(productIds);
+        for (Long id : pids) {
             Product product = productDao.findOne(id);
             if (product != null) {
                 enuu = product.getEnUU();
                 break;
-            } else {
-                System.err.println(id + "----------------------------");
             }
         }
         //筛选已经存在个人物料库的信息
-        if (!CollectionUtils.isEmpty(productIds)) {
-            List<Long> productIdInProductPerson = productUsersDao.findProductIdInProductUsers(productIds, userUU);
+        if (!CollectionUtils.isEmpty(pids)) {
+            List<Long> productIdInProductPerson = productUsersDao.findProductIdInProductUsers(pids, userUU);
             for (Long productid : productIdInProductPerson) {
-                productIds.remove(productid);
+                pids.remove(productid);
             }
         }
 
         //转成需要保存的信息
         List<ProductUsers> list = new ArrayList<>();
         ProductUsers productUsers = null;
-        for (Long prId : productIds) {
+        for (Long prId : pids) {
             productUsers = new ProductUsers(enuu, userUU, prId);
             list.add(productUsers);
         }