diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java index 1966e58..58b8015 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/flow/CaseFlowController.java @@ -25,17 +25,16 @@ public class CaseFlowController { * 查询案件流程节点信息 */ @PostMapping("/queryCaseFlowInfo") - public AjaxResult queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) { - Object obj = caseFlowService.queryCaseFlowInfo(caseFlowSearchVO); - return success(obj); + public Object queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) { + return caseFlowService.queryCaseFlowInfo(caseFlowSearchVO); } /** * 新增或编辑案件流程节点信息 */ @PostMapping("/saveCaseFlow") - public AjaxResult addCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) { - Boolean result = caseFlowService.addCaseFlow(caseFlowVO); + public AjaxResult saveCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) { + Boolean result = caseFlowService.saveCaseFlow(caseFlowVO); return success(result); } @@ -53,8 +52,8 @@ public class CaseFlowController { * 排序案件流程节点 */ @PostMapping("/sortCaseFlow") - public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) { - Boolean result = caseFlowService.sortCaseFlow(caseFlowVO); + public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) { + Boolean result = caseFlowService.sortCaseFlow(caseFlowSearchVO); return success(result); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java index b337f8c..73708c3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowSearchVO.java @@ -17,6 +17,14 @@ public class MsCaseFlowSearchVO { * 主键id */ private Integer id; + /** + * 排序类型0降序1升序 + */ + private Integer sortType; + /** + * 序号 + */ + private Integer sort; /** * 案件节点名称 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowVO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowVO.java index d1ba4ca..a468c9c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowVO.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/flow/MsCaseFlowVO.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @AllArgsConstructor @NoArgsConstructor @@ -41,5 +43,12 @@ public class MsCaseFlowVO { */ private Integer backFlowId; private String backFlowName; + /** + * 角色名称 + */ private String roleNames; + /** + * 角色id + */ + private List roleIds; } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowService.java index bf0c988..8f906d7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowService.java @@ -16,7 +16,7 @@ public interface CaseFlowService { * @param caseFlowVO * @return */ - Boolean addCaseFlow(MsCaseFlowVO caseFlowVO); + Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO); /** * 删除案件流程节点信息 @@ -27,8 +27,8 @@ public interface CaseFlowService { /** * 排序案件流程节点 - * @param caseFlowVO + * @param caseFlowSearchVO * @return */ - Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO); + Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowSearchVO); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java index 6b83abe..2bc0181 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java @@ -3,8 +3,7 @@ package com.ruoyi.system.service.flow; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.common.utils.PageUtils; -import com.ruoyi.system.domain.SysOperLog; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.system.domain.entity.flow.MsCaseFlow; import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated; import com.ruoyi.system.domain.vo.flow.MsCaseFlowSearchVO; @@ -12,6 +11,8 @@ import com.ruoyi.system.domain.vo.flow.MsCaseFlowVO; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.flow.MsCaseFlowMapper; import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper; +import com.ruoyi.system.util.NewStringUtil; +import com.ruoyi.system.util.TableDataUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -23,10 +24,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static com.deepoove.poi.data.NumberingRenderData.build; -import static com.ruoyi.common.utils.PageUtils.startPage; -import static jdk.nashorn.internal.runtime.Debug.id; - @Service public class CaseFlowServiceImpl implements CaseFlowService { @Autowired @@ -48,10 +45,13 @@ public class CaseFlowServiceImpl implements CaseFlowService { if (caseFlowSearchVO.getId() != null) { return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId()); } else if (caseFlowSearchVO == null) { + //查询所有案件流程节点信息 return msCaseFlowMapper.selectAll(); } else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) { + //查询所有案件流程节点信息 return msCaseFlowMapper.selectAll(); } else { + //分页查询案件流程节点信息 Map> sysRoleMap = queryRoleByFlowId(null); Example example = new Example(MsCaseFlow.class); example.setOrderByClause(" sort DESC "); @@ -62,23 +62,26 @@ public class CaseFlowServiceImpl implements CaseFlowService { PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize()); List msCaseFlows = msCaseFlowMapper.selectByExample(example); PageInfo pageInfo = new PageInfo<>(msCaseFlows); - PageInfo newpageInfo = new PageInfo<>(); - BeanUtils.copyProperties(pageInfo, newpageInfo); + long total = pageInfo.getTotal(); List list = new ArrayList<>(); for (int i = 0; i < msCaseFlows.size(); i++) { MsCaseFlow msCaseFlow = msCaseFlows.get(i); MsCaseFlowVO temp = new MsCaseFlowVO(); BeanUtils.copyProperties(msCaseFlow, temp); //关联的角色 - List roleNames = new ArrayList<>(); + StringBuilder roleNames = new StringBuilder(); + List roleIds = new ArrayList<>(); if (sysRoleMap.containsKey(msCaseFlow.getId())) { List sysRoles = sysRoleMap.get(msCaseFlow.getId()); - roleNames = sysRoles - .stream() - .map(sysRole -> sysRole.getRoleName()) - .collect(Collectors.toList()); - temp.setRoleNames(roleNames.toString()); + sysRoles.stream().forEach(item -> { + roleNames.append(item.getRoleName()).append(","); + }); + temp.setRoleNames(NewStringUtil.stringListToStringBuilder(sysRoles.stream().map(SysRole::getRoleName).collect(Collectors.toList()), ",")); + roleIds.addAll(sysRoles.stream().map(SysRole::getRoleId).collect(Collectors.toList())); + } else { + temp.setRoleNames(""); } + temp.setRoleIds(roleIds); //驳回节点 if (msCaseFlow.getBackFlowId() != null) { MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId()); @@ -86,7 +89,8 @@ public class CaseFlowServiceImpl implements CaseFlowService { } list.add(temp); } - return list; + TableDataInfo tableDataInfo = TableDataUtil.rebuildTableDataInfo(list, total); + return tableDataInfo; } } @@ -126,8 +130,68 @@ public class CaseFlowServiceImpl implements CaseFlowService { * @return */ @Override - public Boolean addCaseFlow(MsCaseFlowVO caseFlowVO) { - return null; + public Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO) { + if (caseFlowVO.getId() != null) { + //更新案件流程信息 + MsCaseFlow msCaseFlow = new MsCaseFlow(); + BeanUtils.copyProperties(caseFlowVO, msCaseFlow); + int i = msCaseFlowMapper.updateByPrimaryKey(msCaseFlow); + if (i > 0) { + //更新流程节点和角色之间的关系 + updateFlowRoleByFlowId(caseFlowVO.getId(), caseFlowVO.getRoleIds()); + return true; + } + } else { + int sort = 1; + Example example = new Example(MsCaseFlow.class); + example.setOrderByClause("sort DESC limit 1"); + Example.Criteria criteria = example.createCriteria(); + List msCaseFlows = msCaseFlowMapper.selectByExample(example); + if (msCaseFlows != null && msCaseFlows.size() > 0) { + sort = msCaseFlows.get(0).getSort() + 1; + } + //新增案件流程信息 + MsCaseFlow msCaseFlow = new MsCaseFlow(); + BeanUtils.copyProperties(caseFlowVO, msCaseFlow); + msCaseFlow.setSort(sort); + int insert = msCaseFlowMapper.insert(msCaseFlow); + if (insert > 0) { + //更新流程节点和角色之间的关系 + updateFlowRoleByFlowId(caseFlowVO.getId(), caseFlowVO.getRoleIds()); + return true; + } + } + return false; + } + + /** + * 更新流程节点和角色之间的关系 + * + * @param id + * @param roleIds + */ + private void updateFlowRoleByFlowId(Integer id, List roleIds) { + if (roleIds != null && roleIds.size() > 0) { + //删除流程节点和角色之间的关系 + deleteFlowRoleByFlowId(id); + for (int i = 0; i < roleIds.size(); i++) { + MsCaseFlowRoleRelated msCaseFlowRoleRelated = new MsCaseFlowRoleRelated(); + msCaseFlowRoleRelated.setFlowId(id); + msCaseFlowRoleRelated.setRoleid(roleIds.get(i)); + msCaseFlowRoleRelatedMapper.insertSelective(msCaseFlowRoleRelated); + } + } + } + + /** + * 删除流程节点和角色之间的关系 + * + * @param id + */ + private void deleteFlowRoleByFlowId(Integer id) { + if (id != null) { + msCaseFlowRoleRelatedMapper.deleteByExample(new Example(MsCaseFlowRoleRelated.class).createCriteria().andEqualTo("flowId", id)); + } } /** @@ -138,7 +202,16 @@ public class CaseFlowServiceImpl implements CaseFlowService { */ @Override public Boolean deleteCaseFlow(MsCaseFlowVO caseFlowVO) { - return null; + if (caseFlowVO.getId() != null) { + //删除案件流程信息 + int i = msCaseFlowMapper.deleteByPrimaryKey(caseFlowVO.getId()); + if (i > 0) { + //删除流程节点和角色之间的关系 + deleteFlowRoleByFlowId(caseFlowVO.getId()); + return true; + } + } + return false; } /** @@ -148,7 +221,17 @@ public class CaseFlowServiceImpl implements CaseFlowService { * @return */ @Override - public Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO) { - return null; + public Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowVO) { + if (caseFlowVO != null && caseFlowVO.getId() != null && caseFlowVO.getSortType() != null) { + if (caseFlowVO.getSortType() == 0) { + //降序 + + return true; + } else if (caseFlowVO.getSortType() == 1) { + //升序 + return true; + } + } + return false; } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/util/NewStringUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/util/NewStringUtil.java new file mode 100644 index 0000000..9f1abf6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/util/NewStringUtil.java @@ -0,0 +1,27 @@ +package com.ruoyi.system.util; + +import java.util.List; + +public class NewStringUtil { + /** + * 将字符串集合转换成字符串 + * + * @param list + * @param split + * @return + */ + public static String stringListToStringBuilder(List list, String split) { + if (list == null || list.size() == 0) { + return ""; + } else { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < list.size(); i++) { + sb.append(list.get(i)); + if (i != list.size() - 1) { + sb.append(split); + } + } + return sb.toString(); + } + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/util/TableDataUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/util/TableDataUtil.java new file mode 100644 index 0000000..e834a4d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/util/TableDataUtil.java @@ -0,0 +1,22 @@ +package com.ruoyi.system.util; + +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.core.page.TableDataInfo; + +import java.util.List; + +public class TableDataUtil { + /** + * 响应请求分页数据 + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + public static TableDataInfo rebuildTableDataInfo(List list, long total) { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(HttpStatus.SUCCESS); + rspData.setMsg("查询成功"); + rspData.setRows(list); + rspData.setTotal(total); + return rspData; + } + +}