| | |
| | | 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.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.utils.date.DateUtil; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.flow.vo.AssignFlowTaskVo; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | 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.IFlowDefinitionService; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService { |
| | | @Service("IAssignFileStreamService") |
| | | public class AssignFileStreamServiceImpl extends ServiceImpl<AssignFileStreamMapper, AssignFileStream> implements IAssignFileStreamService , FlowCallBackServiceI { |
| | | private static final String PROCESS_KEY = "assign_nc_to_device"; |
| | | private static final String APPLY_VARIABLE = "apply_user"; |
| | | private static final String APPROVE_VARIABLE = "approve_users"; |
| | |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | |
| | | @Value("${securedoc.serverIp}") |
| | | private String serverIp; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public ResponseResult applyAssignFile(AssignFileStream stream) { |
| | | public Result applyAssignFile(AssignFileStream stream) { |
| | | synchronized (this){ |
| | | //判断设备特殊字符 |
| | | String specialChar = getDeviceSpecialChar(stream.getDeviceId(),stream.getFileId()); |
| | | if (StrUtil.isNotEmpty(specialChar)){ |
| | | //抛出特殊字符异常 |
| | | return createSpecialCharErrorResponse(specialChar); |
| | | return Result.error("文件名称存在设备特殊字符"); |
| | | } |
| | | if(flowableEnable) { |
| | | boolean b = applyAssignFileActive(stream); |
| | | if (b) { |
| | | return ResponseResult.SUCCESS(); |
| | | } else { |
| | | return ResponseResult.SUCCESS(); |
| | | } |
| | | |
| | | return applyAssignFileActive(stream); |
| | | }else { |
| | | return applyAssignFileNonActive(stream); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean applyAssignFileActive(AssignFileStream stream) { |
| | | public Result<?> applyAssignFileActive(AssignFileStream stream) { |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | |
| | | List<PermissionStream> permissionStreams = getPermissionStreams(stream); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | // List<String> departIds = getDepartIds(permissionStreams, userId); |
| | | // List<String> userIdList = getUserIdList(departIds); |
| | | // saveBusinessObject(stream, userId); |
| | | // ProcessInstance processInstance = startProcessInstance(stream, userIdList); |
| | | // completeTask(processInstance, userId); |
| | | saveBusinessObject(stream, userId); |
| | | System.out.println("指派NC文档到设备流程:" + stream.getDocId()); |
| | | flowCommonService.initActBusiness("指派NC文档到设备流程:" + stream.getStreamId(), stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null); |
| | | flowCommonService.initActBusiness("指派NC文档到设备流程:" +docInfo.getDocName()+"."+docInfo.getDocSuffix()+"到设备->"+mdcEquipment.getEquipmentName() , |
| | | stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("id", stream.getStreamId()); |
| | | variables.put("approveContent", stream.getApproveContent()); |
| | | flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); |
| | | return true; |
| | | variables.put("dataId", stream.getStreamId()); |
| | | variables.put("organization", stream.getApplyReason()); |
| | | return flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public ResponseResult applyAssignFileNonActive(AssignFileStream stream) { |
| | | public Result<?> applyAssignFileNonActive(AssignFileStream stream) { |
| | | //权限校验 |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | |
| | | handleFileTransfer(mdcEquipment, docFile); |
| | | handleFileProcessing(docFile, mdcEquipment, whether, localFilePath); |
| | | synchronizedFlagService.updateFlag(2); |
| | | return new ResponseResult(CommonCode.SUCCESS); |
| | | return Result.OK("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean approveAssignFile(String taskId, String streamId, AssignFileStream stream) { |
| | | if(!ValidateUtil.validateString(taskId) || !ValidateUtil.validateString(streamId) || stream == null) |
| | | public boolean approveAssignFile(AssignFlowTaskVo assignFlowTaskVo) { |
| | | if(!ValidateUtil.validateString(assignFlowTaskVo.getTaskId()) || !ValidateUtil.validateString(assignFlowTaskVo.getDataId()) || assignFlowTaskVo == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if(!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | if(!ValidateUtil.validateInteger(stream.getStatus())) |
| | | if(!ValidateUtil.validateInteger(assignFlowTaskVo.getStatus())) |
| | | ExceptionCast.cast(ActivitiCode.ACT_STATUS_ERROR); |
| | | AssignFileStream en = super.getById(streamId); |
| | | AssignFileStream en = super.getById(assignFlowTaskVo.getDataId()); |
| | | if(en == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_DETAIL_ERROR); |
| | | Task task = taskService.createTaskQuery().taskId(taskId).taskCandidateOrAssigned(userId).singleResult(); |
| | | if(task == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_TASK_ERROR); |
| | | if(!ValidateUtil.validateString(task.getAssignee())) { |
| | | //拾取任务 |
| | | taskService.claim(task.getId(), userId); |
| | | //完成任务 |
| | | taskService.complete(task.getId()); |
| | | }else { |
| | | //完成任务 |
| | | taskService.complete(task.getId()); |
| | | } |
| | | //flowable处理 |
| | | FlowTaskVo flowTaskVo = new FlowTaskVo(); |
| | | BeanUtils.copyProperties(assignFlowTaskVo, flowTaskVo); |
| | | flowTaskService.complete(flowTaskVo); |
| | | //更新对象封装 |
| | | AssignFileStream up = new AssignFileStream(); |
| | | up.setApproveContent(stream.getApproveContent()); |
| | | up.setStatus(stream.getStatus()); |
| | | up.setApproveContent(assignFlowTaskVo.getApproveContent()); |
| | | up.setStatus(assignFlowTaskVo.getStatus()); |
| | | up.setApproveUserId(userId); |
| | | up.setApproveTime(DateUtil.getNow()); |
| | | up.setStreamId(streamId); |
| | | up.setStreamId(assignFlowTaskVo.getDataId()); |
| | | boolean b = super.updateById(up); |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | if(up.getStatus() == 2) { |
| | | DocInfo docInfo; |
| | | //同意操作 |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getProcessId()); |
| | | if (StrUtil.isNotEmpty(en.getStepId())){ |
| | | //工步指派 |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getStepId()); |
| | | }else { |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getProcessId()); |
| | | } |
| | | if(docInfo == null || docInfo.getDocStatus() == 3) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | DeviceInfo deviceInfo = deviceInfoService.getById(en.getDeviceId()); |
| | | if(deviceInfo == null) |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(en.getDeviceId()); |
| | | if(mdcEquipment == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | DocFile docFile = docFileService.getById(en.getFileId()); |
| | | if(docFile == null) |
| | |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),4, en.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // 删除 备份 覆盖 原有的 |
| | | List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ deviceInfo.getDeviceNo(), |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | /* //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId()); |
| | | boolean doc = docRelativeService.deleteCopyDocByAttrNext(deviceDoc.getDocId(),4,stream.getDeviceId()); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | }*/ |
| | | |
| | | } |
| | | } else { |
| | | //插入文档到设备发送文档 |
| | |
| | | } |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_ERROR); |
| | | if (deviceInfo != null) { |
| | | List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); |
| | | if (mdcEquipment != null) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(),path + "/"+ deviceInfo.getDeviceNo(), |
| | | boolean copyFileNc = FileUtilS.copyFileNc(docFile.getFilePath(),path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(path + "/"+ deviceInfo.getDeviceNo(), |
| | | FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | return synchronizedFlagService.updateFlag(1); |
| | | }else if(up.getStatus() == 3) { |
| | |
| | | for(String id : deviceIds) { |
| | | stream = new AssignFileStream(); |
| | | stream.setProcessId(assignFileRequest.getProcessId()); |
| | | stream.setStepId(assignFileRequest.getStepId()); |
| | | stream.setDocId(assignFileRequest.getDocId()); |
| | | stream.setFileId(assignFileRequest.getFileId()); |
| | | stream.setApplyReason(assignFileRequest.getApplyReason()); |
| | | stream.setDeviceId(id); |
| | | ResponseResult b = applyAssignFile(stream); |
| | | Result b = applyAssignFile(stream); |
| | | if(!b.isSuccess()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPLY_ERROR); |
| | | } |
| | |
| | | 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); |
| | | }); |
| | | // 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); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//接下来审批的节点 |
| | | business.getValues();//前端传进来的参数 |
| | | business.getActStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getBusinessDataById(String dataId) { |
| | | return this.getById(dataId); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return Lists.newArrayList("jeecg"); |
| | | } |
| | | } |