|
@@ -0,0 +1,141 @@
|
|
|
+package com.sd.business.strategy.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+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.core.toolkit.StringPool;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.sd.business.entity.statement.bo.ExportDocumentByOrderBo;
|
|
|
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
|
|
|
+import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.business.service.statement.impl.DocumentByOrderExcelCellMergeStrategy;
|
|
|
+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.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订单对账单
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class DocumentByOrderExcelExportStrategy implements ExcelExportStrategy<Map<String, Object>> {
|
|
|
+
|
|
|
+ private static final StatementOfAccountService statementOfAccountService = SpringUtil.getBean(StatementOfAccountService.class);
|
|
|
+
|
|
|
+ private final List<Long> idList;
|
|
|
+ private final String departmentName;
|
|
|
+ private final String beginDate;
|
|
|
+ private final String endDate;
|
|
|
+
|
|
|
+ private List<DocumentByOrderVo> list;
|
|
|
+
|
|
|
+ public DocumentByOrderExcelExportStrategy(List<Long> idList, String departmentName, String beginDate, String endDate) {
|
|
|
+ this.idList = idList;
|
|
|
+ this.departmentName = departmentName;
|
|
|
+ this.beginDate = beginDate;
|
|
|
+ this.endDate = endDate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getData() {
|
|
|
+ list = statementOfAccountService.getDocumentByOrder(idList);
|
|
|
+
|
|
|
+ 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()
|
|
|
+ .wlnCreateTime(documentByOrderVo.getWlnCreateTime())
|
|
|
+ .code(documentByOrderVo.getCode())
|
|
|
+ .wlnCode(documentByOrderVo.getWlnCode())
|
|
|
+ .skuSpecCode(skuSpec.getSkuSpecCode())
|
|
|
+ .skuSpecName(skuSpec.getSkuSpecName())
|
|
|
+ .quantity(skuSpec.getQuantity())
|
|
|
+ .unitPrice(skuSpec.getUnitPrice())
|
|
|
+ .subtotal(skuSpec.getSubtotal())
|
|
|
+ .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())
|
|
|
+ .outerBoxPackingFee(documentByOrderVo.getOuterBoxPackingFee())
|
|
|
+ .total(documentByOrderVo.getTotal())
|
|
|
+ .build();
|
|
|
+ exportDocumentByOrderBos.add(exportDocumentByOrderBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ all = all.add(documentByOrderVo.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("department", StrUtil.isBlank(departmentName) ? StringPool.EMPTY : departmentName + StringPool.DASH);
|
|
|
+ map.put("beginDate", beginDate);
|
|
|
+ map.put("endDate", endDate);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ FileOutputStream os = new FileOutputStream(filePath);
|
|
|
+
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template" + File.separator + "orderDocument.xlsx");
|
|
|
+ InputStream is = classPathResource.getInputStream();
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(os).withTemplate(is).build();
|
|
|
+ try {
|
|
|
+ DocumentByOrderExcelCellMergeStrategy strategy = new DocumentByOrderExcelCellMergeStrategy(list);
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().registerWriteHandler(strategy).build();
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
+
|
|
|
+ excelWriter.fill(data, fillConfig, writeSheet);
|
|
|
+ excelWriter.fill(exportDocumentByOrderBos, fillConfig, writeSheet);
|
|
|
+ } finally {
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.finish();
|
|
|
+ excelWriter.close();
|
|
|
+ }
|
|
|
+ os.close();
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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导出失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|