ソースを参照

fix:动态数据回显、驼峰之间的转换、公共实体等bug修复

韩帛霖 1 年間 前
コミット
270322cad0

+ 0 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java

@@ -90,12 +90,6 @@ public class CommonController extends BaseController {
      */
     @PostMapping("/export")
     public void export(HttpServletResponse response, CommonEntity commonEntity) throws Exception {
-
-//        CommonEntity commonEntity1 =commonEntity;
-//        CommonEntity commonEntity = new CommonEntity();
-//        Map<String, Object> map = new HashMap<>();
-//        map.put("sqlKey", sqlkey);
-//        commonEntity.setQueryMap(map);
         commonService.export(response, commonEntity);
     }
 

+ 14 - 13
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -54,7 +54,7 @@ public class CommonEntity extends BaseEntity {
     /**
      * excelMap
      */
-    private List<Map<String, Object>> execlMap;
+    private String execlMap;
 
     public List<Map<String, String>> getAddListMap() {
         return addListMap;
@@ -77,7 +77,7 @@ public class CommonEntity extends BaseEntity {
                 '}';
     }
 
-    public CommonEntity(Map<String, Object> basicMap, Map<String, Object> queryMap, Map<String, Object> conditionMap, Map<String, Object> resultMap, Map<String, Object> commMap, List<Map<String, String>> addListMap, List<Map<String, Object>> execlMap) {
+    public CommonEntity(Map<String, Object> basicMap, Map<String, Object> queryMap, Map<String, Object> conditionMap, Map<String, Object> resultMap, Map<String, Object> commMap, List<Map<String, String>> addListMap, String execlMap) {
         this.basicMap = basicMap;
         this.queryMap = queryMap;
         this.conditionMap = conditionMap;
@@ -131,21 +131,22 @@ public class CommonEntity extends BaseEntity {
         this.commMap = commMap;
     }
 
-    public List<Map<String, Object>> getExeclMap() {
+    public String getExeclMap() {
         return execlMap;
     }
 
     public void setExeclMap(String execlMap) {
-        ObjectMapper mapper = new ObjectMapper();
-        try {
-            this.execlMap = mapper.readValue(execlMap, new TypeReference<List<Map<String, Object>>>() {
-            });
-        } catch (JsonProcessingException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    public void setExeclMap(List<Map<String, Object>> execlMap) {
         this.execlMap = execlMap;
     }
+
+
+    /**
+     * org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
+     * Field error in object 'commonEntity' on field 'execlMap': rejected value
+     * [[{"address":"主1","name":"主1","id":1},{"address":"主2","name":"主2","id":2}]];
+     * codes [typeMismatch.commonEntity.execlMap,typeMismatch.execlMap,typeMismatch.java.util.List,typeMismatch];
+     * arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [commonEntity.execlMap,execlMap];
+     * arguments []; default message [execlMap]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'execlMap';
+     * nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map' for property 'execlMap[0]': no matching editors or conversion strategy found]
+     */
 }

+ 30 - 2
ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableVo.java

@@ -50,6 +50,11 @@ public class DragTableVo {
      */
     private Object dtColumnName;
 
+    /**
+     * 列字段标题名称(存储显示字段信息JSON)
+     */
+    private String dtColumnNameEcho;
+
     /**
      * 时间格式
      */
@@ -74,6 +79,10 @@ public class DragTableVo {
      * 导出字段名以及列名JSON
      */
     private Object tableExportField;
+    /**
+     * 导出字段名以及列名JSON
+     */
+    private String tableExportFieldEcho;
 
     /**
      * 回显数据(前端修改回显数据使用)
@@ -110,11 +119,13 @@ public class DragTableVo {
                 ", sqlKey='" + sqlKey + '\'' +
                 ", dtTableName='" + dtTableName + '\'' +
                 ", dtColumnName=" + dtColumnName +
+                ", dtColumnNameEcho='" + dtColumnNameEcho + '\'' +
                 ", timeFormat='" + timeFormat + '\'' +
                 ", isSelection='" + isSelection + '\'' +
                 ", searchFieldList=" + searchFieldList +
                 ", tableSql='" + tableSql + '\'' +
                 ", tableExportField=" + tableExportField +
+                ", tableExportFieldEcho=" + tableExportFieldEcho +
                 ", echoData='" + echoData + '\'' +
                 ", menuId=" + menuId +
                 ", primaryKey='" + primaryKey + '\'' +
@@ -179,6 +190,14 @@ public class DragTableVo {
         this.dtColumnName = dtColumnName;
     }
 
+    public String getDtColumnNameEcho() {
+        return dtColumnNameEcho;
+    }
+
+    public void setDtColumnNameEcho(String dtColumnNameEcho) {
+        this.dtColumnNameEcho = dtColumnNameEcho;
+    }
+
     public String getTimeFormat() {
         return timeFormat;
     }
@@ -219,6 +238,14 @@ public class DragTableVo {
         this.tableExportField = tableExportField;
     }
 
+    public Object getTableExportFieldEcho() {
+        return tableExportFieldEcho;
+    }
+
+    public void setTableExportFieldEcho(String tableExportFieldEcho) {
+        this.tableExportFieldEcho = tableExportFieldEcho;
+    }
+
     public String getEchoData() {
         return echoData;
     }
@@ -260,10 +287,9 @@ public class DragTableVo {
     }
 
     public DragTableVo() {
-
     }
 
-    public DragTableVo(Long tId, String dtName, String dtNickname, String tableKey, String sqlKey, String dtTableName, Object dtColumnName, String timeFormat, String isSelection, List<String> searchFieldList, String tableSql, Object tableExportField, String echoData, Long menuId, String primaryKey, String orderByColumn, String sortOrder) {
+    public DragTableVo(Long tId, String dtName, String dtNickname, String tableKey, String sqlKey, String dtTableName, Object dtColumnName, String dtColumnNameEcho, String timeFormat, String isSelection, List<String> searchFieldList, String tableSql, Object tableExportField, String tableExportFieldEcho, String echoData, Long menuId, String primaryKey, String orderByColumn, String sortOrder) {
         this.tId = tId;
         this.dtName = dtName;
         this.dtNickname = dtNickname;
@@ -271,11 +297,13 @@ public class DragTableVo {
         this.sqlKey = sqlKey;
         this.dtTableName = dtTableName;
         this.dtColumnName = dtColumnName;
+        this.dtColumnNameEcho = dtColumnNameEcho;
         this.timeFormat = timeFormat;
         this.isSelection = isSelection;
         this.searchFieldList = searchFieldList;
         this.tableSql = tableSql;
         this.tableExportField = tableExportField;
+        this.tableExportFieldEcho = tableExportFieldEcho;
         this.echoData = echoData;
         this.menuId = menuId;
         this.primaryKey = primaryKey;

+ 37 - 9
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -2,7 +2,9 @@ package com.ruoyi.system.service.impl;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
-import com.alibaba.fastjson2.TypeReference;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.TableSql;
@@ -41,22 +43,41 @@ public class CommonServiceImpl implements ICommonService {
 
     @Override
     public int batchInsert(CommonEntity commonEntity) {
+
+
         String tableName = (String) commonEntity.getBasicMap().get("tableName");
         List<Map<String, String>> list = commonEntity.getAddListMap();
         List<Map<String, Object>> mapList = new ArrayList<>();
         for (Object obj : list) {
+            System.out.println(obj);
             Map<String, Object> map1 = (Map<String, Object>) obj;
-            map1.keySet().forEach(item -> {
-                mapList.add((Map<String, Object>) JSON.parse(toUnderScoreCase(item) + map1.get(item)));
-            });
+            mapList.add(map1);
         }
         Set<String> fieldNames = new LinkedHashSet<>();
         mapList.stream().forEach(map1 -> {
             map1.forEach((key, value) -> {
-                fieldNames.add(key);
+                fieldNames.add(toUnderScoreCase(key));
             });
         });
         return commonMapper.batchInsert(fieldNames, tableName, mapList);
+
+
+//        String tableName = (String) commonEntity.getBasicMap().get("tableName");
+//        List<Map<String, String>> list = commonEntity.getAddListMap();
+//        List<Map<String, Object>> mapList = new ArrayList<>();
+//        for (Object obj : list) {
+//            Map<String, Object> map1 = (Map<String, Object>) obj;
+//            map1.keySet().forEach(item -> {
+//                mapList.add((Map<String, Object>) JSON.parse(toUnderScoreCase(item) + map1.get(item)));
+//            });
+//        }
+//        Set<String> fieldNames = new LinkedHashSet<>();
+//        mapList.stream().forEach(map1 -> {
+//            map1.forEach((key, value) -> {
+//                fieldNames.add(key);
+//            });
+//        });
+//        return commonMapper.batchInsert(fieldNames, tableName, mapList);
     }
 
     @Override
@@ -64,13 +85,13 @@ public class CommonServiceImpl implements ICommonService {
         String tableName = (String) commonEntity.getBasicMap().get("tableName");
         Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
         Map<String, Object> fields = JSONObject.parseObject(JSON.toJSONString(commonEntity.getCommMap()));
-        Map<String, Object> endfields = null;
+        Map<String, Object> endfields = new HashMap<>();
         fields.keySet().forEach(item -> {
 //            Map<String, Object> asd = JSONObject.parseObject("{ \"" + toUnderScoreCase(item) + "\":\"" + fields.get(item) + "\"}", new TypeReference<Map<String, Object>>() {
 //            });
             endfields.put(toUnderScoreCase(item), fields.get(item));
         });
-        return commonMapper.edit(fields, tableName, conditions);
+        return commonMapper.edit(endfields, tableName, conditions);
     }
 
     @Override
@@ -128,8 +149,15 @@ public class CommonServiceImpl implements ICommonService {
         //查询列表信息
         List<Map<String, Object>> mapList = null;
         //根据条件获取列表信息
-        if (commonEntity.getExeclMap() != null && commonEntity.getExeclMap().size() > 0) {
-            mapList = commonEntity.getExeclMap();
+        if (commonEntity.getExeclMap() != null && !commonEntity.getExeclMap().equals("")) {
+            ObjectMapper mapper = new ObjectMapper();
+            try {
+                mapList = mapper.readValue(commonEntity.getExeclMap(), new TypeReference<List<Map<String, Object>>>() {
+                });
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+//            mapList = commonEntity.getExeclMap();
         } else {
             List<Map<String, Object>> maps = new ArrayList<>();
             List<CommonEntity> commonEntities = queryTableList(commonEntity, tableSql);

+ 7 - 4
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DataSourceServiceImpl.java

@@ -121,10 +121,13 @@ public class DataSourceServiceImpl implements IDataSourceService {
         } else if (dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())) {
             tableInfoList = tableInfoMapper.dmTableFieldInfo(dataSource.getDatabaseName(), map.get("tableName").toString());
         }
-        // 将列中的字段属性驼峰转换
-        tableInfoList.forEach(item -> {
-            item.setFieldName(StringUtils.toCamelCase(item.getFieldName()));
-        });
+        // 校验是否驼峰
+        if (map.get("isHump") != null && (boolean) map.get("isHump")) {
+            // 将列中的字段属性驼峰转换
+            tableInfoList.forEach(item -> {
+                item.setFieldName(StringUtils.toCamelCase(item.getFieldName()));
+            });
+        }
         return tableInfoList;
     }
 

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragFormServiceImpl.java

@@ -86,7 +86,7 @@ public class DragFormServiceImpl implements IDragFormService {
 
         //新增关联表
         DragTableForm dragTableForm = new DragTableForm();
-        dragTableForm.setDfId(Long.valueOf(dragFormMapper.selectDragFormFId()));
+        dragTableForm.setDfId(dragForm.getfId());
         dragTableForm.setDtId(dragForm.getDtId());
         dragTableFormMapper.insertDragTableForm(dragTableForm);
         return AjaxResult.success();

+ 9 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -1,6 +1,9 @@
 package com.ruoyi.system.service.impl;
 
 import java.sql.SQLSyntaxErrorException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -16,6 +19,7 @@ import com.ruoyi.system.entity.vo.DragTableVo;
 import com.ruoyi.system.mapper.CommonMapper;
 import com.ruoyi.system.mapper.DragTableConditionMapper;
 import com.ruoyi.system.mapper.TableSqlMapper;
+import org.apache.ibatis.jdbc.SQL;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -126,7 +130,6 @@ public class DragTableServiceImpl implements IDragTableService {
         Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("template", dragTable);
 //        resultMap.put("where",dragTableConditionMapper.selectDragTableConditionByTid(dragTable.gettId()));
-
         List<DragTableCondition> dragTableConditions = dragTableConditionMapper.selectDragTableConditionByTid(dragTable.gettId());
         dragTableConditions.forEach(d -> {
             // 0 查询字典 1 查询表数据
@@ -172,6 +175,7 @@ public class DragTableServiceImpl implements IDragTableService {
         //add table_sql
         TableSql tableSql = new TableSql();
         tableSql.setTableSql(dragTableVo.getTableSql());
+        tableSql.setCreateTime(DateUtils.getNowDate());
         dragTableMapper.insertDragTable(dragTable);
         // 拼接sql查询条件
         switch (SecurityUtils.getDatabaseType().toUpperCase()) {
@@ -239,15 +243,17 @@ public class DragTableServiceImpl implements IDragTableService {
         // 拼接sql查询条件
         switch (SecurityUtils.getDatabaseType().toUpperCase()) {
             case "MYSQL":
+                SQL += SQL_START;
                 for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
-                    SQL += SQL_START + SQL_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
+                    SQL += SQL_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
                     SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
                 }
                 break;
             case "DM":
             case "SQLSERVER":
+                SQL += SQL_START;
                 for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
-                    SQL += SQL_START + SQL_DM_SERVER_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
+                    SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
                     SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
                 }
                 break;

+ 7 - 4
ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java

@@ -114,9 +114,12 @@ public class ljj {
                 System.out.println("xczxcz");
                 break;
         }
-
-
     }
-
-
 }
+
+/**
+ * Type definition error:
+ * [simple type, class dm.jdbc.c.a.a];
+ * nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
+ * No serializer found for class dm.jdbc.c.a.a and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.ruoyi.common.core.domain.AjaxResult["data"]->com.ruoyi.system.entity.vo.DragTableVo["dtColumnName"]->dm.jdbc.driver.DmdbNClob["connection"]->dm.jdbc.driver.DmdbConnection["hd"]->dm.jdbc.c.a["kQ"])
+ */

+ 4 - 4
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

@@ -34,11 +34,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="tableKey"    column="table_key"    />
         <result property="sqlKey"    column="sql_key"    />
         <result property="dtTableName"    column="dt_table_name"    />
-        <result property="dtColumnName"    column="dt_column_name"    />
+        <result property="dtColumnNameEcho"    column="dt_column_name"    />
         <result property="timeFormat" column="time_format"/>
         <result property="isSelection"   column="is_selection"/>
         <result property="tableSql" column="table_sql"/>
-        <result property="tableExportField" column="table_export_field"/>
+        <result property="tableExportFieldEcho" column="table_export_field"/>
         <result property="echoData"      column="echo_data"/>
         <result property="menuId" column="menu_id"/>
         <result property="primaryKey" column="primary_key"/>
@@ -87,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="echoData != null">echo_data,</if>
             <if test="menuId != null">menu_id,</if>
             <if test="primaryKey != null">primary_key,</if>
-            create_time
+            <if test="createTime != null">create_time,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="dtName != null">#{dtName},</if>
@@ -106,7 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="echoData != null">#{echoData},</if>
             <if test="menuId != null">#{menuId},</if>
             <if test="primaryKey != null">#{primaryKey},</if>
-            now()
+            <if test="createTime != null">#{createTime},</if>
          </trim>
     </insert>