24282 há 9 meses atrás
pai
commit
d128aaf23f

+ 12 - 2
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/controller/jd/JdRefundController.java

@@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 
 /**
@@ -41,7 +43,7 @@ public class JdRefundController {
      */
     @PostMapping("confirm")
     public void confirm(@RequestBody JdRefundDto dto) {
-        JdRefundService.confirm(dto);
+        JdRefundService.confirm(dto.getId());
     }
 
     /**
@@ -49,7 +51,15 @@ public class JdRefundController {
      */
     @PostMapping("cancelConfirm")
     public void cancelConfirm(@RequestBody JdRefundDto dto) {
-        JdRefundService.cancelConfirm(dto);
+        JdRefundService.cancelConfirm(dto.getId());
+    }
+
+    /**
+     * 售后退货确认Excel导入
+     */
+    @PostMapping("/confirmExcelImport")
+    public void confirmExcelImport(@RequestParam("file") MultipartFile file) {
+        JdRefundService.confirmExcelImport(file);
     }
 
 }

+ 11 - 0
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/controller/jd/JdRefundNotQualityCheckController.java

@@ -9,7 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -45,4 +47,13 @@ public class JdRefundNotQualityCheckController {
         jdRefundNotQualityCheckService.submitQualityCheck(dto);
     }
 
+    /**
+     * 京东售后退货待质检导入列表
+     */
+    @PostMapping("/excelList")
+    public List<JdRefundNotQualityCheckVo> excelList(@RequestParam("file") MultipartFile file) {
+        return jdRefundNotQualityCheckService.excelList(file);
+    }
+
+
 }

+ 15 - 0
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/entity/jd/vo/JdRefundNotQualityCheckVo.java

@@ -19,4 +19,19 @@ public class JdRefundNotQualityCheckVo extends JdRefundNotQualityCheck {
     private String productSpec;
     private String productUnit;
 
+    /**
+     * 报废转良品数量
+     */
+    private Integer qualifiedCount;
+
+    /**
+     * 报废转次品数量
+     */
+    private Integer defectiveCount;
+
+    /**
+     * 最终报废数量
+     */
+    private Integer scrappedCount;
+
 }

+ 6 - 0
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/jd/JdRefundNotQualityCheckService.java

@@ -6,6 +6,7 @@ import com.fjhx.victoriatourist.entity.jd.po.JdRefundNotQualityCheck;
 import com.fjhx.victoriatourist.entity.jd.po.JdRefundQualityCheck;
 import com.fjhx.victoriatourist.entity.jd.vo.JdRefundNotQualityCheckVo;
 import com.ruoyi.common.core.service.BaseService;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -30,4 +31,9 @@ public interface JdRefundNotQualityCheckService extends BaseService<JdRefundNotQ
      */
     void submitQualityCheck(List<JdRefundQualityCheck> dto);
 
+    /**
+     * 京东售后退货待质检导入列表
+     */
+    List<JdRefundNotQualityCheckVo> excelList(MultipartFile file);
+
 }

+ 5 - 3
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/jd/JdRefundService.java

@@ -1,11 +1,11 @@
 package com.fjhx.victoriatourist.service.jd;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.victoriatourist.entity.jd.dto.JdRefundDto;
 import com.fjhx.victoriatourist.entity.jd.dto.JdRefundSelectDto;
 import com.fjhx.victoriatourist.entity.jd.po.JdRefund;
 import com.fjhx.victoriatourist.entity.jd.vo.JdRefundVo;
 import com.ruoyi.common.core.service.BaseService;
+import org.springframework.web.multipart.MultipartFile;
 
 
 /**
@@ -20,8 +20,10 @@ public interface JdRefundService extends BaseService<JdRefund> {
 
     Page<JdRefundVo> getPage(JdRefundSelectDto dto);
 
-    void confirm(JdRefundDto dto);
+    void confirm(Long id);
 
-    void cancelConfirm(JdRefundDto dto);
+    void cancelConfirm(Long id);
+
+    void confirmExcelImport(MultipartFile file);
 
 }

+ 20 - 18
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/jd/impl/JdApiServiceImpl.java

@@ -162,6 +162,22 @@ public class JdApiServiceImpl implements JdApiService {
     @Resource
     private JdClient jdClient;
 
+    /**
+     * 请求API工具方法
+     */
+    private static JSONObject getJSON(HttpRequestBase httpRequestBase) throws IOException {
+        HttpClient client = HttpClients.createDefault();
+        httpRequestBase.setConfig(RequestConfig.custom().setConnectTimeout(3000).build());
+        HttpResponse response = client.execute(httpRequestBase);
+        int statusCode = response.getStatusLine().getStatusCode();
+        HttpEntity entity = response.getEntity();
+        String responseStr = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
+        if (statusCode != 200) {
+            log.error("请求失败 {} {} {}", statusCode, httpRequestBase.getURI(), responseStr);
+        }
+        return JSONObject.parseObject(responseStr);
+    }
+
     //每小时执行一次
     @Scheduled(cron = "0 0 0/1 * * ?")
     public void refreshToken() {
@@ -598,7 +614,10 @@ public class JdApiServiceImpl implements JdApiService {
             }
 
             List<JdRefundDetail> data = result.getData();
-            data.forEach(item -> item.setJdRefundId(jdRefund.getId()));
+            data.forEach(item -> {
+                item.setJdRefundId(jdRefund.getId());
+                item.setStatus(0);
+            });
             jdRefundDetails.addAll(data);
         }
 
@@ -628,7 +647,6 @@ public class JdApiServiceImpl implements JdApiService {
                 .getJSONObject("result");
     }
 
-
     private List<JdRefund> getRefundInfoList(Date startTime, Date endTime) throws Exception {
         int pageIndex = 1;
         int pageSize = 50;
@@ -646,22 +664,6 @@ public class JdApiServiceImpl implements JdApiService {
         return list;
     }
 
-    /**
-     * 请求API工具方法
-     */
-    private static JSONObject getJSON(HttpRequestBase httpRequestBase) throws IOException {
-        HttpClient client = HttpClients.createDefault();
-        httpRequestBase.setConfig(RequestConfig.custom().setConnectTimeout(3000).build());
-        HttpResponse response = client.execute(httpRequestBase);
-        int statusCode = response.getStatusLine().getStatusCode();
-        HttpEntity entity = response.getEntity();
-        String responseStr = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
-        if (statusCode != 200) {
-            log.error("请求失败 {} {} {}", statusCode, httpRequestBase.getURI(), responseStr);
-        }
-        return JSONObject.parseObject(responseStr);
-    }
-
     private boolean dealOrderDetail(JdOrder jdOrder, List<JdOrderDetails> jdOrderDetailsList) throws Exception {
 
         DynamicDataSourceContextHolder.push(SourceConstant.ITEM);

+ 72 - 0
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/jd/impl/JdRefundNotQualityCheckServiceImpl.java

@@ -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;
+    }
+
 }

+ 48 - 7
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/jd/impl/JdRefundServiceImpl.java

@@ -1,6 +1,9 @@
 package com.fjhx.victoriatourist.service.jd.impl;
 
 import cn.hutool.core.util.StrUtil;
+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.mybatisplus.core.toolkit.Wrappers;
@@ -9,7 +12,7 @@ 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.victoriatourist.entity.jd.dto.JdRefundDto;
+import com.fjhx.item.util.excel.util.ExcelUtil;
 import com.fjhx.victoriatourist.entity.jd.dto.JdRefundSelectDto;
 import com.fjhx.victoriatourist.entity.jd.po.JdRefund;
 import com.fjhx.victoriatourist.entity.jd.po.JdRefundDetail;
@@ -27,8 +30,10 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -105,17 +110,17 @@ public class JdRefundServiceImpl extends ServiceImpl<JdRefundMapper, JdRefund> i
 
     @DSTransactional
     @Override
-    public void confirm(JdRefundDto dto) {
-        JdRefundDetail jdRefundDetail = jdRefundDetailService.getById(dto.getId());
+    public void confirm(Long id) {
+        JdRefundDetail jdRefundDetail = jdRefundDetailService.getById(id);
         Assert.notEmpty(jdRefundDetail, "京东售后明细不存在");
 
         Integer status = jdRefundDetail.getStatus();
-        Assert.eqZero(status, "京东售后单已确认");
+        Assert.eqZero(status, "京东售后单已确认,备件条码:" + jdRefundDetail.getPartCode());
 
         // 获取产品编号
         String wareId = jdRefundDetail.getWareId();
         ProductInfo productInfo = productInfoService.getOne(q -> q.eq(ProductInfo::getCustomCode, wareId));
-        Assert.notEmpty(productInfo, "未知产品编码:" + wareId);
+        Assert.notEmpty(productInfo, "未知产品编码:" + wareId + ",备件条码:" + jdRefundDetail.getPartCode());
 
         // key: product_id  value:产品数量
         Map<Long, Integer> map = new HashMap<>();
@@ -180,8 +185,8 @@ public class JdRefundServiceImpl extends ServiceImpl<JdRefundMapper, JdRefund> i
 
     @DSTransactional
     @Override
-    public void cancelConfirm(JdRefundDto dto) {
-        JdRefundDetail jdRefundDetail = jdRefundDetailService.getById(dto.getId());
+    public void cancelConfirm(Long id) {
+        JdRefundDetail jdRefundDetail = jdRefundDetailService.getById(id);
         Assert.notEmpty(jdRefundDetail, "京东售后明细不存在");
 
         Integer status = jdRefundDetail.getStatus();
@@ -239,6 +244,42 @@ public class JdRefundServiceImpl extends ServiceImpl<JdRefundMapper, JdRefund> i
 
     }
 
+    @DSTransactional
+    @Override
+    public void confirmExcelImport(MultipartFile file) {
+
+        // 备件条码列表
+        List<String> partCodeList = new ArrayList<>();
+
+        EasyExcel.read(ExcelUtil.getInputStream(file)).sheet(0).registerReadListener(new AnalysisEventListener<Map<Integer, String>>() {
+
+            @Override
+            public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
+                partCodeList.add(map.get(0));
+            }
+
+            @Override
+            public void doAfterAllAnalysed(AnalysisContext context) {
+                //数据读取完毕
+            }
+        }).headRowNumber(1).doRead();
+
+        if (partCodeList.isEmpty()) {
+            return;
+        }
+
+        Map<String, Long> map = jdRefundDetailService.list(q -> q.in(JdRefundDetail::getPartCode, partCodeList))
+                .stream().collect(Collectors.toMap(JdRefundDetail::getPartCode, JdRefundDetail::getId));
+
+
+        for (String partCode : partCodeList) {
+            Long id = map.get(partCode);
+            Assert.notEmpty(id, "备件条码不存在:" + partCode);
+            confirm(id);
+        }
+
+    }
+
     /**
      * 赋值需要质检的商品
      */