| | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean applyAssignFileActive(AssignFileStream stream) { |
| | | //æ ¡éªå¼å§ |
| | | if(stream == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId()) |
| | | || !ValidateUtil.validateString(stream.getFileId())||!ValidateUtil.validateString(stream.getAttributionType()) ) |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); |
| | | if(!ValidateUtil.validateString(stream.getDeviceId())) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if(!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | //ä¿®æ¹ä¸ºåç«¯ä¼ å
¥ |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId()); |
| | | if(docInfo == null || docInfo.getDocStatus() == 3) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId()); |
| | | if(deviceInfo == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | if(deviceInfo == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 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()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId()); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(),4,stream.getDeviceId()); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | } |
| | | } |
| | | }*/ |
| | | if (deviceDoc != null) { |
| | | handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); |
| | | } |
| | | 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()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | //docInfoService.getBaseMapper().deleteById(deviceDoc.getDocId()); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(),4,stream.getDeviceId()); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | } |
| | | } |
| | | }*/ |
| | | if (deviceDoc != null) { |
| | | handleExistingDeviceDoc(docFile, mdcEquipment, stream.getDeviceId()); |
| | | } |
| | | |
| | | ProcessStream processStream = processStreamService.getById(stream.getProcessId()); |
| | | if(processStream == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); |
| | | stream.setProductId(processStream.getProductId()); |
| | | stream.setComponentId(processStream.getComponentId()); |
| | | stream.setPartsId(processStream.getPartsId()); |
| | | List<PermissionStream> permissionStreams = null; |
| | | if(ValidateUtil.validateString(processStream.getPartsId())) { |
| | | //è¿å
¥é¶ä»¶ |
| | | permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId()); |
| | | }else if(ValidateUtil.validateString(processStream.getComponentId())) { |
| | | //è¿å
¥é¨ä»¶çå¤ç |
| | | permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId()); |
| | | } |
| | | if(permissionStreams == null || permissionStreams.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | List<String> departIds = new ArrayList<>(); |
| | | Map<String, Department> map = departmentService.getMapByUserId(userId); |
| | | permissionStreams.forEach(item -> { |
| | | if(map.containsKey(item.getDepartId())) { |
| | | departIds.add(item.getDepartId()); |
| | | } |
| | | }); |
| | | if(departIds.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM); |
| | | //è·åé¨é¨å®¡æ¹äºº |
| | | List<String> userIdList = definitionService.getByDepartIds(departIds); |
| | | if(userIdList == null || userIdList.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | //æ ¡éªç»æ |
| | | String streamId = IdWorker.getIdStr(); |
| | | stream.setStreamId(streamId); |
| | | stream.setApplyUserId(userId); |
| | | stream.setApplyTime(DateUtil.getNow()); |
| | | stream.setStatus(1); |
| | | //ä¿åæµç¨ä¸å¡å¯¹è±¡ |
| | | boolean b = super.save(stream); |
| | | if(!b) |
| | | ExceptionCast.cast(ActivitiCode.ACT_BUSINESS_SAVE_ERROR); |
| | | //ä¿åæµç¨ä»»å¡ |
| | | String approveUsers = String.join(",", userIdList); |
| | | Map<String, Object> avariableMap = new HashMap<>(); |
| | | avariableMap.put(APPLY_VARIABLE, userId); |
| | | avariableMap.put(APPROVE_VARIABLE, approveUsers); |
| | | //å¯å¨æµç¨ |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, streamId, avariableMap); |
| | | if(processInstance == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | //æ¥è¯¢å½åæµç¨ç¨æ·æµç¨ä»»å¡ |
| | | Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId) |
| | | .processInstanceId(processInstance.getId()).singleResult(); |
| | | if(task == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | //宿æµç¨ä»»å¡ |
| | | taskService.complete(task.getId()); |
| | | 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); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public ResponseResult applyAssignFileNonActive(AssignFileStream stream) { |
| | | if(stream == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId()) |
| | | || !ValidateUtil.validateString(stream.getFileId())||!ValidateUtil.validateString(stream.getAttributionType())) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(stream.getDeviceId())) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if(!ValidateUtil.validateString(userId)) |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId()); |
| | | if(docInfo == null || docInfo.getDocStatus() == 3) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(stream.getDeviceId()); |
| | | // DeviceInfo deviceInfo = deviceInfoService.getById(stream.getDeviceId()); |
| | | if(mdcEquipment == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | if(docFile == null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | //æéæ ¡éª |
| | | validateParams(stream); |
| | | DocInfo docInfo = getDocInfo(stream); |
| | | MdcEquipment mdcEquipment = getMdcEquipment(stream); |
| | | DocFile docFile = getDocFile(stream); |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(stream.getDocId(), 4, stream.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // å é¤ å¤ä»½ è¦ç åæç |
| | |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } |
| | | |
| | | /*deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); |
| | | if(deviceDoc != null) { |
| | | // å é¤ å¤ä»½ è¦ç åæç |
| | |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | }*/ |
| | | List<String> departIds = new ArrayList<>(); |
| | | 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(stream.getAttributionId()); |
| | | List<PermissionStream> permissionStreams = null; |
| | | if(ValidateUtil.validateString(processStream.getPartsId())) { |
| | | //è¿å
¥é¶ä»¶ |
| | | permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId()); |
| | | }else if(ValidateUtil.validateString(processStream.getComponentId())) { |
| | | //è¿å
¥é¨ä»¶çå¤ç |
| | | permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId()); |
| | | } |
| | | if(permissionStreams == null || permissionStreams.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | Map<String, Department> map = departmentService.getMapByUserId(userId); |
| | | permissionStreams.forEach(item -> { |
| | | if(map.containsKey(item.getDepartId())) { |
| | | departIds.add(item.getDepartId()); |
| | | } |
| | | }); |
| | | }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.setProcessId(stream.getAttributionId()); |
| | | List<PermissionStream> permissionStreams = null; |
| | | if(ValidateUtil.validateString(workStep.getProcessId())) { |
| | | //è¿å
¥å·¥åº |
| | | permissionStreams=permissionStreamService.getByProcessId(stream.getProductId(), stream.getComponentId(), stream.getPartsId(),stream.getProcessId()); |
| | | }else if(ValidateUtil.validateString(workStep.getPartsId())) { |
| | | //è¿å
¥é¶ä»¶ |
| | | permissionStreams = permissionStreamService.getByPartsId(stream.getProductId(), stream.getComponentId(), stream.getPartsId()); |
| | | }else if(ValidateUtil.validateString(workStep.getComponentId())) { |
| | | //è¿å
¥é¨ä»¶çå¤ç |
| | | permissionStreams = permissionStreamService.getByComponentId(stream.getProductId(), stream.getComponentId()); |
| | | } |
| | | if(permissionStreams == null || permissionStreams.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | Map<String, Department> map = departmentService.getMapByUserId(userId); |
| | | permissionStreams.forEach(item -> { |
| | | if(map.containsKey(item.getDepartId())) { |
| | | departIds.add(item.getDepartId()); |
| | | } |
| | | }); |
| | | } |
| | | if(departIds.isEmpty()) |
| | | ExceptionCast.cast(ActivitiCode.ACT_USER_NOT_PERM); |
| | | //deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); |
| | | /*if(deviceDoc != null) |
| | | ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_ERROR);*/ |
| | | getPermissionStreams(stream); |
| | | //æå
¥ææ¡£å°è®¾å¤åéææ¡£ |
| | | if(deviceDoc == null) { |
| | | DocClassification classification = classificationService.getByCode(SEND_CODE); |
| | | if(classification == null) |
| | | ExceptionCast.cast(DocumentCode.DOC_CLASS_ERROR); |
| | | |
| | | DocRelative docRelative = new DocRelative(); |
| | | docRelative.setDocId(docInfo.getDocId()); |
| | | docRelative.setClassificationId(classification.getClassificationId()); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | //TODO |
| | | //æå
¥æä»¶ä¼ è¾ä»»å¡è¡¨ |
| | | 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 + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(path + "/"+ mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(),docFile.getFileSuffix()); |
| | | |
| | | } |
| | | } else { |
| | | return new ResponseResult(CommonCode.FAIL); |
| | | } |
| | | String size = FileUtilS.fileSizeNC(docFile.getFilePath(),docFile.getFileEncodeName()); |
| | | if (whether.equals("true") && !docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar") ) { |
| | | //å¤çæä»¶ è®°å½å¹¶ä¸æ¥ |
| | | //1ã å¤æç«¯å£æ¯å¦è½å¤è®¿é® æä»¶è·¯å¾å |
| | | /*boolean btelnetPort = TelnetUtil.telnetPort(serverIp,serverPort,10); |
| | | if (!btelnetPort) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DEVICE_DOC_FILELABLE); |
| | | }*/ |
| | | DncPassLog passInfoTxt = new DncPassLog(); |
| | | |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | Date dateFirst = DateUtil.getNow(); |
| | | passInfoTxt.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | /*æ¥è¯¢æå䏿¡è®°å½*/ |
| | | //ä¼ç 500æ¯«ç§ |
| | | DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | Integer fileTxt = 0, fileNc =0; |
| | | if (dncPassLog !=null) { |
| | | fileTxt = dncPassLog.getSequenceNumber() + 1; |
| | | fileNc = fileTxt + 1; |
| | | } else { |
| | | fileTxt = 1; |
| | | fileNc = fileTxt + 1; |
| | | } |
| | | //å¤çæä»¶åç§° æä»¶è·¯å¾ |
| | | String sequence = String.format("%06d",fileTxt); |
| | | String sequenceNc = String.format("%06d",fileNc); |
| | | passInfoTxt.setSequenceNumber(fileTxt); |
| | | passInfoTxt.setSequenceOrder(sequence); |
| | | passInfoTxt.setCreateTime(dateFirst); |
| | | System.out.println(DateUtil.format(dateFirst,DateUtil.STR_DATE_TIME)); |
| | | passInfoTxt.setPassType("02"); |
| | | dncPassLogService.save(passInfoTxt); |
| | | |
| | | DncPassLog passInfoNc = new DncPassLog(); |
| | | passInfoNc.setSequenceNumber(fileNc); |
| | | passInfoNc.setSequenceOrder(sequenceNc); |
| | | passInfoNc.setDayTime(DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)); |
| | | passInfoNc.setPassType("02"); |
| | | passInfoNc.setPassName(docFile.getFileName()); |
| | | try { |
| | | Thread.sleep(1000); |
| | | Date date = new Date(); |
| | | passInfoNc.setCreateTime(date); |
| | | System.out.println(DateUtil.format(date,DateUtil.STR_DATE_TIME)); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | dncPassLogService.save(passInfoNc); |
| | | |
| | | NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo(); |
| | | ncTxt.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | ncTxt.setFileNcName("02A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequenceNc); |
| | | ncTxt.setFileTxtName("02A"+DateUtil.format(dateFirst,DateUtil.STR_YEARMONTHDAY)+sequence); |
| | | ncTxt.setFilePath(path + "/"+ mdcEquipment.getEquipmentId() + "/" ); |
| | | ncTxt.setOrigFileName(docFile.getFileName()); |
| | | ncTxt.setOrigFileSuffix(docFile.getFileSuffix()); |
| | | ncTxt.setFileAddOrDelete(1); |
| | | String loFilePath = localFilePath + ncTxt.getFileTxtName() + ".nc"; |
| | | // String loFilePath = localFilePath + "\\" + ncTxt.getFileTxtName() + ".nc"; |
| | | try { |
| | | String allList = new String(); |
| | | allList=(ncTxt.getFileTxtName()+"\n"); |
| | | allList+=(ncTxt.getFileNcName()+"\n"); |
| | | allList+=(ncTxt.getOrigFileName()+"\n"); |
| | | allList+=(ncTxt.getOrigFileSuffix()+"\n"); |
| | | allList+=(ncTxt.getFilePath()+"\n"); |
| | | allList+=(ncTxt.getEquipmentId()+"\n"); |
| | | allList+=(ncTxt.getFileAddOrDelete().toString()+"\n"); |
| | | // æä»¶å¤§å°åè 第äºè¡ å·¥æ§ç½è¿è¡æä»¶åæ |
| | | allList+= (size+"\n"); |
| | | |
| | | FileUtilS.fileWriterSql(loFilePath,allList); |
| | | //æä»¶è§£æéæ°è§å |
| | | //æ·»å æä»¶ååï¼ç¬¬ä¸è¡ï¼ |
| | | |
| | | |
| | | /* |
| | | boolean copyFileNc = FileUtilS.copyFileNcIntegration(path + "/"+ deviceInfo.getDeviceNo() +"/send/" + |
| | | docFile.getFileName(), |
| | | localFilePath + "\\" + ncTxt.getFileNcName(), |
| | | docFile.getFileSuffix()); |
| | | */ |
| | | boolean copyFileNc = FileUtilS.copyFileUpName(path + "/"+ mdcEquipment.getEquipmentId() +"/send/" + |
| | | docFile.getFileName(), |
| | | localFilePath + ncTxt.getFileNcName(), |
| | | // localFilePath + "\\" + ncTxt.getFileNcName(), |
| | | docFile.getFileSuffix(),"NC"); |
| | | if (!copyFileNc) { |
| | | FileUtilS.deleteNcFile(loFilePath); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | handleFileTransfer(mdcEquipment, docFile); |
| | | handleFileProcessing(docFile, mdcEquipment, whether, localFilePath); |
| | | synchronizedFlagService.updateFlag(2); |
| | | return new ResponseResult(CommonCode.SUCCESS); |
| | | } |
| | |
| | | } |
| | | return synchronizedFlagService.updateFlag(1); |
| | | } |
| | | |
| | | //ä¼ åéªè¯ |
| | | private void validateParams(AssignFileStream stream) { |
| | | if (stream == null) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | if (!ValidateUtil.validateString(stream.getAttributionId()) || !ValidateUtil.validateString(stream.getDocId()) |
| | | || !ValidateUtil.validateString(stream.getFileId()) || !ValidateUtil.validateString(stream.getAttributionType())) { |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | } |
| | | if (!ValidateUtil.validateString(stream.getDeviceId())) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | if (!ValidateUtil.validateString(userId)) { |
| | | ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); |
| | | } |
| | | } |
| | | |
| | | //è·åæä»¶ä¿¡æ¯ |
| | | private DocInfo getDocInfo(AssignFileStream stream) { |
| | | DocInfo docInfo = docInfoService.getByDocAttrAndDocId(stream.getDocId(), Integer.parseInt(stream.getAttributionType()), stream.getAttributionId()); |
| | | if (docInfo == null || docInfo.getDocStatus() == 3) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR); |
| | | } |
| | | return docInfo; |
| | | } |
| | | |
| | | //è·åæä»¶ |
| | | private void handleExistingDeviceDoc(DocFile docFile, MdcEquipment mdcEquipment, String deviceId) { |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getEquipmentId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | boolean copyFileNc = FileUtilS.copyFileNcToBak(path + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | DocInfo deviceDoc = docInfoService.getByDocAttrAndDocId(deviceId, 4, deviceId); |
| | | boolean doc = docRelativeService.deleteDocByAttr(deviceDoc.getDocId(), 4, deviceId); |
| | | if (!doc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR_DELEVE); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //æéæ ¡éª |
| | | private List<PermissionStream> getPermissionStreams(AssignFileStream stream) { |
| | | List<PermissionStream> permissionStreams = new ArrayList<>(); |
| | | 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 = permissionStreamService |
| | | .getByProcessId(processStream.getProductId(), processStream.getComponentId(), processStream.getPartsId(), processStream.getProcessId()); |
| | | } 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 = permissionStreamService |
| | | .getByStepId(workStep.getProductId(), workStep.getComponentId(), workStep.getPartsId(), workStep.getProcessId(), workStep.getId()); |
| | | } |
| | | if (permissionStreams == null || permissionStreams.isEmpty()) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE); |
| | | } |
| | | return permissionStreams; |
| | | } |
| | | |
| | | //è·åé¨é¨ä¿¡æ¯ |
| | | //todo ä¿®æ¹ |
| | | private List<String> getDepartIds(List<PermissionStream> permissionStreams, String userId) { |
| | | Map<String, Department> map = departmentService.getMapByUserId(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 List<String> getUserIdList(List<String> departIds) { |
| | | List<String> userIdList = definitionService.getByDepartIds(departIds); |
| | | if (userIdList == null || userIdList.isEmpty()) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | } |
| | | return userIdList; |
| | | } |
| | | |
| | | //å°è£
æ°æ® |
| | | private void saveBusinessObject(AssignFileStream stream, String userId) { |
| | | String streamId = IdWorker.getIdStr(); |
| | | stream.setStreamId(streamId); |
| | | stream.setApplyUserId(userId); |
| | | stream.setApplyTime(DateUtil.getNow()); |
| | | stream.setStatus(1); |
| | | boolean b = super.save(stream); |
| | | if (!b) { |
| | | 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) { |
| | | Task task = taskService.createTaskQuery().processDefinitionKey(PROCESS_KEY).taskAssignee(userId) |
| | | .processInstanceId(processInstance.getId()).singleResult(); |
| | | if (task == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_APPROVE_USERS_NONE); |
| | | } |
| | | taskService.complete(task.getId()); |
| | | } |
| | | |
| | | //è·åè®¾å¤ |
| | | private MdcEquipment getMdcEquipment(AssignFileStream stream) { |
| | | MdcEquipment mdcEquipment = iMdcEquipmentService.getById(stream.getDeviceId()); |
| | | if (mdcEquipment == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_ASSIGN_DEVICE_NONE); |
| | | } |
| | | return mdcEquipment; |
| | | } |
| | | |
| | | //è·åæä»¶ |
| | | private DocFile getDocFile(AssignFileStream stream) { |
| | | DocFile docFile = docFileService.getById(stream.getFileId()); |
| | | if (docFile == null) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } |
| | | return docFile; |
| | | } |
| | | |
| | | //æå
¥æä»¶ä¼ è¾ä»»å¡è¡¨ |
| | | private void handleFileTransfer(MdcEquipment mdcEquipment, DocFile docFile) { |
| | | 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 + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileEncodeName(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | if (!copyFileNc) { |
| | | ExceptionCast.cast(ActivitiCode.ACT_FILE_ERROR); |
| | | } else { |
| | | FileUtilS.deleteZipFromToSend(path + "/" + mdcEquipment.getEquipmentId(), |
| | | docFile.getFileName(), docFile.getFileSuffix()); |
| | | } |
| | | } else { |
| | | throw new RuntimeException("æä»¶ä¼ è¾è·¯å¾è·å失败"); |
| | | } |
| | | } |
| | | |
| | | //å°è£
å¤çæä»¶ |
| | | private void handleFileProcessing(DocFile docFile, MdcEquipment mdcEquipment, String whether, String localFilePath) { |
| | | if (whether.equals("true") && !docFile.getFileSuffix().equals("zip") && !docFile.getFileSuffix().equals("rar")) { |
| | | String size = FileUtilS.fileSizeNC(docFile.getFilePath(), docFile.getFileEncodeName()); |
| | | List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (strings != null && !strings.isEmpty()) { |
| | | String path = StringUtils.join(strings.toArray(), "/"); |
| | | Date dateFirst = DateUtil.getNow(); |
| | | DncPassLog passInfoTxt = new DncPassLog(); |
| | | passInfoTxt.setDayTime(DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY)); |
| | | DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY)); |
| | | Integer fileTxt = 0, fileNc = 0; |
| | | if (dncPassLog != null) { |
| | | fileTxt = dncPassLog.getSequenceNumber() + 1; |
| | | fileNc = fileTxt + 1; |
| | | } else { |
| | | fileTxt = 1; |
| | | fileNc = fileTxt + 1; |
| | | } |
| | | String sequence = String.format("%06d", fileTxt); |
| | | String sequenceNc = String.format("%06d", fileNc); |
| | | passInfoTxt.setSequenceNumber(fileTxt); |
| | | passInfoTxt.setSequenceOrder(sequence); |
| | | passInfoTxt.setCreateTime(dateFirst); |
| | | passInfoTxt.setPassType("02"); |
| | | dncPassLogService.save(passInfoTxt); |
| | | |
| | | DncPassLog passInfoNc = new DncPassLog(); |
| | | passInfoNc.setSequenceNumber(fileNc); |
| | | passInfoNc.setSequenceOrder(sequenceNc); |
| | | passInfoNc.setDayTime(DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY)); |
| | | passInfoNc.setPassType("02"); |
| | | passInfoNc.setPassName(docFile.getFileName()); |
| | | try { |
| | | Thread.sleep(1000); |
| | | Date date = new Date(); |
| | | passInfoNc.setCreateTime(date); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | dncPassLogService.save(passInfoNc); |
| | | |
| | | NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo(); |
| | | ncTxt.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | ncTxt.setFileNcName("02A" + DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY) + sequenceNc); |
| | | ncTxt.setFileTxtName("02A" + DateUtil.format(dateFirst, DateUtil.STR_YEARMONTHDAY) + sequence); |
| | | ncTxt.setFilePath(path + "/" + mdcEquipment.getEquipmentId() + "/"); |
| | | ncTxt.setOrigFileName(docFile.getFileName()); |
| | | ncTxt.setOrigFileSuffix(docFile.getFileSuffix()); |
| | | ncTxt.setFileAddOrDelete(1); |
| | | String loFilePath = localFilePath + ncTxt.getFileTxtName() + ".nc"; |
| | | try { |
| | | String allList = ncTxt.getFileTxtName() + "\n" |
| | | + ncTxt.getFileNcName() + "\n" |
| | | + ncTxt.getOrigFileName() + "\n" |
| | | + ncTxt.getOrigFileSuffix() + "\n" |
| | | + ncTxt.getFilePath() + "\n" |
| | | + ncTxt.getEquipmentId() + "\n" |
| | | + ncTxt.getFileAddOrDelete().toString() + "\n" |
| | | + size + "\n"; |
| | | FileUtilS.fileWriterSql(loFilePath, allList); |
| | | boolean copyFileNc = FileUtilS.copyFileUpName(path + "/" + mdcEquipment.getEquipmentId() + "/send/" + |
| | | docFile.getFileName(), |
| | | localFilePath + ncTxt.getFileNcName(), |
| | | docFile.getFileSuffix(), "NC"); |
| | | if (!copyFileNc) { |
| | | FileUtilS.deleteNcFile(loFilePath); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("æä»¶å¤ç失败", e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |