소스 검색

销售出库excel导出

24282 1 년 전
부모
커밋
12578bba9a

+ 8 - 0
sd-business/src/main/java/com/sd/business/controller/statement/StatementOfAccountMergeController.java

@@ -99,4 +99,12 @@ public class StatementOfAccountMergeController {
         return statementOfAccountMergeService.salesOutWarehouseDetails(dto);
     }
 
+    /**
+     * 销售出货明细
+     */
+    @PostMapping("/exportSalesOutWarehouseDetails")
+    public void exportSalesOutWarehouseDetails(@RequestBody SalesOutWarehouseDetailsDto dto) {
+        statementOfAccountMergeService.exportSalesOutWarehouseDetails(dto);
+    }
+
 }

+ 36 - 0
sd-business/src/main/java/com/sd/business/entity/statement/bo/ExportDocumentByOrderBo.java

@@ -13,6 +13,37 @@ import java.util.Date;
 public class ExportDocumentByOrderBo {
 
     /**
+     * 店铺名称
+     */
+    private String shopName;
+
+    /**
+     * 事业部名称
+     */
+    private String departmentName;
+
+    /**
+     * 对账时间
+     */
+    private Date statementOfAccountTime;
+
+    /**
+     * 定制加工类型
+     */
+    private String customProcessingType;
+
+    /**
+     * 分类父名称
+     */
+    private String classifyName;
+
+    /**
+     * 单位
+     */
+    private String unit;
+
+
+    /**
      * 万里牛订单创建时间
      */
     private Date wlnCreateTime;
@@ -23,6 +54,11 @@ public class ExportDocumentByOrderBo {
     private String code;
 
     /**
+     * mes单号
+     */
+    private String mesCode;
+
+    /**
      * 万里牛订单号
      */
     private String wlnCode;

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/statement/dto/SalesOutWarehouseDetailsDto.java

@@ -28,4 +28,9 @@ public class SalesOutWarehouseDetailsDto extends BaseSelectDto {
      */
     private String skuSpecName;
 
+    /**
+     * 是否查询总条数
+     */
+    private Boolean searchCount = true;
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountMergeService.java

@@ -55,4 +55,9 @@ public interface StatementOfAccountMergeService {
      */
     Page<DocumentByOrderVo> salesOutWarehouseDetails(SalesOutWarehouseDetailsDto dto);
 
+    /**
+     * 导出销售出货明细
+     */
+    void exportSalesOutWarehouseDetails(SalesOutWarehouseDetailsDto dto);
+
 }

+ 1 - 1
sd-business/src/main/java/com/sd/business/service/statement/impl/DocumentByOrderExcelCellMergeStrategy.java

@@ -38,7 +38,7 @@ public class DocumentByOrderExcelCellMergeStrategy extends AbstractMergeStrategy
 
             // 赋值订单无需合并的行
             Integer size = skuSpecList.stream().map(item -> item.getBomSpecList().size()).reduce(0, Integer::sum);
-            int orderRowIndexNumber = orderRowIndex.size() == 0 ? mergeRowIndex : orderRowIndex.get(orderRowIndex.size() - 1);
+            int orderRowIndexNumber = orderRowIndex.isEmpty() ? mergeRowIndex : orderRowIndex.get(orderRowIndex.size() - 1);
             orderRowIndex.add(size + orderRowIndexNumber);
 
             // 赋值sku无需合并的行

+ 100 - 0
sd-business/src/main/java/com/sd/business/service/statement/impl/SalesOutWarehouseDetailsExcelCellMergeStrategy.java

@@ -0,0 +1,100 @@
+package com.sd.business.service.statement.impl;
+
+import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.write.merge.AbstractMergeStrategy;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SalesOutWarehouseDetailsExcelCellMergeStrategy extends AbstractMergeStrategy {
+
+    // 最大行数
+    private final int maxRow;
+
+    // sku需要合并的列
+    private final List<Integer> skuColIndex = Arrays.asList(6, 7, 8, 22, 23);
+    // sku无需合并的行
+    private final List<Integer> skuRowIndex = new ArrayList<>();
+
+    // 订单需要合并的列
+    private final List<Integer> orderColIndex = Arrays.asList(0, 1, 2, 3, 4, 5, 24, 25);
+    // 订单无需合并的行
+    private final List<Integer> orderRowIndex = new ArrayList<>();
+
+    public SalesOutWarehouseDetailsExcelCellMergeStrategy(List<DocumentByOrderVo> documentByOrderVoList) {
+
+        // 无需合并的行数
+        int mergeRowIndex = 1;
+        skuRowIndex.add(mergeRowIndex);
+        orderRowIndex.add(mergeRowIndex);
+
+        for (DocumentByOrderVo documentByOrderVo : documentByOrderVoList) {
+            List<DocumentByOrderVo.SkuSpec> skuSpecList = documentByOrderVo.getSkuSpecList();
+
+            // 赋值订单无需合并的行
+            Integer size = skuSpecList.stream().map(item -> item.getBomSpecList().size()).reduce(0, Integer::sum);
+            int orderRowIndexNumber = orderRowIndex.isEmpty() ? mergeRowIndex : orderRowIndex.get(orderRowIndex.size() - 1);
+            orderRowIndex.add(size + orderRowIndexNumber);
+
+            // 赋值sku无需合并的行
+            for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
+                int bomSpecListSize = skuSpec.getBomSpecList().size();
+                int skuRowIndexSize = skuRowIndex.size();
+                int skuRowIndexNumber = skuRowIndexSize == 0 ? mergeRowIndex : skuRowIndex.get(skuRowIndexSize - 1);
+                skuRowIndex.add(bomSpecListSize + skuRowIndexNumber);
+            }
+        }
+
+        maxRow = skuRowIndex.get(skuRowIndex.size() - 1);
+    }
+
+    @Override
+    protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
+
+        // 当前行列
+        int curRowIndex = cell.getRowIndex();
+
+        // 判断是否是最后一行
+        if (curRowIndex != maxRow) {
+            return;
+        }
+
+        int curColIndex = cell.getColumnIndex();
+
+        // 合并订单列
+        if (orderColIndex.contains(curColIndex)) {
+            for (int i = 1; i < orderRowIndex.size(); i++) {
+                int beginRow = orderRowIndex.get(i - 1) + 1;
+                Integer endRow = orderRowIndex.get(i);
+                mergeWithPrevRow(sheet, beginRow, endRow, curColIndex);
+            }
+        }
+
+        // 合并sku列
+        else if (skuColIndex.contains(curColIndex)) {
+            for (int i = 1; i < skuRowIndex.size(); i++) {
+                int beginRow = skuRowIndex.get(i - 1) + 1;
+                Integer endRow = skuRowIndex.get(i);
+                mergeWithPrevRow(sheet, beginRow, endRow, curColIndex);
+            }
+        }
+
+    }
+
+    /**
+     * 合并单元格
+     */
+    private void mergeWithPrevRow(Sheet sheet, int beginRow, int endRow, int col) {
+        if (beginRow == endRow) {
+            return;
+        }
+        CellRangeAddress cellRangeAddress = new CellRangeAddress(beginRow, endRow, col, col);
+        sheet.addMergedRegionUnsafe(cellRangeAddress);
+    }
+
+}

+ 13 - 1
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountMergeServiceImpl.java

@@ -34,6 +34,7 @@ import com.sd.business.service.statement.StatementOfAccountExportService;
 import com.sd.business.service.statement.StatementOfAccountMergeService;
 import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.business.strategy.impl.DocumentByOrderExcelExportStrategy;
+import com.sd.business.strategy.impl.SalesOutWarehouseDetailsExportStrategy;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -257,8 +258,11 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
             orderIdList = orderSkuList.stream().map(OrderSku::getOrderId).collect(Collectors.toList());
         }
 
+        Page<OrderInfo> page = dto.getPage();
+        page.setSearchCount(dto.getSearchCount());
+
         // 查询订单分页
-        Page<OrderInfo> page = orderService.page(dto.getPage(), Wrappers.lambdaQuery(OrderInfo.class)
+        orderService.page(page, Wrappers.lambdaQuery(OrderInfo.class)
                 .in(ObjectUtil.isNotEmpty(orderIdList), BaseIdPo::getId, orderIdList)
                 .in(ObjectUtil.isNotEmpty(statementOfAccountIdList), OrderInfo::getStatementOfAccountId, statementOfAccountIdList)
                 .isNotNull(ObjectUtil.isEmpty(statementOfAccountIdList), OrderInfo::getStatementOfAccountId)
@@ -304,6 +308,14 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
         return result;
     }
 
+    @Override
+    public void exportSalesOutWarehouseDetails(SalesOutWarehouseDetailsDto dto) {
+
+        excelGenerateLogService.generateExcel(ExcelTypeEnum.STATISTICS_DOCUMENT_BY_ORDER,
+                new SalesOutWarehouseDetailsExportStrategy(this, dto),
+                DateUtil.formatDate(new Date()) + " 销售出货明细");
+    }
+
     private List<Long> getIdList(GetDocumentDto dto) {
 
         String idGroupConcat = dto.getIdGroupConcat();

+ 153 - 0
sd-business/src/main/java/com/sd/business/strategy/impl/SalesOutWarehouseDetailsExportStrategy.java

@@ -0,0 +1,153 @@
+package com.sd.business.strategy.impl;
+
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.IoUtil;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.metadata.fill.FillConfig;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.exception.ServiceException;
+import com.sd.business.entity.statement.bo.ExportDocumentByOrderBo;
+import com.sd.business.entity.statement.dto.SalesOutWarehouseDetailsDto;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import com.sd.business.service.statement.impl.SalesOutWarehouseDetailsExcelCellMergeStrategy;
+import com.sd.business.service.statement.impl.StatementOfAccountMergeServiceImpl;
+import com.sd.business.strategy.ExcelExportStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.*;
+import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+
+/**
+ * 订单对账单
+ */
+@Slf4j
+public class SalesOutWarehouseDetailsExportStrategy implements ExcelExportStrategy<Map<String, Object>> {
+
+    private final SalesOutWarehouseDetailsDto dto;
+    private final StatementOfAccountMergeServiceImpl service;
+
+    private List<DocumentByOrderVo> list;
+
+    public SalesOutWarehouseDetailsExportStrategy(StatementOfAccountMergeServiceImpl service, SalesOutWarehouseDetailsDto dto) {
+        this.service = service;
+        this.dto = dto;
+    }
+
+    @Override
+    public Map<String, Object> getData() {
+
+        dto.setPageNum(1);
+        dto.setPageSize(999999999);
+        dto.setSearchCount(false);
+        Page<DocumentByOrderVo> documentByOrderVoPage = service.salesOutWarehouseDetails(dto);
+        list = documentByOrderVoPage.getRecords();
+
+        BigDecimal all = BigDecimal.ZERO;
+
+        List<ExportDocumentByOrderBo> exportDocumentByOrderBos = new ArrayList<>();
+        for (DocumentByOrderVo documentByOrderVo : list) {
+            List<DocumentByOrderVo.SkuSpec> skuSpecList = documentByOrderVo.getSkuSpecList();
+            for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
+                List<DocumentByOrderVo.BomSpec> bomSpecList = skuSpec.getBomSpecList();
+                for (DocumentByOrderVo.BomSpec bomSpec : bomSpecList) {
+                    ExportDocumentByOrderBo exportDocumentByOrderBo = ExportDocumentByOrderBo.builder()
+                            .skuSpecCode(skuSpec.getSkuSpecCode())
+                            .skuSpecName(skuSpec.getSkuSpecName())
+                            .quantity(skuSpec.getQuantity())
+                            .unitPrice(skuSpec.getUnitPrice())
+                            .subtotal(skuSpec.getSubtotal())
+                            .wlnCreateTime(documentByOrderVo.getWlnCreateTime())
+                            .wlnCode(documentByOrderVo.getWlnCode())
+                            .outerBoxPackingFee(documentByOrderVo.getOuterBoxPackingFee())
+                            .total(documentByOrderVo.getTotal())
+                            .bomSpecCode(bomSpec.getBomSpecCode())
+                            .bomSpecName(bomSpec.getBomSpecName())
+                            .bomQuantity(bomSpec.getQuantity())
+                            .bomUnitPrice(bomSpec.getUnitPrice())
+                            .laserLogoSummary(bomSpec.getLaserLogoSummary())
+                            .laserMitochondrialSummary(bomSpec.getLaserMitochondrialSummary())
+                            .lssueFeeSummary(bomSpec.getLssueFeeSummary())
+                            .deliveryMaterialsFeeSummary(bomSpec.getDeliveryMaterialsFeeSummary())
+                            .packingLaborSummary(bomSpec.getPackingLaborSummary())
+                            .managementFeeSummary(bomSpec.getManagementFeeSummary())
+
+                            .shopName(documentByOrderVo.getShopName())
+                            .departmentName(documentByOrderVo.getDepartmentName())
+                            .statementOfAccountTime(documentByOrderVo.getStatementOfAccountTime())
+                            .code(documentByOrderVo.getWlnCode() == null ? null : documentByOrderVo.getCode())
+                            .mesCode(documentByOrderVo.getWlnCode() == null ? documentByOrderVo.getCode() : null)
+                            .customProcessingType(Objects.equals(bomSpec.getCustomProcessingType(), "10") ? "体位线(激光大版)" :
+                                    Objects.equals(bomSpec.getCustomProcessingType(), "20") ? "logo(激光小版)" : null)
+                            .classifyName(bomSpec.getClassifyName())
+                            .unit(bomSpec.getUnit())
+                            .build();
+                    exportDocumentByOrderBos.add(exportDocumentByOrderBo);
+                }
+            }
+
+            all = all.add(documentByOrderVo.getTotal());
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("all", all);
+        map.put("exportDocumentByOrderBos", exportDocumentByOrderBos);
+        return map;
+    }
+
+    @Override
+    public InputStream getInputStream(Map<String, Object> data) {
+        List<ExportDocumentByOrderBo> exportDocumentByOrderBos = (List<ExportDocumentByOrderBo>) data.remove("exportDocumentByOrderBos");
+
+        try {
+            String filePath = "tempExcel" + File.separator + IdWorker.getId() + ".xlsx";
+            File tempExcel = new File("tempExcel");
+            if (!tempExcel.exists()) {
+                tempExcel.mkdir();
+            }
+
+            ClassPathResource classPathResource = new ClassPathResource("template" + File.separator + "salesOutWarehouseDetails.xlsx");
+            InputStream is = null;
+            BufferedOutputStream os = null;
+            ExcelWriter excelWriter = null;
+            try {
+                is = classPathResource.getInputStream();
+                os = new BufferedOutputStream(Files.newOutputStream(Paths.get(filePath)));
+                excelWriter = EasyExcel.write(os).withTemplate(is).build();
+                SalesOutWarehouseDetailsExcelCellMergeStrategy strategy = new SalesOutWarehouseDetailsExcelCellMergeStrategy(list);
+                WriteSheet writeSheet = EasyExcel.writerSheet().registerWriteHandler(strategy).build();
+                FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
+
+                excelWriter.fill(data, fillConfig, writeSheet);
+                for (List<ExportDocumentByOrderBo> documentByOrderBos : ListUtil.partition(exportDocumentByOrderBos, 3000)) {
+                    excelWriter.fill(documentByOrderBos, fillConfig, writeSheet);
+                }
+
+            } finally {
+                if (excelWriter != null) {
+                    excelWriter.finish();
+                    excelWriter.close();
+                }
+                IoUtil.close(os);
+                IoUtil.close(is);
+            }
+
+            File file = new File(filePath);
+            ByteArrayInputStream inputStream = new ByteArrayInputStream(FileUtil.readBytes(file));
+            file.delete();
+
+            return inputStream;
+        } catch (IOException e) {
+            log.error("excel导出失败", e);
+            throw new ServiceException("excel导出失败");
+        }
+    }
+
+}

BIN
sd-starter/src/main/resources/template/salesOutWarehouseDetails.xlsx