将 mall-spring-boot-starter-web 接入新的 system-service 服务

This commit is contained in:
YunaiV 2020-07-04 21:00:34 +08:00
parent c1ca5f7dc5
commit 301e2c5720
49 changed files with 382 additions and 631 deletions

View File

@ -73,7 +73,7 @@ public class AccountAuthInterceptor extends HandlerInterceptorAdapter {
} }
// 设置账号编号 // 设置账号编号
Integer accountId = oauth2AccessTokenResult.getData().getAccountId(); Integer accountId = oauth2AccessTokenResult.getData().getAccountId();
CommonWebUtil.setAccountId(request, accountId); CommonWebUtil.setUserId(request, accountId);
return accountId; return accountId;
} }

View File

@ -22,7 +22,7 @@ public class AdminSecurityInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Integer accountId = CommonWebUtil.getAccountId(request); Integer accountId = CommonWebUtil.getUserId(request);
if (accountId != null) { if (accountId != null) {
// 获得 Admin 信息 // 获得 Admin 信息
CommonResult<AdminResponse> adminResult = adminRPC.getAdminByAccountId(accountId); CommonResult<AdminResponse> adminResult = adminRPC.getAdminByAccountId(accountId);

View File

@ -21,7 +21,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Integer accountId = CommonWebUtil.getAccountId(request); Integer accountId = CommonWebUtil.getUserId(request);
if (accountId != null) { if (accountId != null) {
// 获得 Admin 信息 // 获得 Admin 信息
CommonResult<UserResponse> userResult = userRPC.getUserByAccountId(accountId); CommonResult<UserResponse> userResult = userRPC.getUserByAccountId(accountId);

View File

@ -15,7 +15,7 @@
<!-- Mall 相关 --> <!-- Mall 相关 -->
<dependency> <dependency>
<groupId>cn.iocoder.mall</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>system-rpc-api</artifactId> <artifactId>system-service-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

View File

@ -1,10 +1,9 @@
package cn.iocoder.mall.web.config; package cn.iocoder.mall.web.config;
import cn.iocoder.mall.web.core.servlet.CorsFilter;
import cn.iocoder.mall.web.core.constant.CommonMallConstants;
import cn.iocoder.mall.web.core.handler.GlobalExceptionHandler; import cn.iocoder.mall.web.core.handler.GlobalExceptionHandler;
import cn.iocoder.mall.web.core.handler.GlobalResponseBodyHandler; import cn.iocoder.mall.web.core.handler.GlobalResponseBodyHandler;
import cn.iocoder.mall.web.core.interceptor.AccessLogInterceptor; import cn.iocoder.mall.web.core.interceptor.AccessLogInterceptor;
import cn.iocoder.mall.web.core.servlet.CorsFilter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@ -40,7 +39,7 @@ public class CommonWebAutoConfiguration implements WebMvcConfigurer {
// ========== 拦截器相关 ========== // ========== 拦截器相关 ==========
@Bean @Bean
@ConditionalOnClass(name = {"cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC", "org.apache.dubbo.config.annotation.Reference"}) @ConditionalOnClass(name = {"cn.iocoder.mall.systemservice.rpc.systemlog.SystemLogRPC", "org.apache.dubbo.config.annotation.Reference"})
@ConditionalOnMissingBean(AccessLogInterceptor.class) @ConditionalOnMissingBean(AccessLogInterceptor.class)
public AccessLogInterceptor accessLogInterceptor() { public AccessLogInterceptor accessLogInterceptor() {
return new AccessLogInterceptor(); return new AccessLogInterceptor();
@ -49,8 +48,7 @@ public class CommonWebAutoConfiguration implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
try { try {
registry.addInterceptor(this.accessLogInterceptor()) registry.addInterceptor(this.accessLogInterceptor());
.addPathPatterns(CommonMallConstants.ROOT_PATH_ADMIN + "/**", CommonMallConstants.ROOT_PATH_USER + "/**");
logger.info("[addInterceptors][加载 AccessLogInterceptor 拦截器完成]"); logger.info("[addInterceptors][加载 AccessLogInterceptor 拦截器完成]");
} catch (NoSuchBeanDefinitionException e) { } catch (NoSuchBeanDefinitionException e) {
logger.warn("[addInterceptors][无法获取 AccessLogInterceptor 拦截器,因此不启动 AccessLog 的记录]"); logger.warn("[addInterceptors][无法获取 AccessLogInterceptor 拦截器,因此不启动 AccessLog 的记录]");

View File

@ -6,19 +6,33 @@ public interface CommonMallConstants {
/** /**
* 根路径 - 用户 * 根路径 - 用户
*/ */
@Deprecated
String ROOT_PATH_USER = "/users"; String ROOT_PATH_USER = "/users";
/** /**
* 根路径 - 管理员 * 根路径 - 管理员
*/ */
@Deprecated
String ROOT_PATH_ADMIN = "/admins"; String ROOT_PATH_ADMIN = "/admins";
// HTTP Request Attr // HTTP Request Attr
/** /**
* HTTP Request Attr - 账号编号 * HTTP Request Attr - 用户编号
*
* 考虑到 mall-spring-boot-starter-web 不依赖 mall-spring-boot-starter-security但是又希望拿到认证过的用户编号
* 因此通过 Request Attribute 进行共享
*/ */
String REQUEST_ATTR_USER_ID_KEY = "mall_account_id"; String REQUEST_ATTR_USER_ID_KEY = "mall_user_id";
/**
* HTTP Request Attr - 用户类型
*
* 作用同 {@link #REQUEST_ATTR_USER_ID_KEY}
*/
String REQUEST_ATTR_USER_TYPE_KEY = "mall_user_type";
/** /**
* HTTP Request Attr - Controller 执行返回 * HTTP Request Attr - Controller 执行返回
*
* 通过该 Request Attribute获取到请求执行结果从而在访问日志中记录是否成功
*/ */
String REQUEST_ATTR_COMMON_RESULT = "mall_common_result"; String REQUEST_ATTR_COMMON_RESULT = "mall_common_result";
/** /**

View File

@ -6,8 +6,8 @@ import cn.iocoder.common.framework.util.ExceptionUtil;
import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.HttpUtil;
import cn.iocoder.common.framework.util.MallUtils; import cn.iocoder.common.framework.util.MallUtils;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC; import cn.iocoder.mall.systemservice.rpc.systemlog.SystemLogRPC;
import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest; import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
import cn.iocoder.mall.web.core.util.CommonWebUtil; import cn.iocoder.mall.web.core.util.CommonWebUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
@ -33,7 +33,6 @@ public class GlobalExceptionHandler {
// TODO 芋艿应该还有其它的异常需要进行翻译 // TODO 芋艿应该还有其它的异常需要进行翻译
// /** // /**
// * 异常总数 Metrics // * 异常总数 Metrics
// */ // */
@ -50,20 +49,20 @@ public class GlobalExceptionHandler {
// 逻辑异常 // 逻辑异常
@ExceptionHandler(value = ServiceException.class) @ExceptionHandler(value = ServiceException.class)
public CommonResult serviceExceptionHandler(HttpServletRequest req, ServiceException ex) { public CommonResult serviceExceptionHandler(ServiceException ex) {
logger.debug("[serviceExceptionHandler]", ex); logger.debug("[serviceExceptionHandler]", ex);
return CommonResult.error(ex.getCode(), ex.getMessage()); return CommonResult.error(ex.getCode(), ex.getMessage());
} }
// Spring MVC 参数不正确 // Spring MVC 参数不正确
@ExceptionHandler(value = MissingServletRequestParameterException.class) @ExceptionHandler(value = MissingServletRequestParameterException.class)
public CommonResult missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException ex) { public CommonResult missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
logger.warn("[missingServletRequestParameterExceptionHandler]", ex); logger.warn("[missingServletRequestParameterExceptionHandler]", ex);
return CommonResult.error(SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage() + ":" + ex.getMessage()); return CommonResult.error(SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage() + ":" + ex.getMessage());
} }
@ExceptionHandler(value = ConstraintViolationException.class) @ExceptionHandler(value = ConstraintViolationException.class)
public CommonResult constraintViolationExceptionHandler(HttpServletRequest req, ConstraintViolationException ex) { public CommonResult constraintViolationExceptionHandler(ConstraintViolationException ex) {
logger.info("[constraintViolationExceptionHandler]", ex); logger.info("[constraintViolationExceptionHandler]", ex);
// TODO 芋艿后续要想一个更好的方式 // TODO 芋艿后续要想一个更好的方式
// 拼接详细报错 // 拼接详细报错
@ -77,7 +76,7 @@ public class GlobalExceptionHandler {
public CommonResult exceptionHandler(HttpServletRequest req, Exception e) { public CommonResult exceptionHandler(HttpServletRequest req, Exception e) {
logger.error("[exceptionHandler]", e); logger.error("[exceptionHandler]", e);
// 插入异常日志 // 插入异常日志
ExceptionLogAddRequest exceptionLog = new ExceptionLogAddRequest(); ExceptionLogAddDTO exceptionLog = new ExceptionLogAddDTO();
try { try {
// 增加异常计数 metrics TODO 暂时去掉 // 增加异常计数 metrics TODO 暂时去掉
// EXCEPTION_COUNTER.increment(); // EXCEPTION_COUNTER.increment();
@ -92,9 +91,10 @@ public class GlobalExceptionHandler {
return CommonResult.error(SysErrorCodeEnum.SYS_ERROR.getCode(), SysErrorCodeEnum.SYS_ERROR.getMessage()); return CommonResult.error(SysErrorCodeEnum.SYS_ERROR.getCode(), SysErrorCodeEnum.SYS_ERROR.getMessage());
} }
private void initExceptionLog(ExceptionLogAddRequest exceptionLog, HttpServletRequest request, Exception e) { private void initExceptionLog(ExceptionLogAddDTO exceptionLog, HttpServletRequest request, Exception e) {
// 设置账号编号 // 设置账号编号
exceptionLog.setAccountId(CommonWebUtil.getAccountId(request)); exceptionLog.setUserId(CommonWebUtil.getUserId(request));
exceptionLog.setUserType(CommonWebUtil.getUserType(request));
// 设置异常字段 // 设置异常字段
exceptionLog.setExceptionName(e.getClass().getName()); exceptionLog.setExceptionName(e.getClass().getName());
exceptionLog.setExceptionMessage(ExceptionUtil.getMessage(e)); exceptionLog.setExceptionMessage(ExceptionUtil.getMessage(e));
@ -119,13 +119,12 @@ public class GlobalExceptionHandler {
} }
@Async @Async
public void addExceptionLog(ExceptionLogAddRequest exceptionLog) { public void addExceptionLog(ExceptionLogAddDTO exceptionLog) {
try { try {
systemLogRPC.addExceptionLog(exceptionLog); systemLogRPC.addExceptionLog(exceptionLog);
} catch (Throwable th) { } catch (Throwable th) {
logger.error("[addAccessLog][插入异常日志({}) 发生异常({})", JSON.toJSONString(exceptionLog), ExceptionUtils.getRootCauseMessage(th)); logger.error("[addAccessLog][插入异常日志({}) 发生异常({})", JSON.toJSONString(exceptionLog), ExceptionUtils.getRootCauseMessage(th));
} }
} }
} }

View File

@ -3,8 +3,8 @@ package cn.iocoder.mall.web.core.interceptor;
import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.HttpUtil;
import cn.iocoder.common.framework.util.MallUtils; import cn.iocoder.common.framework.util.MallUtils;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC; import cn.iocoder.mall.systemservice.rpc.systemlog.SystemLogRPC;
import cn.iocoder.mall.system.rpc.request.systemlog.AccessLogAddRequest; import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.web.core.util.CommonWebUtil; import cn.iocoder.mall.web.core.util.CommonWebUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
@ -27,7 +27,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
@Reference(validation = "true", version = "${dubbo.consumer.SystemLogRPC.version}") @Reference(validation = "false", version = "${dubbo.consumer.SystemLogRPC.version}")
private SystemLogRPC systemLogRPC; private SystemLogRPC systemLogRPC;
@Value("${spring.application.name}") @Value("${spring.application.name}")
@ -42,7 +42,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
AccessLogAddRequest accessLog = new AccessLogAddRequest(); AccessLogAddDTO accessLog = new AccessLogAddDTO();
try { try {
// 初始化 accessLog // 初始化 accessLog
initAccessLog(accessLog, request); initAccessLog(accessLog, request);
@ -54,9 +54,10 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
} }
} }
private void initAccessLog(AccessLogAddRequest accessLog, HttpServletRequest request) { private void initAccessLog(AccessLogAddDTO accessLog, HttpServletRequest request) {
// 设置账号编号 // 设置账号编号
accessLog.setAccountId(CommonWebUtil.getAccountId(request)); accessLog.setUserId(CommonWebUtil.getUserId(request));
accessLog.setUserType(CommonWebUtil.getUserType(request));
// 设置访问结果 // 设置访问结果
CommonResult result = CommonWebUtil.getCommonResult(request); CommonResult result = CommonWebUtil.getCommonResult(request);
Assert.isTrue(result != null, "result 必须非空"); Assert.isTrue(result != null, "result 必须非空");
@ -75,7 +76,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
} }
@Async // 异步入库 @Async // 异步入库
public void addAccessLog(AccessLogAddRequest accessLog) { public void addAccessLog(AccessLogAddDTO accessLog) {
try { try {
systemLogRPC.addAccessLog(accessLog); systemLogRPC.addAccessLog(accessLog);
} catch (Throwable th) { } catch (Throwable th) {

View File

@ -8,14 +8,22 @@ import java.util.Date;
public class CommonWebUtil { public class CommonWebUtil {
public static Integer getAccountId(ServletRequest request) { public static Integer getUserId(ServletRequest request) {
return (Integer) request.getAttribute(CommonMallConstants.REQUEST_ATTR_USER_ID_KEY); return (Integer) request.getAttribute(CommonMallConstants.REQUEST_ATTR_USER_ID_KEY);
} }
public static void setAccountId(ServletRequest request, Integer userId) { public static void setUserId(ServletRequest request, Integer userId) {
request.setAttribute(CommonMallConstants.REQUEST_ATTR_USER_ID_KEY, userId); request.setAttribute(CommonMallConstants.REQUEST_ATTR_USER_ID_KEY, userId);
} }
public static Integer getUserType(ServletRequest request) {
return (Integer) request.getAttribute(CommonMallConstants.REQUEST_ATTR_USER_TYPE_KEY);
}
public static void setUserType(ServletRequest request, Integer userType) {
request.setAttribute(CommonMallConstants.REQUEST_ATTR_USER_TYPE_KEY, userType);
}
public static CommonResult getCommonResult(ServletRequest request) { public static CommonResult getCommonResult(ServletRequest request) {
return (CommonResult) request.getAttribute(CommonMallConstants.REQUEST_ATTR_COMMON_RESULT); return (CommonResult) request.getAttribute(CommonMallConstants.REQUEST_ATTR_COMMON_RESULT);
} }

View File

@ -17,7 +17,6 @@
<!-- 属性 --> <!-- 属性 -->
<properties> <properties>
<!-- TODO Spring Boot && Spring Cloud && Spring Cloud Alibaba -->
<spring.boot.version>2.2.4.RELEASE</spring.boot.version> <spring.boot.version>2.2.4.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR1</spring.cloud.version> <spring.cloud.version>Hoxton.SR1</spring.cloud.version>
<spring.cloud.alibaba.version>2.2.1.RELEASE</spring.cloud.alibaba.version> <spring.cloud.alibaba.version>2.2.1.RELEASE</spring.cloud.alibaba.version>

View File

@ -28,8 +28,8 @@
<dependencies> <dependencies>
<!-- Web 相关 --> <!-- Web 相关 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>mall-spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- RPC 相关 --> <!-- RPC 相关 -->

View File

@ -28,3 +28,5 @@ dubbo:
version: 1.0.0 version: 1.0.0
AdminRpc: AdminRpc:
version: 1.0.0 version: 1.0.0
SystemLogRPC:
version: 1.0.0

View File

@ -0,0 +1,13 @@
package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
public interface SystemLogRPC {
CommonResult<Boolean> addAccessLog(AccessLogAddDTO accessLogAddDTO);
CommonResult<Boolean> addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.system.rpc.request.systemlog; package cn.iocoder.mall.systemservice.rpc.systemlog.dto;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -8,25 +9,26 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
* 访问日志添加 Request * 访问日志添加 DTO
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class AccessLogAddRequest implements Serializable { public class AccessLogAddDTO implements Serializable {
/**
* 用户编号 -
*/
public static final Integer ACCOUNT_ID_NULL = 0;
/**
* 链路追踪编号
*/
private String traceId;
/** /**
* 账号编号 * 账号编号
*/ */
private Integer accountId; private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 链路编号
*/
private String traceId;
@NotNull(message = "应用名不能为空") @NotNull(message = "应用名不能为空")
private String applicationName; private String applicationName;
@NotNull(message = "访问地址不能为空") @NotNull(message = "访问地址不能为空")

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.system.rpc.request.systemlog; package cn.iocoder.mall.systemservice.rpc.systemlog.dto;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -8,16 +9,22 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
* 异常日志添加 Request * 异常日志添加 DTO
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class ExceptionLogAddRequest implements Serializable { public class ExceptionLogAddDTO implements Serializable {
/** /**
* 账号编号 * 账号编号
*/ */
private Integer accountId; private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/** /**
* 链路编号 * 链路编号
*/ */

View File

@ -0,0 +1,34 @@
package cn.iocoder.mall.systemservice.convert.systemlog;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.AccessLogAddBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.ExceptionLogAddBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SystemLogConvert {
SystemLogConvert INSTANCE = Mappers.getMapper(SystemLogConvert.class);
AccessLogDO convert(AccessLogAddBO bean);
ExceptionLogDO convert(ExceptionLogAddBO bean);
AccessLogAddBO convert(AccessLogAddDTO bean);
ExceptionLogAddBO convert(ExceptionLogAddDTO bean);
// AccessLogDO convert(AccessLogAddDTO bean);
//
// ExceptionLogDO convert(ExceptionLogAddDTO bean);
//
// @Mapping(source = "records", target = "list")
// PageResult<AccessLogBO> convertPage(IPage<AccessLogDO> page);
//
// AccessLogBO convert(AccessLogDO bean);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.system.biz.dataobject.systemlog; package cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.mybatis.dataobject.BaseDO; import cn.iocoder.mall.mybatis.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -12,27 +13,26 @@ import java.util.Date;
/** /**
* 访问日志 DO * 访问日志 DO
*/ */
@TableName("system_access_log")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)
@TableName("access_log")
public class AccessLogDO extends BaseDO { public class AccessLogDO extends BaseDO {
/**
* 账号编号 -
*/
public static final Integer ACCOUNT_ID_NULL = 0;
/** /**
* 编号 * 编号
*/ */
private Integer id; private Integer id;
/** /**
* 账号编号 * 用户编号
*
* 空值 {@link #ACCOUNT_ID_NULL}
*/ */
private Integer accountId; private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/** /**
* 链路追踪编号 * 链路追踪编号
* *

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.system.biz.dataobject.systemlog; package cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import cn.iocoder.mall.mybatis.dataobject.BaseDO; import cn.iocoder.mall.mybatis.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
@ -11,27 +12,26 @@ import java.util.Date;
/** /**
* 异常日志 DO * 异常日志 DO
*/ */
@TableName("system_exception_log")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)
@TableName("exception_log")
public class ExceptionLogDO extends BaseDO { public class ExceptionLogDO extends BaseDO {
/**
* 账号编号 -
*/
public static final Integer ACCOUNT_ID_NULL = 0;
/** /**
* 编号 * 编号
*/ */
private Integer id; private Integer id;
/** /**
* 账号编号 * 用户编号
*
* 空值 {@link #ACCOUNT_ID_NULL}
*/ */
private Integer accountId; private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/** /**
* 链路追踪编号 * 链路追踪编号
* *

View File

@ -1 +0,0 @@
package cn.iocoder.mall.systemservice.dal.mysql.mapper;

View File

@ -0,0 +1,15 @@
package cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.AccessLogDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface AccessLogMapper extends BaseMapper<AccessLogDO> {
// default IPage<AccessLogDO> selectPage(AccessLogPageDTO accessLogPageDTO) {
// return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()),
// new QueryWrapperX<AccessLogDO>().eqIfPresent("account_id", accessLogPageDTO.getAccountId()));
// }
}

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.system.biz.dao.system; package cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog;
import cn.iocoder.mall.system.biz.dataobject.systemlog.ExceptionLogDO; import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.ExceptionLogDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.systemservice.manager.systemlog;
import cn.iocoder.mall.systemservice.convert.systemlog.SystemLogConvert;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
import cn.iocoder.mall.systemservice.service.systemlog.SystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SystemLogManager {
@Autowired
private SystemLogService systemLogService;
public void addAccessLog(AccessLogAddDTO accessLogAddDTO) {
systemLogService.addAccessLog(SystemLogConvert.INSTANCE.convert(accessLogAddDTO));
}
public void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO) {
systemLogService.addExceptionLog(SystemLogConvert.INSTANCE.convert(exceptionLogAddDTO));
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.systemservice.manager.systemlog.SystemLogManager;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service(version = "${dubbo.provider.SystemLogRPC.version}", validation = "false")
public class SystemLogRPCImpl implements SystemLogRPC {
@Autowired
private SystemLogManager systemLogManager;
@Override
public CommonResult<Boolean> addAccessLog(AccessLogAddDTO accessLogAddDTO) {
systemLogManager.addAccessLog(accessLogAddDTO);
return CommonResult.success(true);
}
@Override
public CommonResult<Boolean> addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO) {
systemLogManager.addExceptionLog(exceptionLogAddDTO);
return CommonResult.success(true);
}
}

View File

@ -36,4 +36,8 @@ public class AdminService {
return AdminConvert.INSTANCE.convert(adminDO); return AdminConvert.INSTANCE.convert(adminDO);
} }
// public PageResult<AdminBO> getAdminPage(AdminPageDTO pageDTO) {
// return AdminConvert.INSTANCE.convertPage(adminMapper.selectPage(pageDTO));
// }
} }

View File

@ -0,0 +1,39 @@
package cn.iocoder.mall.systemservice.service.systemlog;
import cn.iocoder.mall.systemservice.convert.systemlog.SystemLogConvert;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog.AccessLogMapper;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog.ExceptionLogMapper;
import cn.iocoder.mall.systemservice.service.systemlog.bo.AccessLogAddBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.ExceptionLogAddBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SystemLogService {
@Autowired
private AccessLogMapper accessLogMapper;
@Autowired
private ExceptionLogMapper exceptionLogMapper;
public void addAccessLog(AccessLogAddBO accessLogAddBO) {
AccessLogDO logDO = SystemLogConvert.INSTANCE.convert(accessLogAddBO);
accessLogMapper.insert(logDO);
}
public void addExceptionLog(ExceptionLogAddBO exceptionLogAddBO) {
ExceptionLogDO logDO = SystemLogConvert.INSTANCE.convert(exceptionLogAddBO);
exceptionLogMapper.insert(logDO);
}
// @Override
// @SuppressWarnings("Duplicates")
// public PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO) {
// PageResult<AccessLogBO> accessLogPageBOPageResult = SystemLogConvert.INSTANCE.convertPage(
// accessLogMapper.selectPage(accessLogPageDTO)); // TODO FROM 芋艿 to 2447007062可以考虑直接 return简洁 + IDEA 不告警
// return accessLogPageBOPageResult;
// }
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.mall.systemservice.service.systemlog.bo;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* 访问日志添加 BO
*/
@Data
@Accessors(chain = true)
public class AccessLogAddBO implements Serializable {
/**
* 账号编号
*/
private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 链路编号
*/
private String traceId;
@NotNull(message = "应用名不能为空")
private String applicationName;
@NotNull(message = "访问地址不能为空")
private String uri;
@NotNull(message = "请求参数不能为空")
private String queryString;
@NotNull(message = "http 请求方法不能为空")
private String method;
@NotNull(message = "User-Agent 不能为空")
private String userAgent;
@NotNull(message = "ip 不能为空")
private String ip;
@NotNull(message = "请求时间不能为空")
private Date startTime;
@NotNull(message = "响应时长不能为空")
private Integer responseTime;
@NotNull(message = "错误码不能为空")
private Integer errorCode;
/**
* 错误提示
*/
private String errorMessage;
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.mall.systemservice.service.systemlog.bo;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* 异常日志添加 BO
*/
@Data
@Accessors(chain = true)
public class ExceptionLogAddBO implements Serializable {
/**
* 账号编号
*/
private Integer userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 链路编号
*/
private String traceId;
@NotNull(message = "应用名不能为空")
private String applicationName;
@NotNull(message = "访问地址不能为空")
private String uri;
@NotNull(message = "请求参数不能为空")
private String queryString;
@NotNull(message = "http 请求方法不能为空")
private String method;
@NotNull(message = "User-Agent 不能为空")
private String userAgent;
@NotNull(message = "ip 不能为空")
private String ip;
@NotNull(message = "异常时间不能为空")
private Date exceptionTime;
@NotNull(message = "异常名不能为空")
private String exceptionName;
@NotNull(message = "异常发生的类全名不能为空")
private String exceptionClassName;
@NotNull(message = "异常发生的类文件不能为空")
private String exceptionFileName;
@NotNull(message = "异常发生的方法名不能为空")
private String exceptionMethodName;
@NotNull(message = "异常发生的方法所在行不能为空")
private Integer exceptionLineNumber;
@NotNull(message = "异常的栈轨迹不能为空")
private String exceptionStackTrace;
@NotNull(message = "异常导致的根消息不能为空")
private String exceptionRootCauseMessage;
@NotNull(message = "异常导致的消息不能为空")
private String exceptionMessage;
}

View File

@ -37,3 +37,5 @@ dubbo:
version: 1.0.0 version: 1.0.0
AdminRpc: AdminRpc:
version: 1.0.0 version: 1.0.0
SystemLogRPC:
version: 1.0.0

View File

@ -1,26 +0,0 @@
package cn.iocoder.mall.system.biz.bo.account;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 账号模块 - 账号信息 BO
*/
@Data
@Accessors(chain = true)
public class AccountBO {
/**
* 账号编号
*/
private Integer id;
/**
* 登陆账号
*/
private String username;
/**
* 登陆密码
*/
private String password;
}

View File

@ -1,22 +0,0 @@
package cn.iocoder.mall.system.biz.bo.account;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 账号模块 - 用户名登陆 BO
*/
@Data
@Accessors(chain = true)
public class AccountUsernameAuthorizeBO {
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
}

View File

@ -1,40 +0,0 @@
package cn.iocoder.mall.system.biz.bo.admin;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 管理员模块 - 账号信息 BO
*/
@Data
@Accessors(chain = true)
public class AdminBO {
/**
* 管理员编号
*/
private Integer id;
/**
* 账号编号
*/
private Integer accountId;
/**
* 真实名字
*/
private String name;
/**
* 部门编号
*/
private Integer departmentId;
/**
* 在职状态
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -1,32 +0,0 @@
package cn.iocoder.mall.system.biz.bo.ouath2;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 认证模块 - 认证结果 BO
*/
@Data
@Accessors(chain = true)
public class OAuth2AuthenticateBO {
/**
* 访问令牌
*/
private String accessToken;
/**
* 刷新令牌
*/
private String refreshToken;
/**
* 账号编号
*/
private Integer accountId;
/**
* 过期时间
*/
private Date expiresTime;
}

View File

@ -1,41 +0,0 @@
package cn.iocoder.mall.system.biz.bo.systemlog;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/** // TODO FROM 芋艿 to 2447007062最好加下字段的注释哈
* @author:mac
* @descriptio
* @create: 2020-5-12 204300
*/
@Data
@Accessors(chain = true)
public class AccessLogBO implements Serializable {
private String traceId;
private Integer accountId;
private String applicationName;
private String uri;
private String queryString;
private String method;
private String userAgent;
private String ip;
private Date startTime;
private Integer responseTime;
private Integer errorCode;
private String errorMessage;
}

View File

@ -1,15 +0,0 @@
package cn.iocoder.mall.system.biz.bo.user;
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class UserAuthenticateBO {
private UserBO user;
private OAuth2AuthenticateBO token;
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.mall.system.biz.bo.user;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* User 模块 - User 信息 BO
*/
@Data
@Accessors(chain = true)
public class UserBO {
/**
* 用户编号
*/
private Integer id;
/**
* 昵称
*/
private String nickname;
/**
* 手机号
*/
private String mobile;
/**
* 头像
*/
private String avatar;
/**
* 用户状态 1 - 开启2 - 禁用
*/
private Integer status;
}

View File

@ -1,18 +0,0 @@
package cn.iocoder.mall.system.biz.convert.account;
import cn.iocoder.mall.system.biz.bo.account.AccountBO;
import cn.iocoder.mall.system.biz.dataobject.account.AccountDO;
import cn.iocoder.mall.system.biz.dto.account.AccountCreateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AccountConvert {
AccountConvert INSTANCE = Mappers.getMapper(AccountConvert.class);
AccountBO convert(AccountDO bean);
AccountDO convert(AccountCreateDTO bean);
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.system.biz.convert.admin;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.admin.AdminBO;
import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AdminConvert {
AdminConvert INSTANCE = Mappers.getMapper(AdminConvert.class);
AdminBO convert(AdminDO bean);
@Mapping(source = "records", target = "list")
PageResult<AdminBO> convertPage(IPage<AdminDO> bean);
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.mall.system.biz.convert.oauth2;
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
import cn.iocoder.mall.system.biz.dataobject.oauth2.OAuth2AccessTokenDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface OAuth2Convert {
OAuth2Convert INSTANCE = Mappers.getMapper(OAuth2Convert.class);
@Mapping(source = "id", target = "accessToken")
OAuth2AuthenticateBO convert(OAuth2AccessTokenDO bean);
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.system.biz.convert.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SystemLogConvert {
SystemLogConvert INSTANCE = Mappers.getMapper(SystemLogConvert.class);
AccessLogDO convert(AccessLogAddDTO bean);
ExceptionLogDO convert(ExceptionLogAddDTO bean);
@Mapping(source = "records", target = "list")
PageResult<AccessLogBO> convertPage(IPage<AccessLogDO> page);
AccessLogBO convert(AccessLogDO bean);
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.mall.system.biz.dao.system;
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
/**
* 访问日志
* @author:mac
* @descriptio
* @create: 2020-5-12 204300
*/
@Repository
public interface AccessLogMapper extends BaseMapper<AccessLogDO> {
default IPage<AccessLogDO> selectPage(AccessLogPageDTO accessLogPageDTO) {
return selectPage(new Page<>(accessLogPageDTO.getPageNo(), accessLogPageDTO.getPageSize()),
new QueryWrapperX<AccessLogDO>().eqIfPresent("account_id", accessLogPageDTO.getAccountId()));
}
}

View File

@ -1,19 +0,0 @@
package cn.iocoder.mall.system.biz.service.account;
import cn.iocoder.mall.system.biz.bo.account.AccountBO;
import cn.iocoder.mall.system.biz.dto.account.AccountCreateDTO;
/**
* 账号模块 - Service 接口
*/
public interface AccountService {
AccountBO getByUsername(String username);
AccountBO getByMobile(String mobile);
boolean matchPassword(String rawPassword, String encodedPassword);
AccountBO create(AccountCreateDTO createDTO);
}

View File

@ -1,49 +0,0 @@
package cn.iocoder.mall.system.biz.service.account;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.mall.system.biz.bo.account.AccountBO;
import cn.iocoder.mall.system.biz.convert.account.AccountConvert;
import cn.iocoder.mall.system.biz.dao.account.AccountMapper;
import cn.iocoder.mall.system.biz.dataobject.account.AccountDO;
import cn.iocoder.mall.system.biz.dto.account.AccountCreateDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Objects;
@Service
public class AccountServiceImpl implements AccountService {
@Autowired
private AccountMapper accountMapper;
@Override
public AccountBO getByUsername(String username) {
AccountDO accountDO = accountMapper.selectByUsername(username);
return AccountConvert.INSTANCE.convert(accountDO);
}
@Override
public AccountBO getByMobile(String mobile) {
AccountDO accountDO = accountMapper.selectByMobile(mobile);
return AccountConvert.INSTANCE.convert(accountDO);
}
@Override
public boolean matchPassword(String rawPassword, String encodedPassword) {
return Objects.equals(rawPassword, encodedPassword);
}
@Override
public AccountBO create(AccountCreateDTO createDTO) {
// 插入
AccountDO accountDO = AccountConvert.INSTANCE.convert(createDTO);
accountDO.setStatus(CommonStatusEnum.ENABLE.getValue());
accountDO.setCreateTime(new Date());
accountMapper.insert(accountDO);
// 转换返回
return AccountConvert.INSTANCE.convert(accountDO);
}
}

View File

@ -1,30 +0,0 @@
package cn.iocoder.mall.system.biz.service.admin;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.admin.AdminBO;
import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO;
/**
* 管理员模块 - Service 接口
*/
public interface AdminService {
/**
* 根据编号获得管理员信息
*
* @param id 编号
* @return 管理员
*/
AdminBO getAdmin(Integer id);
/**
* 获得账号编号获得管理员信息
*
* @param accountId 账号编号
* @return 管理员
*/
AdminBO getAdminByAccountId(Integer accountId);
PageResult<AdminBO> getAdminPage(AdminPageDTO pageDTO);
}

View File

@ -1,19 +0,0 @@
package cn.iocoder.mall.system.biz.service.admin;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.admin.AdminBO;
import cn.iocoder.mall.system.biz.convert.admin.AdminConvert;
import cn.iocoder.mall.system.biz.dao.admin.AdminMapper;
import cn.iocoder.mall.system.biz.dto.admin.AdminPageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AdminServiceImpl implements AdminService {
@Override
public PageResult<AdminBO> getAdminPage(AdminPageDTO pageDTO) {
return AdminConvert.INSTANCE.convertPage(adminMapper.selectPage(pageDTO));
}
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.mall.system.biz.service.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
public interface SystemLogService {
void addAccessLog(AccessLogAddDTO accessLogAddDTO);
void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO);
PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO);
}

View File

@ -1,54 +0,0 @@
package cn.iocoder.mall.system.biz.service.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.biz.convert.systemlog.SystemLogConvert;
import cn.iocoder.mall.system.biz.dao.system.AccessLogMapper;
import cn.iocoder.mall.system.biz.dao.system.ExceptionLogMapper;
import cn.iocoder.mall.system.biz.dataobject.systemlog.AccessLogDO;
import cn.iocoder.mall.system.biz.dataobject.systemlog.ExceptionLogDO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.AccessLogPageDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class SystemLogServiceImpl implements SystemLogService {
@Autowired
private AccessLogMapper accessLogMapper;
@Autowired
private ExceptionLogMapper exceptionLogMapper;
@Override
public void addAccessLog(AccessLogAddDTO accessLogAddDTO) {
AccessLogDO logDO = SystemLogConvert.INSTANCE.convert(accessLogAddDTO);
if (logDO.getAccountId() == null) {
logDO.setAccountId(AccessLogDO.ACCOUNT_ID_NULL);
}
logDO.setCreateTime(new Date());
accessLogMapper.insert(logDO);
}
@Override
public void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO) {
ExceptionLogDO logDO = SystemLogConvert.INSTANCE.convert(exceptionLogAddDTO);
if (logDO.getAccountId() == null) {
logDO.setAccountId(ExceptionLogDO.ACCOUNT_ID_NULL);
}
logDO.setCreateTime(new Date());
exceptionLogMapper.insert(logDO);
}
@Override
@SuppressWarnings("Duplicates")
public PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO) {
PageResult<AccessLogBO> accessLogPageBOPageResult = SystemLogConvert.INSTANCE.convertPage(
accessLogMapper.selectPage(accessLogPageDTO)); // TODO FROM 芋艿 to 2447007062可以考虑直接 return简洁 + IDEA 不告警
return accessLogPageBOPageResult;
}
}

View File

@ -1,13 +0,0 @@
package cn.iocoder.mall.system.rpc.api.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.rpc.request.systemlog.AccessLogAddRequest;
import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest;
public interface SystemLogRPC {
CommonResult<Boolean> addAccessLog(AccessLogAddRequest accessLogAddRequest);
CommonResult<Boolean> addExceptionLog(ExceptionLogAddRequest exceptionLogAddRequest);
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.mall.system.rpc.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
import cn.iocoder.mall.system.biz.service.systemlog.SystemLogService;
import cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC;
import cn.iocoder.mall.system.rpc.convert.systemlog.SystemLogConvert;
import cn.iocoder.mall.system.rpc.request.systemlog.AccessLogAddRequest;
import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service(version = "${dubbo.provider.SystemLogRPC.version}", validation = "true")
public class SystemLogRPCImpl implements SystemLogRPC {
@Autowired
private SystemLogService systemLogService;
@Override
public CommonResult<Boolean> addAccessLog(AccessLogAddRequest accessLogAddRequest) {
AccessLogAddDTO accessLogAddDTO = SystemLogConvert.INSTANCE.convert(accessLogAddRequest);
systemLogService.addAccessLog(accessLogAddDTO);
return CommonResult.success(true);
}
@Override
public CommonResult<Boolean> addExceptionLog(ExceptionLogAddRequest exceptionLogAddRequest) {
ExceptionLogAddDTO exceptionLogAddDTO = SystemLogConvert.INSTANCE.convert(exceptionLogAddRequest);
systemLogService.addExceptionLog(exceptionLogAddDTO);
return CommonResult.success(true);
}
}