update GAO logger
This commit is contained in:
@@ -188,7 +188,7 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.java</groupId>
|
||||
<artifactId>timi-java</artifactId>
|
||||
<version>0.0.6</version>
|
||||
<version>0.0.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.utils</groupId>
|
||||
|
||||
+8
@@ -72,6 +72,14 @@ public class GaoRegistrationEventController {
|
||||
service.update(registrationEvent);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_UPDATE)
|
||||
@PostMapping("/sort")
|
||||
public void sort(@RequestBody List<String> idList) {
|
||||
service.sort(idList);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_DELETE)
|
||||
|
||||
@@ -30,4 +30,9 @@ public interface GaoRegistrationEventService extends BaseService<GaoRegistration
|
||||
/// @param registrationEventId 登记事件 ID
|
||||
/// @return 角色代码列表
|
||||
List<String> listRoleCode(String registrationEventId);
|
||||
|
||||
/// 按客户端提交的顺序更新登记事件排序
|
||||
///
|
||||
/// @param idList 登记事件 ID 列表
|
||||
void sort(List<String> idList);
|
||||
}
|
||||
|
||||
+5
-13
@@ -77,7 +77,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
|
||||
@Override
|
||||
public void create(GaoCustomer entity) {
|
||||
Logger logger = buildLogger("GAO_CUSTOMER_CREATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_CREATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
checkEntity(entity, false);
|
||||
@@ -105,7 +105,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
|
||||
@Override
|
||||
public void update(GaoCustomer entity) {
|
||||
Logger logger = buildLogger("GAO_CUSTOMER_UPDATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
GaoCustomer dbCustomer = checkEntity(entity, true);
|
||||
@@ -131,7 +131,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
Logger logger = buildLogger("GAO_CUSTOMER_DELETE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE");
|
||||
try {
|
||||
logger.setContent(id);
|
||||
GaoCustomer customer = super.get(id);
|
||||
@@ -274,7 +274,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void saveInviteRelation(GaoCustomerInviteUpdateReq req) {
|
||||
Logger logger = buildLogger("GAO_CUSTOMER_SAVE_INVITE_RELATION");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_SAVE_INVITE_RELATION");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(req));
|
||||
TimiException.required(req, "not found invite req");
|
||||
@@ -304,7 +304,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void deleteInviteRelation(String customerId) {
|
||||
Logger logger = buildLogger("GAO_CUSTOMER_DELETE_INVITE_RELATION");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE_INVITE_RELATION");
|
||||
try {
|
||||
logger.setContent(customerId);
|
||||
TimiException.required(customerId, "not found customerId");
|
||||
@@ -546,12 +546,4 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
private String text(Object value) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-11
@@ -103,7 +103,7 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_CREATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_RECORD_CREATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(req));
|
||||
GaoRegistrationEventRecord record = doCreateRecord(req);
|
||||
@@ -127,7 +127,7 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_QUICK_REGISTER");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_RECORD_QUICK_REGISTER");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(req));
|
||||
TimiException.required(req, "not found req");
|
||||
@@ -160,7 +160,7 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(GaoRegistrationEventRecord entity) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_RECORD_UPDATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_RECORD_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
TimiException.required(entity, "not found record");
|
||||
@@ -642,12 +642,4 @@ public class GaoRegistrationEventRecordServiceImplement extends AbstractEntitySe
|
||||
private String text(Object value) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+41
-48
@@ -2,17 +2,16 @@ 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.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper;
|
||||
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.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
@@ -33,16 +32,18 @@ import java.util.stream.Collectors;
|
||||
///
|
||||
/// 登记事件服务实现
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-07-27
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-27 09:00
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoRegistrationEventServiceImplement extends AbstractEntityService<GaoRegistrationEvent, String> implements GaoRegistrationEventService {
|
||||
|
||||
private final GaoRegistrationEventMapper mapper;
|
||||
private final ObjectMapper jackson;
|
||||
|
||||
private final LoggerService loggerService;
|
||||
|
||||
private final GaoRegistrationEventMapper mapper;
|
||||
private final GaoRegistrationEventRoleRelationMapper roleRelationMapper;
|
||||
|
||||
@Override
|
||||
@@ -53,9 +54,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
@Override
|
||||
public PageResult<GaoRegistrationEvent> pageWithRegistrationEventLimit(Page<GaoRegistrationEvent> page) {
|
||||
PageResult<GaoRegistrationEvent> result = page(page);
|
||||
result.setList(result.getList().stream()
|
||||
.filter(item -> item.getStatus() != GaoRegistrationEvent.Status.DELETED)
|
||||
.toList());
|
||||
result.setList(result.getList().stream().filter(item -> item.getStatus() != GaoRegistrationEvent.Status.DELETED).toList());
|
||||
loadRegistrationEventLimit(result.getList());
|
||||
return result;
|
||||
}
|
||||
@@ -63,7 +62,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoRegistrationEvent entity) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_CREATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_CREATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
checkEntity(entity, false);
|
||||
@@ -88,9 +87,10 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(GaoRegistrationEvent entity) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_UPDATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
Integer sort = entity.getSort();
|
||||
checkEntity(entity, true);
|
||||
GaoRegistrationEvent current = get(entity.getId());
|
||||
current.setName(entity.getName());
|
||||
@@ -102,7 +102,9 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
current.setLimitValue(entity.getLimitValue());
|
||||
current.setBeginAt(entity.getBeginAt());
|
||||
current.setEndAt(entity.getEndAt());
|
||||
current.setSort(entity.getSort());
|
||||
if (sort != null) {
|
||||
current.setSort(sort);
|
||||
}
|
||||
mapper.update(current);
|
||||
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
@@ -124,7 +126,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
Logger logger = buildLogger("GAO_REGISTRATION_EVENT_DELETE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_REGISTRATION_EVENT_DELETE");
|
||||
try {
|
||||
logger.setContent(id);
|
||||
GaoRegistrationEvent entity = get(id);
|
||||
@@ -157,9 +159,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
public List<GaoRegistrationEvent> listEnabled() {
|
||||
List<GaoRegistrationEvent> list = mapper.selectEnabledList(Time.now());
|
||||
loadRegistrationEventLimit(list);
|
||||
list = list.stream()
|
||||
.filter(item -> !TimiJava.isEmpty(item.getRoleCodeList()))
|
||||
.toList();
|
||||
list = list.stream().filter(item -> !TimiJava.isEmpty(item.getRoleCodeList())).toList();
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -168,6 +168,22 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
return roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEventId);
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void sort(List<String> idList) {
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> distinctIdList = new ArrayList<>(new LinkedHashSet<>(idList));
|
||||
Map<String, GaoRegistrationEvent> eventMap = mapper.selectByIdList(distinctIdList).stream().collect(Collectors.toMap(GaoRegistrationEvent::getId, item -> item));
|
||||
TimiException.requiredTrue(eventMap.size() == distinctIdList.size(), "not found registrationEvent");
|
||||
for (int index = 0; index < distinctIdList.size(); index++) {
|
||||
GaoRegistrationEvent registrationEvent = eventMap.get(distinctIdList.get(index));
|
||||
registrationEvent.setSort(index);
|
||||
mapper.update(registrationEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntity(GaoRegistrationEvent entity, boolean requireId) {
|
||||
TimiException.required(entity, "not found registrationEvent");
|
||||
if (requireId) {
|
||||
@@ -183,10 +199,9 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
if (entity.getLimitType() == null) {
|
||||
entity.setLimitType(GaoRegistrationEvent.LimitType.NONE);
|
||||
}
|
||||
TimiException.requiredTrue(
|
||||
entity.getRoleCodeList() != null && entity.getRoleCodeList().stream().anyMatch(item -> item != null && !item.isBlank()),
|
||||
"not found registrationEvent.roleCodeList"
|
||||
);
|
||||
TimiException.requiredTrue(entity.getRoleCodeList() != null && entity.getRoleCodeList()
|
||||
.stream()
|
||||
.anyMatch(item -> item != null && !item.isBlank()), "not found registrationEvent.roleCodeList");
|
||||
checkRegistrationLimit(entity);
|
||||
checkRegisterablePeriod(entity);
|
||||
if (entity.getColor() != null) {
|
||||
@@ -198,9 +213,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
}
|
||||
|
||||
private void checkRegistrationLimit(GaoRegistrationEvent entity) {
|
||||
if (entity.getLimitType() == GaoRegistrationEvent.LimitType.INTERVAL_HOUR
|
||||
|| entity.getLimitType() == GaoRegistrationEvent.LimitType.TOTAL_LIMIT
|
||||
|| entity.getLimitType() == GaoRegistrationEvent.LimitType.CUSTOMER_TOTAL_LIMIT) {
|
||||
if (entity.getLimitType() == GaoRegistrationEvent.LimitType.INTERVAL_HOUR || entity.getLimitType() == GaoRegistrationEvent.LimitType.TOTAL_LIMIT || entity.getLimitType() == GaoRegistrationEvent.LimitType.CUSTOMER_TOTAL_LIMIT) {
|
||||
TimiException.required(entity.getLimitValue(), "not found registrationEvent.limitValue");
|
||||
TimiException.requiredTrue(0 < entity.getLimitValue(), "registrationEvent.limitValue lte 0");
|
||||
return;
|
||||
@@ -212,10 +225,7 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
if (entity.getBeginAt() == null && entity.getEndAt() == null) {
|
||||
return;
|
||||
}
|
||||
TimiException.requiredTrue(
|
||||
entity.getBeginAt() == null || entity.getEndAt() == null || entity.getBeginAt() <= entity.getEndAt(),
|
||||
"registrationEvent.beginAt gt registrationEvent.endAt"
|
||||
);
|
||||
TimiException.requiredTrue(entity.getBeginAt() == null || entity.getEndAt() == null || entity.getBeginAt() <= entity.getEndAt(), "registrationEvent.beginAt gt registrationEvent.endAt");
|
||||
}
|
||||
|
||||
private void saveRoleRelation(String registrationEventId, List<String> roleCodeList) {
|
||||
@@ -235,33 +245,16 @@ public class GaoRegistrationEventServiceImplement extends AbstractEntityService<
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRegistrationEventLimit(GaoRegistrationEvent registrationEvent) {
|
||||
registrationEvent.setRoleCodeList(roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEvent.getId()));
|
||||
}
|
||||
|
||||
private void loadRegistrationEventLimit(List<GaoRegistrationEvent> registrationEventList) {
|
||||
if (registrationEventList == null || registrationEventList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> registrationEventIdList = registrationEventList.stream()
|
||||
.map(GaoRegistrationEvent::getId)
|
||||
.distinct()
|
||||
.toList();
|
||||
Map<String, List<String>> roleCodeMap = roleRelationMapper.selectByRegistrationEventIdList(new ArrayList<>(registrationEventIdList)).stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
GaoRegistrationEventRoleRelation::getRegistrationEventId,
|
||||
Collectors.mapping(GaoRegistrationEventRoleRelation::getRoleCode, Collectors.toList())
|
||||
));
|
||||
List<String> registrationEventIdList = registrationEventList.stream().map(GaoRegistrationEvent::getId).distinct().toList();
|
||||
Map<String, List<String>> roleCodeMap = roleRelationMapper.selectByRegistrationEventIdList(new ArrayList<>(registrationEventIdList))
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(GaoRegistrationEventRoleRelation::getRegistrationEventId, Collectors.mapping(GaoRegistrationEventRoleRelation::getRoleCode, Collectors.toList())));
|
||||
for (GaoRegistrationEvent registrationEvent : registrationEventList) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-10
@@ -59,7 +59,7 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoUser entity) {
|
||||
Logger logger = buildLogger("GAO_USER_CREATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_CREATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
prepareUser(entity);
|
||||
@@ -86,7 +86,7 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(GaoUser entity) {
|
||||
Logger logger = buildLogger("GAO_USER_UPDATE");
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(entity));
|
||||
checkEntity(entity, true);
|
||||
@@ -213,12 +213,4 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,26 @@ public class Logger implements IDEntity<String>, Creatable {
|
||||
/** 创建时间 */
|
||||
private Long createdAt;
|
||||
|
||||
public Logger(Level level) {
|
||||
public Logger(Module module, String operation) {
|
||||
this.module = module;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public Logger(Module module, Level level, String operation) {
|
||||
this.module = module;
|
||||
this.level = level;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public static Logger info(Module module, String operation) {
|
||||
return new Logger(module, Level.INFO, operation);
|
||||
}
|
||||
|
||||
public static Logger warning(Module module, String operation) {
|
||||
return new Logger(module, Level.WARN, operation);
|
||||
}
|
||||
|
||||
public static Logger error(Module module, String operation) {
|
||||
return new Logger(module, Level.ERROR, operation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,41 +16,29 @@ public interface LoggerService extends GettableService<Logger, String>, Pageable
|
||||
|
||||
void createSync(Logger logger);
|
||||
|
||||
void create(Logger.Level level, Logger.Module module, String operation, String userId, String content, String result);
|
||||
void create(Logger.Module module, Logger.Level level, String operation, String content, String result);
|
||||
|
||||
default void info(Logger.Module module, String operation, String userId) {
|
||||
create(Logger.Level.INFO, module, operation, userId, null, null);
|
||||
default void info(Logger.Module module, String operation) {
|
||||
create(module, Logger.Level.INFO, operation, null, null);
|
||||
}
|
||||
|
||||
default void info(Logger.Module module, String operation, String content, String result) {
|
||||
create(Logger.Level.INFO, module, operation, null, content, result);
|
||||
create(module, Logger.Level.INFO, operation, content, result);
|
||||
}
|
||||
|
||||
default void info(Logger.Module module, String operation, String userId, String content, String result) {
|
||||
create(Logger.Level.INFO, module, operation, userId, content, result);
|
||||
}
|
||||
|
||||
default void warning(Logger.Module module, String operation, String userId) {
|
||||
create(Logger.Level.WARN, module, operation, userId, null, null);
|
||||
default void warning(Logger.Module module, String operation) {
|
||||
create(module, Logger.Level.WARN, operation, null, null);
|
||||
}
|
||||
|
||||
default void warning(Logger.Module module, String operation, String content, String result) {
|
||||
create(Logger.Level.WARN, module, operation, null, content, result);
|
||||
create(module, Logger.Level.WARN, operation, content, result);
|
||||
}
|
||||
|
||||
default void warning(Logger.Module module, String operation, String userId, String content, String result) {
|
||||
create(Logger.Level.WARN, module, operation, userId, content, result);
|
||||
}
|
||||
|
||||
default void error(Logger.Module module, String operation, String userId) {
|
||||
create(Logger.Level.ERROR, module, operation, userId, null, null);
|
||||
default void error(Logger.Module module, String operation) {
|
||||
create(module, Logger.Level.ERROR, operation, null, null);
|
||||
}
|
||||
|
||||
default void error(Logger.Module module, String operation, String content, String result) {
|
||||
create(Logger.Level.ERROR, module, operation, null, content, 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(module, Logger.Level.ERROR, operation, content, result);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-6
@@ -3,6 +3,10 @@ package com.imyeyu.api.modules.system.service.implement;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.mapper.LoggerMapper;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -18,6 +22,8 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class LoggerServiceImplement extends AbstractEntityService<Logger, String> implements LoggerService {
|
||||
|
||||
private final UserLoginService userLoginService;
|
||||
|
||||
private final LoggerMapper mapper;
|
||||
|
||||
@Override
|
||||
@@ -28,19 +34,23 @@ public class LoggerServiceImplement extends AbstractEntityService<Logger, String
|
||||
@Override
|
||||
public void create(Logger logger) {
|
||||
// 默认异步
|
||||
Thread.startVirtualThread(() -> super.create(logger));
|
||||
Thread.startVirtualThread(() -> createSync(logger));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSync(Logger logger) {
|
||||
if (TimiJava.isEmpty(logger.getUserId())) {
|
||||
User loginUser = userLoginService.getLoginUser();
|
||||
if (TimiJava.isNotEmpty(loginUser)) {
|
||||
logger.setUserId(loginUser.getId());
|
||||
}
|
||||
}
|
||||
logger.setIp(TimiJava.defaultIfEmpty(logger.getIp(), TimiSpring.getRequestIP()));
|
||||
super.create(logger);
|
||||
}
|
||||
|
||||
public void create(Logger.Level level, Logger.Module module, String operation, String userId, String content, String result) {
|
||||
Logger log = new Logger(level);
|
||||
log.setModule(module);
|
||||
log.setOperation(operation);
|
||||
log.setUserId(userId);
|
||||
public void create(Logger.Module module, Logger.Level level, String operation, String content, String result) {
|
||||
Logger log = new Logger(module, level, operation);
|
||||
log.setContent(content);
|
||||
log.setResult(result);
|
||||
create(log);
|
||||
|
||||
+4
-2
@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/// 用户登录服务实现
|
||||
///
|
||||
@@ -95,7 +95,9 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
@Override
|
||||
public User getLoginUser() {
|
||||
String token = TimiSpring.getToken();
|
||||
TimiException.required(token, "not found token");
|
||||
if (TimiJava.isEmpty(token)) {
|
||||
return null;
|
||||
}
|
||||
String userId = redisUserToken.get(getUserTokenKey(token));
|
||||
if (TimiJava.isEmpty(userId)) {
|
||||
return null;
|
||||
|
||||
@@ -93,7 +93,13 @@ public class InitBuiltinUser implements ApplicationRunner {
|
||||
userService.create(user);
|
||||
|
||||
String logContent = "初始化 %s 自举用户成功,请立即修改密码:%s".formatted(BootstrapData.SYS_USER_NAME, password);
|
||||
loggerService.info(Logger.Module.SYSTEM, "INITIALIZE_SYSTEM_USER", user.getId(), logContent, null);
|
||||
|
||||
Logger logger = new Logger();
|
||||
logger.setModule(Logger.Module.SYSTEM);
|
||||
logger.setOperation("INITIALIZE_SYSTEM_USER");
|
||||
logger.setUserId(user.getId());
|
||||
logger.setContent(logContent);
|
||||
loggerService.create(logger);
|
||||
}
|
||||
// 授权系统用户角色
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user