|
@@ -4,31 +4,36 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.jsh.erp.constants.ExceptionConstants;
|
|
|
-import com.jsh.erp.datasource.entities.DepotHeadVo4Body;
|
|
|
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
|
|
import com.jsh.erp.datasource.entities.Supplier;
|
|
|
import com.jsh.erp.datasource.entities.Unit;
|
|
|
+import com.jsh.erp.datasource.mappers.MaterialCurrentStockMapperEx;
|
|
|
import com.jsh.erp.datasource.tesco.request.ErpXsddReqVO;
|
|
|
import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
|
|
|
import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
|
|
|
import com.jsh.erp.datasource.vo.Material4UnitPrice;
|
|
|
+import com.jsh.erp.datasource.vo.MaterialCurrentStock4SystemSku;
|
|
|
import com.jsh.erp.exception.BusinessRunTimeException;
|
|
|
+import com.jsh.erp.utils.HttpClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @Description TODO
|
|
@@ -52,6 +57,15 @@ public class SyncTescoSystemService {
|
|
|
@Resource
|
|
|
private SupplierService supplierService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MaterialCurrentStockMapperEx materialCurrentStockMapperEx;
|
|
|
+
|
|
|
+ @Value("${tesco.sycnErpMaterialStockUrl}")
|
|
|
+ private String sycnErpMaterialStockUrl;
|
|
|
+
|
|
|
+ @Value("${tesco.sycnErpMaterialPriceUrl}")
|
|
|
+ private String sycnErpMaterialPriceUrl;
|
|
|
+
|
|
|
public String syncSystemSku(String param) {
|
|
|
logger.info("获取商品系统sku,返回信息集采系统 param:{}", param);
|
|
|
JSONObject result = new JSONObject();
|
|
@@ -176,6 +190,118 @@ public class SyncTescoSystemService {
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
|
|
|
+ public String sycnTescoStock(Long mId){
|
|
|
+ return sycnTescoStock(Arrays.asList(mId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public String sycnTescoStock(List<Long> mIdList) {
|
|
|
+ List<MaterialCurrentStock4SystemSku> stockList = materialCurrentStockMapperEx.getCurrentStockMapByMdIdList(mIdList);
|
|
|
+ if (!CollectionUtils.isEmpty(stockList)) {
|
|
|
+ try {
|
|
|
+ for (MaterialCurrentStock4SystemSku stock : stockList) {
|
|
|
+ Unit unitInfo = new Unit(); // 查询多单位信息
|
|
|
+ stock.setBasicUnit(stock.getUnit());
|
|
|
+ stock.setBasicUnitTotalStock(stock.getBasicUnitTotalStock().setScale(0, RoundingMode.DOWN));
|
|
|
+ if (stock.getUnitId() != null) {
|
|
|
+ unitInfo = materialService.findUnit(stock.getMId());
|
|
|
+ stock.setBasicUnit(unitInfo.getBasicUnit());
|
|
|
+ stock.setLargeUnit(true);
|
|
|
+ processOtherUnitStock(stock, unitInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String jsonParam = new ObjectMapper().writeValueAsString(stockList);
|
|
|
+ logger.info("同步集采库存请求参数:{}", jsonParam);
|
|
|
+ String response = HttpClient.httpPost(sycnErpMaterialStockUrl, jsonParam);
|
|
|
+ logger.info("同步集采库存响应:{}", response);
|
|
|
+ return jsonParam;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processOtherUnitStock(MaterialCurrentStock4SystemSku stock, Unit unitInfo) {
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnit())) {
|
|
|
+ BigDecimal otherUnitTotalStock = stock.getBasicUnitTotalStock().divide(unitInfo.getRatio(), 0, RoundingMode.DOWN);
|
|
|
+ String otherUnitStr = "1" + unitInfo.getOtherUnit() + "=" + unitInfo.getRatio().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnit(otherUnitStr);
|
|
|
+ stock.setRatio(unitInfo.getRatio().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitTotalStock(otherUnitTotalStock);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnitTwo())) {
|
|
|
+ BigDecimal otherUnitTwoTotalStock = stock.getBasicUnitTotalStock().divide(unitInfo.getRatioTwo(), 0, RoundingMode.DOWN);
|
|
|
+ String otherUnitTwoStr = "1" + unitInfo.getOtherUnitTwo() + "=" + unitInfo.getRatioTwo().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnitTwo(otherUnitTwoStr);
|
|
|
+ stock.setRatioTwo(unitInfo.getRatioTwo().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitTwoTotalStock(otherUnitTwoTotalStock);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnitThree())) {
|
|
|
+ BigDecimal otherUnitThreeTotalStock = stock.getBasicUnitTotalStock().divide(unitInfo.getRatioThree(), 0, RoundingMode.DOWN);
|
|
|
+ String otherUnitThreeStr = "1" + unitInfo.getOtherUnitThree() + "=" + unitInfo.getRatioThree().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnitTwo(otherUnitThreeStr);
|
|
|
+ stock.setRatioThree(unitInfo.getRatioThree().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitThreeTotalStock(otherUnitThreeTotalStock);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String sycnTescoSalePrice(List<Long> mIdList) {
|
|
|
+ try {
|
|
|
+ List<MaterialCurrentStock4SystemSku> mList = materialService.getMaterialCurrentPriceByIdList(mIdList);
|
|
|
+ if (!CollectionUtils.isEmpty(mList)) {
|
|
|
+ for (MaterialCurrentStock4SystemSku material : mList){
|
|
|
+ Unit unitInfo = new Unit(); // 查询多单位信息
|
|
|
+ material.setBasicUnit(material.getUnit());
|
|
|
+ if (material.getUnitId() != null) {
|
|
|
+ unitInfo = materialService.findUnit(material.getMId());
|
|
|
+ material.setBasicUnit(unitInfo.getBasicUnit());
|
|
|
+ material.setLargeUnit(true);
|
|
|
+
|
|
|
+ processOtherUnitSalePrice(material, unitInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String jsonParam = new ObjectMapper().writeValueAsString(mList);
|
|
|
+ logger.info("同步集采销售价格请求参数:{}", jsonParam);
|
|
|
+ String response = HttpClient.httpPost(sycnErpMaterialPriceUrl, jsonParam);
|
|
|
+ logger.info("同步集采销售价格响应:{}", response);
|
|
|
+ return jsonParam;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processOtherUnitSalePrice(MaterialCurrentStock4SystemSku stock, Unit unitInfo) {
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnit())) {
|
|
|
+ BigDecimal otherUnitSalePrice = stock.getBasicUnitSalePrice().multiply(unitInfo.getRatio());
|
|
|
+ String otherUnitStr = "1" + unitInfo.getOtherUnit() + "=" + unitInfo.getRatio().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnit(otherUnitStr);
|
|
|
+ stock.setRatio(unitInfo.getRatio().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitSalePrice(otherUnitSalePrice);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnitTwo())) {
|
|
|
+ BigDecimal otherUnitTwoSalePrice = stock.getBasicUnitSalePrice().multiply(unitInfo.getRatioTwo());
|
|
|
+ String otherUnitTwoStr = "1" + unitInfo.getOtherUnitTwo() + "=" + unitInfo.getRatioTwo().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnitTwo(otherUnitTwoStr);
|
|
|
+ stock.setRatioTwo(unitInfo.getRatioTwo().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitTwoSalePrice(otherUnitTwoSalePrice);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(unitInfo.getOtherUnitThree())) {
|
|
|
+ BigDecimal otherUnitThreeSalePrice = stock.getBasicUnitSalePrice().multiply(unitInfo.getRatioThree());
|
|
|
+ String otherUnitThreeStr = "1" + unitInfo.getOtherUnitThree() + "=" + unitInfo.getRatioThree().setScale(0, RoundingMode.DOWN) + unitInfo.getBasicUnit();
|
|
|
+ stock.setOtherUnitTwo(otherUnitThreeStr);
|
|
|
+ stock.setRatioThree(unitInfo.getRatioThree().setScale(0, RoundingMode.DOWN));
|
|
|
+ stock.setOtherUnitThreeSalePrice(otherUnitThreeSalePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
|
|
private void buildOrderAndItem(ErpXsddReqVO erpXsddReqVO) throws Exception {
|
|
|
// 1. 初始化订单基本信息
|
|
@@ -200,6 +326,7 @@ public class SyncTescoSystemService {
|
|
|
if (supplier == null) {
|
|
|
// 如果客户不存在,创建新客户
|
|
|
supplier = new Supplier();
|
|
|
+ supplier.setEnabled(true);
|
|
|
supplier.setSupplier(customer.getName());
|
|
|
supplier.setTelephone(customer.getAccount());
|
|
|
supplier.setContacts(customer.getReceiverName());
|