From 7fa7ef5fe1a289f77d753d0b18d69c08f905a596 Mon Sep 17 00:00:00 2001 From: lijiaqi Date: Fri, 14 Jul 2023 14:52:37 +0800 Subject: [PATCH] update --- .../oa/workFlow/data/dto/WorkFlowDto.java | 3 + .../oa/workFlow/data/entity/WorkFlow.java | 3 + .../ydool/oa/workFlow/data/vo/WorkFlowVo.java | 3 + .../data/wrapper/WorkFlowWrapper.java | 7 +- .../service/impl/BudgetWorkFlowService.java | 290 ++++++++++++++++-- .../service/impl/DrugWorkFlowService.java | 122 ++++++-- .../impl/FumigationWorkFlowService.java | 182 +++++++---- .../service/impl/LeaveWorkFlowService.java | 211 +++++++++---- .../service/impl/RepairWorkFlowService.java | 242 +++++++++------ .../service/impl/RotationWorkFlowService.java | 118 ++++--- .../oa/workFlow/service/WorkFlowService.java | 25 ++ 11 files changed, 899 insertions(+), 307 deletions(-) diff --git a/src/main/java/com/ydool/oa/workFlow/data/dto/WorkFlowDto.java b/src/main/java/com/ydool/oa/workFlow/data/dto/WorkFlowDto.java index d56ca6a..c17c5d2 100644 --- a/src/main/java/com/ydool/oa/workFlow/data/dto/WorkFlowDto.java +++ b/src/main/java/com/ydool/oa/workFlow/data/dto/WorkFlowDto.java @@ -45,4 +45,7 @@ public class WorkFlowDto extends WorkFlow { @ApiModelProperty(value = "是否能重新发起") private Boolean isReStart; + @ApiModelProperty(value = "是否能发起维修流程") + private Boolean isRepair; + } diff --git a/src/main/java/com/ydool/oa/workFlow/data/entity/WorkFlow.java b/src/main/java/com/ydool/oa/workFlow/data/entity/WorkFlow.java index 8d888d9..030af59 100644 --- a/src/main/java/com/ydool/oa/workFlow/data/entity/WorkFlow.java +++ b/src/main/java/com/ydool/oa/workFlow/data/entity/WorkFlow.java @@ -43,4 +43,7 @@ public class WorkFlow extends BaseEntity{ @ApiModelProperty(value = "状态") private String status; + @ApiModelProperty(value = "关联流程id") + private String workFlowId; + } diff --git a/src/main/java/com/ydool/oa/workFlow/data/vo/WorkFlowVo.java b/src/main/java/com/ydool/oa/workFlow/data/vo/WorkFlowVo.java index 172b78e..61300b4 100644 --- a/src/main/java/com/ydool/oa/workFlow/data/vo/WorkFlowVo.java +++ b/src/main/java/com/ydool/oa/workFlow/data/vo/WorkFlowVo.java @@ -17,4 +17,7 @@ public class WorkFlowVo { @ApiModelProperty(value = "表单数据") @NotBlank(message = "表单数据不能为空") private String data; + + @ApiModelProperty(value = "关联的预算流程id 用于维修决算 前提必须有预算申请并且通过") + private String workFlowId; } diff --git a/src/main/java/com/ydool/oa/workFlow/data/wrapper/WorkFlowWrapper.java b/src/main/java/com/ydool/oa/workFlow/data/wrapper/WorkFlowWrapper.java index 085f8c9..0590469 100644 --- a/src/main/java/com/ydool/oa/workFlow/data/wrapper/WorkFlowWrapper.java +++ b/src/main/java/com/ydool/oa/workFlow/data/wrapper/WorkFlowWrapper.java @@ -2,6 +2,7 @@ package com.ydool.oa.workFlow.data.wrapper; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.base.BaseWrapper; @@ -25,7 +26,6 @@ import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; -import java.util.ArrayList; import java.util.List; @Mapper @@ -88,6 +88,7 @@ public interface WorkFlowWrapper extends BaseWrapper { dto.setIsApprove(false); dto.setIsWrite(false); + dto.setIsRepair(false); if (count > 0 && WorkFlowStepTypeEnum.APPROVAL.getType().equals(obj.getStepType())) { dto.setIsApprove(true); @@ -97,5 +98,9 @@ public interface WorkFlowWrapper extends BaseWrapper { dto.setIsWrite(true); } + if (obj.getType().equals(WorkFlowTypeEnum.BUDGET.getType()) && obj.getStatus().equals(WorkFlowStatusEnum.PASS.getStatus()) && StrUtil.isBlank(obj.getWorkFlowId())) { + dto.setIsRepair(true); + } + } } diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/BudgetWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/BudgetWorkFlowService.java index 1ff0e61..5d1d461 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/BudgetWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/BudgetWorkFlowService.java @@ -1,8 +1,12 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -18,14 +22,19 @@ import com.ydool.oa.workFlow.service.WorkFlowService; import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; import com.ydool.system.entity.Config; +import com.ydool.system.entity.Dept; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Service public class BudgetWorkFlowService implements IWorkFlowType { @Autowired @@ -49,39 +58,100 @@ public class BudgetWorkFlowService implements IWorkFlowType { @Autowired private ConfigServiceImpl configService; + @Autowired + private RoleServiceImpl roleService; + + @Autowired + private DeptServiceImpl deptService; + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { + //是否维修上报角色 + User user = userService.getById(workFlow.getUserId()); + List roles = roleService.listByIds(Arrays.asList(user.getRoles().split(","))); + List roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); + if (!roleNames.contains("维修上报")) throw new ResultException("您不是维修上报人员"); + + Dept dept = deptService.getById(user.getDept()); + if (ObjUtil.isNull(dept)) throw new ResultException("您没有部门"); // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到领导账号 - Config leadership = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "leadership") - .last("limit 1") - ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User leadershipUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, leadership.getParamValue()) - .last("limit 1") + // 2.通知部门或库点负责人账号 + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "部门负责人") + .last("limit 1")); + String type = JSONUtil.parseObj(workFlow.getData()).getStr("type"); + List nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, user.getDept()) + .like(User::getRoles, role.getId()) ); + if (CollUtil.isNotEmpty(nextUserList) && "1".equals(type)) { + //找到沈总账号 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") + .last("limit 1") + ); + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) + .last("limit 1") + ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); + nextUserList = new ArrayList(); + nextUserList.add(adminUser); + } + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "库点负责人") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, user.getDept()) + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "总经理") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("未找到下一步审批人"); + } // 3.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - leadershipUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 4.通知领导账号 - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, leadershipUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + // 4.通知部门或库点负责人账号 + List nextWorkFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + nextWorkFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } } @@ -95,19 +165,184 @@ public class BudgetWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: // 2.1 预算申请第二步 领导账号审批 return second(vo, workFlow, workFlowStep); + case 3: + // 2.2 预算申请第三步 购销仓储部负责人审批 + return third(vo, workFlow, workFlowStep); + case 4: + // 2.3 预算申请第四步 沈总审批 + return fourth(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } - public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep){ + @Transactional(rollbackFor = Exception.class) + public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { + String type = JSONUtil.parseObj(workFlow.getData()).getStr("type"); + if ("1".equals(type)) { + // 1.流程环节进行变更 + workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); + workFlowStep.setRemarks(vo.getRemarks()); + boolean flag = workFlowStepService.updateById(workFlowStep); + // 2.记录流程环节日志 + WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(workFlowStepLog); + + // 3.流程完结 + workFlow.setStep(workFlow.getStep() + 1); + workFlow.setStepType(WorkFlowStepTypeEnum.END.getType()); + workFlow.setStatus(WorkFlowStatusEnum.PASS.getStatus()); + flag = workFlowService.updateById(workFlow); + + // 4.添加完结流程环节 + WorkFlowStep doneWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.END.getType(), + StpUtil.getLoginIdAsString(), WorkFlowStepStatusEnum.DONE.getStatus(), ""); + flag = workFlowStepService.save(doneWorkFlowStep); + + // 5.记录完结流程环节日志 + WorkFlowStepLog doneWorkFlowStepLog = new WorkFlowStepLog(doneWorkFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(doneWorkFlowStepLog); + + + // 6.通知发起人账号 + String title = + "您的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "已通过审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); + flag = workFlowNoticeService.save(workFlowNotice); + + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } + } else { + User user = userService.getById(workFlow.getUserId()); + // 1.流程环节进行变更 + workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); + workFlowStep.setRemarks(vo.getRemarks()); + boolean flag = workFlowStepService.updateById(workFlowStep); + + // 2.记录流程环节日志 + WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(workFlowStepLog); + + // 3.流程step+1 进入下一步 + workFlow.setStep(workFlow.getStep() + 1); + workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); + workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); + flag = workFlowService.updateById(workFlow); + + // 4.找到购销仓储部负责人审批 + Dept dept = deptService.getOne(new QueryWrapper().lambda() + .eq(Dept::getName, "购销仓储部") + .last("limit 1") + ); + if (ObjUtil.isNull(dept)) { + throw new ResultException("购销仓储部不存在"); + } + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "部门负责人") + .last("limit 1") + ); + if (ObjUtil.isNull(role)) { + throw new ResultException("部门负责人角色不存在"); + } + List nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, dept.getId()) + .like(User::getRoles, role.getId()) + ); + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("购销仓储部负责人不存在"); + } + + // 5.添加下一步流程环节 + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); + + // 6.通知购销仓储部负责人 + List workFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + workFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(workFlowNoticeList); + + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } + } + } + + @Transactional(rollbackFor = Exception.class) + public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { + User user = userService.getById(workFlow.getUserId()); + // 1.流程环节进行变更 + workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); + workFlowStep.setRemarks(vo.getRemarks()); + boolean flag = workFlowStepService.updateById(workFlowStep); + + // 2.记录流程环节日志 + WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(workFlowStepLog); + + // 3.流程step+1 进入下一步 + workFlow.setStep(workFlow.getStep() + 1); + workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); + workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); + flag = workFlowService.updateById(workFlow); + + // 4.找到沈总审批 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") + .last("limit 1") + ); + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) + .last("limit 1") + ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); + + // 5.添加下一步流程环节 + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + adminUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + flag = workFlowStepService.save(nextWorkFlowStep); + + // 6.通知沈总账号 + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, adminUser.getId()); + flag = workFlowNoticeService.save(workFlowNotice); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } + } + + @Transactional(rollbackFor = Exception.class) + public AjaxResult fourth(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { // 1.流程环节进行变更 workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); workFlowStep.setRemarks(vo.getRemarks()); @@ -140,9 +375,14 @@ public class BudgetWorkFlowService implements IWorkFlowType { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } + @Override public String getName() { return "budget"; diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/DrugWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/DrugWorkFlowService.java index 44fb67b..de38a8c 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/DrugWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/DrugWorkFlowService.java @@ -1,8 +1,11 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -17,15 +20,19 @@ import com.ydool.oa.workFlow.service.WorkFlowNoticeService; import com.ydool.oa.workFlow.service.WorkFlowService; import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; -import com.ydool.system.entity.Config; +import com.ydool.system.entity.Dept; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Service public class DrugWorkFlowService implements IWorkFlowType { @Autowired @@ -49,39 +56,77 @@ public class DrugWorkFlowService implements IWorkFlowType { @Autowired private ConfigServiceImpl configService; + @Autowired + private RoleServiceImpl roleService; + + @Autowired + private DeptServiceImpl deptService; + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { + // 是否库点分管人(角色) + User user = userService.getById(workFlow.getUserId()); + List roles = roleService.listByIds(Arrays.asList(user.getRoles().split(","))); + List roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); + if (!roleNames.contains("库点分管人")) { + throw new ResultException("您不是库点分管人,无法发起流程"); + } + // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到保管人账号 - Config keeper = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "keeper") + // 2.找到购销仓储部负责人审批 + Dept dept = deptService.getOne(new QueryWrapper().lambda() + .eq(Dept::getName, "购销仓储部") .last("limit 1") ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User keeperUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, keeper.getParamValue()) + if (ObjUtil.isNull(dept)) { + throw new ResultException("购销仓储部不存在"); + } + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "部门负责人") .last("limit 1") ); + if (ObjUtil.isNull(role)) { + throw new ResultException("部门负责人角色不存在"); + } + List nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, dept.getId()) + .like(User::getRoles, role.getId()) + ); + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("购销仓储部负责人不存在"); + } // 3.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - keeperUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 4.通知保管人账号 - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, keeperUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + // 4.通知购销仓储部负责人 + List workFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + workFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(workFlowNoticeList); - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } } @@ -95,17 +140,19 @@ public class DrugWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: - // 2.1 药剂领用第二步 保管人账号审批 + // 2.1 药剂领用第二步 购销仓储部负责人审批 return second(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } + @Transactional(rollbackFor = Exception.class) public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep){ // 1.流程环节进行变更 @@ -140,7 +187,36 @@ public class DrugWorkFlowService implements IWorkFlowType { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + // 7.通知药剂保管人 + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "药剂保管人") + .last("limit 1") + ); + if (ObjUtil.isNull(role)) { + throw new ResultException("药剂保管人角色不存在"); + } + List nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, role.getId()) + ); + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("药剂保管人不存在"); + } + List nextWorkFlowNoticeList = new ArrayList(); + User user = userService.getById(workFlow.getUserId()); + for (User nextUser : nextUserList) { + title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "审批通过,请您进行药剂发放"; + WorkFlowNotice nextWorkFlowNotice = new WorkFlowNotice(title, workFlow, nextUser.getId()); + nextWorkFlowNoticeList.add(nextWorkFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); + + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @Override diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/FumigationWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/FumigationWorkFlowService.java index bbac2c3..e3b777c 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/FumigationWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/FumigationWorkFlowService.java @@ -1,8 +1,11 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -19,18 +22,17 @@ import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; import com.ydool.system.entity.Config; import com.ydool.system.entity.Dept; -import com.ydool.system.entity.Job; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.DeptServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; @Service public class FumigationWorkFlowService implements IWorkFlowType { @@ -58,40 +60,67 @@ public class FumigationWorkFlowService implements IWorkFlowType { @Autowired private DeptServiceImpl deptService; + @Autowired + private RoleServiceImpl roleService; + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { + //是否库管员 + User user = userService.getById(workFlow.getUserId()); + List roles = roleService.listByIds(Arrays.asList(user.getRoles().split(","))); + List roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); + if (!roleNames.contains("库管员")) { + throw new ResultException("您不是库管员,无法发起流程"); + } + // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到库点负责人账号 - Job libraryPointManager = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "library_point_manager") + // 2.找到库点分管人账号 + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "库点分管人") .last("limit 1") ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User libraryPointManagerUser = userService.getOne(new QueryWrapper().lambda() + if (ObjUtil.isEmpty(role)) { + throw new ResultException("未找到库点分管人角色"); + } + List nextUserList = userService.list(new QueryWrapper().lambda() .eq(User::getDept, user.getDept()) - .eq(User::getJob, libraryPointManager.getId()) - .last("limit 1") + .like(User::getRoles, role.getId()) ); + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("未找到库点分管人"); + } // 3.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - libraryPointManagerUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 4.通知库点负责人账号 - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, libraryPointManagerUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + // 4.通知库点分管人账号 + List nextWorkFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice nextWorkFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + nextWorkFlowNoticeList.add(nextWorkFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } } @Override @@ -104,23 +133,24 @@ public class FumigationWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: - // 2.1 熏蒸申报第二步 库点负责人账号审批 + // 2.1 熏蒸申报第二步 库点分管人(角色)审批 return second(vo, workFlow, workFlowStep); case 3: - // 2.2 熏蒸申报第三步 业务科部门的人员账号审批 + // 2.2 熏蒸申报第三步 购销仓储部负责人审批 return third(vo, workFlow, workFlowStep); case 4: - // 2.3 熏蒸申报第四步 分管负责人账号审批 + // 2.3 熏蒸申报第四步 沈总审批 return fourth(vo, workFlow, workFlowStep); case 5: - // 2.3 熏蒸申报第五步 粮食科部门的人员账号审批 + // 2.3 熏蒸申报第五步 粮食与物资管理科(角色)审批 return fifth(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } @@ -141,43 +171,56 @@ public class FumigationWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); flag = workFlowService.updateById(workFlow); - // 4.找到业务科部门的人员账号 - Dept businessDept = deptService.getOne(new QueryWrapper().lambda() - .eq(Dept::getName, "综合管理部") + // 4.找到购销仓储部负责人 + Dept dept = deptService.getOne(new QueryWrapper().lambda() + .eq(Dept::getName, "购销仓储部") .last("limit 1") ); - Job businessJob = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "business_dept") + if (ObjUtil.isNull(dept)) { + throw new ResultException("购销仓储部不存在"); + } + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "部门负责人") .last("limit 1") ); - List businessDeptUserList = userService.list(new QueryWrapper().lambda() - .eq(User::getDept, businessDept.getId()) - .eq(User::getJob, businessJob.getId()) + if (ObjUtil.isNull(role)) { + throw new ResultException("部门负责人角色不存在"); + } + List nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, dept.getId()) + .like(User::getRoles, role.getId()) ); + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("购销仓储部负责人不存在"); + } // 5.添加下一步流程环节 List nextWorkFlowStepList = new ArrayList(); - businessDeptUserList.forEach(businessDeptUser -> { + nextUserList.forEach(businessDeptUser -> { WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), businessDeptUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); nextWorkFlowStepList.add(nextWorkFlowStep); }); flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 6.通知业务科部门的人员账号 + // 6.通知购销仓储部负责人 User user = userService.getById(workFlow.getUserId()); String title = user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "待您审批"; List workFlowNoticeList = new ArrayList(); - businessDeptUserList.forEach(businessDeptUser -> { + nextUserList.forEach(businessDeptUser -> { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, businessDeptUser.getId()); workFlowNoticeList.add(workFlowNotice); }); flag = workFlowNoticeService.saveBatch(workFlowNoticeList); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @Transactional(rollbackFor = Exception.class) @@ -197,30 +240,37 @@ public class FumigationWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); flag = workFlowService.updateById(workFlow); - // 4.找到分管负责人账号 - Config responsiblePerson = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "responsible.person") + // 4.找到沈总账号 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") .last("limit 1") ); - User responsiblePersonUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, responsiblePerson.getParamValue()) + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) .last("limit 1") ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); // 5.添加下一步流程环节 WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - responsiblePersonUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + adminUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); flag = workFlowStepService.save(nextWorkFlowStep); - // 6.通知分管负责人账号 + // 6.通知沈总账号 User user = userService.getById(workFlow.getUserId()); String title = user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, responsiblePersonUser.getId()); + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, adminUser.getId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @Transactional(rollbackFor = Exception.class) @@ -240,43 +290,45 @@ public class FumigationWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); flag = workFlowService.updateById(workFlow); - // 4.找到粮食科部门的人员账号 - Dept grainDept = deptService.getOne(new QueryWrapper().lambda() - .eq(Dept::getName, "综合管理部") + // 4.找到粮食与物资管理科(角色) + Role nextRole = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "粮食与物资管理科") .last("limit 1") ); - Job grainJob = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "grain_dept") - .last("limit 1") - ); - List grainDeptUserList = userService.list(new QueryWrapper().lambda() - .eq(User::getDept, grainDept.getId()) - .eq(User::getJob, grainJob.getId()) + if (ObjUtil.isNull(nextRole)) throw new ResultException("系统未配置粮食与物资管理科角色"); + + List nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, nextRole.getId()) ); + if (CollUtil.isEmpty(nextUserList)) throw new ResultException("系统未配置粮食与物资管理科账号"); // 5.添加下一步流程环节 List nextWorkFlowStepList = new ArrayList(); - grainDeptUserList.forEach(grainDeptUser -> { + nextUserList.forEach(grainDeptUser -> { WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), grainDeptUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); nextWorkFlowStepList.add(nextWorkFlowStep); }); flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 6.通知粮食科部门的人员账号 + // 6.通知粮食与物资管理科(角色) User user = userService.getById(workFlow.getUserId()); String title = user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "待您审批"; List workFlowNoticeList = new ArrayList(); - grainDeptUserList.forEach(grainDeptUser -> { + nextUserList.forEach(grainDeptUser -> { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, grainDeptUser.getId()); workFlowNoticeList.add(workFlowNotice); }); flag = workFlowNoticeService.saveBatch(workFlowNoticeList); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @@ -314,7 +366,11 @@ public class FumigationWorkFlowService implements IWorkFlowType { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @Override public String getName() { diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/LeaveWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/LeaveWorkFlowService.java index e4e537a..78f4c31 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/LeaveWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/LeaveWorkFlowService.java @@ -1,8 +1,12 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -18,15 +22,16 @@ import com.ydool.oa.workFlow.service.WorkFlowService; import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; import com.ydool.system.entity.Config; -import com.ydool.system.entity.Job; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @Service public class LeaveWorkFlowService implements IWorkFlowType { @@ -51,41 +56,78 @@ public class LeaveWorkFlowService implements IWorkFlowType { @Autowired private ConfigServiceImpl configService; + @Autowired + private DeptServiceImpl deptService; + + @Autowired + private RoleServiceImpl roleService; + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { - + User user = userService.getById(StpUtil.getLoginIdAsString()); // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到上级领导账号 - Job superior = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "superior") - .last("limit 1") - ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User superiorUser = userService.getOne(new QueryWrapper().lambda() + // 2.找到部门或库点负责人审批 + + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "部门负责人") + .last("limit 1")); + List nextUserList = userService.list(new QueryWrapper().lambda() .eq(User::getDept, user.getDept()) - .eq(User::getJob, superior.getId()) - .last("limit 1") + .like(User::getRoles, role.getId()) ); + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "库点负责人") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, user.getDept()) + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "总经理") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("未找到下一步审批人"); + } + // 3.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - superiorUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 4.通知上级领导账号 - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, superiorUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + // 4.通知部门或库点负责人账号 + List nextWorkFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + nextWorkFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } } @@ -100,64 +142,113 @@ public class LeaveWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: - // 2.1 请假流程第二步 上级领导账号审批 + // 2.1 请假流程第二步 上级领导账号审批或直接结束 return second(vo, workFlow, workFlowStep); case 3: - // 2.2 请假流程第三步 总经理账号审批 + // 2.2 请假流程第三步 沈总账号审批 return third(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } @Transactional(rollbackFor = Exception.class) public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { - // 1.流程环节进行变更 - workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); - workFlowStep.setRemarks(vo.getRemarks()); - boolean flag = workFlowStepService.updateById(workFlowStep); + String data = workFlow.getData(); + String type = JSONUtil.parseObj(data).getStr("type"); + if ("1".equals(type)) { - // 2.记录流程环节日志 - WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); - flag = workFlowStepLogService.save(workFlowStepLog); + // 1.流程环节进行变更 + workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); + workFlowStep.setRemarks(vo.getRemarks()); + boolean flag = workFlowStepService.updateById(workFlowStep); - // 3.流程step+1 进入下一步 - workFlow.setStep(workFlow.getStep() + 1); - workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); - workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); - flag = workFlowService.updateById(workFlow); + // 2.记录流程环节日志 + WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(workFlowStepLog); - // 4.找到总经理账号 - Config generalManager = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "general.manager") - .last("limit 1") - ); - User generalManagerUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, generalManager.getParamValue()) - .last("limit 1") - ); + // 3.流程完结 + workFlow.setStep(workFlow.getStep() + 1); + workFlow.setStepType(WorkFlowStepTypeEnum.END.getType()); + workFlow.setStatus(WorkFlowStatusEnum.PASS.getStatus()); + flag = workFlowService.updateById(workFlow); - // 5.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - generalManagerUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + // 4.添加完结流程环节 + WorkFlowStep doneWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.END.getType(), + StpUtil.getLoginIdAsString(), WorkFlowStepStatusEnum.DONE.getStatus(), ""); + flag = workFlowStepService.save(doneWorkFlowStep); - // 6.通知总经理账号 - User user = userService.getById(workFlow.getUserId()); - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, generalManagerUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + // 5.记录完结流程环节日志 + WorkFlowStepLog doneWorkFlowStepLog = new WorkFlowStepLog(doneWorkFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(doneWorkFlowStepLog); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + + // 6.通知发起人账号 + String title = + "您的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "已通过审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); + flag = workFlowNoticeService.save(workFlowNotice); + + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } + } else { + + // 1.流程环节进行变更 + workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); + workFlowStep.setRemarks(vo.getRemarks()); + boolean flag = workFlowStepService.updateById(workFlowStep); + + // 2.记录流程环节日志 + WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); + flag = workFlowStepLogService.save(workFlowStepLog); + + // 3.流程step+1 进入下一步 + workFlow.setStep(workFlow.getStep() + 1); + workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); + workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); + flag = workFlowService.updateById(workFlow); + + // 4.找到沈总账号 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") + .last("limit 1") + ); + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) + .last("limit 1") + ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); + + // 5.添加下一步流程环节 + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + adminUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + flag = workFlowStepService.save(nextWorkFlowStep); + + // 6.通知沈总账号 + User user = userService.getById(workFlow.getUserId()); + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, adminUser.getId()); + flag = workFlowNoticeService.save(workFlowNotice); + + return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + } } + @Transactional(rollbackFor = Exception.class) public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep){ // 1.流程环节进行变更 diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RepairWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RepairWorkFlowService.java index 2f5dc7f..04e386d 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RepairWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RepairWorkFlowService.java @@ -1,8 +1,11 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -19,18 +22,17 @@ import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; import com.ydool.system.entity.Config; import com.ydool.system.entity.Dept; -import com.ydool.system.entity.Job; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.DeptServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; @Service public class RepairWorkFlowService implements IWorkFlowType { @@ -55,43 +57,90 @@ public class RepairWorkFlowService implements IWorkFlowType { @Autowired private ConfigServiceImpl configService; + @Autowired + private RoleServiceImpl roleService; + @Autowired private DeptServiceImpl deptService; @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { + //是否维修上报角色 + User user = userService.getById(workFlow.getUserId()); + List roles = roleService.listByIds(Arrays.asList(user.getRoles().split(","))); + List roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); + if (!roleNames.contains("维修上报")) throw new ResultException("您不是维修上报人员"); + + Dept dept = deptService.getById(user.getDept()); + if (ObjUtil.isNull(dept)) throw new ResultException("您没有部门"); + // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到库点负责人账号 - Job libraryPointManager = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "library_point_manager") - .last("limit 1") - ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User libraryPointManagerUser = userService.getOne(new QueryWrapper().lambda() + // 2.找到部门或库点负责人审批 + + Role role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "部门负责人") + .last("limit 1")); + List nextUserList = userService.list(new QueryWrapper().lambda() .eq(User::getDept, user.getDept()) - .eq(User::getJob, libraryPointManager.getId()) - .last("limit 1") + .like(User::getRoles, role.getId()) ); + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "库点负责人") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .eq(User::getDept, user.getDept()) + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + role = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getCode, "总经理") + .last("limit 1")); + nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, role.getId()) + ); + } + if (CollUtil.isEmpty(nextUserList)) { + throw new ResultException("未找到下一步审批人"); + } + // 3.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - libraryPointManagerUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 4.通知库点负责人账号 - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, libraryPointManagerUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); - - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + // 4.通知部门或库点负责人账号 + List nextWorkFlowNoticeList = new ArrayList(); + for (WorkFlowStep nextWorkFlowStep : nextWorkFlowStepList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextWorkFlowStep.getUserId()); + nextWorkFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); + // 更新关联的维修流程 + WorkFlow workFlow1 = workFlowService.getById(workFlow.getWorkFlowId()); + if (ObjUtil.isNull(workFlow1)) throw new ResultException("未找到流程"); + workFlow1.setWorkFlowId(workFlow.getId()); + flag = workFlowService.updateById(workFlow1); + if (flag) { + return AjaxResult.ok().msg("发起成功"); + } else { + throw new ResultException("发起失败"); + } } @Override @@ -104,81 +153,24 @@ public class RepairWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: - // 2.1维修决算申报第二步 库点负责人账号审批 + // 2.1维修决算申报第二步 部门或库点负责人审批审批 return second(vo, workFlow, workFlowStep); case 3: - // 2.2 维修决算申报第三步 业务科部门的人员账号审批 + // 2.2 维修决算申报第三步 沈总审批审批 return third(vo, workFlow, workFlowStep); - case 4: - // 2.3 维修决算申报第四步 分管负责人账号审批 - return fourth(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } @Transactional(rollbackFor = Exception.class) public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { - // 1.流程环节进行变更 - workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); - workFlowStep.setRemarks(vo.getRemarks()); - boolean flag = workFlowStepService.updateById(workFlowStep); - - // 2.记录流程环节日志 - WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); - flag = workFlowStepLogService.save(workFlowStepLog); - - // 3.流程step+1 进入下一步 - workFlow.setStep(workFlow.getStep() + 1); - workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); - workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); - flag = workFlowService.updateById(workFlow); - - // 4.找到业务科部门的人员账号 - Dept businessDept = deptService.getOne(new QueryWrapper().lambda() - .eq(Dept::getName, "综合管理部") - .last("limit 1") - ); - Job businessJob = jobService.getOne(new QueryWrapper().lambda() - .eq(Job::getCode, "business_dept") - .last("limit 1") - ); - List businessDeptUserList = userService.list(new QueryWrapper().lambda() - .eq(User::getDept, businessDept.getId()) - .eq(User::getJob, businessJob.getId()) - ); - - - // 5.添加下一步流程环节 - List nextWorkFlowStepList = new ArrayList(); - businessDeptUserList.forEach(businessDeptUser -> { - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - businessDeptUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - nextWorkFlowStepList.add(nextWorkFlowStep); - }); - flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - - // 6.通知业务科部门的人员账号 User user = userService.getById(workFlow.getUserId()); - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - List workFlowNoticeList = new ArrayList(); - businessDeptUserList.forEach(businessDeptUser -> { - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, businessDeptUser.getId()); - workFlowNoticeList.add(workFlowNotice); - }); - flag = workFlowNoticeService.saveBatch(workFlowNoticeList); - - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); - } - - @Transactional(rollbackFor = Exception.class) - public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { // 1.流程环节进行变更 workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); workFlowStep.setRemarks(vo.getRemarks()); @@ -194,34 +186,82 @@ public class RepairWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); flag = workFlowService.updateById(workFlow); - // 4.找到分管负责人账号 - Config responsiblePerson = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "responsible.person") + // 4.找到沈总账号 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") .last("limit 1") ); - User responsiblePersonUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, responsiblePerson.getParamValue()) + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) .last("limit 1") ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); // 5.添加下一步流程环节 WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - responsiblePersonUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + adminUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); flag = workFlowStepService.save(nextWorkFlowStep); - // 6.通知分管负责人账号 - User user = userService.getById(workFlow.getUserId()); + // 6.通知沈总账号 String title = user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, responsiblePersonUser.getId()); + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, adminUser.getId()); flag = workFlowNoticeService.save(workFlowNotice); - - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } +// @Transactional(rollbackFor = Exception.class) +// public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { +// // 1.流程环节进行变更 +// workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); +// workFlowStep.setRemarks(vo.getRemarks()); +// boolean flag = workFlowStepService.updateById(workFlowStep); +// +// // 2.记录流程环节日志 +// WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlowStep, workFlow.getData()); +// flag = workFlowStepLogService.save(workFlowStepLog); +// +// // 3.流程step+1 进入下一步 +// workFlow.setStep(workFlow.getStep() + 1); +// workFlow.setStepType(WorkFlowStepTypeEnum.APPROVAL.getType()); +// workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); +// flag = workFlowService.updateById(workFlow); +// +// // 4.找到分管负责人账号 +// Config responsiblePerson = configService.getOne(new QueryWrapper().lambda() +// .eq(Config::getParamKey, "responsible.person") +// .last("limit 1") +// ); +// User responsiblePersonUser = userService.getOne(new QueryWrapper().lambda() +// .eq(User::getLoginName, responsiblePerson.getParamValue()) +// .last("limit 1") +// ); +// +// // 5.添加下一步流程环节 +// WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), +// responsiblePersonUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); +// flag = workFlowStepService.save(nextWorkFlowStep); +// +// // 6.通知分管负责人账号 +// User user = userService.getById(workFlow.getUserId()); +// String title = +// user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + +// "待您审批"; +// WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, responsiblePersonUser.getId()); +// flag = workFlowNoticeService.save(workFlowNotice); +// +// return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); +// } + @Transactional(rollbackFor = Exception.class) - public AjaxResult fourth(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { + public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { // 1.流程环节进行变更 workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); workFlowStep.setRemarks(vo.getRemarks()); @@ -254,7 +294,11 @@ public class RepairWorkFlowService implements IWorkFlowType { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag) { + return AjaxResult.ok().msg("审批成功"); + } else { + throw new ResultException("审批失败"); + } } @Override diff --git a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RotationWorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RotationWorkFlowService.java index fa7291e..c4db0e7 100644 --- a/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RotationWorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/engine/service/impl/RotationWorkFlowService.java @@ -1,8 +1,11 @@ package com.ydool.oa.workFlow.engine.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; import com.ydool.oa.workFlow.data.entity.WorkFlowStep; @@ -18,14 +21,19 @@ import com.ydool.oa.workFlow.service.WorkFlowService; import com.ydool.oa.workFlow.service.WorkFlowStepLogService; import com.ydool.oa.workFlow.service.WorkFlowStepService; import com.ydool.system.entity.Config; +import com.ydool.system.entity.Dept; +import com.ydool.system.entity.Role; import com.ydool.system.entity.User; -import com.ydool.system.service.impl.ConfigServiceImpl; -import com.ydool.system.service.impl.JobServiceImpl; -import com.ydool.system.service.impl.UserServiceImpl; +import com.ydool.system.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Service public class RotationWorkFlowService implements IWorkFlowType { @Autowired @@ -49,9 +57,23 @@ public class RotationWorkFlowService implements IWorkFlowType { @Autowired private ConfigServiceImpl configService; + @Autowired + private RoleServiceImpl roleService; + + @Autowired + private DeptServiceImpl deptService; + @Override @Transactional(rollbackFor = Exception.class) public AjaxResult first(WorkFlow workFlow) { + User user = userService.getById(workFlow.getUserId()); + //是否购销仓储部负责人 + Dept dept = deptService.getById(user.getDept()); + List roles = roleService.listByIds(Arrays.asList(user.getRoles().split(","))); + List roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); + if (!("购销仓储部".equals(dept.getName()) && roleNames.contains("部门负责人"))) + throw new ResultException("您不是购销仓储部负责人,无法发起流程"); + // 1.流程step+1 workFlow.setStep(workFlow.getStep() + 1); @@ -59,30 +81,35 @@ public class RotationWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); boolean flag = workFlowService.updateById(workFlow); - // 2.找到公司账号 - Config company = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "company") + // 2.找到沈总账号 + Config admin = configService.getOne(new QueryWrapper().lambda() + .eq(Config::getParamKey, "sys.admin") .last("limit 1") ); - User user = userService.getById(StpUtil.getLoginIdAsString()); - User companyUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, company.getParamValue()) + if (ObjUtil.isNull(admin)) throw new ResultException("系统未配置沈总账号"); + + User adminUser = userService.getOne(new QueryWrapper().lambda() + .eq(User::getLoginName, admin.getParamValue()) .last("limit 1") ); + if (ObjUtil.isNull(adminUser)) throw new ResultException("系统未配置沈总账号"); // 3.添加下一步流程环节 WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - companyUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + adminUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); flag = workFlowStepService.save(nextWorkFlowStep); - // 4.通知公司账号 + // 4.通知沈总账号 String title = user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, companyUser.getId()); + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, adminUser.getId()); flag = workFlowNoticeService.save(workFlowNotice); - - return flag ? AjaxResult.ok().msg("发起成功") : AjaxResult.fail("发起失败"); + if (flag){ + return AjaxResult.ok().msg("发起成功"); + }else { + throw new ResultException("发起失败"); + } } @Override @@ -95,24 +122,25 @@ public class RotationWorkFlowService implements IWorkFlowType { .eq(WorkFlowStep::getUserId, StpUtil.getLoginIdAsString()) .last("limit 1") ); + if (ObjUtil.isNull(workFlowStep)) throw new ResultException("您不是当前流程环节执行人"); // 2.判断执行哪个方法 switch (workFlow.getStep()) { case 2: - // 2.1 轮换申报第二步 公司账号审批 + // 2.1 轮换申报第二步 沈总审批 return second(vo, workFlow, workFlowStep); case 3: - // 2.2 轮换申报第三步 发改局账号审批 + // 2.2 轮换申报第三步 粮食与物资管理科(角色)审批 return third(vo, workFlow, workFlowStep); default: - return AjaxResult.fail("流程环节错误"); + throw new ResultException("流程环节错误"); } } @Transactional(rollbackFor = Exception.class) public AjaxResult second(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { - + User user = userService.getById(workFlow.getUserId()); // 1.流程环节进行变更 workFlowStep.setStatus(WorkFlowStepStatusEnum.PASS.getStatus()); workFlowStep.setRemarks(vo.getRemarks()); @@ -128,32 +156,46 @@ public class RotationWorkFlowService implements IWorkFlowType { workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus()); flag = workFlowService.updateById(workFlow); - // 4.找到发改局账号 - Config developmentAndReformBureau = configService.getOne(new QueryWrapper().lambda() - .eq(Config::getParamKey, "development.and.reform.bureau") + // 4.找到粮食与物资管理科(角色) + Role nextRole = roleService.getOne(new QueryWrapper().lambda() + .eq(Role::getName, "粮食与物资管理科") .last("limit 1") ); - User developmentAndReformBureauUser = userService.getOne(new QueryWrapper().lambda() - .eq(User::getLoginName, developmentAndReformBureau.getParamValue()) - .last("limit 1") + if (ObjUtil.isNull(nextRole)) throw new ResultException("系统未配置粮食与物资管理科角色"); + + List nextUserList = userService.list(new QueryWrapper().lambda() + .like(User::getRoles, nextRole.getId()) ); // 5.添加下一步流程环节 - WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), - developmentAndReformBureauUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); - flag = workFlowStepService.save(nextWorkFlowStep); + if (CollUtil.isEmpty(nextUserList)) throw new ResultException("系统未配置粮食与物资管理科账号"); + List nextWorkFlowStepList = new ArrayList(); + for (User nextUser : nextUserList) { + WorkFlowStep nextWorkFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.APPROVAL.getType(), + nextUser.getId(), WorkFlowStepStatusEnum.NOT_START.getStatus(), ""); + nextWorkFlowStepList.add(nextWorkFlowStep); + } + flag = workFlowStepService.saveBatch(nextWorkFlowStepList); - // 6.通知发改局账号 - User user = userService.getById(workFlow.getUserId()); - String title = - user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + - "待您审批"; - WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, developmentAndReformBureauUser.getId()); - flag = workFlowNoticeService.save(workFlowNotice); + List nextWorkFlowNoticeList = new ArrayList(); + // 6.通知粮食与物资管理科(角色) + for (User nextUser : nextUserList) { + String title = + user.getUserName() + "的" + WorkFlowTypeEnum.valueOf(workFlow.getType().toUpperCase()).getName() + + "待您审批"; + WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, nextUser.getId()); + nextWorkFlowNoticeList.add(workFlowNotice); + } + flag = workFlowNoticeService.saveBatch(nextWorkFlowNoticeList); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag){ + return AjaxResult.ok().msg("审批成功"); + }else { + throw new ResultException("审批失败"); + } } + @Transactional(rollbackFor = Exception.class) public AjaxResult third(WorkFlowStepVo vo, WorkFlow workFlow, WorkFlowStep workFlowStep) { // 1.流程环节进行变更 @@ -188,7 +230,11 @@ public class RotationWorkFlowService implements IWorkFlowType { WorkFlowNotice workFlowNotice = new WorkFlowNotice(title, workFlow, workFlow.getUserId()); flag = workFlowNoticeService.save(workFlowNotice); - return flag ? AjaxResult.ok().msg("审批成功") : AjaxResult.fail("审批失败"); + if (flag){ + return AjaxResult.ok().msg("审批成功"); + }else { + throw new ResultException("审批失败"); + } } @Override diff --git a/src/main/java/com/ydool/oa/workFlow/service/WorkFlowService.java b/src/main/java/com/ydool/oa/workFlow/service/WorkFlowService.java index 40f4ed5..245e16e 100644 --- a/src/main/java/com/ydool/oa/workFlow/service/WorkFlowService.java +++ b/src/main/java/com/ydool/oa/workFlow/service/WorkFlowService.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ydool.common.base.BaseService; import com.ydool.common.data.dto.AjaxResult; +import com.ydool.common.exception.ResultException; import com.ydool.oa.workFlow.data.dto.WorkFlowCountDto; import com.ydool.oa.workFlow.data.entity.WorkFlow; import com.ydool.oa.workFlow.data.entity.WorkFlowNotice; @@ -69,6 +70,30 @@ public class WorkFlowService extends BaseService { @Transactional(rollbackFor = Exception.class) public AjaxResult start(WorkFlowVo vo) { + if (vo.getType().equals(WorkFlowTypeEnum.REPAIR.getType())) { + if (StrUtil.isBlank(vo.getWorkFlowId())) throw new ResultException("需要提交预算流程id"); + WorkFlow workFlow = getById(vo.getWorkFlowId()); + if (ObjectUtil.isNull(workFlow)) throw new ResultException("预算流程不存在"); + if (!workFlow.getStatus().equals(WorkFlowStatusEnum.PASS.getStatus())) + throw new ResultException("预算流程通过后才能发起维修流程"); + if (!StpUtil.getLoginIdAsString().equals(workFlow.getUserId())) + throw new ResultException("只能发起自己的预算流程的维修流程"); + if (StrUtil.isNotBlank(workFlow.getWorkFlowId())) { + int count = count(new QueryWrapper().lambda() + .eq(WorkFlow::getWorkFlowId, workFlow.getId()) + .eq(WorkFlow::getType, WorkFlowTypeEnum.REPAIR.getType()) + .eq(WorkFlow::getStatus, WorkFlowStatusEnum.PASS.getStatus()) + ); + if (count > 0) throw new ResultException("该预算流程已发起维修流程并且通过"); + count = count(new QueryWrapper().lambda() + .eq(WorkFlow::getWorkFlowId, workFlow.getId()) + .eq(WorkFlow::getType, WorkFlowTypeEnum.REPAIR.getType()) + .eq(WorkFlow::getStatus, WorkFlowStatusEnum.ACTIVE.getStatus()) + ); + if (count > 0) throw new ResultException("该预算流程已发起维修流程并且未结束"); + } + } + // 1.保存流程 WorkFlow workFlow = BeanUtil.copyProperties(vo, WorkFlow.class); workFlow.setUserId(StpUtil.getLoginIdAsString());