Browse Source

Merge branch 'feature-priceSKU-hulh-0103' into dev-mysql

hulh 8 years ago
parent
commit
010d2c7dcd

+ 1 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/ErrorInfoConstant.java

@@ -6,6 +6,7 @@ package com.uas.platform.b2c.prod.commodity.constant;
  * @author hulh
  */
 public enum  ErrorInfoConstant {
+    REPEAT_INFO("产品库已存在该产品"),
     CODE_PATTERN_INFO("A列:请勿输入中文或中文特殊字符"),
     CODE_LENGTH_INFO("A列:产品型号不能超过100字符"),
     CODE_EMPTY_INFO("A列:产品型号不能为空"),

+ 10 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductDao.java

@@ -67,6 +67,16 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findProductByPcmpcodeAndPbrandenAndEnUU(String pcmpcode, String pbranden, Long enUU);
 
+    /**
+     *
+     * @param enUU 企业enuu
+     * @param pcmpcode 型号
+     * @param pbranden 品牌
+     * @param b2cEnabled 启用
+     * @return
+     */
+    List<Product> findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(Long enUU, String pcmpcode, String pbranden, Integer b2cEnabled);
+
 
     /**
      * 根据器件型号,品牌 、enuu

+ 1 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ReleaseProductByBatchDao.java

@@ -71,7 +71,7 @@ public interface ReleaseProductByBatchDao
      * @param publisherUu the publisher uu 发布人
      * @param batchid     the batchid 批次号
      */
-    @Procedure(procedureName = "PRODUCT_RELEASE_VALID_V1")
+    @Procedure(procedureName = "PRODUCT_RELEASE_VALID_V2")
 	public void callValidProcedure(Long publisherUu, String batchid);
 
     /**

+ 3 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -8,6 +8,7 @@ import com.uas.platform.b2c.core.utils.StringUtilB2C;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.commodity.constant.ErrorInfoConstant;
 import com.uas.platform.b2c.prod.commodity.type.ReleaseConstant;
+import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.trade.order.StringConstant.Currency;
 import org.apache.commons.collections.CollectionUtils;
 import org.codehaus.jackson.annotate.JsonIgnore;
@@ -486,7 +487,8 @@ public class ReleaseProductByBatch implements Serializable {
 		if (!minPackageStr.equals(that.minPackageStr)) return false;
 		if (!packaging.equals(that.packaging)) return false;
 		if (!selfMaxDeliveryStr.equals(that.selfMaxDeliveryStr)) return false;
-		return selfMinDeliveryStr.equals(that.selfMinDeliveryStr);
+		if (!selfMinDeliveryStr.equals(that.selfMinDeliveryStr)) return false;
+		return GoodsUtil.compareWithQtyPrice(prices, that.getPrices(), that.getCurrency());
 
 	}
 

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

@@ -564,7 +564,8 @@ public class GoodsServiceImpl implements GoodsService {
         goods.setTaxRate();
 
         if (goods.getReturnInWeek() == null) {
-            goods.setReturnInWeek((short) 0);// 若无设置,默认不支持7天无理由退货
+            // 若无设置,默认不支持7天无理由退货
+            goods.setReturnInWeek((short) 0);
         }
         // 若B2C上架的商品必须有发布人姓名和发布人联系电话
         if (goods.getSourceId() == null) {
@@ -586,16 +587,12 @@ public class GoodsServiceImpl implements GoodsService {
         if (StringUtils.isEmpty(goods.getImg())) {
             Long goodsProductid = goods.getProductid();
             if (goodsProductid != null) {
-                Product product = productDao.findOne
-                        (goodsProductid);
+                Product product = productDao.findOne(goodsProductid);
                 if (product != null) {
                     if (StringUtils.isEmpty(product.getCmpImg())) {
                         String cmpUuId = product.getCmpUuId();
-                        if (!StringUtils.isEmpty
-                                (cmpUuId)) {
-                            Component component = componentDao
-                                    .findByUuid
-                                            (cmpUuId);
+                        if (!StringUtils.isEmpty(cmpUuId)) {
+                            Component component = componentDao.findByUuid(cmpUuId);
                             if (component != null) {
                                 goods.setImg(component.getImg());
                             }
@@ -622,8 +619,13 @@ public class GoodsServiceImpl implements GoodsService {
                 throw new IllegalOperatorException("器件" + goods.getCode() + "品牌" + goods.getBrandNameEn() + "关联的物料库信息丢失");
             }
             List<Goods> goodses = goodsDao.findRepeatGoodsInProductId(goods.getProductid(), goods.getProduceDate(), goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(), goods.getMinDelivery(), goods.getUnit());
-            if ((goods.getId() == null && goodses.size() > 0) || (goodses.size() > 1)) {
-                throw new IllegalOperatorException("该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位)相同的信息");
+            if (!CollectionUtils.isEmpty(goodses)) {
+                for (Goods goods1 : goodses) {
+                    if (!goods1.getId().equals(goods.getId())
+                            && GoodsUtil.compareWithQtyPrice(goods1.getPrices(), goods.getPrices(), goods.getCurrencyName())) {
+                        throw new IllegalOperatorException("该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位、价格)相同的信息");
+                    }
+                }
             }
             //判断自定义标签是否重复
             if (StringUtils.isEmpty(goods.getTag())) {
@@ -633,13 +635,12 @@ public class GoodsServiceImpl implements GoodsService {
                 throw new IllegalOperatorException("传入的产品信息缺失,请重新操作");
             }
             List<Goods> goodsList = goodsDao.findGoodsByProductidAndTag(goods.getProductid(), goods.getTag());
-            if ((goods.getId() == null) &&
-                    (goodsList.size() > 0)) {
+            if ((goods.getId() == null) && (goodsList.size() > 0)) {
                 throw new IllegalOperatorException("该产品下已存在相同的自定义标签");
             } else {
                 for (Goods goods1 : goodsList) {
-                    if (goods.getTag().equals(goods1.getTag()) &&
-                            (goods1.getId().longValue() != goods.getId().longValue())) {
+                    if (goods.getTag().equals(goods1.getTag())
+                            && (goods1.getId().longValue() != goods.getId().longValue())) {
                         throw new IllegalOperatorException("该产品下已存在相同的自定义标签");
                     }
                 }
@@ -1247,26 +1248,20 @@ public class GoodsServiceImpl implements GoodsService {
         if (nowGoods.getReserve().doubleValue() != goods.getOldReserve().doubleValue()) {
             return new ResultMap(CodeType.INFO_UPDATE.code(), "该库存的信息已经被修改了,请刷新界面之后重新操作。");
         }
-        if(StringUtils.isEmpty(goods.getTag())) {
+        if (StringUtils.isEmpty(goods.getTag())) {
             return new ResultMap(CodeType.NOT_PERMIT.code(), "产品自定义标签必须填写");
         }
         List<Goods> tagInTheProdNums = goodsDao.findSameTagInTheProdNum(goods.getProdNum(), goods.getTag());
         for (Goods tagInTheProdNum : tagInTheProdNums) {
-            if(goods.getTag().equals(tagInTheProdNum.getTag())&&(goods.getId().longValue() != tagInTheProdNum.getId().longValue())) {
+            if (goods.getTag().equals(tagInTheProdNum.getTag()) && (goods.getId().longValue() != tagInTheProdNum.getId().longValue())) {
                 return new ResultMap(CodeType.NOT_PERMIT.code(), "标签不能与该器件现有产品的标签重复");
             }
         }
-//		ProductStandardPutOnInfo putOnInfo = productStandardPutOnInfoDao.findOne(goods.getStandprodid());
-//		if(putOnInfo != null) {
-//			if(nowGoods.validProductStandardPutOnInfoAndGoodsSameData(putOnInfo)) {
-//				return new ResultMap(CodeType.INFO_UPDATE.code(), "数据已经被更新了请刷新之后重新操作");
-//			}
-//		}
         List<Goods> repeatGoodsInProductId = goodsDao.findRepeatGoodsInProductId(goods.getProductid(), goods.getProduceDate(), goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(), goods.getMinDelivery(), goods.getUnit());
         for (Goods goods1 : repeatGoodsInProductId) {
-            if(goods1.getId().longValue() !=
-                    goods.getId().longValue()) {
-                throw new IllegalOperatorException("该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位)相同的信息");
+            if (!goods1.getId().equals(goods.getId())
+                    && GoodsUtil.compareWithQtyPrice(goods1.getPrices(), goods.getPrices(), goods.getCurrencyName())) {
+                throw new IllegalOperatorException("该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位、价格)相同的信息");
             }
         }
         resultGoods = updateGoods(nowGoods, goods);
@@ -1278,7 +1273,7 @@ public class GoodsServiceImpl implements GoodsService {
     @Override
     public ResultMap putOn(Long id) {
         Goods goods = goodsDao.findOne(id);
-        if(goods != null) {
+        if (goods != null) {
             setGoodsDefault(goods);
             ResultMap resultMap = checkGoods(goods);
             if (resultMap.getCode() != CodeType.OK.code()) {
@@ -1290,11 +1285,11 @@ public class GoodsServiceImpl implements GoodsService {
             goodsHistoryDao.save(goodsHistory);
             // TODO huxz 添加或修改商品价格信息
             if (goods.getUuid() != null) {
-                saveOrUpdatePriceInfos(goods, "NOMAL");
+//                saveOrUpdatePriceInfos(goods, "NOMAL");
                 updateComponentTradeInfos(goods.getUuid());
             }
             return ResultMap.success(persistGoods);
-        }else {
+        } else {
             return new ResultMap(CodeType.NO_INFO, "找不到对应的在售产品信息");
         }
     }
@@ -1308,7 +1303,7 @@ public class GoodsServiceImpl implements GoodsService {
     @Transactional
     @Override
     public ResultMap addGoods(Goods goods) {
-        if(goods == null) {
+        if (goods == null) {
             throw new IllegalOperatorException("传入的需要添加的产品信息为空");
         }
         if (Integer.valueOf(goods.getSelfSale()).equals(IntegerConstant.B2C_SALE)) {

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

@@ -176,6 +176,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		}
 		List<ReleaseProductByBatch> addList = new ArrayList<>(releaseProductByBatchs.size());
 		addList.addAll(releaseProductByBatchs);
+		resetRepeatData(addList);
 		commonDao.save(addList, ReleaseProductByBatch.class);
 		Long userUU = SystemSession.getUser().getUserUU();
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
@@ -191,6 +192,38 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return modelMap;
 	}
 
+	/**
+	 * 判断是否重复,重复则重设状态
+	 * @param data
+	 */
+	private void resetRepeatData(List<ReleaseProductByBatch> data) {
+		Long enuu = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
+		if (enuu == null) {
+			throw new IllegalOperatorException("企业enuu丢失");
+		}
+		for (ReleaseProductByBatch each : data) {
+			List<Product> standardList = productDao.findMatchStandard(enuu, each.getBrandNameEn(), each.getCode(), IntegerConstant.YES_SHORT);
+			if (!CollectionUtils.isEmpty(standardList)) {
+				each.setB2cBranden(standardList.get(0).getPbranden());
+				each.setB2cCode(standardList.get(0).getPcmpcode());
+			}
+			List<Product> productList = productDao.findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(enuu, each.getB2cCode(), each.getB2cBranden(), IntegerConstant.YES_SHORT);
+			if (!CollectionUtils.isEmpty(productList)) {
+				List<Goods> goodsList = goodsDao.findRepeatGoodsInProductId(productList.get(0).getId(), each.getProductDate(), each.getPackaging(), each.getMinPackage(), each.getMinBuyQty(), each.getSelfMaxDelivery(), each.getSelfMinDelivery(), each.getUnit());
+				if (!CollectionUtils.isEmpty(goodsList)) {
+					for (Goods goods1 : goodsList) {
+						if (GoodsUtil.compareWithQtyPrice(each.getPrices(), goods1.getPrices(), each.getCurrency())) {
+							each.setErrmsg(ErrorInfoConstant.REPEAT_INFO.getInfo());
+							each.setReleaseCode(ReleaseStatus.had_exists.value());
+							each.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+							break;
+						}
+					}
+				}
+			}
+		}
+	}
+
 	/**
 	 * 验证该产品自定义标签是否重复
 	 * @param aProduct 单个产品

+ 42 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/util/GoodsUtil.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.prod.commodity.util;
 
 import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
+import com.uas.platform.b2c.trade.order.StringConstant.Currency;
 import org.apache.commons.collections.CollectionUtils;
 
 import java.util.List;
@@ -95,4 +96,45 @@ public class GoodsUtil {
 		return maxPrice;
 	}
 
+	/**
+	 比较分段价格是否一致
+	 * @param qtyPriceList 分段价格列表
+	 * @param targetList  比较价格列表
+	 * @param currency 币别
+	 * @return
+	 */
+	public static Boolean compareWithQtyPrice(List<GoodsQtyPrice> qtyPriceList, List<GoodsQtyPrice> targetList, String currency) {
+		if (qtyPriceList.size() != targetList.size()) {
+			return false;
+		}
+		for (int i = 0; i < qtyPriceList.size(); i++) {
+			if (!compareWithPrice(qtyPriceList.get(i), targetList.get(i), currency)) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * 判断分段价格是否相等
+	 * @param first	分段价格1
+	 * @param second 分段价格2
+	 * @param currency 币别
+	 * @return
+	 */
+	public static Boolean compareWithPrice(GoodsQtyPrice first, GoodsQtyPrice second, String currency) {
+		if (!first.getStart().equals(second.getStart()) || !first.getEnd().equals(second.getEnd())) {
+			return false;
+		}
+		if (Currency.RMB.equals(currency)) {
+			if (!first.getRMBPrice().equals(second.getRMBPrice())) {
+				return false;
+			}
+		} else if (Currency.USD.equals(currency)) {
+			if (!first.getRMBPrice().equals(second.getRMBPrice())) {
+				return false;
+			}
+		}
+		return true;
+	}
 }