Browse Source

处理在售产品关联不到物料id的问题

yujia 7 years ago
parent
commit
b5755ccbb3

+ 10 - 0
src/main/java/com/uas/platform/b2c/core/constant/IntegerConstant.java

@@ -32,4 +32,14 @@ public class IntegerConstant {
      * 年月日 合计的长度 20180725
      */
     public static final Integer TIME_LENGTH = 8;
+
+    /**
+     * 国内交货
+     */
+    public static final Integer DOMESTIC_DELAY = 3;
+
+    /**
+     * 国外交货
+     */
+    public static final Integer ABROAD_DELAY = 2;
 }

+ 64 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -1,10 +1,12 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.core.utils.NumberUtil;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
+import com.uas.platform.b2c.trade.presale.model.TradeDeliveryDelayTime;
 import com.uas.platform.b2c.trade.support.CodeType;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
@@ -1699,4 +1701,66 @@ public class Goods implements Serializable {
 		this.productAttachSubmit = productAttachSubmit;
 		return this;
 	}
+
+	public Goods setGoodsByReleaseProductByBatch(ReleaseProductByBatch releaseProductByBatch, TradeDeliveryDelayTime deliveryDelayTime) {
+		this.productid = releaseProductByBatch.getProductid();
+		this.prodNum = releaseProductByBatch.getProductNum();
+		this.tag = StringUtils.isEmpty(releaseProductByBatch.getTag()) ? "类型1" : releaseProductByBatch.getTag();
+		this.unit = StringUtils.isEmpty(releaseProductByBatch.getUnit()) ? "PCS" : releaseProductByBatch.getUnit();
+		this.shipArea = releaseProductByBatch.getShipArea();
+		this.batchCode = "BT" + (Long.valueOf(releaseProductByBatch.getRelbatchid()) + releaseProductByBatch.getNum());
+		this.brandNameCn = releaseProductByBatch.getB2cBrandcn();
+		this.brandNameEn = releaseProductByBatch.getB2cBranden();
+		this.brandid = releaseProductByBatch.getBrandId();
+		this.branduuid = releaseProductByBatch.getBranduuid();
+		this.code = releaseProductByBatch.getB2cCode();
+		this.createdDate = releaseProductByBatch.getCreateDate();
+		this.currencyName = releaseProductByBatch.getCurrency();
+		this.enterpriseName = SystemSession.getUser().getEnterprise().getEnName();
+		this.enUU = SystemSession.getUser().getEnterprise().getUu();
+		this.img = releaseProductByBatch.getImg();
+		this.kindNameCn = releaseProductByBatch.getKindName();
+		this.minBuyQty = releaseProductByBatch.getMinBuyQty();
+		this.minPackQty = releaseProductByBatch.getMinPackage();
+		this.original = releaseProductByBatch.getOriginal();
+		this.produceDate = releaseProductByBatch.getProductDate();
+		this.publishPhone = releaseProductByBatch.getPublisherTel();
+		this.publisherName = releaseProductByBatch.getPublisherName();
+		this.publisherUU = releaseProductByBatch.getPublisherUu();
+		this.qtyPrice = releaseProductByBatch.getQtyPrice();
+		this.remark = releaseProductByBatch.getRemark();
+		this.reserve = releaseProductByBatch.getReserve();
+		this.lastReserve = releaseProductByBatch.getReserve();
+		this.returnInWeek = releaseProductByBatch.getReturnInWeek();
+		this.sampleQty = releaseProductByBatch.getSampleqty();
+		this.status = (NumberUtil.compare(releaseProductByBatch.getReserve(), releaseProductByBatch.getMinBuyQty()) > -1) ? 601 : 602;
+		this.updateDate = releaseProductByBatch.getCreateDate();
+		this.uuid = releaseProductByBatch.getComponentUuId();
+		this.rmbTaxRate = releaseProductByBatch.getRmbTaxRate();
+		this.usdTaxRate = releaseProductByBatch.getUsdTaxRate();
+		this.maxDelivery = releaseProductByBatch.getSelfMaxDelivery();
+		this.minDelivery = releaseProductByBatch.getSelfMinDelivery();
+		if (deliveryDelayTime == null) {
+			this.b2cMaxDelivery = releaseProductByBatch.getSelfMaxDelivery();
+			this.b2cMinDelivery = releaseProductByBatch.getSelfMinDelivery();
+		} else {
+			this.b2cMaxDelivery = (short)(releaseProductByBatch.getSelfMaxDelivery() + deliveryDelayTime.getMaxTime());
+			this.b2cMinDelivery = (short)(releaseProductByBatch.getSelfMinDelivery() + deliveryDelayTime.getMinTime());
+		}
+		this.maxPriceRMB = releaseProductByBatch.getMaxPriceRMB();
+		this.minPriceRMB = releaseProductByBatch.getMinPriceRMB();
+		this.maxPriceUSD = releaseProductByBatch.getMaxPriceUSD();
+		this.minPriceUSD = releaseProductByBatch.getMinPriceUSD();
+		this.batchid = releaseProductByBatch.getRelbatchid();
+		this.storeid = releaseProductByBatch.getStoreid();
+		this.storeName = releaseProductByBatch.getStoreName();
+		this.kindUuid = releaseProductByBatch.getKindUuid();
+		this.packaging = releaseProductByBatch.getPackaging();
+		this.encapsulation = releaseProductByBatch.getEncapsulation();
+		this.breakUp = releaseProductByBatch.getBreakUp();
+		this.perQty = releaseProductByBatch.getBreakUp() ? 1 : releaseProductByBatch.getMinPackage();
+		this.spec = releaseProductByBatch.getSpec();
+		this.attach = releaseProductByBatch.getAttach();
+		return this;
+	}
 }

+ 2 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java

@@ -382,7 +382,7 @@ public class GoodsHistory {
 	/**
 	 * 每次加减单位数量,可拆卖,等于1,不可拆卖 等于最小包数量
 	 */
-	@Column(name = "go_perQty")
+	@Column(name = "go_per_qty")
 	private Double perQty;
 
 	/**
@@ -1082,6 +1082,7 @@ public class GoodsHistory {
 		this.spec = goods.getSpec();
 		this.goid  = goods.getId();
 		this.batchid = goods.getBatchid();
+		this.attach = goods.getAttach();
     }
 
 	public Short getSelfDeliveryDemMinTime() {

+ 2 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -959,6 +959,8 @@ public class ReleaseProductByBatch implements Serializable {
 		this.brandId = brandId;
 	}
 
+
+
 	public String getCode() {
 		return code;
 	}

+ 6 - 4
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsHistoryServiceImpl.java

@@ -138,12 +138,14 @@ public class GoodsHistoryServiceImpl implements GoodsHistoryService {
 		if (null != isERP && isERP == true) {
 			goodsHistory.setOperateUU(88888888L);
 		} else {
-			goodsHistory.setOperateUU(SystemSession.getUser().getUserUU());
+			// 当用线程做批量发布之后的动作时,会没有用户信息
+			if (SystemSession.getUser() == null) {
+				goodsHistory.setOperateUU(goods.getPublisherUU());
+			} else {
+				goodsHistory.setOperateUU(SystemSession.getUser().getUserUU());
+			}
 		}
 		goodsHistory.setOperateType(type);
-//		if(GoodsHistory.OperateType.Update.getPhrase().equals(type)) {
-//			goodsHistory.setMessage(compareGoodsHistory(goodsHistory));
-//		}
 		return goodsHistory;
 	}
 

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

@@ -1,6 +1,5 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
-import com.uas.platform.b2c.common.account.model.Enterprise;
 import com.uas.platform.b2c.common.base.dao.CommonDao;
 import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.core.constant.IntegerConstant;
@@ -28,6 +27,8 @@ import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.b2c.prod.store.model.StoreStatus;
 import com.uas.platform.b2c.prod.store.service.StoreInService;
 import com.uas.platform.b2c.trade.order.StringConstant.Currency;
+import com.uas.platform.b2c.trade.presale.model.TradeDeliveryDelayTime;
+import com.uas.platform.b2c.trade.presale.service.TradeDeliveryDelayTimeService;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.b2c.trade.util.BoundedExecutor;
 import com.uas.platform.core.exception.IllegalOperatorException;
@@ -136,6 +137,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
     @Autowired
     private GoodsHistoryService goodsHistoryService;
 
+	@Autowired
+	private TradeDeliveryDelayTimeService tradeDeliveryDelayTimeService;
+
 	private final Logger logger = Logger.getLogger(getClass());
 
 	/**
@@ -210,7 +214,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (rowNum > 2002) {
 			throw new IllegalOperatorException ("您上传的信息超过2000条,请拆分成2000以下再上传");
 		}
-		if (rowNum < 3) {
+		if (rowNum < 2) {
 			throw new IllegalOperatorException ("请填写上传信息");
 		}
 		List<ReleaseProductByBatch> releaseProductByBatchs = new ArrayList<>(rowNum);
@@ -1728,26 +1732,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (isPcb) {
 			savePcbInfo(idSet, map);
 		}
-		System.err.println("测试信息的1-2" + "---------------------");
-		Enterprise enterprise = SystemSession.getUser().getEnterprise();
-        final Object[] obj = new Object[]{enterprise.getUu(), enterprise.getEnName(), batch};
-        String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_GOODS_V5(@enuu, @enName, @batch, @out); select @out; commit;";
-        final String updateSql = String.format(sql, obj);
-        String num = jdbcTemplate.execute(new StatementCallback<String>() {
-
-            @Override
-            public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
-                stmt.executeUpdate(updateSql);
-                ResultSet rs = stmt.getResultSet();
-				System.err.println("测试信息的1-3" + "---------------------");
-                if (null != rs) {
-                    rs.next();
-					System.err.println("测试信息的1-3" + "---------------------" + rs.getString(1));
-                    return rs.getString(1);
-                }
-                return "0";
-            }
-        });
+		Integer num = releaseToGoods(releaseProductByBatchList);
 		System.err.println("测试信息的1" + "---------------------");
 		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});
@@ -1760,6 +1745,55 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		return StringUtilB2C.getStr(num);
 	}
 
+
+	/**
+	 * 临时表保存到goods信息
+	 * @param list
+	 * @return
+	 */
+	public Integer releaseToGoods(List<ReleaseProductByBatch> list) {
+		if (CollectionUtils.isNotEmpty(list)) {
+			List<Goods> goodses = new ArrayList<>();
+			Goods goods = null;
+			TradeDeliveryDelayTime delayTime = null;
+			ReleaseProductByBatch releaseProductByBatch1 = list.get(0);
+			if (releaseProductByBatch1.getStoreid().equals(SysConf.getStoreid())) {
+				// 增加交货延长期限
+				List<TradeDeliveryDelayTime> tradeDeliveryDelayTime = tradeDeliveryDelayTimeService.getTradeDeliveryDelayTime();
+				if (releaseProductByBatch1.getCurrency().equals(StringConstant.RMB)) {
+					for (TradeDeliveryDelayTime deliveryDelayTime : tradeDeliveryDelayTime) {
+						if (deliveryDelayTime.getType() == IntegerConstant.DOMESTIC_DELAY) {
+							delayTime = deliveryDelayTime;
+						}
+					}
+				} else {
+					for (TradeDeliveryDelayTime deliveryDelayTime : tradeDeliveryDelayTime) {
+						if (deliveryDelayTime.getType() == IntegerConstant.ABROAD_DELAY) {
+							delayTime = deliveryDelayTime;
+						}
+					}
+				}
+				if (delayTime == null) {
+					throw new IllegalOperatorException("平台未设置供应商延长时间,请联系管理员");
+				}
+			}
+
+			for (ReleaseProductByBatch releaseProductByBatch : list) {
+				if (releaseProductByBatch.getReleaseCode().intValue() == ReleaseStatus.success.value() || releaseProductByBatch.getReleaseCode().intValue() == ReleaseStatus.failure.value()) {
+					goods = new Goods();
+					goods.setGoodsByReleaseProductByBatch(releaseProductByBatch, delayTime);
+					goodses.add(goods);
+				}
+			}
+			if (CollectionUtils.isNotEmpty(goodses)) {
+				commonDao.save(goodses, Goods.class);
+			}
+			return goodses.size();
+		} else {
+			return 0;
+		}
+	}
+
 	/**
 	 * 批量保存pcb的信息
 	 * @param idSet id
@@ -1963,6 +1997,17 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		final Runnable afterPublishToGoodsRunnable = new Runnable() {
 			@Override
 			public void run() {
+
+				//创建历史库存
+				List<Goods> goodses1 = goodsService.findByBatchId(batchid);
+				List<GoodsHistory> list = new ArrayList<>();
+				for (Goods goods : goodses1) {
+					GoodsHistory goodsHistory = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.Publish.getPhrase(), false);
+					list.add(goodsHistory);
+				}
+				if (CollectionUtils.isNotEmpty(list)) {
+					goodsHistoryService.save(list);
+				}
 				//创建物料的私有信息
 				productPrivateService.newProductPrivateIfNotExist(productIds);
 
@@ -1970,12 +2015,14 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					List<ReleaseProductByBatch> productByBatches = releaseProductByBatchDao.findAll(reIds);
 					List<Long> prIds = new ArrayList<>();
 					for (ReleaseProductByBatch productByBatch : productByBatches) {
-						prIds.add(productByBatch.getProductid());
+						if (productByBatch.getProductid() != null) {
+							prIds.add(productByBatch.getProductid());
+						}
 					}
 					List<Product> products = productService.findByProductId(prIds);
 					for (Product product : products) {
 						for (ReleaseProductByBatch productByBatch : productByBatches) {
-							if ((productByBatch.getProductid() != null ) && (product.getId().longValue() == productByBatch.getProductid().longValue())) {
+							if ((productByBatch.getProductid() != null) && (product.getId().longValue() == productByBatch.getProductid().longValue())) {
 								product.setSpec(productByBatch.getSpec());
 							}
 						}