From 42e68faca0756d44b7c880c9876810ee47d6e92b Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期一, 17 二月 2025 17:57:25 +0800 Subject: [PATCH] 1.DNC模块,设备结构树权限分配优化与修改bug 2.MDC模块,设备编辑车间同步平移设备send目录 3.优化原有指派设备代码 --- lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java | 588 +++++++++++++++++++++++++++------------------------------- 1 files changed, 277 insertions(+), 311 deletions(-) diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java index 9e4f927..a17b68e 100644 --- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java +++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/activiti/service/impl/AssignFileStreamServiceImpl.java @@ -194,150 +194,37 @@ @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) { // 鍒犻櫎 澶囦唤 瑕嗙洊 鍘熸湁鐨� @@ -348,7 +235,6 @@ docFile.getFileName(), docFile.getFileSuffix()); } } - /*deviceDoc = docInfoService.findByAttrAndDocName(docInfo.getDocName(), 4, stream.getDeviceId()); if(deviceDoc != null) { // 鍒犻櫎 澶囦唤 瑕嗙洊 鍘熸湁鐨� @@ -359,73 +245,12 @@ 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()); @@ -437,121 +262,8 @@ } } - - //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); - //鏂囦欢瑙f瀽閲嶆柊瑙勫垝 - //娣诲姞鏂囦欢鍚嶅瓧锛岀涓�琛岋紝 - - -/* - 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); } @@ -848,4 +560,258 @@ } 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); + } + } + } + } + } -- Gitblit v1.9.3