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

pull/3/head
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();
CommonWebUtil.setAccountId(request, accountId);
CommonWebUtil.setUserId(request, accountId);
return accountId;
}

View File

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

View File

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

View File

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

View File

@ -1,10 +1,9 @@
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.GlobalResponseBodyHandler;
import cn.iocoder.mall.web.core.interceptor.AccessLogInterceptor;
import cn.iocoder.mall.web.core.servlet.CorsFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@ -40,7 +39,7 @@ public class CommonWebAutoConfiguration implements WebMvcConfigurer {
// ========== 拦截器相关 ==========
@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)
public AccessLogInterceptor accessLogInterceptor() {
return new AccessLogInterceptor();
@ -49,8 +48,7 @@ public class CommonWebAutoConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
try {
registry.addInterceptor(this.accessLogInterceptor())
.addPathPatterns(CommonMallConstants.ROOT_PATH_ADMIN + "/**", CommonMallConstants.ROOT_PATH_USER + "/**");
registry.addInterceptor(this.accessLogInterceptor());
logger.info("[addInterceptors][加载 AccessLogInterceptor 拦截器完成]");
} catch (NoSuchBeanDefinitionException e) {
logger.warn("[addInterceptors][无法获取 AccessLogInterceptor 拦截器,因此不启动 AccessLog 的记录]");

View File

@ -6,19 +6,33 @@ public interface CommonMallConstants {
/**
* -
*/
@Deprecated
String ROOT_PATH_USER = "/users";
/**
* -
*/
@Deprecated
String ROOT_PATH_ADMIN = "/admins";
// 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
*
* Request Attribute访
*/
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.MallUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC;
import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest;
import cn.iocoder.mall.systemservice.rpc.systemlog.SystemLogRPC;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.ExceptionLogAddDTO;
import cn.iocoder.mall.web.core.util.CommonWebUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.exception.ExceptionUtils;
@ -33,7 +33,6 @@ public class GlobalExceptionHandler {
// TODO 芋艿,应该还有其它的异常,需要进行翻译
// /**
// * 异常总数 Metrics
// */
@ -50,20 +49,20 @@ public class GlobalExceptionHandler {
// 逻辑异常
@ExceptionHandler(value = ServiceException.class)
public CommonResult serviceExceptionHandler(HttpServletRequest req, ServiceException ex) {
public CommonResult serviceExceptionHandler(ServiceException ex) {
logger.debug("[serviceExceptionHandler]", ex);
return CommonResult.error(ex.getCode(), ex.getMessage());
}
// Spring MVC 参数不正确
@ExceptionHandler(value = MissingServletRequestParameterException.class)
public CommonResult missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException ex) {
public CommonResult missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
logger.warn("[missingServletRequestParameterExceptionHandler]", ex);
return CommonResult.error(SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getCode(), SysErrorCodeEnum.MISSING_REQUEST_PARAM_ERROR.getMessage() + ":" + ex.getMessage());
}
@ExceptionHandler(value = ConstraintViolationException.class)
public CommonResult constraintViolationExceptionHandler(HttpServletRequest req, ConstraintViolationException ex) {
public CommonResult constraintViolationExceptionHandler(ConstraintViolationException ex) {
logger.info("[constraintViolationExceptionHandler]", ex);
// TODO 芋艿,后续要想一个更好的方式。
// 拼接详细报错
@ -77,7 +76,7 @@ public class GlobalExceptionHandler {
public CommonResult exceptionHandler(HttpServletRequest req, Exception e) {
logger.error("[exceptionHandler]", e);
// 插入异常日志
ExceptionLogAddRequest exceptionLog = new ExceptionLogAddRequest();
ExceptionLogAddDTO exceptionLog = new ExceptionLogAddDTO();
try {
// 增加异常计数 metrics TODO 暂时去掉
// EXCEPTION_COUNTER.increment();
@ -92,9 +91,10 @@ public class GlobalExceptionHandler {
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.setExceptionMessage(ExceptionUtil.getMessage(e));
@ -119,13 +119,12 @@ public class GlobalExceptionHandler {
}
@Async
public void addExceptionLog(ExceptionLogAddRequest exceptionLog) {
public void addExceptionLog(ExceptionLogAddDTO exceptionLog) {
try {
systemLogRPC.addExceptionLog(exceptionLog);
} catch (Throwable 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.MallUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.rpc.api.systemlog.SystemLogRPC;
import cn.iocoder.mall.system.rpc.request.systemlog.AccessLogAddRequest;
import cn.iocoder.mall.systemservice.rpc.systemlog.SystemLogRPC;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.AccessLogAddDTO;
import cn.iocoder.mall.web.core.util.CommonWebUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.exception.ExceptionUtils;
@ -27,7 +27,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
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;
@Value("${spring.application.name}")
@ -42,7 +42,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
AccessLogAddRequest accessLog = new AccessLogAddRequest();
AccessLogAddDTO accessLog = new AccessLogAddDTO();
try {
// 初始化 accessLog
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);
Assert.isTrue(result != null, "result 必须非空");
@ -75,7 +76,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
}
@Async // 异步入库
public void addAccessLog(AccessLogAddRequest accessLog) {
public void addAccessLog(AccessLogAddDTO accessLog) {
try {
systemLogRPC.addAccessLog(accessLog);
} catch (Throwable th) {

View File

@ -8,14 +8,22 @@ import java.util.Date;
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);
}
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);
}
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) {
return (CommonResult) request.getAttribute(CommonMallConstants.REQUEST_ATTR_COMMON_RESULT);
}

View File

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

View File

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

View File

@ -28,3 +28,5 @@ dubbo:
version: 1.0.0
AdminRpc:
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.experimental.Accessors;
@ -8,25 +9,26 @@ import java.io.Serializable;
import java.util.Date;
/**
* 访 Request
* 访 DTO
*/
@Data
@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 = "应用名不能为空")
private String applicationName;
@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.experimental.Accessors;
@ -8,16 +9,22 @@ import java.io.Serializable;
import java.util.Date;
/**
* Request
* DTO
*/
@Data
@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.mall.mybatis.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableName;
@ -12,27 +13,26 @@ import java.util.Date;
/**
* 访 DO
*/
@TableName("system_access_log")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("access_log")
public class AccessLogDO extends BaseDO {
/**
* -
*/
public static final Integer ACCOUNT_ID_NULL = 0;
/**
*
*/
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 com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -11,27 +12,26 @@ import java.util.Date;
/**
* DO
*/
@TableName("system_exception_log")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("exception_log")
public class ExceptionLogDO extends BaseDO {
/**
* -
*/
public static final Integer ACCOUNT_ID_NULL = 0;
/**
*
*/
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 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);
}
// 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
AdminRpc:
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);
}
}