| | |
| | | import com.ruoyi.basic.mapper.*; |
| | | import com.ruoyi.basic.pojo.*; |
| | | import com.ruoyi.basic.service.WorkShopFileService; |
| | | import com.ruoyi.common.config.MinioConfig; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @description 针对表【work_shop_file(车间附件名称)】的数据库操作Service实现 |
| | |
| | | @Resource |
| | | private MinioUtils minioUtils; |
| | | |
| | | @Value("${minio.bucketName}") |
| | | private String bucketName; |
| | | @Autowired |
| | | private MinioConfig minioConfig; |
| | | |
| | | @Override |
| | | public int delFile(Integer id) { |
| | |
| | | WorkShopFile file = workShopFileMapper.selectById(id); |
| | | if (file != null && file.getFileUrl() != null) { |
| | | // 检查 MinIO 中文件是否存在 |
| | | if (minioUtils.objectExists(bucketName, file.getFileUrl())) { |
| | | if (minioUtils.objectExists(minioConfig.getBucketName(), file.getFileUrl())) { |
| | | // 先删除 MinIO 中的对象 |
| | | minioUtils.removeObjectsResult(bucketName, file.getFileUrl()); |
| | | minioUtils.removeObjectsResult(minioConfig.getBucketName(), file.getFileUrl()); |
| | | } |
| | | } |
| | | // 执行数据库删除操作 |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<WorkShopFile> fileListById(Integer workShopId) { |
| | | List<WorkShopFile> workShopFiles = workShopFileMapper.selectList(new LambdaQueryWrapper<WorkShopFile>().eq(WorkShopFile::getWorkShopId, workShopId)); |
| | | return removeSuffixFromList(workShopFiles); |
| | | } |
| | | |
| | | public static List<WorkShopFile> removeSuffixFromList(List<WorkShopFile> list) { |
| | | for (WorkShopFile file : list) { |
| | | int dotIndex = file.getFileName().lastIndexOf('.'); |
| | | if (dotIndex != -1) { |
| | | file.setFileName(file.getFileName().substring(0, dotIndex)); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private StructureTestObject findStructureTestObjectByPartNo(String partNo) { |
| | | ProductPart productPart = productPartMapper.selectOne(new LambdaQueryWrapper<ProductPart>().eq(ProductPart::getPartNo, partNo)); |
| | | if (productPart != null) { |