mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	将 login_log、error_log 迁移到 yudao-core-service 项目中
This commit is contained in:
		| @@ -18,7 +18,7 @@ public class SecurityConfiguration { | ||||
|     @Bean | ||||
|     public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { | ||||
|         return registry -> { | ||||
|             registry.antMatchers(api("/**")).anonymous(); // 默认 API 都是用户可访问 | ||||
|             registry.antMatchers(api("/**")).permitAll(); // 默认 API 都是用户可访问 | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,28 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.controller; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.security.access.annotation.Secured; | ||||
| import org.springframework.security.access.prepost.PreAuthorize; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| /** | ||||
|  * @author weir | ||||
|  */ | ||||
| @Slf4j | ||||
| @RestController | ||||
| public class HelloController { | ||||
|  | ||||
|     @RequestMapping("/user/hello") | ||||
|     public String hello(String hello) { | ||||
|         return "echo + " + hello; | ||||
|     } | ||||
|  | ||||
|     @RequestMapping("/user/info") | ||||
|     @PreAuthenticated | ||||
|     public String xx() { | ||||
|         return "none"; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,20 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.convert.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| /** | ||||
|  * API 访问日志 Convert | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface InfApiAccessLogConvert { | ||||
|  | ||||
|     InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class); | ||||
|  | ||||
|     InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); | ||||
|  | ||||
| } | ||||
| @@ -1,20 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.convert.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| /** | ||||
|  * API 错误日志 Convert | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface InfApiErrorLogConvert { | ||||
|  | ||||
|     InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); | ||||
|  | ||||
|     InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); | ||||
|  | ||||
| } | ||||
| @@ -1,6 +0,0 @@ | ||||
| /** | ||||
|  * 提供 POJO 类的实体转换 | ||||
|  * | ||||
|  * 目前使用 MapStruct 框架 | ||||
|  */ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.convert; | ||||
| @@ -1 +0,0 @@ | ||||
| <http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao> | ||||
| @@ -1,64 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.config; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.TableField; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| /** | ||||
|  * 参数配置表 | ||||
|  * | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| @TableName("inf_config") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class InfConfigDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 参数主键 | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|     /** | ||||
|      * 参数分组 | ||||
|      */ | ||||
|     @TableField("`group`") | ||||
|     private String group; | ||||
|     /** | ||||
|      * 参数名称 | ||||
|      */ | ||||
|     private String name; | ||||
|     /** | ||||
|      * 参数键名 | ||||
|      */ | ||||
|     @TableField("`key`") | ||||
|     private String key; | ||||
|     /** | ||||
|      * 参数键值 | ||||
|      */ | ||||
|     private String value; | ||||
|     /** | ||||
|      * 参数类型 | ||||
|      * | ||||
|      * 枚举 {@link InfConfigTypeEnum} | ||||
|      */ | ||||
|     @TableField("`type`") | ||||
|     private Integer type; | ||||
|     /** | ||||
|      * 是否敏感 | ||||
|      * | ||||
|      * 对于敏感配置,需要管理权限才能查看 | ||||
|      */ | ||||
|     @TableField("`sensitive`") | ||||
|     private Boolean sensitive; | ||||
|     /** | ||||
|      * 备注 | ||||
|      */ | ||||
|     private String remark; | ||||
|  | ||||
| } | ||||
| @@ -1,43 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.IdType; | ||||
| import com.baomidou.mybatisplus.annotation.TableField; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| import java.io.InputStream; | ||||
|  | ||||
| /** | ||||
|  * 文件表 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Data | ||||
| @TableName("inf_file") | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class InfFileDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 文件路径 | ||||
|      */ | ||||
|     @TableId(type = IdType.INPUT) | ||||
|     private String id; | ||||
|     /** | ||||
|      * 文件类型 | ||||
|      * | ||||
|      * 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取 | ||||
|      */ | ||||
|     @TableField(value = "`type`") | ||||
|     private String type; | ||||
|     /** | ||||
|      * 文件内容 | ||||
|      */ | ||||
|     private byte[] content; | ||||
|  | ||||
| } | ||||
| @@ -1,107 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * API 访问日志 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @TableName("inf_api_access_log") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class InfApiAccessLogDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 编号 | ||||
|      */ | ||||
|     @TableId | ||||
|     private Integer id; | ||||
|     /** | ||||
|      * 链路追踪编号 | ||||
|      * | ||||
|      * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。 | ||||
|      */ | ||||
|     private String traceId; | ||||
|     /** | ||||
|      * 用户编号 | ||||
|      */ | ||||
|     private Long userId; | ||||
|     /** | ||||
|      * 用户类型 | ||||
|      * | ||||
|      * 枚举 {@link UserTypeEnum} | ||||
|      */ | ||||
|     private Integer userType; | ||||
|     /** | ||||
|      * 应用名 | ||||
|      * | ||||
|      * 目前读取 `spring.application.name` 配置项 | ||||
|      */ | ||||
|     private String applicationName; | ||||
|  | ||||
|     // ========== 请求相关字段 ========== | ||||
|  | ||||
|     /** | ||||
|      * 请求方法名 | ||||
|      */ | ||||
|     private String requestMethod; | ||||
|     /** | ||||
|      * 访问地址 | ||||
|      */ | ||||
|     private String requestUrl; | ||||
|     /** | ||||
|      * 请求参数 | ||||
|      * | ||||
|      * query: Query String | ||||
|      * body: Quest Body | ||||
|      */ | ||||
|     private String requestParams; | ||||
|     /** | ||||
|      * 用户 IP | ||||
|      */ | ||||
|     private String userIp; | ||||
|     /** | ||||
|      * 浏览器 UA | ||||
|      */ | ||||
|     private String userAgent; | ||||
|  | ||||
|     // ========== 执行相关字段 ========== | ||||
|  | ||||
|     /** | ||||
|      * 开始请求时间 | ||||
|      */ | ||||
|     private Date beginTime; | ||||
|     /** | ||||
|      * 结束请求时间 | ||||
|      */ | ||||
|     private Date endTime; | ||||
|     /** | ||||
|      * 执行时长,单位:毫秒 | ||||
|      */ | ||||
|     private Integer duration; | ||||
|     /** | ||||
|      * 结果码 | ||||
|      * | ||||
|      * 目前使用的 {@link CommonResult#getCode()} 属性 | ||||
|      */ | ||||
|     private Integer resultCode; | ||||
|     /** | ||||
|      * 结果提示 | ||||
|      * | ||||
|      * 目前使用的 {@link CommonResult#getMsg()} 属性 | ||||
|      */ | ||||
|     private String resultMsg; | ||||
|  | ||||
| } | ||||
| @@ -1,152 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * API 异常数据 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @TableName("inf_api_error_log") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class InfApiErrorLogDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 编号 | ||||
|      */ | ||||
|     private Long id; | ||||
|     /** | ||||
|      * 用户编号 | ||||
|      */ | ||||
|     private Long userId; | ||||
|     /** | ||||
|      * 链路追踪编号 | ||||
|      * | ||||
|      * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。 | ||||
|      */ | ||||
|     private String traceId; | ||||
|     /** | ||||
|      * 用户类型 | ||||
|      * | ||||
|      * 枚举 {@link UserTypeEnum} | ||||
|      */ | ||||
|     private Integer userType; | ||||
|     /** | ||||
|      * 应用名 | ||||
|      * | ||||
|      * 目前读取 spring.application.name | ||||
|      */ | ||||
|     private String applicationName; | ||||
|  | ||||
|     // ========== 请求相关字段 ========== | ||||
|  | ||||
|     /** | ||||
|      * 请求方法名 | ||||
|      */ | ||||
|     private String requestMethod; | ||||
|     /** | ||||
|      * 访问地址 | ||||
|      */ | ||||
|     private String requestUrl; | ||||
|     /** | ||||
|      * 请求参数 | ||||
|      * | ||||
|      * query: Query String | ||||
|      * body: Quest Body | ||||
|      */ | ||||
|     private String requestParams; | ||||
|     /** | ||||
|      * 用户 IP | ||||
|      */ | ||||
|     private String userIp; | ||||
|     /** | ||||
|      * 浏览器 UA | ||||
|      */ | ||||
|     private String userAgent; | ||||
|  | ||||
|     // ========== 异常相关字段 ========== | ||||
|  | ||||
|     /** | ||||
|      * 异常发生时间 | ||||
|      */ | ||||
|     private Date exceptionTime; | ||||
|     /** | ||||
|      * 异常名 | ||||
|      * | ||||
|      * {@link Throwable#getClass()} 的类全名 | ||||
|      */ | ||||
|     private String exceptionName; | ||||
|     /** | ||||
|      * 异常导致的消息 | ||||
|      * | ||||
|      * {@link cn.hutool.core.exceptions.ExceptionUtil#getMessage(Throwable)} | ||||
|      */ | ||||
|     private String exceptionMessage; | ||||
|     /** | ||||
|      * 异常导致的根消息 | ||||
|      * | ||||
|      * {@link cn.hutool.core.exceptions.ExceptionUtil#getRootCauseMessage(Throwable)} | ||||
|      */ | ||||
|     private String exceptionRootCauseMessage; | ||||
|     /** | ||||
|      * 异常的栈轨迹 | ||||
|      * | ||||
|      * {@link org.apache.commons.lang3.exception.ExceptionUtils#getStackTrace(Throwable)} | ||||
|      */ | ||||
|     private String exceptionStackTrace; | ||||
|     /** | ||||
|      * 异常发生的类全名 | ||||
|      * | ||||
|      * {@link StackTraceElement#getClassName()} | ||||
|      */ | ||||
|     private String exceptionClassName; | ||||
|     /** | ||||
|      * 异常发生的类文件 | ||||
|      * | ||||
|      * {@link StackTraceElement#getFileName()} | ||||
|      */ | ||||
|     private String exceptionFileName; | ||||
|     /** | ||||
|      * 异常发生的方法名 | ||||
|      * | ||||
|      * {@link StackTraceElement#getMethodName()} | ||||
|      */ | ||||
|     private String exceptionMethodName; | ||||
|     /** | ||||
|      * 异常发生的方法所在行 | ||||
|      * | ||||
|      * {@link StackTraceElement#getLineNumber()} | ||||
|      */ | ||||
|     private Integer exceptionLineNumber; | ||||
|  | ||||
|     // ========== 处理相关字段 ========== | ||||
|  | ||||
|     /** | ||||
|      * 处理状态 | ||||
|      * | ||||
|      * 枚举 {@link InfApiErrorLogProcessStatusEnum} | ||||
|      */ | ||||
|     private Integer processStatus; | ||||
|     /** | ||||
|      * 处理时间 | ||||
|      */ | ||||
|     private Date processTime; | ||||
|     /** | ||||
|      * 处理用户编号 | ||||
|      * | ||||
|      * 关联 cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO.SysUserDO#getId() | ||||
|      */ | ||||
|     private Long processUserId; | ||||
|  | ||||
| } | ||||
| @@ -1,39 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; | ||||
| import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; | ||||
| import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||||
| import org.springframework.jdbc.core.JdbcTemplate; | ||||
| import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||||
|  | ||||
| import javax.sql.DataSource; | ||||
| import java.sql.ResultSet; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * ConfigFrameworkDAO 实现类 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| public class InfConfigDAOImpl implements ConfigFrameworkDAO { | ||||
|  | ||||
|     private final JdbcTemplate jdbcTemplate; | ||||
|  | ||||
|     public InfConfigDAOImpl(String jdbcUrl, String username, String password) { | ||||
|         DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password); | ||||
|         this.jdbcTemplate = new JdbcTemplate(dataSource); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { | ||||
|         return jdbcTemplate.query("SELECT id FROM inf_config WHERE update_time > ? LIMIT 1", | ||||
|                 ResultSet::next, maxUpdateTime); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ConfigRespDTO> selectList() { | ||||
|         return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,10 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.file; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file.InfFileDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| @Mapper | ||||
| public interface InfFileMapper extends BaseMapperX<InfFileDO> { | ||||
|  | ||||
| } | ||||
| @@ -1,16 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * API 访问日志 Mapper | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface InfApiAccessLogMapper extends BaseMapperX<InfApiAccessLogDO> { | ||||
| } | ||||
| @@ -1,14 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| /** | ||||
|  * API 错误日志 Mapper | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> { | ||||
| } | ||||
| @@ -1,28 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.enums.logger; | ||||
|  | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.Getter; | ||||
|  | ||||
| /** | ||||
|  * API 异常数据的处理状态 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @AllArgsConstructor | ||||
| @Getter | ||||
| public enum InfApiErrorLogProcessStatusEnum { | ||||
|  | ||||
|     INIT(0, "未处理"), | ||||
|     DONE(1, "已处理"), | ||||
|     IGNORE(2, "已忽略"); | ||||
|  | ||||
|     /** | ||||
|      * 状态 | ||||
|      */ | ||||
|     private final Integer status; | ||||
|     /** | ||||
|      * 资源类型名 | ||||
|      */ | ||||
|     private final String name; | ||||
|  | ||||
| } | ||||
| @@ -1,4 +0,0 @@ | ||||
| /** | ||||
|  * 占位类,可以无视 | ||||
|  */ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.enums; | ||||
| @@ -1,7 +0,0 @@ | ||||
| /** | ||||
|  * infra 包下,我们放基础设施的运维与管理,支撑上层的通用与核心业务。 | ||||
|  * 例如说:定时任务的管理、服务器的信息等等 | ||||
|  * | ||||
|  * 缩写:inf | ||||
|  */ | ||||
| package cn.iocoder.yudao.userserver.modules.infra; | ||||
| @@ -1,12 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.service.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; | ||||
|  | ||||
| /** | ||||
|  * API 访问日志 Service 接口 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| public interface InfApiAccessLogService extends ApiAccessLogFrameworkService { | ||||
|  | ||||
| } | ||||
| @@ -1,12 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.service.logger; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; | ||||
|  | ||||
| /** | ||||
|  * API 错误日志 Service 接口 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { | ||||
|  | ||||
| } | ||||
| @@ -1,36 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiAccessLogConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiAccessLogService; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.scheduling.annotation.AsyncResult; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.concurrent.Future; | ||||
|  | ||||
| /** | ||||
|  * API 访问日志 Service 实现类 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Service | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class InfApiAccessLogServiceImpl implements InfApiAccessLogService { | ||||
|  | ||||
|     @Resource | ||||
|     private InfApiAccessLogMapper apiAccessLogMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { | ||||
|         InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO); | ||||
|         int insert = apiAccessLogMapper.insert(apiAccessLog); | ||||
|         return new AsyncResult<>(insert > 1); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,38 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiErrorLogConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiErrorLogService; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.scheduling.annotation.AsyncResult; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.concurrent.Future; | ||||
|  | ||||
| /** | ||||
|  * API 错误日志 Service 实现类 | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| @Service | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { | ||||
|  | ||||
|     @Resource | ||||
|     private InfApiErrorLogMapper apiErrorLogMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { | ||||
|         InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); | ||||
|         apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); | ||||
|         int insert = apiErrorLogMapper.insert(apiErrorLog); | ||||
|         return new AsyncResult<>(insert == 1); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1 +0,0 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.infra.service; | ||||
| @@ -0,0 +1 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller; | ||||
| @@ -0,0 +1,3 @@ | ||||
| ### 请求 /system/user/profile/get 接口 => 没有权限 | ||||
| GET {{userServerUrl}}/system/user/profile/get | ||||
| Authorization: Bearer test245 | ||||
| @@ -0,0 +1,27 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.user; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| @Api(tags = "用户个人中心") | ||||
| @RestController | ||||
| @RequestMapping("/system/user/profile") | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class SysUserProfileController { | ||||
|  | ||||
|     @GetMapping("/get") | ||||
|     @ApiOperation("获得登录用户信息") | ||||
|     @PreAuthenticated | ||||
|     public CommonResult<Boolean> profile() { | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -25,4 +25,12 @@ public interface MbrUserService { | ||||
|      */ | ||||
|     void updateUserLogin(Long id, String loginIp); | ||||
|  | ||||
|     /** | ||||
|      * 通过用户 ID 查询用户 | ||||
|      * | ||||
|      * @param id 用户ID | ||||
|      * @return 用户对象信息 | ||||
|      */ | ||||
|     MbrUserDO getUser(Long id); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -33,4 +33,9 @@ public class MbrUserServiceImpl implements MbrUserService { | ||||
|         userMapper.updateById(new MbrUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public MbrUserDO getUser(Long id) { | ||||
|         return userMapper.selectById(id); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -8,9 +8,9 @@ import org.mapstruct.Mapping; | ||||
| import org.mapstruct.factory.Mappers; | ||||
| 
 | ||||
| @Mapper | ||||
| public interface MbrAuthConvert { | ||||
| public interface SysAuthConvert { | ||||
| 
 | ||||
|     MbrAuthConvert INSTANCE = Mappers.getMapper(MbrAuthConvert.class); | ||||
|     SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); | ||||
| 
 | ||||
|     @Mapping(source = "mobile", target = "username") | ||||
|     LoginUser convert0(MbrUserDO bean); | ||||
| @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||||
| import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||||
| import cn.iocoder.yudao.framework.security.core.LoginUser; | ||||
| import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; | ||||
| import cn.iocoder.yudao.userserver.modules.system.convert.auth.MbrAuthConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.system.convert.auth.SysAuthConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||||
| @@ -60,7 +60,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||||
|             throw new UsernameNotFoundException(mobile); | ||||
|         } | ||||
|         // 创建 LoginUser 对象 | ||||
|         return MbrAuthConvert.INSTANCE.convert(user); | ||||
|         return SysAuthConvert.INSTANCE.convert(user); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -125,7 +125,15 @@ public class SysAuthServiceImpl implements SysAuthService { | ||||
|  | ||||
|     @Override | ||||
|     public LoginUser mockLogin(Long userId) { | ||||
|         return null; | ||||
|         // 获取用户编号对应的 MbrUserDO | ||||
|         MbrUserDO user = userService.getUser(userId); | ||||
|         if (user == null) { | ||||
|             throw new UsernameNotFoundException(String.valueOf(userId)); | ||||
|         } | ||||
|         this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS); | ||||
|  | ||||
|         // 创建 LoginUser 对象 | ||||
|         return SysAuthConvert.INSTANCE.convert(user); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV