|
|
@@ -2,14 +2,21 @@ package com.uas.platform.b2c.trade.order.service.impl;
|
|
|
|
|
|
import com.uas.platform.b2c.core.constant.IntegerConstant;
|
|
|
import com.uas.platform.b2c.core.constant.ReleaseStatus;
|
|
|
+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.support.log.UsageBufferedLogger;
|
|
|
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.constant.StringConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.ShortConstant;
|
|
|
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.ProductPrivateDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ReleaseProductByBatchDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ProductService;
|
|
|
@@ -19,6 +26,7 @@ import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
import com.uas.platform.b2c.trade.order.service.PurchaseProductService;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
import com.uas.platform.core.util.HttpUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
@@ -64,6 +72,12 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
@Autowired
|
|
|
private ProductPrivateDao productPrivateDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsHistoryDao goodsHistoryDao;
|
|
|
+
|
|
|
/**
|
|
|
* 物料服务访问路径
|
|
|
*/
|
|
|
@@ -75,6 +89,11 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
*/
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseProductServiceImpl.class);
|
|
|
|
|
|
+ /**
|
|
|
+ * 系统操作日志
|
|
|
+ */
|
|
|
+ private static final UsageBufferedLogger USE_LOG = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
+
|
|
|
/**
|
|
|
* 不需要传入的状态码
|
|
|
*/
|
|
|
@@ -161,7 +180,7 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
// 去重后的数据
|
|
|
List<ReleaseProductByBatch> uniqueBatchList = releaseProductByBatchDao.findByRelbatchidAndReleaseCodeNot(userUU, batch, failCode);
|
|
|
if (!CollectionUtils.isEmpty(uniqueBatchList)) {
|
|
|
- assignNumber = assignBatch(uniqueBatchList);
|
|
|
+ assignNumber = assignBatch(uniqueBatchList, batch);
|
|
|
}
|
|
|
modelMap.put("assignSuccess", assignNumber);
|
|
|
modelMap.put("assignFailure", total - assignNumber);
|
|
|
@@ -218,13 +237,11 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
// 统计为空的个数
|
|
|
int result = 0;
|
|
|
aProduct.setNum(rowNum - 2);
|
|
|
- StringBuilder errMsg = new StringBuilder();
|
|
|
// 品牌
|
|
|
Object brandValue = releaseProductByBatchService.readWorkBookCell(row.getCell(UploadConstant.BRAND_ENGLISH), Cell.CELL_TYPE_STRING,
|
|
|
rowNum, UploadConstant.BRAND_ENGLISH);
|
|
|
if (StringUtils.isEmpty(brandValue)) {
|
|
|
result += 1;
|
|
|
- errMsg.append(String.format(StringConstant.EXCEL_POSITION + ErrorInfoConstant.BRAND_EMPTY_INFO.getInfo(), rowNum + 1, "A"));
|
|
|
}
|
|
|
aProduct.setBrandEnByExcel(brandValue);
|
|
|
|
|
|
@@ -233,10 +250,6 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
rowNum, UploadConstant.KIND);
|
|
|
if (StringUtils.isEmpty(kindValue)) {
|
|
|
result += 1;
|
|
|
- if (errMsg.length() > 0) {
|
|
|
- errMsg.append(",");
|
|
|
- }
|
|
|
- errMsg.append(String.format(StringConstant.EXCEL_POSITION + ErrorInfoConstant.KIND_EMPTY_INFO.getInfo(), rowNum + 1, "B"));
|
|
|
}
|
|
|
aProduct.setKindByExcel(kindValue);
|
|
|
|
|
|
@@ -245,10 +258,6 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
rowNum, UploadConstant.PRODUCT_CODE);
|
|
|
if (StringUtils.isEmpty(codeValue)) {
|
|
|
result += 1;
|
|
|
- if (errMsg.length() > 0) {
|
|
|
- errMsg.append(",");
|
|
|
- }
|
|
|
- errMsg.append(String.format(StringConstant.EXCEL_POSITION + ErrorInfoConstant.CODE_EMPTY_INFO.getInfo(), rowNum + 1, "C"));
|
|
|
}
|
|
|
aProduct.setCodeByExcel(codeValue);
|
|
|
|
|
|
@@ -257,8 +266,10 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
rowNum, UploadConstant.SPEC);
|
|
|
aProduct.setSpecByExcel(specValue);
|
|
|
|
|
|
- if (errMsg.length() > 0) {
|
|
|
- aProduct.setErrmsg(errMsg.toString());
|
|
|
+ if (!StringUtils.isEmpty(aProduct.getErrmsg())) {
|
|
|
+ if (aProduct.getErrmsg().startsWith(SplitChar.COMMA)) {
|
|
|
+ aProduct.setErrmsg(aProduct.getErrmsg().replaceFirst(SplitChar.COMMA, ""));
|
|
|
+ }
|
|
|
aProduct.setReleaseCode(ReleaseStatus.lack_info.value());
|
|
|
aProduct.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
|
|
|
}
|
|
|
@@ -311,10 +322,11 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
* 将去重的数据批量绑定到个人物料库
|
|
|
*
|
|
|
* @param uniqueBatchList 去重后的物料信息
|
|
|
+ * @param batch 批次号
|
|
|
* @return 保存成功的数量
|
|
|
*/
|
|
|
- private Integer assignBatch(List<ReleaseProductByBatch> uniqueBatchList) {
|
|
|
- Set<Long> idSet = getProductIdSet(uniqueBatchList);
|
|
|
+ private Integer assignBatch(List<ReleaseProductByBatch> uniqueBatchList, String batch) {
|
|
|
+ Set<Long> idSet = getProductIdSet(uniqueBatchList, batch);
|
|
|
if (CollectionUtils.isNotEmpty(idSet)) {
|
|
|
HashMap<String, Object> params = new HashMap<>(5);
|
|
|
ModelMap data = new ModelMap();
|
|
|
@@ -338,9 +350,10 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
* 获取物料id字段
|
|
|
*
|
|
|
* @param uniqueBatchList 去重后的物料信息
|
|
|
+ * @param batchCode 批次号
|
|
|
* @return 物料id集合
|
|
|
*/
|
|
|
- private Set<Long> getProductIdSet(List<ReleaseProductByBatch> uniqueBatchList) {
|
|
|
+ private Set<Long> getProductIdSet(List<ReleaseProductByBatch> uniqueBatchList, String batchCode) {
|
|
|
List<String> productCodeList = new ArrayList<>();
|
|
|
Set<Long> idSet = new HashSet<>();
|
|
|
List<ReleaseProductByBatch> batchList = new ArrayList<>();
|
|
|
@@ -360,7 +373,18 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
productService.saveByJdbcTemplate(batchList);
|
|
|
List<com.uas.platform.b2c.prod.commodity.model.Product> productList = productService.findProductIdAndProdnumsByProdNums(productCodeList);
|
|
|
List<ProductPrivate> privateList = new ArrayList<>();
|
|
|
+ String defaultPackaging = "其他";
|
|
|
+ Boolean defaultBreakUp = true;
|
|
|
+ Boolean defaultAutoPublish = true;
|
|
|
+ List<Goods> goodsList = new ArrayList<>();
|
|
|
+ List<GoodsHistory> historyList = new ArrayList<>();
|
|
|
productList.forEach(product -> {
|
|
|
+ Goods goods = new Goods(defaultPackaging, defaultBreakUp, defaultAutoPublish, ShortConstant.defaultMaxDelivery,
|
|
|
+ ShortConstant.defaultMinDelivery, DoubleConstant.defaultMinBuyQty, DoubleConstant.defaultMinPackQty, Status.NO_SHELVE.value());
|
|
|
+ goods = productService.bindProductToGoods(goods, product);
|
|
|
+ goodsList.add(goods);
|
|
|
+ GoodsHistory goodsHistory = productService.assignmentGoodsHistory(goods);
|
|
|
+ historyList.add(goodsHistory);
|
|
|
ProductPrivate productPrivate;
|
|
|
List<ProductPrivate> privates = productPrivateDao.findByPrId(product.getId());
|
|
|
if (CollectionUtils.isNotEmpty(privates)) {
|
|
|
@@ -376,6 +400,16 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
idSet.add(product.getId());
|
|
|
});
|
|
|
|
|
|
+ // 保存goods
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsList)) {
|
|
|
+ goodsDao.save(goodsList);
|
|
|
+ USE_LOG.log("上架商品", "新增上架商品", "批量导入上架商品,数量 " + goodsList.size() + ", 批号 " + batchCode);
|
|
|
+ }
|
|
|
+ // 保存goodsHistory
|
|
|
+ if (CollectionUtils.isNotEmpty(historyList)) {
|
|
|
+ goodsHistoryDao.save(historyList);
|
|
|
+ USE_LOG.log("库存操作", "批量导入上架商品更新库存操作", "数量 " + historyList.size() + ", 批次号 " + batchCode);
|
|
|
+ }
|
|
|
// 保存到私有库
|
|
|
if (CollectionUtils.isNotEmpty(privateList)) {
|
|
|
productPrivateDao.save(privateList);
|