Przeglądaj źródła

Revert "Revert "完善共通实体接受数据格式,细节优化""

This reverts commit 7d162669a9ac9383730d226557ea24d98054a43f.
韩帛霖 1 rok temu
rodzic
commit
cd4957a9ea

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

@@ -43,7 +43,7 @@ public class CommonController extends BaseController {
      * 共通查询
      */
     @GetMapping("/selectList")
-    public TableDataInfo selectList(CommonEntity commonEntity) {
+    public TableDataInfo selectList(@RequestBody CommonEntity commonEntity) {
         startPage();
         return getDataTable(commonService.selectList(commonEntity));
     }
@@ -80,7 +80,6 @@ public class CommonController extends BaseController {
      */
     @GetMapping("/getTableList")
     public TableDataInfo queryTableList(CommonEntity commonEntity) {
-        System.out.println(commonEntity.getQueryMap());
         TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getQueryMap().get("sqlkey").toString());
         startPage();  // 校验是否sqlserver 否执行 是执行另一种方式的分页
         return getDataTable(commonService.queryTableList(commonEntity, tableSql));
@@ -90,7 +89,13 @@ public class CommonController extends BaseController {
      * 通用导出excel
      */
     @PostMapping("/export")
-    public void export(HttpServletResponse response,@RequestBody CommonEntity commonEntity) throws Exception {
+    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);
     }
 
@@ -102,9 +107,9 @@ public class CommonController extends BaseController {
      * @param sqlKey
      * @throws Exception
      */
-    @GetMapping("/exportTemplate")
-    public void exportTemplate(HttpServletResponse response, @RequestParam("tableName") String tableName, @RequestParam("sqlKey") String sqlKey) throws Exception {
-        commonService.exportTemplate(response, tableName, sqlKey);
+    @PostMapping("/exportTemplate")
+    public void exportTemplate(HttpServletResponse response, String tableName, String sqlkey) throws Exception {
+        commonService.exportTemplate(response, tableName, sqlkey);
     }
 
     /**

+ 5 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonFileController.java

@@ -185,11 +185,11 @@ public class CommonFileController {
     @Anonymous
     @ApiOperation("上传文件")
     @PostMapping(value = "/uploadData", headers = "content-type=multipart/form-data")
-    public AjaxResult uploadDataFile(@RequestPart("file") MultipartFile file) throws Exception {
+    public AjaxResult uploadDataFile(String tableName, @RequestPart("file") MultipartFile file) throws Exception {
         Map<String, Object> map = new HashMap<>();
-        map.put("tableName", file.getOriginalFilename().substring(0, file.getOriginalFilename().indexOf(".")));
-        map.put("databaseType", SecurityUtils.getDatabaseType());
-        map.put("databaseName", SecurityUtils.getDatabaseName());
+        map.put("tableName", "test");
+        map.put("databaseType", "mysql");
+        map.put("databaseName", "zkqy-call");
         try {
             // 创建一个工作簿对象 解析上传的excel表数据
             List<Map<String, String>> listMap = convertList(EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync());
@@ -215,7 +215,7 @@ public class CommonFileController {
             CommonEntity commonEntity = new CommonEntity();
             commonEntity.setBasicMap(JSONObject.parseObject("{ \"tableName\":\"test\"}", new TypeReference<Map<String, Object>>() {
             }));
-            commonEntity.setCommMap((Map<String, Object>) listMap);
+            commonEntity.setAddListMap(listMap);
             return success(commonService.batchInsert(commonEntity));
         } catch (Exception e) {
             return AjaxResult.error(e.getMessage());

+ 18 - 18
ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java

@@ -20,21 +20,26 @@ import java.util.List;
 
 /**
  * Swagger2的接口配置
- * 
+ *
  * @author ruoyi
  */
 @Configuration
-public class SwaggerConfig
-{
-    /** 系统基础配置 */
+public class SwaggerConfig {
+    /**
+     * 系统基础配置
+     */
     @Autowired
     private RuoYiConfig ruoyiConfig;
 
-    /** 是否开启swagger */
+    /**
+     * 是否开启swagger
+     */
     @Value("${swagger.enabled}")
     private boolean enabled;
 
-    /** 设置请求的统一前缀 */
+    /**
+     * 设置请求的统一前缀
+     */
     @Value("")
     private String pathMapping;
 
@@ -42,8 +47,7 @@ public class SwaggerConfig
      * 创建API
      */
     @Bean
-    public Docket createRestApi()
-    {
+    public Docket createRestApi() {
         return new Docket(DocumentationType.OAS_30)
                 // 是否启用Swagger
                 .enable(enabled)
@@ -60,15 +64,14 @@ public class SwaggerConfig
                 .build()
                 /* 设置安全模式,swagger可以设置访问token */
                 .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts())
-                .pathMapping(pathMapping);
+                .securityContexts(securityContexts());
+//                .pathMapping(pathMapping);
     }
 
     /**
      * 安全模式,这里指定token通过Authorization头请求头传递
      */
-    private List<SecurityScheme> securitySchemes()
-    {
+    private List<SecurityScheme> securitySchemes() {
         List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
         apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
         return apiKeyList;
@@ -77,8 +80,7 @@ public class SwaggerConfig
     /**
      * 安全上下文
      */
-    private List<SecurityContext> securityContexts()
-    {
+    private List<SecurityContext> securityContexts() {
         List<SecurityContext> securityContexts = new ArrayList<>();
         securityContexts.add(
                 SecurityContext.builder()
@@ -91,8 +93,7 @@ public class SwaggerConfig
     /**
      * 默认的安全上引用
      */
-    private List<SecurityReference> defaultAuth()
-    {
+    private List<SecurityReference> defaultAuth() {
         AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
         AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
         authorizationScopes[0] = authorizationScope;
@@ -104,8 +105,7 @@ public class SwaggerConfig
     /**
      * 添加摘要信息
      */
-    private ApiInfo apiInfo()
-    {
+    private ApiInfo apiInfo() {
         // 用ApiInfoBuilder进行定制
         return new ApiInfoBuilder()
                 // 设置标题

+ 4 - 1
ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml

@@ -17,7 +17,10 @@ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
         <setting name="mapUnderscoreToCamelCase" value="true"/>
         <!-- value为空时显示key -->
         <setting name="callSettersOnNulls" value="true" />
-	</settings>
+
+        <setting name="mapUnderscoreToCamelCase" value="true"/>
+    </settings>
+    <!--  重写驼峰转换工具类  -->
     <objectWrapperFactory type="com.ruoyi.common.utils.MapWrapperFactory"/>
 
 

+ 41 - 12
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -1,11 +1,16 @@
 package com.ruoyi.system.entity;
 
+import com.alibaba.fastjson2.JSON;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ruoyi.common.core.domain.BaseEntity;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+
 
 /**
  * 通用实体
@@ -41,23 +46,22 @@ public class CommonEntity extends BaseEntity {
      */
     private Map<String, Object> commMap;
 
+    /**
+     * 新增map
+     */
+    private List<Map<String, String>> addListMap;
+
     /**
      * excelMap
      */
     private List<Map<String, Object>> execlMap;
 
-
-
-    public CommonEntity() {
+    public List<Map<String, String>> getAddListMap() {
+        return addListMap;
     }
 
-    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, Object>> execlMap) {
-        this.basicMap = basicMap;
-        this.queryMap = queryMap;
-        this.conditionMap = conditionMap;
-        this.resultMap = resultMap;
-        this.commMap = commMap;
-        this.execlMap = execlMap;
+    public void setAddListMap(List<Map<String, String>> addListMap) {
+        this.addListMap = addListMap;
     }
 
     @Override
@@ -68,10 +72,25 @@ public class CommonEntity extends BaseEntity {
                 ", conditionMap=" + conditionMap +
                 ", resultMap=" + resultMap +
                 ", commMap=" + commMap +
+                ", addListMap=" + addListMap +
                 ", execlMap=" + 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, List<Map<String, Object>> execlMap) {
+        this.basicMap = basicMap;
+        this.queryMap = queryMap;
+        this.conditionMap = conditionMap;
+        this.resultMap = resultMap;
+        this.commMap = commMap;
+        this.addListMap = addListMap;
+        this.execlMap = execlMap;
+    }
+
+    public CommonEntity() {
+    }
+
+
     public Map<String, Object> getBasicMap() {
         return basicMap;
     }
@@ -116,6 +135,16 @@ public class CommonEntity extends BaseEntity {
         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;
     }

+ 5 - 6
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableConditionMapper.java

@@ -10,12 +10,11 @@ import java.util.Set;
 
 /**
  * 动态格条件Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2023-07-31
  */
-public interface DragTableConditionMapper 
-{
+public interface DragTableConditionMapper {
     /**
      * 查询动态格条件列表
      */
@@ -24,7 +23,7 @@ public interface DragTableConditionMapper
     /**
      * 新增动态格条件
      */
-    int insertDragTableCondition(@Param("fieldNames") Set<String> fieldNames,@Param("fieldValues") List<Map<String, Object>> fieldValues);
+    int insertDragTableCondition(@Param("fieldNames") Set<String> fieldNames, @Param("fieldValues") List<Map<String, Object>> fieldValues);
 
     /**
      * 修改动态格条件
@@ -33,7 +32,7 @@ public interface DragTableConditionMapper
 
     /**
      * 批量删除动态格条件
-     * 
+     *
      * @param tcIds 需要删除的数据主键集合
      * @return 结果
      */
@@ -45,5 +44,5 @@ public interface DragTableConditionMapper
      * @param tId 动态格条件主键
      * @return 动态格条件
      */
-    List<DragTableCondition> selectDragTableConditionByTid(Long tId);
+    List<Map<String,Object>> selectDragTableConditionByTid(Long tId);
 }

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

@@ -12,7 +12,6 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.ServletOutputStream;
@@ -42,7 +41,7 @@ public class CommonServiceImpl implements ICommonService {
     @Override
     public int batchInsert(CommonEntity commonEntity) {
         String tableName = (String) commonEntity.getBasicMap().get("tableName");
-        List<Object> list = (List<Object>) commonEntity.getCommMap();
+        List<Map<String, String>> list =  commonEntity.getAddListMap();
         List<Map<String, Object>> mapList = new ArrayList<>();
         for (Object obj : list) {
             System.out.println(obj);
@@ -92,9 +91,9 @@ public class CommonServiceImpl implements ICommonService {
             } catch (NoSuchElementException e) {
                 return;
             }
-            if (sqlWhere.indexOf("#{timeframe}") != -1) {  // 时间范围查询拼接
+            if (sqlWhere.indexOf("#{timeframe}") != -1 && !val.toString().isEmpty()) {  // 时间范围查询拼接
                 endSQL.append(" AND " + sqlWhere.replace("#{timeframe}", "'" + val.toString().split(",")[0] + "'" + " and " + "'" + val.toString().split(",")[1] + "'"));
-            } else if (sqlWhere.indexOf("#{val}") != -1) { // 寻常条件拼接
+            } else if (sqlWhere.indexOf("#{val}") != -1 && !val.toString().isEmpty()) { // 寻常条件拼接
                 endSQL.append(" AND " + sqlWhere.replace("#{val}", val.toString()));
             }
         });
@@ -103,18 +102,18 @@ public class CommonServiceImpl implements ICommonService {
 
     @Override
     public void export(HttpServletResponse response, CommonEntity commonEntity) throws Exception {
-        String sqlKey = commonEntity.getQueryMap().get("sqlKey").toString();
-        String tableName = commonEntity.getQueryMap().get("tableName").toString();
+        String sqlKey = commonEntity.getQueryMap().get("sqlkey").toString();
+//        String tableName = commonEntity.getQueryMap().get("tableName").toString();
         //查询标题信息
         TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(sqlKey);
 
         //查询列表信息
-        List<Map<String,Object>> mapList = null;
+        List<Map<String, Object>> mapList = null;
         //根据条件获取列表信息
-        if (commonEntity.getExeclMap().size()>0) {
+        if (commonEntity.getExeclMap() != null && commonEntity.getExeclMap().size() > 0) {
             mapList = commonEntity.getExeclMap();
         } else {
-            List<Map<String,Object>> maps = new ArrayList<>();
+            List<Map<String, Object>> maps = new ArrayList<>();
             List<CommonEntity> commonEntities = queryTableList(commonEntity, tableSql);
             commonEntities.stream().forEach(c -> maps.add(c.getResultMap()));
             mapList = maps;

+ 20 - 0
ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java

@@ -16,6 +16,7 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.IntStream;
 
 
 import static com.ruoyi.common.utils.StringUtils.convertToCamelCase;
@@ -106,3 +107,22 @@ public class ljj {
     }
 
 }
+
+class PrimeFinder {
+
+    public static void main(String[] args) {
+        IntStream.iterate(1, n -> n + 1)
+                .limit(100)
+                .filter(PrimeTest::isPrime)
+                .filter(value -> value > 50)
+                .forEach(System.out::println);
+    }
+}
+
+class PrimeTest {
+    static boolean isPrime(int candidate) {
+        return candidate == 91 ||
+                IntStream.rangeClosed(2, (int) Math.sqrt(candidate))
+                        .noneMatch(n -> (candidate % n == 0));
+    }
+}

+ 13 - 6
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableConditionMapper.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.DragTableConditionMapper">
-
+    
     <resultMap type="com.ruoyi.system.entity.DragTableCondition" id="DragTableConditionResult">
         <result property="tcId"    column="tc_id"    />
         <result property="tId"    column="t_id"    />
@@ -13,6 +13,13 @@
         <result property="conditionType"    column="condition_type"    />
         <result property="conditionDefaultValue"    column="condition_default_value"    />
         <result property="sort"    column="sort"    />
+        <result property="conditionTableName"    column="condition_table_name"    />
+        <result property="conditionTableFieldName"    column="condition_table_field_name"    />
+        <result property="conditionTableFieldKey" column="condition_table_field_key"/>
+        <result property="conditionDatasource"    column="condition_datasource"    />
+        <result property="componentType"    column="component_type"    />
+        <result property="componentSize"    column="component_size"    />
+        <result property="componentIcon"    column="component_icon"    />
         <result property="isHidden"    column="is_hidden"    />
         <result property="delFlag"    column="del_flag"    />
         <result property="createBy"    column="create_by"    />
@@ -27,7 +34,8 @@
     </resultMap>
 
     <sql id="selectDragTableConditionVo">
-        select tc_id, t_id, condition_name, condition_field, condition_notes, condition_type, condition_default_value, sort, is_hidden, del_flag, create_by, create_time, update_by, update_time from drag_table_condition
+        select tc_id, t_id, condition_name, condition_field, condition_notes, condition_type, condition_default_value, sort, condition_table_name,
+               condition_table_field_name, condition_table_field_key, condition_datasource, component_type, component_size, component_icon, is_hidden, del_flag, create_by, create_time, update_by, update_time from drag_table_condition
     </sql>
 
     <select id="selectDragTableConditionList" resultMap="retMap">
@@ -40,7 +48,7 @@
             </if>
         </where>
     </select>
-
+        
     <insert id="insertDragTableCondition">
         insert into drag_table_condition
         <foreach collection="fieldNames" item="fieldName" open="(" close=")" separator=",">
@@ -86,6 +94,5 @@
     <select id="selectDragTableConditionByTid" resultMap="DragTableConditionResult">
         <include refid="selectDragTableConditionVo"/>
         where t_id = #{tId}
-        ORDER BY sort ASC
     </select>
 </mapper>