| | |
| | | package org.jeecg.modules.dncFlow.service.impl; |
| | | |
| | | 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.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | |
| | | import org.jeecg.modules.dncFlow.service.IToEquipmentTaskService; |
| | | import org.jeecg.modules.dncFlow.vo.AssignFlowTaskVo; |
| | | 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.domain.vo.FlowTaskVo; |
| | |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private IProcessStreamService processStreamService; |
| | | @Autowired |
| | | private IWorkStepService workStepService; |
| | | @Autowired |
| | | private IPermissionStreamNewService permissionStreamNewService; |
| | | @Autowired |
| | | private IDocClassificationService classificationService; |
| | | @Autowired |
| | | private IToEquipmentTaskService equipmentTaskService; |
| | |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private IDeviceTypeService deviceTypeService; |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private PermissionService permissionService; |
| | | |
| | | @Value("${securedoc.whether}") |
| | | private String whether; |
| | |
| | | //flowable处理 |
| | | FlowTaskVo flowTaskVo = new FlowTaskVo(); |
| | | BeanUtils.copyProperties(assignFlowTaskVo, flowTaskVo); |
| | | |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("process_instance_id", assignFlowTaskVo.getInstanceId()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return false; |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | return false; |
| | | } |
| | | |
| | | // 4. 认领任务(处理已被认领的情况) |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | 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()); |
| | | Map<String, Object> values=new HashMap<>(); |
| | | values.put("dataId", assignFlowTaskVo.getDataId()); |
| | | flowTaskVo.setTaskId(assignFlowTaskVo.getTaskId()); |
| | | flowTaskVo.setValues(values); |
| | | flowTaskService.complete(flowTaskVo); |
| | | //更新对象封装 |
| | | AssignFileStream up = new AssignFileStream(); |
| | |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | if(up.getStatus() == 2) { |
| | | DocInfo docInfo; |
| | | //同意操作 |
| | | if (StrUtil.isNotEmpty(en.getStepId())){ |
| | | //工步下设备类指派 |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getDeviceTypeId()); |
| | | }else { |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getDeviceTypeId()); |
| | | } |
| | | if(docInfo == null || docInfo.getDocStatus() == 3) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), Integer.valueOf(en.getAttributionType()), en.getAttributionId()); |
| | | if(docInfo == null ) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(en.getDeviceId()); |
| | | if(mdcEquipment == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | |
| | | List<TaskRequest> list = approveBatchRequest.getTaskArr(); |
| | | if(list == null || list.isEmpty()) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | // list.forEach(item -> { |
| | | // AssignFileStream stream = new AssignFileStream(); |
| | | // stream.setApproveContent(approveBatchRequest.getApproveContent()); |
| | | // stream.setStatus(approveBatchRequest.getStatus()); |
| | | // boolean b = approveAssignFile(item.getId(), item.getBusinessKey(), stream); |
| | | // if(!b) |
| | | // ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | // }); |
| | | return synchronizedFlagService.updateFlag(1); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private PermissionStreamNew getPermissionStreams(AssignFileStream stream) { |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | DeviceType deviceType = deviceTypeService.getById(stream.getAttributionId()); |
| | | String attributionId = deviceType != null ? deviceType.getAttributionId() : stream.getAttributionId(); |
| | | |
| | | PermissionStreamNew permissionStreams; |
| | | if (stream.getAttributionType().equals("5")) { |
| | | // 工序 |
| | | permissionStreams = handleProcess(stream, attributionId, user); |
| | | } else { |
| | | // 工步 |
| | | permissionStreams = handleWorkStep(stream, attributionId, user); |
| | | } |
| | | if (permissionStreams == null) { |
| | | PermissionStreamNew permissionStreamNew = permissionService.getPermissionStreams(stream); |
| | | if (permissionStreamNew == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | } |
| | | return permissionStreams; |
| | | return permissionStreamNew ; |
| | | } |
| | | |
| | | private PermissionStreamNew handleProcess(AssignFileStream stream, String attributionId, LoginUser user) { |
| | | ProcessStream processStream = processStreamService.getById(attributionId); |
| | | if (processStream == null) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | stream.setProductId(processStream.getProductId()); |
| | | stream.setComponentId(processStream.getComponentId()); |
| | | stream.setPartsId(processStream.getPartsId()); |
| | | stream.setProcessId(processStream.getProcessId()); |
| | | if (deviceTypeService.getById(stream.getAttributionId()) != null) { |
| | | stream.setDeviceTypeId(deviceTypeService.getById(stream.getAttributionId()).getId()); |
| | | } |
| | | return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(), user.getId(), "5"); |
| | | } |
| | | |
| | | private PermissionStreamNew handleWorkStep(AssignFileStream stream, String attributionId, LoginUser user) { |
| | | WorkStep workStep = workStepService.getById(attributionId); |
| | | if (workStep == null) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | stream.setProductId(workStep.getProductId()); |
| | | stream.setComponentId(workStep.getComponentId()); |
| | | stream.setPartsId(workStep.getPartsId()); |
| | | stream.setProcessId(workStep.getProcessId()); |
| | | stream.setStepId(workStep.getId()); |
| | | if (deviceTypeService.getById(stream.getAttributionId()) != null) { |
| | | stream.setDeviceTypeId(deviceTypeService.getById(stream.getAttributionId()).getId()); |
| | | } |
| | | return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(), user.getId(), "6"); |
| | | } |
| | | |
| | | //获取部门信息 |
| | | //todo 修改 |
| | | private List<String> getDepartIds(List<PermissionStream> permissionStreams, String userId) { |
| | | Map<String, MdcProduction> map = iMdcProductionService.getUserAssignedDepart(userId); |
| | | List<String> departIds = permissionStreams.stream() |
| | | .filter(item -> map.containsKey(item.getDepartId())) |
| | | .map(PermissionStream::getDepartId) |
| | | .collect(Collectors.toList()); |
| | | if (departIds.isEmpty()) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM); |
| | | } |
| | | return departIds; |
| | | } |
| | | |
| | | |
| | | //封装数据 |
| | | private void saveBusinessObject(AssignFileStream stream, String userId) { |
| | |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); |
| | | } |
| | | } |
| | | |
| | | //开始工作流 |
| | | // private ProcessInstance startProcessInstance(AssignFileStream stream, List<String> userIdList) { |
| | | // String approveUsers = String.join(",", userIdList); |
| | | // Map<String, Object> avariableMap = new HashMap<>(); |
| | | // avariableMap.put(APPLY_VARIABLE, stream.getApplyUserId()); |
| | | // avariableMap.put(APPROVE_VARIABLE, approveUsers); |
| | | // ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, stream.getStreamId(), avariableMap); |
| | | // if (processInstance == null) { |
| | | // ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | // } |
| | | // return processInstance; |
| | | // } |
| | | |
| | | //拾取任务 |
| | | private void completeTask(ProcessInstance processInstance, String userId) { |
| | |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return Lists.newArrayList("jeecg"); |
| | | return null; |
| | | } |
| | | } |