|
@@ -1,24 +1,33 @@
|
|
|
package com.aizuda.boot.modules.flw.service.impl;
|
|
|
|
|
|
+import com.aizuda.boot.modules.flw.entity.FlwProcessActor;
|
|
|
+import com.aizuda.boot.modules.flw.entity.FlwProcessCategory;
|
|
|
import com.aizuda.boot.modules.flw.entity.FlwProcessConfigure;
|
|
|
-import com.aizuda.boot.modules.flw.entity.FlwProcessSetting;
|
|
|
+import com.aizuda.boot.modules.flw.entity.FlwProcessPermission;
|
|
|
import com.aizuda.boot.modules.flw.entity.dto.FlwProcessActorDTO;
|
|
|
import com.aizuda.boot.modules.flw.entity.dto.FlwProcessDTO;
|
|
|
import com.aizuda.boot.modules.flw.entity.dto.FlwProcessPermissionDTO;
|
|
|
-import com.aizuda.boot.modules.flw.service.IFlwProcessActorService;
|
|
|
-import com.aizuda.boot.modules.flw.service.IFlwProcessConfigureService;
|
|
|
-import com.aizuda.boot.modules.flw.service.IFlwProcessPermissionService;
|
|
|
-import com.aizuda.boot.modules.flw.service.IFlwProcessService;
|
|
|
+import com.aizuda.boot.modules.flw.entity.vo.FlwProcessCategoryVO;
|
|
|
+import com.aizuda.boot.modules.flw.entity.vo.FlwProcessVO;
|
|
|
+import com.aizuda.boot.modules.flw.mapper.FlowlongMapper;
|
|
|
+import com.aizuda.boot.modules.flw.service.*;
|
|
|
import com.aizuda.core.api.ApiAssert;
|
|
|
+import com.aizuda.service.web.UserSession;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.flowlong.bpm.engine.core.mapper.FlwProcessMapper;
|
|
|
import com.flowlong.bpm.engine.entity.FlwProcess;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 流程分类 服务实现类
|
|
@@ -29,43 +38,181 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class FlwProcessServiceImpl extends ServiceImpl<FlwProcessMapper, FlwProcess> implements IFlwProcessService {
|
|
|
- private IFlwProcessActorService flwProcessActorService;
|
|
|
+ private IFlwProcessCategoryService flwProcessCategoryService;
|
|
|
private IFlwProcessPermissionService flwProcessPermissionService;
|
|
|
private IFlwProcessConfigureService flwProcessConfigureService;
|
|
|
+ private IFlwProcessActorService flwProcessActorService;
|
|
|
+ private FlowlongMapper flowlongMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FlwProcessCategoryVO> listCategoryAll(String keyword) {
|
|
|
+ List<FlwProcessCategoryVO> voList = new ArrayList<>();
|
|
|
+ List<FlwProcessCategory> categoryList = this.listProcessCategoryByKeyword();
|
|
|
+ // 全部查询
|
|
|
+ if (CollectionUtils.isNotEmpty(categoryList)) {
|
|
|
+ List<FlwProcessVO> flwProcessVOList = flowlongMapper.selectFlwProcessList();
|
|
|
+ if (null == keyword) {
|
|
|
+ // 不存在关键词查询
|
|
|
+ voList = categoryList.stream().map(t -> FlwProcessCategoryVO.of(t)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(flwProcessVOList)) {
|
|
|
+ voList.forEach(t -> t.setProcessList(flwProcessVOList.stream().filter(f -> Objects.equals(t.getCategoryId(), f.getCategoryId()))
|
|
|
+ .collect(Collectors.toList())));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 关键词查询
|
|
|
+ for (FlwProcessCategory category : categoryList) {
|
|
|
+ FlwProcessCategoryVO vo = FlwProcessCategoryVO.of(category);
|
|
|
+ List<FlwProcessVO> processList = flwProcessVOList.stream().filter(t -> Objects.equals(t.getCategoryId(), category.getId())
|
|
|
+ && t.getProcessName().contains(keyword)).collect(Collectors.toList());
|
|
|
+ if (category.getName().contains(keyword)) {
|
|
|
+ // 匹配分类名称
|
|
|
+ if (CollectionUtils.isEmpty(processList)) {
|
|
|
+ vo.setProcessList(flwProcessVOList.stream().filter(f -> Objects.equals(f.getCategoryId(), category.getId()))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ } else {
|
|
|
+ vo.setProcessList(processList);
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ } else if (CollectionUtils.isNotEmpty(processList)) {
|
|
|
+ // 匹配流程定义
|
|
|
+ vo.setProcessList(processList);
|
|
|
+ voList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 所有流程定义分类列表
|
|
|
+ */
|
|
|
+ protected List<FlwProcessCategory> listProcessCategoryByKeyword() {
|
|
|
+ LambdaQueryWrapper<FlwProcessCategory> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByDesc(FlwProcessCategory::getSort);
|
|
|
+ return flwProcessCategoryService.list(lqw);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public boolean save(FlwProcessDTO dto) {
|
|
|
+ public FlwProcessDTO getDtoById(Long id) {
|
|
|
+ FlwProcess flwProcess = this.checkById(id);
|
|
|
+ FlwProcessDTO dto = FlwProcessDTO.of(flwProcess);
|
|
|
+ // 流程参与者
|
|
|
+ List<FlwProcessActor> flwProcessActors = flwProcessActorService.getByProcessId(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(flwProcessActors)) {
|
|
|
+ dto.setProcessActorList(flwProcessActors.stream().map(t -> FlwProcessActorDTO.of(t)).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ // 流程权限
|
|
|
+ List<FlwProcessPermission> flwProcessPermissions = flwProcessPermissionService.getByProcessId(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(flwProcessPermissions)) {
|
|
|
+ dto.setProcessPermissionList(flwProcessPermissions.stream().map(t -> FlwProcessPermissionDTO.of(t)).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ // 流程配置
|
|
|
+ FlwProcessConfigure configure = flwProcessConfigureService.getByProcessId(id);
|
|
|
+ if (null != configure) {
|
|
|
+ dto.setCategoryId(configure.getCategoryId());
|
|
|
+ dto.setProcessSetting(configure.getProcessSetting());
|
|
|
+ dto.setProcessForm(configure.getProcessForm());
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public Long saveDto(FlwProcessDTO dto) {
|
|
|
+ ApiAssert.fail(null == dto.getCategoryId(), "流程定义分类ID不存在");
|
|
|
+ // 流程定义ID
|
|
|
+ Long processId = dto.getProcessId();
|
|
|
FlwProcess flwProcess = new FlwProcess();
|
|
|
flwProcess.setProcessName(dto.getProcessName());
|
|
|
flwProcess.setDisplayName(dto.getDisplayName());
|
|
|
flwProcess.setProcessIcon(dto.getProcessIcon());
|
|
|
flwProcess.setUseScope(dto.getUseScope());
|
|
|
flwProcess.setModelContent(dto.getModelContent());
|
|
|
- ApiAssert.fail(!super.save(flwProcess), "流程定义保存失败");
|
|
|
+ if (null == processId) {
|
|
|
+ // 设置创建者信息
|
|
|
+ UserSession userSession = UserSession.getLoginInfo();
|
|
|
+ flwProcess.setCreateId(String.valueOf(userSession.getId()));
|
|
|
+ flwProcess.setCreateBy(userSession.getUsername());
|
|
|
+ flwProcess.setCreateTime(new Date());
|
|
|
+ ApiAssert.fail(!super.save(flwProcess), "流程定义保存失败");
|
|
|
+ processId = flwProcess.getId();
|
|
|
+ } else {
|
|
|
+ flwProcess.setId(processId);
|
|
|
+ ApiAssert.fail(!super.updateById(flwProcess), "流程定义保存失败");
|
|
|
+ }
|
|
|
// 1,指定人员(谁可以提交该审批)
|
|
|
if (Objects.equals(1, dto.getUseScope())) {
|
|
|
List<FlwProcessActorDTO> processActorList = dto.getProcessActorList();
|
|
|
if (CollectionUtils.isNotEmpty(processActorList)) {
|
|
|
- ApiAssert.fail(!flwProcessActorService.saveProcessActors(flwProcess.getId(),
|
|
|
- processActorList), "流程定义指定提交人员保存失败");
|
|
|
+ ApiAssert.fail(!flwProcessActorService.saveProcessActors(processId, processActorList),
|
|
|
+ "流程定义指定提交人员保存失败");
|
|
|
}
|
|
|
}
|
|
|
// 流程定义权限
|
|
|
List<FlwProcessPermissionDTO> processPermissionList = dto.getProcessPermissionList();
|
|
|
if (CollectionUtils.isNotEmpty(processPermissionList)) {
|
|
|
- ApiAssert.fail(!flwProcessPermissionService.saveProcessPermissions(flwProcess.getId(),
|
|
|
- processPermissionList), "流程定义管理权限保存失败");
|
|
|
+ ApiAssert.fail(!flwProcessPermissionService.saveProcessPermissions(processId, processPermissionList),
|
|
|
+ "流程定义管理权限保存失败");
|
|
|
}
|
|
|
// 保存流程定义配置
|
|
|
- FlwProcessSetting processSetting = dto.getProcessSetting();
|
|
|
- if (null != processSetting) {
|
|
|
- FlwProcessConfigure fpc = new FlwProcessConfigure();
|
|
|
- fpc.setProcessId(flwProcess.getId());
|
|
|
- fpc.setCategoryId(dto.getCategoryId());
|
|
|
- fpc.setProcessSetting(processSetting);
|
|
|
- fpc.setProcessForm(dto.getProcessForm());
|
|
|
- ApiAssert.fail(!flwProcessConfigureService.save(fpc), "流程定义配置保存失败");
|
|
|
+ if (null != dto.getCategoryId()) {
|
|
|
+ ApiAssert.fail(!flwProcessConfigureService.saveByDto(processId, dto), "流程定义配置保存失败");
|
|
|
}
|
|
|
- return true;
|
|
|
+ return processId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public boolean removeProcessInfo(Long id) {
|
|
|
+ // 检查流程定义操作权限
|
|
|
+ this.checkOperateApproval(id);
|
|
|
+ // 删除相关流程定义信息
|
|
|
+ flwProcessActorService.removeByProcessId(id);
|
|
|
+ flwProcessPermissionService.removeByProcessId(id);
|
|
|
+ flwProcessConfigureService.removeByProcessId(id);
|
|
|
+ return super.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void checkOperateApproval(Long processId) {
|
|
|
+ UserSession userSession = UserSession.getLoginInfo();
|
|
|
+ if (null == userSession || !UserSession.isAdmin(userSession.getId())) {
|
|
|
+ FlwProcessPermission fpp = getFlwProcessPermissionByProcessId(processId);
|
|
|
+ ApiAssert.fail(null == fpp || !fpp.allowOperateApproval(), "无权限编辑操作审批流程");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected FlwProcessPermission getFlwProcessPermissionByProcessId(Long processId) {
|
|
|
+ UserSession userSession = UserSession.getLoginInfo();
|
|
|
+ return flwProcessPermissionService.getByUserIdAndProcessId(userSession.getId(), processId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateSortById(Long id, Integer sort) {
|
|
|
+ // 检查流程定义操作权限
|
|
|
+ this.checkOperateApproval(id);
|
|
|
+ // 更新流程定义排序
|
|
|
+ FlwProcess flwProcess = new FlwProcess();
|
|
|
+ flwProcess.setId(id);
|
|
|
+ flwProcess.setSort(sort);
|
|
|
+ return super.updateById(flwProcess);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateSateById(Long id, Integer state) {
|
|
|
+ // 检查流程定义操作权限
|
|
|
+ this.checkOperateApproval(id);
|
|
|
+ // 更新流程定义排序
|
|
|
+ FlwProcess flwProcess = new FlwProcess();
|
|
|
+ flwProcess.setId(id);
|
|
|
+ flwProcess.setProcessState(Objects.equals(1, state) ? 1 : 0);
|
|
|
+ return super.updateById(flwProcess);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean cloneById(Long id) {
|
|
|
+ FlwProcessDTO dto = this.getDtoById(id);
|
|
|
+ dto.setProcessId(null);
|
|
|
+ return null != this.saveDto(dto);
|
|
|
}
|
|
|
}
|