|
|
@@ -1,15 +1,15 @@
|
|
|
package com.uas.platform.b2c.trade.order.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.platform.b2c.core.constant.ReleaseStatus;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
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.UploadConstant;
|
|
|
+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.ProductPrivate;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.ReleaseProductByBatch;
|
|
|
+import com.uas.platform.b2c.prod.commodity.service.ProductService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
|
|
|
import com.uas.platform.b2c.prod.commodity.util.SheetUtil;
|
|
|
import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
@@ -17,8 +17,6 @@ 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.util.HttpUtil;
|
|
|
-import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
-import com.uas.ps.entity.Product;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
@@ -31,8 +29,10 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 买家中心物料相关
|
|
|
@@ -52,22 +52,18 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
@Autowired
|
|
|
private ReleaseProductByBatchDao releaseProductByBatchDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductPrivateDao productPrivateDao;
|
|
|
+
|
|
|
/**
|
|
|
* 物料服务访问路径
|
|
|
*/
|
|
|
@Value("#{sys.productServiceIp}")
|
|
|
private String productServiceIp;
|
|
|
|
|
|
- /**
|
|
|
- * HTTP请求成功标志
|
|
|
- */
|
|
|
- static final String TRUE_SIGN = "true";
|
|
|
-
|
|
|
- /**
|
|
|
- * HTTP请求成功返回值
|
|
|
- */
|
|
|
- static final String SUCCESS_CODE = "success";
|
|
|
-
|
|
|
/**
|
|
|
* 程序执行日志
|
|
|
*/
|
|
|
@@ -144,7 +140,7 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
// 验证成功后进行绑定处理
|
|
|
Integer assignNumber = 0;
|
|
|
// 去重后的数据
|
|
|
- List<ReleaseProductByBatch> uniqueBatchList = releaseProductByBatchDao.findByRelbatchidAndReleaseCode(batch, ReleaseStatus.unreleased.value());
|
|
|
+ List<ReleaseProductByBatch> uniqueBatchList = releaseProductByBatchDao.findByRelbatchidAndReleaseCodeNot(batch, ReleaseStatus.lack_info.value());
|
|
|
if (!CollectionUtils.isEmpty(uniqueBatchList)) {
|
|
|
assignNumber = assignBatch(uniqueBatchList);
|
|
|
}
|
|
|
@@ -266,19 +262,66 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
* @return 保存成功的数量
|
|
|
*/
|
|
|
private Integer assignBatch(List<ReleaseProductByBatch> uniqueBatchList) {
|
|
|
- List<Product> productList = covert(uniqueBatchList);
|
|
|
- try {
|
|
|
- String res = HttpUtil.doPost(productServiceIp + "/product/update/addToProductUser", FlexJsonUtils.toJsonDeep(productList));
|
|
|
- JSONObject response = JSON.parseObject(res);
|
|
|
- if (TRUE_SIGN.equals(response.get(SUCCESS_CODE))) {
|
|
|
- return Integer.valueOf(response.get("result").toString());
|
|
|
+ Set<Long> idSet = getProductIdSet(uniqueBatchList);
|
|
|
+ if (CollectionUtils.isNotEmpty(idSet)) {
|
|
|
+ HashMap<String, Object> params = new HashMap<>(5);
|
|
|
+ ModelMap data = new ModelMap();
|
|
|
+ data.put("ids", idSet.toString());
|
|
|
+ data.put("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ data.put("userUU", SystemSession.getUser().getUserUU());
|
|
|
+ params.put("data", data);
|
|
|
+ HttpUtil.Response res = null;
|
|
|
+ try {
|
|
|
+ res = HttpUtil.sendPostRequest(productServiceIp + "/productuser/coverToUserByIds", params);
|
|
|
+ return Integer.valueOf(res.getResponseText());
|
|
|
+ } catch (Exception e) {
|
|
|
+ String resultCode = null != res ? String.valueOf(res.getStatusCode()) : "access error";
|
|
|
+ LOGGER.error("coverToUserProd http response status error: " + resultCode);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- LOGGER.info("访问接口失败", e);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取物料id字段
|
|
|
+ *
|
|
|
+ * @param uniqueBatchList 去重后的物料信息
|
|
|
+ * @return 物料id集合
|
|
|
+ */
|
|
|
+ private Set<Long> getProductIdSet(List<ReleaseProductByBatch> uniqueBatchList) {
|
|
|
+ List<String> productCodeList = new ArrayList<>();
|
|
|
+ Set<Long> idSet = new HashSet<>();
|
|
|
+ List<ReleaseProductByBatch> batchList = new ArrayList<>();
|
|
|
+ uniqueBatchList.forEach(batch -> {
|
|
|
+ if (null != batch.getProductid()) {
|
|
|
+ idSet.add(batch.getProductid());
|
|
|
+ } else {
|
|
|
+ if (StringUtilB2C.isEmpty(batch.getProductNum())) {
|
|
|
+ String code = "PNUM" + StringUtilB2C.getRandomNumber(6);
|
|
|
+ batch.setProductNum(code);
|
|
|
+ }
|
|
|
+ productCodeList.add(batch.getProductNum());
|
|
|
+ batchList.add(batch);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 新增到物料库
|
|
|
+ productService.saveByJdbcTemplate(batchList);
|
|
|
+ List<com.uas.platform.b2c.prod.commodity.model.Product> productList = productService.findProductIdAndProdnumsByProdNums(productCodeList);
|
|
|
+ List<ProductPrivate> privateList = new ArrayList<>();
|
|
|
+ productList.forEach(product -> {
|
|
|
+ ProductPrivate productPrivate = new ProductPrivate(product.getId());
|
|
|
+ privateList.add(productPrivate);
|
|
|
+ idSet.add(product.getId());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 保存到私有库
|
|
|
+ if (CollectionUtils.isNotEmpty(privateList)) {
|
|
|
+ productPrivateDao.save(privateList);
|
|
|
+ LOGGER.info("批量上传个人物料库,同步新增到商城私有库: " + privateList.size());
|
|
|
+ }
|
|
|
+ return idSet;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理验证后的数据
|
|
|
*
|
|
|
@@ -312,49 +355,9 @@ public class PurchaseProductServiceImpl implements PurchaseProductService {
|
|
|
if (aBatch.getErrmsg().substring(0, 1).equals(",")) {
|
|
|
aBatch.setErrmsg(aBatch.getErrmsg().substring(1));
|
|
|
}
|
|
|
- } else {
|
|
|
- aBatch.setReleaseStatus(ReleaseStatus.unreleased.getPhrase());
|
|
|
- aBatch.setReleaseCode(ReleaseStatus.unreleased.value());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 将去重的数据转换成Product数据并进行保存处理
|
|
|
- *
|
|
|
- * @param uniqueBatchList 上传后去重的数据
|
|
|
- * @return List<Product>
|
|
|
- */
|
|
|
- private List<Product> covert(List<ReleaseProductByBatch> uniqueBatchList) {
|
|
|
- List<Product> productList = new ArrayList<>();
|
|
|
- uniqueBatchList.forEach(batch -> {
|
|
|
- Product product = new Product();
|
|
|
- product.setSpec(batch.getSpec());
|
|
|
- String brand = batch.getBrandNameEn() != null ? batch.getBrandNameEn() : batch.getBrandNameCn();
|
|
|
- product.setBrand(brand);
|
|
|
- product.setpBrand(brand);
|
|
|
- product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- product.setCmpCode(batch.getCode());
|
|
|
- product.setpCmpCode(batch.getCode());
|
|
|
- // 没有编号设置编号
|
|
|
- if (null == product.getCode()) {
|
|
|
- String code = "PNUM" + StringUtilB2C.getRandomNumber(6);
|
|
|
- product.setCode(code);
|
|
|
- }
|
|
|
- // 交期默认赋值为0
|
|
|
- Double leadTime = 0D;
|
|
|
- product.setLeadTime(leadTime);
|
|
|
- product.setCmpUuid(batch.getComponentUuId());
|
|
|
- product.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
- product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- product.setKind(batch.getKindName());
|
|
|
- product.setUnit(batch.getUnit());
|
|
|
- product.setTitle(batch.getKindName());
|
|
|
- product.setId(batch.getProductid());
|
|
|
- product.setSourceApp(StringConstant.SOURCE);
|
|
|
- productList.add(product);
|
|
|
- });
|
|
|
- return productList;
|
|
|
- }
|
|
|
}
|