Commit 8c7fb381 by lijingjing

Merge remote-tracking branch 'origin/master'

parents 1542bba8 66455bdc
...@@ -961,166 +961,153 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -961,166 +961,153 @@ 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++) {
String sheetName = sheetOne.getSheetName(); HSSFWorkbookUtil.replaceModel(mapReplace, xssfWorkbook, k);
System.out.println(sheetName); XSSFSheet sheetOne = xssfWorkbook.getSheetAt(k);
sheetOne.setForceFormulaRecalculation(true); String sheetName = sheetOne.getSheetName();
System.out.println(sheetName);
int sampleMergerNum = sysFileTemplate.getSampleMergerNum(); sheetOne.setForceFormulaRecalculation(true);
int templateSampleNum = sysFileTemplate.getTemplateSampleNum();
if (templateSampleNum >= sampleVOList.size()) { int sampleMergerNum = sysFileTemplate.getSampleMergerNum();
Integer beginRow = sysFileTemplate.getSampleBeginRow(); int templateSampleNum = sysFileTemplate.getTemplateSampleNum();
for (EntrustSampleVO vo : sampleVOList) { if (templateSampleNum >= sampleVOList.size()) {
Integer beginRow = sysFileTemplate.getSampleBeginRow();
HashMap<Long, List<EntrustSampleItemIndex>> indexMap = new HashMap<>();
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<>();
vo.setIndexList(indexList); if (indexMap.containsKey(vo.getId())) {
XSSFRow xssfRow = sheetOne.getRow(beginRow); indexList = indexMap.get(vo.getId());
for (EntrustReportTemplateConfig config : configList) { } else {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace()); indexList = entrustSampleItemIndexService.getInReportItemIndex(vo.getId());
if ("sn".equals(config.getDataAttribute())) {
continue;
} }
if (StringUtils.isBlank(config.getDataAttribute())) { vo.setIndexList(indexList);
continue; XSSFRow xssfRow = sheetOne.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
if (null != config.getSheetNum() && config.getSheetNum() != k) {
continue;
}
if (null == config.getColumnPlace()) {
continue;
}
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
} }
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo); beginRow += sampleMergerNum;
cell.setCellValue(value);
}
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 {
if (null != sysFileTemplate.getMoreSheet() && sysFileTemplate.getMoreSheet() == 1) { if (null != sysFileTemplate.getMoreSheet() && sysFileTemplate.getMoreSheet() == 1) {
int total = sampleVOList.size(); int total = sampleVOList.size();
int totalSheetSize = (total + templateSampleNum - 1) / templateSampleNum; int totalSheetSize = (total + templateSampleNum - 1) / templateSampleNum;
List<List<EntrustSampleVO>> listList = Lists.partition(sampleVOList, templateSampleNum); List<List<EntrustSampleVO>> listList = Lists.partition(sampleVOList, templateSampleNum);
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();
List<EntrustSampleVO> sampleVOListIndex = listList.get(k);
for (EntrustSampleVO vo : sampleVOListIndex) {
List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId());
vo.setIndexList(indexList);
XSSFSheet sheetOneIndex = xssfWorkbook.getSheetAt(k);
XSSFRow xssfRow = sheetOneIndex.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
if ("sn".equals(config.getDataAttribute())) {
continue;
}
if (StringUtils.isBlank(config.getDataAttribute())) {
continue;
}
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo);
cell.setCellValue(value);
}
beginRow += sampleMergerNum;
}
}
} else {
Integer beginRow = sysFileTemplate.getSampleBeginRow(); Integer beginRow = sysFileTemplate.getSampleBeginRow();
List<EntrustSampleVO> sampleVOListIndex = listList.get(k); int insertRow = beginRow + sampleMergerNum * templateSampleNum;
XSSFRow zeroRow = sheetOne.getRow(beginRow);
XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum();
int insertCount = sampleVOList.size() - templateSampleNum;
for (int m = 0; m < insertCount; m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1, true, false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
for (EntrustSampleVO vo : sampleVOListIndex) { }
}
int sn = 1;
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId()); List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId());
vo.setIndexList(indexList); vo.setIndexList(indexList);
XSSFSheet sheetOneIndex = xssfWorkbook.getSheetAt(k);
XSSFRow xssfRow = sheetOneIndex.getRow(beginRow);
for (EntrustReportTemplateConfig config : configList) { for (EntrustReportTemplateConfig config : configList) {
XSSFCell cell = xssfRow.getCell(config.getColumnPlace()); if (null != config.getSheetNum() && config.getSheetNum() != k) {
if ("sn".equals(config.getDataAttribute())) {
continue; continue;
} }
if (StringUtils.isBlank(config.getDataAttribute())) { if (null == config.getColumnPlace()) {
continue; continue;
} }
String value = StringHandleUtils.getFieldValue(config.getDataAttribute(), vo); XSSFCell cell = xssfRow.getCell(config.getColumnPlace());
cell.setCellValue(value); if ("sn".equals(config.getDataAttribute())) {
cell.setCellValue(sn);
} else {
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(), vo));
}
} }
beginRow += sampleMergerNum; beginRow += sampleMergerNum;
} sn++;
}
} else {
Integer beginRow = sysFileTemplate.getSampleBeginRow();
int insertRow = beginRow + sampleMergerNum * templateSampleNum;
XSSFRow zeroRow = sheetOne.getRow(beginRow);
XSSFCellStyle cellStyle = zeroRow.getCell(0).getCellStyle();
int lastCellNum = zeroRow.getLastCellNum();
int insertCount = sampleVOList.size() - templateSampleNum;
for (int m = 0; m < insertCount; m++) {
for (int i = 0; i < sampleMergerNum; i++) {
sheetOne.shiftRows(insertRow, sheetOne.getLastRowNum(), 1, true, false);
XSSFRow row = sheetOne.createRow(insertRow);
row.setHeight(zeroRow.getHeight());
for (int j = 0; j < lastCellNum; j++) {
XSSFCell xssfCell = row.createCell(j);
xssfCell.setCellStyle(cellStyle);
}
insertRow++;
} }
}
int sn = 1;
for (EntrustSampleVO vo : sampleVOList) {
XSSFRow xssfRow = sheetOne.getRow(beginRow);
List<EntrustSampleItemIndex> indexList = entrustSampleItemIndexService.listBySampleId(vo.getId());
vo.setIndexList(indexList);
for (EntrustReportTemplateConfig config : configList) { for (EntrustReportTemplateConfig config : configList) {
if (null == config.getColumnPlace()) { if (null == config.getMergeRowNum()) {
config.setMergeRowNum(1);
}
if (null == config.getMergeBegin()) {
continue; continue;
} }
XSSFCell cell = xssfRow.getCell(config.getColumnPlace()); if (null == config.getMergeEnd()) {
if ("sn".equals(config.getDataAttribute())) { continue;
cell.setCellValue(sn);
} else {
cell.setCellValue(StringHandleUtils.getFieldValue(config.getDataAttribute(), vo));
} }
} int step = config.getMergeRowNum();
beginRow += sampleMergerNum; if (step == 1 && config.getMergeEnd() == config.getMergeBegin()) {
sn++; continue;
}
} if (null != config.getColumnPlace() && null != config.getMergeRowNum()) {
for (EntrustReportTemplateConfig config : configList) { Integer sampleBgMum = sysFileTemplate.getSampleBeginRow() + templateSampleNum * sampleMergerNum;
if (null == config.getMergeRowNum()) { Integer sampleEnMum = sysFileTemplate.getSampleBeginRow() + sampleVOList.size() * sampleMergerNum - 1;
config.setMergeRowNum(1); while (sampleBgMum <= sampleEnMum) {
} sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum, sampleBgMum + step - 1, config.getMergeBegin(), config.getMergeEnd()));
if (null == config.getMergeBegin()) { sampleBgMum = sampleBgMum + step;
continue; }
}
if (null == config.getMergeEnd()) {
continue;
}
int step = config.getMergeRowNum();
if (step == 1 && config.getMergeEnd() == config.getMergeBegin()) {
continue;
}
if (null != config.getColumnPlace() && null != config.getMergeRowNum()) {
Integer sampleBgMum = sysFileTemplate.getSampleBeginRow() + templateSampleNum * sampleMergerNum;
Integer sampleEnMum = sysFileTemplate.getSampleBeginRow() + sampleVOList.size() * sampleMergerNum - 1;
while (sampleBgMum <= sampleEnMum) {
sheetOne.addMergedRegion(new CellRangeAddress(sampleBgMum, sampleBgMum + step - 1, config.getMergeBegin(), config.getMergeEnd()));
sampleBgMum = sampleBgMum + step;
} }
} }
} }
}
}
} }
String generated = entrust.getCode(); String generated = entrust.getCode();
FileOutputStream os = null; FileOutputStream os = 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