v0.0.18 #13

Merged
timi merged 9 commits from dev into master 2026-08-03 11:58:16 +00:00
9 changed files with 425 additions and 116 deletions
Showing only changes of commit 20289a3168 - Show all commits
@@ -46,8 +46,8 @@ public class TempFileServiceImplement implements TempFileService {
public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException { public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException {
Logger logger = new Logger(); Logger logger = new Logger();
logger.setModule("TEMP_FILE"); logger.setModule(Logger.Module.COMMON);
logger.setOperation("STORE"); logger.setOperation("TEMP_FILE_STORE");
logger.setIp(TimiSpring.getRequestIP()); logger.setIp(TimiSpring.getRequestIP());
try { try {
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl))); logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
@@ -116,8 +116,8 @@ public class TempFileServiceImplement implements TempFileService {
@Override @Override
public void save(TempFileSaveReq request) { public void save(TempFileSaveReq request) {
Logger logger = new Logger(); Logger logger = new Logger();
logger.setModule("TEMP_FILE"); logger.setModule(Logger.Module.COMMON);
logger.setOperation("SAVE"); logger.setOperation("TEMP_FILE_SAVE");
logger.setIp(TimiSpring.getRequestIP()); logger.setIp(TimiSpring.getRequestIP());
try { try {
logger.setContent(jackson.writeValueAsString(request)); logger.setContent(jackson.writeValueAsString(request));
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.service.implement; package com.imyeyu.api.modules.gao.service.implement;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig; import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.common.entity.Attachment; import com.imyeyu.api.modules.common.entity.Attachment;
import com.imyeyu.api.modules.common.service.AttachmentService; import com.imyeyu.api.modules.common.service.AttachmentService;
@@ -7,21 +8,25 @@ import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
import com.imyeyu.api.modules.gao.entity.GaoCustomer; import com.imyeyu.api.modules.gao.entity.GaoCustomer;
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper; import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
import com.imyeyu.api.modules.gao.service.GaoCustomerService; import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView; import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView; import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq; import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq; import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq; import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.java.TimiJava; import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode; import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.bean.Page; import com.imyeyu.spring.bean.Page;
import com.imyeyu.spring.bean.PageResult; import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService; import com.imyeyu.spring.service.AbstractEntityService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
@@ -50,6 +55,7 @@ import java.util.stream.Collectors;
/// ///
/// @author Codex /// @author Codex
/// @since 2026-07-27 /// @since 2026-07-27
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService { public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService {
@@ -58,7 +64,9 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()); private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
private final GaoCustomerMapper mapper; private final GaoCustomerMapper mapper;
private final ObjectMapper jackson;
private final AttachmentService attachmentService; private final AttachmentService attachmentService;
private final LoggerService loggerService;
private final UserLoginService userLoginService; private final UserLoginService userLoginService;
private final UserService userService; private final UserService userService;
@@ -69,29 +77,80 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
@Override @Override
public void create(GaoCustomer entity) { public void create(GaoCustomer entity) {
checkEntity(entity, false); Logger logger = buildLogger("GAO_CUSTOMER_CREATE");
entity.setCreatorUserId(userLoginService.getRequireLoginUserId()); try {
entity.setInvitedCount(0L); logger.setContent(jackson.writeValueAsString(entity));
super.create(entity); checkEntity(entity, false);
saveAttachment(entity.getId(), resolveAttachmentList(entity)); entity.setCreatorUserId(userLoginService.getRequireLoginUserId());
changeInvitedCount(entity.getIntroducerCustomerId(), 1L); entity.setInvitedCount(0L);
loadDetailTransient(entity); super.create(entity);
saveAttachment(entity.getId(), resolveAttachmentList(entity));
changeInvitedCount(entity.getIntroducerCustomerId(), 1L);
loadDetailTransient(entity);
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("新增 GAO 客户失败", e);
throw new TimiException(TimiCode.ERROR, "新增 GAO 客户失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
public void update(GaoCustomer entity) { public void update(GaoCustomer entity) {
GaoCustomer dbCustomer = checkEntity(entity, true); Logger logger = buildLogger("GAO_CUSTOMER_UPDATE");
super.update(entity); try {
saveAttachment(entity.getId(), resolveAttachmentList(entity)); logger.setContent(jackson.writeValueAsString(entity));
syncIntroducerInvitedCount(dbCustomer.getIntroducerCustomerId(), entity.getIntroducerCustomerId()); GaoCustomer dbCustomer = checkEntity(entity, true);
super.update(entity);
saveAttachment(entity.getId(), resolveAttachmentList(entity));
syncIntroducerInvitedCount(dbCustomer.getIntroducerCustomerId(), entity.getIntroducerCustomerId());
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("修改 GAO 客户失败", e);
throw new TimiException(TimiCode.ERROR, "修改 GAO 客户失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void delete(String id) { public void delete(String id) {
GaoCustomer customer = super.get(id); Logger logger = buildLogger("GAO_CUSTOMER_DELETE");
super.delete(id); try {
changeInvitedCount(customer.getIntroducerCustomerId(), -1L); logger.setContent(id);
GaoCustomer customer = super.get(id);
super.delete(id);
changeInvitedCount(customer.getIntroducerCustomerId(), -1L);
logger.setLevel(Logger.Level.INFO);
logger.setResult(id);
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("删除 GAO 客户失败", e);
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
@@ -215,25 +274,59 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void saveInviteRelation(GaoCustomerInviteUpdateReq req) { public void saveInviteRelation(GaoCustomerInviteUpdateReq req) {
TimiException.required(req, "not found invite req"); Logger logger = buildLogger("GAO_CUSTOMER_SAVE_INVITE_RELATION");
TimiException.required(req.getCustomerId(), "not found invite req.customerId"); try {
GaoCustomer customer = super.get(req.getCustomerId()); logger.setContent(jackson.writeValueAsString(req));
String oldIntroducerCustomerId = customer.getIntroducerCustomerId(); TimiException.required(req, "not found invite req");
customer.setIntroducerCustomerId(req.getIntroducerCustomerId()); TimiException.required(req.getCustomerId(), "not found invite req.customerId");
checkEntity(customer, true); GaoCustomer customer = super.get(req.getCustomerId());
super.update(customer); String oldIntroducerCustomerId = customer.getIntroducerCustomerId();
syncIntroducerInvitedCount(oldIntroducerCustomerId, customer.getIntroducerCustomerId()); customer.setIntroducerCustomerId(req.getIntroducerCustomerId());
checkEntity(customer, true);
super.update(customer);
syncIntroducerInvitedCount(oldIntroducerCustomerId, customer.getIntroducerCustomerId());
logger.setLevel(Logger.Level.INFO);
logger.setResult(req.getCustomerId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("保存 GAO 客户邀请关系失败", e);
throw new TimiException(TimiCode.ERROR, "保存 GAO 客户邀请关系失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void deleteInviteRelation(String customerId) { public void deleteInviteRelation(String customerId) {
TimiException.required(customerId, "not found customerId"); Logger logger = buildLogger("GAO_CUSTOMER_DELETE_INVITE_RELATION");
GaoCustomer customer = super.get(customerId); try {
String oldIntroducerCustomerId = customer.getIntroducerCustomerId(); logger.setContent(customerId);
customer.setIntroducerCustomerId(null); TimiException.required(customerId, "not found customerId");
super.update(customer); GaoCustomer customer = super.get(customerId);
changeInvitedCount(oldIntroducerCustomerId, -1L); String oldIntroducerCustomerId = customer.getIntroducerCustomerId();
customer.setIntroducerCustomerId(null);
super.update(customer);
changeInvitedCount(oldIntroducerCustomerId, -1L);
logger.setLevel(Logger.Level.INFO);
logger.setResult(customerId);
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("删除 GAO 客户邀请关系失败", e);
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户邀请关系失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
@@ -453,4 +546,12 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
private String text(Object value) { private String text(Object value) {
return value == null ? "" : value.toString(); return value == null ? "" : value.toString();
} }
private Logger buildLogger(String operation) {
Logger logger = new Logger();
logger.setModule(Logger.Module.GAO);
logger.setOperation(operation);
logger.setIp(TimiSpring.getRequestIP());
return logger;
}
} }
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.service.implement; package com.imyeyu.api.modules.gao.service.implement;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig; import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.bean.ModuleCode; import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.modules.common.entity.Attachment; import com.imyeyu.api.modules.common.entity.Attachment;
@@ -25,18 +26,23 @@ import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq; import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq; import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq; import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.service.RoleChecker; import com.imyeyu.api.modules.user.service.RoleChecker;
import com.imyeyu.api.modules.user.service.UserLoginService; import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserService; import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.api.modules.user.mapper.UserMapper; import com.imyeyu.api.modules.user.mapper.UserMapper;
import com.imyeyu.java.TimiJava; import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.bean.Page; import com.imyeyu.spring.bean.Page;
import com.imyeyu.spring.bean.PageResult; import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService; import com.imyeyu.spring.service.AbstractEntityService;
import com.imyeyu.utils.Time; import com.imyeyu.utils.Time;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
@@ -68,6 +74,7 @@ import java.util.stream.Collectors;
/// ///
/// @author Codex /// @author Codex
/// @since 2026-07-27 /// @since 2026-07-27
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class GaoRegistrationEventRecordServiceImplement extends AbstractEntityService<GaoRegistrationEventRecord, String> implements GaoRegistrationEventRecordService { public class GaoRegistrationEventRecordServiceImplement extends AbstractEntityService<GaoRegistrationEventRecord, String> implements GaoRegistrationEventRecordService {
@@ -76,10 +83,12 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()); private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
private final GaoRegistrationEventRecordMapper mapper; private final GaoRegistrationEventRecordMapper mapper;
private final ObjectMapper jackson;
private final GaoCustomerMapper customerMapper; private final GaoCustomerMapper customerMapper;
private final GaoRegistrationEventMapper registrationEventMapper; private final GaoRegistrationEventMapper registrationEventMapper;
private final UserMapper userMapper; private final UserMapper userMapper;
private final AttachmentService attachmentService; private final AttachmentService attachmentService;
private final LoggerService loggerService;
private final RoleChecker roleChecker; private final RoleChecker roleChecker;
private final UserLoginService userLoginService; private final UserLoginService userLoginService;
private final UserService userService; private final UserService userService;
@@ -94,56 +103,90 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) { public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) {
TimiException.required(req, "not found req"); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_CREATE");
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId"); try {
String customerId = resolveCustomerId(req); logger.setContent(jackson.writeValueAsString(req));
GaoRegistrationEvent registrationEvent = registrationEventService.get(req.getRegistrationEventId()); GaoRegistrationEventRecord record = doCreateRecord(req);
checkRegistrationEventPermission(registrationEvent); logger.setLevel(Logger.Level.INFO);
long registeredAt = TimiJava.defaultIfNull(req.getRegisteredAt(), Time.now()); logger.setResult(record.getId());
checkRegistrationEventCreatable(registrationEvent, customerId, registeredAt); return record;
if (Boolean.TRUE.equals(registrationEvent.getRequirePhoto())) { } catch (TimiException e) {
TimiException.requiredTrue(req.getAttachmentIdList() != null && !req.getAttachmentIdList().isEmpty(), "required record photo"); logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("新增 GAO 登记记录失败", e);
throw new TimiException(TimiCode.ERROR, "新增 GAO 登记记录失败", e);
} finally {
loggerService.create(logger);
} }
GaoRegistrationEventRecord record = new GaoRegistrationEventRecord();
record.setCustomerId(customerId);
record.setRegistrationEventId(req.getRegistrationEventId());
record.setOperatorUserId(userLoginService.getRequireLoginUserId());
record.setRemark(req.getRemark());
record.setRegisteredAt(registeredAt);
super.create(record);
saveAttachment(record.getId(), buildPhotoAttachmentList(req.getAttachmentIdList()));
return get(record.getId());
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) { public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) {
TimiException.required(req, "not found req"); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_QUICK_REGISTER");
TimiException.required(req.getCustomerCode(), "not found req.customerCode"); try {
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId"); logger.setContent(jackson.writeValueAsString(req));
GaoCustomer customer = customerService.getOrQuickCreateByCode(req.getCustomerCode()); TimiException.required(req, "not found req");
GaoRegistrationEventRecordCreateReq recordReq = new GaoRegistrationEventRecordCreateReq(); TimiException.required(req.getCustomerCode(), "not found req.customerCode");
recordReq.setCustomerId(customer.getId()); TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
recordReq.setRegistrationEventId(req.getRegistrationEventId()); GaoCustomer customer = customerService.getOrQuickCreateByCode(req.getCustomerCode());
recordReq.setRemark(req.getRemark()); GaoRegistrationEventRecordCreateReq recordReq = new GaoRegistrationEventRecordCreateReq();
recordReq.setAttachmentIdList(req.getAttachmentIdList()); recordReq.setCustomerId(customer.getId());
return createRecord(recordReq); recordReq.setRegistrationEventId(req.getRegistrationEventId());
recordReq.setRemark(req.getRemark());
recordReq.setAttachmentIdList(req.getAttachmentIdList());
GaoRegistrationEventRecord record = doCreateRecord(recordReq);
logger.setLevel(Logger.Level.INFO);
logger.setResult(record.getId());
return record;
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("GAO 快速登记失败", e);
throw new TimiException(TimiCode.ERROR, "GAO 快速登记失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void update(GaoRegistrationEventRecord entity) { public void update(GaoRegistrationEventRecord entity) {
TimiException.required(entity, "not found record"); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_UPDATE");
TimiException.required(entity.getId(), "not found record.id"); try {
TimiException.required(entity.getCustomerId(), "not found record.customerId"); logger.setContent(jackson.writeValueAsString(entity));
TimiException.required(entity.getRegistrationEventId(), "not found record.registrationEventId"); TimiException.required(entity, "not found record");
customerService.get(entity.getCustomerId()); TimiException.required(entity.getId(), "not found record.id");
GaoRegistrationEvent registrationEvent = registrationEventService.get(entity.getRegistrationEventId()); TimiException.required(entity.getCustomerId(), "not found record.customerId");
checkRegistrationEventPermission(registrationEvent); TimiException.required(entity.getRegistrationEventId(), "not found record.registrationEventId");
entity.setRegisteredAt(TimiJava.defaultIfNull(entity.getRegisteredAt(), Time.now())); customerService.get(entity.getCustomerId());
super.update(entity); GaoRegistrationEvent registrationEvent = registrationEventService.get(entity.getRegistrationEventId());
saveAttachment(entity.getId(), resolveAttachmentList(entity)); checkRegistrationEventPermission(registrationEvent);
entity.setRegisteredAt(TimiJava.defaultIfNull(entity.getRegisteredAt(), Time.now()));
super.update(entity);
saveAttachment(entity.getId(), resolveAttachmentList(entity));
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("修改 GAO 登记记录失败", e);
throw new TimiException(TimiCode.ERROR, "修改 GAO 登记记录失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
@@ -311,6 +354,29 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
return customer.getId(); return customer.getId();
} }
private GaoRegistrationEventRecord doCreateRecord(GaoRegistrationEventRecordCreateReq req) {
TimiException.required(req, "not found req");
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
String customerId = resolveCustomerId(req);
GaoRegistrationEvent registrationEvent = registrationEventService.get(req.getRegistrationEventId());
checkRegistrationEventPermission(registrationEvent);
long registeredAt = TimiJava.defaultIfNull(req.getRegisteredAt(), Time.now());
checkRegistrationEventCreatable(registrationEvent, customerId, registeredAt);
if (Boolean.TRUE.equals(registrationEvent.getRequirePhoto())) {
TimiException.requiredTrue(req.getAttachmentIdList() != null && !req.getAttachmentIdList().isEmpty(), "required record photo");
}
GaoRegistrationEventRecord record = new GaoRegistrationEventRecord();
record.setCustomerId(customerId);
record.setRegistrationEventId(req.getRegistrationEventId());
record.setOperatorUserId(userLoginService.getRequireLoginUserId());
record.setRemark(req.getRemark());
record.setRegisteredAt(registeredAt);
super.create(record);
saveAttachment(record.getId(), buildPhotoAttachmentList(req.getAttachmentIdList()));
return get(record.getId());
}
private void checkRegistrationEventPermission(GaoRegistrationEvent registrationEvent) { private void checkRegistrationEventPermission(GaoRegistrationEvent registrationEvent) {
List<String> roleCodeList = registrationEventService.listRoleCode(registrationEvent.getId()); List<String> roleCodeList = registrationEventService.listRoleCode(registrationEvent.getId());
TimiException.requiredTrue(roleCodeList != null && !roleCodeList.isEmpty(), "登记事件未配置可登记角色"); TimiException.requiredTrue(roleCodeList != null && !roleCodeList.isEmpty(), "登记事件未配置可登记角色");
@@ -576,4 +642,12 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
private String text(Object value) { private String text(Object value) {
return value == null ? "" : value.toString(); return value == null ? "" : value.toString();
} }
private Logger buildLogger(String operation) {
Logger logger = new Logger();
logger.setModule(Logger.Module.GAO);
logger.setOperation(operation);
logger.setIp(TimiSpring.getRequestIP());
return logger;
}
} }
@@ -1,19 +1,25 @@
package com.imyeyu.api.modules.gao.service.implement; package com.imyeyu.api.modules.gao.service.implement;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig; import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation; import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent; import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper; import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper;
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper; import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper;
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService; import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.java.TimiJava; import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.bean.Page; import com.imyeyu.spring.bean.Page;
import com.imyeyu.spring.bean.PageResult; import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService; import com.imyeyu.spring.service.AbstractEntityService;
import com.imyeyu.utils.Time; import com.imyeyu.utils.Time;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -29,11 +35,14 @@ import java.util.stream.Collectors;
/// ///
/// @author Codex /// @author Codex
/// @since 2026-07-27 /// @since 2026-07-27
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class GaoRegistrationEventServiceImplement extends AbstractEntityService<GaoRegistrationEvent, String> implements GaoRegistrationEventService { public class GaoRegistrationEventServiceImplement extends AbstractEntityService<GaoRegistrationEvent, String> implements GaoRegistrationEventService {
private final GaoRegistrationEventMapper mapper; private final GaoRegistrationEventMapper mapper;
private final ObjectMapper jackson;
private final LoggerService loggerService;
private final GaoRegistrationEventRoleRelationMapper roleRelationMapper; private final GaoRegistrationEventRoleRelationMapper roleRelationMapper;
@Override @Override
@@ -54,36 +63,87 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void create(GaoRegistrationEvent entity) { public void create(GaoRegistrationEvent entity) {
checkEntity(entity, false); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_CREATE");
super.create(entity); try {
saveRoleRelation(entity.getId(), entity.getRoleCodeList()); logger.setContent(jackson.writeValueAsString(entity));
checkEntity(entity, false);
super.create(entity);
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("新增 GAO 登记事件失败", e);
throw new TimiException(TimiCode.ERROR, "新增 GAO 登记事件失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void update(GaoRegistrationEvent entity) { public void update(GaoRegistrationEvent entity) {
checkEntity(entity, true); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_UPDATE");
GaoRegistrationEvent current = get(entity.getId()); try {
current.setName(entity.getName()); logger.setContent(jackson.writeValueAsString(entity));
current.setDescription(entity.getDescription()); checkEntity(entity, true);
current.setColor(entity.getColor()); GaoRegistrationEvent current = get(entity.getId());
current.setStatus(entity.getStatus()); current.setName(entity.getName());
current.setRequirePhoto(entity.getRequirePhoto()); current.setDescription(entity.getDescription());
current.setLimitType(entity.getLimitType()); current.setColor(entity.getColor());
current.setLimitValue(entity.getLimitValue()); current.setStatus(entity.getStatus());
current.setBeginAt(entity.getBeginAt()); current.setRequirePhoto(entity.getRequirePhoto());
current.setEndAt(entity.getEndAt()); current.setLimitType(entity.getLimitType());
current.setSort(entity.getSort()); current.setLimitValue(entity.getLimitValue());
mapper.update(current); current.setBeginAt(entity.getBeginAt());
saveRoleRelation(entity.getId(), entity.getRoleCodeList()); current.setEndAt(entity.getEndAt());
current.setSort(entity.getSort());
mapper.update(current);
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("修改 GAO 登记事件失败", e);
throw new TimiException(TimiCode.ERROR, "修改 GAO 登记事件失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void delete(String id) { public void delete(String id) {
GaoRegistrationEvent entity = get(id); Logger logger = buildLogger("GAO_REGISTRATION_EVENT_DELETE");
entity.setStatus(GaoRegistrationEvent.Status.DELETED); try {
super.update(entity); logger.setContent(id);
GaoRegistrationEvent entity = get(id);
entity.setStatus(GaoRegistrationEvent.Status.DELETED);
super.update(entity);
logger.setLevel(Logger.Level.INFO);
logger.setResult(id);
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("删除 GAO 登记事件失败", e);
throw new TimiException(TimiCode.ERROR, "删除 GAO 登记事件失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
@@ -196,4 +256,12 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
registrationEvent.setRoleCodeList(roleCodeMap.getOrDefault(registrationEvent.getId(), List.of())); registrationEvent.setRoleCodeList(roleCodeMap.getOrDefault(registrationEvent.getId(), List.of()));
} }
} }
private Logger buildLogger(String operation) {
Logger logger = new Logger();
logger.setModule(Logger.Module.GAO);
logger.setOperation(operation);
logger.setIp(TimiSpring.getRequestIP());
return logger;
}
} }
@@ -1,10 +1,13 @@
package com.imyeyu.api.modules.gao.service.implement; package com.imyeyu.api.modules.gao.service.implement;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.imyeyu.api.bean.ModuleCode; import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig; import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.gao.entity.GaoUser; import com.imyeyu.api.modules.gao.entity.GaoUser;
import com.imyeyu.api.modules.gao.mapper.GaoUserMapper; import com.imyeyu.api.modules.gao.mapper.GaoUserMapper;
import com.imyeyu.api.modules.gao.service.GaoUserService; import com.imyeyu.api.modules.gao.service.GaoUserService;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.entity.Role; import com.imyeyu.api.modules.user.entity.Role;
import com.imyeyu.api.modules.user.entity.User; import com.imyeyu.api.modules.user.entity.User;
import com.imyeyu.api.modules.user.mapper.UserMapper; import com.imyeyu.api.modules.user.mapper.UserMapper;
@@ -14,12 +17,14 @@ import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeReq;
import com.imyeyu.java.TimiJava; import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode; import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.bean.Page; import com.imyeyu.spring.bean.Page;
import com.imyeyu.spring.bean.PageResult; import com.imyeyu.spring.bean.PageResult;
import com.imyeyu.spring.mapper.BaseMapper; import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService; import com.imyeyu.spring.service.AbstractEntityService;
import com.imyeyu.utils.Time; import com.imyeyu.utils.Time;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -34,11 +39,14 @@ import java.util.stream.Collectors;
/// ///
/// @author Codex /// @author Codex
/// @since 2026-07-30 /// @since 2026-07-30
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, String> implements GaoUserService { public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, String> implements GaoUserService {
private final GaoUserMapper mapper; private final GaoUserMapper mapper;
private final ObjectMapper jackson;
private final LoggerService loggerService;
private final UserMapper userMapper; private final UserMapper userMapper;
private final UserService userService; private final UserService userService;
private final RoleService roleService; private final RoleService roleService;
@@ -51,20 +59,54 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void create(GaoUser entity) { public void create(GaoUser entity) {
prepareUser(entity); Logger logger = buildLogger("GAO_USER_CREATE");
checkEntity(entity, false); try {
super.create(entity); logger.setContent(jackson.writeValueAsString(entity));
saveUserRole(entity); prepareUser(entity);
loadUser(entity); checkEntity(entity, false);
super.create(entity);
saveUserRole(entity);
loadUser(entity);
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("新增 GAO 用户失败", e);
throw new TimiException(TimiCode.ERROR, "新增 GAO 用户失败", e);
} finally {
loggerService.create(logger);
}
} }
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public void update(GaoUser entity) { public void update(GaoUser entity) {
checkEntity(entity, true); Logger logger = buildLogger("GAO_USER_UPDATE");
updateUser(entity); try {
super.update(entity); logger.setContent(jackson.writeValueAsString(entity));
saveUserRole(entity); checkEntity(entity, true);
updateUser(entity);
super.update(entity);
saveUserRole(entity);
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
throw e;
} catch (Exception e) {
logger.setLevel(Logger.Level.ERROR);
logger.setException(TimiJava.serializeThrowable(e));
log.error("修改 GAO 用户失败", e);
throw new TimiException(TimiCode.ERROR, "修改 GAO 用户失败", e);
} finally {
loggerService.create(logger);
}
} }
@Override @Override
@@ -171,4 +213,12 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
gaoUser.setRoleList(roleList); gaoUser.setRoleList(roleList);
} }
} }
private Logger buildLogger(String operation) {
Logger logger = new Logger();
logger.setModule(Logger.Module.GAO);
logger.setOperation(operation);
logger.setIp(TimiSpring.getRequestIP());
return logger;
}
} }
@@ -17,6 +17,21 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
public class Logger implements IDEntity<String>, Creatable { public class Logger implements IDEntity<String>, Creatable {
///
///
/// @author 夜雨
/// @since 2026-08-03 11:43
public enum Module {
SYSTEM,
COMMON,
USER,
GAO,
}
/** /**
* 日志级别 * 日志级别
* *
@@ -43,7 +58,7 @@ public class Logger implements IDEntity<String>, Creatable {
private Level level; private Level level;
/** 模块名称 */ /** 模块名称 */
private String module; private Module module;
/** 操作描述 */ /** 操作描述 */
private String operation; private String operation;
@@ -16,41 +16,41 @@ public interface LoggerService extends GettableService<Logger, String>, Pageable
void createSync(Logger logger); void createSync(Logger logger);
void create(Logger.Level level, String module, String operation, String userId, String content, String result); void create(Logger.Level level, Logger.Module module, String operation, String userId, String content, String result);
default void info(String module, String operation, String userId) { default void info(Logger.Module module, String operation, String userId) {
create(Logger.Level.INFO, module, operation, userId, null, null); create(Logger.Level.INFO, module, operation, userId, null, null);
} }
default void info(String module, String operation, String content, String result) { default void info(Logger.Module module, String operation, String content, String result) {
create(Logger.Level.INFO, module, operation, null, content, result); create(Logger.Level.INFO, module, operation, null, content, result);
} }
default void info(String module, String operation, String userId, String content, String result) { default void info(Logger.Module module, String operation, String userId, String content, String result) {
create(Logger.Level.INFO, module, operation, userId, content, result); create(Logger.Level.INFO, module, operation, userId, content, result);
} }
default void warning(String module, String operation, String userId) { default void warning(Logger.Module module, String operation, String userId) {
create(Logger.Level.WARN, module, operation, userId, null, null); create(Logger.Level.WARN, module, operation, userId, null, null);
} }
default void warning(String module, String operation, String content, String result) { default void warning(Logger.Module module, String operation, String content, String result) {
create(Logger.Level.WARN, module, operation, null, content, result); create(Logger.Level.WARN, module, operation, null, content, result);
} }
default void warning(String module, String operation, String userId, String content, String result) { default void warning(Logger.Module module, String operation, String userId, String content, String result) {
create(Logger.Level.WARN, module, operation, userId, content, result); create(Logger.Level.WARN, module, operation, userId, content, result);
} }
default void error(String module, String operation, String userId) { default void error(Logger.Module module, String operation, String userId) {
create(Logger.Level.ERROR, module, operation, userId, null, null); create(Logger.Level.ERROR, module, operation, userId, null, null);
} }
default void error(String module, String operation, String content, String result) { default void error(Logger.Module module, String operation, String content, String result) {
create(Logger.Level.ERROR, module, operation, null, content, result); create(Logger.Level.ERROR, module, operation, null, content, result);
} }
default void error(String module, String operation, String userId, String content, String result) { default void error(Logger.Module module, String operation, String userId, String content, String result) {
create(Logger.Level.ERROR, module, operation, userId, content, result); create(Logger.Level.ERROR, module, operation, userId, content, result);
} }
} }
@@ -36,7 +36,7 @@ public class LoggerServiceImplement extends AbstractEntityService<Logger, String
super.create(logger); super.create(logger);
} }
public void create(Logger.Level level, String module, String operation, String userId, String content, String result) { public void create(Logger.Level level, Logger.Module module, String operation, String userId, String content, String result) {
Logger log = new Logger(level); Logger log = new Logger(level);
log.setModule(module); log.setModule(module);
log.setOperation(operation); log.setOperation(operation);
@@ -1,10 +1,11 @@
package com.imyeyu.api.util; package com.imyeyu.api.util;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.bean.ModuleCode; import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.common.bean.ImageType; import com.imyeyu.api.modules.common.bean.ImageType;
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode; import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
import com.imyeyu.api.modules.gao.bean.GaoRoleCode; import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService; import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.bean.BootstrapData; import com.imyeyu.api.modules.user.bean.BootstrapData;
import com.imyeyu.api.modules.user.bean.BuiltinAuthRegistry; import com.imyeyu.api.modules.user.bean.BuiltinAuthRegistry;
@@ -92,7 +93,7 @@ public class InitBuiltinUser implements ApplicationRunner {
userService.create(user); userService.create(user);
String logContent = "初始化 %s 自举用户成功,请立即修改密码:%s".formatted(BootstrapData.SYS_USER_NAME, password); String logContent = "初始化 %s 自举用户成功,请立即修改密码:%s".formatted(BootstrapData.SYS_USER_NAME, password);
loggerService.info("SYSTEM", "INITIALIZE_SYSTEM_USER", user.getId(), logContent, null); loggerService.info(Logger.Module.SYSTEM, "INITIALIZE_SYSTEM_USER", user.getId(), logContent, null);
} }
// 授权系统用户角色 // 授权系统用户角色
{ {