| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | | import org.jeecg.modules.tms.entity.ToolsLossBound; |
| | | import org.jeecg.modules.tms.entity.ToolsLossBoundDetail; |
| | | import org.jeecg.modules.tms.entity.dto.LossBoundFlowDto; |
| | | import org.jeecg.modules.tms.enums.OutBillStatus; |
| | | import org.jeecg.modules.tms.enums.OutBoundStatusEnum; |
| | | import org.jeecg.modules.tms.mapper.ToolsLossBoundDetailMapper; |
| | | import org.jeecg.modules.tms.mapper.ToolsLossBoundMapper; |
| | | import org.jeecg.modules.tms.service.IToolsLossBoundDetailService; |
| | |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Override |
| | | public void delMain(String id) { |
| | |
| | | @Override |
| | | public void addTotal(ToolsLossBound toolsLossBound) { |
| | | LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (loginUser != null){ |
| | | toolsLossBound.setHandler(loginUser.getId()); |
| | | } |
| | | if (loginUser != null) { |
| | | toolsLossBound.setHandler(loginUser.getId()); |
| | | } |
| | | toolsLossBound.setOrderCode(businessCodeRuleService.generateBusinessCodeSeq("LossBound")); |
| | | toolsLossBound.setOrderStatus(OutBillStatus.DRAFT.getValue()); |
| | | save(toolsLossBound); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void approvalProcess(LossBoundFlowDto lossBoundFlowDto) { |
| | | if (StrUtil.isBlank(lossBoundFlowDto.getTaskId()) || StrUtil.isBlank(lossBoundFlowDto.getDataId())) { |
| | | throw new JeecgBootException("非法参数!"); |
| | | } |
| | | |
| | | // 获取当前登录用户 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("账号不存在"); |
| | | } |
| | | |
| | | //获取报损单信息 |
| | | ToolsLossBound toolsLossBound = getById(lossBoundFlowDto.getDataId()); |
| | | if (toolsLossBound == null) { |
| | | throw new JeecgBootException("未找到对应的出库申请单!"); |
| | | } |
| | | |
| | | //获取流程业务记录 |
| | | FlowMyBusiness flowMyBusiness = getFlowMyBusiness(lossBoundFlowDto.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("流程记录不存在"); |
| | | } |
| | | |
| | | // 检查用户是否有权限操作任务 |
| | | if (!isUserAuthorized(flowMyBusiness, user)) { |
| | | throw new JeecgBootException("用户无权操作此任务"); |
| | | } |
| | | |
| | | // 认领任务 |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("任务不存在、已完成或已被他人认领"); |
| | | } |
| | | |
| | | //设置流程变量 |
| | | setupProcessVariables(lossBoundFlowDto, toolsLossBound, user); |
| | | |
| | | //完成流程任务 |
| | | Result result = flowTaskService.complete(lossBoundFlowDto); |
| | | |
| | | //根据任务完成结果更新申请单状态 |
| | | if (result.isSuccess()) { |
| | | toolsLossBound.setOrderStatus(lossBoundFlowDto.getStatus()); |
| | | if (OutBillStatus.APPROVED.getValue().equals(lossBoundFlowDto.getStatus())) { |
| | | toolsLossBound.setOrderStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue()); |
| | | } |
| | | toolsLossBound.setApprovalDate(new Date()); |
| | | toolsLossBound.setApprovalOpinion(lossBoundFlowDto.getApprovalOpinion()); |
| | | updateById(toolsLossBound); |
| | | } |
| | | } |
| | | |
| | | private void setupProcessVariables(LossBoundFlowDto lossBoundFlowDto, ToolsLossBound toolsLossBound, LoginUser user) { |
| | | if (OutBillStatus.SUBMITTED.getValue().equals(toolsLossBound.getOrderStatus()) && user.getUsername().equals(toolsLossBound.getReviewer())) { |
| | | Map<String, Object> values = new HashMap<>(); |
| | | values.put("dataId", toolsLossBound.getId()); |
| | | values.put("organization", lossBoundFlowDto.getApprovalOpinion()); |
| | | values.put("comment", lossBoundFlowDto.getApprovalOpinion()); |
| | | values.put("status", lossBoundFlowDto.getStatus()); |
| | | values.put("NextAssignee", Collections.singletonList(toolsLossBound.getReviewer())); |
| | | lossBoundFlowDto.setValues(values); |
| | | } |
| | | } |
| | | |
| | | private FlowMyBusiness getFlowMyBusiness(String instanceId) { |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new LambdaQueryWrapper<FlowMyBusiness>().eq(FlowMyBusiness::getProcessInstanceId, instanceId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |
| | | private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | return todoUsers != null && todoUsers.contains(user.getUsername()); |
| | | } |
| | | |
| | | private boolean claimTask(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return false; |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return false; |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//接下来审批的节点 |
| | | business.getValues();//前端传进来的参数 |