package com.ruoyi.production.service.impl; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.production.pojo.ProductionProductRouteItemFile; import com.ruoyi.production.mapper.ProductionProductRouteItemFileMapper; import com.ruoyi.production.service.IProductionProductRouteItemFileService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.nio.file.Files; /** *

* 生产报工记录的工序附件表 服务实现类 *

* * @author deslrey * @since 2026-03-23 */ @Slf4j @Service public class ProductionProductRouteItemFileServiceImpl extends ServiceImpl implements IProductionProductRouteItemFileService { @Override @Transactional(rollbackFor = Exception.class) public void deleteFile(Long fileId) { if (fileId == null) { throw new ServiceException("附件删除失败,数据不能为空"); } ProductionProductRouteItemFile productionProductRouteItemFile = baseMapper.selectById(fileId); if (productionProductRouteItemFile == null) { throw new ServiceException("附件删除失败,附件不存在"); } String fileUrl = productionProductRouteItemFile.getFileUrl(); if (fileUrl != null) { try { java.nio.file.Path path = java.nio.file.Paths.get(fileUrl); if (Files.exists(path)) { Files.delete(path); } else { log.warn("文件不存在,无需删除: {}", fileUrl); } } catch (Exception e) { log.error("删除文件失败: {}", fileUrl, e); throw new ServiceException("附件删除失败,物理文件删除异常"); } } int result = baseMapper.deleteById(fileId); if (result == 0) { throw new ServiceException("附件删除失败,数据库删除失败"); } } }