| | |
| | | import com.ots.project.tool.ShellTool; |
| | | import com.ots.project.tool.exam.ExamUtil; |
| | | import com.ots.project.tool.exam.ImageUtil; |
| | | import com.ots.project.tool.exam.JsonUtil; |
| | | import com.ots.project.tool.exam.ZipUtil; |
| | | import com.ots.project.tool.libreoffice.LibreOfficeUtil; |
| | | import com.ots.project.tool.report.APIFan.chart.APIFanChart; |
| | | import com.ots.project.tool.report.CIAQ.chart.CIAQChart; |
| | | import com.ots.project.tool.report.JAQ.condition.JAQTeam; |
| | | import com.ots.project.tool.report.LAQ.chart.LAQChart; |
| | | import com.ots.project.tool.report.MAQTR.chart.MAQTRChart; |
| | | import com.ots.project.tool.report.PAQ.chart.PAQChart; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.w3c.dom.Node; |
| | | import org.w3c.dom.NodeList; |
| | | import springfox.documentation.spring.web.json.Json; |
| | | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | log.info("表格数据:" + table.getText()); |
| | | //增加表格或者減少表格 |
| | | if (Objects.equals(textMap.get("sendEmailFileName"), ReportTypeEnum.JAQ.getCode())) { |
| | | log.info("表:{}",i); |
| | | addOrDelTableRow(table,i,textMap); |
| | | } |
| | | if (checkText(table.getText())) { |
| | |
| | | Integer tableNum = Integer.valueOf(textMap.get(tableEnum.getName()).toString()); |
| | | Integer rows = table.getRows().size(); |
| | | |
| | | log.info("[测试]-tableEnum:"+tableEnum.toString()); |
| | | |
| | | //表1-表3 需剔除表头 |
| | | Integer contentRows = rows - 1; |
| | | //表4 需剔除表头跟尾部预留行数 |
| | | if(tableEnum == TableEnum.table4){ |
| | | contentRows -= 5; |
| | | rows -= 5; |
| | | //如果表4,要增加显示行,这里要改动 |
| | | contentRows -= 3; |
| | | rows -= 3; |
| | | |
| | | //表4 行为表现举例处理 |
| | | Integer table4ChildrenNum = Integer.valueOf(textMap.get(TableEnum.table4Children.getName()).toString()); |
| | |
| | | } |
| | | } |
| | | |
| | | //table5不需要追加,单独处理 |
| | | if(tableEnum != TableEnum.table5) { |
| | | //限制行数不为空 和 限制行数跟报告现有不一致需进行处理 |
| | | if(tableNum != null && !tableNum.equals(contentRows)){ |
| | | if(tableNum > contentRows){ |
| | |
| | | log.info("{}减少{}行数",TableEnum.codeOf(index).getName(),delRow-1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //如果表4,要增加显示行,这里要改动 |
| | | //表4 胜任力预留位置序号处理 |
| | | if(tableEnum == TableEnum.table4){ |
| | | if(tableNum != null && tableNum != 8){ |
| | | for (int i = tableNum; i <= tableNum + 4; i++) { |
| | | if(tableNum != null && tableNum != 12){ |
| | | for (int i = tableNum; i <= tableNum + 2; i++) { |
| | | if(i+2 > table.getRows().size()){ |
| | | continue; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //表6,显示JAQ报告参与人 |
| | | if(tableEnum == TableEnum.table5) |
| | | { |
| | | log.info("【表5】开始处理...{}",tableNum); |
| | | // if(tableNum != null && !tableNum.equals(contentRows)) { |
| | | // if (tableNum > contentRows) { |
| | | // //增加行数 |
| | | // Integer addRow = tableNum - contentRows; |
| | | // log.info("{}增加{}行", tableEnum.getName(), addRow); |
| | | // for (int i = rows; i < rows + addRow; i++) { |
| | | // addJAQTable(table, tableEnum, i, textMap); |
| | | // } |
| | | // } |
| | | // } |
| | | if(tableNum>0) |
| | | { |
| | | for(int i=rows;i<rows+tableNum;i++) |
| | | { |
| | | addJAQTable(table, tableEnum, i, textMap); |
| | | } |
| | | |
| | | delJAQTable(table,1); |
| | | } |
| | | log.info("【表5】处理完成..."); |
| | | } |
| | | |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.info("表{}增加表格或者減少表格异常",index+1); |
| | | log.info("异常:{}",e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | XWPFTableRow row = table.getRows().get(index); |
| | | List<XWPFTableCell> cells = row.getTableCells(); |
| | | |
| | | switch (tableEnum){ |
| | | case table1: |
| | | cells.get(0).getParagraphs().get(0).getRuns().get(0).setText(textMap.get("T1rank"+index)+""); |
| | |
| | | cell.getParagraphs().get(cell.getParagraphs().size()-1).getRuns().get(0).setText(null); |
| | | } |
| | | } |
| | | break; |
| | | case table5: |
| | | log.info("[add] table5,增加行。index={}",index); |
| | | String teamUsers = textMap.get("teamUserList").toString(); |
| | | List<JAQTeam> teamUserList = JsonUtil.toJsonListObject(teamUsers,JAQTeam.class); |
| | | |
| | | int keyIndex = index-2; |
| | | if(keyIndex>=0) |
| | | { |
| | | log.info("当前keyIndex:{}",keyIndex); |
| | | for(int k =0;k<3;k++) |
| | | { |
| | | XWPFParagraph p =cells.get(k).getParagraphs().get(0); |
| | | List<XWPFRun> runs = p.getRuns(); |
| | | if(runs.isEmpty()) |
| | | { |
| | | p.createRun(); |
| | | } |
| | | for (int i = runs.size()-1;i>0;i--) |
| | | { |
| | | p.removeRun(i); |
| | | } |
| | | XWPFRun run = runs.get(0); |
| | | |
| | | switch (k){ |
| | | case 0:run.setText(String.valueOf(keyIndex+1),0); break; |
| | | case 1:run.setText(teamUserList.get(keyIndex).getTeamName(),0);break; |
| | | case 2:run.setText(teamUserList.get(keyIndex).getTeamDepart(),0);break; |
| | | case 3:run.setText(teamUserList.get(keyIndex).getTeamName(),0);break; |
| | | default:break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // cells.get(0).getParagraphs().get(0).getRuns().get(0).setText(index.toString()); |
| | | // cells.get(1).getParagraphs().get(0).getRuns().get(0).setText(teamUserList.get(index).getTeamName()); |
| | | // cells.get(2).getParagraphs().get(0).getRuns().get(0).setText(teamUserList.get(index).getTeamDepart()); |
| | | // cells.get(3).getParagraphs().get(0).getRuns().get(0).setText(teamUserList.get(index).getTeamName()); |
| | | break; |
| | | } |
| | | } |
| | |
| | | // //设置文本 |
| | | // changeText(document, textMap); |
| | | |
| | | |
| | | //修改页脚 |
| | | changeFootNotes(document,textMap); |
| | | |
| | | //插入表格 |
| | | addTableValue(document, autoTableMap); |
| | |
| | | changChart(textMap, document, reportType,dataPath); |
| | | document.write(out); |
| | | } |
| | | |
| | | /** |
| | | * 修改页脚(主要是把年限给换了) |
| | | * @param document |
| | | * @param textMap |
| | | * @throws DocumentException |
| | | */ |
| | | private static void changeFootNotes(XWPFDocument document,Map<String,Object> textMap) throws DocumentException{ |
| | | |
| | | LocalDate currentDate = LocalDate.now(); |
| | | int year = currentDate.getYear(); |
| | | |
| | | // 获取所有页 |
| | | List<XWPFFooter> footers = document.getFooterList(); |
| | | |
| | | for (XWPFFooter footer : footers) { |
| | | // 获取每个页脚的段落 |
| | | List<XWPFParagraph> paragraphs = footer.getParagraphs(); |
| | | |
| | | // 打印每个段落的文本 |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | | System.out.println(paragraph.getText()); |
| | | |
| | | log.info("【页脚】:{}",paragraph.getText()); |
| | | if(paragraph.getText().contains("%year%")) |
| | | { |
| | | // 获取段落中的所有run |
| | | List<XWPFRun> runs = paragraph.getRuns(); |
| | | |
| | | // 替换文本 |
| | | for (XWPFRun run : runs) { |
| | | String text = run.getText(0); |
| | | if (text != null && text.contains("%year%")) { |
| | | text = text.replace("%year%", String.valueOf(year)); |
| | | run.setText(text, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException { |
| | | List<XWPFParagraph> paragraphs = document.getParagraphs(); |
| | | |