| | |
| | | import com.ruoyi.basic.mapper.WorkShopFileMapper; |
| | | import com.ruoyi.basic.pojo.WorkShopFile; |
| | | import com.ruoyi.basic.service.WorkShopFileService; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @description 针对表【work_shop_file(车间附件名称)】的数据库操作Service实现 |
| | |
| | | @Service |
| | | public class WorkShopFileServiceImpl extends ServiceImpl<WorkShopFileMapper, WorkShopFile> implements WorkShopFileService { |
| | | |
| | | @Resource |
| | | private WorkShopFileMapper workShopFileMapper; |
| | | |
| | | @Resource |
| | | private MinioUtils minioUtils; |
| | | |
| | | @Value("${minio.bucketName}") |
| | | private String bucketName; |
| | | |
| | | @Override |
| | | public int delFile(Integer id) { |
| | | // 若 id 为空,直接返回 0,表示未删除任何记录 |
| | | if (id == null) { |
| | | return 0; |
| | | } |
| | | try { |
| | | // 查询要删除的文件信息 |
| | | WorkShopFile file = workShopFileMapper.selectById(id); |
| | | if (file != null && file.getFileUrl() != null) { |
| | | // 检查 MinIO 中文件是否存在 |
| | | if (minioUtils.objectExists(bucketName, file.getFileUrl())) { |
| | | // 先删除 MinIO 中的对象 |
| | | minioUtils.removeObjectsResult(bucketName, file.getFileUrl()); |
| | | } |
| | | } |
| | | // 执行数据库删除操作 |
| | | int deleteResult = workShopFileMapper.deleteById(id); |
| | | return deleteResult; |
| | | } catch (Exception e) { |
| | | // 处理异常,可根据实际情况记录日志或抛出自定义异常 |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |