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