From d58292a7a895984300f3ee69b81c6eb4f87e345f Mon Sep 17 00:00:00 2001
From: whycxzp <glperry@163.com>
Date: 星期六, 13 一月 2024 15:44:19 +0800
Subject: [PATCH] 导出和测试参数国际化

---
 src/main/java/com/whyc/service/ExcelExportService.java |   72 +++++++++++++++++++++++++++++++-----
 1 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/whyc/service/ExcelExportService.java b/src/main/java/com/whyc/service/ExcelExportService.java
index 5c832de..04a7bb2 100644
--- a/src/main/java/com/whyc/service/ExcelExportService.java
+++ b/src/main/java/com/whyc/service/ExcelExportService.java
@@ -4,6 +4,7 @@
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
 import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
 import com.google.common.collect.Maps;
+import com.whyc.config.I18nLocaleResolver;
 import com.whyc.dto.BattGroupStationInfoWithFileParam;
 import com.whyc.dto.Response;
 import com.whyc.pojo.BattgroupData;
@@ -44,7 +45,12 @@
     @Autowired
     private TestParamService testParamService;
 
+    @Autowired
+    private I18nLocaleResolver i18nLocaleResolver;
+
     public void resTestReport(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;
@@ -120,14 +126,26 @@
             else if(br >= stdRes*resGoodCoeK3/100){
                 if(br >= stdRes*resBadCoeK4/100){
                     // data.setHighResFlag2(true);
-                    data.setResEvaluation("宸�");
+                    if(zhFlag) {
+                        data.setResEvaluation("宸�");
+                    }else{
+                        data.setResEvaluation("bad");
+                    }
                 }else{
                     // data.setHighResFlag1(true);
-                    data.setResEvaluation("鑹�");
+                    if(zhFlag) {
+                        data.setResEvaluation("鑹�");
+                    }else {
+                        data.setResEvaluation("good");
+                    }
                 }
             }else{
                 resGoodCount +=1;
-                data.setResEvaluation("浼�");
+                if(zhFlag) {
+                    data.setResEvaluation("浼�");
+                }else {
+                    data.setResEvaluation("excellent");
+                }
             }
             /*if(bv!=0.0 && !data.isLowVolFlag() && !data.isHighVolFlag()){
                 volGoodCount +=1;
@@ -202,12 +220,22 @@
         //map.put("resImage","resImage");
 
         //鑾峰彇瀵煎嚭妯℃澘鍦板潃
-        ClassPathResource classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template.xls");
+        ClassPathResource classPathResource;
+        if(zhFlag){
+            classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template.xls");
+        }else {
+            classPathResource = new ClassPathResource("excel_templates/res_test_report_single_template_en.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 = "鍐呴樆璁℃祴璇�"+time+".xls";
+        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");
@@ -220,6 +248,8 @@
     }
 
     public void resTestCompareReport(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();
@@ -324,11 +354,23 @@
             }
             else if(!data.isHighResFlag1() && !data.isHighResFlag2() ){
                 resGoodCount +=1;
-                data.setResEvaluation("浼�");
+                if(zhFlag) {
+                    data.setResEvaluation("浼�");
+                }else {
+                    data.setResEvaluation("excellent");
+                }
             }else if(data.isHighResFlag1()){
-                data.setResEvaluation("鑹�");
+                if(zhFlag) {
+                    data.setResEvaluation("鑹�");
+                }else{
+                    data.setResEvaluation("good");
+                }
             }else{
-                data.setResEvaluation("宸�");
+                if(zhFlag) {
+                    data.setResEvaluation("宸�");
+                }else{
+                    data.setResEvaluation("bad");
+                }
             }
             if(bv!=0.0 && !data.isLowVolFlag() && !data.isHighVolFlag()){
                 volGoodCount +=1;
@@ -359,13 +401,23 @@
 
 
         //鑾峰彇瀵煎嚭妯℃澘鍦板潃
-        ClassPathResource classPathResource = new ClassPathResource("excel_templates/res_test_report_compare_template.xls");
+        ClassPathResource classPathResource;
+        if(zhFlag){
+            classPathResource  = new ClassPathResource("excel_templates/res_test_report_compare_template.xls");
+        }else{
+            classPathResource  = new ClassPathResource("excel_templates/res_test_report_compare_template_en.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 = "鍐呴樆璁℃祴璇�"+time+".xls";
+        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");

--
Gitblit v1.9.1