Browse Source

计算客诉单中财务复核表合计数据、 MAR单Excel导出

turujie 1 year ago
parent
commit
bb047881ca

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ExportService.java

@@ -9,4 +9,7 @@ import java.util.List;
 public interface ExportService {
 
     void exportComProductListTempWord(List<String> ids, HttpServletResponse response);
+
+    void comProductListTempExcel(List<String> ids, HttpServletResponse response);
+
 }

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ComMetalFinanceItemServiceImpl.java

@@ -21,6 +21,7 @@ import com.rongwei.bscommon.sys.service.ComMetalFinanceRecheckItemService;
 import com.rongwei.bscommon.sys.service.ComMetalProductService;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.base.exception.CustomException;
+import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -41,6 +42,7 @@ import java.util.stream.Collectors;
  * @author trj
  * @since 2023-07-15
  */
+@Log4j2
 @Service
 public class ComMetalFinanceItemServiceImpl extends ServiceImpl<ComMetalFinanceItemDao, ComMetalFinanceItemDo> implements ComMetalFinanceItemService {
 
@@ -101,6 +103,7 @@ public class ComMetalFinanceItemServiceImpl extends ServiceImpl<ComMetalFinanceI
         if (StrUtil.isEmpty(request.getCustomerId()) && ArrayUtil.isEmpty(request.getFinalWeightVos())) {
             return R.error("数据不存在");
         }
+        log.info("计算复核数据请求信息 -- > {}",request.getFinalWeightVos());
         //获取客诉单信息
         ComCustomerDo customer = customerService.getById(request.getCustomerId());
 

+ 173 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ExportServiceImpl.java

@@ -4,6 +4,9 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.aspose.cells.SaveFormat;
+import com.aspose.cells.Workbook;
+import com.aspose.cells.WorkbookDesigner;
 import com.aspose.words.Document;
 import com.aspose.words.MailMergeCleanupOptions;
 import com.aspose.words.net.System.Data.DataRow;
@@ -11,12 +14,15 @@ import com.aspose.words.net.System.Data.DataTable;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.bsentity.domin.ComCustomerDo;
 import com.bsentity.dto.ComExportMasterDto;
+import com.bsentity.dto.ComProTempExcelDto;
 import com.bsentity.dto.ComProductExportDto;
 import com.bsentity.vo.ComProTempWordVo;
+import com.bsentity.vo.HashMapDataTableVo;
 import com.rongwei.bscommon.sys.service.ComCustomerService;
 import com.rongwei.bscommon.sys.service.ExportService;
 import com.rongwei.bscommon.sys.utils.AsposeWordsUtils;
 import com.rongwei.rwcommon.base.exception.CustomException;
+import lombok.Data;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -85,6 +91,173 @@ public class ExportServiceImpl implements ExportService {
         }
     }
 
+
+    /**
+     *  excel 导出
+     * @param ids
+     * @param response
+     */
+    @Override
+    public void comProductListTempExcel(List<String> ids, HttpServletResponse response) {
+        AsposeWordsUtils.getExcelLicense();
+        ClassPathResource classPathResource = new ClassPathResource("template/comProductListTemp.xlsx");
+        try {
+
+            response.setContentType("application/octet-stream;charset=utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=comProductListTemp.xlsx");
+            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+
+            // 数据准备
+            ComProTempExcelDto comProTempExcelDto = getComProTempExcelVo(ids);
+
+            Workbook wb = getWork(classPathResource , comProTempExcelDto );
+
+            wb.save(response.getOutputStream(), SaveFormat.XLSX);
+            wb.dispose();
+
+
+
+            // 设置打印编号
+            comCustomerService.updatePrintNoByIds(ids,"'"+comProTempExcelDto.getPrintNo()+"'");
+
+        }catch (Exception e){
+            e.printStackTrace();
+            log.error(e.getMessage());
+            throw new CustomException("MAR单Excel导出异常");
+        }
+
+    }
+
+    /**
+     * 将数据塞入模板
+     * @param classPathResource 模板
+     * @param comProTempExcelDto 业务数据
+     * @return 数据表
+     */
+    private Workbook getWork(ClassPathResource classPathResource, ComProTempExcelDto comProTempExcelDto) throws Exception{
+
+        Workbook wb = new Workbook(classPathResource.getInputStream());
+        WorkbookDesigner designer = new WorkbookDesigner();
+        designer.setWorkbook(wb);
+        designer.setDataSource("PRINTNO", comProTempExcelDto.getPrintNo());
+        designer.setDataSource("CUSTOMERNAME", comProTempExcelDto.getCustomerName());
+        designer.setDataSource("COMNO", comProTempExcelDto.getComNo());
+        designer.setDataSource("CUSTOMERUSERNAME", comProTempExcelDto.getCustomerUserName());
+        designer.setDataSource("PRODUCTENGINEERNAME", comProTempExcelDto.getProductEngineerName());
+        designer.setDataSource("CUSTOMERPHONE", comProTempExcelDto.getCustomerPhone());
+        designer.setDataSource("CREATEUSERNAME", comProTempExcelDto.getCreatUserName());
+        designer.setDataSource("DATENOW", comProTempExcelDto.getDateNow());
+        designer.setDataSource("TOTALMARWEIGHT", comProTempExcelDto.getTotalMraWeight());
+
+        // 子表数据
+        List<Map<String, Object>> listMap = new ArrayList<>();
+        Map<String, Object> dataMap;
+        List<ComProductExportDto> comProductExportDtos = comProTempExcelDto.getComProductExportDtos();
+        for (ComProductExportDto comProductExportDto : comProductExportDtos) {
+            dataMap = new HashMap<>();
+            dataMap.put("NO",comProductExportDto.getNo());
+            dataMap.put("ORIORDERNO",comProductExportDto.getOriOrderNo());
+            dataMap.put("ALLOY",comProductExportDto.getAlloy());
+            dataMap.put("ISSTATUS",comProductExportDto.getIsStatus());
+            dataMap.put("SPECIFICATIONS",comProductExportDto.getSpecifications());
+            dataMap.put("MRAWEIGHT",comProductExportDto.getMraWeight());
+            dataMap.put("DEFECT",comProductExportDto.getDefect());
+            listMap.add(dataMap);
+        }
+
+        designer.setDataSource("LIST", new HashMapDataTableVo(listMap));
+        designer.process();
+        return wb;
+    }
+
+
+    /**
+     * 数据准备
+     * @param ids 主表ids集合
+     * @return 模板数据
+     */
+    private ComProTempExcelDto getComProTempExcelVo(List<String> ids) {
+        ComProTempExcelDto comProTempExcelDto = new ComProTempExcelDto();
+        if (ArrayUtil.isEmpty(ids)) {
+            return comProTempExcelDto;
+        }
+
+        // 查询主表信息
+        ComExportMasterDto comExportMasterDto = comCustomerService.getCustomerByIds(ids);
+        if (ObjectUtil.isEmpty(comExportMasterDto)) {
+            return comProTempExcelDto;
+        }
+        // 数据转换
+        comDtos(comProTempExcelDto , comExportMasterDto);
+
+
+        /************************************ 子表信息 *****************************/
+
+        // 根据id 查询 客诉单信息
+        List<ComProductExportDto> comProductExportDtos = comCustomerService.getProductByIds(ids);
+        if (ArrayUtil.isEmpty(comProductExportDtos)) {
+            return comProTempExcelDto;
+        }
+        comProTempExcelDto.setComProductExportDtos(comProductExportDtos);
+
+
+        // 计算 MRA重量总和
+        BigDecimal totalMraWeight = comProductExportDtos.stream().map(ComProductExportDto::getMraWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        comProTempExcelDto.setTotalMraWeight(totalMraWeight);
+
+        return comProTempExcelDto;
+    }
+
+    /**
+     * 数据转换
+     * @param comProTempExcelDto 模板数据
+     * @param comExportMasterDto 主表数据
+     */
+    private void comDtos(ComProTempExcelDto comProTempExcelDto, ComExportMasterDto comExportMasterDto) {
+        String printNo = null;
+        //  最大 打印号
+        ComCustomerDo comCustomerDo = comCustomerService.getBaseMapper()
+                .selectOne(
+                        new LambdaQueryWrapper<ComCustomerDo>()
+                                .select(ComCustomerDo::getPrintNo)
+                                .orderByDesc(ComCustomerDo::getPrintNo)
+                                .last("LIMIT 1")
+
+                );
+
+        // 编号:规则(MRA+年份+序号)。例如,当年导出的第一个MRA就是MRA23001,导出的第二个就是MRA23002,按照年份以此递增
+        String year = String.valueOf(DateUtil.year(new Date())).substring(2);
+        if (ObjectUtil.isEmpty(comCustomerDo)) {
+            printNo = "MRA" + year + "001";
+        }else  {
+            printNo = comCustomerDo.getPrintNo();
+            // 不为空
+            String number = printNo.substring(3);
+            Integer no = Integer.parseInt(number) + 1;
+            String y = String.valueOf(no).substring(0, 2);
+            //  跨年了。年份加一,从001开始计算
+            if (y.equals(year)) {
+                // 未跨年
+                printNo = "MRA" + no;
+            } else {
+                printNo = "MRA" + year + "001";
+            }
+
+        }
+
+
+        // 赋值
+        comProTempExcelDto.setPrintNo(printNo);
+        comProTempExcelDto.setComNo(comExportMasterDto.getComNo());
+        comProTempExcelDto.setCustomerUserName(comExportMasterDto.getCustomerUserName());
+        comProTempExcelDto.setCustomerName(comExportMasterDto.getCustomerName());
+        comProTempExcelDto.setCustomerPhone(comExportMasterDto.getCustomerPhone());
+        comProTempExcelDto.setCreatUserName(comExportMasterDto.getCreateUserName());
+        comProTempExcelDto.setDateNow(DateUtil.formatDate(comExportMasterDto.getDateNow()));
+        comProTempExcelDto.setProductEngineerName(comExportMasterDto.getProductEngineerName());
+    }
+
     /**
      * 数据准备
      *

+ 64 - 0
business-entity/src/main/java/com/bsentity/dto/ComProTempExcelDto.java

@@ -0,0 +1,64 @@
+package com.bsentity.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 导出数据
+ */
+@Data
+public class ComProTempExcelDto implements Serializable {
+
+    /**
+     * 编号
+     */
+    private String printNo;
+
+    /**
+     * 客户名称
+     */
+    private String customerName;
+
+    /**
+     *  投诉编号
+     */
+    private String comNo;
+
+    /**
+     * 收件人
+     */
+    private String customerUserName;
+
+    /**
+     * 发件人
+     */
+    private String creatUserName;
+
+    /**
+     * 日期
+     */
+    private String dateNow;
+
+    /**
+     *  联系人电话
+     */
+    private String customerPhone;
+
+    /**
+     * 联系人
+     */
+    private String productEngineerName;
+
+    /**
+     * 总和
+     */
+    private BigDecimal  totalMraWeight;
+
+    /**
+     * 退回材料信息
+     */
+    List<ComProductExportDto> comProductExportDtos;
+}

+ 100 - 0
business-entity/src/main/java/com/bsentity/vo/HashMapDataTableVo.java

@@ -0,0 +1,100 @@
+package com.bsentity.vo;
+
+import com.aspose.cells.ICellsDataTable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * 实现ICellsDataTable接口
+ * 以便支持对HashMap的支持
+ */
+public class HashMapDataTableVo implements ICellsDataTable {
+
+    //数据集合
+    private List<Map<String, Object>> dataList = null;
+
+    //索引
+    private int index;
+
+    //存放dataList当中Map<String, Object>的key
+    private String[] columns = null;
+
+    public HashMapDataTableVo(Map<String, Object> data) {
+        if(this.dataList == null) {
+            this.dataList = new ArrayList<Map<String,Object>>();
+        }
+        dataList.add(data);
+    }
+
+    public HashMapDataTableVo(List<Map<String, Object>> data) {
+        this.dataList = data;
+    }
+
+    /**
+     * 初始化方法
+     */
+    @Override
+    public void beforeFirst() {
+        index = -1;
+        columns = this.getColumns();
+    }
+
+    /**
+     * WorkbookDesigner自动调用
+     * 会将this.getColumns()方法所返回的列 按照顺序调用改方法
+     */
+    @Override
+    public Object get(int columnIndex) {
+        if(index < 0 || index >= this.getCount()) {
+            return null;
+        }
+        Map<String, Object> record = this.dataList.get(index);
+        String columnName = this.columns[columnIndex];
+        return record.get(columnName);
+    }
+
+    /**
+     * 根据columnName返回数据
+     */
+    @Override
+    public Object get(String columnName) {
+        Map<String, Object> record = this.dataList.get(index);
+        return record.get(columnName);
+    }
+
+    /**
+     * 获得列集合
+     */
+    @Override
+    public String[] getColumns() {
+        if(this.dataList ==null || this.dataList.isEmpty()){
+            return new String[0];
+        }
+        Map<String, Object> temp = this.dataList.get(0);
+        Set<Entry<String, Object>> entrys = temp.entrySet();
+        List<String> columns = new ArrayList<String>();
+        for (Entry<String, Object> e : entrys) {
+            columns.add(e.getKey());
+        }
+        String[] s = new String[entrys.size()];
+        columns.toArray(s);
+        return s;
+    }
+
+    @Override
+    public int getCount() {
+        return this.dataList.size();
+    }
+
+    @Override
+    public boolean next() {
+        index += 1;
+        return index < this.getCount();
+    }
+
+}
+

+ 3 - 3
business-entity/src/main/resources/mybatis/ComCustomerDao.xml

@@ -66,8 +66,8 @@
         <result column="RECHECKPRICETOTALUSD" property="recheckpricetotalusd" />
         <result column="RECHECKOTHERCOSTRMB" property="recheckothercostrmb" />
         <result column="RECHECKOTHERCOSTUSD" property="recheckothercostusd" />
-        <result column="COMWEIGHT" property="comweight" />
-        <result column="FINALWEIGHT" property="finalweight" />
+        <result column="TOLCOMWEIGHT" property="tolcomweight" />
+        <result column="TOLFINALWEIGHT" property="tolfinalweight" />
         <result column="COMTYPE" property="comtype" />
         <result column="PRINTNO" property="printNo" />
     </resultMap>
@@ -119,7 +119,7 @@
 
 
     <update id="updatePrintNoByIds">
-        UPDATE com_customer SET PRINTNO = #{printNo}
+        UPDATE com_customer SET PRINTNO =  ${printNo}
         <where>
             <if test="ids != null  and ids.size > 0">
                 ID IN

+ 9 - 0
business-server/src/main/java/com/rongwei/controller/ExportController.java

@@ -34,4 +34,13 @@ public class ExportController {
 
         exportService.exportComProductListTempWord(ids,response);
     }
+
+    @PostMapping("excel/ptar")
+    public void comProductListTempExcel(@RequestBody List<String> ids , HttpServletResponse response){
+        log.info("客诉单id Word导出 接口入参:{}",ids);
+
+        exportService.comProductListTempExcel(ids,response);
+
+    }
+
 }