batch customer event
This commit is contained in:
+2
-2
@@ -79,8 +79,8 @@ public class GaoRegistrationEventRecordController {
|
||||
@RequestRateLimit
|
||||
@PostMapping("/create")
|
||||
@JsonView(ResponseView.Public.class)
|
||||
public GaoRegistrationEventRecord create(@RequestBody GaoRegistrationEventRecordCreateReq req) {
|
||||
return service.createRecord(req);
|
||||
public List<GaoRegistrationEventRecord> create(@RequestBody GaoRegistrationEventRecordCreateReq req) {
|
||||
return service.createRecords(req);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
|
||||
+4
-4
@@ -26,11 +26,11 @@ import java.util.List;
|
||||
/// @since 2026-07-27
|
||||
public interface GaoRegistrationEventRecordService extends BaseService<GaoRegistrationEventRecord, String> {
|
||||
|
||||
/// 创建登记事件记录
|
||||
/// 批量创建登记事件记录
|
||||
///
|
||||
/// @param req 创建请求
|
||||
/// @return 创建后的登记事件记录
|
||||
GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req);
|
||||
/// @param req 批量创建请求
|
||||
/// @return 创建后的登记事件记录列表
|
||||
List<GaoRegistrationEventRecord> createRecords(GaoRegistrationEventRecordCreateReq req);
|
||||
|
||||
/// 快速录入客户并创建登记事件记录
|
||||
///
|
||||
|
||||
+72
-19
@@ -53,6 +53,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@@ -102,14 +103,24 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) {
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_RECORD_CREATE");
|
||||
public List<GaoRegistrationEventRecord> createRecords(GaoRegistrationEventRecordCreateReq req) {
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_RECORD_BATCH_CREATE");
|
||||
try {
|
||||
TimiException.required(req, "not found req");
|
||||
TimiException.requiredTrue(req.getCustomerIdList() != null && !req.getCustomerIdList().isEmpty(), "customerIdList is empty");
|
||||
logger.setContent(jackson.writeValueAsString(req));
|
||||
GaoRegistrationEventRecord record = doCreateRecord(req);
|
||||
List<GaoRegistrationEventRecord> recordList = new ArrayList<>();
|
||||
for (int index = 0; index < req.getCustomerIdList().size(); index++) {
|
||||
String customerId = req.getCustomerIdList().get(index);
|
||||
GaoRegistrationEventRecordCreateReq customerReq = copyCreateReq(req);
|
||||
customerReq.setAttachmentIdList(0 == index && canUseSourceTempFileList(req.getAttachmentIdList())
|
||||
? req.getAttachmentIdList()
|
||||
: duplicateTempFileList(req.getAttachmentIdList()));
|
||||
recordList.add(doCreateRecord(customerReq, customerId));
|
||||
}
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(record.getId());
|
||||
return record;
|
||||
logger.setResult(recordList.stream().map(GaoRegistrationEventRecord::getId).collect(Collectors.joining(",")));
|
||||
return recordList;
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
@@ -117,13 +128,59 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("新增 GAO 登记记录失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "新增 GAO 登记记录失败", e);
|
||||
log.error("批量新增 GAO 登记记录失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "批量新增 GAO 登记记录失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> duplicateTempFileList(List<String> sourceIdList) {
|
||||
if (sourceIdList == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> targetIdList = new ArrayList<>();
|
||||
for (String sourceId : sourceIdList) {
|
||||
if (sourceId == null || sourceId.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Attachment source = attachmentService.get(sourceId.trim());
|
||||
TimiException.required(source, "not found attachment");
|
||||
TimiException.required(source.getMongoId(), "not found attachment.mongoId");
|
||||
Attachment target = new Attachment();
|
||||
target.setBizType(Attachment.BizType.TEMP_FILE);
|
||||
target.setName(source.getName());
|
||||
target.setInputStream(new ByteArrayInputStream(attachmentService.readAllByMongoId(source.getMongoId())));
|
||||
attachmentService.create(target);
|
||||
targetIdList.add(target.getId());
|
||||
}
|
||||
return targetIdList;
|
||||
}
|
||||
|
||||
private boolean canUseSourceTempFileList(List<String> sourceIdList) {
|
||||
if (sourceIdList == null || sourceIdList.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (String sourceId : sourceIdList) {
|
||||
if (sourceId == null || sourceId.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Attachment source = attachmentService.get(sourceId.trim());
|
||||
if (source == null || source.getBizType() != Attachment.BizType.TEMP_FILE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private GaoRegistrationEventRecordCreateReq copyCreateReq(GaoRegistrationEventRecordCreateReq source) {
|
||||
GaoRegistrationEventRecordCreateReq target = new GaoRegistrationEventRecordCreateReq();
|
||||
target.setRegistrationEventId(source.getRegistrationEventId());
|
||||
target.setRemark(source.getRemark());
|
||||
target.setRegisteredAt(source.getRegisteredAt());
|
||||
return target;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) {
|
||||
@@ -135,11 +192,11 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||
GaoCustomer customer = customerService.getOrQuickCreateByCode(req.getCustomerCode());
|
||||
GaoRegistrationEventRecordCreateReq recordReq = new GaoRegistrationEventRecordCreateReq();
|
||||
recordReq.setCustomerId(customer.getId());
|
||||
recordReq.setCustomerIdList(List.of(customer.getId()));
|
||||
recordReq.setRegistrationEventId(req.getRegistrationEventId());
|
||||
recordReq.setRemark(req.getRemark());
|
||||
recordReq.setAttachmentIdList(req.getAttachmentIdList());
|
||||
GaoRegistrationEventRecord record = doCreateRecord(recordReq);
|
||||
GaoRegistrationEventRecord record = createRecords(recordReq).get(0);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(record.getId());
|
||||
return record;
|
||||
@@ -344,20 +401,16 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
return list;
|
||||
}
|
||||
|
||||
private String resolveCustomerId(GaoRegistrationEventRecordCreateReq req) {
|
||||
if (TimiJava.isNotEmpty(req.getCustomerId())) {
|
||||
customerService.get(req.getCustomerId());
|
||||
return req.getCustomerId();
|
||||
}
|
||||
TimiException.required(req.getCustomerCode(), "not found req.customerCode");
|
||||
GaoCustomer customer = customerService.getByCode(req.getCustomerCode());
|
||||
return customer.getId();
|
||||
private String resolveCustomerId(String customerId) {
|
||||
TimiException.required(customerId, "not found customerId");
|
||||
customerService.get(customerId);
|
||||
return customerId;
|
||||
}
|
||||
|
||||
private GaoRegistrationEventRecord doCreateRecord(GaoRegistrationEventRecordCreateReq req) {
|
||||
private GaoRegistrationEventRecord doCreateRecord(GaoRegistrationEventRecordCreateReq req, String customerId) {
|
||||
TimiException.required(req, "not found req");
|
||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||
String customerId = resolveCustomerId(req);
|
||||
customerId = resolveCustomerId(customerId);
|
||||
GaoRegistrationEvent registrationEvent = registrationEventService.get(req.getRegistrationEventId());
|
||||
checkRegistrationEventPermission(registrationEvent);
|
||||
long registeredAt = TimiJava.defaultIfNull(req.getRegisteredAt(), Time.now());
|
||||
|
||||
+2
-5
@@ -13,11 +13,8 @@ import java.util.List;
|
||||
@Data
|
||||
public class GaoRegistrationEventRecordCreateReq {
|
||||
|
||||
/// 客户 ID
|
||||
private String customerId;
|
||||
|
||||
/// 客户编码,扫码登记可直接传这个
|
||||
private String customerCode;
|
||||
/// 客户 ID 列表,批量登记时使用
|
||||
private List<String> customerIdList = new ArrayList<>();
|
||||
|
||||
/// 登记事件 ID
|
||||
private String registrationEventId;
|
||||
|
||||
Reference in New Issue
Block a user