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

This commit is contained in:
gy b
2024-01-09 14:13:25 +08:00
parent 9d7be2c16b
commit 4796b52963
7 changed files with 178 additions and 30 deletions
@@ -25,17 +25,16 @@ public class CaseFlowController {
* 查询案件流程节点信息 * 查询案件流程节点信息
*/ */
@PostMapping("/queryCaseFlowInfo") @PostMapping("/queryCaseFlowInfo")
public AjaxResult queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) { public Object queryCaseFlowInfo(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) {
Object obj = caseFlowService.queryCaseFlowInfo(caseFlowSearchVO); return caseFlowService.queryCaseFlowInfo(caseFlowSearchVO);
return success(obj);
} }
/** /**
* 新增或编辑案件流程节点信息 * 新增或编辑案件流程节点信息
*/ */
@PostMapping("/saveCaseFlow") @PostMapping("/saveCaseFlow")
public AjaxResult addCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) { public AjaxResult saveCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) {
Boolean result = caseFlowService.addCaseFlow(caseFlowVO); Boolean result = caseFlowService.saveCaseFlow(caseFlowVO);
return success(result); return success(result);
} }
@@ -53,8 +52,8 @@ public class CaseFlowController {
* 排序案件流程节点 * 排序案件流程节点
*/ */
@PostMapping("/sortCaseFlow") @PostMapping("/sortCaseFlow")
public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowVO caseFlowVO) { public AjaxResult sortCaseFlow(@RequestBody MsCaseFlowSearchVO caseFlowSearchVO) {
Boolean result = caseFlowService.sortCaseFlow(caseFlowVO); Boolean result = caseFlowService.sortCaseFlow(caseFlowSearchVO);
return success(result); return success(result);
} }
} }
@@ -17,6 +17,14 @@ public class MsCaseFlowSearchVO {
* 主键id * 主键id
*/ */
private Integer id; private Integer id;
/**
* 排序类型0降序1升序
*/
private Integer sortType;
/**
* 序号
*/
private Integer sort;
/** /**
* 案件节点名称 * 案件节点名称
@@ -5,6 +5,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@@ -41,5 +43,12 @@ public class MsCaseFlowVO {
*/ */
private Integer backFlowId; private Integer backFlowId;
private String backFlowName; private String backFlowName;
/**
* 角色名称
*/
private String roleNames; private String roleNames;
/**
* 角色id
*/
private List<Long> roleIds;
} }
@@ -16,7 +16,7 @@ public interface CaseFlowService {
* @param caseFlowVO * @param caseFlowVO
* @return * @return
*/ */
Boolean addCaseFlow(MsCaseFlowVO caseFlowVO); Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO);
/** /**
* 删除案件流程节点信息 * 删除案件流程节点信息
@@ -27,8 +27,8 @@ public interface CaseFlowService {
/** /**
* 排序案件流程节点 * 排序案件流程节点
* @param caseFlowVO * @param caseFlowSearchVO
* @return * @return
*/ */
Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO); Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowSearchVO);
} }
@@ -3,8 +3,7 @@ package com.ruoyi.system.service.flow;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysOperLog;
import com.ruoyi.system.domain.entity.flow.MsCaseFlow; import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated; import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated;
import com.ruoyi.system.domain.vo.flow.MsCaseFlowSearchVO; 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.SysRoleMapper;
import com.ruoyi.system.mapper.flow.MsCaseFlowMapper; import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper; 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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -23,10 +24,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; 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 @Service
public class CaseFlowServiceImpl implements CaseFlowService { public class CaseFlowServiceImpl implements CaseFlowService {
@Autowired @Autowired
@@ -48,10 +45,13 @@ public class CaseFlowServiceImpl implements CaseFlowService {
if (caseFlowSearchVO.getId() != null) { if (caseFlowSearchVO.getId() != null) {
return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId()); return msCaseFlowMapper.selectByPrimaryKey(caseFlowSearchVO.getId());
} else if (caseFlowSearchVO == null) { } else if (caseFlowSearchVO == null) {
//查询所有案件流程节点信息
return msCaseFlowMapper.selectAll(); return msCaseFlowMapper.selectAll();
} else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) { } else if (caseFlowSearchVO.getPageNum() == null || caseFlowSearchVO.getPageSize() == null) {
//查询所有案件流程节点信息
return msCaseFlowMapper.selectAll(); return msCaseFlowMapper.selectAll();
} else { } else {
//分页查询案件流程节点信息
Map<Integer, List<SysRole>> sysRoleMap = queryRoleByFlowId(null); Map<Integer, List<SysRole>> sysRoleMap = queryRoleByFlowId(null);
Example example = new Example(MsCaseFlow.class); Example example = new Example(MsCaseFlow.class);
example.setOrderByClause(" sort DESC "); example.setOrderByClause(" sort DESC ");
@@ -62,23 +62,26 @@ public class CaseFlowServiceImpl implements CaseFlowService {
PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize()); PageHelper.startPage(caseFlowSearchVO.getPageNum(), caseFlowSearchVO.getPageSize());
List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example); List<MsCaseFlow> msCaseFlows = msCaseFlowMapper.selectByExample(example);
PageInfo<MsCaseFlow> pageInfo = new PageInfo<>(msCaseFlows); PageInfo<MsCaseFlow> pageInfo = new PageInfo<>(msCaseFlows);
PageInfo<MsCaseFlowVO> newpageInfo = new PageInfo<>(); long total = pageInfo.getTotal();
BeanUtils.copyProperties(pageInfo, newpageInfo);
List<MsCaseFlowVO> list = new ArrayList<>(); List<MsCaseFlowVO> list = new ArrayList<>();
for (int i = 0; i < msCaseFlows.size(); i++) { for (int i = 0; i < msCaseFlows.size(); i++) {
MsCaseFlow msCaseFlow = msCaseFlows.get(i); MsCaseFlow msCaseFlow = msCaseFlows.get(i);
MsCaseFlowVO temp = new MsCaseFlowVO(); MsCaseFlowVO temp = new MsCaseFlowVO();
BeanUtils.copyProperties(msCaseFlow, temp); BeanUtils.copyProperties(msCaseFlow, temp);
//关联的角色 //关联的角色
List<String> roleNames = new ArrayList<>(); StringBuilder roleNames = new StringBuilder();
List<Long> roleIds = new ArrayList<>();
if (sysRoleMap.containsKey(msCaseFlow.getId())) { if (sysRoleMap.containsKey(msCaseFlow.getId())) {
List<SysRole> sysRoles = sysRoleMap.get(msCaseFlow.getId()); List<SysRole> sysRoles = sysRoleMap.get(msCaseFlow.getId());
roleNames = sysRoles sysRoles.stream().forEach(item -> {
.stream() roleNames.append(item.getRoleName()).append(",");
.map(sysRole -> sysRole.getRoleName()) });
.collect(Collectors.toList()); temp.setRoleNames(NewStringUtil.stringListToStringBuilder(sysRoles.stream().map(SysRole::getRoleName).collect(Collectors.toList()), ","));
temp.setRoleNames(roleNames.toString()); roleIds.addAll(sysRoles.stream().map(SysRole::getRoleId).collect(Collectors.toList()));
} else {
temp.setRoleNames("");
} }
temp.setRoleIds(roleIds);
//驳回节点 //驳回节点
if (msCaseFlow.getBackFlowId() != null) { if (msCaseFlow.getBackFlowId() != null) {
MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId()); MsCaseFlow msCaseFlow1 = msCaseFlowMapper.selectByPrimaryKey(msCaseFlow.getBackFlowId());
@@ -86,7 +89,8 @@ public class CaseFlowServiceImpl implements CaseFlowService {
} }
list.add(temp); list.add(temp);
} }
return list; TableDataInfo tableDataInfo = TableDataUtil.rebuildTableDataInfo(list, total);
return tableDataInfo;
} }
} }
@@ -126,8 +130,68 @@ public class CaseFlowServiceImpl implements CaseFlowService {
* @return * @return
*/ */
@Override @Override
public Boolean addCaseFlow(MsCaseFlowVO caseFlowVO) { public Boolean saveCaseFlow(MsCaseFlowVO caseFlowVO) {
return null; 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<MsCaseFlow> 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<Long> 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 @Override
public Boolean deleteCaseFlow(MsCaseFlowVO caseFlowVO) { 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 * @return
*/ */
@Override @Override
public Boolean sortCaseFlow(MsCaseFlowVO caseFlowVO) { public Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowVO) {
return null; if (caseFlowVO != null && caseFlowVO.getId() != null && caseFlowVO.getSortType() != null) {
if (caseFlowVO.getSortType() == 0) {
//降序
return true;
} else if (caseFlowVO.getSortType() == 1) {
//升序
return true;
}
}
return false;
} }
} }
@@ -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<String> 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();
}
}
}
@@ -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;
}
}