From c1e85975772b22e926ff4a75870c86f3b234aec4 Mon Sep 17 00:00:00 2001 From: 林致杰 <1003392067@qq.com> Date: 星期日, 31 七月 2022 14:10:14 +0800 Subject: [PATCH] MAQ组别报告更改数据源 --- src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java | 183 ++++++++++++++++++++++++++++++++++-- src/main/java/com/ots/common/enums/CapabilityEnum.java | 81 ++++++++++++++++ 2 files changed, 251 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ots/common/enums/CapabilityEnum.java b/src/main/java/com/ots/common/enums/CapabilityEnum.java new file mode 100644 index 0000000..fa244e5 --- /dev/null +++ b/src/main/java/com/ots/common/enums/CapabilityEnum.java @@ -0,0 +1,81 @@ +package com.ots.common.enums; + +import lombok.Data; + +import java.util.Objects; + +/** + * @version 1.0 + * @Author linzhijie + * @Description 鑳滀换鍔� + * @Date 2022/07/31 12:00 + */ +public enum CapabilityEnum { + + C_1(1, "1.鐏垫椿鎬�"), + C_2(2, "2.鍒涢�犳��"), + C_3(3,"3.鍒嗘瀽瀵煎悜"), + C_4(4, "4.鑷富鐙珛"), + C_5(5,"5.鎴愬氨瀵煎悜"), + C_6(6, "6.鑳藉姩鎬�"), + C_7(7, "7.鍧氭寔鎬�"), + C_8(8, "8.缁嗚嚧鎬�"), + C_9(9, "9.鍙潬鎬�"), + C_10(10, "10.璁″垝/缁勭粐鎬�"), + C_11(11, "11.鍧﹁瘹瀹堣"), + C_12(12, "12.涓汉绮惧姏"), + C_13(13, "13.绀句氦涓诲姩鎬�"), + C_14(14, "14.鏀厤鎬�"), + C_15(15, "15.褰卞搷鍔�"), + C_16(16, "16.鍥㈤槦鍚堜綔"), + C_17(17, "17.鍚岀悊蹇�"), + C_18(18, "18.绀句氦鏁忔劅鎬�"), + C_19(19, "19.鑷帶鍔�"), + C_20(20, "20.鍘嬪姏绠$悊"), + C_21(21, "21.鑷俊/寮规��"), + C_22(22, "22.涓撴敞/瑙夊療"), + C_23(23, "23.鑷じ"), + C_24(24, "24.鍗拌薄绠$悊"), + C_25(25,"25.绛旈涓嶄竴鑷�"), + C_26(26, "26.寮�鏀炬��"), + C_27(27, "27.璁ょ湡璐熻矗鎬�"), + C_28(28, "28.澶栧悜鎬�"), + C_29(29, "29.浜插拰鎬�"), + C_30(30, "30.鎯呯华绋冲畾鎬�"), + C_31(31, "31.浠诲姟/缁撴灉瀵煎悜"), + C_32(32, "32.鍏崇郴/浜洪檯瀵煎悜"), + C_33(33, "33.鍒ゆ柇-鍐崇瓥娼滃姏"); + + int code; + String name; + + CapabilityEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public Integer getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static String codeOf(Integer code) { + for (CapabilityEnum xxxEnum : values()) { + if (Objects.equals(xxxEnum.getCode(), code)) { + return xxxEnum.getName(); + } + } + throw new RuntimeException("The Capability is not supported!"); + } +} diff --git a/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java index ac49bee..0dd7306 100644 --- a/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java +++ b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java @@ -1,6 +1,7 @@ package com.ots.project.tool.report.MAQTR.chart; import com.alibaba.fastjson.JSON; +import com.ots.common.enums.CapabilityEnum; import com.ots.common.utils.StringUtils; import com.ots.project.tool.report.MAQ.base.RowData; import com.ots.project.tool.report.MAQ.base.SeriesData; @@ -13,8 +14,7 @@ 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.openxmlformats.schemas.drawingml.x2006.chart.*; import java.io.*; @@ -33,15 +33,16 @@ public static void main(String[] args) throws IOException { try { -/* OutputStream os = new FileOutputStream("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\鏋梍PAQ_IA_CN1.docx"); + OutputStream os = new FileOutputStream("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\鏋梍PAQ_IA_CN2.docx"); XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁堢銆�0607涓枃鐗堛�慚AQ缁勫埆瀵规瘮鎶ュ憡.docx")); - String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\MAQ缁勫埆瀵煎叆鏁版嵁妯℃澘.xlsx"; + String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁勫埆瀵规瘮鎶ュ憡娴嬭瘯鏁版嵁.xlsx"; //鍙樻洿鍥捐〃鏁版嵁 changeMAQTRChart(document,fileName); - document.write(os);*/ - String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁勫埆瀵规瘮鎶ュ憡娴嬭瘯鏁版嵁.xlsx"; - replaceContent(fileName); + document.write(os); +/* String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁勫埆瀵规瘮鎶ュ憡娴嬭瘯鏁版嵁.xlsx"; + //replaceContent(fileName); + initDataNew(fileName,1);*/ }catch (Exception e){ e.printStackTrace(); } @@ -51,7 +52,9 @@ /** * 璁$畻鏁版嵁骞剁敓鎴愭ā鏉� */ - public static void replaceContent(String fileName){ + public static Map<String,Map<Integer,Double>> replaceContent(String fileName){ + //骞冲潎鍊奸泦鍚� + Map<String,Map<Integer,Double>> averageMap = new HashMap<>(); try { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(fileName)); Map<String,Map<Integer,List<Double>>> dataMap = new HashMap<>(); @@ -60,8 +63,9 @@ String companyName = sheet.getRow(1).getCell(0).getStringCellValue(); Map<Integer,List<Double>> map = new HashMap<>(); //琛� - for (int j = 1; j < sheet.getLastRowNum(); j++) { + for (int j = 1; j <= sheet.getLastRowNum(); j++) { XSSFRow row = sheet.getRow(j); + //鍒� for (int k = 1; k < row.getLastCellNum(); k++) { XSSFCell cell = row.getCell(k); /* @@ -83,11 +87,156 @@ } dataMap.put(companyName,map); } - System.out.println(dataMap); + //骞冲潎鍊奸泦鍚� + for (Map.Entry<String, Map<Integer, List<Double>>> map : dataMap.entrySet()) { + //33涓釜鎬ч泦鍚堝�� + Map<Integer,List<Double>> valMap = map.getValue(); + //缁熻涓�у钩鍧囧�� + Map<Integer,Double> doubleMap = new HashMap<>(); + for (Map.Entry<Integer, List<Double>> val : valMap.entrySet()) { + List<Double> doubleList = val.getValue(); + //璁$畻骞冲潎鍊� + double average = doubleList.stream().mapToDouble(e -> e).average().orElse(0.00); + doubleMap.put(val.getKey(),average); + } + averageMap.put(map.getKey(),doubleMap); + } + //System.out.println(averageMap); }catch (Exception e){ e.printStackTrace(); + log.error("璁$畻骞冲潎鍊煎嚭閿�!"); } + return averageMap; + } + /** + * 鍒濆鍖栨姤鍛婃暟鎹� + * @param fileName 鏁版嵁婧愭枃浠跺悕 + * @param index 妯℃澘sheet绱㈠紩 + * @return + */ + public static List<SeriesData> initDataNew(String fileName,Integer index){ + Map<String,Map<Integer,Double>> dataMap = replaceContent(fileName); + List<SeriesData> seriesDatas = new ArrayList<>(); + if(dataMap != null){ + int oneIndex = 22; + int twoIndex = 33; + //1-22涓�� + if(index == 0){ + //涓�� [绗竴琛宂 + SeriesData title = new SeriesData(); + String name = "涓��"; + title.setName(name); + List<RowData> rowDataList = new ArrayList<>(); + for (int i = oneIndex; i > 0; i--) { + RowData rowData = new RowData(); + rowData.setName(name); + rowData.setValueStr(CapabilityEnum.codeOf(i)); + rowDataList.add(rowData); + } + title.setValue(rowDataList); + seriesDatas.add(title); + //鍔ㄦ�佸�� + for (Map.Entry<String,Map<Integer,Double>> map : dataMap.entrySet()) { + SeriesData valSeriesData = new SeriesData(); + valSeriesData.setName(map.getKey()); + Map<Integer,Double> valMap = map.getValue(); + List<RowData> valRowDataList = new ArrayList<>(); + for (int i = oneIndex; i > 0; i--) { + RowData rowData = new RowData(); + rowData.setName(map.getKey()); + rowData.setValue(valMap.get(i)); + valRowDataList.add(rowData); + } + valSeriesData.setValue(valRowDataList); + seriesDatas.add(valSeriesData); + } + //鍥哄畾杈呭姪鍒� + String auxiliary = "杈呭姪"; + SeriesData auxiliaryTitle = new SeriesData(); + auxiliaryTitle.setName(auxiliary); + List<RowData> auxiliaryRowDataList = new ArrayList<>(); + for (int i = 1; i <= oneIndex; i++) { + RowData rowData = new RowData(); + rowData.setName(auxiliary); + rowData.setValue(i); + auxiliaryRowDataList.add(rowData); + } + auxiliaryTitle.setValue(auxiliaryRowDataList); + seriesDatas.add(auxiliaryTitle); + //鍧愭爣绾� + String blank = " "; + SeriesData blankTitle = new SeriesData(); + blankTitle.setName(blank); + List<RowData> blankTitleRowDataList = new ArrayList<>(); + for (int i = 1; i <= oneIndex; i++) { + RowData rowData = new RowData(); + rowData.setName(blank); + rowData.setValue(0); + blankTitleRowDataList.add(rowData); + } + blankTitle.setValue(blankTitleRowDataList); + seriesDatas.add(blankTitle); + } + //23-33涓�� + if(index == 1){ + //涓�� [绗竴琛宂 + SeriesData title = new SeriesData(); + String name = "涓��"; + title.setName(name); + List<RowData> rowDataList = new ArrayList<>(); + for (int i = twoIndex; i > oneIndex; i--) { + RowData rowData = new RowData(); + rowData.setName(name); + rowData.setValueStr(CapabilityEnum.codeOf(i)); + rowDataList.add(rowData); + } + title.setValue(rowDataList); + seriesDatas.add(title); + //鍔ㄦ�佸�� + for (Map.Entry<String,Map<Integer,Double>> map : dataMap.entrySet()) { + SeriesData valSeriesData = new SeriesData(); + valSeriesData.setName(map.getKey()); + Map<Integer,Double> valMap = map.getValue(); + List<RowData> valRowDataList = new ArrayList<>(); + for (int i = twoIndex; i > oneIndex; i--) { + RowData rowData = new RowData(); + rowData.setName(map.getKey()); + rowData.setValue(valMap.get(i)); + valRowDataList.add(rowData); + } + valSeriesData.setValue(valRowDataList); + seriesDatas.add(valSeriesData); + } + //鍥哄畾杈呭姪鍒� + String auxiliary = "杈呭姪"; + SeriesData auxiliaryTitle = new SeriesData(); + auxiliaryTitle.setName(auxiliary); + List<RowData> auxiliaryRowDataList = new ArrayList<>(); + for (int i = 1; i <= (twoIndex-oneIndex); i++) { + RowData rowData = new RowData(); + rowData.setName(auxiliary); + rowData.setValue(i); + auxiliaryRowDataList.add(rowData); + } + auxiliaryTitle.setValue(auxiliaryRowDataList); + seriesDatas.add(auxiliaryTitle); + //鍧愭爣绾� + String blank = " "; + SeriesData blankTitle = new SeriesData(); + blankTitle.setName(blank); + List<RowData> blankTitleRowDataList = new ArrayList<>(); + for (int i = 1; i <= (twoIndex-oneIndex); i++) { + RowData rowData = new RowData(); + rowData.setName(blank); + rowData.setValue(0); + blankTitleRowDataList.add(rowData); + } + blankTitle.setValue(blankTitleRowDataList); + seriesDatas.add(blankTitle); + } + } + return seriesDatas; } /** @@ -200,7 +349,9 @@ index = 1; } //鑾峰彇妯℃澘鏁版嵁 - List<SeriesData> seriesDatas = initData(fileName,index); + List<SeriesData> seriesDatas = initDataNew(fileName,index); + //List<SeriesData> seriesDatas = initData(fileName,index); + //log.error(JSON.toJSONString(seriesDatas)); //鏁版嵁闀垮害 int size = seriesDatas.size(); // 鏌ョ湅閲岄潰鐨勫浘琛ㄦ暟鎹紝鎵嶈兘鐭ラ亾鏄粈涔堝浘琛� @@ -242,7 +393,7 @@ } CTScatterSer ser = scatterChart.getSerList().get(i); - updateScatterChart(scatterDatas, ser.getXVal(), ser.getYVal()); + updateScatterChart(scatterDatas,ser.getTx(), ser.getXVal(), ser.getYVal()); } } } @@ -361,9 +512,15 @@ * @param xDataSource X鍧愭爣鏁版嵁缂撳瓨 * @param yDataSource Y鍧愭爣鏁版嵁缂撳瓨 */ - protected static void updateScatterChart(List<SeriesData> seriesDatas, CTAxDataSource xDataSource, + protected static void updateScatterChart(List<SeriesData> seriesDatas,CTSerTx serTitle, CTAxDataSource xDataSource, CTNumDataSource yDataSource) { + // 鏇存柊绯诲垪鏍囬 + if(StringUtils.isNotEmpty(seriesDatas.get(0).getName())){ + serTitle.getStrRef().setF(serTitle.getStrRef().getF()); + serTitle.getStrRef().getStrCache().getPtArray(0).setV(seriesDatas.get(0).getName()); + } + //鑾峰彇xy鍧愭爣鏁版嵁鏉℃暟 long xNumCnt = xDataSource.getNumRef().getNumCache().getPtCount().getVal(); long yNumCnt = yDataSource.getNumRef().getNumCache().getPtCount().getVal(); -- Gitblit v1.9.1