| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.MinioResult; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.utils.LimsDateUtil; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.InspectionPurchasedDto; |
| | | import com.ruoyi.inspect.mapper.InspectionPurchasedMapper; |
| | | import com.ruoyi.inspect.pojo.InspectionPurchased; |
| | | import com.ruoyi.inspect.service.InspectionPurchasedService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.Setter; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2025-03-25 11:22:56 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @Setter |
| | | public class InspectionPurchasedServiceImpl extends ServiceImpl<InspectionPurchasedMapper, InspectionPurchased> implements InspectionPurchasedService { |
| | | |
| | | @Resource |
| | | private InspectionPurchasedMapper inspectionPurchasedMapper; |
| | | private final InspectionPurchasedMapper inspectionPurchasedMapper; |
| | | |
| | | @Resource |
| | | private MinioUtils minioUtils; |
| | | private final MinioUtils minioUtils; |
| | | |
| | | private final NumberGenerator<InspectionPurchased> numberGenerator; |
| | | |
| | | @Value("${minio.bucketName}") |
| | | private String bucketName; |
| | |
| | | public int addOrUpdateInspection(InspectionPurchasedDto inspectionPurchasedDto) { |
| | | if (inspectionPurchasedDto.getId() == null) { |
| | | inspectionPurchasedDto.setInspectionStatus(String.valueOf(0)); |
| | | |
| | | //委托编号规则是JCZX/SP+W+年月+序号 |
| | | String no = numberGenerator.generateNumberWithPrefix(3, |
| | | "JCZX/SP-" + "W" + LimsDateUtil.resetDate(LocalDateTime.now()), |
| | | InspectionPurchased::getEntrustmentNo); |
| | | inspectionPurchasedDto.setEntrustmentNo(no); |
| | | return inspectionPurchasedMapper.insert(inspectionPurchasedDto); |
| | | } else { |
| | | return inspectionPurchasedMapper.updateById(inspectionPurchasedDto); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int UpdateInspection(InspectionPurchasedDto inspectionPurchasedDto) throws Exception { |
| | | int insertResult = 0; |
| | | InspectionPurchased inspectionPurchased = inspectionPurchasedMapper.selectById(inspectionPurchasedDto.getId()); |
| | | if (ObjectUtils.isNotEmpty(inspectionPurchasedDto.getFile())) { |
| | | public int updateInspection(MultipartFile file, Integer id, String inspectionItems, String result) throws Exception { |
| | | InspectionPurchased inspectionPurchased = inspectionPurchasedMapper.selectById(id); |
| | | inspectionPurchased.setInspectionStatus(String.valueOf(2)); |
| | | inspectionPurchased.setInspectionItems(inspectionItems); |
| | | inspectionPurchased.setResult(result); |
| | | // 检查文件是否存在 |
| | | if (file != null && !ObjectUtils.isEmpty(file)) { |
| | | if (ObjectUtils.isNotEmpty(inspectionPurchased.getFileUrl())){ |
| | | if (inspectionPurchased != null && inspectionPurchased.getFileUrl() != null) { |
| | | // 检查 MinIO 中文件是否存在 |
| | |
| | | } |
| | | } |
| | | try { |
| | | String contentType = inspectionPurchasedDto.getFile().getContentType(); |
| | | String contentType = file.getContentType(); |
| | | String category = contentType != null && contentType.startsWith("image/") ? "images" : "docs"; |
| | | MinioResult upload = minioUtils.upload(bucketName, inspectionPurchasedDto.getFile(), true); |
| | | MinioResult upload = minioUtils.upload(bucketName, file, true); |
| | | // 记录存储路径 |
| | | inspectionPurchased.setFileUrl(upload.getBucketFileName()); |
| | | inspectionPurchased.setFilePreviewUrl(upload.getPreviewExpiry()); |
| | | inspectionPurchased.setType(category.equals("images") ? 1 : 2); |
| | | // 数据库操作 |
| | | insertResult = inspectionPurchasedMapper.updateById(inspectionPurchased); |
| | | if (insertResult <= 0) { |
| | | throw new ErrorException("数据库插入失败"); |
| | | } |
| | | return insertResult; |
| | | inspectionPurchased.setFileName(upload.getOriginalName()); |
| | | } catch (Exception e) { |
| | | throw new Exception("系统异常: ", e); |
| | | } |
| | | } |
| | | return insertResult; |
| | | return inspectionPurchasedMapper.updateById(inspectionPurchased); |
| | | } |
| | | } |