From ecb37e69b4b9587de63a584064688442cf4b64b7 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 22 四月 2025 10:07:59 +0800
Subject: [PATCH] art: 设备管理-点检工单-字典翻译

---
 lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java |  248 +++++++++++++++++++++++++------------------------
 1 files changed, 126 insertions(+), 122 deletions(-)

diff --git a/lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java b/lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java
index a4ed593..1c4ff26 100644
--- a/lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java
+++ b/lxzn-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java
@@ -58,14 +58,14 @@
 
     @Around("excudeService()")
     public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
-    	long time1=System.currentTimeMillis();
+        long time1 = System.currentTimeMillis();
         Object result = pjp.proceed();
-        long time2=System.currentTimeMillis();
-        log.debug("鑾峰彇JSON鏁版嵁 鑰楁椂锛�"+(time2-time1)+"ms");
-        long start=System.currentTimeMillis();
-        result=this.parseDictText(result);
-        long end=System.currentTimeMillis();
-        log.debug("娉ㄥ叆瀛楀吀鍒癑SON鏁版嵁  鑰楁椂"+(end-start)+"ms");
+        long time2 = System.currentTimeMillis();
+        log.debug("鑾峰彇JSON鏁版嵁 鑰楁椂锛�" + (time2 - time1) + "ms");
+        long start = System.currentTimeMillis();
+        result = this.parseDictText(result);
+        long end = System.currentTimeMillis();
+        log.debug("娉ㄥ叆瀛楀吀鍒癑SON鏁版嵁  鑰楁椂" + (end - start) + "ms");
         return result;
     }
 
@@ -75,20 +75,21 @@
      * 绀轰緥涓篠ysUser   瀛楁涓簊ex 娣诲姞浜嗘敞瑙Dict(dicCode = "sex") 浼氬湪瀛楀吀鏈嶅姟绔嬮┈鏌ュ嚭鏉ュ搴旂殑text 鐒跺悗鍦ㄨ姹俵ist鐨勬椂鍊欏皢杩欎釜瀛楀吀text锛屽凡瀛楁鍚嶇О鍔燺dictText褰㈠紡杩斿洖鍒板墠绔�
      * 渚嬭緭鍏ュ綋鍓嶈繑鍥炲�肩殑灏变細澶氬嚭涓�涓猻ex_dictText瀛楁
      * {
-     *      sex:1,
-     *      sex_dictText:"鐢�"
+     * sex:1,
+     * sex_dictText:"鐢�"
      * }
      * 鍓嶇鐩存帴鍙栧�約ext_dictText鍦╰able閲岄潰鏃犻渶鍐嶈繘琛屽墠绔殑瀛楀吀杞崲浜�
-     *  customRender:function (text) {
-     *               if(text==1){
-     *                 return "鐢�";
-     *               }else if(text==2){
-     *                 return "濂�";
-     *               }else{
-     *                 return text;
-     *               }
-     *             }
-     *             鐩墠vue鏄繖涔堣繘琛屽瓧鍏告覆鏌撳埌table涓婄殑澶氫簡灏卞緢楹荤儲浜� 杩欎釜鐩存帴鍦ㄦ湇鍔$娓叉煋瀹屾垚鍓嶇鍙互鐩存帴鐢�
+     * customRender:function (text) {
+     * if(text==1){
+     * return "鐢�";
+     * }else if(text==2){
+     * return "濂�";
+     * }else{
+     * return text;
+     * }
+     * }
+     * 鐩墠vue鏄繖涔堣繘琛屽瓧鍏告覆鏌撳埌table涓婄殑澶氫簡灏卞緢楹荤儲浜� 杩欎釜鐩存帴鍦ㄦ湇鍔$娓叉煋瀹屾垚鍓嶇鍙互鐩存帴鐢�
+     *
      * @param result
      */
     private Object parseDictText(Object result) {
@@ -101,101 +102,101 @@
                 // 瀛楀吀鏁版嵁鍒楄〃锛� key = 瀛楀吀code锛寁alue=鏁版嵁鍒楄〃
                 Map<String, List<String>> dataListMap = new HashMap<>(5);
                 //鍙栧嚭缁撴灉闆�
-                List<Object> records=((IPage) ((Result) result).getResult()).getRecords();
+                List<Object> records = ((IPage) ((Result) result).getResult()).getRecords();
                 //update-begin--Author:zyf -- Date:20220606 ----for锛氥�怴UEN-1230銆� 鍒ゆ柇鏄惁鍚湁瀛楀吀娉ㄨВ,娌℃湁娉ㄨВ杩斿洖-----
-                Boolean hasDict= checkHasDict(records);
-                if(!hasDict){
+                Boolean hasDict = checkHasDict(records);
+                if (!hasDict) {
                     return result;
                 }
 
-        log.debug(" __ 杩涘叆瀛楀吀缈昏瘧鍒囬潰 DictAspect 鈥斺�� " );
-        //update-end--Author:zyf -- Date:20220606 ----for锛氥�怴UEN-1230銆� 鍒ゆ柇鏄惁鍚湁瀛楀吀娉ㄨВ,娌℃湁娉ㄨВ杩斿洖-----
-        for (Object record : records) {
-            String json="{}";
-            try {
-                //update-begin--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
-                //瑙e喅@JsonFormat娉ㄨВ瑙f瀽涓嶄簡鐨勯棶棰樿瑙丼ysAnnouncement绫荤殑@JsonFormat
-                json = objectMapper.writeValueAsString(record);
-                //update-end--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
-            } catch (JsonProcessingException e) {
-                log.error("json瑙f瀽澶辫触"+e.getMessage(),e);
-            }
-            //update-begin--Author:scott -- Date:20211223 ----for锛氥�恑ssues/3303銆憆estcontroller杩斿洖json鏁版嵁鍚巏ey椤哄簭閿欎贡 -----
-            JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
-            //update-end--Author:scott -- Date:20211223 ----for锛氥�恑ssues/3303銆憆estcontroller杩斿洖json鏁版嵁鍚巏ey椤哄簭閿欎贡 -----
-
-            //update-begin--Author:scott -- Date:20190603 ----for锛氳В鍐崇户鎵垮疄浣撳瓧娈垫棤娉曠炕璇戦棶棰�------
-            //for (Field field : record.getClass().getDeclaredFields()) {
-            // 閬嶅巻鎵�鏈夊瓧娈碉紝鎶婂瓧鍏窩ode鍙栧嚭鏉ワ紝鏀惧埌 map 閲�
-            for (Field field : oConvertUtils.getAllFields(record)) {
-                String value = item.getString(field.getName());
-                if (oConvertUtils.isEmpty(value)) {
-                    continue;
-                }
-                //update-end--Author:scott  -- Date:20190603 ----for锛氳В鍐崇户鎵垮疄浣撳瓧娈垫棤娉曠炕璇戦棶棰�------
-                if (field.getAnnotation(Dict.class) != null) {
-                    if (!dictFieldList.contains(field)) {
-                        dictFieldList.add(field);
+                log.debug(" __ 杩涘叆瀛楀吀缈昏瘧鍒囬潰 DictAspect 鈥斺�� ");
+                //update-end--Author:zyf -- Date:20220606 ----for锛氥�怴UEN-1230銆� 鍒ゆ柇鏄惁鍚湁瀛楀吀娉ㄨВ,娌℃湁娉ㄨВ杩斿洖-----
+                for (Object record : records) {
+                    String json = "{}";
+                    try {
+                        //update-begin--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
+                        //瑙e喅@JsonFormat娉ㄨВ瑙f瀽涓嶄簡鐨勯棶棰樿瑙丼ysAnnouncement绫荤殑@JsonFormat
+                        json = objectMapper.writeValueAsString(record);
+                        //update-end--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
+                    } catch (JsonProcessingException e) {
+                        log.error("json瑙f瀽澶辫触" + e.getMessage(), e);
                     }
-                    String code = field.getAnnotation(Dict.class).dicCode();
-                    String text = field.getAnnotation(Dict.class).dicText();
-                    String table = field.getAnnotation(Dict.class).dictTable();
+                    //update-begin--Author:scott -- Date:20211223 ----for锛氥�恑ssues/3303銆憆estcontroller杩斿洖json鏁版嵁鍚巏ey椤哄簭閿欎贡 -----
+                    JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
+                    //update-end--Author:scott -- Date:20211223 ----for锛氥�恑ssues/3303銆憆estcontroller杩斿洖json鏁版嵁鍚巏ey椤哄簭閿欎贡 -----
 
-                    List<String> dataList;
-                    String dictCode = code;
-                    if (!StringUtils.isEmpty(table)) {
-                        dictCode = String.format("%s,%s,%s", table, text, code);
+                    //update-begin--Author:scott -- Date:20190603 ----for锛氳В鍐崇户鎵垮疄浣撳瓧娈垫棤娉曠炕璇戦棶棰�------
+                    //for (Field field : record.getClass().getDeclaredFields()) {
+                    // 閬嶅巻鎵�鏈夊瓧娈碉紝鎶婂瓧鍏窩ode鍙栧嚭鏉ワ紝鏀惧埌 map 閲�
+                    for (Field field : oConvertUtils.getAllFields(record)) {
+                        String value = item.getString(field.getName());
+                        if (oConvertUtils.isEmpty(value)) {
+                            continue;
+                        }
+                        //update-end--Author:scott  -- Date:20190603 ----for锛氳В鍐崇户鎵垮疄浣撳瓧娈垫棤娉曠炕璇戦棶棰�------
+                        if (field.getAnnotation(Dict.class) != null) {
+                            if (!dictFieldList.contains(field)) {
+                                dictFieldList.add(field);
+                            }
+                            String code = field.getAnnotation(Dict.class).dicCode();
+                            String text = field.getAnnotation(Dict.class).dicText();
+                            String table = field.getAnnotation(Dict.class).dictTable();
+
+                            List<String> dataList;
+                            String dictCode = code;
+                            if (!StringUtils.isEmpty(table)) {
+                                dictCode = String.format("%s,%s,%s", table, text, code);
+                            }
+                            dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());
+                            this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));
+                        }
+                        //date绫诲瀷榛樿杞崲string鏍煎紡鍖栨棩鏈�
+                        //update-begin--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
+                        //if (JAVA_UTIL_DATE.equals(field.getType().getName())&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
+                        //SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                        // item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
+                        //}
+                        //update-end--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
                     }
-                    dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());
-                    this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));
-                }
-                //date绫诲瀷榛樿杞崲string鏍煎紡鍖栨棩鏈�
-                //update-begin--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
-                //if (JAVA_UTIL_DATE.equals(field.getType().getName())&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
-                //SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                // item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
-                //}
-                //update-end--Author:zyf -- Date:20220531 ----for锛氥�恑ssues/#3629銆� DictAspect Jackson搴忓垪鍖栨姤閿�-----
-            }
-            items.add(item);
-        }
-
-        //step.2 璋冪敤缈昏瘧鏂规硶锛屼竴娆℃�х炕璇�
-        Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
-
-        //step.3 灏嗙炕璇戠粨鏋滃~鍏呭埌杩斿洖缁撴灉閲�
-        for (JSONObject record : items) {
-            for (Field field : dictFieldList) {
-                String code = field.getAnnotation(Dict.class).dicCode();
-                String text = field.getAnnotation(Dict.class).dicText();
-                String table = field.getAnnotation(Dict.class).dictTable();
-
-                String fieldDictCode = code;
-                if (!StringUtils.isEmpty(table)) {
-                    fieldDictCode = String.format("%s,%s,%s", table, text, code);
+                    items.add(item);
                 }
 
-                String value = record.getString(field.getName());
-                if (oConvertUtils.isNotEmpty(value)) {
-                    List<DictModel> dictModels = translText.get(fieldDictCode);
-                    if(dictModels==null || dictModels.size()==0){
-                        continue;
+                //step.2 璋冪敤缈昏瘧鏂规硶锛屼竴娆℃�х炕璇�
+                Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
+
+                //step.3 灏嗙炕璇戠粨鏋滃~鍏呭埌杩斿洖缁撴灉閲�
+                for (JSONObject record : items) {
+                    for (Field field : dictFieldList) {
+                        String code = field.getAnnotation(Dict.class).dicCode();
+                        String text = field.getAnnotation(Dict.class).dicText();
+                        String table = field.getAnnotation(Dict.class).dictTable();
+
+                        String fieldDictCode = code;
+                        if (!StringUtils.isEmpty(table)) {
+                            fieldDictCode = String.format("%s,%s,%s", table, text, code);
+                        }
+
+                        String value = record.getString(field.getName());
+                        if (oConvertUtils.isNotEmpty(value)) {
+                            List<DictModel> dictModels = translText.get(fieldDictCode);
+                            if (dictModels == null || dictModels.size() == 0) {
+                                continue;
+                            }
+
+                            String textValue = this.translDictText(dictModels, value);
+                            log.debug(" 瀛楀吀Val : " + textValue);
+                            log.debug(" __缈昏瘧瀛楀吀瀛楁__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + "锛� " + textValue);
+
+                            // TODO-sun 娴嬭瘯杈撳嚭锛屽緟鍒�
+                            log.debug(" ---- dictCode: " + fieldDictCode);
+                            log.debug(" ---- value: " + value);
+                            log.debug(" ----- text: " + textValue);
+                            log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
+
+                            record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
+                        }
                     }
-
-                    String textValue = this.translDictText(dictModels, value);
-                    log.debug(" 瀛楀吀Val : " + textValue);
-                    log.debug(" __缈昏瘧瀛楀吀瀛楁__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + "锛� " + textValue);
-
-                    // TODO-sun 娴嬭瘯杈撳嚭锛屽緟鍒�
-                    log.debug(" ---- dictCode: " + fieldDictCode);
-                    log.debug(" ---- value: " + value);
-                    log.debug(" ----- text: " + textValue);
-                    log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
-
-                    record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
                 }
-            }
-        }
 
                 ((IPage) ((Result) result).getResult()).setRecords(items);
             }
@@ -217,6 +218,7 @@
      * 涓�娆℃�ф妸鎵�鏈夌殑瀛楀吀閮界炕璇戜簡
      * 1.  鎵�鏈夌殑鏅�氭暟鎹瓧鍏哥殑鎵�鏈夋暟鎹彧鎵ц涓�娆QL
      * 2.  琛ㄥ瓧鍏哥浉鍚岀殑鎵�鏈夋暟鎹彧鎵ц涓�娆QL
+     *
      * @param dataListMap
      * @return
      */
@@ -352,7 +354,8 @@
     }
 
     /**
-     *  缈昏瘧瀛楀吀鏂囨湰
+     * 缈昏瘧瀛楀吀鏂囨湰
+     *
      * @param code
      * @param text
      * @param table
@@ -361,39 +364,39 @@
      */
     @Deprecated
     private String translateDictValue(String code, String text, String table, String key) {
-    	if(oConvertUtils.isEmpty(key)) {
-    		return null;
-    	}
-        StringBuffer textValue=new StringBuffer();
+        if (oConvertUtils.isEmpty(key)) {
+            return null;
+        }
+        StringBuffer textValue = new StringBuffer();
         String[] keys = key.split(",");
         for (String k : keys) {
             String tmpValue = null;
-            log.debug(" 瀛楀吀 key : "+ k);
+            log.debug(" 瀛楀吀 key : " + k);
             if (k.trim().length() == 0) {
                 continue; //璺宠繃寰幆
             }
             //update-begin--Author:scott -- Date:20210531 ----for锛� !56 浼樺寲寰湇鍔″簲鐢ㄤ笅瀛樺湪琛ㄥ瓧娈甸渶瑕佸瓧鍏哥炕璇戞椂鍔犺浇缂撴參闂-----
-            if (!StringUtils.isEmpty(table)){
-                log.debug("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code);
-                String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s,%s,%s]",table,text,code,k.trim());
-                    if (redisTemplate.hasKey(keyString)){
+            if (!StringUtils.isEmpty(table)) {
+                log.debug("--DictAspect------dicTable=" + table + " ,dicText= " + text + " ,dicCode=" + code);
+                String keyString = String.format("sys:cache:dictTable::SimpleKey [%s,%s,%s,%s]", table, text, code, k.trim());
+                if (redisTemplate.hasKey(keyString)) {
                     try {
                         tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
                     } catch (Exception e) {
                         log.warn(e.getMessage());
                     }
-                }else {
-                    tmpValue= commonApi.translateDictFromTable(table,text,code,k.trim());
+                } else {
+                    tmpValue = commonApi.translateDictFromTable(table, text, code, k.trim());
                 }
-            }else {
-                String keyString = String.format("sys:cache:dict::%s:%s",code,k.trim());
-                if (redisTemplate.hasKey(keyString)){
+            } else {
+                String keyString = String.format("sys:cache:dict::%s:%s", code, k.trim());
+                if (redisTemplate.hasKey(keyString)) {
                     try {
                         tmpValue = oConvertUtils.getString(redisTemplate.opsForValue().get(keyString));
                     } catch (Exception e) {
-                       log.warn(e.getMessage());
+                        log.warn(e.getMessage());
                     }
-                }else {
+                } else {
                     tmpValue = commonApi.translateDict(code, k.trim());
                 }
             }
@@ -412,11 +415,12 @@
 
     /**
      * 妫�娴嬭繑鍥炵粨鏋滈泦涓槸鍚﹀寘鍚獶ict娉ㄨВ
+     *
      * @param records
      * @return
      */
-    private Boolean checkHasDict(List<Object> records){
-        if(oConvertUtils.isNotEmpty(records) && records.size()>0){
+    private Boolean checkHasDict(List<Object> records) {
+        if (oConvertUtils.isNotEmpty(records) && records.size() > 0) {
             for (Field field : oConvertUtils.getAllFields(records.get(0))) {
                 if (oConvertUtils.isNotEmpty(field.getAnnotation(Dict.class))) {
                     return true;

--
Gitblit v1.9.3