| | |
| | | @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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |