|
1
|
package com.lframework.xingyun.sc.procurement.impl.buyoutAccount;
|
1
|
package com.lframework.xingyun.sc.procurement.impl.buyoutAccount;
|
|
2
|
|
2
|
|
|
3
|
import cn.hutool.core.bean.BeanUtil;
|
3
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
4
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
|
5
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
4
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
6
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
5
|
import com.github.pagehelper.PageInfo;
|
7
|
import com.github.pagehelper.PageInfo;
|
|
6
|
import com.lframework.starter.bpm.dto.FlowTaskDto;
|
8
|
import com.lframework.starter.bpm.dto.FlowTaskDto;
|
|
@@ -13,12 +15,19 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; |
|
@@ -13,12 +15,19 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; |
|
13
|
import com.lframework.starter.common.exceptions.impl.InputErrorException;
|
15
|
import com.lframework.starter.common.exceptions.impl.InputErrorException;
|
|
14
|
import com.lframework.starter.common.utils.Assert;
|
16
|
import com.lframework.starter.common.utils.Assert;
|
|
15
|
import com.lframework.starter.common.utils.CollectionUtil;
|
17
|
import com.lframework.starter.common.utils.CollectionUtil;
|
|
|
|
18
|
+import com.lframework.starter.common.utils.DateUtil;
|
|
|
|
19
|
+import com.lframework.starter.common.utils.FileUtil;
|
|
16
|
import com.lframework.starter.common.utils.StringUtil;
|
20
|
import com.lframework.starter.common.utils.StringUtil;
|
|
|
|
21
|
+import com.lframework.starter.mq.core.entity.ExportTask;
|
|
|
|
22
|
+import com.lframework.starter.mq.core.enums.ExportTaskStatus;
|
|
|
|
23
|
+import com.lframework.starter.mq.core.service.ExportTaskService;
|
|
17
|
import com.lframework.starter.web.core.annotations.oplog.OpLog;
|
24
|
import com.lframework.starter.web.core.annotations.oplog.OpLog;
|
|
18
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
25
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
|
|
26
|
+import com.lframework.starter.web.core.components.security.AbstractUserDetails;
|
|
19
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
27
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
|
20
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
28
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
|
21
|
import com.lframework.starter.web.core.utils.IdUtil;
|
29
|
import com.lframework.starter.web.core.utils.IdUtil;
|
|
|
|
30
|
+import com.lframework.starter.web.core.utils.JsonUtil;
|
|
22
|
import com.lframework.starter.web.core.utils.OpLogUtil;
|
31
|
import com.lframework.starter.web.core.utils.OpLogUtil;
|
|
23
|
import com.lframework.starter.web.core.utils.PageHelperUtil;
|
32
|
import com.lframework.starter.web.core.utils.PageHelperUtil;
|
|
24
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
33
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
|
@@ -26,7 +35,10 @@ import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; |
|
@@ -26,7 +35,10 @@ import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; |
|
26
|
import com.lframework.starter.web.inner.entity.SysDept;
|
35
|
import com.lframework.starter.web.inner.entity.SysDept;
|
|
27
|
import com.lframework.starter.web.inner.service.system.SysDeptService;
|
36
|
import com.lframework.starter.web.inner.service.system.SysDeptService;
|
|
28
|
import com.lframework.xingyun.sc.bo.procurement.GetBuyoutAccountOrderBo;
|
37
|
import com.lframework.xingyun.sc.bo.procurement.GetBuyoutAccountOrderBo;
|
|
|
|
38
|
+import com.lframework.xingyun.sc.bo.procurement.GetBuyoutAccountSummaryLineBo;
|
|
29
|
import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSettleDataBo;
|
39
|
import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSettleDataBo;
|
|
|
|
40
|
+import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSummaryTaskStatusBo;
|
|
|
|
41
|
+import com.lframework.xingyun.sc.enums.ExportType;
|
|
30
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply;
|
42
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply;
|
|
31
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApplyLine;
|
43
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApplyLine;
|
|
32
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
|
44
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
|
|
@@ -50,17 +62,33 @@ import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialS |
|
@@ -50,17 +62,33 @@ import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialS |
|
50
|
import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
|
62
|
import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
|
|
51
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.CreateBuyoutAccountOrderVo;
|
63
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.CreateBuyoutAccountOrderVo;
|
|
52
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
|
64
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
|
|
|
|
65
|
+import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountSummaryVo;
|
|
53
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.UpdateBuyoutAccountOrderVo;
|
66
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.UpdateBuyoutAccountOrderVo;
|
|
54
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.BuyoutAccountOrderLineVo;
|
67
|
import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.BuyoutAccountOrderLineVo;
|
|
|
|
68
|
+import com.lframework.xingyun.sc.utils.ExcelUtil;
|
|
|
|
69
|
+import com.lframework.xingyun.sc.utils.ResponseUtil;
|
|
55
|
|
70
|
|
|
|
|
71
|
+import java.io.File;
|
|
|
|
72
|
+import java.io.FileOutputStream;
|
|
|
|
73
|
+import java.io.IOException;
|
|
|
|
74
|
+import java.io.InputStream;
|
|
56
|
import java.math.BigDecimal;
|
75
|
import java.math.BigDecimal;
|
|
57
|
import java.time.LocalDate;
|
76
|
import java.time.LocalDate;
|
|
|
|
77
|
+import java.time.LocalDateTime;
|
|
58
|
import java.util.*;
|
78
|
import java.util.*;
|
|
59
|
import java.util.stream.Collectors;
|
79
|
import java.util.stream.Collectors;
|
|
60
|
import javax.annotation.Resource;
|
80
|
import javax.annotation.Resource;
|
|
|
|
81
|
+import javax.servlet.http.HttpServletResponse;
|
|
61
|
|
82
|
|
|
62
|
import lombok.extern.slf4j.Slf4j;
|
83
|
import lombok.extern.slf4j.Slf4j;
|
|
63
|
import org.apache.commons.collections.CollectionUtils;
|
84
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
85
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
86
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
87
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
88
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
89
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
90
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
91
|
+import org.springframework.beans.factory.annotation.Value;
|
|
64
|
import org.springframework.stereotype.Service;
|
92
|
import org.springframework.stereotype.Service;
|
|
65
|
import org.springframework.transaction.annotation.Transactional;
|
93
|
import org.springframework.transaction.annotation.Transactional;
|
|
66
|
|
94
|
|
|
@@ -110,9 +138,17 @@ public class ProcurementBuyoutAccountOrderServiceImpl |
|
@@ -110,9 +138,17 @@ public class ProcurementBuyoutAccountOrderServiceImpl |
|
110
|
*/
|
138
|
*/
|
|
111
|
private static final String BPM_FLAG = "BUYOUT_ACCOUNT_ORDER";
|
139
|
private static final String BPM_FLAG = "BUYOUT_ACCOUNT_ORDER";
|
|
112
|
|
140
|
|
|
|
|
141
|
+ /**
|
|
|
|
142
|
+ * 买断核算单汇总导出文件目录(默认与客户资信导出同款目录,多实例部署可配置共享挂载路径)
|
|
|
|
143
|
+ */
|
|
|
|
144
|
+ @Value("${buyout.account.summary.export:/web/service/erp/xingyun/export/templates/}")
|
|
|
|
145
|
+ private String summaryExportDir;
|
|
|
|
146
|
+
|
|
113
|
@Resource
|
147
|
@Resource
|
|
114
|
private ProcurementBuyoutAccountOrderMapper buyoutAccountOrderMapper;
|
148
|
private ProcurementBuyoutAccountOrderMapper buyoutAccountOrderMapper;
|
|
115
|
@Resource
|
149
|
@Resource
|
|
|
|
150
|
+ private ExportTaskService exportTaskService;
|
|
|
|
151
|
+ @Resource
|
|
116
|
private ProcurementBuyoutAccountOrderLineService orderLineService;
|
152
|
private ProcurementBuyoutAccountOrderLineService orderLineService;
|
|
117
|
@Resource
|
153
|
@Resource
|
|
118
|
private ProcurementMaterialSettleDetailMapper settleDetailMapper;
|
154
|
private ProcurementMaterialSettleDetailMapper settleDetailMapper;
|
|
@@ -589,6 +625,233 @@ public class ProcurementBuyoutAccountOrderServiceImpl |
|
@@ -589,6 +625,233 @@ public class ProcurementBuyoutAccountOrderServiceImpl |
|
589
|
.ne(ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_CANCEL)) > 0;
|
625
|
.ne(ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_CANCEL)) > 0;
|
|
590
|
}
|
626
|
}
|
|
591
|
|
627
|
|
|
|
|
628
|
+ @Override
|
|
|
|
629
|
+ public void exportSummary(QueryBuyoutAccountSummaryVo vo) {
|
|
|
|
630
|
+ // 1. 创建导出任务(导出中心可见),随后异步生成
|
|
|
|
631
|
+ AbstractUserDetails user = SecurityUtil.getCurrentUser();
|
|
|
|
632
|
+ ExportTask task = new ExportTask();
|
|
|
|
633
|
+ task.setName("买断入库核算单汇总导出_"
|
|
|
|
634
|
+ + DateUtil.formatDateTime(LocalDateTime.now(), "yyyyMMddHHmmss"));
|
|
|
|
635
|
+ task.setReqClassName(QueryBuyoutAccountSummaryVo.class.getName());
|
|
|
|
636
|
+ task.setReqParams(JsonUtil.toJsonString(vo));
|
|
|
|
637
|
+ task.setStatus(ExportTaskStatus.CREATED);
|
|
|
|
638
|
+ if (user != null) {
|
|
|
|
639
|
+ // createById 存用户ID(表字段长度有限,不能用 Sa-Token 的 loginId)
|
|
|
|
640
|
+ task.setCreateById(user.getId());
|
|
|
|
641
|
+ task.setCreateBy(user.getName());
|
|
|
|
642
|
+ }
|
|
|
|
643
|
+ task.setCreateTime(LocalDateTime.now());
|
|
|
|
644
|
+ String taskId = exportTaskService.create(task);
|
|
|
|
645
|
+ log.info("=====taskId===" + taskId);
|
|
|
|
646
|
+
|
|
|
|
647
|
+ // 2. 异步生成(月度数据量小;生成到固定目录→更新任务状态,前端轮询状态接口后走下载接口)
|
|
|
|
648
|
+ ThreadUtil.execAsync(() -> doExportSummary(taskId, vo));
|
|
|
|
649
|
+ }
|
|
|
|
650
|
+
|
|
|
|
651
|
+ /**
|
|
|
|
652
|
+ * 生成汇总 Excel(落到固定目录,文件名=任务ID.xlsx;recordId 留空,下载走自有接口而非导出中心)
|
|
|
|
653
|
+ */
|
|
|
|
654
|
+ private void doExportSummary(String taskId, QueryBuyoutAccountSummaryVo vo) {
|
|
|
|
655
|
+ try {
|
|
|
|
656
|
+ exportTaskService.setExporting(taskId);
|
|
|
|
657
|
+
|
|
|
|
658
|
+ // 年月参数格式 yyyy-MM(如 2026-11),缺省当前年月
|
|
|
|
659
|
+ int year;
|
|
|
|
660
|
+ int month;
|
|
|
|
661
|
+ if (StringUtil.isBlank(vo.getMonth())) {
|
|
|
|
662
|
+ year = LocalDate.now().getYear();
|
|
|
|
663
|
+ month = LocalDate.now().getMonthValue();
|
|
|
|
664
|
+ } else {
|
|
|
|
665
|
+ String[] parts = vo.getMonth().split("-");
|
|
|
|
666
|
+ year = Integer.parseInt(parts[0]);
|
|
|
|
667
|
+ month = Integer.parseInt(parts[1]);
|
|
|
|
668
|
+ }
|
|
|
|
669
|
+ List<GetBuyoutAccountSummaryLineBo> rows = buyoutAccountOrderMapper.querySummary(year, month);
|
|
|
|
670
|
+
|
|
|
|
671
|
+ File file = FileUtil.newFile(getSummaryExportDir() + taskId + ".xlsx");
|
|
|
|
672
|
+ buildSummaryExcel(file, rows, year, month);
|
|
|
|
673
|
+ // 文件生成完成即视为导出成功(recordId 留空,下载走自有接口)
|
|
|
|
674
|
+ exportTaskService.setSuccess(taskId, "", FileUtil.readableFileSize(file.length()));
|
|
|
|
675
|
+ } catch (Exception e) {
|
|
|
|
676
|
+ log.error("买断入库核算单汇总导出失败, taskId={}", taskId, e);
|
|
|
|
677
|
+ exportTaskService.setFail(taskId, e.getMessage());
|
|
|
|
678
|
+ }
|
|
|
|
679
|
+ }
|
|
|
|
680
|
+
|
|
|
|
681
|
+ /**
|
|
|
|
682
|
+ * 汇总导出文件目录(可配置共享挂载,多实例部署时需指向共享路径)
|
|
|
|
683
|
+ */
|
|
|
|
684
|
+ private String getSummaryExportDir() {
|
|
|
|
685
|
+ if (!summaryExportDir.endsWith("/") && !summaryExportDir.endsWith("\\")) {
|
|
|
|
686
|
+ return summaryExportDir + File.separator;
|
|
|
|
687
|
+ }
|
|
|
|
688
|
+ return summaryExportDir;
|
|
|
|
689
|
+ }
|
|
|
|
690
|
+
|
|
|
|
691
|
+ @Override
|
|
|
|
692
|
+ public GetBuyoutSummaryTaskStatusBo getExportSummaryStatus() {
|
|
|
|
693
|
+ // 按当前用户 + 导出类型查最新一条任务(req_params 里含 exportType)
|
|
|
|
694
|
+ AbstractUserDetails user = SecurityUtil.getCurrentUser();
|
|
|
|
695
|
+ ExportTask task = exportTaskService.getOne(Wrappers.lambdaQuery(ExportTask.class)
|
|
|
|
696
|
+ .eq(ExportTask::getCreateById, user.getId())
|
|
|
|
697
|
+ .like(ExportTask::getReqParams, "\"" + ExportType.BUYOUT_ACCOUNT_SUMMARY.getCode() + "\"")
|
|
|
|
698
|
+ .orderByDesc(ExportTask::getCreateTime)
|
|
|
|
699
|
+ .last("LIMIT 1"), false);
|
|
|
|
700
|
+ if (task == null) {
|
|
|
|
701
|
+ throw new DefaultClientException("暂无买断入库核算单汇总导出任务!");
|
|
|
|
702
|
+ }
|
|
|
|
703
|
+ GetBuyoutSummaryTaskStatusBo bo = new GetBuyoutSummaryTaskStatusBo();
|
|
|
|
704
|
+ bo.setTaskId(task.getId());
|
|
|
|
705
|
+ bo.setName(task.getName());
|
|
|
|
706
|
+ bo.setStatus(task.getStatus() == null ? "" : task.getStatus().name());
|
|
|
|
707
|
+ bo.setStatusDesc(task.getStatus() == null ? "" : task.getStatus().getDesc());
|
|
|
|
708
|
+ bo.setErrorMsg(task.getErrorMsg());
|
|
|
|
709
|
+ bo.setFileSize(task.getFileSize());
|
|
|
|
710
|
+ // 导出完成 = SUCCESS 且文件已生成
|
|
|
|
711
|
+ bo.setFinished(task.getStatus() == ExportTaskStatus.SUCCESS
|
|
|
|
712
|
+ && new File(getSummaryExportDir() + task.getId() + ".xlsx").exists());
|
|
|
|
713
|
+ return bo;
|
|
|
|
714
|
+ }
|
|
|
|
715
|
+
|
|
|
|
716
|
+ @Override
|
|
|
|
717
|
+ public void downloadExportSummary(String taskId, HttpServletResponse response) throws IOException {
|
|
|
|
718
|
+ if (StringUtil.isBlank(taskId)) {
|
|
|
|
719
|
+ throw new InputErrorException("任务ID不能为空!");
|
|
|
|
720
|
+ }
|
|
|
|
721
|
+ ExportTask task = exportTaskService.getById(taskId);
|
|
|
|
722
|
+ if (task == null) {
|
|
|
|
723
|
+ throw new DefaultClientException("导出任务不存在!");
|
|
|
|
724
|
+ }
|
|
|
|
725
|
+ if (task.getStatus() != ExportTaskStatus.SUCCESS) {
|
|
|
|
726
|
+ throw new DefaultClientException("文件尚未导出完成,请稍后再试!");
|
|
|
|
727
|
+ }
|
|
|
|
728
|
+ File file = new File(getSummaryExportDir() + taskId + ".xlsx");
|
|
|
|
729
|
+ if (!file.exists()) {
|
|
|
|
730
|
+ throw new DefaultClientException("文件不存在!");
|
|
|
|
731
|
+ }
|
|
|
|
732
|
+ // 下载文件名:买断入库核算单汇总_{yyyy}年{m}月.xlsx(年月取自任务参数 month="yyyy-MM",缺省当前年月)
|
|
|
|
733
|
+ String fileName;
|
|
|
|
734
|
+ if (StringUtil.isNotBlank(task.getReqParams())) {
|
|
|
|
735
|
+ try {
|
|
|
|
736
|
+ QueryBuyoutAccountSummaryVo vo = JsonUtil.parseObject(task.getReqParams(),
|
|
|
|
737
|
+ QueryBuyoutAccountSummaryVo.class);
|
|
|
|
738
|
+ if (vo != null && StringUtil.isNotBlank(vo.getMonth())) {
|
|
|
|
739
|
+ // "2026-11" -> "2026年11月"
|
|
|
|
740
|
+ fileName = "买断入库核算单汇总_" + vo.getMonth().replace("-", "年") + "月.xlsx";
|
|
|
|
741
|
+ } else {
|
|
|
|
742
|
+ LocalDate now = LocalDate.now();
|
|
|
|
743
|
+ fileName = "买断入库核算单汇总_" + now.getYear() + "年" + now.getMonthValue() + "月.xlsx";
|
|
|
|
744
|
+ }
|
|
|
|
745
|
+ } catch (Exception ignore) {
|
|
|
|
746
|
+ LocalDate now = LocalDate.now();
|
|
|
|
747
|
+ fileName = "买断入库核算单汇总_" + now.getYear() + "年" + now.getMonthValue() + "月.xlsx";
|
|
|
|
748
|
+ }
|
|
|
|
749
|
+ } else {
|
|
|
|
750
|
+ LocalDate now = LocalDate.now();
|
|
|
|
751
|
+ fileName = "买断入库核算单汇总_" + now.getYear() + "年" + now.getMonthValue() + "月.xlsx";
|
|
|
|
752
|
+ }
|
|
|
|
753
|
+ ResponseUtil.setExcelResponseHead(response, fileName);
|
|
|
|
754
|
+ try (InputStream in = FileUtil.getInputStream(file)) {
|
|
|
|
755
|
+ byte[] buffer = new byte[8192];
|
|
|
|
756
|
+ int len;
|
|
|
|
757
|
+ while ((len = in.read(buffer)) != -1) {
|
|
|
|
758
|
+ response.getOutputStream().write(buffer, 0, len);
|
|
|
|
759
|
+ }
|
|
|
|
760
|
+ response.getOutputStream().flush();
|
|
|
|
761
|
+ }
|
|
|
|
762
|
+ }
|
|
|
|
763
|
+
|
|
|
|
764
|
+ /**
|
|
|
|
765
|
+ * 按模板生成汇总 Excel(标题年月占位符 + 明细动态行 + 同单多行纵向合并:序号/厂别/采购处/来料单位/合计金额;
|
|
|
|
766
|
+ * 盈亏金额列填明细差异金额,漆损盈亏金额/合计金额两列按需求默认空白)
|
|
|
|
767
|
+ */
|
|
|
|
768
|
+ private void buildSummaryExcel(File file, List<GetBuyoutAccountSummaryLineBo> rows, int year, int month)
|
|
|
|
769
|
+ throws IOException {
|
|
|
|
770
|
+ int dataSize = rows == null ? 0 : rows.size();
|
|
|
|
771
|
+ try (InputStream inputStream = new ClassPathResource(
|
|
|
|
772
|
+ "templates/buyoutAccountOrderSummaryTemplate.xlsx").getStream();
|
|
|
|
773
|
+ Workbook workbook = new XSSFWorkbook(inputStream)) {
|
|
|
|
774
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
775
|
+
|
|
|
|
776
|
+ // 标题:${year}年${month}月统货买断入库核算汇总(年份随查询条件)
|
|
|
|
777
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
|
778
|
+ dataMap.put("year", String.valueOf(year));
|
|
|
|
779
|
+ dataMap.put("month", String.valueOf(month));
|
|
|
|
780
|
+ ExcelUtil.processTemplateSheet(sheet, dataMap);
|
|
|
|
781
|
+
|
|
|
|
782
|
+ // 明细动态行:模板仅预留1行(Excel第4行,索引3),其余按数据量复制样式补充(模板行下方无其他内容)
|
|
|
|
783
|
+ final int lineStartRow = 3;
|
|
|
|
784
|
+ final int columnCount = 12;
|
|
|
|
785
|
+ Row templateRow = sheet.getRow(lineStartRow);
|
|
|
|
786
|
+ for (int i = 1; i < dataSize; i++) {
|
|
|
|
787
|
+ int rowIdx = lineStartRow + i;
|
|
|
|
788
|
+ Row newRow = sheet.createRow(rowIdx);
|
|
|
|
789
|
+ newRow.setHeight(templateRow.getHeight());
|
|
|
|
790
|
+ for (int c = 0; c < columnCount; c++) {
|
|
|
|
791
|
+ Cell tc = templateRow.getCell(c);
|
|
|
|
792
|
+ if (tc != null) {
|
|
|
|
793
|
+ newRow.createCell(c).setCellStyle(tc.getCellStyle());
|
|
|
|
794
|
+ }
|
|
|
|
795
|
+ }
|
|
|
|
796
|
+ }
|
|
|
|
797
|
+ if (dataSize == 0) {
|
|
|
|
798
|
+ // 无数据时清掉模板预填的序号
|
|
|
|
799
|
+ ExcelUtil.setCellValue(sheet, lineStartRow, 0, "");
|
|
|
|
800
|
+ }
|
|
|
|
801
|
+
|
|
|
|
802
|
+ // 分组填充:连续相同核算单ID为一组;A序号/B厂别/C采购处/D来料单位/L合计金额仅组首行填值,
|
|
|
|
803
|
+ // 同单多行时纵向合并(合计金额列默认空白,仅合并单元格便于人工填写)
|
|
|
|
804
|
+ int seq = 1;
|
|
|
|
805
|
+ int i = 0;
|
|
|
|
806
|
+ while (i < dataSize) {
|
|
|
|
807
|
+ int j = i;
|
|
|
|
808
|
+ while (j < dataSize && rows.get(j).getOrderId().equals(rows.get(i).getOrderId())) {
|
|
|
|
809
|
+ j++;
|
|
|
|
810
|
+ }
|
|
|
|
811
|
+ int firstRow = lineStartRow + i;
|
|
|
|
812
|
+ GetBuyoutAccountSummaryLineBo first = rows.get(i);
|
|
|
|
813
|
+ ExcelUtil.setCellValue(sheet, firstRow, 0, seq);
|
|
|
|
814
|
+ ExcelUtil.setCellValue(sheet, firstRow, 1, first.getWorkshopName());
|
|
|
|
815
|
+ ExcelUtil.setCellValue(sheet, firstRow, 2, first.getPurchaseDepartmentName());
|
|
|
|
816
|
+ ExcelUtil.setCellValue(sheet, firstRow, 3, first.getIncomingUnit());
|
|
|
|
817
|
+ if (j - i > 1) {
|
|
|
|
818
|
+ for (int col : new int[]{0, 1, 2, 3, 11}) {
|
|
|
|
819
|
+ sheet.addMergedRegion(new CellRangeAddress(firstRow, lineStartRow + j - 1, col, col));
|
|
|
|
820
|
+ }
|
|
|
|
821
|
+ }
|
|
|
|
822
|
+ // 明细列:E品种/F买断数量/G预计损耗/H实际损耗/I吨损耗差异/J盈亏金额(=差异金额)
|
|
|
|
823
|
+ for (int k = i; k < j; k++) {
|
|
|
|
824
|
+ int rowIdx = lineStartRow + k;
|
|
|
|
825
|
+ GetBuyoutAccountSummaryLineBo row = rows.get(k);
|
|
|
|
826
|
+ if (row.getBuyoutCategory() != null) {
|
|
|
|
827
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 4, row.getBuyoutCategory());
|
|
|
|
828
|
+ }
|
|
|
|
829
|
+ if (row.getBuyoutQuantity() != null) {
|
|
|
|
830
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 5, row.getBuyoutQuantity());
|
|
|
|
831
|
+ }
|
|
|
|
832
|
+ if (row.getExpectTonLoss() != null) {
|
|
|
|
833
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 6, row.getExpectTonLoss());
|
|
|
|
834
|
+ }
|
|
|
|
835
|
+ if (row.getActualTonLoss() != null) {
|
|
|
|
836
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 7, row.getActualTonLoss());
|
|
|
|
837
|
+ }
|
|
|
|
838
|
+ if (row.getTonLossDiff() != null) {
|
|
|
|
839
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 8, row.getTonLossDiff());
|
|
|
|
840
|
+ }
|
|
|
|
841
|
+ if (row.getDiffAmount() != null) {
|
|
|
|
842
|
+ ExcelUtil.setCellValue(sheet, rowIdx, 9, row.getDiffAmount());
|
|
|
|
843
|
+ }
|
|
|
|
844
|
+ }
|
|
|
|
845
|
+ seq++;
|
|
|
|
846
|
+ i = j;
|
|
|
|
847
|
+ }
|
|
|
|
848
|
+
|
|
|
|
849
|
+ try (FileOutputStream fos = new FileOutputStream(file)) {
|
|
|
|
850
|
+ workbook.write(fos);
|
|
|
|
851
|
+ }
|
|
|
|
852
|
+ }
|
|
|
|
853
|
+ }
|
|
|
|
854
|
+
|
|
592
|
/**
|
855
|
/**
|
|
593
|
* 保存明细(数量、单价、金额均由前端计算传入,后端只保存)
|
856
|
* 保存明细(数量、单价、金额均由前端计算传入,后端只保存)
|
|
594
|
*/
|
857
|
*/
|