| | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.config.MinioConfig; |
| | | import com.ruoyi.common.core.domain.MinioResult; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.utils.LimsDateUtil; |
| | |
| | | import com.ruoyi.inspect.service.InspectionPurchasedService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.Setter; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | |
| | | private final NumberGenerator<InspectionPurchased> numberGenerator; |
| | | |
| | | @Value("${minio.bucketName}") |
| | | private String bucketName; |
| | | @Autowired |
| | | private MinioConfig minioConfig; |
| | | |
| | | @Override |
| | | public int addOrUpdateInspection(InspectionPurchasedDto inspectionPurchasedDto) { |
| | |
| | | if (ObjectUtils.isNotEmpty(inspectionPurchased.getFileUrl())) { |
| | | if (inspectionPurchased != null && inspectionPurchased.getFileUrl() != null) { |
| | | // 检查 MinIO 中文件是否存在 |
| | | if (minioUtils.objectExists(bucketName, inspectionPurchased.getFileUrl())) { |
| | | if (minioUtils.objectExists(minioConfig.getBucketName(), inspectionPurchased.getFileUrl())) { |
| | | // 先删除 MinIO 中的对象 |
| | | minioUtils.removeObjectsResult(bucketName, inspectionPurchased.getFileUrl()); |
| | | minioUtils.removeObjectsResult(minioConfig.getBucketName(), inspectionPurchased.getFileUrl()); |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | String contentType = file.getContentType(); |
| | | String category = contentType != null && contentType.startsWith("image/") ? "images" : "docs"; |
| | | MinioResult upload = minioUtils.upload(bucketName, file, true); |
| | | MinioResult upload = minioUtils.upload(minioConfig.getBucketName(), file, true); |
| | | // 记录存储路径 |
| | | inspectionPurchased.setFileUrl(upload.getBucketFileName()); |
| | | inspectionPurchased.setFilePreviewUrl(upload.getPreviewExpiry()); |