fix require photo event

This commit is contained in:
Timi
2026-08-30 01:25:22 +08:00
parent 94c99e3444
commit c85b400a94
@@ -43,7 +43,9 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/// 登记事件记录服务实现
///
@@ -126,6 +128,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
TimiException.required(event, "not found event");
TimiException.required(event.getStoreId(), "not found event.storeId");
verifyRecordValue(event, record.getNumberValue());
verifyRecordAttachment(event, record.getAttachmentList());
// 检查权限
checkEventPermission(event);
int registeredDateValue = dateValue(registeredAt);
@@ -199,11 +202,25 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void createBatch(List<GaoEventRecord> recordList) {
Set<String> usedTempFileIdSet = new HashSet<>();
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
TimiException.required(record, "not found record");
prepareBatchAttachments(record, usedTempFileIdSet);
create(record);
}
}
private void prepareBatchAttachments(GaoEventRecord record, Set<String> usedTempFileIdSet) {
for (Attachment attachment : TimiJava.safeIterable(record.getAttachmentList())) {
if (attachment == null || TimiJava.isEmpty(attachment.getTempFileId()) || usedTempFileIdSet.add(attachment.getTempFileId())) {
continue;
}
Attachment clone = attachmentService.clone(attachment.getTempFileId());
TimiException.required(clone.getId(), "登记照片临时附件复制失败");
attachment.setTempFileId(clone.getId());
}
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void update(GaoEventRecord record) {
@@ -221,6 +238,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
GaoEvent event = eventService.get(dbRecord.getEventId());
TimiException.required(event, "not found event");
TimiException.required(event.getStoreId(), "not found event.storeId");
verifyRecordAttachment(event, record.getAttachmentList());
checkEventPermission(event);
dbRecord.setRemark(record.getRemark());
super.update(dbRecord);
@@ -414,6 +432,20 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
}
}
private void verifyRecordAttachment(GaoEvent event, List<Attachment> attachmentList) {
if (!Boolean.TRUE.equals(event.getRequirePhoto())) {
return;
}
boolean hasPhoto = false;
for (Attachment attachment : TimiJava.safeIterable(attachmentList)) {
if (attachment != null && (attachment.getAttachType() == null || GaoEventRecord.AttachType.PHOTO.name().equalsIgnoreCase(attachment.getAttachType()))) {
hasPhoto = true;
break;
}
}
TimiException.requiredTrue(hasPhoto, "该事件必须上传照片");
}
private void verifyImmutableRecordFields(GaoEventRecord request, GaoEventRecord dbRecord) {
TimiException.requiredTrue(request.getCustomerId() == null || request.getCustomerId().equals(dbRecord.getCustomerId()), "登记记录 customerId 创建后不可修改");
TimiException.requiredTrue(request.getEventId() == null || request.getEventId().equals(dbRecord.getEventId()), "登记记录 eventId 创建后不可修改");