Procházet zdrojové kódy

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

gy b před 2 roky
rodič
revize
4796b52963

+ 6
- 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java Zobrazit soubor

25
      * 查询案件流程节点信息
25
      * 查询案件流程节点信息
26
      */
26
      */
27
     @PostMapping("/queryCaseFlowInfo")
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
     @PostMapping("/saveCaseFlow")
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
         return success(result);
38
         return success(result);
40
 
39
 
41
     }
40
     }
53
      * 排序案件流程节点
52
      * 排序案件流程节点
54
      */
53
      */
55
     @PostMapping("/sortCaseFlow")
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
         return success(result);
57
         return success(result);
59
     }
58
     }
60
 }
59
 }

+ 8
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java Zobrazit soubor

17
      * 主键id
17
      * 主键id
18
      */
18
      */
19
     private Integer id;
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 Zobrazit soubor

5
 import lombok.Data;
5
 import lombok.Data;
6
 import lombok.NoArgsConstructor;
6
 import lombok.NoArgsConstructor;
7
 
7
 
8
+import java.util.List;
9
+
8
 
10
 
9
 @AllArgsConstructor
11
 @AllArgsConstructor
10
 @NoArgsConstructor
12
 @NoArgsConstructor
41
      */
43
      */
42
     private Integer backFlowId;
44
     private Integer backFlowId;
43
     private String backFlowName;
45
     private String backFlowName;
46
+    /**
47
+     * 角色名称
48
+     */
44
     private String roleNames;
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 Zobrazit soubor

16
      * @param caseFlowVO
16
      * @param caseFlowVO
17
      * @return
17
      * @return
18
      */
18
      */
19
-    Boolean addCaseFlow(MsCaseFlowVO caseFlowVO);
19
+    Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO);
20
 
20
 
21
     /**
21
     /**
22
      * 删除案件流程节点信息
22
      * 删除案件流程节点信息
27
 
27
 
28
     /**
28
     /**
29
      * 排序案件流程节点
29
      * 排序案件流程节点
30
-     * @param caseFlowVO
30
+     * @param caseFlowSearchVO
31
      * @return
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 Zobrazit soubor

3
 import com.github.pagehelper.PageHelper;
3
 import com.github.pagehelper.PageHelper;
4
 import com.github.pagehelper.PageInfo;
4
 import com.github.pagehelper.PageInfo;
5
 import com.ruoyi.common.core.domain.entity.SysRole;
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
 import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
7
 import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
9
 import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated;
8
 import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated;
10
 import com.ruoyi.system.domain.vo.flow.MsCaseFlowSearchVO;
9
 import com.ruoyi.system.domain.vo.flow.MsCaseFlowSearchVO;
12
 import com.ruoyi.system.mapper.SysRoleMapper;
11
 import com.ruoyi.system.mapper.SysRoleMapper;
13
 import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
12
 import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
14
 import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper;
13
 import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper;
14
+import com.ruoyi.system.util.NewStringUtil;
15
+import com.ruoyi.system.util.TableDataUtil;
15
 import org.springframework.beans.BeanUtils;
16
 import org.springframework.beans.BeanUtils;
16
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.stereotype.Service;
18
 import org.springframework.stereotype.Service;
23
 import java.util.Map;
24
 import java.util.Map;
24
 import java.util.stream.Collectors;
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
 @Service
27
 @Service
31
 public class CaseFlowServiceImpl implements CaseFlowService {
28
 public class CaseFlowServiceImpl implements CaseFlowService {
32
     @Autowired
29
     @Autowired
48
         if (caseFlowSearchVO.getId() != null) {
45
         if (caseFlowSearchVO.getId() != null) {
49
             return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId());
46
             return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId());
50
         } else if (caseFlowSearchVO == null) {
47
         } else if (caseFlowSearchVO == null) {
48
+            //查询所有案件流程节点信息
51
             return msCaseFlowMapper.selectAll();
49
             return msCaseFlowMapper.selectAll();
52
         } else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) {
50
         } else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) {
51
+            //查询所有案件流程节点信息
53
             return msCaseFlowMapper.selectAll();
52
             return msCaseFlowMapper.selectAll();
54
         } else {
53
         } else {
54
+            //分页查询案件流程节点信息
55
             Map<Integer, List<SysRole>> sysRoleMap = queryRoleByFlowId(null);
55
             Map<Integer, List<SysRole>> sysRoleMap = queryRoleByFlowId(null);
56
             Example example = new Example(MsCaseFlow.class);
56
             Example example = new Example(MsCaseFlow.class);
57
             example.setOrderByClause(" sort DESC ");
57
             example.setOrderByClause(" sort DESC ");
62
             PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize());
62
             PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize());
63
             List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example);
63
             List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example);
64
             PageInfo<MsCaseFlow> pageInfo = new PageInfo<>(msCaseFlows);
64
             PageInfo<MsCaseFlow> pageInfo = new PageInfo<>(msCaseFlows);
65
-            PageInfo<MsCaseFlowVO> newpageInfo = new PageInfo<>();
66
-            BeanUtils.copyProperties(pageInfo, newpageInfo);
65
+            long total = pageInfo.getTotal();
67
             List<MsCaseFlowVO> list = new ArrayList<>();
66
             List<MsCaseFlowVO> list = new ArrayList<>();
68
             for (int i = 0; i < msCaseFlows.size(); i++) {
67
             for (int i = 0; i < msCaseFlows.size(); i++) {
69
                 MsCaseFlow msCaseFlow = msCaseFlows.get(i);
68
                 MsCaseFlow msCaseFlow = msCaseFlows.get(i);
70
                 MsCaseFlowVO temp = new MsCaseFlowVO();
69
                 MsCaseFlowVO temp = new MsCaseFlowVO();
71
                 BeanUtils.copyProperties(msCaseFlow, temp);
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
                 if (sysRoleMap.containsKey(msCaseFlow.getId())) {
74
                 if (sysRoleMap.containsKey(msCaseFlow.getId())) {
75
                     List<SysRole> sysRoles = sysRoleMap.get(msCaseFlow.getId());
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
                 if (msCaseFlow.getBackFlowId() != null) {
86
                 if (msCaseFlow.getBackFlowId() != null) {
84
                     MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId());
87
                     MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId());
86
                 }
89
                 }
87
                 list.add(temp);
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
      * @return
130
      * @return
127
      */
131
      */
128
     @Override
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
      */
202
      */
139
     @Override
203
     @Override
140
     public Boolean deleteCaseFlow(MsCaseFlowVO caseFlowVO) {
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
      * @return
221
      * @return
149
      */
222
      */
150
     @Override
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 Zobrazit soubor

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 Zobrazit soubor

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
+}