From f891000086af5ac150fc120e1f3c781266f1d063 Mon Sep 17 00:00:00 2001 From: wzp <2040239371@qq.com> Date: 星期三, 21 八月 2024 17:13:57 +0800 Subject: [PATCH] 优化LAQ全景图图表,使用python生成 --- src/main/java/com/ots/project/tool/report/LAQ/chart/LAQAllChart.java | 210 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 191 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQAllChart.java b/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQAllChart.java index 4308b1c..abe27f9 100644 --- a/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQAllChart.java +++ b/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQAllChart.java @@ -2,6 +2,7 @@ import com.ots.common.utils.StringUtils; import com.ots.common.utils.poi.ExcelUtil; +import com.ots.framework.config.EssConfig; import com.ots.project.tool.report.LAQ.LAQTemplate; import com.ots.project.tool.report.MAQ.base.RowData; import com.ots.project.tool.report.MAQ.base.SeriesData; @@ -9,13 +10,17 @@ import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.openxml4j.util.ZipSecureFile; +import org.apache.poi.util.Units; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xwpf.usermodel.XWPFChart; -import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.*; +import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.drawingml.x2006.chart.*; +import org.openxmlformats.schemas.drawingml.x2006.chartDrawing.CTDrawing; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject; +import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor; import java.io.*; import java.util.*; @@ -24,6 +29,7 @@ /** * 鍏ㄦ櫙鍥惧浘琛ㄦ覆鏌� + * 锛�2024.8.21浣滃簾锛� */ @Slf4j public class LAQAllChart { @@ -35,7 +41,7 @@ */ public static void main(String[] args) throws Exception { System.out.println("鍚姩娴嬭瘯.."); - String dataPath = "D:\\妗岄潰鏂囦欢\\LAQ鍏ㄦ櫙鍥炬姤鍛奬\LAQ瀵煎叆娴嬭瘯鏁版嵁.xlsx"; + String dataPath = "D:\\妗岄潰鏂囦欢\\LAQ鍏ㄦ櫙鍥炬姤鍛奬\53208d066321f94f47deecec7e9c6907.xlsx"; // 鑾峰彇瀵煎叆鏁版嵁 File file = new File(dataPath); InputStream in = new FileInputStream(file); @@ -66,19 +72,111 @@ * @param textMap 鏁版嵁婧� */ public static void changeChart(XWPFDocument document, Map<String, Object> textMap) { -// Map<Integer, List<SeriesData>> seriesDatas = initData(textMap); -// changeChart(document,seriesDatas,textMap); - System.out.println("杩涘叆鍏ㄦ櫙鍥炬覆鏌撴ā寮�"); + log.info("銆愯繘鍏ュ叏鏅浘娓叉煋妯″紡銆�"); try{ List<LAQTemplate> laqTemplateList = (List<LAQTemplate>)textMap.get("allList"); - changeChartNew(document,laqTemplateList); + //changeChartNew(document,laqTemplateList); + updateImage(document); System.out.println("鍏ㄦ櫙鍥炬覆鏌撳畬鎴�"); } catch (Exception ex) { log.error("LAQ鍏ㄦ櫙鍥惧紓甯革細"+ex.getMessage()); } + } + public static void updateImage(XWPFDocument document){ + //鏇挎崲鍥剧墖 + try{ + // 鑾峰彇鎵�鏈夋钀� + List<XWPFParagraph> paragraphs = document.getParagraphs(); + + //鑾峰彇鍥剧墖璺緞 +// String selectedPic = EssConfig.getReportTemplates()+"apifanSelected.png"; +// String defaultPic =EssConfig.getReportTemplates()+"apifanDefalut.png"; + + //娴嬭瘯鐢ㄧ殑 +// String img1 = "D:\\妗岄潰鏂囦欢\\LAQ鍏ㄦ櫙鍥炬姤鍛奬\111.png"; +// String img2 ="D:\\妗岄潰鏂囦欢\\LAQ鍏ㄦ櫙鍥炬姤鍛奬\222.png"; +// String img3 ="D:\\妗岄潰鏂囦欢\\LAQ鍏ㄦ櫙鍥炬姤鍛奬\333.png"; + + // /home/data + String img1 = EssConfig.getReportTemplates()+"111.png"; + String img2 =EssConfig.getReportTemplates()+"222.png"; + String img3 =EssConfig.getReportTemplates()+"333.png"; + + // 閬嶅巻娈佃惤杩涜鏇挎崲鎿嶄綔 + synchronized (paragraphs) { + for (XWPFParagraph paragraph : paragraphs) { + String text = paragraph.getText(); + + log.info("銆愯幏鍙栧埌鏂囨湰銆戯細"+text); + + // 灏嗗浘鐗囨彃鍏ュ埌娈佃惤涓� + int width = Units.toEMU(580); // 鍥剧墖瀹藉害 + int height = Units.toEMU(700); // 鍥剧墖楂樺害 + + //鐢�%%鍙峰湪鍓嶉潰灏辫鏇挎崲浜� + if (text.contains("{{box0}}")) { // 妫�鏌ユ槸鍚﹀寘鍚鏇挎崲鐨勬枃瀛楀彉閲� + log.info("銆愯幏鍙栧埌box0銆戯細"+img1); + // 鑾峰彇鎵�鏈夎繍琛岀殑鍒楄〃 + List<XWPFRun> runs = paragraph.getRuns(); + // 绉婚櫎鎵�鏈夎繍琛� + for (int i = runs.size() - 1; i >= 0 ; i--) { + paragraph.removeRun(i); + } + + //鍒涘缓Random绫诲璞� + Random random = new Random(); + //浜х敓闅忔満鏁� + int number = random.nextInt(999) + 1; + + // 鍒涘缓鍥剧墖瀵硅薄 + XWPFRun run = paragraph.createRun(); + int pictureType = Document.PICTURE_TYPE_PNG; // 鍥剧墖绫诲瀷 + run.addPicture(new FileInputStream(img1), pictureType, "Seal"+number, width, height); + + } + if (text.contains("{{box1}}")) { // 妫�鏌ユ槸鍚﹀寘鍚鏇挎崲鐨勬枃瀛楀彉閲� + + // 鑾峰彇鎵�鏈夎繍琛岀殑鍒楄〃 + List<XWPFRun> runs = paragraph.getRuns(); + // 绉婚櫎鎵�鏈夎繍琛� + for (int i = runs.size() - 1; i >= 0 ; i--) { + paragraph.removeRun(i); + } + // 鍒涘缓鍥剧墖瀵硅薄 + XWPFRun run = paragraph.createRun(); + int pictureType = Document.PICTURE_TYPE_PNG; // 鍥剧墖绫诲瀷 + + run.addPicture(new FileInputStream(img2), pictureType, "image.png", width, height); + + } + if (text.contains("{{box2}}")) { // 妫�鏌ユ槸鍚﹀寘鍚鏇挎崲鐨勬枃瀛楀彉閲� + + // 鑾峰彇鎵�鏈夎繍琛岀殑鍒楄〃 + List<XWPFRun> runs = paragraph.getRuns(); + // 绉婚櫎鎵�鏈夎繍琛� + for (int i = runs.size() - 1; i >= 0 ; i--) { + paragraph.removeRun(i); + } + // 鍒涘缓鍥剧墖瀵硅薄 + XWPFRun run = paragraph.createRun(); + int pictureType = Document.PICTURE_TYPE_PNG; // 鍥剧墖绫诲瀷 + + run.addPicture(new FileInputStream(img3), pictureType, "image.png", width, height); + + } + } + } + + + + } + catch (Exception ex) + { + log.info("銆愬紓甯搞��"+ex.getMessage()); + } } @@ -373,32 +471,64 @@ perfomance = 0.0; } + String name = laqTemplate.getName();//鏍囩鍚嶅瓧銆傝�冭檻鍒拌嫳鏂囦細姣旇緝闀匡紝浼氭牴鎹暱搴﹀仛閫傞厤 - //濡傛灉y杞村皬浜�1锛岃璁剧疆鎴�3锛屽線涓婄Щ鍔ㄤ竴涓� + + //濡傛灉y杞村皬浜�1锛岃璁剧疆鎴�3锛屽線涓婄Щ鍔ㄤ竴涓嬨�倅杞磋皟鏁� if(perfomance<=1.2) { - perfomance=perfomance+1.2; + perfomance=perfomance+1.5; } //濡傛灉y杞村ぇ浜�97锛岃缃垚97锛屽線涓嬬Щ鍔ㄤ竴鐐癸紝濂界湅 if(perfomance>=99) { - perfomance=99.0; + perfomance=98.0; } + + if(perfomance>33.0&&perfomance<34.0) + { + perfomance = perfomance+2.0; + } + + if(perfomance>66.0&&perfomance<67) + { + perfomance = perfomance+2.0; + } + + if(type==1) { //x杞磋寰�鍙宠竟绉诲姩 if(olas>67.0&olas<=70.0) { - olas=olas+1.5; - } + //鏍规嵁鍚嶅瓧闀垮害杩涜浣嶇Щ + double len = Math.ceil(name.length()/10.0)+1.0; + if(name.length()>15) + { + System.out.println("鍙栨暣鍊硷細"+len); + olas=olas+len; + } + else + { + olas=olas+1.5; + } + + } if(olas>=99.0) { - olas = olas-2.0; + if(name.length()>15) + { + olas = olas-3.0; + } + else { + olas = olas-2.0; + } + } } @@ -407,18 +537,60 @@ //x杞磋寰�鍙宠竟绉诲姩 if(olas>=33.0&olas<=35.0) { - olas= olas+1; + //鏍规嵁鍚嶅瓧闀垮害杩涜浣嶇Щ + double len = Math.ceil(name.length()/10.0)+1.0; + + if(name.length()>15) + { + System.out.println("鍙栨暣鍊硷細"+len); + olas=olas+len; + } + else + { + olas=olas+1.5; + } + } + + if(olas>66.0&olas<=67.0) + { + if(name.length()>15) + { + olas = olas-3.0; + } + else { + olas = olas-2.0; + } } } if(type==3) { //x杞磋寰�鍙宠竟绉诲姩 - if(olas>0.0 && olas<=3.0) + if(olas>=0.0 && olas<=3.0) { - olas= olas + 1; + double len = Math.ceil(name.length()/10.0)+1.0; + + if(name.length()>15) + { + System.out.println("鍙栨暣鍊硷細"+len); + olas=olas+len; + } + else + { + olas=olas+1.5; + } } + if(olas>=32.0&olas<=33.0) + { + if(name.length()>15) + { + olas = olas-3.0; + } + else { + olas = olas-2.0; + } + } } List<SeriesData> seriesDatas = new ArrayList<>(); @@ -505,7 +677,7 @@ { if(olas>67) { - seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"\n("+olasStr+"-"+perfomanceStr+")"); + seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"("+olasStr+"-"+perfomanceStr+")"); dataIndex++; } } @@ -514,7 +686,7 @@ { if(olas<=67 && olas>33) { - seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"\n("+olasStr+"-"+perfomanceStr+")"); + seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"("+olasStr+"-"+perfomanceStr+")"); dataIndex++; } } @@ -523,7 +695,7 @@ { if(olas<=33) { - seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"\n("+olasStr+"-"+perfomanceStr+")"); + seriesDataMapLables.put(dataIndex,laqTemplate.getName()+"("+olasStr+"-"+perfomanceStr+")"); dataIndex++; } -- Gitblit v1.9.1