Browse Source

queryList中返回值中处理日期和字典值

shiqian 4 years ago
parent
commit
52b70e67e1

+ 10 - 0
boman-api/boman-api-system/src/main/java/com/boman/system/api/RemoteDictDataService.java

@@ -23,5 +23,15 @@ public interface RemoteDictDataService {
      */
     @GetMapping(value = "/dict/data/type/data/{dictType}")
     List<SysDictData> listByType(@PathVariable(value = "dictType") String dictType);
+
+    /**
+     * 功能描述: 根据type和value查字典值
+     *
+     * @param dictType  dictType
+     * @param dictValue dictValue
+     * @return java.lang.String
+     */
+    @GetMapping(value = "/dict/data/type/data/{dictType}/{dictValue}")
+    String selectDictLabel(@PathVariable("dictType") String dictType, @PathVariable("dictValue") String dictValue);
 }
 

+ 8 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysDictDataController.java

@@ -93,6 +93,14 @@ public class SysDictDataController extends BaseController
         return dictTypeService.selectDictDataByType(dictType);
     }
 
+    /**
+     * 根据字典类型查询字典数据信息
+     */
+    @GetMapping(value = "/type/data/{dictType}/{dictValue}")
+    public String selectDictLabel(@PathVariable("dictType") String dictType, @PathVariable("dictValue") String dictValue) {
+        return dictDataService.selectDictLabel(dictType, dictValue);
+    }
+
     /**
      * 新增字典类型
      */

+ 1 - 1
boman-modules/boman-system/src/main/resources/mapper/system/SysDictDataMapper.xml

@@ -48,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="selectDictLabel" resultType="java.lang.String">
 		select dict_label from sys_dict_data
-		where dict_type = #{dictType} and dict_value = #{dictValue}
+		where dict_type = #{dictType} and dict_value = #{dictValue} limit 1;
 	</select>
 	
 	<select id="selectDictDataById" parameterType="Long" resultMap="SysDictDataResult">

+ 30 - 5
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -203,7 +203,8 @@ public class TableServiceCmdService {
 
         List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
                 , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
-        handlerDate(result);
+        handlerDate(result, columns);
+        handlerSysDictData(result, columns);
         result = isCustomized(dto.getTable(),result,"trigger_retrieve");
         rows.put(FormDataConstant.PAGE_ROWS, result);
         return AjaxResult.success(rows);
@@ -214,13 +215,38 @@ public class TableServiceCmdService {
      *
      * @param result 被转的数据
      */
-    private void handlerDate(List<JSONObject> result) {
+    private void handlerDate(List<JSONObject> result, List<GenTableColumn> columns) {
         if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
             return;
         }
+
         for (JSONObject jsonObject : result) {
-            getStrByTimeStamp(jsonObject, FormDataConstant.CREATE_TIME);
-            getStrByTimeStamp(jsonObject, FormDataConstant.UPDATE_TIME.toLowerCase());
+            for (GenTableColumn column : columns) {
+                if (jsonObject.containsKey(column.getColumnName()) && DATETIME.equalsIgnoreCase(column.getColumnType())) {
+                    getStrByTimeStamp(jsonObject, column.getColumnName());
+                }
+            }
+        }
+    }
+
+    /**
+     * 功能描述: 把返回值中含有字典值的转为可视化的心事
+     *
+     * @param result 被转的数据
+     */
+    private void handlerSysDictData(List<JSONObject> result, List<GenTableColumn> columns) {
+        if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
+            return;
+        }
+
+        for (JSONObject jsonObject : result) {
+            for (GenTableColumn column : columns) {
+                String dictType = column.getDictType();
+                if (isNotEmpty(dictType) && jsonObject.containsKey(column.getColumnName())) {
+                    String dictLabel = remoteDictDataService.selectDictLabel(dictType, jsonObject.getString(column.getColumnName()));
+                    jsonObject.put(column.getColumnName(), dictLabel);
+                }
+            }
         }
     }
 
@@ -233,7 +259,6 @@ public class TableServiceCmdService {
     private void getStrByTimeStamp(JSONObject jsonObject, String columnType) {
         Date date = jsonObject.getTimestamp(columnType);
         if (null != date) {
-
             jsonObject.put(columnType, DateUtils.dateTime(date));
         }
     }