Commit 03d3bcd95e1142ef25394e12cd9954fffe65db19

Authored by 房远帅
2 parents afcd2b6e 19259c78

Merge remote-tracking branch 'origin/master_cj_zq' into master_cj_zq

... ... @@ -18,6 +18,7 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException;
18 18 import io.swagger.annotations.ApiOperation;
19 19 import com.lframework.starter.common.utils.CollectionUtil;
20 20 import io.swagger.annotations.Api;
  21 +import org.apache.commons.lang3.StringUtils;
21 22 import org.springframework.web.bind.annotation.DeleteMapping;
22 23 import com.lframework.starter.web.core.components.resp.PageResult;
23 24 import com.lframework.starter.web.core.components.resp.InvokeResult;
... ... @@ -150,7 +151,9 @@ public class ReceiptLedgerInfoController extends DefaultBaseController {
150 151 @HasPermission({"customer-dev-manage:customer-dev-plan:export"})
151 152 @GetMapping("/report/export")
152 153 public InvokeResult<Void> export(@Valid ReceiptLedgerReportVo vo) {
153   - vo.setExportType(ExportType.RECEIVABLE_LEDGER_REPORT.getCode());
  154 + if (StringUtils.isBlank(vo.getExportType())) {
  155 + throw new DefaultClientException("导出类型不能为空!");
  156 + }
154 157 ExportTaskUtil.exportTask("应收款台账报表信息", LedgerReportExportTaskWorker.class, vo);
155 158 return InvokeResultBuilder.success();
156 159 }
... ...
... ... @@ -32,7 +32,7 @@ import java.util.Map;
32 32 public class LedgerReportExportHandler implements ExportHandler {
33 33
34 34 @Override
35   - public void exportLedgerReport(Object params, Object dataList, File xlsxFile) {
  35 + public void exportLedgerReport(Object params, Object dataList, File xlsxFile, String exportType) {
36 36 List<LedgerReportExportModel> ledgerReportList = JsonUtil.parseList(JsonUtil.toJsonString(dataList), LedgerReportExportModel.class);
37 37 // 读取模板文件
38 38 ClassPathResource templateResource = new ClassPathResource("templates/ledgerReportExportTemplate.xlsx");
... ... @@ -41,8 +41,7 @@ public class LedgerReportExportHandler implements ExportHandler {
41 41 Sheet sheet = workbook.getSheetAt(0);
42 42 // 数据填充起始行
43 43 int rowIndex = 2;
44   - for (int i = 0; i < ledgerReportList.size(); i++) {
45   - LedgerReportExportModel model = ledgerReportList.get(i);
  44 + for (LedgerReportExportModel model : ledgerReportList) {
46 45 ExcelUtil.setCellValue(sheet, rowIndex, 0, model.getQuota()
47 46 , setCellStyle(workbook, VerticalAlignment.CENTER, false));
48 47 ExcelUtil.setCellValue(sheet, rowIndex, 1, model.getSettleTerm()
... ... @@ -61,72 +60,58 @@ public class LedgerReportExportHandler implements ExportHandler {
61 60 rowIndex++;
62 61 continue;
63 62 }
64   - // 合并起始行
65   - int startMergeIndex = rowIndex;
66   - // 合并结束行
67   - int endMergeIndex = rowIndex + detailList.size();
68   - for (int j = 0; j < detailList.size(); j++) {
69   - ReceiptLedgerReportDetail detail = detailList.get(j);
70   - ExcelUtil.setCellValue(sheet, rowIndex, 6, detail.getCustomerName()
71   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
72   - ExcelUtil.setCellValue(sheet, rowIndex, 7, detail.getDebtTotal()
73   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
74   - ExcelUtil.setCellValue(sheet, rowIndex, 8, detail.getAgreement()
75   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
76   - ExcelUtil.setCellValue(sheet, rowIndex, 9, detail.getFirstCoordinate()
77   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
78   - ExcelUtil.setCellValue(sheet, rowIndex, 10, detail.getSecondCoordinate()
79   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
80   - ExcelUtil.setCellValue(sheet, rowIndex, 11, detail.getClearDebt()
81   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
82   - ExcelUtil.setCellValue(sheet, rowIndex, 12, detail.getCreditStatus()
83   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
84   - ExcelUtil.setCellValue(sheet, rowIndex, 13, detail.getTimingStatus()
85   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
86   - ExcelUtil.setCellValue(sheet, rowIndex, 14, detail.getWaitDeliveredOrder()
87   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
88   - rowIndex++;
89   - }
90   - if (detailList.size() > 1) {
91   - ExcelUtil.setCellValue(sheet, rowIndex, 6, "小计"
92   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
93   - ExcelUtil.setCellValue(sheet, rowIndex, 7, model.getDebtTotal()
94   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
95   - ExcelUtil.setCellValue(sheet, rowIndex, 8, model.getAgreementTotal()
96   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
97   - ExcelUtil.setCellValue(sheet, rowIndex, 9, model.getFirstCoordinateTotal()
98   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
99   - ExcelUtil.setCellValue(sheet, rowIndex, 10, model.getSecondCoordinateTotal()
100   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
101   - ExcelUtil.setCellValue(sheet, rowIndex, 11, model.getClearDebtTotal()
102   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
103   - ExcelUtil.setCellValue(sheet, rowIndex, 12, model.getCreditStatus()
104   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
105   - ExcelUtil.setCellValue(sheet, rowIndex, 13, model.getTimingStatus()
106   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
107   - ExcelUtil.setCellValue(sheet, rowIndex, 14, model.getWaitDeliveredOrderTotal()
108   - , setCellStyle(workbook, VerticalAlignment.CENTER, false));
109   - // 合并单位格
110   - CellRangeAddress cellRangeAddress1 = new CellRangeAddress(
111   - startMergeIndex, endMergeIndex, 0, 0);
112   - sheet.addMergedRegion(cellRangeAddress1);
113   - CellRangeAddress cellRangeAddress2 = new CellRangeAddress(
114   - startMergeIndex, endMergeIndex, 1, 1);
115   - sheet.addMergedRegion(cellRangeAddress2);
116   - CellRangeAddress cellRangeAddress3 = new CellRangeAddress(
117   - startMergeIndex, endMergeIndex, 2, 2);
118   - sheet.addMergedRegion(cellRangeAddress3);
119   - CellRangeAddress cellRangeAddress4 = new CellRangeAddress(
120   - startMergeIndex, endMergeIndex, 3, 3);
121   - sheet.addMergedRegion(cellRangeAddress4);
122   - CellRangeAddress cellRangeAddress5 = new CellRangeAddress(
123   - startMergeIndex, endMergeIndex, 4, 4);
124   - sheet.addMergedRegion(cellRangeAddress5);
125   - CellRangeAddress cellRangeAddress6 = new CellRangeAddress(
126   - startMergeIndex, endMergeIndex, 5, 5);
127   - sheet.addMergedRegion(cellRangeAddress6);
128   - rowIndex++;
  63 + if ("RECEIVABLE_LEDGER_REPORT".equals(exportType)) {
  64 + // 合并起始行
  65 + int startMergeIndex = rowIndex;
  66 + // 合并结束行
  67 + int endMergeIndex = rowIndex + detailList.size();
  68 + for (ReceiptLedgerReportDetail detail : detailList) {
  69 + ExcelUtil.setCellValue(sheet, rowIndex, 6, detail.getCustomerName()
  70 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  71 + ExcelUtil.setCellValue(sheet, rowIndex, 7, detail.getDebtTotal()
  72 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  73 + ExcelUtil.setCellValue(sheet, rowIndex, 8, detail.getAgreement()
  74 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  75 + ExcelUtil.setCellValue(sheet, rowIndex, 9, detail.getFirstCoordinate()
  76 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  77 + ExcelUtil.setCellValue(sheet, rowIndex, 10, detail.getSecondCoordinate()
  78 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  79 + ExcelUtil.setCellValue(sheet, rowIndex, 11, detail.getClearDebt()
  80 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  81 + ExcelUtil.setCellValue(sheet, rowIndex, 12, detail.getCreditStatus()
  82 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  83 + ExcelUtil.setCellValue(sheet, rowIndex, 13, detail.getTimingStatus()
  84 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  85 + ExcelUtil.setCellValue(sheet, rowIndex, 14, detail.getWaitDeliveredOrder()
  86 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  87 + rowIndex++;
  88 + }
  89 + if (detailList.size() > 1) {
  90 + setSubtotalCell(workbook, sheet, rowIndex, model);
  91 + // 合并单位格
  92 + CellRangeAddress cellRangeAddress1 = new CellRangeAddress(
  93 + startMergeIndex, endMergeIndex, 0, 0);
  94 + sheet.addMergedRegion(cellRangeAddress1);
  95 + CellRangeAddress cellRangeAddress2 = new CellRangeAddress(
  96 + startMergeIndex, endMergeIndex, 1, 1);
  97 + sheet.addMergedRegion(cellRangeAddress2);
  98 + CellRangeAddress cellRangeAddress3 = new CellRangeAddress(
  99 + startMergeIndex, endMergeIndex, 2, 2);
  100 + sheet.addMergedRegion(cellRangeAddress3);
  101 + CellRangeAddress cellRangeAddress4 = new CellRangeAddress(
  102 + startMergeIndex, endMergeIndex, 3, 3);
  103 + sheet.addMergedRegion(cellRangeAddress4);
  104 + CellRangeAddress cellRangeAddress5 = new CellRangeAddress(
  105 + startMergeIndex, endMergeIndex, 4, 4);
  106 + sheet.addMergedRegion(cellRangeAddress5);
  107 + CellRangeAddress cellRangeAddress6 = new CellRangeAddress(
  108 + startMergeIndex, endMergeIndex, 5, 5);
  109 + sheet.addMergedRegion(cellRangeAddress6);
  110 + }
  111 + } else if ("RECEIVABLE_LEDGER_REPORT_MERGE".equals(exportType)) {
  112 + setSubtotalCell(workbook, sheet, rowIndex, model);
129 113 }
  114 + rowIndex++;
130 115 }
131 116 // ========== 填充标题和表头 ==========
132 117 Map<String, Object> dataMap = new HashMap<>();
... ... @@ -166,6 +151,35 @@ public class LedgerReportExportHandler implements ExportHandler {
166 151 }
167 152
168 153 /**
  154 + * 设置“小计”单元格
  155 + *
  156 + * @param workbook 工作簿
  157 + * @param sheet sheet
  158 + * @param rowIndex 当前所在行索引
  159 + * @param model 实体数据
  160 + */
  161 + private void setSubtotalCell(Workbook workbook, Sheet sheet, int rowIndex, LedgerReportExportModel model) {
  162 + ExcelUtil.setCellValue(sheet, rowIndex, 6, "小计"
  163 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  164 + ExcelUtil.setCellValue(sheet, rowIndex, 7, model.getDebtTotal()
  165 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  166 + ExcelUtil.setCellValue(sheet, rowIndex, 8, model.getAgreementTotal()
  167 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  168 + ExcelUtil.setCellValue(sheet, rowIndex, 9, model.getFirstCoordinateTotal()
  169 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  170 + ExcelUtil.setCellValue(sheet, rowIndex, 10, model.getSecondCoordinateTotal()
  171 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  172 + ExcelUtil.setCellValue(sheet, rowIndex, 11, model.getClearDebtTotal()
  173 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  174 + ExcelUtil.setCellValue(sheet, rowIndex, 12, model.getCreditStatus()
  175 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  176 + ExcelUtil.setCellValue(sheet, rowIndex, 13, model.getTimingStatus()
  177 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  178 + ExcelUtil.setCellValue(sheet, rowIndex, 14, model.getWaitDeliveredOrderTotal()
  179 + , setCellStyle(workbook, VerticalAlignment.CENTER, false));
  180 + }
  181 +
  182 + /**
169 183 * 设置单元格样式
170 184 *
171 185 * @param workbook 工作簿
... ...