Merge branch 'main' into dyf-device
This commit is contained in:
@ -18,6 +18,7 @@ import com.fuyuanshen.equipment.domain.vo.DeviceRepairImagesVo;
|
||||
import com.fuyuanshen.equipment.enums.RepairImageType;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceRepairImagesMapper;
|
||||
import com.fuyuanshen.equipment.utils.FileHashUtil;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -32,6 +33,7 @@ import com.fuyuanshen.equipment.service.IDeviceRepairRecordsService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -178,6 +180,10 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
// 3. 删除旧图片
|
||||
if(bo.getImageIds() != null){
|
||||
imagesMapper.deleteByIds(bo.getImageIds());
|
||||
}
|
||||
|
||||
// 3. 收集需要保存的图片
|
||||
List<DeviceRepairImages> images = new ArrayList<>(2);
|
||||
@ -200,12 +206,28 @@ public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairReco
|
||||
if (file == null || file.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SysOssVo ossVo = ossService.upload(file);
|
||||
|
||||
// 1. 计算文件哈希
|
||||
String hash = null;
|
||||
try {
|
||||
hash = FileHashUtil.hash(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 2. 先根据 hash 查库(秒传)
|
||||
SysOssVo exist = ossService.selectByHash(hash);
|
||||
if (exist == null) {
|
||||
// 2.2 不存在,真正上传
|
||||
exist = ossService.upload(file);
|
||||
// 2.3 把 hash 写回记录(供下次去重)
|
||||
ossService.updateHashById(exist.getOssId(), hash);
|
||||
}
|
||||
|
||||
DeviceRepairImages image = new DeviceRepairImages();
|
||||
image.setRecordId(recordId);
|
||||
image.setImageType(imageType);
|
||||
image.setImageUrl(ossVo.getUrl());
|
||||
image.setImageUrl(exist.getUrl());
|
||||
|
||||
list.add(image);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user