feature: config 引入 log record 组件, 实现操作日志打印.

pull/161/head
chen.ma 3 years ago
parent 7c22923dff
commit b1b82d9534

@ -61,6 +61,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.github.dynamic-threadpool</groupId>
<artifactId>log-record-tool</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,15 @@
package com.github.dynamic.threadpool.config.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.dynamic.threadpool.logrecord.model.LogRecordInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* Log record mapper.
*
* @author chen.ma
* @date 2021/10/24 21:01
*/
@Mapper
public interface LogRecordMapper extends BaseMapper<LogRecordInfo> {
}

@ -0,0 +1,26 @@
package com.github.dynamic.threadpool.config.service.biz.impl;
import com.github.dynamic.threadpool.config.mapper.LogRecordMapper;
import com.github.dynamic.threadpool.logrecord.model.LogRecordInfo;
import com.github.dynamic.threadpool.logrecord.service.LogRecordService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* .
*
* @author chen.ma
* @date 2021/10/24 20:57
*/
@Service
@AllArgsConstructor
public class LogRecordServiceImpl implements LogRecordService {
private LogRecordMapper logRecordMapper;
@Override
public void record(LogRecordInfo logRecordInfo) {
logRecordMapper.insert(logRecordInfo);
}
}

@ -1,4 +1,4 @@
package com.github.dynamic.threadpool.config.service.biz;
package com.github.dynamic.threadpool.config.service.biz.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -15,7 +15,10 @@ import com.github.dynamic.threadpool.config.model.biz.tenant.TenantQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantRespDTO;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantSaveReqDTO;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantUpdateReqDTO;
import com.github.dynamic.threadpool.config.service.biz.ItemService;
import com.github.dynamic.threadpool.config.service.biz.TenantService;
import com.github.dynamic.threadpool.config.toolkit.BeanUtil;
import com.github.dynamic.threadpool.logrecord.annotation.LogRecord;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -37,7 +40,12 @@ public class TenantServiceImpl implements TenantService {
private final TenantInfoMapper tenantInfoMapper;
@Override
public TenantRespDTO getTenantById(String tenantId) {
public TenantRespDTO getTenantById(String id) {
return BeanUtil.convert(tenantInfoMapper.selectById(id), TenantRespDTO.class);
}
@Override
public TenantRespDTO getTenantByTenantId(String tenantId) {
LambdaQueryWrapper<TenantInfo> queryWrapper = Wrappers
.lambdaQuery(TenantInfo.class).eq(TenantInfo::getTenantId, tenantId);
TenantInfo tenantInfo = tenantInfoMapper.selectOne(queryWrapper);
@ -69,6 +77,13 @@ public class TenantServiceImpl implements TenantService {
}
@Override
@LogRecord(
prefix = "item",
bizNo = "{{#reqDTO.tenantId}}_{{#reqDTO.tenantName}}",
category = "TENANT_UPDATE",
success = "更新租户, ID :: {{#reqDTO.id}}, 租户名称由 :: {TENANT{#reqDTO.id}} -> {{#reqDTO.tenantName}}",
detail = "{{#reqDTO.toString()}}"
)
public void updateTenant(TenantUpdateReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers

@ -0,0 +1,34 @@
package com.github.dynamic.threadpool.config.service.handler;
import com.github.dynamic.threadpool.config.model.biz.tenant.TenantRespDTO;
import com.github.dynamic.threadpool.config.service.biz.TenantService;
import com.github.dynamic.threadpool.logrecord.service.ParseFunction;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* Id .
*
* @author chen.ma
* @date 2021/10/24 22:07
*/
@Component
@AllArgsConstructor
public class TenantIdFunctionServiceImpl implements ParseFunction {
private final TenantService tenantService;
@Override
public String functionName() {
return "TENANT";
}
@Override
public String apply(String tenantId) {
TenantRespDTO tenant = tenantService.getTenantById(tenantId);
return Optional.ofNullable(tenant).map(TenantRespDTO::getTenantName).orElse("");
}
}
Loading…
Cancel
Save