Просмотр исходного кода

优化案例流程管理增删改查接口

gy b 2 лет назад
Родитель
Сommit
4796b52963

+ 6
- 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java Просмотреть файл

@@ -25,17 +25,16 @@ public class CaseFlowController {
25 25
      * 查询案件流程节点信息
26 26
      */
27 27
     @PostMapping("/queryCaseFlowInfo")
28
-    public AjaxResult queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) {
29
-        Object obj = caseFlowService.queryCaseFlowInfo(caseFlowSearchVO);
30
-        return success(obj);
28
+    public Object queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) {
29
+        return caseFlowService.queryCaseFlowInfo(caseFlowSearchVO);
31 30
     }
32 31
 
33 32
     /**
34 33
      * 新增或编辑案件流程节点信息
35 34
      */
36 35
     @PostMapping("/saveCaseFlow")
37
-    public AjaxResult addCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) {
38
-        Boolean result = caseFlowService.addCaseFlow(caseFlowVO);
36
+    public AjaxResult saveCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) {
37
+        Boolean result = caseFlowService.saveCaseFlow(caseFlowVO);
39 38
         return success(result);
40 39
 
41 40
     }
@@ -53,8 +52,8 @@ public class CaseFlowController {
53 52
      * 排序案件流程节点
54 53
      */
55 54
     @PostMapping("/sortCaseFlow")
56
-    public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) {
57
-        Boolean result = caseFlowService.sortCaseFlow(caseFlowVO);
55
+    public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) {
56
+        Boolean result = caseFlowService.sortCaseFlow(caseFlowSearchVO);
58 57
         return success(result);
59 58
     }
60 59
 }

+ 8
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java Просмотреть файл

@@ -17,6 +17,14 @@ public class MsCaseFlowSearchVO {
17 17
      * 主键id
18 18
      */
19 19
     private Integer id;
20
+    /**
21
+     * 排序类型0降序1升序
22
+     */
23
+    private Integer sortType;
24
+    /**
25
+     * 序号
26
+     */
27
+    private Integer sort;
20 28
 
21 29
     /**
22 30
      * 案件节点名称

+ 9
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowVO.java Просмотреть файл

@@ -5,6 +5,8 @@ import lombok.Builder;
5 5
 import lombok.Data;
6 6
 import lombok.NoArgsConstructor;
7 7
 
8
+import java.util.List;
9
+
8 10
 
9 11
 @AllArgsConstructor
10 12
 @NoArgsConstructor
@@ -41,5 +43,12 @@ public class MsCaseFlowVO {
41 43
      */
42 44
     private Integer backFlowId;
43 45
     private String backFlowName;
46
+    /**
47
+     * 角色名称
48
+     */
44 49
     private String roleNames;
50
+    /**
51
+     * 角色id
52
+     */
53
+    private List<Long> roleIds;
45 54
 }

+ 3
- 3
ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowService.java Просмотреть файл

@@ -16,7 +16,7 @@ public interface CaseFlowService {
16 16
      * @param caseFlowVO
17 17
      * @return
18 18
      */
19
-    Boolean addCaseFlow(MsCaseFlowVO caseFlowVO);
19
+    Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO);
20 20
 
21 21
     /**
22 22
      * 删除案件流程节点信息
@@ -27,8 +27,8 @@ public interface CaseFlowService {
27 27
 
28 28
     /**
29 29
      * 排序案件流程节点
30
-     * @param caseFlowVO
30
+     * @param caseFlowSearchVO
31 31
      * @return
32 32
      */
33
-    Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO);
33
+    Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowSearchVO);
34 34
 }

+ 103
- 20
ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java Просмотреть файл

@@ -3,8 +3,7 @@ package com.ruoyi.system.service.flow;
3 3
 import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5 5
 import com.ruoyi.common.core.domain.entity.SysRole;
6
-import com.ruoyi.common.utils.PageUtils;
7
-import com.ruoyi.system.domain.SysOperLog;
6
+import com.ruoyi.common.core.page.TableDataInfo;
8 7
 import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
9 8
 import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated;
10 9
 import com.ruoyi.system.domain.vo.flow.MsCaseFlowSearchVO;
@@ -12,6 +11,8 @@ import com.ruoyi.system.domain.vo.flow.MsCaseFlowVO;
12 11
 import com.ruoyi.system.mapper.SysRoleMapper;
13 12
 import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
14 13
 import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper;
14
+import com.ruoyi.system.util.NewStringUtil;
15
+import com.ruoyi.system.util.TableDataUtil;
15 16
 import org.springframework.beans.BeanUtils;
16 17
 import org.springframework.beans.factory.annotation.Autowired;
17 18
 import org.springframework.stereotype.Service;
@@ -23,10 +24,6 @@ import java.util.List;
23 24
 import java.util.Map;
24 25
 import java.util.stream.Collectors;
25 26
 
26
-import static com.deepoove.poi.data.NumberingRenderData.build;
27
-import static com.ruoyi.common.utils.PageUtils.startPage;
28
-import static jdk.nashorn.internal.runtime.Debug.id;
29
-
30 27
 @Service
31 28
 public class CaseFlowServiceImpl implements CaseFlowService {
32 29
     @Autowired
@@ -48,10 +45,13 @@ public class CaseFlowServiceImpl implements CaseFlowService {
48 45
         if (caseFlowSearchVO.getId() != null) {
49 46
             return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId());
50 47
         } else if (caseFlowSearchVO == null) {
48
+            //查询所有案件流程节点信息
51 49
             return msCaseFlowMapper.selectAll();
52 50
         } else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) {
51
+            //查询所有案件流程节点信息
53 52
             return msCaseFlowMapper.selectAll();
54 53
         } else {
54
+            //分页查询案件流程节点信息
55 55
             Map<Integer, List<SysRole>> sysRoleMap = queryRoleByFlowId(null);
56 56
             Example example = new Example(MsCaseFlow.class);
57 57
             example.setOrderByClause(" sort DESC ");
@@ -62,23 +62,26 @@ public class CaseFlowServiceImpl implements CaseFlowService {
62 62
             PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize());
63 63
             List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example);
64 64
             PageInfo<MsCaseFlow> pageInfo = new PageInfo<>(msCaseFlows);
65
-            PageInfo<MsCaseFlowVO> newpageInfo = new PageInfo<>();
66
-            BeanUtils.copyProperties(pageInfo, newpageInfo);
65
+            long total = pageInfo.getTotal();
67 66
             List<MsCaseFlowVO> list = new ArrayList<>();
68 67
             for (int i = 0; i < msCaseFlows.size(); i++) {
69 68
                 MsCaseFlow msCaseFlow = msCaseFlows.get(i);
70 69
                 MsCaseFlowVO temp = new MsCaseFlowVO();
71 70
                 BeanUtils.copyProperties(msCaseFlow, temp);
72 71
                 //关联的角色
73
-                List<String> roleNames = new ArrayList<>();
72
+                StringBuilder roleNames = new StringBuilder();
73
+                List<Long> roleIds = new ArrayList<>();
74 74
                 if (sysRoleMap.containsKey(msCaseFlow.getId())) {
75 75
                     List<SysRole> sysRoles = sysRoleMap.get(msCaseFlow.getId());
76
-                    roleNames = sysRoles
77
-                            .stream()
78
-                            .map(sysRole -> sysRole.getRoleName())
79
-                            .collect(Collectors.toList());
80
-                    temp.setRoleNames(roleNames.toString());
76
+                    sysRoles.stream().forEach(item -> {
77
+                        roleNames.append(item.getRoleName()).append(",");
78
+                    });
79
+                    temp.setRoleNames(NewStringUtil.stringListToStringBuilder(sysRoles.stream().map(SysRole::getRoleName).collect(Collectors.toList()), ","));
80
+                    roleIds.addAll(sysRoles.stream().map(SysRole::getRoleId).collect(Collectors.toList()));
81
+                } else {
82
+                    temp.setRoleNames("");
81 83
                 }
84
+                temp.setRoleIds(roleIds);
82 85
                 //驳回节点
83 86
                 if (msCaseFlow.getBackFlowId() != null) {
84 87
                     MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId());
@@ -86,7 +89,8 @@ public class CaseFlowServiceImpl implements CaseFlowService {
86 89
                 }
87 90
                 list.add(temp);
88 91
             }
89
-            return list;
92
+            TableDataInfo tableDataInfo = TableDataUtil.rebuildTableDataInfo(list, total);
93
+            return tableDataInfo;
90 94
         }
91 95
     }
92 96
 
@@ -126,8 +130,68 @@ public class CaseFlowServiceImpl implements CaseFlowService {
126 130
      * @return
127 131
      */
128 132
     @Override
129
-    public Boolean addCaseFlow(MsCaseFlowVO caseFlowVO) {
130
-        return null;
133
+    public Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO) {
134
+        if (caseFlowVO.getId() != null) {
135
+            //更新案件流程信息
136
+            MsCaseFlow msCaseFlow = new MsCaseFlow();
137
+            BeanUtils.copyProperties(caseFlowVO, msCaseFlow);
138
+            int i = msCaseFlowMapper.updateByPrimaryKey(msCaseFlow);
139
+            if (i > 0) {
140
+                //更新流程节点和角色之间的关系
141
+                updateFlowRoleByFlowId(caseFlowVO.getId(), caseFlowVO.getRoleIds());
142
+                return true;
143
+            }
144
+        } else {
145
+            int sort = 1;
146
+            Example example = new Example(MsCaseFlow.class);
147
+            example.setOrderByClause("sort DESC limit 1");
148
+            Example.Criteria criteria = example.createCriteria();
149
+            List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example);
150
+            if (msCaseFlows != null && msCaseFlows.size() > 0) {
151
+                sort = msCaseFlows.get(0).getSort() + 1;
152
+            }
153
+            //新增案件流程信息
154
+            MsCaseFlow msCaseFlow = new MsCaseFlow();
155
+            BeanUtils.copyProperties(caseFlowVO, msCaseFlow);
156
+            msCaseFlow.setSort(sort);
157
+            int insert = msCaseFlowMapper.insert(msCaseFlow);
158
+            if (insert > 0) {
159
+                //更新流程节点和角色之间的关系
160
+                updateFlowRoleByFlowId(caseFlowVO.getId(), caseFlowVO.getRoleIds());
161
+                return true;
162
+            }
163
+        }
164
+        return false;
165
+    }
166
+
167
+    /**
168
+     * 更新流程节点和角色之间的关系
169
+     *
170
+     * @param id
171
+     * @param roleIds
172
+     */
173
+    private void updateFlowRoleByFlowId(Integer id, List<Long> roleIds) {
174
+        if (roleIds != null && roleIds.size() > 0) {
175
+            //删除流程节点和角色之间的关系
176
+            deleteFlowRoleByFlowId(id);
177
+            for (int i = 0; i < roleIds.size(); i++) {
178
+                MsCaseFlowRoleRelated msCaseFlowRoleRelated = new MsCaseFlowRoleRelated();
179
+                msCaseFlowRoleRelated.setFlowId(id);
180
+                msCaseFlowRoleRelated.setRoleid(roleIds.get(i));
181
+                msCaseFlowRoleRelatedMapper.insertSelective(msCaseFlowRoleRelated);
182
+            }
183
+        }
184
+    }
185
+
186
+    /**
187
+     * 删除流程节点和角色之间的关系
188
+     *
189
+     * @param id
190
+     */
191
+    private void deleteFlowRoleByFlowId(Integer id) {
192
+        if (id != null) {
193
+            msCaseFlowRoleRelatedMapper.deleteByExample(new Example(MsCaseFlowRoleRelated.class).createCriteria().andEqualTo("flowId", id));
194
+        }
131 195
     }
132 196
 
133 197
     /**
@@ -138,7 +202,16 @@ public class CaseFlowServiceImpl implements CaseFlowService {
138 202
      */
139 203
     @Override
140 204
     public Boolean deleteCaseFlow(MsCaseFlowVO caseFlowVO) {
141
-        return null;
205
+        if (caseFlowVO.getId() != null) {
206
+            //删除案件流程信息
207
+            int i = msCaseFlowMapper.deleteByPrimaryKey(caseFlowVO.getId());
208
+            if (i > 0) {
209
+                //删除流程节点和角色之间的关系
210
+                deleteFlowRoleByFlowId(caseFlowVO.getId());
211
+                return true;
212
+            }
213
+        }
214
+        return false;
142 215
     }
143 216
 
144 217
     /**
@@ -148,7 +221,17 @@ public class CaseFlowServiceImpl implements CaseFlowService {
148 221
      * @return
149 222
      */
150 223
     @Override
151
-    public Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO) {
152
-        return null;
224
+    public Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowVO) {
225
+        if (caseFlowVO != null && caseFlowVO.getId() != null && caseFlowVO.getSortType() != null) {
226
+            if (caseFlowVO.getSortType() == 0) {
227
+                //降序
228
+
229
+                return true;
230
+            } else if (caseFlowVO.getSortType() == 1) {
231
+                //升序
232
+                return true;
233
+            }
234
+        }
235
+        return false;
153 236
     }
154 237
 }

+ 27
- 0
ruoyi-system/src/main/java/com/ruoyi/system/util/NewStringUtil.java Просмотреть файл

@@ -0,0 +1,27 @@
1
+package com.ruoyi.system.util;
2
+
3
+import java.util.List;
4
+
5
+public class NewStringUtil {
6
+    /**
7
+     * 将字符串集合转换成字符串
8
+     *
9
+     * @param list
10
+     * @param split
11
+     * @return
12
+     */
13
+    public static String stringListToStringBuilder(List<String> list, String split) {
14
+        if (list == null || list.size() == 0) {
15
+            return "";
16
+        } else {
17
+            StringBuilder sb = new StringBuilder();
18
+            for (int i = 0; i < list.size(); i++) {
19
+                sb.append(list.get(i));
20
+                if (i != list.size() - 1) {
21
+                    sb.append(split);
22
+                }
23
+            }
24
+            return sb.toString();
25
+        }
26
+    }
27
+}

+ 22
- 0
ruoyi-system/src/main/java/com/ruoyi/system/util/TableDataUtil.java Просмотреть файл

@@ -0,0 +1,22 @@
1
+package com.ruoyi.system.util;
2
+
3
+import com.ruoyi.common.constant.HttpStatus;
4
+import com.ruoyi.common.core.page.TableDataInfo;
5
+
6
+import java.util.List;
7
+
8
+public class TableDataUtil {
9
+    /**
10
+     * 响应请求分页数据
11
+     */
12
+    @SuppressWarnings({"rawtypes", "unchecked"})
13
+    public static TableDataInfo rebuildTableDataInfo(List<?> list, long total) {
14
+        TableDataInfo rspData = new TableDataInfo();
15
+        rspData.setCode(HttpStatus.SUCCESS);
16
+        rspData.setMsg("查询成功");
17
+        rspData.setRows(list);
18
+        rspData.setTotal(total);
19
+        return rspData;
20
+    }
21
+
22
+}