chenrui
2025-04-03 cf396d3076a064998fbac84f76861f5ed918c5e5
basic-server/src/main/java/com/ruoyi/basic/service/impl/WorkShopFileServiceImpl.java
@@ -1,11 +1,15 @@
package com.ruoyi.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.WorkShopFileMapper;
import com.ruoyi.basic.pojo.WorkShopFile;
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.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -22,10 +26,21 @@
    private WorkShopFileMapper workShopFileMapper;
    @Resource
    private ProductPartMapper productPartMapper;
    @Resource
    private ProductMapper productMapper;
    @Resource
    private StructureTestObjectPartMapper structureTestObjectPartMapper;
    @Resource
    private StructureTestObjectMapper structureTestObjectMapper;
    @Resource
    private MinioUtils minioUtils;
    @Value("${minio.bucketName}")
    private String bucketName;
    @Autowired
    private MinioConfig minioConfig;
    @Override
    public int delFile(Integer id) {
@@ -38,9 +53,9 @@
            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());
                }
            }
            // 执行数据库删除操作
@@ -52,6 +67,30 @@
            return 0;
        }
    }
    @Override
    public IPage<WorkShopFile> partFileList(Page page, String partNo) {
        StructureTestObject structureTestObject = findStructureTestObjectByPartNo(partNo);
        if (structureTestObject != null && structureTestObject.getWorkShopId() != null) {
            return workShopFileMapper.selectPage(page, new LambdaQueryWrapper<WorkShopFile>().eq(WorkShopFile::getWorkShopId, structureTestObject.getWorkShopId()));
        }
        return null;
    }
    private StructureTestObject findStructureTestObjectByPartNo(String partNo) {
        ProductPart productPart = productPartMapper.selectOne(new LambdaQueryWrapper<ProductPart>().eq(ProductPart::getPartNo, partNo));
        if (productPart != null) {
            Product product = productMapper.selectById(productPart.getProductId());
            if (product != null) {
                return structureTestObjectMapper.selectById(product.getObjectId());
            }
        }
        StructureTestObjectPart structureTestObjectPart = structureTestObjectPartMapper.selectOne(new LambdaQueryWrapper<StructureTestObjectPart>().eq(StructureTestObjectPart::getPartNo, partNo));
        if (structureTestObjectPart != null) {
            return structureTestObjectMapper.selectById(structureTestObjectPart.getTestObjectId());
        }
        return null;
    }
}