Bladeren bron

调整批量上架的接口
增加根据物料id获取物料的信息

yujia 8 jaren geleden
bovenliggende
commit
9240c32964

+ 10 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ProductController.java

@@ -430,4 +430,14 @@ public class ProductController {
 	public List<Product> getProductsMatchCodeByKeyword(String keyword) {
 		return productService.getProductsMatchCodeByKeyword(keyword);
 	}
+
+	/**
+	 * 根据物料id获取物料信息
+	 * @param ids 物料id用逗号拼接
+	 * @return
+	 */
+	@RequestMapping(value = "/ids", method = RequestMethod.GET)
+	public  List<Product> getProductByIds(String ids) {
+		return productService.getProductByIds(ids);
+	}
 }

+ 10 - 12
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -704,21 +704,19 @@ public class ReleaseProductByBatch implements Serializable {
 	public void setReserveByExcel(Object value) {
 		setReserveStr(StringUtilB2C.getStr(value));
 		if (StringUtils.isEmpty(value) || !RegexConstant.isNumber(value.toString())) {
-			addErrmsg(ErrorInfoConstant.RESERVE_NUMBER_INFO.getInfo());
+			setReserve(DoubleConstant.zero);
 		} else {
 			Double reserve = Double.valueOf(value.toString());
 			if (reserve % 1 != 0) {
-				addErrmsg(ErrorInfoConstant.RESERVE_NUMBER_INFO.getInfo());
-			} else {
-				int compareTo = reserve.compareTo(DoubleConstant.maxReserve);
-				if (compareTo > 0) {
-					addErrmsg(ErrorInfoConstant.RESERVE_NUMBER_INFO.getInfo());
-				} else if (NumberUtil.compare(reserve, DoubleConstant.zero) < 1) {
-					addErrmsg(ErrorInfoConstant.RESERVE_NUMBER_INFO.getInfo());
-				} else {
-					setReserve(reserve);
-				}
+				reserve = Math.ceil(reserve);
+			}
+			int compareTo = reserve.compareTo(DoubleConstant.maxReserve);
+			if (compareTo > 0) {
+				reserve = DoubleConstant.maxReserve;
+			} else if (NumberUtil.compare(reserve, DoubleConstant.zero) < 1) {
+				reserve = DoubleConstant.minReserve;
 			}
+			setReserve(reserve);
 		}
 	}
 
@@ -1985,7 +1983,7 @@ public class ReleaseProductByBatch implements Serializable {
 	 */
 	public Boolean compareSameProductTagInfo(ReleaseProductByBatch batch) {
 		if (batch != null) {
-			return StringUtilB2C.equals(batch.getB2cBranden(), this.b2cBranden) && StringUtilB2C.equals(batch.getB2cCode(), this.b2cCode) && StringUtilB2C.equals(batch.getTag(), this.tag);
+			return StringUtilB2C.equals(batch.getB2cBranden(), this.b2cBranden) && StringUtilB2C.equals(batch.getB2cCode(), this.b2cCode);
 		} else {
 			return Boolean.FALSE;
 		}

+ 12 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java

@@ -8,6 +8,8 @@ import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
 import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 
 import java.util.List;
 import java.util.Map;
@@ -367,7 +369,7 @@ public interface ProductService {
      * @param newInOutboundDetail 出入库明细
      * @param inOutMap 出入库的map
      */
-    void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap);
+    void updateProductsByReleaseProductByBatch(Set<Long> prIds, List<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap);
 
 
     /**
@@ -383,4 +385,13 @@ public interface ProductService {
      * @return
      */
     List<Product> getProductsMatchCodeByKeyword(String keyword);
+
+
+
+    /**
+     * 根据物料id获取物料信息
+     * @param ids 物料拼接
+     * @return
+     */
+    List<Product> getProductByIds(String ids);
 }

+ 77 - 66
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -13,10 +13,7 @@ import com.uas.platform.b2c.common.base.dao.CommonDao;
 import com.uas.platform.b2c.common.search.rpc.service.SearchService;
 import com.uas.platform.b2c.common.search.util.SPage;
 import com.uas.platform.b2c.core.config.SysConf;
-import com.uas.platform.b2c.core.constant.IntegerConstant;
-import com.uas.platform.b2c.core.constant.ShortConstant;
-import com.uas.platform.b2c.core.constant.SplitChar;
-import com.uas.platform.b2c.core.constant.Status;
+import com.uas.platform.b2c.core.constant.*;
 import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.core.utils.NumberUtil;
@@ -2357,77 +2354,71 @@ public class ProductServiceImpl implements ProductService {
      * @param inOutMap 出入库的map
      */
     @Override
-    public void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap) {
-        if (CollectionUtils.isNotEmpty(reList)) {
-            Set<Long> prIds = new HashSet<>();
+    public void updateProductsByReleaseProductByBatch(Set<Long> prIds, List<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap) {
+        if (CollectionUtils.isEmpty(prIds) || CollectionUtils.isEmpty(reList)) {
+            return ;
+        }
+        List<Product> products = productDao.findAll(prIds);
+        List<Product> freshProducts = new ArrayList<>();
+        InOutboundDetail detail = null;
+        for (Product product : products) {
             for (ReleaseProductByBatch productByBatch : reList) {
-                if (productByBatch.getProductid() != null) {
-                    prIds.add(productByBatch.getProductid());
+                if (!productByBatch.getReleaseCode().equals(ReleaseStatus.failure.value()) &&
+                        !productByBatch.getReleaseCode().equals(ReleaseStatus.success.value())) {
+                    continue;
                 }
-            }
-            if (CollectionUtils.isNotEmpty(prIds)) {
-                List<Product> products = productDao.findAll(prIds);
-                List<Product> freshProducts = new ArrayList<>();
-                InOutboundDetail detail = null;
-                for (Product product : products) {
-                    for (ReleaseProductByBatch productByBatch : reList) {
-                        if ((productByBatch.getId() != null) &&(productByBatch.getId().longValue() == product.getId().longValue()) ) {
-                            // ignoreImport 1表示忽略导入,0代表覆盖导入
-                            if (StringUtils.isEmpty(product.getPackaging()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
-                                product.setPackaging(productByBatch.getPackaging());
-                            }
-                            if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
-                                product.setMinPackQty(productByBatch.getMinPackage());
-                            }
-                            if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
-                                product.setMinPackQty(productByBatch.getMinPackage());
-                            }
-                            if ((product.getKind() == null)  || (ignoreImport == IntegerConstant.NO_SHORT)) {
-                                product.setKind(productByBatch.getKindName());
-                                product.setKindid(productByBatch.getKindUuid());
-                            }
-                            if (StringUtils.isEmpty(product.getSpec()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
-                                product.setSpec(productByBatch.getSpec());
-                            }
-                            if ((ignoreImport == IntegerConstant.NO_SHORT) || (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) < 1)) {
-                                Double qty = productByBatch.getReserve();
-                                if (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) > 0) {
-                                    qty = NumberUtil.sub(qty, product.getErpReserve());
-                                }
-                                if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
-                                    //做出入库记录
-                                    product.setErpReserve(productByBatch.getReserve());
-                                    detail = new InOutboundDetail(product);
-                                    detail.setQty(qty);
-                                    detail.setPrice(productByBatch.getCostPrice());
-                                    newInOutboundDetail.add(detail);
-                                }
-                            }
-                            freshProducts.add(product);
-                        }
+                if ((productByBatch.getId() != null) &&(productByBatch.getId().longValue() == product.getId().longValue()) ) {
+                    // ignoreImport 1表示忽略导入,0代表覆盖导入
+                    if (StringUtils.isEmpty(product.getPackaging()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                        product.setPackaging(productByBatch.getPackaging());
                     }
-                }
-                productDao.save(freshProducts);
-                if (CollectionUtils.isNotEmpty(newInOutboundDetail)) {
-                    Set<InOutboundDetail> inBoundDetail = new HashSet<>();
-                    Set<InOutboundDetail> outBoundDetail = new HashSet<>();
-                    for (InOutboundDetail detail1 : newInOutboundDetail) {
-                        if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) < 0) {
-                            detail1.setQty(Math.abs(detail1.getQty()));
-                            outBoundDetail.add(detail1);
-                        } else if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) > 0) {
-                            inBoundDetail.add(detail1);
-                        }
+                    if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                        product.setMinPackQty(productByBatch.getMinPackage());
+                    }
+                    if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                        product.setMinPackQty(productByBatch.getMinPackage());
+                    }
+                    if ((product.getKind() == null)  || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                        product.setKind(productByBatch.getKindName());
+                        product.setKindid(productByBatch.getKindUuid());
                     }
-                    if (CollectionUtils.isNotEmpty(inBoundDetail)) {
-                        inOutMap.put(InOutBoundType.OTHER_INBOUND, inBoundDetail);
+                    if (StringUtils.isEmpty(product.getSpec()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                        product.setSpec(productByBatch.getSpec());
                     }
-                    if (CollectionUtils.isNotEmpty(outBoundDetail)) {
-                        inOutMap.put(InOutBoundType.OTHER_OUTBOUND, outBoundDetail);
+                    if ((ignoreImport == IntegerConstant.NO_SHORT) || (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) != 0)) {
+                        Double qty = NumberUtil.sub(productByBatch.getReserve(), product.getErpReserve());
+                        if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
+                            //做出入库记录
+                            product.setErpReserve(productByBatch.getReserve());
+                            detail = new InOutboundDetail(product);
+                            detail.setQty(qty);
+                            detail.setPrice(productByBatch.getCostPrice());
+                            newInOutboundDetail.add(detail);
+                        }
                     }
+                    freshProducts.add(product);
                 }
             }
         }
+        productDao.save(freshProducts);
+        if (CollectionUtils.isNotEmpty(newInOutboundDetail)) {
+            Set<InOutboundDetail> inBoundDetail = new HashSet<>();
+            Set<InOutboundDetail> outBoundDetail = new HashSet<>();
+            for (InOutboundDetail detail1 : newInOutboundDetail) {
+                if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) < 0) {
+                    detail1.setQty(Math.abs(detail1.getQty()));
+                    outBoundDetail.add(detail1);
+                } else if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) > 0) {
+                    inBoundDetail.add(detail1);
+                }
+            }
+            if (CollectionUtils.isNotEmpty(inBoundDetail)) {
+                inOutMap.put(InOutBoundType.OTHER_INBOUND, inBoundDetail);
+            }
+            if (CollectionUtils.isNotEmpty(outBoundDetail)) {
+                inOutMap.put(InOutBoundType.OTHER_OUTBOUND, outBoundDetail);
+            }
+        }
     }
 
 
@@ -2542,5 +2533,25 @@ public class ProductServiceImpl implements ProductService {
         }
         return new ArrayList<>();
     }
+
+    /**
+     * 根据物料id获取物料信息
+     *
+     * @param ids 物料拼接
+     * @return
+     */
+    @Override
+    public List<Product> getProductByIds(String ids) {
+        if (StringUtils.isEmpty(ids)) {
+            return new ArrayList<>();
+        } else {
+            String[] splits = ids.split(SplitChar.COMMA);
+            List<Long> idList = new ArrayList<>();
+            for (String id : splits) {
+                idList.add(Long.valueOf(id));
+            }
+            return productDao.findAll(idList);
+        }
+    }
 }
 

+ 8 - 22
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -257,8 +257,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 						releaseProductByBatch.setReleaseCode(ReleaseStatus.lack_info.value());
 						releaseProductByBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
 					}
-					// 简单验证数据,防止空行保存的情况(品牌、类目、型号、库存量)
-					if (blankNum != 4) {
+					// 简单验证数据,防止空行保存的情况(品牌、类目、型号)
+					if (blankNum != 3) {
 						total++;
 						releaseProductByBatchs.add(releaseProductByBatch);
 					}
@@ -270,7 +270,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			//1:比较品牌、型号、是否重复,一个EXCEL中只能有一条物料信息
 			for(int i = releaseProductByBatchs.size() - 1; i > -1; i--) {
 				ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
-				for(int j = i - 1; j > -1; j--) {
+				for (int j = i - 1; j > -1; j--) {
 					ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
 					if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
 						releaseProductByBatch.setTag("");
@@ -340,9 +340,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (!isAPerson) {
 			String publish = publishByBatch(batch, isPcb, ignoreImport);
 			modelMap.put("publish", publish);
-		} else {
-
-        }
+		}
 		modelMap.put("total", total);
 		modelMap.put("success", success);
 		modelMap.put("failure", failure);
@@ -1125,9 +1123,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 
 			Object reserveValue = readWorkBookCell(row.getCell(UploadConstant.RESERVE_NUMBER), Cell.CELL_TYPE_STRING,
 					rowNum, UploadConstant.RESERVE_NUMBER);
-			if (StringUtils.isEmpty(reserveValue)) {
-				result += 1;
-			}
 			aProduct.setReserveByExcel(reserveValue);
 
 			Object costPrice = readWorkBookCell(row.getCell(UploadConstant.COST_PRICE), Cell.CELL_TYPE_STRING,
@@ -1173,8 +1168,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					rowNum, UploadConstant.BUY_MIN_QTY);
 			aProduct.setMinBuyQtyByExcel(buyQtyValue);
 
-//			Object tagValue = readWorkBookCell(row.getCell(UploadConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
-//					rowNum, UploadConstant.CUSTOM_LABEL);
 			aProduct.setTagByExcel("");
 //			// 自定义标签不为null,则检查是否重复
 //			if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
@@ -1743,6 +1736,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (isPcb) {
 			savePcbInfo(idSet, map);
 		}
+		//添加个人关系
+		String res  = restTemplate.postForEntity(productServiceIp + "/product/assign/batch?userUU=" + SystemSession.getUser().getUserUU(), idSet, String.class).getBody();
 		Integer num = releaseToGoods(releaseProductByBatchList, ignoreImport, idSet);
 		String updateReleaseSql = "/*#mycat:db_type=master*/ update trade$releasebybatch set rel_releasecode = 101,rel_releasestatus = '已发布' where (rel_releasecode = 112 OR rel_releasecode = 113) and rel_batchid = '%s';";
 		final String updateRelease = String.format(updateReleaseSql, new Object[]{batch});
@@ -1898,6 +1893,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		List<ReleaseProductByBatch> productsfromRelease = new ArrayList<>();
 		List<ProductPrivate> productPrivates = new ArrayList<>();
 		Set<Long> prIds = new HashSet<>();
+		//需要更新的规格、最小包数量、包装方式
 		Set<ReleaseProductByBatch> updateProducts = new HashSet<>();
 		Map<String, List<PCBPropertyValue>> propertyMap = new HashedMap();
 
@@ -1920,16 +1916,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				} else {
 					//对于已经存在于物料库的信息,如果规格信息已存在,则做更新
 					prIds.add(releaseProductByBatch.getProductid());
-                    if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getSpec()) || (releaseProductByBatch.getMinPackage() != null) || org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getPackaging()) || (releaseProductByBatch.getCostPrice() != null)) {
-						updateProducts.add(releaseProductByBatch);
-					} else {
-                        if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getKindName())) {
-                            //如果是非标,则可以填充,或者覆盖
-                            if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getComponentUuId())) {
-								updateProducts.add(releaseProductByBatch);
-                            }
-                        }
-                    }
 				}
 
 				if (isPcb) {
@@ -1975,7 +1961,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		//将本次临时表中的数据更新到物料表中
         if (CollectionUtils.isNotEmpty(updateProducts)) {
 			Map<String, Set<InOutboundDetail>> inOutMap = new HashedMap();
-            productService.updateProductsByReleaseProductByBatch(updateProducts, ignoreImport, newInOutboundDetail, inOutMap);
+            productService.updateProductsByReleaseProductByBatch(prIds, releaseProductByBatchList, ignoreImport, newInOutboundDetail, inOutMap);
 			Set<String> stringSet = inOutMap.keySet();
 			for (String type : stringSet) {
 				CommodityInOutbound commodityInOutbound = commodityInOutboundService.produceCommodityInOutbound(inOutMap.get(type), type);