| | |
| | | package com.ruoyi.device.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.common.enums.FileNameType; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceDefectRecordDto; |
| | |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.device.service.IDeviceRepairService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.other.service.TempFileService; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | private DeviceRepairMapper deviceRepairMapper; |
| | | @Autowired |
| | | private IDeviceLedgerService deviceLedgerService; |
| | | |
| | | @Autowired |
| | | private CommonFileMapper commonFileMapper; |
| | | |
| | | @Autowired |
| | | private TempFileService tempFileService; |
| | | |
| | | @Override |
| | | public IPage<DeviceRepairDto> queryPage(Page page, DeviceRepairDto deviceRepairDto) { |
| | | |
| | |
| | | return deviceRepairMapper.detailById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void uploadFile(MultipartFile file, Long deviceRepairId) { |
| | | if (file == null || file.isEmpty()) { |
| | | throw new ServiceException("上传失败,文件不能为空"); |
| | | } |
| | | if (deviceRepairId == null || deviceRepairId <= 0) { |
| | | throw new ServiceException("上传失败,设备报修ID不能为空"); |
| | | } |
| | | |
| | | try { |
| | | tempFileService.uploadByCommon(file, FileNameType.EQUIPMENT_WARRANTY.getValue(), deviceRepairId); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("上传失败," + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<CommonFile> getFiles(Long deviceRepairId) { |
| | | if (deviceRepairId == null || deviceRepairId <= 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | return commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .eq(CommonFile::getCommonId, deviceRepairId) |
| | | .eq(CommonFile::getType, FileNameType.EQUIPMENT_WARRANTY.getValue())); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteFile(Long fileId) { |
| | | if (fileId == null || fileId <= 0) { |
| | | throw new ServiceException("删除失败,传入数据异常"); |
| | | } |
| | | CommonFile commonFile = commonFileMapper.selectById(fileId); |
| | | if (commonFile == null) { |
| | | throw new ServiceException("删除失败,文件不存在"); |
| | | } |
| | | try { |
| | | if (commonFile.getUrl() != null && !commonFile.getUrl().isEmpty()) { |
| | | Files.deleteIfExists(Paths.get(commonFile.getUrl())); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("设备保修文件删除失败: {}", e.getMessage()); |
| | | throw new ServiceException("删除失败," + e.getMessage()); |
| | | } |
| | | commonFileMapper.deleteById(fileId); |
| | | } |
| | | } |