| | |
| | | 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 org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Autowired |
| | | private ISynchronizedFlagService synchronizedFlagService; |
| | | @Autowired |
| | | private IDeviceGroupService deviceGroupService; |
| | | @Autowired |
| | | private IDeviceCharactersService iDeviceCharactersService; |
| | | @Autowired |
| | | private IMdcEquipmentService iMdcEquipmentService; |
| | | @Autowired |
| | | private IMdcProductionService iMdcProductionService; |
| | | @Autowired |
| | | private StringRedisTemplate redisTemplate; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Resource |
| | |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private IDeviceTypeService deviceTypeService; |
| | | |
| | | @Value("${securedoc.whether}") |
| | | private String whether; |
| | |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); |
| | | if (deviceDoc != null) { |
| | | handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); |
| | | } |
| | | deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); |
| | | deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 7, stream.getDeviceId()); |
| | | if (deviceDoc != null) { |
| | | handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); |
| | | } |
| | | PermissionStreamNew permissionStreams = getPermissionStreams(stream); |
| | | if (permissionStreams==null){ |
| | | return Result.error("用户没有权限"); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | saveBusinessObject(stream, userId); |
| | |
| | | stream.getStreamId(), "IAssignFileStreamService", "assign_nc_to_device", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", stream.getStreamId()); |
| | | variables.put("organization", stream.getApplyReason()); |
| | | return flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); |
| | | if (stream.getApplyReason() != null) { |
| | | variables.put("organization", stream.getApplyReason()); |
| | | }else { |
| | | variables.put("organization", ""); |
| | | } |
| | | Result result= flowDefinitionService.startProcessInstanceByKey("assign_nc_to_device", variables); |
| | | if (result.isSuccess()){ |
| | | return Result.OK("操作成功"); |
| | | }else { |
| | | super.removeById(stream.getStreamId()); |
| | | |
| | | return Result.error("操作失败"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = getDocFile(stream); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 7, stream.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // 删除 备份 覆盖 原有的 |
| | | List<String> strings=iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } |
| | | /*deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // 删除 备份 覆盖 原有的 |
| | | List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/"+ deviceInfo.getDeviceNo(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | }*/ |
| | | getPermissionStreams(stream); |
| | | //插入文档到设备发送文档 |
| | | if(deviceDoc == null) { |
| | |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(4); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(stream.getDeviceId()); |
| | | boolean b = docRelativeService.save(docRelative); |
| | | if(!b) { |
| | |
| | | //flowable处理 |
| | | FlowTaskVo flowTaskVo = new FlowTaskVo(); |
| | | BeanUtils.copyProperties(assignFlowTaskVo, flowTaskVo); |
| | | 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(); |
| | |
| | | DocInfo docInfo; |
| | | //同意操作 |
| | | if (StrUtil.isNotEmpty(en.getStepId())){ |
| | | //工步指派 |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getStepId()); |
| | | //工步下设备类指派 |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 6, en.getDeviceTypeId()); |
| | | }else { |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getProcessId()); |
| | | docInfo = docInfoService.getByDocAttrAndDocId(en.getDocId(), 5, en.getDeviceTypeId()); |
| | | } |
| | | if(docInfo == null || docInfo.getDocStatus() == 3) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | 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) |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),4, en.getDeviceId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(en.getDocId(),7, en.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // 删除 备份 覆盖 原有的 |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | |
| | | 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()); |
| | | boolean doc = docRelativeService.deleteCopyDocByAttrNext(deviceDoc.getDocId(),7,stream.getDeviceId()); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | }*/ |
| | |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(4); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(en.getDeviceId()); |
| | | b = docRelativeService.save(docRelative); |
| | | } |
| | |
| | | if(deviceInfo == null) |
| | | ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST); |
| | | //删除原来设备下的所有文档 |
| | | docRelativeService.deleteByDocAttr(4, deviceInfo.getDeviceId()); |
| | | docRelativeService.deleteByDocAttr(7, deviceInfo.getDeviceId()); |
| | | List<DocInfo> docInfoList = docInfoService.getByProcessIds(streams); |
| | | if(docInfoList == null || docInfoList.isEmpty()) |
| | | ExceptionCast.cast(DocumentCode.DOC_NOT_EXIST); |
| | |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | | docRelative.setAttributionType(4); |
| | | docRelative.setAttributionType(7); |
| | | docRelative.setAttributionId(deviceInfo.getDeviceId()); |
| | | boolean b = docRelativeService.save(docRelative); |
| | | if(!b) |
| | |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 4, deviceId); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 4, deviceId); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 7, deviceId); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 7, deviceId); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //权限校验 |
| | | private PermissionStreamNew getPermissionStreams(AssignFileStream stream) { |
| | | PermissionStreamNew permissionStreams; |
| | | 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")) { |
| | | // 工序 |
| | | ProcessStream processStream = processStreamService.getById(stream.getAttributionId()); |
| | | if (processStream == null) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | stream.setProductId(processStream.getProductId()); |
| | | stream.setComponentId(processStream.getComponentId()); |
| | | stream.setPartsId(processStream.getPartsId()); |
| | | stream.setProcessId(processStream.getProcessId()); |
| | | permissionStreams = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(),user.getId(),"5"); |
| | | permissionStreams = handleProcess(stream, attributionId, user); |
| | | } else { |
| | | // 工步 |
| | | WorkStep workStep = workStepService.getById(stream.getAttributionId()); |
| | | 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()); |
| | | permissionStreams = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(),user.getId(),"6"); |
| | | permissionStreams = handleWorkStep(stream, attributionId, user); |
| | | } |
| | | if (permissionStreams == null ) { |
| | | if (permissionStreams == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | } |
| | | return permissionStreams; |
| | | } |
| | | |
| | | 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) { |