Explorar o código

调整批量修改在售产品的逻辑

yujia %!s(int64=7) %!d(string=hai) anos
pai
achega
eb9752895a

+ 5 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/ModifyConstant.java

@@ -125,6 +125,11 @@ public class ModifyConstant {
      */
     public static final int RESERVE_NUMBER = 17;
 
+    /**
+     * 成本单价
+     */
+    public static final int COST_PRICE = 18;
+
     /**
      * The constant CUSTOM_LABEL.
      */

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsDao.java

@@ -43,6 +43,14 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      */
     Goods findByBatchCode(String batchCode);
 
+    /**
+     * 批量获取在售产品信息
+     * @param batchCodes
+     * @return
+     */
+    @Query(value = "select g from Goods g.batchCode in (:batchCodes)")
+    List<Goods> findByBatchCodes(@Param("batchCodes") List<String> batchCodes);
+
     /**
      * 根据UUID和状态查找对应的货物信息
      *

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

@@ -593,21 +593,18 @@ public class ReleaseProductByBatch implements Serializable {
 		ReleaseProductByBatch that = (ReleaseProductByBatch) o;
 
 		if (!brandNameEn.equals(that.brandNameEn)) return false;
-		if (!code.equals(that.code)) return false;
-		if (!minBuyQtyStr.equals(that.minBuyQtyStr)) return false;
-		if (!productDate.equals(that.productDate)) return false;
-		if (!minPackageStr.equals(that.minPackageStr)) return false;
-		if (!packaging.equals(that.packaging)) return false;
-		if (!selfMaxDeliveryStr.equals(that.selfMaxDeliveryStr)) return false;
+//		if (!code.equals(that.code)) return false;
+//		if (!minBuyQtyStr.equals(that.minBuyQtyStr)) return false;
+//		if (!productDate.equals(that.productDate)) return false;
+//		if (!minPackageStr.equals(that.minPackageStr)) return false;
+//		if (!packaging.equals(that.packaging)) return false;
+//		if (!selfMaxDeliveryStr.equals(that.selfMaxDeliveryStr)) return false;
 //		if (!selfMinDeliveryStr.equals(that.selfMinDeliveryStr)) return false;
 //		return GoodsUtil.compareWithQtyPrice(prices, that.getPrices(), that.getCurrency());
-		return selfMinDeliveryStr.equals(that.selfMinDeliveryStr);
+		return code.equals(that.code);
 	}
 
 	public void setBatchCodeByExcel(Object value) {
-		if (StringUtils.isEmpty(value)) {
-			addErrmsg(ErrorInfoConstant.BATCH_EMPTY.getInfo());
-		}
 		setBatchCode(StringUtilB2C.getStr(value).trim());
 	}
 

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java

@@ -65,6 +65,13 @@ public interface GoodsService {
      */
     Goods findGoodsByBatchCode(String code);
 
+    /**
+     * 在售产品批次号
+     * @param batchCodes 批次号
+     * @return List<Goods>
+     */
+    List<Goods> findGoodsByBatchCodes(List<String> batchCodes);
+
     /**
      * 根据uuid查找简单货物信息
      *

+ 43 - 48
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -1,7 +1,5 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
-import static com.uas.platform.core.persistence.criteria.PredicateUtils.like;
-
 import com.alibaba.fastjson.JSONObject;
 import com.uas.api.b2c_erp.core.model.OperateErrorStatus;
 import com.uas.api.b2c_erp.seller.model.GoodsFUas;
@@ -20,24 +18,13 @@ 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.support.SystemSession;
-import com.uas.platform.b2c.core.utils.DoubleArith;
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
-import com.uas.platform.b2c.core.utils.NumberUtil;
-import com.uas.platform.b2c.core.utils.RegexConstant;
-import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.core.utils.*;
 import com.uas.platform.b2c.external.erp.commodity.util.ModelConverter;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.commodity.constant.IntegerConstant;
 import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
 import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsHistoryDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsModifyInfoDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsSimpleDao;
-import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDetailDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
+import com.uas.platform.b2c.prod.commodity.dao.*;
 import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.model.GoodsHistory.OperateType;
 import com.uas.platform.b2c.prod.commodity.service.*;
@@ -79,11 +66,7 @@ import com.uas.platform.b2c.trade.support.CodeType;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.b2c.trade.util.BoundedExecutor;
 import com.uas.platform.core.exception.IllegalOperatorException;
-import com.uas.platform.core.model.Constant;
-import com.uas.platform.core.model.EncodingRulesConstant;
-import com.uas.platform.core.model.PageInfo;
-import com.uas.platform.core.model.PageParams;
-import com.uas.platform.core.model.Type;
+import com.uas.platform.core.model.*;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
@@ -91,33 +74,6 @@ import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.platform.core.persistence.criteria.SimpleExpression;
 import com.uas.platform.core.util.StringUtil;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
-import java.math.BigInteger;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
@@ -142,6 +98,26 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.StringUtils;
 
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigInteger;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static com.uas.platform.core.persistence.criteria.PredicateUtils.like;
+
 
 /**
  * @author ChenHao
@@ -400,7 +376,26 @@ public class GoodsServiceImpl implements GoodsService {
 
     @Override
     public Goods findGoodsByBatchCode(String code) {
-        return goodsDao.findByBatchCode(code);
+        if (StringUtils.isEmpty(code)) {
+            return null;
+        } else {
+            return goodsDao.findByBatchCode(code);
+        }
+    }
+
+    /**
+     * 在售产品批次号
+     *
+     * @param batchCodes 批次号
+     * @return List<Goods>
+     */
+    @Override
+    public List<Goods> findGoodsByBatchCodes(List<String> batchCodes) {
+        if (CollectionUtils.isEmpty(batchCodes)) {
+            return new ArrayList<>();
+        } else {
+            return goodsDao.findByBatchCodes(batchCodes);
+        }
     }
 
     @Override

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

@@ -425,9 +425,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			Object skuObj = readWorkBookCell(row.getCell(ModifyConstant.SKU_CODE), Cell.CELL_TYPE_STRING,
 					r, ModifyConstant.SKU_CODE);
 			aBatch.setBatchCodeByExcel(skuObj);
-			if (!validateBatchCode(aBatch.getBatchCode(), aBatch)) {
-				aBatch.addErrmsg(ErrorInfoConstant.BATCH_ERROR.getInfo());
-			}
 
 			Object sellObj = readWorkBookCell(row.getCell(ModifyConstant.SALE_METHOD), Cell.CELL_TYPE_STRING,
 					r, ModifyConstant.SALE_METHOD);
@@ -454,21 +451,21 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
 			} else {
 				// 导入成功的需要判断自定义标签是否重复
-				if (CollectionUtils.isNotEmpty(batchList) && aBatch.getTag() != null) {
-					if (validateTagInfo(aBatch, batchList)) {
-						aBatch.setTag(null);
-					}
-				}
+//				if (CollectionUtils.isNotEmpty(batchList) && aBatch.getTag() != null) {
+//					if (validateTagInfo(aBatch, batchList)) {
+//						aBatch.setTag(null);
+//					}
+//				}
 				validateRepeatInExcel(batchList, aBatch, true);
 			}
 			batchList.add(aBatch);
 			total++;
 		}
+		int success = goodsFillDataToExcel(batchList);
 		Long userUU = SystemSession.getUser().getUserUU();
-		Long enUU = SystemSession.getUser().getEnterprise().getUu();
-		resetRepeatData(batchList, true, false);
-		setDefaultTag(batchList);
-		int success = modifyGoodsByBatch(batchList);
+//		Long enUU = SystemSession.getUser().getEnterprise().getUu();
+//		resetRepeatData(batchList, true, false);
+//		setDefaultTag(batchList);
 		commonDao.save(batchList, ReleaseProductByBatch.class);
 		Integer filter = releaseProductByBatchDao.getCountOfImportFail(userUU, batch, failCode);
 		modelMap.put("total", total);
@@ -479,6 +476,67 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return modelMap;
 	}
 
+	/**
+	 * 根据批次号设置需要被修改的信息
+	 * @param batchList
+	 */
+	private Integer goodsFillDataToExcel(List<ReleaseProductByBatch> batchList) {
+		int result = 0;
+		if (CollectionUtils.isEmpty(batchList)) {
+			return result;
+		}
+		List<String> batchCodes = new ArrayList<>();
+		for (ReleaseProductByBatch aBatch : batchList) {
+			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode())) {
+				batchCodes.add(aBatch.getBatchCode());
+			}
+		}
+
+		List<Goods> goodses = new ArrayList<>();
+		if (CollectionUtils.isNotEmpty(batchCodes)) {
+			goodses = goodsService.findGoodsByBatchCodes(batchCodes);
+		}
+		for (Goods goods : goodses) {
+			for (ReleaseProductByBatch aBatch : batchList) {
+				if (goods.getBatchCode().equals(aBatch.getBatchCode())) {
+					aBatch.setB2cBranden(goods.getBrandNameEn());
+					aBatch.setBrandNameEn(goods.getBrandNameEn());
+					aBatch.setKindName(goods.getKindNameCn());
+					aBatch.setB2cCode(goods.getCode());
+					aBatch.setCode(goods.getCode());
+					aBatch.setCurrency(goods.getCurrencyName());
+					if (goods.getUuid() == null) {
+						aBatch.setReleaseCode(ReleaseStatus.failure.value());
+						aBatch.setReleaseStatus(ReleaseStatus.failure.getPhrase());
+					}
+					fillInGoods(goods, aBatch);
+					ResultMap resultMap = goodsService.updateGoods(goods);
+					if (resultMap.isSuccess()) {
+						Goods goods1 = (Goods) resultMap.getData();
+						if (Status.REMOVED.value() == aBatch.getStatus() && Status.REMOVED.value() != goods1.getStatus()) {
+							ResultMap offMap = goodsService.offShelfGoodsByProvider(goods.getBatchCode(), null, false);
+							if (offMap.isSuccess()) {
+								result++;
+							} else {
+								aBatch.setErrmsg(offMap.getMessage());
+								aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
+								aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+							}
+						} else {
+							result++;
+						}
+					} else {
+						aBatch.setErrmsg(resultMap.getMessage());
+						aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
+						aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+					}
+				}
+			}
+		}
+
+		return result;
+	}
+
 	/**
 	 * 给自定义标签为空的batch设置默认自定义标签
 	 * @param batchList
@@ -531,27 +589,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				continue;
 			}
 			Goods goods = goodsDao.findByBatchCode(aBatch.getBatchCode());
-			fillInGoods(goods, aBatch);
-			ResultMap resultMap = goodsService.updateGoods(goods);
-			if (resultMap.isSuccess()) {
-				Goods goods1 = (Goods) resultMap.getData();
-				if (Status.REMOVED.value() == aBatch.getStatus() && Status.REMOVED.value() != goods1.getStatus()) {
-					ResultMap offMap = goodsService.offShelfGoodsByProvider(goods.getBatchCode(), null, false);
-					if (offMap.isSuccess()) {
-						result++;
-					} else {
-						aBatch.setErrmsg(offMap.getMessage());
-						aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
-						aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
-					}
-				} else {
-					result++;
-				}
-			} else {
-				aBatch.setErrmsg(resultMap.getMessage());
-				aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
-				aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
-			}
+
 		}
 		return result;
 	}
@@ -677,10 +715,10 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
             aProduct.setReserveByExcel(reserveValue);
         }
 
-		Object statusValue = readWorkBookCell(row.getCell(ModifyConstant.SALE_STATUS), Cell.CELL_TYPE_STRING,
-				rowNum, ModifyConstant.SALE_STATUS);
+		Object statusValue = readWorkBookCell(row.getCell(ModifyConstant.COST_PRICE), Cell.CELL_TYPE_STRING,
+				rowNum, ModifyConstant.COST_PRICE);
         if (!StringUtils.isEmpty(statusValue)) {
-            aProduct.setStatusByExcel(statusValue);
+            aProduct.setCostPriceByExcel(statusValue);
         }
 
 //		Object tagValue = readWorkBookCell(row.getCell(ModifyConstant.CUSTOM_LABEL), Cell.CELL_TYPE_STRING,
@@ -694,37 +732,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 //		}
 	}
 
-	/**
-	 * 验证批次号是否正确,并为该公司下的goods
-	 * @param batchCode
-	 * @param aBatch
-	 * @return
-	 */
-	private boolean validateBatchCode(String batchCode, ReleaseProductByBatch aBatch) {
-		if (StringUtils.isEmpty(batchCode)) {
-			return false;
-		}
-		Goods goods = goodsDao.findByBatchCode(batchCode);
-		if (goods == null) {
-			return false;
-		}
-		aBatch.setB2cBranden(goods.getBrandNameEn());
-		aBatch.setBrandNameEn(goods.getBrandNameEn());
-		aBatch.setKindName(goods.getKindNameCn());
-		aBatch.setB2cCode(goods.getCode());
-		aBatch.setCode(goods.getCode());
-		aBatch.setCurrency(goods.getCurrencyName());
-		if (goods.getUuid() == null) {
-			aBatch.setReleaseCode(ReleaseStatus.failure.value());
-			aBatch.setReleaseStatus(ReleaseStatus.failure.getPhrase());
-		}
-		Long enuu = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
-		if (goods.getEnUU() != null) {
-			return goods.getEnUU().equals(enuu);
-		}
-		return goods.getEnUU() == null && enuu == null;
-	}
-
 	private void validateModifyExcel(Row headerRow) {
 		Object skuCellObj = readWorkBookCell(headerRow.getCell(ModifyConstant.SKU_CODE), Cell.CELL_TYPE_STRING,
 				1, ModifyConstant.SKU_CODE);
@@ -746,19 +753,22 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			return ;
 		for (ReleaseProductByBatch each : batchList) {
 			if (StringUtils.isEmpty(each.getErrmsg()) && each.equals(aBatch)) {
-				if (!isImport) {
-					aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-					aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-					aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-					break;
-				} else {
-					if (GoodsUtil.compareWithQtyPrice(each.getPrices(), aBatch.getPrices(), each.getCurrency())) {
-						aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
-						aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
-						aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
-						break;
-					}
-				}
+				aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+				aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+				aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+//				if (!isImport) {
+//					aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+//					aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+//					aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+//					break;
+//				} else {
+//					if (GoodsUtil.compareWithQtyPrice(each.getPrices(), aBatch.getPrices(), each.getCurrency())) {
+//						aBatch.setErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+//						aBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+//						aBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+//						break;
+//					}
+//				}
 			}
 		}
 	}