Commit 8ab8432a by ghxdhr

报告多sheet页填充数据

parent c9ba93e8
...@@ -961,8 +961,10 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -961,8 +961,10 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
mapReplace.put("#{sampleFrom}", list.size() > 0 ? list.get(0).getSampleFrom() : " - "); mapReplace.put("#{sampleFrom}", list.size() > 0 ? list.get(0).getSampleFrom() : " - ");
list = sampleList.stream().filter(s -> StringUtils.isNotEmpty(s.getName())).collect(Collectors.toList()); list = sampleList.stream().filter(s -> StringUtils.isNotEmpty(s.getName())).collect(Collectors.toList());
mapReplace.put("#{sampleName}", list.size() > 0 ? list.get(0).getName() : " - "); mapReplace.put("#{sampleName}", list.size() > 0 ? list.get(0).getName() : " - ");
HSSFWorkbookUtil.replaceModel(mapReplace, xssfWorkbook, 0); int numberOfSheets = xssfWorkbook.getNumberOfSheets();
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(0); for (int k = 0; k < numberOfSheets; k++) {
HSSFWorkbookUtil.replaceModel(mapReplace, xssfWorkbook, k);
XSSFSheet sheetOne = xssfWorkbook.getSheetAt(k);
String sheetName = sheetOne.getSheetName(); String sheetName = sheetOne.getSheetName();
System.out.println(sheetName); System.out.println(sheetName);
sheetOne.setForceFormulaRecalculation(true); sheetOne.setForceFormulaRecalculation(true);
...@@ -971,12 +973,24 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -971,12 +973,24 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
int templateSampleNum = sysFileTemplate.getTemplateSampleNum(); int templateSampleNum = sysFileTemplate.getTemplateSampleNum();
if (templateSampleNum >= sampleVOList.size()) { if (templateSampleNum >= sampleVOList.size()) {
Integer beginRow = sysFileTemplate.getSampleBeginRow(); Integer beginRow = sysFileTemplate.getSampleBeginRow();
HashMap<Long, List<EntrustSampleItemIndex>> indexMap = new HashMap<>();
for (EntrustSampleVO vo : sampleVOList) { for (EntrustSampleVO vo : sampleVOList) {
// List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId()); // List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId());
List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.getInReportItemIndex(vo.getId()); List<EntrustSampleItemIndex> indexList = new ArrayList<>();
if (indexMap.containsKey(vo.getId())) {
indexList = indexMap.get(vo.getId());
} else {
indexList = entrustSampleItemIndexService.getInReportItemIndex(vo.getId());
}
vo.setIndexList(indexList); vo.setIndexList(indexList);
XSSFRow xssfRow = sheetOne.getRow(beginRow); XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) { for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace()); XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) { if ("sn".equals(config.getDataAttribute())) {
continue; continue;
...@@ -989,35 +1003,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -989,35 +1003,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
} }
beginRow += sampleMergerNum; beginRow += sampleMergerNum;
} }
String generated = entrust.getCode();
FileOutputStream os = null;
File file = null;
try {
file = File.createTempFile(generated, ".xlsx");
os = new FileOutputStream(file);
xssfWorkbook.write(os);
os.flush();
entrustReportService.uploadReportGenerateDocx(entrust, ids, account, StringHandleUtils.join(sampleNameSet), "报告生成", file);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
xssfWorkbook.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
io.close();
} catch (IOException e) {
e.printStackTrace();
}
FileUtils.deleteFiles(file);
}
} else { } else {
...@@ -1028,7 +1013,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -1028,7 +1013,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
for (int i = 1; i < totalSheetSize; i++) { for (int i = 1; i < totalSheetSize; i++) {
xssfWorkbook.cloneSheet(0, sheetOne.getSheetName() + (i + 1)); xssfWorkbook.cloneSheet(0, sheetOne.getSheetName() + (i + 1));
} }
for (int k = 0; k < listList.size(); k++) { for (int m = 0; m < listList.size(); m++) {
Integer beginRow = sysFileTemplate.getSampleBeginRow(); Integer beginRow = sysFileTemplate.getSampleBeginRow();
List<EntrustSampleVO> sampleVOListIndex = listList.get(k); List<EntrustSampleVO> sampleVOListIndex = listList.get(k);
...@@ -1053,8 +1038,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -1053,8 +1038,6 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
beginRow += sampleMergerNum; beginRow += sampleMergerNum;
} }
} }
} else { } else {
Integer beginRow = sysFileTemplate.getSampleBeginRow(); Integer beginRow = sysFileTemplate.getSampleBeginRow();
int insertRow = beginRow + sampleMergerNum * templateSampleNum; int insertRow = beginRow + sampleMergerNum * templateSampleNum;
...@@ -1081,6 +1064,9 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -1081,6 +1064,9 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId()); List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId());
vo.setIndexList(indexList); vo.setIndexList(indexList);
for (EntrustReportTemplateConfig config : configList) { for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) { if (null == config.getColumnPlace()) {
continue; continue;
} }
...@@ -1122,6 +1108,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -1122,6 +1108,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
} }
}
String generated = entrust.getCode(); String generated = entrust.getCode();
FileOutputStream os = null; FileOutputStream os = null;
File file = null; File file = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment