paascloud/paascloud-master · error · OpcBizException

OPC10040007

OPC10040007

Error message

OPC10040007

What it means

OpcBizException with code OPC10040007 thrown by OptAttachmentServiceImpl.saveAttachment when updating an existing attachment (isNew() false) affects zero rows in optAttachmentMapper.updateByPrimaryKeySelective. This means the record with the given id no longer exists (or was concurrently deleted), so the update is a no-op and is treated as a business failure.

Solutions

  1. Verify the attachment id exists before updating (query by primary key)
  2. Use insert-on-missing/upsert semantics or re-create the record if it should exist
  3. Add optimistic locking/version check and surface a clear 'record changed or deleted' message to the user
  4. Confirm the client is not sending stale ids after deletion

Example fix

// before
int result = optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);
if (result < 1) {
    throw new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId());
}
// after
OptAttachment existing = optAttachmentMapper.selectByPrimaryKey(optAttachment.getId());
if (existing == null) {
    optAttachmentMapper.insertSelective(optAttachment); // or fail fast with a clearer message
} else {
    optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);
}
Defensive patterns

Strategy: validation

Validate before calling

OptAttachment existing = optAttachmentMapper.selectByPrimaryKey(optAttachment.getId());
if (existing == null) {
    throw new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId()); // or insert
}

Type guard

if (optAttachment == null || optAttachment.getId() == null) { throw new IllegalArgumentException("id required for update"); }

Try / catch

try { attachmentService.saveAttachment(optAttachment, loginAuthDto); } catch (OpcBizException e) { if ("OPC10040007".equals(e.getCode())) { /* record vanished; reload or recreate */ } }

Prevention

When it happens

Trigger: saveAttachment called with an attachment whose id points to a deleted/nonexistent row; concurrent transaction deleted the attachment between load and update; caller passed a stale id from the client; wrong datasource/env so the id does not exist.

Common situations: Double-submit forms where one request deleted the attachment; optimistic-concurrency races in multi-instance deployments; frontend caching an id after the record was removed; environment mismatch (test id used against prod DB).

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/a075df628d4de6ec. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java:149

	@Override
	public int deleteFile(final Long attachmentId) throws QiniuException {
		OptAttachment optAttachment = optAttachmentMapper.selectByPrimaryKey(attachmentId);
		if (optAttachment != null) {
			optOssService.deleteFile(optAttachment.getPath() + optAttachment.getName(), optAttachment.getBucketName());
			return optAttachmentMapper.deleteByPrimaryKey(attachmentId);
		}
		return 1;
	}

	@Override
	public void saveAttachment(OptAttachment optAttachment, LoginAuthDto loginAuthDto) {
		optAttachment.setUpdateInfo(loginAuthDto);
		if (optAttachment.isNew()) {
			optAttachmentMapper.insertSelective(optAttachment);
		} else {
			int result = optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);
			if (result < 1) {
				throw new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId());
			}
		}
	}

	@Override
	public OptUploadFileRespDto rpcUploadFile(OptUploadFileReqDto optUploadFileReqDto) throws IOException {
		String fileType = optUploadFileReqDto.getFileType();
		String filePath = optUploadFileReqDto.getFilePath();
		String bucketName = optUploadFileReqDto.getBucketName();
		OptUploadFileByteInfoReqDto uploadFileByteInfoReqDto = optUploadFileReqDto.getUploadFileByteInfoReqDto();
		LoginAuthDto authResDto = new LoginAuthDto();
		authResDto.setUserId(optUploadFileReqDto.getUserId());
		authResDto.setUserName(optUploadFileReqDto.getUserName());

		if (PublicUtil.isEmpty(filePath)) {
			filePath = GlobalConstant.Oss.DEFAULT_FILE_PATH;
		}
		InputStream is = null;

View on GitHub (pinned to 781281a950)