| | |
| | | package com.vincent.rsf.server.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.vincent.rsf.server.manager.entity.Task; |
| | | import com.vincent.rsf.server.manager.service.TaskService; |
| | | import com.vincent.rsf.server.system.entity.FlowInstance; |
| | | import com.vincent.rsf.server.system.mapper.FlowStepInstanceMapper; |
| | | import com.vincent.rsf.server.system.entity.FlowStepInstance; |
| | | import com.vincent.rsf.server.system.service.FlowInstanceService; |
| | | import com.vincent.rsf.server.system.service.FlowStepInstanceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Service("flowStepInstanceService") |
| | | public class FlowStepInstanceServiceImpl extends ServiceImpl<FlowStepInstanceMapper, FlowStepInstance> implements FlowStepInstanceService { |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean jumpCurrent(Long id) { |
| | | try{ |
| | | FlowStepInstance flowStepInstance = getById(id); |
| | | if (flowStepInstance == null || flowStepInstance.getFlowInstanceId() == null) { |
| | | return false; |
| | | } |
| | | Date now = new Date(); |
| | | String taskNo = flowStepInstance.getTaskNo(); |
| | | Task one = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskCode, taskNo)); |
| | | |
| | | //检测当前步骤 |
| | | FlowStepInstance flowStepInstanceNow = getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getWmsNowTaskStatus, one.getTaskStatus()) |
| | | .eq(FlowStepInstance::getTaskNo, taskNo) |
| | | .eq(FlowStepInstance::getFlowInstanceNo, flowStepInstance.getFlowInstanceNo()) |
| | | .ge(FlowStepInstance::getStatus, (short) 1) |
| | | .ne(FlowStepInstance::getStatus, (short) 3).last("limit 1")); |
| | | if (flowStepInstanceNow == null) { |
| | | return false; |
| | | } |
| | | int stepOrderDifference = flowStepInstanceNow.getStepOrder() - flowStepInstance.getStepOrder(); |
| | | if (stepOrderDifference>0) {//回退 |
| | | for (int i = 1; i <= stepOrderDifference; i++) { |
| | | FlowStepInstance flowStepInstanceUpdate = getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getTaskNo, taskNo) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder()+i) |
| | | .eq(FlowStepInstance::getFlowInstanceNo, flowStepInstance.getFlowInstanceNo()) |
| | | .last("limit 1")); |
| | | if (flowStepInstanceUpdate==null) { |
| | | return false; |
| | | } |
| | | flowStepInstanceUpdate.setStatus((short)0); |
| | | flowStepInstanceUpdate.setErrorMessage(flowStepInstanceUpdate.getErrorMessage()+now+"人工调整;"); |
| | | flowStepInstanceUpdate.setErrorCode(now.toString()); |
| | | flowStepInstanceUpdate.setUpdateTime(now); |
| | | updateById(flowStepInstanceUpdate); |
| | | } |
| | | } else if (stepOrderDifference<0) {//跳转 |
| | | for (int i = 1; i <= -stepOrderDifference; i++) { |
| | | FlowStepInstance flowStepInstanceUpdate = getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getTaskNo, taskNo) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder()-i) |
| | | .eq(FlowStepInstance::getFlowInstanceNo, flowStepInstance.getFlowInstanceNo()) |
| | | .last("limit 1")); |
| | | if (flowStepInstanceUpdate==null) { |
| | | return false; |
| | | } |
| | | flowStepInstanceUpdate.setStatus((short)3); |
| | | flowStepInstanceUpdate.setErrorMessage(flowStepInstanceUpdate.getErrorMessage()+now+"人工调整;"); |
| | | flowStepInstanceUpdate.setErrorCode(now.toString()); |
| | | flowStepInstanceUpdate.setUpdateTime(now); |
| | | updateById(flowStepInstanceUpdate); |
| | | } |
| | | } |
| | | |
| | | flowStepInstance.setErrorMessage(flowStepInstance.getErrorMessage()+now+"人工调整;"); |
| | | flowStepInstance.setErrorCode(now.toString()); |
| | | flowStepInstance.setUpdateTime(now); |
| | | flowStepInstance.setStatus((short)1); |
| | | updateById(flowStepInstance); |
| | | |
| | | |
| | | one.setTaskStatus(flowStepInstance.getWmsNowTaskStatus()); |
| | | taskService.updateById(one); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("人工调整出错:" + e); |
| | | } |
| | | // FlowInstance flowInstance = new FlowInstance(); |
| | | // flowInstance.setId(flowStepInstance.getFlowInstanceId()); |
| | | // flowInstance.setCurrentStepCode(flowStepInstance.getStepCode()); |
| | | // flowInstance.setCurrentStepOrder(flowStepInstance.getStepOrder()); |
| | | // flowInstance.setUpdateTime(new java.util.Date()); |
| | | // flowInstanceService.updateById(flowInstance); |
| | | return true; |
| | | } |
| | | |
| | | } |