Эх сурвалжийг харах

重构共通实体传参返回结构

韩帛霖 1 жил өмнө
parent
commit
532fab6ae7

+ 1 - 1
pom.xml

@@ -5,7 +5,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	
     <groupId>com.ruoyi</groupId>
-    <artifactId>mec_dragForm</artifactId>
+    <artifactId>mec_dragForm_end</artifactId>
     <version>3.8.5</version>
 
     <name>ruoyi</name>

+ 1 - 1
ruoyi-admin/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>mec_dragForm</artifactId>
+        <artifactId>mec_dragForm_end</artifactId>
         <groupId>com.ruoyi</groupId>
         <version>3.8.5</version>
     </parent>

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

@@ -41,31 +41,31 @@ public class CommonController extends BaseController {
     @GetMapping("/selectList")
     public TableDataInfo selectList(CommonEntity commonEntity) {
         startPage();
-        return getDataTable(commonService.selectList(commonEntity.getFormMap()));
+        return getDataTable(commonService.selectList(commonEntity));
     }
 
     /**
      * 共通批量新增
      */
     @PostMapping("/batchInsert")
-    public AjaxResult batchInsert(@RequestBody Map<String, Object> map) {
-        return toAjax(commonService.batchInsert(map));
+    public AjaxResult batchInsert(@RequestBody CommonEntity commonEntity) {
+        return toAjax(commonService.batchInsert(commonEntity));
     }
 
     /**
      * 共通修改sql
      */
     @PutMapping("/edit")
-    public AjaxResult edit(@RequestBody Map<String, Object> map) {
-        return toAjax(commonService.edit(map));
+    public AjaxResult edit(@RequestBody CommonEntity commonEntity) {
+        return toAjax(commonService.edit(commonEntity));
     }
 
     /**
      * 批量删除
      */
     @DeleteMapping("/batchDelete")
-    public AjaxResult batchDelete(@RequestBody Map<String, Object> map) {
-        return toAjax(commonService.batchDelete(map));
+    public AjaxResult batchDelete(@RequestBody CommonEntity commonEntity) {
+        return toAjax(commonService.batchDelete(commonEntity));
     }
 
     /**
@@ -76,7 +76,7 @@ public class CommonController extends BaseController {
      */
     @GetMapping("/getTableList")
     public TableDataInfo queryTableList(CommonEntity commonEntity) {
-        TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getFormMap().get("SQLKEY").toString());
+        TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getQueryMap().get("SQLKEY").toString());
         startPage();  // 校验是否sqlserver 否执行 是执行另一种方式的分页
         return getDataTable(commonService.queryTableList(commonEntity, tableSql));
     }

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

@@ -2,6 +2,8 @@ package com.ruoyi.web.controller.dragForm;
 
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.TypeReference;
 import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.config.RuoYiConfig;
@@ -210,10 +212,11 @@ public class CommonFileController {
                 });
             });
             listMap.remove(0);
-            Map<String, Object> endMap = new HashMap<>();
-            endMap.put("tableName", "test");
-            endMap.put("field", listMap);
-            return success(commonService.batchInsert(endMap));
+            CommonEntity commonEntity = new CommonEntity();
+            commonEntity.setBasicMap(JSONObject.parseObject("{ \"tableName\":\"test\"}", new TypeReference<Map<String, Object>>() {
+            }));
+            commonEntity.setCommMap((Map<String, Object>) listMap);
+            return success(commonService.batchInsert(commonEntity));
         } catch (Exception e) {
             return AjaxResult.error(e.getMessage());
         }

+ 11 - 23
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableController.java

@@ -24,24 +24,22 @@ import com.ruoyi.common.core.page.TableDataInfo;
 
 /**
  * 动态格Controller
- * 
- * @author ruoyi
+ *
+ * @author xzz
  * @date 2023-07-31
  */
+
 @RestController
 @RequestMapping("/system/table")
-public class DragTableController extends BaseController
-{
+public class DragTableController extends BaseController {
     @Autowired
     private IDragTableService dragTableService;
 
     /**
      * 查询动态格列表
      */
-    @PreAuthorize("@ss.hasPermi('system:table:list')")
     @GetMapping("/list")
-    public TableDataInfo list(DragTable dragTable)
-    {
+    public TableDataInfo list(DragTable dragTable) {
         startPage();
         List<DragTable> list = dragTableService.selectDragTableList(dragTable);
         return getDataTable(list);
@@ -50,11 +48,9 @@ public class DragTableController extends BaseController
     /**
      * 导出动态格列表
      */
-    @PreAuthorize("@ss.hasPermi('system:table:export')")
     @Log(title = "动态格", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, DragTable dragTable)
-    {
+    public void export(HttpServletResponse response, DragTable dragTable) {
         List<DragTable> list = dragTableService.selectDragTableList(dragTable);
         ExcelUtil<DragTable> util = new ExcelUtil<DragTable>(DragTable.class);
         util.exportExcel(response, list, "动态格数据");
@@ -63,43 +59,35 @@ public class DragTableController extends BaseController
     /**
      * 获取动态格详细信息
      */
-    @PreAuthorize("@ss.hasPermi('system:table:query')")
     @GetMapping(value = "/{tId}")
-    public AjaxResult getInfo(@PathVariable("tId") Long tId)
-    {
+    public AjaxResult getInfo(@PathVariable("tId") Long tId) {
         return success(dragTableService.selectDragTableByTId(tId));
     }
 
     /**
      * 新增动态格
      */
-    @PreAuthorize("@ss.hasPermi('system:table:add')")
     @Log(title = "动态格", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody DragTable dragTable)
-    {
+    public AjaxResult add(@RequestBody DragTable dragTable) {
         return toAjax(dragTableService.insertDragTable(dragTable));
     }
 
     /**
      * 修改动态格
      */
-    @PreAuthorize("@ss.hasPermi('system:table:edit')")
     @Log(title = "动态格", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody DragTable dragTable)
-    {
+    public AjaxResult edit(@RequestBody DragTable dragTable) {
         return toAjax(dragTableService.updateDragTable(dragTable));
     }
 
     /**
      * 删除动态格
      */
-    @PreAuthorize("@ss.hasPermi('system:table:remove')")
     @Log(title = "动态格", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{tIds}")
-    public AjaxResult remove(@PathVariable Long[] tIds)
-    {
+    @DeleteMapping("/{tIds}")
+    public AjaxResult remove(@PathVariable Long[] tIds) {
         return toAjax(dragTableService.deleteDragTableByTIds(tIds));
     }
 }

+ 1 - 1
ruoyi-common/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>mec_dragForm</artifactId>
+        <artifactId>mec_dragForm_end</artifactId>
         <groupId>com.ruoyi</groupId>
         <version>3.8.5</version>
     </parent>

+ 1 - 1
ruoyi-framework/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>mec_dragForm</artifactId>
+        <artifactId>mec_dragForm_end</artifactId>
         <groupId>com.ruoyi</groupId>
         <version>3.8.5</version>
     </parent>

+ 1 - 1
ruoyi-system/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>mec_dragForm</artifactId>
+        <artifactId>mec_dragForm_end</artifactId>
         <groupId>com.ruoyi</groupId>
         <version>3.8.5</version>
     </parent>

+ 58 - 38
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -7,6 +7,8 @@ import java.util.Map;
 import java.util.TreeMap;
 
 /**
+ * 通用实体
+ *
  * @author hanzihang
  * @date 2023/7/19 4:05 PM
  */
@@ -14,19 +16,29 @@ public class CommonEntity extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
     /**
-     * 基本参数map
+     * 基本参数Map(例如tableName,pagesize。。。)
      */
-    private Map<String, Object> formMap;
+    private Map<String, Object> basicMap;
 
     /**
-     * 主表参数map
+     * 查询条件Map (查询当前表的条件字段k/v)
      */
-    private Map<String, Object> condition;
+    private Map<String, Object> queryMap;
 
     /**
-     * 返回前端map
+     * 条件Map(例如修改时前端回传的唯一id标识,删除同理)
      */
-    private Map<String, Object> retMap;
+    private Map<String, Object> conditionMap;
+
+    /**
+     * 回传Map(得到结果返回前端)
+     */
+    private Map<String, Object> resultMap;
+
+    /**
+     * 通用Map(新增时,修改时存放字段k/v)
+     */
+    private Map<String, Object> commMap;
 
     /**
      * 导入数据Map
@@ -34,67 +46,75 @@ public class CommonEntity extends BaseEntity {
     private Map<String, Object> execlMap;
 
 
-    private MultipartFile file;
-
     public CommonEntity() {
     }
 
+    public CommonEntity(Map<String, Object> basicMap, Map<String, Object> queryMap, Map<String, Object> conditionMap, Map<String, Object> resultMap, Map<String, Object> commMap, Map<String, Object> execlMap) {
+        this.basicMap = basicMap;
+        this.queryMap = queryMap;
+        this.conditionMap = conditionMap;
+        this.resultMap = resultMap;
+        this.commMap = commMap;
+        this.execlMap = execlMap;
+    }
+
     @Override
     public String toString() {
         return "CommonEntity{" +
-                "formMap=" + formMap +
-                ", condition=" + condition +
-                ", retMap=" + retMap +
+                "basicMap=" + basicMap +
+                ", queryMap=" + queryMap +
+                ", conditionMap=" + conditionMap +
+                ", resultMap=" + resultMap +
+                ", commMap=" + commMap +
                 ", execlMap=" + execlMap +
-                ", file=" + file +
                 '}';
     }
 
-    public CommonEntity(Map<String, Object> formMap, Map<String, Object> condition, Map<String, Object> retMap, Map<String, Object> execlMap, MultipartFile file) {
-        this.formMap = formMap;
-        this.condition = condition;
-        this.retMap = retMap;
-        this.execlMap = execlMap;
-        this.file = file;
+    public Map<String, Object> getBasicMap() {
+        return basicMap;
     }
 
-    public Map<String, Object> getFormMap() {
-        return formMap;
+    public void setBasicMap(Map<String, Object> basicMap) {
+        this.basicMap = basicMap;
     }
 
-    public void setFormMap(Map<String, Object> formMap) {
-        this.formMap = formMap;
+    public Map<String, Object> getQueryMap() {
+        return queryMap;
     }
 
-    public Map<String, Object> getCondition() {
-        return condition;
+    public void setQueryMap(Map<String, Object> queryMap) {
+        this.queryMap = queryMap;
     }
 
-    public void setCondition(Map<String, Object> condition) {
-        this.condition = condition;
+    public Map<String, Object> getConditionMap() {
+        return conditionMap;
     }
 
-    public Map<String, Object> getRetMap() {
-        return retMap;
+    public void setConditionMap(Map<String, Object> conditionMap) {
+        this.conditionMap = conditionMap;
     }
 
-    public void setRetMap(Map<String, Object> retMap) {
-        this.retMap = retMap;
+    public Map<String, Object> getResultMap() {
+        return resultMap;
     }
 
-    public Map<String, Object> getExeclMap() {
-        return execlMap;
+    public void setResultMap(Map<String, Object> resultMap) {
+        this.resultMap = resultMap;
     }
 
-    public void setExeclMap(Map<String, Object> execlMap) {
-        this.execlMap = execlMap;
+    public Map<String, Object> getCommMap() {
+        return commMap;
+    }
+
+    public void setCommMap(Map<String, Object> commMap) {
+        this.commMap = commMap;
     }
 
-    public MultipartFile getFile() {
-        return file;
+    public Map<String, Object> getExeclMap() {
+        return execlMap;
     }
 
-    public void setFile(MultipartFile file) {
-        this.file = file;
+    public void setExeclMap(Map<String, Object> execlMap) {
+        this.execlMap = execlMap;
     }
 }

+ 7 - 6
ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java

@@ -13,22 +13,22 @@ public interface ICommonService {
     /**
      * 单表查询列表
      */
-    List<CommonEntity> selectList(Map<String, Object> map);
+    List<CommonEntity> selectList(CommonEntity commonEntity);
 
     /**
      * 批量新增
      */
-    int batchInsert(Map<String, Object> map);
+    int batchInsert(CommonEntity commonEntity);
 
     /**
      * 修改
      */
-    int edit(Map<String, Object> map);
+    int edit(CommonEntity commonEntity);
 
     /**
      * 批量删除
      */
-    int batchDelete(Map<String, Object> map);
+    int batchDelete(CommonEntity commonEntity);
 
     /**
      * 根据sqlkey 执行sql并返回结果
@@ -38,10 +38,11 @@ public interface ICommonService {
     /**
      * 导出列表
      */
-    void export(HttpServletResponse response,String tableName,String sqlKey) throws Exception;
+    void export(HttpServletResponse response, String tableName, String sqlKey) throws Exception;
+
     /**
      * 导出模版
      */
-    void exportTemplate(HttpServletResponse response,String tableName,String sqlKey) throws Exception;
+    void exportTemplate(HttpServletResponse response, String tableName, String sqlKey) throws Exception;
 
 }

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

@@ -34,16 +34,16 @@ public class CommonServiceImpl implements ICommonService {
     private TableSqlMapper tableSqlMapper;
 
     @Override
-    public List<CommonEntity> selectList(Map<String, Object> map) {
-        String tableName = (String) map.get("tableName");
-        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(map.get("condition")));
+    public List<CommonEntity> selectList(CommonEntity commonEntity) {
+        String tableName = (String) commonEntity.getBasicMap().get("tableName");
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
         return commonMapper.selectList(tableName, conditions);
     }
 
     @Override
-    public int batchInsert(Map<String, Object> map) {
-        String tableName = (String) map.get("tableName");
-        List<Object> list = (List<Object>) map.get("field");
+    public int batchInsert(CommonEntity commonEntity) {
+        String tableName = (String) commonEntity.getBasicMap().get("tableName");
+        List<Object> list = (List<Object>) commonEntity.getCommMap();
         List<Map<String, Object>> mapList = new ArrayList<>();
         for (Object obj : list) {
             System.out.println(obj);
@@ -60,24 +60,24 @@ public class CommonServiceImpl implements ICommonService {
     }
 
     @Override
-    public int edit(Map<String, Object> map) {
-        String tableName = (String) map.get("tableName");
-        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(map.get("condition")));
-        Map<String, Object> fields = JSONObject.parseObject(JSON.toJSONString(map.get("field")));
+    public int edit(CommonEntity commonEntity) {
+        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()));
         return commonMapper.edit(fields, tableName, conditions);
     }
 
     @Override
-    public int batchDelete(Map<String, Object> map) {
-        String tableName = (String) map.get("tableName");
-        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(map.get("condition")));
+    public int batchDelete(CommonEntity commonEntity) {
+        String tableName = (String) commonEntity.getBasicMap().get("tableName");
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
         return commonMapper.batchDelete(tableName, conditions);
     }
 
     @Override
     public List<CommonEntity> queryTableList(CommonEntity commonEntity, TableSql tableSql) {
         // 根据sqlkey查询得到当前表单对应的sql
-        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getCondition()));
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
         // sql当中拼接好条件格式 后台使用AND分割 拼接条件
         //  and 。。。。 and 。。。。 and。。。。
         StringBuilder endSQL = new StringBuilder();
@@ -133,7 +133,7 @@ public class CommonServiceImpl implements ICommonService {
         for (int w = 0; w < commonEntities.size(); w++) {
             XSSFRow row = sheet.createRow(rowIndex++);
             for (int e = 0; e < fieldList.size(); e++) {
-                Object val = commonEntities.get(w).getRetMap().get(toUnderScoreCase(fieldList.get(e)));
+                Object val = commonEntities.get(w).getResultMap().get(toUnderScoreCase(fieldList.get(e)));
                 row.createCell(e).setCellValue((val == null ? "" : val).toString());
             }
         }

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

@@ -1,13 +1,25 @@
 package com.ruoyi.system.test;
 
 
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 
 import static com.ruoyi.common.utils.StringUtils.convertToCamelCase;
-import static com.ruoyi.common.utils.StringUtils.toUnderScoreCase;
-import static org.apache.commons.lang3.StringUtils.lowerCase;
+
 
 /**
  * @author hanzihang
@@ -46,11 +58,51 @@ public class ljj {
     }
 
     public static void main(String[] args) {
-        String input = "AND dragform.df_name like concat('%', #{val}, '%')";
-        String identifier = "dragForm";
-//        String extractedSubstring = extractSubstring(input, identifier);
-        String extractedSubstring = toUnderScoreCase(identifier);
-        System.out.println(extractedSubstring);
+
+
+        try {
+            FileInputStream file = new FileInputStream(new File("data.xlsx"));
+
+            // 创建一个工作簿对象
+            Workbook workbook = new XSSFWorkbook(file);
+
+            // 获取第一个sheet
+            Sheet sheet = workbook.getSheetAt(0);
+
+            // 配置数据库连接
+            String url = "jdbc:mysql://localhost:3306/mydatabase";
+            String username = "root";
+            String password = "password";
+
+            // 建立数据库连接
+            Connection connection = DriverManager.getConnection(url, username, password);
+
+            // 准备插入数据的SQL语句
+            String insertQuery = "INSERT INTO mytable (column1, column2) VALUES (?, ?)";
+
+            // 创建预处理语句对象
+            PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
+
+            // 迭代每一行并插入数据
+            for (Row row : sheet) {
+                // 读取每一列数据
+                Cell cell1 = row.getCell(0);
+                Cell cell2 = row.getCell(1);
+
+                // 设置参数并执行插入操作
+                preparedStatement.setString(1, cell1.getStringCellValue());
+                preparedStatement.setString(2, cell2.getStringCellValue());
+                preparedStatement.executeUpdate();
+            }
+
+            // 关闭预处理语句、数据库连接和文件流
+            preparedStatement.close();
+            connection.close();
+            workbook.close();
+            file.close();
+        } catch (IOException | SQLException e) {
+            e.printStackTrace();
+        }
     }
 
 }

+ 1 - 1
ruoyi-system/src/main/resources/mapper/common/CommonMapper.xml

@@ -6,7 +6,7 @@
 
 
     <resultMap id="retMap" type="com.ruoyi.system.entity.CommonEntity" autoMapping="true">
-        <collection property="retMap" ofType="map" autoMapping="true"
+        <collection property="resultMap" ofType="map" autoMapping="true"
                     javaType="map"></collection>
     </resultMap>