{"record":{"id":"27112541a1459026","repo":"paascloud/paascloud-master","slug":"opc10040008","errorCode":"OPC10040008","errorMessage":"OPC10040008","messagePattern":"OPC10040008","errorType":"error_code","errorClass":"OpcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java","lineNumber":229,"sourceCode":"\t}\n\n\tprivate String getUrl(final Long expires, final boolean encrypt, final String fileName) {\n\t\tfinal String domainOfBucket;\n\t\tif (encrypt) {\n\t\t\tdomainOfBucket = paascloudProperties.getQiniu().getOss().getPrivateHost();\n\t\t\treturn optOssService.getFileUrl(domainOfBucket, fileName, expires);\n\t\t} else {\n\t\t\tdomainOfBucket = paascloudProperties.getQiniu().getOss().getPublicHost();\n\t\t\treturn domainOfBucket + \"/\" + fileName;\n\t\t}\n\t}\n\n\t@Override\n\tpublic OptAttachment getById(Long attachmentId) {\n\t\tPreconditions.checkArgument(attachmentId != null, \"文件流水号不能为空\");\n\t\tOptAttachment optAttachment = optAttachmentMapper.selectByPrimaryKey(attachmentId);\n\t\tif (PublicUtil.isEmpty(optAttachment)) {\n\t\t\tthrow new OpcBizException(ErrorCodeEnum.OPC10040008, attachmentId);\n\t\t}\n\t\treturn optAttachment;\n\t}\n\n\t@Override\n\tpublic OptUploadFileRespDto uploadFile(byte[] uploadBytes, String fileName, String fileType, String filePath, String bucketName, LoginAuthDto loginAuthDto) throws IOException {\n\t\tOptUploadFileRespDto fileInfo = optOssService.uploadFile(uploadBytes, fileName, filePath, bucketName);\n\t\tinsertAttachment(fileType, bucketName, loginAuthDto, fileInfo);\n\t\treturn fileInfo;\n\t}\n\n\t@Override\n\t@Transactional(rollbackFor = Exception.class)\n\tpublic void updateAttachment(final UpdateAttachmentDto attachmentDto) throws QiniuException {\n\t\tList<Long> attachmentIdList = attachmentDto.getAttachmentIdList();\n\t\tLoginAuthDto loginAuthDto = attachmentDto.getLoginAuthDto();\n\t\tString refNo = attachmentDto.getRefNo();\n\t\tList<Long> idList = optAttachmentMapper.queryAttachmentByRefNo(refNo);","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java#L211-L247","documentation":"OpcBizException with code OPC10040008 thrown by OptAttachmentServiceImpl.getById when selectByPrimaryKey returns no OptAttachment for the given attachmentId (null id is separately rejected by a Preconditions check). Any consumer of getById — e.g. rpcGetFileUrl building a file URL — cannot proceed without the attachment record's path and name.","triggerScenarios":"getById called with an id of a deleted attachment row; a stale/cached id from the client after deletion; an id from a different environment/datasource; integer/string id truncation or mapping mistake producing a nonexistent key.","commonSituations":"rpcGetFileUrl invoked for an attachment removed by cleanup jobs; frontend link pointing at a purged file; cross-environment data (test id queried in prod); concurrent delete racing with the URL lookup.","solutions":["Verify the attachment row exists for the id (select by primary key) before calling","Have callers catch/handle OpcBizException OPC10040008 and return a friendly 'attachment not found' to users","Confirm both sides operate on the same database/environment","Fix deletion flows to invalidate or cascade references so stale ids are not used downstream"],"exampleFix":"// before\nOptAttachment att = optAttachmentService.getById(attachmentId);\nString fileName = att.getPath() + att.getName();\n// after\nOptAttachment att;\ntry {\n    att = optAttachmentService.getById(attachmentId);\n} catch (OpcBizException e) {\n    log.warn(\"attachment {} not found\", attachmentId);\n    throw new ResourceNotFoundException(\"Attachment not found: \" + attachmentId);\n}\nString fileName = att.getPath() + att.getName();","handlingStrategy":"try-catch","validationCode":"OptAttachment exists = optAttachmentMapper.selectByPrimaryKey(attachmentId);\nif (exists == null) { throw new OpcBizException(ErrorCodeEnum.OPC10040008, attachmentId); }","typeGuard":"if (attachmentId == null) { throw new IllegalArgumentException(\"文件流水号不能为空\"); }","tryCatchPattern":"try { att = service.getById(attachmentId); } catch (OpcBizException e) { throw new ResponseStatusException(NOT_FOUND, \"attachment \" + attachmentId + \" not found\"); }","preventionTips":["Catch OPC10040008 at the API layer and return 404-style responses","Clean up downstream references when attachments are deleted","Confirm the id originates from the same environment's DB","Guard against id truncation/mapping errors between layers"],"tags":["attachment","not-found","lookup"],"backgroundTag":"entity-not-found","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}