|
@@ -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导出失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|