Prechádzať zdrojové kódy

feat:处理按钮通用接口

xuezizhuo 1 rok pred
rodič
commit
49671e7ec6

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

@@ -1,17 +1,19 @@
 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.ICommonService;
-import com.ruoyi.system.service.IDragTableGroupService;
-import com.ruoyi.system.service.IDragTableService;
-import com.ruoyi.system.service.ITableSqlService;
+import com.ruoyi.system.service.*;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/dragform/common")
@@ -29,6 +31,9 @@ public class CommonController extends BaseController {
     @Resource
     private IDragTableGroupService dragTableGroupService;
 
+    @Resource
+    private IDragFormService dragFormService;
+
     /**
      * 共通查询
      */
@@ -97,4 +102,44 @@ public class CommonController extends BaseController {
         startPage();
         return getDataTable(commonService.dragTablePreview(commonEntity));
     }
+
+    /**
+     * 处理按钮通用接口(新增、修改、删除)
+     */
+    @PostMapping("/commonBtnHandle")
+    public AjaxResult commonBtnHandle(@RequestBody CommonEntity commonEntity) throws JsonProcessingException {
+        //按钮类型
+        Long btnType = Long.valueOf(commonEntity.getBasicMap().get("btnType").toString());
+        //是否开启弹窗
+        String visible = commonEntity.getBasicMap().get("visible").toString();
+        /*
+        * 判断什么类型走什么接口:
+        * btnType  10:新增、8:修改、9:删除、5:脚本
+        * visible  false代表弹窗未开启时走回显表单模板及数据信息接口;true代表弹窗开启时走保存数据接口
+        * */
+        if (btnType == ButtonTypeConstants.INSERT && visible.equals("true")) {
+            return toAjax(commonService.batchInsert(commonEntity));
+        } else if (btnType == ButtonTypeConstants.INSERT && visible.equals("false")) {
+            String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
+            return success(dragFormService.selectDragFormBySqlKey(sqlKey));
+        } else if (btnType == ButtonTypeConstants.UPDATE && visible.equals("true")) {
+            return toAjax(commonService.edit(commonEntity));
+        } else if (btnType == ButtonTypeConstants.UPDATE && visible.equals("false")) {
+            Map<String,Object> map = new HashMap<>();
+            //获取模板信息
+            String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
+            DragForm dragForm = dragFormService.selectDragFormBySqlKey(sqlKey);
+            map.put("template",dragForm);
+            //返回结果
+            map.put("result",commonService.getInfoById(commonEntity));
+            return success(map);
+        } else if (btnType == ButtonTypeConstants.DELETE) {
+            return toAjax(commonService.batchDelete(commonEntity));
+        } else if(btnType == ButtonTypeConstants.SCRIPT) {
+
+        }
+        return warn("暂不支持该操作!");
+    }
+
+
 }

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragFormController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.controller.dragForm;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
@@ -100,7 +101,7 @@ public class DragFormController extends BaseController {
      * 详细信息
      */
     @GetMapping("/getInfoBySqlKey/{sqlKey}")
-    public AjaxResult getInfoBySqlKey(@PathVariable("sqlKey") String sqlKey) {
+    public AjaxResult getInfoBySqlKey(@PathVariable("sqlKey") String sqlKey) throws JsonProcessingException {
         return success(dragFormService.selectDragFormBySqlKey(sqlKey));
     }
 

+ 5 - 0
ruoyi-common/pom.xml

@@ -167,6 +167,11 @@
             <artifactId>spring-webmvc</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 41 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/ButtonTypeConstants.java

@@ -0,0 +1,41 @@
+package com.ruoyi.common.constant;
+
+/**
+ * 按钮类型
+ */
+public class ButtonTypeConstants {
+
+    /** 操作按钮 */
+    public static final Long HANDLE = 0L;
+
+    /** 其他按钮 */
+    public static final Long OTHER = 1L;
+
+    /** 表单按钮 */
+    public static final Long FORM = 2L;
+
+    /** 内链按钮 */
+    public static final Long INNER_CHAIN = 3L;
+
+    /** 流程按钮 */
+    public static final Long PROCESS = 4L;
+
+    /** 脚本按钮 */
+    public static final Long SCRIPT = 5L;
+
+    /** 目录 */
+    public static final Long CATALOGUE = 6L;
+
+    /** 外链按钮 */
+    public static final Long OUTSIDE_CHAIN = 7L;
+
+    /** 修改按钮 */
+    public static final Long UPDATE = 8L;
+
+    /** 删除按钮 */
+    public static final Long DELETE = 9L;
+
+    /** 新增按钮 */
+    public static final Long INSERT = 10L;
+
+}

+ 10 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/CommonMapper.java

@@ -48,4 +48,14 @@ public interface CommonMapper {
      */
     List<Map<String,Object>> selectDropDownListByDict(String dictType);
 
+    /**
+     * 获取详情
+     */
+    CommonEntity getInfoById(@Param("tableName") String tableName, @Param("conditions") Map<String, Object> conditions);
+
+    /**
+     * 执行sql,直接返回map形式
+     */
+    List<Map<String,Object>> executeSql(String sql);
+
 }

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

@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
 
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.TableSql;
+import org.apache.ibatis.annotations.Param;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
@@ -52,4 +53,11 @@ public interface ICommonService {
      */
     List<CommonEntity> dragTablePreview(CommonEntity commonEntity);
 
+    /**
+     * 获取详情
+     */
+    CommonEntity getInfoById(CommonEntity commonEntity);
+
+
+
 }

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

@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
 
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.entity.DragForm;
 
@@ -72,5 +73,5 @@ public interface IDragFormService {
     /**
      * 根据sqlKey查询动态表单
      */
-    DragForm selectDragFormBySqlKey(String sqlKey);
+    DragForm selectDragFormBySqlKey(String sqlKey) throws JsonProcessingException;
 }

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

@@ -289,6 +289,13 @@ public class CommonServiceImpl implements ICommonService {
         return commonMapper.queryTableList(sql);
     }
 
+    @Override
+    public CommonEntity getInfoById(CommonEntity commonEntity) {
+        String tableName = (String) commonEntity.getBasicMap().get("tableName");
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getConditionMap()));
+        return commonMapper.getInfoById(tableName,conditions);
+    }
+
     public static String extractSubstring(String input, String identifier) {
         int startIndex = input.indexOf(identifier);
         if (startIndex == -1) {

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

@@ -1,13 +1,20 @@
 package com.ruoyi.system.service.impl;
 
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragForm;
 import com.ruoyi.system.entity.DragTableForm;
+import com.ruoyi.system.mapper.CommonMapper;
 import com.ruoyi.system.mapper.DragFormMapper;
 import com.ruoyi.system.mapper.DragTableFormMapper;
 import com.ruoyi.system.service.IDragFormService;
@@ -20,6 +27,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 /**
@@ -38,6 +46,9 @@ public class DragFormServiceImpl implements IDragFormService {
     @Resource
     private DragTableFormMapper dragTableFormMapper;
 
+    @Resource
+    private CommonMapper commonMapper;
+
     /**
      * 查询动态表单
      *
@@ -146,11 +157,43 @@ public class DragFormServiceImpl implements IDragFormService {
     }
 
     @Override
-    public DragForm selectDragFormBySqlKey(String sqlKey) {
-        return dragFormMapper.selectDragFormBySqlKey(sqlKey);
+    public DragForm selectDragFormBySqlKey(String sqlKey) throws JsonProcessingException {
+        DragForm dragForm = dragFormMapper.selectDragFormBySqlKey(sqlKey);
+        ObjectMapper objectMapper = new ObjectMapper();
+        Gson gson = new Gson();
+        //单个下拉框
+        //获取要执行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(entry.getValue().toString());
+            sqlMap.put(entry.getKey(),mapList);
+        }
+        dragForm.setDfFormSql(gson.toJson(sqlMap));
+
+//        //级联下拉框
+//        //获取需要执行的sql集合
+//        List<Object> sqlList = objectMapper.readValue(dragForm.getDfFormSql(), new TypeReference<List<Object>>() {});
+//        //得到根节点数据
+//        List<Map<String, Object>> rootList = commonMapper.executeSql(sqlList.get(0).toString());
+//        for (Object sql: sqlList){
+//            //跳过执行第一条sql,第一条为根节点
+//            if(sqlList.indexOf(sql) == 0){
+//                continue;
+//            }
+//
+//
+//
+//        }
+//        for (Map<String, Object> m : rootList){
+//
+//        }
+
+
+
+        return dragForm;
     }
 
-
     /**
      * 删除表单源文件
      *

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

@@ -81,4 +81,19 @@
         select dict_value as fieldKey,dict_label as fieldName from sys_dict_data where dict_type = #{dictType} and status = '0'
     </select>
 
+    <select id="getInfoById" resultMap="retMap">
+        select * from ${tableName}
+        <where>
+            <if test="conditions != null">
+                <foreach collection="conditions" item="value" index="key" separator="and">
+                    ${key} = #{value}
+                </foreach>
+            </if>
+        </where>
+    </select>
+
+    <select id="executeSql" resultType="map">
+        ${sql}
+    </select>
+
 </mapper>

+ 1 - 1
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableBtnMapper.xml

@@ -163,7 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="hasChildByBtnId" resultType="Integer">
-        select count(1) from drag_table_btn where btn_parent_id = #{btnId}
+        select count(1) from drag_table_btn where btn_parent_id = #{btnId} and del_flag = '0'
     </select>
 
 </mapper>