From a09523e8eeb5ae9fd7998feaa2a8886c369066a2 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期六, 22 三月 2025 08:31:18 +0800 Subject: [PATCH] 2025-3-22定制修改导出去掉容量和连接条 --- src/main/java/com/whyc/service/ExcelExportService.java | 389 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 389 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/whyc/service/ExcelExportService.java b/src/main/java/com/whyc/service/ExcelExportService.java index f89ecd6..028adeb 100644 --- a/src/main/java/com/whyc/service/ExcelExportService.java +++ b/src/main/java/com/whyc/service/ExcelExportService.java @@ -252,6 +252,210 @@ } } + public void resTestReport_cg(BattGroupStationInfoWithFileParam info, HttpServletResponse response) throws IOException { + Locale local = i18nLocaleResolver.getLocal(); + boolean zhFlag = local.getLanguage().toLowerCase().equals("zh"); + HashMap<String, Object> map = Maps.newHashMap(); + //鎬讳綋璇勪环:鍐呴樆/鐢靛帇/杩炴帴鏉�/?瀹归噺 + int resGoodCount = 0; + int volGoodCount = 0; + int chainResGoodCount = 0; + //鎬讳綋璇勪环:鏈夋晥鐨勭數闃�/鐢靛帇/杩炴帴鏉� 鏁� + int battVolTestCount = 0; + int battResTestCount = 0; + int battChainResTestCount = 0; + FileParam param = info.getFileParam(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + param.setTestTimeStr(format.format(param.getTestTime())); + //鏌ヨ鍏ㄥ眬鐨勬祴璇曠郴鏁板拰鍙傛暟 + TestParam param2 = testParamService.getFactorsAndThreshold(); + //鍒ゆ柇娴嬭瘯鏁版嵁鍛婅鑼冨洿 + Float stdRes = param.getBattRes(); + Float volLowCoeK1 = null; + Float volHighCoeK2 = null; + //鐢靛帇涓嶅悓,鐢靛帇闃堝�间笉鍚� + if(param.getBattVol() == 2){ + volLowCoeK1 = param2.getVol2LowCoeK1(); + volHighCoeK2 = param2.getVol2HighCoeK2(); + } + else if(param.getBattVol() == 1.2){ + volLowCoeK1 = param2.getVol1d2LowCoeK1(); + volHighCoeK2 = param2.getVol1d2HighCoeK2(); + } + else if(param.getBattVol() == 6){ + volLowCoeK1 = param2.getVol6LowCoeK1(); + volHighCoeK2 = param2.getVol6HighCoeK2(); + } + else if(param.getBattVol() == 12){ + volLowCoeK1 = param2.getVol12LowCoeK1(); + volHighCoeK2 = param2.getVol12HighCoeK2(); + }else{ //鐢靛帇闈炲父瑙勫��,鍒欓粯璁よ缃负2v鐨勭數鍘嬮槇鍊� + volLowCoeK1 = param2.getVol2LowCoeK1(); + volHighCoeK2 = param2.getVol2HighCoeK2(); + } + Float resGoodCoeK3 = param2.getResGoodCoeK3(); + Float resBadCoeK4 = param2.getResBadCoeK4(); + Float chainRes = param.getVersion().toUpperCase().contains("V2.0")?param.getChainRes():param.getConnRes(); + Float finalVolLowCoeK = volLowCoeK1; + Float finalVolHighCoeK = volHighCoeK2; + List<BattgroupData> dataList = info.getDataList(); + for(BattgroupData data : dataList){ + //璁$畻鐢靛帇,鍐呴樆,杩炴帴鏉℃暟鍊兼槸鍚︽湁鏁�,琚祴璇曡繃 + float bv = Float.parseFloat(data.getBv()); + float br = Float.parseFloat(data.getBr()); + float cr = Float.parseFloat(data.getCr()); + //璁$畻瀹归噺鐧惧垎姣�,骞跺洖濉埌dataList涓� + float preCap = MathUtil.getPreCapTest(br, stdRes); + String preCapStr = NumberFormat.getPercentInstance().format(preCap); + data.setPreCapPercentStr(preCapStr); + + if (bv!=0.0){ + battVolTestCount++; + } + if(br!=0.0){ + battResTestCount++; + } + if (cr!=0.0){ + battChainResTestCount++; + } + + data.setMonNumStr("#"+data.getMonNum()); + if(br==0.0){ + data.setResEvaluation("鈥�"); + } + /*else if(!data.isHighResFlag1() && !data.isHighResFlag2()){ + resGoodCount +=1; + data.setResEvaluation("浼�"); + }else if(data.isHighResFlag1()){ + data.setResEvaluation("鑹�"); + }else{ + data.setResEvaluation("宸�"); + }*/ + else if(br >= stdRes*resGoodCoeK3/100){ + if(br >= stdRes*resBadCoeK4/100){ + // data.setHighResFlag2(true); + if(zhFlag) { + data.setResEvaluation("宸�"); + }else{ + data.setResEvaluation("bad"); + } + }else{ + // data.setHighResFlag1(true); + if(zhFlag) { + data.setResEvaluation("鑹�"); + }else { + data.setResEvaluation("good"); + } + } + }else{ + resGoodCount +=1; + if(zhFlag) { + data.setResEvaluation("浼�"); + }else { + data.setResEvaluation("excellent"); + } + } + /*if(bv!=0.0 && !data.isLowVolFlag() && !data.isHighVolFlag()){ + volGoodCount +=1; + }*/ + if(bv!=0.0 && bv > finalVolLowCoeK && bv < finalVolHighCoeK){ + volGoodCount +=1; + } + /*if(cr!=0.0 && !data.isHighChainResFlag1() && !data.isHighChainResFlag2()){ + chainResGoodCount +=1; + }*/ + if(cr!=0.0 && cr < chainRes*param2.getChainResCoeK5()/100){ + chainResGoodCount +=1; + } + }; + info.setResGoodCount(resGoodCount); + info.setVolGoodCount(volGoodCount); + info.setChainResGoodCount(chainResGoodCount); + + info.setBattVolTestCount(battVolTestCount); + info.setBattResTestCount(battResTestCount); + info.setBattChainResTestCount(battChainResTestCount); + + StationInfo stationInfo = info.getStationInfo(); + if(stationInfo!=null) { + if (stationInfo.getStationName2().equals("-")) { + stationInfo.setStationName(stationInfo.getStationName1()); + } else { + stationInfo.setStationName(stationInfo.getStationName1() + "-" + stationInfo.getStationName2()); + } + } + map.put("dto", info); + //鍥剧墖 + //鐢靛帇鏌辩姸鍥� + BASE64Decoder decoder = new BASE64Decoder(); + if(!info.getVolPic().equals("")) { + ImageEntity volImage = new ImageEntity(); + volImage.setData(decoder.decodeBuffer(info.getVolPic().substring(info.getVolPic().indexOf(",") + 1))); + volImage.setColspan(6); + volImage.setRowspan(17); + + map.put("volImage",volImage); + } + //鍐呴樆鏌辩姸鍥� + if(!info.getResPic().equals("")) { + ImageEntity resImage = new ImageEntity(); + resImage.setData(decoder.decodeBuffer(info.getResPic().substring(info.getResPic().indexOf(",") + 1))); + resImage.setColspan(6); + resImage.setRowspan(16); + + map.put("resImage", resImage); + } + //鐢靛鏌辩姸鍥� + if(!info.getCondPic().equals("")) { + ImageEntity condImage = new ImageEntity(); + condImage.setData(decoder.decodeBuffer(info.getCondPic().substring(info.getCondPic().indexOf(",") + 1))); + condImage.setColspan(6); + condImage.setRowspan(16); + + map.put("condImage", condImage); + } + //閾炬帴鏉℃煴鐘跺浘 + if(!info.getChainPic().equals("")) { + ImageEntity chainImage = new ImageEntity(); + chainImage.setData(decoder.decodeBuffer(info.getChainPic().substring(info.getChainPic().indexOf(",") + 1))); + chainImage.setColspan(6); + chainImage.setRowspan(16); + + map.put("chainImage", chainImage); + } + + //map.put("volImage","volImage"); + //map.put("resImage","resImage"); + + //鑾峰彇瀵煎嚭妯℃澘鍦板潃 + ClassPathResource classPathResource; + if(zhFlag){ + classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template_cg.xls"); + }else { + classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template_en_cg.xls"); + } + String path = classPathResource.getPath(); + TemplateExportParams templateExportParams1 = new TemplateExportParams(path); + Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map); + String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); + String fileName; + if(zhFlag) { + fileName = "鍐呴樆璁℃祴璇�" + time + ".xls"; + }else{ + fileName = "Resistance Meter Test Report" + time + ".xls"; + } + try { + //response.setContentType("application/octet-stream;charset=utf-8"); + response.setContentType("application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); + response.flushBuffer(); + wb.write(response.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void resTestCompareReport(String fileId, String fileId2, BattGroupStationInfoWithFileParam dto, HttpServletResponse response) throws IOException { Locale local = i18nLocaleResolver.getLocal(); boolean zhFlag = local.getLanguage().toLowerCase().equals("zh"); @@ -433,4 +637,189 @@ e.printStackTrace(); } } + + + public void resTestCompareReport_cg(String fileId, String fileId2, BattGroupStationInfoWithFileParam dto, HttpServletResponse response) throws IOException { + Locale local = i18nLocaleResolver.getLocal(); + boolean zhFlag = local.getLanguage().toLowerCase().equals("zh"); + Map<String,Object> map = new HashMap<>(); + Response comparedList = battGroupDataService.getComparedList(fileId, fileId2); + List<BattgroupData> dataList = (List<BattgroupData>) comparedList.getData(); + List<BattgroupData> dataList2 = (List<BattgroupData>) comparedList.getData2(); + Map<String,List<String>> data3 = (Map<String, List<String>>) comparedList.getData3(); + + int baseSize = dataList.size(); + int size = dataList2.size(); + if(baseSize > size){ + dataList = dataList.subList(0,size); + }else{ + dataList2 = dataList2.subList(0,baseSize); + } + + + //鍙樺寲鐜� + List<String> resChangeRateList = data3.get("resChangeRate"); + List<String> volChangeRateList = data3.get("volChangeRate"); + /*map.put("resChangeRateList",resChangeRateList.subList(0,resChangeRateList.size()-1)); + map.put("volChangeRateList",volChangeRateList.subList(0,volChangeRateList.size()-1));*/ + + map.put("resChangeRateList",resChangeRateList); + map.put("volChangeRateList",volChangeRateList); + + map.put("volBalanceRateChangeRate",volChangeRateList.get(volChangeRateList.size()-1)); + map.put("resBalanceRateChangeRate",resChangeRateList.get(resChangeRateList.size()-1)); + //鍧囦竴鎬�:res/vol + List<String> resBalanceRateList = data3.get("resBalanceRate"); + List<String> volBalanceRateList = data3.get("volBalanceRate"); + //鍧囦竴鎬�:chainRes/?瀹归噺/bs(鐢靛) + NumberFormat percentInstance = NumberFormat.getPercentInstance(); + percentInstance.setMinimumFractionDigits(2); + + List<Float> chainResList = dataList2.stream().map(BattgroupData::getCr).map(Float::parseFloat).collect(Collectors.toList()); + List<Float> bsList = dataList2.stream().map(BattgroupData::getBs).map(Float::parseFloat).collect(Collectors.toList()); + String chainResBalanceRate = percentInstance.format(MathUtil.getStandardDeviation(chainResList)); + String bsBalanceRate = percentInstance.format(MathUtil.getStandardDeviation(bsList)); + //鑾峰彇FileParam鍜孲tationInfo + StationInfo stationInfo = stationInfoService.getByFileId(fileId2); + FileParam param = fileParamService.getByFileId(fileId2); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + param.setTestTimeStr(format.format(param.getTestTime())); + + FileParam paramBase = fileParamService.getByFileId(fileId); + String testTimeStrBase = format.format(paramBase.getTestTime()); + //鍥剧墖 + BASE64Decoder decoder = new BASE64Decoder(); + if(!dto.getVolPic().equals("")) { + ImageEntity volImage = new ImageEntity(); + volImage.setData(decoder.decodeBuffer(dto.getVolPic().substring(dto.getVolPic().indexOf(",") + 1))); + volImage.setColspan(6); + volImage.setRowspan(17); + + map.put("volImage",volImage); + } + + if(!dto.getResPic().equals("")) { + ImageEntity resImage = new ImageEntity(); + resImage.setData(decoder.decodeBuffer(dto.getResPic().substring(dto.getResPic().indexOf(",") + 1))); + resImage.setColspan(6); + resImage.setRowspan(16); + + map.put("resImage",resImage); + } + + if(stationInfo.getStationName2().equals("-")){ + stationInfo.setStationName(stationInfo.getStationName1()); + }else{ + stationInfo.setStationName(stationInfo.getStationName1()+"-"+stationInfo.getStationName2()); + } + + map.put("fileParam",param); + map.put("stationInfo",stationInfo); + //鎬讳綋璇勪环:鍐呴樆/鐢靛帇/杩炴帴鏉�/?瀹归噺 + int resGoodCount = 0; + int volGoodCount = 0; + int chainResGoodCount = 0; + + //鎬讳綋璇勪环:鏈夋晥鐨勭數闃�/鐢靛帇/杩炴帴鏉� 鏁� + int battVolTestCount = 0; + int battResTestCount = 0; + int battChainResTestCount = 0; + + for(BattgroupData data : dataList2){ + //璁$畻鐢靛帇,鍐呴樆,杩炴帴鏉℃暟鍊兼槸鍚︽湁鏁�,琚祴璇曡繃 + float bv = Float.parseFloat(data.getBv()); + float br = Float.parseFloat(data.getBr()); + float cr = Float.parseFloat(data.getCr()); + if (bv!=0.0){ + battVolTestCount++; + } + if(br!=0.0){ + battResTestCount++; + } + if (cr!=0.0){ + battChainResTestCount++; + } + + data.setMonNumStr("#"+data.getMonNum()); + if(br==0.0){ + data.setResEvaluation("鈥�"); + } + else if(!data.isHighResFlag1() && !data.isHighResFlag2() ){ + resGoodCount +=1; + if(zhFlag) { + data.setResEvaluation("浼�"); + }else { + data.setResEvaluation("excellent"); + } + }else if(data.isHighResFlag1()){ + if(zhFlag) { + data.setResEvaluation("鑹�"); + }else{ + data.setResEvaluation("good"); + } + }else{ + if(zhFlag) { + data.setResEvaluation("宸�"); + }else{ + data.setResEvaluation("bad"); + } + } + if(bv!=0.0 && !data.isLowVolFlag() && !data.isHighVolFlag()){ + volGoodCount +=1; + } + if(cr!=0.0 && !data.isHighChainResFlag1() && !data.isHighChainResFlag2()){ + chainResGoodCount +=1; + } + }; + map.put("resGoodCount",resGoodCount); + map.put("volGoodCount",volGoodCount); + map.put("chainResGoodCount",chainResGoodCount); + + map.put("battVolTestCount",battVolTestCount); + map.put("battResTestCount",battResTestCount); + map.put("battChainResTestCount",battChainResTestCount); + + map.put("dataList",dataList); + map.put("dataList2",dataList2); + + map.put("stdDevBv",volBalanceRateList.get(1)); + map.put("stdDevBr",resBalanceRateList.get(1)); + map.put("stdDevCr",chainResBalanceRate); + map.put("stdDevBs",bsBalanceRate); + map.put("testTimeStrBase",testTimeStrBase); + + map.put("stdDevBvBase",volBalanceRateList.get(0)); + map.put("stdDevBrBase",resBalanceRateList.get(0)); + + + //鑾峰彇瀵煎嚭妯℃澘鍦板潃 + ClassPathResource classPathResource; + if(zhFlag){ + classPathResource = new ClassPathResource("excel_templates/res_test_report_compare_template_cg.xls"); + }else{ + classPathResource = new ClassPathResource("excel_templates/res_test_report_compare_template_en_cg.xls"); + } + String path = classPathResource.getPath(); + TemplateExportParams templateExportParams1 = new TemplateExportParams(path); + templateExportParams1.setColForEach(true); + Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map); + String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss")); + String fileName; + if(zhFlag) { + fileName = "鍐呴樆璁℃祴璇�" + time + ".xls"; + }else{ + fileName = "Resistance Meter Test Report" + time + ".xls"; + } + try { + //response.setContentType("application/octet-stream;charset=utf-8"); + response.setContentType("application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); + response.flushBuffer(); + wb.write(response.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } -- Gitblit v1.9.1