forked from dyf/fys-Multi-tenant
Merge branch 'main' into dyf-device
This commit is contained in:
@ -11,6 +11,8 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -70,4 +72,6 @@ public class DeviceRepairRecordsBo extends BaseEntity {
|
||||
@Schema(title = "维修后图片")
|
||||
@JsonIgnore
|
||||
private MultipartFile afterFile;
|
||||
|
||||
private List<Long> imageIds;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
@ -51,8 +52,10 @@ public class DeviceRepairRecordsQueryCriteria extends BaseEntity {
|
||||
private String repairPerson;
|
||||
|
||||
@Schema(title = "维修开始时间")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date repairBeginTime;
|
||||
@Schema(title = "维修结束时间")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date repairEndTime;
|
||||
|
||||
@Schema(title = "所属客户")
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.fuyuanshen.equipment.utils;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/**
|
||||
* 文件哈希工具类
|
||||
*/
|
||||
public class FileHashUtil {
|
||||
private static final String ALGORITHM = "SHA-256";
|
||||
|
||||
public static String hash(MultipartFile file) throws IOException {
|
||||
MessageDigest digest = DigestUtils.getDigest(ALGORITHM);
|
||||
try (InputStream in = file.getInputStream()) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
digest.update(buf, 0, len);
|
||||
}
|
||||
}
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
FROM device_repair_records dr
|
||||
JOIN device d ON dr.device_id = d.id
|
||||
<where>
|
||||
<if test="criteria.searchValue != null">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.searchValue}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceId != null">
|
||||
and dr.device_id = #{criteria.deviceId}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user