Переглянути джерело

refactor: 按钮共通接口

韩帛霖 1 рік тому
батько
коміт
8d99f1203d

+ 28 - 41
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonBtnController.java

@@ -1,30 +1,17 @@
 package com.ruoyi.web.controller.dragForm;
 
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.ruoyi.common.constant.ButtonTypeConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.form.FromUtils;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragForm;
 import com.ruoyi.system.entity.DragTableBtn;
-import com.ruoyi.system.entity.DragTableGroup;
-import com.ruoyi.system.entity.vo.DragTableGroupVo;
-import com.ruoyi.system.entity.vo.DragTableVo;
-import com.ruoyi.system.mapper.DragTableBtnMapper;
-import com.ruoyi.system.mapper.DragTableBtnRelevanceMapper;
-import com.ruoyi.system.mapper.DragTableGroupMapper;
 import com.ruoyi.system.mapper.DragTableMapper;
 import com.ruoyi.system.service.*;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * @author hanzihang
@@ -49,33 +36,18 @@ public class CommonBtnController extends BaseController {
     private DragTableMapper dragTableMapper;
 
     @Resource
-    private   IDragTableGroupService dragTableGroupService;
-
-
+    private IDragTableGroupService dragTableGroupService;
 
     /**
-     * 处理按钮通用接口(新增、修改、删除)
+     * 处理按钮通用接口(新增、修改、删除...)
+     * 判断什么类型走什么接口: visible  false代表弹窗未开启时走回显表单模板及数据信息接口;true代表弹窗开启时走保存数据接口
+     * 是否提交表单操作 true是 false回显表单数据  commonEntity.getBasicMap().get("visible").toString()
      */
     @PostMapping("/commonBtnHandle")
-    public AjaxResult commonBtnHandle(@RequestBody CommonEntity commonEntity) throws JsonProcessingException {
-
-        //按钮类型
-        Long btnType = Long.valueOf(commonEntity.getBasicMap().get("btnType").toString());
-        String type = "";
-        if (btnType == ButtonTypeConstants.INSERT) {
-            type = "INSERT";
-        } else if (btnType == ButtonTypeConstants.UPDATE) {
-            type = "UPDATE";
-        } else if (btnType == ButtonTypeConstants.DELETE) {
-            type = "DELETE";
-        }
-        /*
-         * 判断什么类型走什么接口:
-         * btnType  10:新增、8:修改、9:删除、5:脚本
-         * visible  false代表弹窗未开启时走回显表单模板及数据信息接口;true代表弹窗开启时走保存数据接口
-         * */
-        //是否提交表单操作 true是 false回显表单数据 commonEntity.getBasicMap().get("visible").toString()
-        switch (type) {
+    public AjaxResult commonBtnHandle(@RequestBody CommonEntity commonEntity) {
+        // 获取到按钮类型
+        String btnType = commonEntity.getBasicMap().get("btnType").toString();
+        switch (btnType) {
             case "INSERT":
                 return insertBtn(commonEntity);
             case "UPDATE":
@@ -87,9 +59,14 @@ public class CommonBtnController extends BaseController {
         }
     }
 
+    /**
+     * 新增类型按钮
+     *
+     * @param commonEntity
+     * @return
+     */
 
-    // 新增类型按钮
-    public AjaxResult insertBtn(CommonEntity commonEntity) throws JsonProcessingException {
+    public AjaxResult insertBtn(CommonEntity commonEntity) {
         if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
             return AjaxResult.btnMessage(commonService.batchInsert(commonEntity));
         } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
@@ -101,8 +78,13 @@ public class CommonBtnController extends BaseController {
     }
 
 
-    // 修改类型按钮
-    public AjaxResult updateBtn(CommonEntity commonEntity) throws JsonProcessingException {
+    /**
+     * 修改类型按钮
+     *
+     * @param commonEntity
+     * @return
+     */
+    public AjaxResult updateBtn(CommonEntity commonEntity) {
         //是否开启弹窗
         if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
             if (commonEntity.getBasicMap().containsKey("btnKey")) {  // 按钮提交时会触发别的操作
@@ -136,7 +118,12 @@ public class CommonBtnController extends BaseController {
     }
 
 
-    // 删除类型按钮
+    /**
+     * 删除类型按钮
+     *
+     * @param commonEntity
+     * @return
+     */
     public AjaxResult deleteBtn(CommonEntity commonEntity) {
         return toAjax(commonService.batchDelete(commonEntity));
     }

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

@@ -1,20 +1,16 @@
 package com.ruoyi.web.controller.dragForm;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.ruoyi.common.constant.ButtonTypeConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.exception.tenantdatassource.TenantDataSource;
 import com.ruoyi.system.entity.CommonEntity;
-import com.ruoyi.system.entity.DragForm;
 import com.ruoyi.system.entity.TableSql;
 import com.ruoyi.system.service.*;
 import org.springframework.web.bind.annotation.*;
+
 import javax.annotation.Resource;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 @RestController
 @RequestMapping("/dragform/common")
@@ -72,7 +68,7 @@ public class CommonController extends BaseController {
      * 共通获取详情
      */
     @GetMapping("/getInfo")
-    public AjaxResult getInfo(CommonEntity commonEntity){
+    public AjaxResult getInfo(CommonEntity commonEntity) {
         return success(commonService.getInfoById(commonEntity));
     }
 
@@ -84,9 +80,9 @@ public class CommonController extends BaseController {
      */
     @GetMapping("/getTableList")
     public TableDataInfo queryTableList(CommonEntity commonEntity) throws TenantDataSource {
-        if(commonEntity.getQueryMap().get("sqlkey").toString().equals("")){
-            return  getDataTable(null);
-        }else {
+        if (commonEntity.getQueryMap().get("sqlkey").toString().equals("")) {
+            return getDataTable(null);
+        } else {
             TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getQueryMap().get("sqlkey").toString());
             startPage();  // 校验是否sqlserver 否执行 是执行另一种方式的分页
             return getDataTable(commonService.queryGroupTableList(commonEntity, tableSql));
@@ -98,7 +94,7 @@ public class CommonController extends BaseController {
      */
     @GetMapping("/dragTableInfo")
     public AjaxResult dragTableInfo(CommonEntity commonEntity) {
-      return   AjaxResult.success(dragTableService.dragTableInfo(commonEntity.getQueryMap().get("tableKey").toString()));
+        return AjaxResult.success(dragTableService.dragTableInfo(commonEntity.getQueryMap().get("tableKey").toString()));
     }
 
     /**
@@ -114,10 +110,9 @@ public class CommonController extends BaseController {
      * 通用批量查询下拉框数据接口
      */
     @PostMapping("/queryDropDownBoxData")
-    public AjaxResult queryDropDownBoxData(@RequestBody List<CommonEntity> commonEntityList){
+    public AjaxResult queryDropDownBoxData(@RequestBody List<CommonEntity> commonEntityList) {
         return AjaxResult.success(commonService.queryDropDownBoxData(commonEntityList));
     }
 
 
-
 }

+ 0 - 85
ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java

@@ -70,90 +70,5 @@ public interface ICommonService {
      */
     CommonEntity queryDropDownBoxData(List<CommonEntity> commonEntityList);
 
-
-
 }
-/*
-
-  bpm_execute_process bep.id AS bep_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
-  bpm_execute_process bep.task_key AS bep_task_key` varchar(255) DEFAULT NULL COMMENT '流程任务执行别名',
-  bpm_execute_process bep.task_name AS bep_task_name` varchar(255) DEFAULT NULL COMMENT '任务名称',
-  bpm_execute_process bep.task_plan_key AS bep_task_plan_key` varchar(255) DEFAULT NULL COMMENT '任务计划key',
-  bpm_execute_process bep.task_node_key AS bep_task_node_key` varchar(255) DEFAULT NULL COMMENT '任务节点别名(记录当前流程执行过的最后一个节点id)',
-  bpm_execute_process bep.task_node_next_key AS bep_task_node_next_key` varchar(255) DEFAULT NULL COMMENT '存贮下一个执行的节点',
-  bpm_execute_process bep.task_process_type AS bep_task_process_type` varchar(100) DEFAULT NULL COMMENT '任务流程类型',
-  bpm_execute_process bep.task_process_key AS bep_task_process_key` varchar(255) DEFAULT NULL COMMENT '定义的流程别名',
-  bpm_execute_process bep.task_process_xml_content AS bep_task_process_xml_content` text COMMENT 'xml标签内容',
-  bpm_execute_process bep.task_process_state AS bep_task_process_state` int(11) DEFAULT NULL COMMENT '任务流程状态',
-  bpm_execute_process bep.task_process_note AS bep_task_process_note` text COMMENT '版本注释',
-  bpm_execute_process bep.del_flag AS bep_del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
-  bpm_execute_process bep.remark AS bep_remark` varchar(255) DEFAULT NULL COMMENT '备注',
-
-
-bep.id AS bep_id,
-bep.task_key AS bep_task_key,
-bep.task_name AS bep_task_name,
-bep.task_plan_key AS bep_task_plan_key,
-bep.task_node_key AS bep_task_node_key,
-bep.task_node_next_key AS bep_task_node_next_key,
-bep.task_process_type AS bep_task_process_type,
-bep.task_process_key AS bep_task_process_key,
-bep.task_process_xml_content AS bep_task_process_xml_content,
-bep.task_process_state AS bep_task_process_state,
-bep.task_process_note AS bep_task_process_note,
-bep.del_flag AS bep_del_flag,
-bep.remark AS bep_remark,
-
-
-bpm_execute_node` (
-  id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
-  ` varchar(50) DEFAULT NULL COMMENT '当前执行流程任务编号task_key',
-  ` varchar(50) DEFAULT NULL COMMENT '节点编号',
-  ` varchar(100) DEFAULT NULL COMMENT '节点名称',
-  ` varchar(50) DEFAULT NULL COMMENT '表单编号',
-  ` varchar(50) DEFAULT NULL COMMENT '节点类型(当前节点是判断、网关、普通节点等等。。。。。)',
-  ` varchar(255) DEFAULT NULL COMMENT '节点前(节点前后只能执行脚本,下一个节点前相当于当前节点后)',
-  ` varchar(255) DEFAULT NULL COMMENT '节点后(节点前只存在一个)',
-  ` varchar(255) DEFAULT NULL COMMENT '角色权限 虚拟角色-》勾选用户存储中间表',
-  ` varchar(255) DEFAULT NULL COMMENT '节点描述',
-  ` varchar(255) DEFAULT NULL COMMENT '节点任务执行数量记录(件数)',
-  ` varchar(255) DEFAULT NULL COMMENT '节点任务执行重量记录(重量)',
-  ` varchar(255) DEFAULT NULL COMMENT '节点状态(0:未执行 1:已执行)',
-  ` varchar(255) DEFAULT NULL COMMENT '流程发起的时添设置该任务的优先级',
-  ` varchar(255) DEFAULT NULL COMMENT '执行节点备用列(未启用)',
-  ` varchar(255) DEFAULT NULL COMMENT '执行节点备用列(未启用)',
-  ` varchar(255) DEFAULT NULL COMMENT '执行节点备用列(未启用)',
-  ` varchar(255) DEFAULT NULL COMMENT '执行节点备用列(未启用)',
-  ` varchar(255) DEFAULT NULL COMMENT '执行节点备用列(未启用)',
-  ` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
-  ` varchar(64) DEFAULT NULL COMMENT '执行者ID',
-  ` varchar(64) DEFAULT NULL COMMENT '执行者',
-  ` datetime DEFAULT NULL COMMENT '执行时间',
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- */
-
 

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

@@ -73,5 +73,5 @@ public interface IDragFormService {
     /**
      * 根据sqlKey查询动态表单
      */
-    DragForm selectDragFormBySqlKey(String sqlKey) throws JsonProcessingException;
+    DragForm selectDragFormBySqlKey(String sqlKey);
 }

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

@@ -58,7 +58,7 @@ public class DragFormServiceImpl implements IDragFormService {
      */
     @Override
     public DragForm selectDragFormByFId(Long fId) {
-        return dragFormMapper.selectDragFormByFId(fId);
+        return queryFormSelect(dragFormMapper.selectDragFormByFId(fId));
     }
 
     /**
@@ -156,22 +156,9 @@ public class DragFormServiceImpl implements IDragFormService {
     }
 
     @Override
-    public DragForm selectDragFormBySqlKey(String sqlKey) throws JsonProcessingException {
+    public DragForm selectDragFormBySqlKey(String sqlKey) {
         DragForm dragForm = dragFormMapper.selectDragFormBySqlKey(sqlKey);
-        ObjectMapper objectMapper = new ObjectMapper();
-        Gson gson = new Gson();
-        if (dragForm == null){
-            return dragForm;
-        }
-        //单个下拉框
-        //获取要执行sql
-        Map<String, Object> sqlMap = objectMapper.readValue(dragForm.getDfFormSql(), Map.class);
-        //循环得到每一个sql语句返回结果
-        for (Map.Entry<String, Object> entry : sqlMap.entrySet()) {
-            List<Map<String, Object>> mapList = commonMapper.executeSql(String.valueOf(entry.getValue()));
-            sqlMap.put(entry.getKey(), mapList);
-        }
-        dragForm.setDfFormSql(gson.toJson(sqlMap));
+
 
 //        //级联下拉框
 //        //获取需要执行的sql集合
@@ -192,7 +179,33 @@ public class DragFormServiceImpl implements IDragFormService {
 //        }
 
 
-        return dragForm;
+        return queryFormSelect(dragForm);
+    }
+
+    /**
+     * 查询当前表单的详细信息-》中前表单中所包含的下拉框
+     */
+    public DragForm queryFormSelect(DragForm dragForm) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        Gson gson = new Gson();
+        if (dragForm == null) {
+            return dragForm;
+        }
+        //单个下拉框
+        //获取要执行sql
+        Map<String, Object> sqlMap = null;
+        try {
+            sqlMap = objectMapper.readValue(dragForm.getDfFormSql(), Map.class);
+            //循环得到每一个sql语句返回结果
+            for (Map.Entry<String, Object> entry : sqlMap.entrySet()) {
+                List<Map<String, Object>> mapList = commonMapper.executeSql(String.valueOf(entry.getValue()));
+                sqlMap.put(entry.getKey(), mapList);
+            }
+            dragForm.setDfFormSql(gson.toJson(sqlMap));
+            return dragForm;
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     /**