|
@@ -6,6 +6,10 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -19,6 +23,7 @@ import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.kd100.entity.company.po.CompanyInfo;
|
|
|
import com.fjhx.kd100.service.company.CompanyInfoService;
|
|
|
+import com.fjhx.victoriatourist.entity.JdBatchOutStockBo;
|
|
|
import com.fjhx.victoriatourist.entity.abnormal.po.AbnormalInfo;
|
|
|
import com.fjhx.victoriatourist.entity.jd.bo.JdOrderExcelImportBo;
|
|
|
import com.fjhx.victoriatourist.entity.jd.dto.JdOrderDto;
|
|
@@ -41,6 +46,7 @@ import com.fjhx.victoriatourist.service.jd.JdOrderService;
|
|
|
import com.fjhx.victoriatourist.service.logistics.LogisticsInfosService;
|
|
|
import com.fjhx.victoriatourist.service.stock.StockTransferDetailsService;
|
|
|
import com.fjhx.victoriatourist.service.stock.StockTransferService;
|
|
|
+import com.fjhx.wms.entity.stock.dto.StockWaitDto;
|
|
|
import com.fjhx.wms.entity.stock.emums.JournalType;
|
|
|
import com.fjhx.wms.entity.stock.emums.StockWaitType;
|
|
|
import com.fjhx.wms.entity.stock.po.*;
|
|
@@ -57,6 +63,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.util.*;
|
|
@@ -708,6 +715,7 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
for (JdOrderDetailsVo jdOrderDetailsVo : jdOrderDetailsList) {
|
|
|
//创建待出库明细
|
|
|
StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setBusinessId(jdOrder.getId());
|
|
|
stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
stockWaitDetails.setBusinessDetailsId(jdOrderDetailsVo.getId());
|
|
|
stockWaitDetails.setProductId(jdOrderDetailsVo.getProductId());
|
|
@@ -814,4 +822,161 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
.set(JdOrder::getUpdateTime, new Date())
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ private List<Map<Integer, String>> readBatchOutExcel(MultipartFile file) {
|
|
|
+ //读取数据
|
|
|
+ List<Map<Integer, String>> list = new ArrayList<Map<Integer, String>>();
|
|
|
+ try {
|
|
|
+ EasyExcel.read(file.getInputStream()).sheet(0).registerReadListener(new AnalysisEventListener<Map<Integer, String>>() {
|
|
|
+ @Override
|
|
|
+ public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
|
|
|
+ list.add(integerStringMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ }
|
|
|
+ }).headRowNumber(0).doRead();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ServiceException("读取Excel文件异常!");
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getBatchOutExcelInfo(MultipartFile file) {
|
|
|
+ //读取数据
|
|
|
+ List<Map<Integer, String>> list = readBatchOutExcel(file);
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<String> collect = list.get(0).values().stream().collect(Collectors.toList());
|
|
|
+ collect.remove(0);
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchOutStock(MultipartFile file, Long warehouseId, JSONObject outInfo) {
|
|
|
+ //读取数据
|
|
|
+ List<Map<Integer, String>> list = readBatchOutExcel(file);
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ List<JdBatchOutStockBo> outList = new ArrayList<>();
|
|
|
+ Object[] titles = null;
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Map<Integer, String> items = list.get(i);
|
|
|
+
|
|
|
+ //标题数据
|
|
|
+ if (i == 0) {
|
|
|
+ titles = items.values().toArray();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //正文数据
|
|
|
+ for (int j = 1; j < titles.length; j++) {
|
|
|
+ if (items.get(j) == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JdBatchOutStockBo jdBatchOutStockBo = new JdBatchOutStockBo();
|
|
|
+ jdBatchOutStockBo.setOrderId(Long.parseLong((String) titles[j]));//订单号
|
|
|
+ jdBatchOutStockBo.setProductCode(items.get(0));//产品编号
|
|
|
+ jdBatchOutStockBo.setQuantity(new BigDecimal(items.get(j)));//出库数量
|
|
|
+
|
|
|
+ outList.add(jdBatchOutStockBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取基础信息集合
|
|
|
+ List<String> pCodes = outList.stream().map(JdBatchOutStockBo::getProductCode).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> jdOrderIds = outList.stream().map(JdBatchOutStockBo::getOrderId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ //赋值并校验 产品,京东订单 信息
|
|
|
+ List<String> errProductCodes = new ArrayList<>();
|
|
|
+ List<String> errJdOrderCodes = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String, Long> pInfoMap = productInfoService.mapKV(ProductInfo::getCustomCode, ProductInfo::getId, q -> q.in(ProductInfo::getCustomCode, pCodes));
|
|
|
+ Map<Long, Long> jdInfoMap = this.mapKV(JdOrder::getOrderId, JdOrder::getId, q -> q.in(JdOrder::getOrderId, jdOrderIds));
|
|
|
+
|
|
|
+ for (JdBatchOutStockBo teaBo : outList) {
|
|
|
+ //赋值并校验产品信息
|
|
|
+ String productCode = teaBo.getProductCode();
|
|
|
+ Long productId = pInfoMap.get(productCode);
|
|
|
+ if (ObjectUtil.isEmpty(productId)) {
|
|
|
+ errProductCodes.add(productCode);
|
|
|
+ }
|
|
|
+ teaBo.setProductId(productId);
|
|
|
+
|
|
|
+ //赋值并校验京东订单信息
|
|
|
+ Long orderId = teaBo.getOrderId();
|
|
|
+ Long jdInfoId = jdInfoMap.get(orderId);
|
|
|
+ if (ObjectUtil.isEmpty(jdInfoId)) {
|
|
|
+ errJdOrderCodes.add(String.valueOf(orderId));
|
|
|
+ }
|
|
|
+ teaBo.setOrderInfoId(jdInfoId);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(errProductCodes)) {
|
|
|
+ throw new ServiceException("无法查询到以下产品编号对应的产品信息,请检查:" + errProductCodes.stream().distinct().collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(errJdOrderCodes)) {
|
|
|
+ throw new ServiceException("无法查询到以下京东订单信息,请检查:" + errJdOrderCodes.stream().distinct().collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+
|
|
|
+ //封装待出库数据
|
|
|
+ List<Long> businessIds = outList.stream().map(JdBatchOutStockBo::getOrderInfoId).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> productIds = outList.stream().map(JdBatchOutStockBo::getProductId).distinct().collect(Collectors.toList());
|
|
|
+ List<StockWaitDetails> list1 = stockWaitDetailsService.list(q -> q
|
|
|
+ .in(StockWaitDetails::getBusinessId, businessIds)
|
|
|
+ .in(StockWaitDetails::getProductId, productIds)
|
|
|
+ );
|
|
|
+ ArrayList<StockWaitDetails> outStockWaitDetailsList = new ArrayList<>();
|
|
|
+ for (JdBatchOutStockBo teaBo : outList) {
|
|
|
+ StockWaitDetails dataBaseInfo = list1.stream().filter(item ->
|
|
|
+ item.getBusinessId().equals(teaBo.getOrderInfoId()) &&
|
|
|
+ item.getProductId().equals(teaBo.getProductId())
|
|
|
+ ).findFirst().orElse(null);
|
|
|
+// StockWaitDetails dataBaseInfo = stockWaitDetailsService.getOne(q -> q
|
|
|
+// .eq(StockWaitDetails::getBusinessId, teaBo.getOrderInfoId())
|
|
|
+// .eq(StockWaitDetails::getProductId, teaBo.getProductId())
|
|
|
+// );
|
|
|
+ if (ObjectUtil.isEmpty(dataBaseInfo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //数量校验
|
|
|
+ BigDecimal receiptQuantity = dataBaseInfo.getReceiptQuantity();
|
|
|
+ receiptQuantity = ObjectUtil.isEmpty(receiptQuantity) ? BigDecimal.ZERO : receiptQuantity;
|
|
|
+ if (receiptQuantity.add(teaBo.getQuantity()).compareTo(dataBaseInfo.getQuantity()) > 0) {
|
|
|
+ throw new ServiceException(String.format("订单号:%s,产品编号:%s 出库数量>待出库数量", teaBo.getOrderId(), teaBo.getProductCode()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成信息
|
|
|
+ StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setStockWaitId(dataBaseInfo.getStockWaitId());
|
|
|
+ stockWaitDetails.setId(dataBaseInfo.getId());
|
|
|
+ stockWaitDetails.setQuantity(teaBo.getQuantity());
|
|
|
+ stockWaitDetails.setJdOrderId(teaBo.getOrderId());
|
|
|
+ stockWaitDetails.setBusinessDetailsId(dataBaseInfo.getBusinessDetailsId());
|
|
|
+
|
|
|
+ outStockWaitDetailsList.add(stockWaitDetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ //操作待出库
|
|
|
+ Map<Long, List<StockWaitDetails>> outMap = outStockWaitDetailsList.stream().collect(Collectors.groupingBy(StockWaitDetails::getStockWaitId));
|
|
|
+ for (Map.Entry<Long, List<StockWaitDetails>> entry : outMap.entrySet()) {
|
|
|
+ StockWait dataBaseInfo = stockWaitService.getById(entry.getKey());
|
|
|
+
|
|
|
+ StockWaitDto stockWaitDto = outInfo.getObject(entry.getValue().get(0).getJdOrderId().toString(), StockWaitDto.class);
|
|
|
+ stockWaitDto.setId(entry.getKey());
|
|
|
+ stockWaitDto.setWarehouseId(warehouseId);
|
|
|
+ stockWaitDto.setStockWaitDetailsList(entry.getValue());
|
|
|
+ stockWaitDto.setBusinessId(dataBaseInfo.getBusinessId());
|
|
|
+
|
|
|
+ stockWaitService.addByWdly(stockWaitDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|