|
@@ -1,11 +1,17 @@
|
|
|
package com.fjhx.victoriatourist.service.jd.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.victoriatourist.entity.jd.dto.JdRefundNotQualityCheckSelectDto;
|
|
|
import com.fjhx.victoriatourist.entity.jd.po.JdRefundNotQualityCheck;
|
|
|
import com.fjhx.victoriatourist.entity.jd.po.JdRefundQualityCheck;
|
|
@@ -16,12 +22,17 @@ import com.fjhx.victoriatourist.service.jd.JdRefundQualityCheckService;
|
|
|
import com.fjhx.victoriatourist.utils.CodeEnum;
|
|
|
import com.fjhx.wms.entity.stock.po.Stock;
|
|
|
import com.fjhx.wms.service.stock.StockService;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
@@ -139,4 +150,65 @@ public class JdRefundNotQualityCheckServiceImpl extends ServiceImpl<JdRefundNotQ
|
|
|
updateBatchById(list);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<JdRefundNotQualityCheckVo> excelList(MultipartFile file) {
|
|
|
+ // 备件条码列表
|
|
|
+ Map<String, JdRefundNotQualityCheckVo> JdRefundNotQualityCheckMap = new HashMap<>();
|
|
|
+
|
|
|
+ EasyExcel.read(ExcelUtil.getInputStream(file)).sheet(0).registerReadListener(new AnalysisEventListener<Map<Integer, String>>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
|
|
|
+ String productCustomCode = map.get(0);
|
|
|
+ Assert.notEmpty(productCustomCode, "存在物品编码为空的数据");
|
|
|
+
|
|
|
+ JdRefundNotQualityCheckVo vo = JdRefundNotQualityCheckMap.get(productCustomCode);
|
|
|
+ Assert.empty(vo, "物品编码重复:" + productCustomCode);
|
|
|
+
|
|
|
+ vo = new JdRefundNotQualityCheckVo();
|
|
|
+ vo.setProductCustomCode(productCustomCode);
|
|
|
+ vo.setQualifiedCount(Convert.toInt(map.get(1), 0));
|
|
|
+ vo.setDefectiveCount(Convert.toInt(map.get(2), 0));
|
|
|
+ vo.setScrappedCount(Convert.toInt(map.get(3), 0));
|
|
|
+
|
|
|
+ JdRefundNotQualityCheckMap.put(productCustomCode, vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
+ //数据读取完毕
|
|
|
+ }
|
|
|
+ }).headRowNumber(1).doRead();
|
|
|
+
|
|
|
+ if (JdRefundNotQualityCheckMap.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<JdRefundNotQualityCheckVo> list = new ArrayList<>(JdRefundNotQualityCheckMap.values());
|
|
|
+
|
|
|
+ Set<String> productCustomCodeSet = list.stream().map(JdRefundNotQualityCheckVo::getProductCustomCode).collect(Collectors.toSet());
|
|
|
+ List<ProductInfo> productInfoList = productInfoService.list(q -> q.in(ProductInfo::getCustomCode, productCustomCodeSet));
|
|
|
+ Assert.notEmpty(productInfoList, "物品编码不存在");
|
|
|
+
|
|
|
+ Map<String, ProductInfo> productInfoMap = productInfoList.stream().collect(Collectors.toMap(ProductInfo::getCustomCode, Function.identity()));
|
|
|
+
|
|
|
+ Set<Long> productIdSet = productInfoList.stream().map(BaseIdPo::getId).collect(Collectors.toSet());
|
|
|
+ Map<Long, Integer> productQuantityMap = list(q -> q.in(JdRefundNotQualityCheck::getProductId, productIdSet))
|
|
|
+ .stream().collect(Collectors.toMap(JdRefundNotQualityCheck::getProductId, JdRefundNotQualityCheck::getQuantity));
|
|
|
+
|
|
|
+ for (JdRefundNotQualityCheckVo item : list) {
|
|
|
+ ProductInfo productInfo = productInfoMap.get(item.getProductCustomCode());
|
|
|
+ Assert.notEmpty(productInfo, "物品编码不存在:" + item.getProductCustomCode());
|
|
|
+
|
|
|
+ item.setProductId(productInfo.getId());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductCustomCode(productInfo.getCustomCode());
|
|
|
+ item.setProductSpec(productInfo.getSpec());
|
|
|
+ item.setProductUnit(productInfo.getUnit());
|
|
|
+ item.setQuantity(productQuantityMap.getOrDefault(productInfo.getId(), 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|