diff --git a/README.md b/README.md index f2251a3e8..c5a210733 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,9 @@ | `yudao-admin-ui` | 管理后台的 UI 界面 | | `yudao-user-server` | 用户前台的服务端 | | `yudao-user-ui` | 用户前台的 UI 界面 | +| `yudao-core-service` | 公共服务,提供共享逻辑 | + +> 友情提示:`yudao-admin-server` 和 `yudao-user-server` 会存在需要复用的逻辑,通过 `yudao-core-service` 实现。 ### 后端 diff --git a/http-client.env.json b/http-client.env.json index ad661c281..c4686b274 100644 --- a/http-client.env.json +++ b/http-client.env.json @@ -1,6 +1,7 @@ { "local": { "baseUrl": "http://127.0.0.1:48080/api", + "userServerUrl": "http://127.0.0.1:28080/api", "token": "test1" } } diff --git a/pom.xml b/pom.xml index 84e886116..1ca158c9f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ yudao-framework yudao-admin-server yudao-user-server + yudao-core-service ${artifactId} diff --git a/yudao-admin-server/pom.xml b/yudao-admin-server/pom.xml index 8fad2d92c..120d3e926 100644 --- a/yudao-admin-server/pom.xml +++ b/yudao-admin-server/pom.xml @@ -18,6 +18,11 @@ + + cn.iocoder.boot + yudao-core-service + + cn.iocoder.boot yudao-spring-boot-starter-biz-operatelog diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java index ba791871d..810869768 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java @@ -3,7 +3,8 @@ package cn.iocoder.yudao.adminserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} +@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}) public class AdminServerApplication { public static void main(String[] args) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java index b0ff2ca9a..3167a09d1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.config; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java index b59593859..6b2c743ca 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.file; import cn.hutool.core.io.IoUtil; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import io.swagger.annotations.Api; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiAccessLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiAccessLogController.java index 434fb1f75..3aec60d4f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiAccessLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiAccessLogController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccess import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiErrorLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiErrorLogController.java index abc227fae..7b83022ca 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiErrorLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiErrorLogController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorl import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java index 0b076b6e0..4a5eaf2f7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.config; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigRespVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java index 9d3e95ca9..d39452ffe 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.file; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiAccessLogConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiAccessLogConvert.java index 71b319cb4..ba21d33ce 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiAccessLogConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiAccessLogConvert.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExcelVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -20,8 +20,6 @@ public interface InfApiAccessLogConvert { InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class); - InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); - InfApiAccessLogRespVO convert(InfApiAccessLogDO bean); List convertList(List list); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiErrorLogConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiErrorLogConvert.java index 359ffafc0..de10d48fc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiErrorLogConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiErrorLogConvert.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -20,8 +19,6 @@ public interface InfApiErrorLogConvert { InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); - InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); - InfApiErrorLogRespVO convert(InfApiErrorLogDO bean); PageResult convertPage(PageResult page); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java deleted file mode 100644 index 119d069d9..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; -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; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java deleted file mode 100644 index 7f19defca..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java +++ /dev/null @@ -1,153 +0,0 @@ -package cn.iocoder.yudao.adminserver.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.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; -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; - /** - * 处理用户编号 - * - * 关联 {@link SysUserDO#getId()} - */ - private Long processUserId; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java index 546ef843a..e7960eaef 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java index 0a487e025..022f90acb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; import org.apache.ibatis.annotations.Mapper; @Mapper diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java index 85d04a3b5..4552762fc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; +import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; +import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java index 4e7481d11..d96e5fc3b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java index 2430c329b..166ebdbd1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.config; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import javax.validation.Valid; import java.util.List; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java index 13bc2aafc..65839e20e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; @@ -8,7 +9,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfig import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java index 0a1193365..e19e3ecab 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; /** * 文件 Service 接口 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java index a574147f0..0436b804f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; import cn.hutool.core.io.FileTypeUtil; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; import org.springframework.stereotype.Service; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogService.java index f4eb6bd43..347372bb4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogService.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import java.util.List; @@ -13,7 +12,7 @@ import java.util.List; * * @author 芋道源码 */ -public interface InfApiAccessLogService extends ApiAccessLogFrameworkService { +public interface InfApiAccessLogService { /** * 获得 API 访问日志分页 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogService.java index f5e41a57b..c778eee31 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogService.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import java.util.List; @@ -13,7 +12,7 @@ import java.util.List; * * @author 芋道源码 */ -public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { +public interface InfApiErrorLogService { /** * 获得 API 错误日志分页 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java index aba6382d2..207b3d152 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java @@ -1,21 +1,16 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; -import java.util.concurrent.Future; /** * API 访问日志 Service 实现类 @@ -29,14 +24,6 @@ public class InfApiAccessLogServiceImpl implements InfApiAccessLogService { @Resource private InfApiAccessLogMapper apiAccessLogMapper; - @Override - @Async - public Future createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { - InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO); - int insert = apiAccessLogMapper.insert(apiAccessLog); - return new AsyncResult<>(insert > 1); - } - @Override public PageResult getApiAccessLogPage(InfApiAccessLogPageReqVO pageReqVO) { return apiAccessLogMapper.selectPage(pageReqVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java index aa0fe1fed..6918aec06 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java @@ -1,27 +1,22 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Date; import java.util.List; -import java.util.concurrent.Future; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND; import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * API 错误日志 Service 实现类 @@ -35,15 +30,6 @@ public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { @Resource private InfApiErrorLogMapper apiErrorLogMapper; - @Override - @Async - public Future createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { - InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); - apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); - int insert = apiErrorLogMapper.insert(apiErrorLog); - return new AsyncResult<>(insert == 1); - } - @Override public PageResult getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO) { return apiErrorLogMapper.selectPage(pageReqVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java index 092baca5d..b87deaca9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java @@ -4,13 +4,13 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*; import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; @@ -43,7 +43,7 @@ public class SysAuthController { @Resource private SysAuthService authService; @Resource - private SysUserService userService; + private SysUserCoreService userCoreService; @Resource private SysRoleService roleService; @Resource @@ -64,7 +64,7 @@ public class SysAuthController { @ApiOperation("获取登录用户的权限信息") public CommonResult getPermissionInfo() { // 获得用户信息 - SysUserDO user = userService.getUser(getLoginUserId()); + SysUserDO user = userCoreService.getUser(getLoginUserId()); if (user == null) { return null; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysUserSessionController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysUserSessionController.java index 253b25126..25279ef80 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysUserSessionController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysUserSessionController.java @@ -1,16 +1,17 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.auth; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysUserSessionConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -35,6 +36,8 @@ public class SysUserSessionController { @Resource private SysUserSessionService userSessionService; @Resource + private SysUserSessionCoreService userSessionCoreService; + @Resource private SysUserService userService; @Resource private SysDeptService deptService; @@ -72,7 +75,7 @@ public class SysUserSessionController { example = "fe50b9f6-d177-44b1-8da9-72ea34f63db7") @PreAuthorize("@ss.hasPermission('system:user-session:delete')") public CommonResult deleteUserSession(@RequestParam("id") String id) { - userSessionService.deleteUserSession(id); + userSessionCoreService.deleteUserSession(id); return success(true); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/SysDictDataController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/SysDictDataController.java index 6f45fc3b6..5db6ccf6d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/SysDictDataController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/SysDictDataController.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.dict; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java index 6f9a0d208..24260c4a2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.logger; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysLoginLogConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysOperateLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysOperateLogController.java index 042bf933f..e44a4dd4d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysOperateLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysOperateLogController.java @@ -1,20 +1,20 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.logger; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java deleted file mode 100644 index 738937806..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog; - -import io.swagger.annotations.ApiModel; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@ApiModel(value = "登录日志创建 Request VO", - description = "暂时提供给前端,仅仅后端记录登录日志时,进行使用") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SysLoginLogCreateReqVO extends SysLoginLogBaseVO { -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SmsCallbackController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SmsCallbackController.java index ec3287f63..322b99d00 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SmsCallbackController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SmsCallbackController.java @@ -2,10 +2,10 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.sms; import cn.hutool.core.util.URLUtil; import cn.hutool.extra.servlet.ServletUtil; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.sms.core.enums.SmsChannelEnum; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class SmsCallbackController { @Resource - private SysSmsService smsService; + private SysSmsCoreService smsCoreService; @PostMapping("/sms/yunpian") @ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档") @@ -33,7 +33,7 @@ public class SmsCallbackController { @OperateLog(enable = false) public String receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable { String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode - smsService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text); + smsCoreService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text); return "SUCCESS"; // 约定返回 SUCCESS 为成功 } @@ -42,7 +42,7 @@ public class SmsCallbackController { @OperateLog(enable = false) public CommonResult receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable { String text = ServletUtil.getBody(request); - smsService.receiveSmsStatus(SmsChannelEnum.ALIYUN.getCode(), text); + smsCoreService.receiveSmsStatus(SmsChannelEnum.ALIYUN.getCode(), text); return success(true); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsChannelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsChannelController.java index 5a05a2e6b..b7a98a1c2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsChannelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsChannelController.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.sms; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.*; import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsLogController.java index a39f0a77b..aa1eec9b2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsLogController.java @@ -1,16 +1,16 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.sms; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsLogConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsTemplateController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsTemplateController.java index c3a280a5f..4743cfdb8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsTemplateController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsTemplateController.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.sms; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.*; +import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; +import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.*; -import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -32,7 +32,7 @@ public class SysSmsTemplateController { @Resource private SysSmsTemplateService smsTemplateService; @Resource - private SysSmsService smsService; + private SysSmsCoreService smsCoreService; @PostMapping("/create") @ApiOperation("创建短信模板") @@ -91,7 +91,7 @@ public class SysSmsTemplateController { @ApiOperation("发送短信") @PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')") public CommonResult sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) { - return success(smsService.sendSingleSms(sendReqVO.getMobile(), null, null, + return success(smsCoreService.sendSingleSms(sendReqVO.getMobile(), null, null, sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams())); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java index 6de3f6b0c..f4e32fb59 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java @@ -1,20 +1,21 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.user; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -42,6 +43,8 @@ public class SysUserController { @Resource private SysUserService userService; @Resource + private SysUserCoreService userCoreService; + @Resource private SysDeptService deptService; @PostMapping("/create") @@ -113,7 +116,7 @@ public class SysUserController { @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:user:query')") public CommonResult getInfo(@RequestParam("id") Long id) { - return success(SysUserConvert.INSTANCE.convert(userService.getUser(id))); + return success(SysUserConvert.INSTANCE.convert(userCoreService.getUser(id))); } @GetMapping("/export") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java index b00720ce2..523359b08 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java @@ -1,10 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.user; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; -import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; @@ -12,12 +8,17 @@ import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -30,13 +31,10 @@ import javax.validation.Valid; import java.io.IOException; import java.util.List; +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY; -/** - * @author niudehua - */ @Api(tags = "用户个人中心") @RestController @RequestMapping("/system/user/profile") @@ -47,6 +45,8 @@ public class SysUserProfileController { @Resource private SysUserService userService; @Resource + private SysUserCoreService userCoreService; + @Resource private SysDeptService deptService; @Resource private SysPostService postService; @@ -61,7 +61,7 @@ public class SysUserProfileController { @ApiOperation("获得登录用户信息") public CommonResult profile() { // 获得用户基本信息 - SysUserDO user = userService.getUser(getLoginUserId()); + SysUserDO user = userCoreService.getUser(getLoginUserId()); SysUserProfileRespVO resp = SysUserConvert.INSTANCE.convert03(user); // 获得用户角色 List userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(user.getId())); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserImportExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserImportExcelVO.java index bef545178..b641f6412 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserImportExcelVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserImportExcelVO.java @@ -8,6 +8,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; /** * 用户 Excel 导入 VO @@ -16,6 +17,7 @@ import lombok.NoArgsConstructor; @Builder @AllArgsConstructor @NoArgsConstructor +@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题 public class SysUserImportExcelVO { @ExcelProperty("登录名称") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysAuthConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysAuthConvert.java index 65d79a898..80b7d2bd4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysAuthConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysAuthConvert.java @@ -2,17 +2,13 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.auth; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuIdEnum; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.security.core.LoginUser; -import me.zhyd.oauth.model.AuthCallback; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @@ -25,9 +21,13 @@ public interface SysAuthConvert { SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); - @Mapping(source = "updateTime", target = "updateTime", ignore = true) - // 字段相同,但是含义不同,忽略 - LoginUser convert(SysUserDO bean); + @Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略 + LoginUser convert0(SysUserDO bean); + + default LoginUser convert(SysUserDO bean) { + // 目的,为了设置 UserTypeEnum.ADMIN.getValue() + return convert0(bean).setUserType(UserTypeEnum.ADMIN.getValue()); + } default SysAuthPermissionInfoRespVO convert(SysUserDO user, List roleList, List menuList) { return SysAuthPermissionInfoRespVO.builder() @@ -39,10 +39,6 @@ public interface SysAuthConvert { SysAuthMenuRespVO convertTreeNode(SysMenuDO menu); - LoginUser convert(SysUserProfileUpdateReqVO reqVO); - - LoginUser convert(SysUserProfileUpdatePasswordReqVO reqVO); - /** * 将菜单列表,构建成菜单树 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysUserSessionConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysUserSessionConvert.java index 473fa911c..0defeed97 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysUserSessionConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysUserSessionConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.auth; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/dict/SysDictDataConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/dict/SysDictDataConvert.java index d8e54bc8b..e916def4f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/dict/SysDictDataConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/dict/SysDictDataConvert.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.dict; +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysLoginLogConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysLoginLogConvert.java index 7c31fe3ae..d6226491c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysLoginLogConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysLoginLogConvert.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.logger; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -15,8 +14,6 @@ public interface SysLoginLogConvert { SysLoginLogConvert INSTANCE = Mappers.getMapper(SysLoginLogConvert.class); - SysLoginLogDO convert(SysLoginLogCreateReqVO bean); - PageResult convertPage(PageResult page); List convertList(List list); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysOperateLogConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysOperateLogConvert.java index dc31e078a..51e08f1dc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysOperateLogConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysOperateLogConvert.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.logger; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsChannelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsChannelConvert.java index 8d8304d37..cc3b27b64 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsChannelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsChannelConvert.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.sms; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelSimpleRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsLogConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsLogConvert.java index 792d3290a..afcd9443d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsLogConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsLogConvert.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.sms; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsTemplateConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsTemplateConvert.java index f7ffeb6eb..4d1e0dc40 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsTemplateConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsTemplateConvert.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.sms; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExcelVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java index 7039cabe8..dbe5b365f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java @@ -8,7 +8,7 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java index 1983518fc..e937327ee 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/social/SysSocialUserDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/social/SysSocialUserDO.java index cde686983..7e998b8fc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/social/SysSocialUserDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/social/SysSocialUserDO.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableId; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/auth/SysUserSessionMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/auth/SysUserSessionMapper.java index bc6e31c83..f5ae670b0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/auth/SysUserSessionMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/auth/SysUserSessionMapper.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth; +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -23,4 +23,5 @@ public interface SysUserSessionMapper extends BaseMapperX { default List selectListBySessionTimoutLt() { return selectList(new QueryWrapperX().lt("session_timeout",new Date())); } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java index dba4b5503..ad63bf624 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict; +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/logger/SysLoginLogMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/logger/SysLoginLogMapper.java index 62a70f046..eea1812e8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/logger/SysLoginLogMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/logger/SysLoginLogMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsChannelMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsChannelMapper.java index bc48f2b85..bd69d4f73 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsChannelMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsChannelMapper.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsLogMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsLogMapper.java index 663b00af0..0269e75e6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsLogMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsLogMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java index 04465fe41..f0a315076 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java @@ -1,15 +1,13 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import java.util.Date; import java.util.List; @Mapper @@ -47,7 +45,4 @@ public interface SysSmsTemplateMapper extends BaseMapperX { return selectCount("channel_id", channelId); } - @Select("SELECT id FROM sys_sms_template WHERE update_time > #{maxUpdateTime} LIMIT 1") - Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java index e36727ebe..548352e2b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -19,14 +19,14 @@ public interface SysUserMapper extends BaseMapperX { return selectOne(new QueryWrapper().eq("username", username)); } - default SysUserDO selectByMobile(String mobile) { - return selectOne(new QueryWrapper().eq("mobile", mobile)); - } - default SysUserDO selectByEmail(String email) { return selectOne(new QueryWrapper().eq("email", email)); } + default SysUserDO selectByMobile(String mobile) { + return selectOne(new QueryWrapper().eq("mobile", mobile)); + } + default PageResult selectPage(SysUserPageReqVO reqVO, Collection deptIds) { return selectPage(reqVO, new QueryWrapperX() .likeIfPresent("username", reqVO.getUsername()) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/RedisKeyConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/RedisKeyConstants.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java index 78109c73c..e7c484bb0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java @@ -15,10 +15,6 @@ import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.S */ public interface SysRedisKeyConstants { - RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", - "login_user:%s", // 参数为 sessionId - STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); - RedisKeyDefine CAPTCHA_CODE = new RedisKeyDefine("验证码的缓存", "captcha_code:%s", // 参数为 uuid STRING, String.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java index e7388cca8..8a606e062 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.system.enums; -import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.config.ErrorCodeConfiguration; import cn.iocoder.yudao.framework.common.exception.ErrorCode; -import org.springframework.validation.Errors; +import javafx.beans.binding.MapExpression; /** * System 错误码枚举类 @@ -14,14 +13,11 @@ public interface SysErrorCodeConstants { // ========== AUTH 模块 1002000000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1002000000, "登录失败,账号密码不正确"); ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1002000001, "登录失败,账号被禁用"); - ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,位置原因 + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,未知原因 ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); - - // ========== TOKEN 模块 1002001000 ========== - ErrorCode TOKEN_EXPIRED = new ErrorCode(1002001000, "Token 已经过期"); - ErrorCode TOKEN_PARSE_FAIL = new ErrorCode(1002001001, "Token 解析失败"); + ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1002000006, "Token 已经过期"); // ========== 菜单模块 1002002000 ========== ErrorCode MENU_NAME_DUPLICATE = new ErrorCode(1002002000, "已经存在该名字的菜单"); @@ -90,10 +86,6 @@ public interface SysErrorCodeConstants { ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在"); ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}】的短信模板"); - // ========== 短信发送 1002012000 ========== - ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1002012000, "手机号不存在"); - ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1002012001, "模板参数({})缺失"); - // ========== 错误码模块 1002013000 ========== ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002013000, "错误码不存在"); ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002013001, "已经存在编码为【{}】的错误码"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java index 3b56f2f08..40f18e867 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java @@ -13,6 +13,8 @@ public enum SysLoginLogTypeEnum { LOGIN_USERNAME(100), // 使用账号登录 LOGIN_SOCIAL(101), // 使用社交登录 LOGIN_MOCK(102), // 使用 Mock 登录 + LOGIN_MOBILE(103), // 使用手机登陆 + LOGIN_SMS(104), // 使用短信登陆 LOGOUT_SELF(200), // 自己主动登出 LOGOUT_TIMEOUT(201), // 超时登出 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java index e1bdeb955..218b2d97f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java @@ -13,8 +13,8 @@ public enum SysLoginResultEnum { SUCCESS(0), // 成功 BAD_CREDENTIALS(10), // 账号或密码不正确 USER_DISABLED(20), // 用户被禁用 - CAPTCHA_NOT_FOUND(30), // 验证码不存在 - CAPTCHA_CODE_ERROR(31), // 验证码不正确 + CAPTCHA_NOT_FOUND(30), // 图片验证码不存在 + CAPTCHA_CODE_ERROR(31), // 图片验证码不正确 UNKNOWN_ERROR(100), // 未知异常 ; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java index 08f4b813e..33f00e077 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.dict; +import cn.iocoder.yudao.coreservice.modules.system.service.dict.SysDictDataCoreService; import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import cn.iocoder.yudao.adminserver.modules.system.mq.message.dict.SysDictDataRefreshMessage; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; @@ -18,12 +19,12 @@ import javax.annotation.Resource; public class SysDictDataRefreshConsumer extends AbstractChannelMessageListener { @Resource - private SysDictDataService dictDataService; + private SysDictDataCoreService dictDataCoreService; @Override public void onMessage(SysDictDataRefreshMessage message) { log.info("[onMessage][收到 DictData 刷新消息]"); - dictDataService.initLocalCache(); + dictDataCoreService.initLocalCache(); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsSendConsumer.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsSendConsumer.java index 947b23940..b8ad6ad30 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsSendConsumer.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsSendConsumer.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -19,12 +19,12 @@ import javax.annotation.Resource; public class SysSmsSendConsumer extends AbstractStreamMessageListener { @Resource - private SysSmsService smsService; + private SysSmsCoreService smsCoreService; @Override public void onMessage(SysSmsSendMessage message) { log.info("[onMessage][消息内容({})]", message); - smsService.doSendSms(message); + smsCoreService.doSendSms(message); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsTemplateRefreshConsumer.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsTemplateRefreshConsumer.java index 1f4d92ffc..305672bc7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsTemplateRefreshConsumer.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsTemplateRefreshConsumer.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; -import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -18,12 +18,12 @@ import javax.annotation.Resource; public class SysSmsTemplateRefreshConsumer extends AbstractChannelMessageListener { @Resource - private SysSmsTemplateService smsTemplateService; + private SysSmsTemplateCoreService smsTemplateCoreService; @Override public void onMessage(SysSmsTemplateRefreshMessage message) { log.info("[onMessage][收到 SmsTemplate 刷新消息]"); - smsTemplateService.initLocalCache(); + smsTemplateCoreService.initLocalCache(); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/producer/sms/SysSmsProducer.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/producer/sms/SysSmsProducer.java index 81236287c..739603301 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/producer/sms/SysSmsProducer.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/producer/sms/SysSmsProducer.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsChannelRefreshMessage; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.StringRedisTemplate; @@ -25,22 +24,6 @@ public class SysSmsProducer { @Resource private StringRedisTemplate stringRedisTemplate; - /** - * 发送 {@link SysSmsSendMessage} 消息 - * - * @param logId 短信日志编号 - * @param mobile 手机号 - * @param channelId 渠道编号 - * @param apiTemplateId 短信模板编号 - * @param templateParams 短信模板参数 - */ - public void sendSmsSendMessage(Long logId, String mobile, - Long channelId, String apiTemplateId, List> templateParams) { - SysSmsSendMessage message = new SysSmsSendMessage().setLogId(logId).setMobile(mobile); - message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams); - RedisMessageUtils.sendStreamMessage(stringRedisTemplate, message); - } - /** * 发送 {@link SysSmsChannelRefreshMessage} 消息 */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java index 369f7c0b9..2d5fe8c47 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkSer import javax.validation.Valid; /** - * 认证 Service 接口 + * 管理后台的认证 Service 接口 * * 提供用户的账号密码登录、token 的校验等认证相关的功能 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java index 900ed1c0a..ebfa6606d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; /** * 在线用户 Session Service 接口 @@ -12,53 +11,6 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSe */ public interface SysUserSessionService { - /** - * 创建在线用户 Session - * - * @param loginUser 登录用户 - * @param userIp 用户 IP - * @param userAgent 用户 UA - * @return Session 编号 - */ - String createUserSession(LoginUser loginUser, String userIp, String userAgent); - - /** - * 刷新在线用户 Session 的更新时间 - * - * @param sessionId Session 编号 - * @param loginUser 登录用户 - */ - void refreshUserSession(String sessionId, LoginUser loginUser); - - /** - * 删除在线用户 Session - * - * @param sessionId Session 编号 - */ - void deleteUserSession(String sessionId); - - /** - * 获得 Session 编号对应的在线用户 - * - * @param sessionId Session 编号 - * @return 在线用户 - */ - LoginUser getLoginUser(String sessionId); - - /** - * 获取当前登录用户信息 - * @param username 用户名称 - * @return 在线用户 - */ - String getSessionId(String username); - - /** - * 获得 Session 超时时间,单位:毫秒 - * - * @return 超时时间 - */ - Long getSessionTimeoutMillis(); - /** * 获得在线用户分页列表 * @@ -73,4 +25,5 @@ public interface SysUserSessionService { * @return {@link Long } 移出的超时用户数量 **/ long clearSessionTimeout(); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java index a17042822..d5fb91f95 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -5,20 +5,22 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAu import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; -import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; 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; @@ -38,6 +40,7 @@ import org.springframework.util.Assert; import javax.annotation.Resource; import java.util.List; +import java.util.Objects; import java.util.Set; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; @@ -60,13 +63,15 @@ public class SysAuthServiceImpl implements SysAuthService { @Resource private SysUserService userService; @Resource + private SysUserCoreService userCoreService; + @Resource private SysPermissionService permissionService; @Resource private SysCaptchaService captchaService; @Resource - private SysLoginLogService loginLogService; + private SysLoginLogCoreService loginLogCoreService; @Resource - private SysUserSessionService userSessionService; + private SysUserSessionCoreService userSessionCoreService; @Resource private SysSocialService socialService; @@ -84,7 +89,7 @@ public class SysAuthServiceImpl implements SysAuthService { @Override public LoginUser mockLogin(Long userId) { // 获取用户编号对应的 SysUserDO - SysUserDO user = userService.getUser(userId); + SysUserDO user = userCoreService.getUser(userId); if (user == null) { throw new UsernameNotFoundException(String.valueOf(userId)); } @@ -106,7 +111,7 @@ public class SysAuthServiceImpl implements SysAuthService { loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 // 缓存登录用户到 Redis 中,返回 sessionId 编号 - return userSessionService.createUserSession(loginUser, userIp, userAgent); + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); } private void verifyCaptcha(String username, String captchaUUID, String captchaCode) { @@ -154,14 +159,25 @@ public class SysAuthServiceImpl implements SysAuthService { } private void createLoginLog(String username, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); - reqVO.setLogType(logTypeEnum.getType()); - reqVO.setTraceId(TracerUtils.getTraceId()); - reqVO.setUsername(username); - reqVO.setUserAgent(ServletUtils.getUserAgent()); - reqVO.setUserIp(ServletUtils.getClientIP()); - reqVO.setResult(loginResult.getResult()); - loginLogService.createLoginLog(reqVO); + // 获得用户 + SysUserDO user = userService.getUserByUsername(username); + // 插入登录日志 + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); + reqDTO.setLogType(logTypeEnum.getType()); + reqDTO.setTraceId(TracerUtils.getTraceId()); + if (user != null) { + reqDTO.setUserId(user.getId()); + } + reqDTO.setUserType(UserTypeEnum.ADMIN.getValue()); + reqDTO.setUsername(username); + reqDTO.setUserAgent(ServletUtils.getUserAgent()); + reqDTO.setUserIp(ServletUtils.getClientIP()); + reqDTO.setResult(loginResult.getResult()); + loginLogCoreService.createLoginLog(reqDTO); + // 更新最后登录时间 + if (user != null && Objects.equals(SysLoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) { + userService.updateUserLogin(user.getId(), ServletUtils.getClientIP()); + } } /** @@ -188,7 +204,7 @@ public class SysAuthServiceImpl implements SysAuthService { } // 自动登录 - SysUserDO user = userService.getUser(socialUsers.get(0).getUserId()); + SysUserDO user = userCoreService.getUser(socialUsers.get(0).getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); } @@ -203,7 +219,7 @@ public class SysAuthServiceImpl implements SysAuthService { socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); // 缓存登录用户到 Redis 中,返回 sessionId 编号 - return userSessionService.createUserSession(loginUser, userIp, userAgent); + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); } @Override @@ -220,7 +236,7 @@ public class SysAuthServiceImpl implements SysAuthService { socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); // 缓存登录用户到 Redis 中,返回 sessionId 编号 - return userSessionService.createUserSession(loginUser, userIp, userAgent); + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); } @Override @@ -236,31 +252,33 @@ public class SysAuthServiceImpl implements SysAuthService { @Override public void logout(String token) { // 查询用户信息 - LoginUser loginUser = userSessionService.getLoginUser(token); + LoginUser loginUser = userSessionCoreService.getLoginUser(token); if (loginUser == null) { return; } // 删除 session - userSessionService.deleteUserSession(token); - // 记录登出日子和 - this.createLogoutLog(loginUser.getUsername()); + userSessionCoreService.deleteUserSession(token); + // 记录登出日志 + this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); } - private void createLogoutLog(String username) { - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); - reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); - reqVO.setTraceId(TracerUtils.getTraceId()); - reqVO.setUsername(username); - reqVO.setUserAgent(ServletUtils.getUserAgent()); - reqVO.setUserIp(ServletUtils.getClientIP()); - reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult()); - loginLogService.createLoginLog(reqVO); + private void createLogoutLog(Long userId, String username) { + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); + reqDTO.setTraceId(TracerUtils.getTraceId()); + reqDTO.setUserId(userId); + reqDTO.setUserType(UserTypeEnum.ADMIN.getValue()); + reqDTO.setUsername(username); + reqDTO.setUserAgent(ServletUtils.getUserAgent()); + reqDTO.setUserIp(ServletUtils.getClientIP()); + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); + loginLogCoreService.createLoginLog(reqDTO); } @Override public LoginUser verifyTokenAndRefresh(String token) { // 获得 LoginUser - LoginUser loginUser = userSessionService.getLoginUser(token); + LoginUser loginUser = userSessionCoreService.getLoginUser(token); if (loginUser == null) { return null; } @@ -272,20 +290,20 @@ public class SysAuthServiceImpl implements SysAuthService { private void refreshLoginUserCache(String token, LoginUser loginUser) { // 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存 if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() < - userSessionService.getSessionTimeoutMillis() / 3) { + userSessionCoreService.getSessionTimeoutMillis() / 3) { return; } // 重新加载 SysUserDO 信息 - SysUserDO user = userService.getUser(loginUser.getId()); + SysUserDO user = userCoreService.getUser(loginUser.getId()); if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { - throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 + throw exception(AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 } // 刷新 LoginUser 缓存 loginUser.setDeptId(user.getDeptId()); loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); - userSessionService.refreshUserSession(token, loginUser); + userSessionCoreService.refreshUserSession(token, loginUser); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysUserSessionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysUserSessionServiceImpl.java index a715971d8..6e2623b28 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysUserSessionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysUserSessionServiceImpl.java @@ -1,37 +1,32 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.security.config.SecurityProperties; -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; -import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysLoginUserRedisDAO; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.Duration; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; /** * 在线用户 Session Service 实现类 @@ -42,73 +37,15 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; @Service public class SysUserSessionServiceImpl implements SysUserSessionService { - @Resource - private SecurityProperties securityProperties; - @Resource - private SysLoginUserRedisDAO loginUserRedisDAO; @Resource private SysUserSessionMapper userSessionMapper; @Resource private SysUserService userService; @Resource - private SysLoginLogService loginLogService; + private SysLoginLogCoreService loginLogCoreService; - @Override - public String createUserSession(LoginUser loginUser, String userIp, String userAgent) { - // 生成 Session 编号 - String sessionId = generateSessionId(); - // 写入 Redis 缓存 - loginUser.setUpdateTime(new Date()); - loginUserRedisDAO.set(sessionId, loginUser); - // 写入 DB 中 - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) - .sessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))) - .build(); - userSessionMapper.insert(userSession); - // 返回 Session 编号 - return sessionId; - } - - @Override - public void refreshUserSession(String sessionId, LoginUser loginUser) { - // 写入 Redis 缓存 - loginUser.setUpdateTime(new Date()); - loginUserRedisDAO.set(sessionId, loginUser); - // 更新 DB 中 - SysUserSessionDO updateObj = SysUserSessionDO.builder().id(sessionId).build(); - updateObj.setUsername(loginUser.getUsername()); - updateObj.setUpdateTime(new Date()); - updateObj.setSessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))); - userSessionMapper.updateById(updateObj); - } - - @Override - public void deleteUserSession(String sessionId) { - // 删除 Redis 缓存 - loginUserRedisDAO.delete(sessionId); - // 删除 DB 记录 - userSessionMapper.deleteById(sessionId); - } - - @Override - public LoginUser getLoginUser(String sessionId) { - return loginUserRedisDAO.get(sessionId); - } - - @Override - public String getSessionId(String username) { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("username", username); - wrapper.orderByDesc("create_time"); - SysUserSessionDO sysUserSessionDO = userSessionMapper.selectOne(wrapper); - return sysUserSessionDO.getId(); - } - - @Override - public Long getSessionTimeoutMillis() { - return securityProperties.getSessionTimeout().toMillis(); - } + @Resource + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; @Override public PageResult getUserSessionPage(SysUserSessionPageReqVO reqVO) { @@ -123,18 +60,20 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { return userSessionMapper.selectPage(reqVO, userIds); } + // TODO @芋艿:优化下该方法 @Override public long clearSessionTimeout() { // 获取db里已经超时的用户列表 List sessionTimeoutDOS = userSessionMapper.selectListBySessionTimoutLt(); Map timeoutSessionDOMap = sessionTimeoutDOS .stream() - .filter(sessionDO -> loginUserRedisDAO.get(sessionDO.getId()) == null) + .filter(sessionDO -> loginUserCoreRedisDAO.get(sessionDO.getId()) == null) .collect(Collectors.toMap(SysUserSessionDO::getId, o -> o)); // 确认已经超时,按批次移出在线用户列表 if (CollUtil.isNotEmpty(timeoutSessionDOMap)) { - Lists.partition(new ArrayList<>(timeoutSessionDOMap.keySet()), 100).forEach(userSessionMapper::deleteBatchIds); - //记录用户超时退出日志 + Lists.partition(new ArrayList<>(timeoutSessionDOMap.keySet()), 100) + .forEach(userSessionMapper::deleteBatchIds); + // 记录用户超时退出日志 createTimeoutLogoutLog(timeoutSessionDOMap.values()); } return timeoutSessionDOMap.size(); @@ -142,24 +81,17 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { private void createTimeoutLogoutLog(Collection timeoutSessionDOS) { for (SysUserSessionDO timeoutSessionDO : timeoutSessionDOS) { - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); - reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_TIMEOUT.getType()); - reqVO.setTraceId(TracerUtils.getTraceId()); - reqVO.setUsername(timeoutSessionDO.getUsername()); - reqVO.setUserAgent(timeoutSessionDO.getUserAgent()); - reqVO.setUserIp(timeoutSessionDO.getUserIp()); - reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult()); - loginLogService.createLoginLog(reqVO); + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_TIMEOUT.getType()); + reqDTO.setTraceId(TracerUtils.getTraceId()); + reqDTO.setUserId(timeoutSessionDO.getUserId()); + reqDTO.setUserType(timeoutSessionDO.getUserType()); + reqDTO.setUsername(timeoutSessionDO.getUsername()); + reqDTO.setUserAgent(timeoutSessionDO.getUserAgent()); + reqDTO.setUserIp(timeoutSessionDO.getUserIp()); + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); + loginLogCoreService.createLoginLog(reqDTO); } } - /** - * 生成 Session 编号,目前采用 UUID 算法 - * - * @return Session 编号 - */ - private static String generateSessionId() { - return IdUtil.fastSimpleUUID(); - } - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java index 20457202d..e1efea03d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.service.dict; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import java.util.List; @@ -15,12 +15,7 @@ import java.util.List; * * @author ruoyi */ -public interface SysDictDataService extends DictDataFrameworkService { - - /** - * 初始化字典数据的本地缓存 - */ - void initLocalCache(); +public interface SysDictDataService { /** * 创建字典数据 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java index 4f23dac88..88fb99966 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java @@ -1,35 +1,29 @@ package cn.iocoder.yudao.adminserver.modules.system.service.dict.impl; -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictTypeService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableTable; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.Comparator; import java.util.Date; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 字典数据 Service 实现类 @@ -47,31 +41,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { .comparing(SysDictDataDO::getDictType) .thenComparingInt(SysDictDataDO::getSort); - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - - /** - * 字典数据缓存,第二个 key 使用 label - * - * key1:字典类型 dictType - * key2:字典标签 label - */ - private ImmutableTable labelDictDataCache; - /** - * 字典数据缓存,第二个 key 使用 value - * - * key1:字典类型 dictType - * key2:字典值 value - */ - private ImmutableTable valueDictDataCache; - /** - * 缓存字典数据的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile Date maxUpdateTime; - @Resource private SysDictTypeService dictTypeService; @@ -81,34 +50,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { @Resource private SysDictDataProducer dictDataProducer; - @Override - @PostConstruct - public synchronized void initLocalCache() { - // 获取字典数据列表,如果有更新 - List dataList = this.loadDictDataIfUpdate(maxUpdateTime); - if (CollUtil.isEmpty(dataList)) { - return; - } - - // 构建缓存 - ImmutableTable.Builder labelDictDataBuilder = ImmutableTable.builder(); - ImmutableTable.Builder valueDictDataBuilder = ImmutableTable.builder(); - dataList.forEach(dictData -> { - labelDictDataBuilder.put(dictData.getDictType(), dictData.getLabel(), dictData); - valueDictDataBuilder.put(dictData.getDictType(), dictData.getValue(), dictData); - }); - labelDictDataCache = labelDictDataBuilder.build(); - valueDictDataCache = valueDictDataBuilder.build(); - assert dataList.size() > 0; // 断言,避免告警 - maxUpdateTime = dataList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); - log.info("[initLocalCache][缓存字典数据,数量为:{}]", dataList.size()); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCache(); - } - /** * 如果字典数据发生变化,从数据库中获取最新的全量字典数据。 * 如果未发生变化,则返回空 @@ -238,19 +179,4 @@ public class SysDictDataServiceImpl implements SysDictDataService { } } - @Override - public DictDataRespDTO getDictDataFromCache(String type, String value) { - return SysDictDataConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); - } - - @Override - public DictDataRespDTO parseDictDataFromCache(String type, String label) { - return SysDictDataConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); - } - - @Override - public List listDictDatasFromCache(String type) { - return SysDictDataConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); - } - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java index fd4ad6658..b7b30e198 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import java.util.List; @@ -13,13 +12,6 @@ import java.util.List; */ public interface SysLoginLogService { - /** - * 创建登录日志 - * - * @param reqVO 日志信息 - */ - void createLoginLog(SysLoginLogCreateReqVO reqVO); - /** * 获得登录日志分页 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java index b5a7b3500..fc651469d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger.impl; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysLoginLogConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -24,21 +19,6 @@ public class SysLoginLogServiceImpl implements SysLoginLogService { @Resource private SysLoginLogMapper loginLogMapper; - @Resource - private SysUserService userService; - - @Override - public void createLoginLog(SysLoginLogCreateReqVO reqVO) { - SysLoginLogDO loginLog = SysLoginLogConvert.INSTANCE.convert(reqVO); - // 获得用户 - SysUserDO user = userService.getUserByUsername(reqVO.getUsername()); - if (user != null) { - loginLog.setUserId(user.getId()); - } - loginLog.setUserType(UserTypeEnum.ADMIN.getValue()); - // 插入 - loginLogMapper.insert(loginLog); - } @Override public PageResult getLoginLogPage(SysLoginLogPageReqVO reqVO) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysOperateLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysOperateLogServiceImpl.java index 69c684ebd..811710e24 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysOperateLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysOperateLogServiceImpl.java @@ -2,17 +2,17 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.string.StrUtils; +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelService.java index cd6451482..5724b1274 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelService.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; import javax.validation.Valid; import java.util.Collection; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogService.java index 980cf2864..75bc3a6cc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogService.java @@ -1,63 +1,20 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; -import java.util.Date; import java.util.List; -import java.util.Map; /** - * 短信日志 Service 实现类 + * 短信日志 Service 接口 * * @author zzf * @date 13:48 2021/3/2 */ public interface SysSmsLogService { - /** - * 创建短信日志 - * - * @param mobile 手机号 - * @param userId 用户编号 - * @param userType 用户类型 - * @param isSend 是否发送 - * @param template 短信模板 - * @param templateContent 短信内容 - * @param templateParams 短信参数 - * @return 发送日志编号 - */ - Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, - SysSmsTemplateDO template, String templateContent, Map templateParams); - - /** - * 更新日志的发送结果 - * - * @param id 日志编号 - * @param sendCode 发送结果的编码 - * @param sendMsg 发送结果的提示 - * @param apiSendCode 短信 API 发送结果的编码 - * @param apiSendMsg 短信 API 发送失败的提示 - * @param apiRequestId 短信 API 发送返回的唯一请求 ID - * @param apiSerialNo 短信 API 发送返回的序号 - */ - void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, - String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo); - - /** - * 更新日志的接收结果 - * - * @param id 日志编号 - * @param success 是否接收成功 - * @param receiveTime 用户接收时间 - * @param apiReceiveCode API 接收结果的编码 - * @param apiReceiveMsg API 接收结果的说明 - */ - void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg); - /** * 获得短信日志分页 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateService.java index 40207cf43..723eef1ff 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateService.java @@ -1,16 +1,15 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import javax.validation.Valid; import java.util.Collection; import java.util.List; -import java.util.Map; /** * 短信模板 Service 接口 @@ -20,11 +19,6 @@ import java.util.Map; */ public interface SysSmsTemplateService { - /** - * 初始化短信模板的本地缓存 - */ - void initLocalCache(); - /** * 获得短信模板 * @@ -33,23 +27,6 @@ public interface SysSmsTemplateService { */ SysSmsTemplateDO getSmsTemplateByCode(String code); - /** - * 获得短信模板,从缓存中 - * - * @param code 模板编码 - * @return 短信模板 - */ - SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code); - - /** - * 格式化短信内容 - * - * @param content 短信模板的内容 - * @param params 内容的参数 - * @return 格式化后的内容 - */ - String formatSmsTemplateContent(String content, Map params); - /** * 创建短信模板 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java index 444cae63c..59f2a9a30 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java @@ -1,19 +1,19 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; -import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; +import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -25,9 +25,9 @@ import java.util.Comparator; import java.util.Date; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 短信渠道Service实现类 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsLogServiceImpl.java index 4b291d9d5..866e60729 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsLogServiceImpl.java @@ -1,23 +1,16 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Date; import java.util.List; -import java.util.Map; -import java.util.Objects; /** * 短信日志 Service 实现类 @@ -32,47 +25,6 @@ public class SysSmsLogServiceImpl implements SysSmsLogService { @Resource private SysSmsLogMapper smsLogMapper; - @Override - public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, - SysSmsTemplateDO template, String templateContent, Map templateParams) { - SysSmsLogDO.SysSmsLogDOBuilder logBuilder = SysSmsLogDO.builder(); - // 根据是否要发送,设置状态 - logBuilder.sendStatus(Objects.equals(isSend, true) ? SysSmsSendStatusEnum.INIT.getStatus() - : SysSmsSendStatusEnum.IGNORE.getStatus()); - // 设置手机相关字段 - logBuilder.mobile(mobile).userId(userId).userType(userType); - // 设置模板相关字段 - logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); - logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId()); - // 设置渠道相关字段 - logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); - // 设置接收相关字段 - logBuilder.receiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus()); - - // 插入数据库 - SysSmsLogDO logDO = logBuilder.build(); - smsLogMapper.insert(logDO); - return logDO.getId(); - } - - @Override - public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, - String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) { - SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS - : SysSmsSendStatusEnum.FAILURE; - smsLogMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date()) - .sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg) - .apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build()); - } - - @Override - public void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg) { - SysSmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? SysSmsReceiveStatusEnum.SUCCESS - : SysSmsReceiveStatusEnum.FAILURE; - smsLogMapper.updateById(SysSmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()).receiveTime(receiveTime) - .apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build()); - } - @Override public PageResult getSmsLogPage(SysSmsLogPageReqVO pageReqVO) { return smsLogMapper.selectPage(pageReqVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java index 9df2592fd..deb76e56e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java @@ -1,40 +1,36 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.sms.core.client.SmsClient; -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; -import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; -import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.sms.core.client.SmsClient; +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; +import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; +import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import javax.annotation.PostConstruct; import javax.annotation.Resource; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 短信模板Service实现类 @@ -51,24 +47,6 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { */ private static final Pattern PATTERN_PARAMS = Pattern.compile("\\{(.*?)}"); - /** - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 - */ - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; - - /** - * 短信模板缓存 - * key:短信模板编码 {@link SysSmsTemplateDO#getCode()} - * - * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 - */ - private volatile Map smsTemplateCache; - /** - * 缓存短信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 - */ - private volatile Date maxUpdateTime; - @Resource private SysSmsTemplateMapper smsTemplateMapper; @@ -81,68 +59,11 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { @Resource private SysSmsProducer smsProducer; - /** - * 初始化 {@link #smsTemplateCache} 缓存 - */ - @Override - @PostConstruct - public void initLocalCache() { - // 获取短信模板列表,如果有更新 - List smsTemplateList = this.loadSmsTemplateIfUpdate(maxUpdateTime); - if (CollUtil.isEmpty(smsTemplateList)) { - return; - } - - // 写入缓存 - ImmutableMap.Builder builder = ImmutableMap.builder(); - smsTemplateList.forEach(sysSmsTemplateDO -> builder.put(sysSmsTemplateDO.getCode(), sysSmsTemplateDO)); - smsTemplateCache = builder.build(); - assert smsTemplateList.size() > 0; // 断言,避免告警 - maxUpdateTime = smsTemplateList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); - log.info("[initLocalCache][初始化 SmsTemplate 数量为 {}]", smsTemplateList.size()); - } - - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) - public void schedulePeriodicRefresh() { - initLocalCache(); - } - - /** - * 如果短信模板发生变化,从数据库中获取最新的全量短信模板。 - * 如果未发生变化,则返回空 - * - * @param maxUpdateTime 当前短信模板的最大更新时间 - * @return 短信模板列表 - */ - private List loadSmsTemplateIfUpdate(Date maxUpdateTime) { - // 第一步,判断是否要更新。 - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 - log.info("[loadSmsTemplateIfUpdate][首次加载全量短信模板]"); - } else { // 判断数据库中是否有更新的短信模板 - if (smsTemplateMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) { - return null; - } - log.info("[loadSmsTemplateIfUpdate][增量加载全量短信模板]"); - } - // 第二步,如果有更新,则从数据库加载所有短信模板 - return smsTemplateMapper.selectList(); - } - @Override public SysSmsTemplateDO getSmsTemplateByCode(String code) { return smsTemplateMapper.selectByCode(code); } - @Override - public SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code) { - return smsTemplateCache.get(code); - } - - @Override - public String formatSmsTemplateContent(String content, Map params) { - return StrUtil.format(content, params); - } - @VisibleForTesting public List parseTemplateContentParams(String content) { return ReUtil.findAllGroup1(PATTERN_PARAMS, content); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java index 792ea9038..a9c0acb82 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.service.user; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserCreateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportExcelVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportRespVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import java.io.InputStream; @@ -20,7 +15,7 @@ import java.util.List; import java.util.Map; /** - * 用户 Service 接口 + * 后台用户 Service 接口 * * @author 芋道源码 */ @@ -41,6 +36,14 @@ public interface SysUserService { */ void updateUser(SysUserUpdateReqVO reqVO); + /** + * 更新用户的最后登陆信息 + * + * @param id 用户编号 + * @param loginIp 登陆 IP + */ + void updateUserLogin(Long id, String loginIp); + /** * 修改用户个人信息 * @@ -96,14 +99,6 @@ public interface SysUserService { */ SysUserDO getUserByUsername(String username); - /** - * 通过用户 ID 查询用户 - * - * @param id 用户ID - * @return 用户对象信息 - */ - SysUserDO getUser(Long id); - /** * 获得用户分页列表 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java index ff3e098dc..af7705b63 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java @@ -11,12 +11,12 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -84,6 +84,11 @@ public class SysUserServiceImpl implements SysUserService { userMapper.updateById(updateObj); } + @Override + public void updateUserLogin(Long id, String loginIp) { + userMapper.updateById(new SysUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); + } + @Override public void updateUserProfile(Long id, SysUserProfileUpdateReqVO reqVO) { // 校验正确性 @@ -154,11 +159,6 @@ public class SysUserServiceImpl implements SysUserService { return userMapper.selectByUsername(username); } - @Override - public SysUserDO getUser(Long id) { - return userMapper.selectById(id); - } - @Override public PageResult getUserPage(SysUserPageReqVO reqVO) { return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId())); diff --git a/yudao-admin-server/src/main/resources/application-dev.yaml b/yudao-admin-server/src/main/resources/application-dev.yaml index 3cbdefcf3..94d9cf9db 100644 --- a/yudao-admin-server/src/main/resources/application-dev.yaml +++ b/yudao-admin-server/src/main/resources/application-dev.yaml @@ -99,7 +99,7 @@ apollo: eagerLoad: enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 - dao: cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigDAOImpl + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl url: ${spring.datasource.dynamic.datasource.master.url} username: ${spring.datasource.dynamic.datasource.master.username} password: ${spring.datasource.dynamic.datasource.master.password} diff --git a/yudao-admin-server/src/main/resources/application-local.yaml b/yudao-admin-server/src/main/resources/application-local.yaml index a0ffb67ec..2d36b7157 100644 --- a/yudao-admin-server/src/main/resources/application-local.yaml +++ b/yudao-admin-server/src/main/resources/application-local.yaml @@ -99,7 +99,7 @@ apollo: eagerLoad: enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 - dao: cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigDAOImpl + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl url: ${spring.datasource.dynamic.datasource.master.url} username: ${spring.datasource.dynamic.datasource.master.username} password: ${spring.datasource.dynamic.datasource.master.password} diff --git a/yudao-admin-server/src/main/resources/application.yaml b/yudao-admin-server/src/main/resources/application.yaml index 486d4a487..cad787dfe 100644 --- a/yudao-admin-server/src/main/resources/application.yaml +++ b/yudao-admin-server/src/main/resources/application.yaml @@ -31,7 +31,7 @@ mybatis-plus: logic-delete-value: 1 # 逻辑已删除值(默认为 1) logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) mapper-locations: classpath*:mapper/*.xml - type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject + type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject --- #################### 芋道相关配置 #################### @@ -39,6 +39,8 @@ yudao: info: version: 1.0.0 base-package: cn.iocoder.yudao.adminserver + core-service: + base-package: cn.iocoder.yudao.coreservice web: api-prefix: /api controller-package: ${yudao.info.base-package} diff --git a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/redis/core/stream/RedisStreamTest.java b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/redis/core/stream/RedisStreamTest.java index 727b25750..90e25aeeb 100644 --- a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/redis/core/stream/RedisStreamTest.java +++ b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/redis/core/stream/RedisStreamTest.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.adminserver.BaseRedisIntegrationTest; import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.mail.SysMailSendConsumer; import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms.SysSmsSendConsumer; import cn.iocoder.yudao.adminserver.modules.system.mq.message.mail.SysMailSendMessage; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java index 7bbaab67a..dc4301952 100644 --- a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java +++ b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java @@ -7,9 +7,9 @@ import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms.SysSmsSendCon import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsCoreServiceImpl; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.sms.config.YudaoSmsAutoConfiguration; import org.junit.jupiter.api.Test; @@ -20,13 +20,14 @@ import javax.annotation.Resource; import java.util.Map; import java.util.concurrent.TimeUnit; +// TODO @芋艿:需要迁移 @Import({YudaoSmsAutoConfiguration.class, - SysSmsChannelServiceImpl.class, SysSmsServiceImpl.class, SysSmsTemplateServiceImpl.class, SysSmsLogServiceImpl.class, + SysSmsChannelServiceImpl.class, SysSmsCoreServiceImpl.class, SysSmsTemplateServiceImpl.class, SysSmsLogServiceImpl.class, SysSmsProducer.class, SysSmsSendConsumer.class}) public class SysSmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest { @Resource - private SysSmsServiceImpl smsService; + private SysSmsCoreServiceImpl smsService; @Resource private SysSmsChannelServiceImpl smsChannelService; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/BaseRedisUnitTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/BaseRedisUnitTest.java index fa6bd636b..7e650bc3e 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/BaseRedisUnitTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/BaseRedisUnitTest.java @@ -24,7 +24,7 @@ public class BaseRedisUnitTest { // Redis 配置类 RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer RedisAutoConfiguration.class, // Spring Redis 自动配置类 - YudaoTracerAutoConfiguration.class, // 自己的 Redis 配置类 + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 RedissonAutoConfiguration.class, // Redisson 自动高配置类 }) public static class Application { diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java index 4ef105df3..311792215 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.config; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java index 260ae7c60..4849d49cd 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java @@ -2,14 +2,15 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; import cn.hutool.core.io.resource.ResourceUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; @@ -29,8 +30,9 @@ public class InfFileServiceTest extends BaseDbUnitTest { @Resource private InfFileServiceImpl fileService; - @Resource + @MockBean private FileProperties fileProperties; + @Resource private InfFileMapper fileMapper; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogServiceImplTest.java index 689b88ec2..9a1edf3cf 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogServiceImplTest.java @@ -2,13 +2,13 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl; import cn.iocoder.yudao.framework.test.core.util.RandomUtils; @@ -38,26 +38,6 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest { @Resource private InfApiAccessLogMapper infApiAccessLogMapper; - @Test - public void testCreateApiAccessLogAsync() throws Exception { - ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo( - ApiAccessLogCreateDTO.class, - dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()) - ); - - // 执行service方法 - Future future = infApiAccessLogServiceImpl.createApiAccessLogAsync(createDTO); - - // 等异步执行完 - future.get(); - - InfApiAccessLogDO infApiAccessLogDO = infApiAccessLogMapper.selectOne(null); - // 断言 - assertNotNull(infApiAccessLogDO); - // 断言,忽略基本字段 - assertPojoEquals(createDTO, infApiAccessLogDO); - } - @Test public void testGetApiAccessLogPage() { // 构造测试数据 diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogServiceImplTest.java index 0a0c26c8a..97ce8c661 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogServiceImplTest.java @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl; @@ -41,28 +41,6 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { @Resource private InfApiErrorLogMapper infApiErrorLogMapper; - - @Test - public void testCreateApiErrorLogAsync() throws Exception { - ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo( - ApiErrorLogCreateDTO.class, - dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()) - ); - - // 执行service方法 - Future future = infApiErrorLogServiceImpl.createApiErrorLogAsync(createDTO); - - // 等异步执行完 - future.get(); - - InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogMapper.selectOne(null); - // 断言 - assertNotNull(infApiErrorLogDO); - // 断言,忽略基本字段 - assertPojoEquals(createDTO, infApiErrorLogDO); - } - - @Test public void testGetApiErrorLogPage() { // 构造测试数据 @@ -204,4 +182,5 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { // 验证 progressUserId 是否修改成功 assertEquals(processUserId, secondSelect.getProcessUserId()); } + } diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java index ed00a6690..51e59dc0a 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java @@ -1,17 +1,20 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysAuthServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.test.core.util.AssertUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -49,6 +52,8 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { @MockBean private SysUserService userService; @MockBean + private SysUserCoreService userCoreService; + @MockBean private SysPermissionService permissionService; @MockBean private AuthenticationManager authenticationManager; @@ -57,9 +62,11 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { @MockBean private SysCaptchaService captchaService; @MockBean - private SysLoginLogService loginLogService; + private SysLoginLogCoreService loginLogCoreService; @MockBean - private SysUserSessionService userSessionService; + private SysUserSessionCoreService userSessionCoreService; + @MockBean + private SysSocialService socialService; @Test public void testLoadUserByUsername_success() { @@ -94,7 +101,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { Long userId = randomLongId(); // mock 方法 01 SysUserDO user = randomPojo(SysUserDO.class, o -> o.setId(userId)); - when(userService.getUser(eq(userId))).thenReturn(user); + when(userCoreService.getUser(eq(userId))).thenReturn(user); // mock 方法 02 Set roleIds = randomSet(Long.class); when(permissionService.getUserRoleIds(eq(userId), eq(singleton(CommonStatusEnum.ENABLE.getStatus())))) @@ -128,7 +135,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { // 调用, 并断言异常 assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_NOT_FOUND); // 校验调用参数 - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.CAPTCHA_NOT_FOUND.getResult())) ); @@ -146,7 +153,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { // 调用, 并断言异常 assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_CODE_ERROR); // 校验调用参数 - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.CAPTCHA_CODE_ERROR.getResult())) ); @@ -167,7 +174,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_BAD_CREDENTIALS); // 校验调用参数 verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.BAD_CREDENTIALS.getResult())) ); @@ -188,7 +195,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_USER_DISABLED); // 校验调用参数 verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.USER_DISABLED.getResult())) ); @@ -209,7 +216,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_FAIL_UNKNOWN); // 校验调用参数 verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.UNKNOWN_ERROR.getResult())) ); @@ -237,13 +244,13 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { // mock 获得 User 拥有的角色编号数组 when(permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus()))).thenReturn(userRoleIds); // mock 缓存登录用户到 Redis - when(userSessionService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); + when(userSessionCoreService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); // 调用, 并断言异常 String login = authService.login(reqVO, userIp, userAgent); assertEquals(sessionId, login); // 校验调用参数 verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); - verify(loginLogService, times(1)).createLoginLog( + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) ); @@ -255,12 +262,12 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { String token = randomString(); LoginUser loginUser = randomPojo(LoginUser.class); // mock - when(userSessionService.getLoginUser(token)).thenReturn(loginUser); + when(userSessionCoreService.getLoginUser(token)).thenReturn(loginUser); // 调用 authService.logout(token); // 校验调用参数 - verify(userSessionService, times(1)).deleteUserSession(token); - verify(loginLogService, times(1)).createLoginLog( + verify(userSessionCoreService, times(1)).deleteUserSession(token); + verify(loginLogCoreService, times(1)).createLoginLog( argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGOUT_SELF.getType()) && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) ); diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionServiceImplTest.java index 740460ec9..ed7eac563 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionServiceImplTest.java @@ -1,207 +1,103 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth; -import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomDate; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.when; +import cn.hutool.core.date.DateUtil; +import cn.iocoder.yudao.adminserver.BaseDbAndRedisUnitTest; +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; +import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; +import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysUserSessionServiceImpl; +import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.test.core.util.AssertUtils; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; -import java.time.Duration; +import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.annotation.Resource; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; - -import cn.hutool.core.date.DateUtil; -import cn.iocoder.yudao.adminserver.BaseDbAndRedisUnitTest; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.security.config.SecurityProperties; -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; -import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; -import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysLoginUserRedisDAO; -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; -import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysUserSessionServiceImpl; -import cn.iocoder.yudao.adminserver.modules.system.service.dept.impl.SysDeptServiceImpl; -import cn.iocoder.yudao.adminserver.modules.system.service.logger.impl.SysLoginLogServiceImpl; -import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; -import cn.iocoder.yudao.framework.test.core.util.AssertUtils; -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; +import static java.util.Collections.singletonList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; /** - * SysUserSessionServiceImpl Tester. + * {@link SysUserSessionServiceImpl} 的单元测试 * * @author Lyon - * @version 1.0 - * @since
3月 8, 2021
*/ -@Import({SysUserSessionServiceImpl.class, SysLoginUserRedisDAO.class}) +@Import({SysUserSessionServiceImpl.class}) public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { @Resource - private SysUserSessionServiceImpl sysUserSessionService; + private SysUserSessionServiceImpl userSessionService; + @Resource - private SysUserSessionMapper sysUserSessionMapper; - @Resource - private SysLoginUserRedisDAO sysLoginUserRedisDAO; - @Resource - private SysUserMapper sysUserMapper; + private SysUserSessionMapper userSessionMapper; @MockBean - private SecurityProperties securityProperties; + private SysUserService userService; @MockBean - private SysDeptServiceImpl sysDeptService; + private SysLoginLogCoreService loginLogCoreService; @MockBean - private SysUserServiceImpl sysUserService; - @MockBean - private SysLoginLogServiceImpl sysLoginLogService; - - @Test - public void testCreateUserSession_success() { - // 准备参数 - String userIp = randomString(); - String userAgent = randomString(); - LoginUser loginUser = randomPojo(LoginUser.class); - // mock - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); - // 调用 - String sessionId = sysUserSessionService.createUserSession(loginUser, userIp, userAgent); - // 校验记录的属性是否正确 - SysUserSessionDO sysUserSessionDO = sysUserSessionMapper.selectById(sessionId); - assertEquals(sysUserSessionDO.getId(), sessionId); - assertEquals(sysUserSessionDO.getUserId(), loginUser.getId()); - assertEquals(sysUserSessionDO.getUserIp(), userIp); - assertEquals(sysUserSessionDO.getUserAgent(), userAgent); - assertEquals(sysUserSessionDO.getUsername(), loginUser.getUsername()); - LoginUser redisLoginUser = sysLoginUserRedisDAO.get(sessionId); - AssertUtils.assertPojoEquals(redisLoginUser, loginUser, "username","password"); - } - - @Test - public void testCreateRefreshUserSession_success() { - // 准备参数 - String sessionId = randomString(); - String userIp = randomString(); - String userAgent = randomString(); - Long timeLong = randomLongId(); - String userName = randomString(); - Date date = randomDate(); - LoginUser loginUser = randomPojo(LoginUser.class); - // mock - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); - loginUser.setUpdateTime(date); - sysLoginUserRedisDAO.set(sessionId, loginUser); - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(userName) - .sessionTimeout(addTime(Duration.ofMillis(timeLong))) - .build(); - sysUserSessionMapper.insert(userSession); - SysUserSessionDO insertDO = sysUserSessionMapper.selectById(sessionId); - // 调用 - sysUserSessionService.refreshUserSession(sessionId, loginUser); - // 校验记录 redis - LoginUser redisLoginUser = sysLoginUserRedisDAO.get(sessionId); - assertNotEquals(redisLoginUser.getUpdateTime(), date); - // 校验记录 SysUserSessionDO - SysUserSessionDO updateDO = sysUserSessionMapper.selectById(sessionId); - assertEquals(updateDO.getUsername(), loginUser.getUsername()); - assertNotEquals(updateDO.getUpdateTime(), insertDO.getUpdateTime()); - assertNotEquals(updateDO.getSessionTimeout(), addTime(Duration.ofMillis(timeLong))); - } - - @Test - public void testDeleteUserSession_success() { - // 准备参数 - String sessionId = randomString(); - String userIp = randomString(); - String userAgent = randomString(); - Long timeLong = randomLongId(); - LoginUser loginUser = randomPojo(LoginUser.class); - // mock 存入 Redis - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); - sysLoginUserRedisDAO.set(sessionId, loginUser); - // mock 存入 db - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) - .sessionTimeout(addTime(Duration.ofMillis(timeLong))) - .build(); - sysUserSessionMapper.insert(userSession); - // 校验数据存在 - assertNotNull(sysLoginUserRedisDAO.get(sessionId)); - assertNotNull(sysUserSessionMapper.selectById(sessionId)); - // 调用 - sysUserSessionService.deleteUserSession(sessionId); - // 校验数据不存在了 - assertNull(sysLoginUserRedisDAO.get(sessionId)); - assertNull(sysUserSessionMapper.selectById(sessionId)); - } + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; @Test public void testGetUserSessionPage_success() { // mock 数据 + SysUserDO dbUser = randomPojo(SysUserDO.class, o -> { + o.setSex(randomEle(SysSexEnum.values()).getSex()); + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + }); + when(userService.getUsersByUsername(eq(dbUser.getUsername()))).thenReturn(singletonList(dbUser)); + // 插入可被查询到的数据 String userIp = randomString(); - SysUserDO dbUser1 = randomPojo(SysUserDO.class, o -> { - o.setUsername("testUsername1"); - o.setSex(randomEle(SysSexEnum.values()).getSex()); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); - SysUserDO dbUser2 = randomPojo(SysUserDO.class, o -> { - o.setUsername("testUsername2"); - o.setSex(randomEle(SysSexEnum.values()).getSex()); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); SysUserSessionDO dbSession = randomPojo(SysUserSessionDO.class, o -> { - o.setUserId(dbUser1.getId()); + o.setUserId(dbUser.getId()); + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); o.setUserIp(userIp); }); - sysUserMapper.insert(dbUser1); - sysUserMapper.insert(dbUser2); - sysUserSessionMapper.insert(dbSession); - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { + userSessionMapper.insert(dbSession); + // 测试 username 不匹配 + userSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { o.setId(randomString()); - o.setUserId(dbUser2.getId()); - })); - // 测试 userId 不匹配 - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { - o.setId(randomString()); - o.setUserId(123456l); + o.setUserId(123456L); })); // 测试 userIp 不匹配 - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { + userSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { o.setId(randomString()); o.setUserIp("testUserIp"); })); // 准备参数 - SysUserSessionPageReqVO reqVo = new SysUserSessionPageReqVO(); - reqVo.setUserIp(userIp); + SysUserSessionPageReqVO reqVO = new SysUserSessionPageReqVO(); + reqVO.setUsername(dbUser.getUsername()); + reqVO.setUserIp(userIp); + // 调用 - PageResult pageResult = sysUserSessionService.getUserSessionPage(reqVo); + PageResult pageResult = userSessionService.getUserSessionPage(reqVO); // 断言 - assertEquals(3, pageResult.getTotal()); - assertEquals(3, pageResult.getList().size()); + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); assertPojoEquals(dbSession, pageResult.getList().get(0)); } + // TODO 芋艿:单测写的有问题 @Test - public void testClearSessionTimeout_success() throws Exception { + public void testClearSessionTimeout_success() { // 准备超时数据 120 条, 在线用户 1 条 int expectedTimeoutCount = 120, expectedTotal = 1; @@ -209,17 +105,23 @@ public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { List prepareData = Stream .iterate(0, i -> i) .limit(expectedTimeoutCount) - .map(i -> RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetSecond(new Date(), -1)))) + .map(i -> randomPojo(SysUserSessionDO.class, o -> { + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); + o.setSessionTimeout(DateUtil.offsetSecond(new Date(), -1)); + })) .collect(Collectors.toList()); - SysUserSessionDO sessionDO = RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30))); + SysUserSessionDO sessionDO = randomPojo(SysUserSessionDO.class, o -> { + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); + o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30)); + }); prepareData.add(sessionDO); - prepareData.forEach(sysUserSessionMapper::insert); + prepareData.forEach(userSessionMapper::insert); - //清空超时数据 - long actualTimeoutCount = sysUserSessionService.clearSessionTimeout(); - //校验 + // 清空超时数据 + long actualTimeoutCount = userSessionService.clearSessionTimeout(); + // 校验 assertEquals(expectedTimeoutCount, actualTimeoutCount); - List userSessionDOS = sysUserSessionMapper.selectList(); + List userSessionDOS = userSessionMapper.selectList(); assertEquals(expectedTotal, userSessionDOS.size()); AssertUtils.assertPojoEquals(sessionDO, userSessionDOS.get(0), "updateTime"); } diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataServiceTest.java index ecb009335..e44024477 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataServiceTest.java @@ -1,13 +1,13 @@ package cn.iocoder.yudao.adminserver.modules.system.service.dict; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; @@ -51,37 +51,6 @@ public class SysDictDataServiceTest extends BaseDbUnitTest { @MockBean private SysDictDataProducer dictDataProducer; - /** - * 测试加载到新的字典数据的情况 - */ - @Test - @SuppressWarnings("unchecked") - public void testInitLocalCache() { - // mock 数据 - SysDictDataDO dictData01 = randomDictDataDO(); - dictDataMapper.insert(dictData01); - SysDictDataDO dictData02 = randomDictDataDO(); - dictDataMapper.insert(dictData02); - - // 调用 - dictDataService.initLocalCache(); - // 断言 labelDictDataCache 缓存 - ImmutableTable labelDictDataCache = - (ImmutableTable) getFieldValue(dictDataService, "labelDictDataCache"); - assertEquals(2, labelDictDataCache.size()); - assertPojoEquals(dictData01, labelDictDataCache.get(dictData01.getDictType(), dictData01.getLabel())); - assertPojoEquals(dictData02, labelDictDataCache.get(dictData02.getDictType(), dictData02.getLabel())); - // 断言 valueDictDataCache 缓存 - ImmutableTable valueDictDataCache = - (ImmutableTable) getFieldValue(dictDataService, "valueDictDataCache"); - assertEquals(2, valueDictDataCache.size()); - assertPojoEquals(dictData01, valueDictDataCache.get(dictData01.getDictType(), dictData01.getValue())); - assertPojoEquals(dictData02, valueDictDataCache.get(dictData02.getDictType(), dictData02.getValue())); - // 断言 maxUpdateTime 缓存 - Date maxUpdateTime = (Date) getFieldValue(dictDataService, "maxUpdateTime"); - assertEquals(ObjectUtils.max(dictData01.getUpdateTime(), dictData02.getUpdateTime()), maxUpdateTime); - } - @Test public void testGetDictDataPage() { // mock 数据 diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogServiceImplTest.java index d6a921fe1..e50141f35 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogServiceImplTest.java @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; @@ -33,35 +33,14 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { @Resource private SysLoginLogMapper loginLogMapper; - @Test - public void testCreateLoginLog() { - String traceId = TracerUtils.getTraceId(); - SysLoginLogCreateReqVO reqVO = RandomUtils.randomPojo(SysLoginLogCreateReqVO.class, vo -> { - // 指定随机的范围,避免超出范围入库失败 - vo.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); - vo.setResult(RandomUtil.randomEle(SysLoginResultEnum.values()).getResult()); - // 使用TracerUtils生成的TraceId - vo.setTraceId(traceId); - }); - - // 执行service方法 - sysLoginLogService.createLoginLog(reqVO); - - // 断言,忽略基本字段 - SysLoginLogDO sysLoginLogDO = loginLogMapper.selectOne(null); - assertPojoEquals(reqVO, sysLoginLogDO); - } - - @Test public void testGetLoginLogPage() { - // 构造测试数据 - // 登录成功的 SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); logDO.setTraceId(TracerUtils.getTraceId()); + logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); logDO.setUserIp("192.168.199.16"); logDO.setUsername("wangkai"); @@ -100,13 +79,13 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { @Test public void testGetLoginLogList() { - // 构造测试数据 // 登录成功的 SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); logDO.setTraceId(TracerUtils.getTraceId()); + logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); logDO.setUserIp("192.168.111.16"); logDO.setUsername("wangxiaokai"); diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysOperateLogServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysOperateLogServiceImplTest.java index 48cc4c5cc..7523c5c5d 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysOperateLogServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysOperateLogServiceImplTest.java @@ -2,34 +2,35 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; import cn.iocoder.yudao.adminserver.modules.system.service.logger.impl.SysOperateLogServiceImpl; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; +import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.*; +import java.util.Collections; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelServiceTest.java index 76337aa5d..38499d2c4 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelServiceTest.java @@ -2,18 +2,18 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; import cn.hutool.core.bean.BeanUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogServiceTest.java index 4ea3745df..23ab395b7 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogServiceTest.java @@ -2,35 +2,32 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import static cn.hutool.core.util.RandomUtil.randomBoolean; import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static org.junit.jupiter.api.Assertions.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * {@link SysSmsLogServiceImpl} 的单元测试类 @@ -46,93 +43,6 @@ public class SysSmsLogServiceTest extends BaseDbUnitTest { @Resource private SysSmsLogMapper smsLogMapper; - @Test - public void testCreateSmsLog() { - // 准备参数 - String mobile = randomString(); - Long userId = randomLongId(); - Integer userType = randomEle(UserTypeEnum.values()).getValue(); - Boolean isSend = randomBoolean(); - SysSmsTemplateDO templateDO = randomPojo(SysSmsTemplateDO.class, - o -> o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType())); - String templateContent = randomString(); - Map templateParams = randomTemplateParams(); - // mock 方法 - - // 调用 - Long logId = smsLogService.createSmsLog(mobile, userId, userType, isSend, - templateDO, templateContent, templateParams); - // 断言 - SysSmsLogDO logDO = smsLogMapper.selectById(logId); - assertEquals(isSend ? SysSmsSendStatusEnum.INIT.getStatus() : SysSmsSendStatusEnum.IGNORE.getStatus(), - logDO.getSendStatus()); - assertEquals(mobile, logDO.getMobile()); - assertEquals(userType, logDO.getUserType()); - assertEquals(userId, logDO.getUserId()); - assertEquals(templateDO.getId(), logDO.getTemplateId()); - assertEquals(templateDO.getCode(), logDO.getTemplateCode()); - assertEquals(templateDO.getType(), logDO.getTemplateType()); - assertEquals(templateDO.getChannelId(), logDO.getChannelId()); - assertEquals(templateDO.getChannelCode(), logDO.getChannelCode()); - assertEquals(templateContent, logDO.getTemplateContent()); - assertEquals(templateParams, logDO.getTemplateParams()); - assertEquals(SysSmsReceiveStatusEnum.INIT.getStatus(), logDO.getReceiveStatus()); - } - - @Test - public void testUpdateSmsSendResult() { - // mock 数据 - SysSmsLogDO dbSmsLog = randomSmsLogDO( - o -> o.setSendStatus(SysSmsSendStatusEnum.IGNORE.getStatus())); - smsLogMapper.insert(dbSmsLog); - // 准备参数 - Long id = dbSmsLog.getId(); - Integer sendCode = randomInteger(); - String sendMsg = randomString(); - String apiSendCode = randomString(); - String apiSendMsg = randomString(); - String apiRequestId = randomString(); - String apiSerialNo = randomString(); - - // 调用 - smsLogService.updateSmsSendResult(id, sendCode, sendMsg, - apiSendCode, apiSendMsg, apiRequestId, apiSerialNo); - // 断言 - dbSmsLog = smsLogMapper.selectById(id); - assertEquals(CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS.getStatus() - : SysSmsSendStatusEnum.FAILURE.getStatus(), dbSmsLog.getSendStatus()); - assertNotNull(dbSmsLog.getSendTime()); - assertEquals(sendMsg, dbSmsLog.getSendMsg()); - assertEquals(apiSendCode, dbSmsLog.getApiSendCode()); - assertEquals(apiSendMsg, dbSmsLog.getApiSendMsg()); - assertEquals(apiRequestId, dbSmsLog.getApiRequestId()); - assertEquals(apiSerialNo, dbSmsLog.getApiSerialNo()); - } - - @Test - public void testUpdateSmsReceiveResult() { - // mock 数据 - SysSmsLogDO dbSmsLog = randomSmsLogDO( - o -> o.setReceiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus())); - smsLogMapper.insert(dbSmsLog); - // 准备参数 - Long id = dbSmsLog.getId(); - Boolean success = randomBoolean(); - Date receiveTime = randomDate(); - String apiReceiveCode = randomString(); - String apiReceiveMsg = randomString(); - - // 调用 - smsLogService.updateSmsReceiveResult(id, success, receiveTime, apiReceiveCode, apiReceiveMsg); - // 断言 - dbSmsLog = smsLogMapper.selectById(id); - assertEquals(success ? SysSmsReceiveStatusEnum.SUCCESS.getStatus() - : SysSmsReceiveStatusEnum.FAILURE.getStatus(), dbSmsLog.getReceiveStatus()); - assertEquals(receiveTime, dbSmsLog.getReceiveTime()); - assertEquals(apiReceiveCode, dbSmsLog.getApiReceiveCode()); - assertEquals(apiReceiveMsg, dbSmsLog.getApiReceiveMsg()); - } - @Test public void testGetSmsLogPage() { // mock 数据 diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateServiceTest.java index 4707b9102..b751fe499 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateServiceTest.java @@ -1,43 +1,39 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.sms.core.client.SmsClient; -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; -import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; -import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.framework.sms.core.client.SmsClient; +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; +import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; +import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.Date; import java.util.List; -import java.util.Map; import java.util.function.Consumer; -import static cn.hutool.core.bean.BeanUtil.getFieldValue; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; @@ -66,27 +62,6 @@ public class SysSmsTemplateServiceTest extends BaseDbUnitTest { @MockBean private SysSmsProducer smsProducer; - @Test - @SuppressWarnings("unchecked") - void testInitLocalCache() { - // mock 数据 - SysSmsTemplateDO smsTemplate01 = randomSmsTemplateDO(); - smsTemplateMapper.insert(smsTemplate01); - SysSmsTemplateDO smsTemplate02 = randomSmsTemplateDO(); - smsTemplateMapper.insert(smsTemplate02); - - // 调用 - smsTemplateService.initLocalCache(); - // 断言 deptCache 缓存 - Map smsTemplateCache = (Map) getFieldValue(smsTemplateService, "smsTemplateCache"); - assertEquals(2, smsTemplateCache.size()); - assertPojoEquals(smsTemplate01, smsTemplateCache.get(smsTemplate01.getCode())); - assertPojoEquals(smsTemplate02, smsTemplateCache.get(smsTemplate02.getCode())); - // 断言 maxUpdateTime 缓存 - Date maxUpdateTime = (Date) getFieldValue(smsTemplateService, "maxUpdateTime"); - assertEquals(max(smsTemplate01.getUpdateTime(), smsTemplate02.getUpdateTime()), maxUpdateTime); - } - @Test public void testParseTemplateContentParams() { // 准备参数 diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java index 2e9ed80b4..e20e72793 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImplTest.java @@ -3,21 +3,21 @@ package cn.iocoder.yudao.adminserver.modules.system.service.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.adminserver.BaseDbUnitTest; -import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; +import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; @@ -36,9 +36,9 @@ import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomBytes; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static org.assertj.core.util.Lists.newArrayList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -243,7 +243,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest { // 调用数据 userService.deleteUser(userId); // 校验结果 - assertNull(userService.getUser(userId)); + assertNull(userMapper.selectById(userId)); // 校验调用次数 verify(permissionService, times(1)).processUserDeleted(eq(userId)); } diff --git a/yudao-admin-server/src/test/resources/application-unit-test.yaml b/yudao-admin-server/src/test/resources/application-unit-test.yaml index 5b1461447..d306a7af4 100644 --- a/yudao-admin-server/src/test/resources/application-unit-test.yaml +++ b/yudao-admin-server/src/test/resources/application-unit-test.yaml @@ -36,34 +36,9 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) # Resilience4j 配置项 -resilience4j: - ratelimiter: - instances: - backendA: - limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 - limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 - timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s - register-health-indicator: true # 是否注册到健康监测 --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### # 芋道配置项,设置当前项目所有自定义的配置 -yudao: - security: - token-header: Authorization - token-secret: abcdefghijklmnopqrstuvwxyz - token-timeout: 1d - session-timeout: 30m - mock-enable: true - mock-secret: test - swagger: - enable: false # 单元测试,禁用 Swagger - file: - base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ - xss: - enable: false - exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 - - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求 - - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 diff --git a/yudao-admin-server/src/test/resources/sql/create_tables.sql b/yudao-admin-server/src/test/resources/sql/create_tables.sql index e575d184b..db67cad23 100644 --- a/yudao-admin-server/src/test/resources/sql/create_tables.sql +++ b/yudao-admin-server/src/test/resources/sql/create_tables.sql @@ -179,6 +179,7 @@ CREATE TABLE IF NOT EXISTS "sys_dict_type" ( CREATE TABLE IF NOT EXISTS `sys_user_session` ( `id` varchar(32) NOT NULL, `user_id` bigint DEFAULT NULL, + "user_type" tinyint NOT NULL, `username` varchar(50) NOT NULL DEFAULT '', `user_ip` varchar(50) DEFAULT NULL, `user_agent` varchar(512) DEFAULT NULL, @@ -223,6 +224,8 @@ CREATE TABLE IF NOT EXISTS "sys_notice" ( CREATE TABLE IF NOT EXISTS `sys_login_log` ( `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, `log_type` bigint(4) NOT NULL, + "user_id" bigint not null default '0', + "user_type" tinyint NOT NULL, `trace_id` varchar(64) NOT NULL DEFAULT '', `username` varchar(50) NOT NULL DEFAULT '', `result` tinyint(4) NOT NULL, diff --git a/yudao-core-service/pom.xml b/yudao-core-service/pom.xml new file mode 100644 index 000000000..3ce350b54 --- /dev/null +++ b/yudao-core-service/pom.xml @@ -0,0 +1,90 @@ + + + + yudao + cn.iocoder.boot + 1.1.0-snapshot + + 4.0.0 + + yudao-core-service + jar + + yudao-admin-server + + 公共服务,通过 jar 包的方式,被 yudao-admin-server、yudao-user-service 使用。例如说: + 1. 日志相关:访问日志、登录日志、异常日志等等 + 2. 认证相关:在线 Session + 3. 短信相关:短信模板、短信日志 + 等等 + + https://github.com/YunaiV/ruoyi-vue-pro + + + + + cn.iocoder.boot + yudao-spring-boot-starter-biz-dict + + + cn.iocoder.boot + yudao-spring-boot-starter-biz-sms + + + + + cn.iocoder.boot + yudao-spring-boot-starter-web + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + + cn.iocoder.boot + yudao-spring-boot-starter-redis + + + + + cn.iocoder.boot + yudao-spring-boot-starter-config + + + + + cn.iocoder.boot + yudao-spring-boot-starter-mq + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + test + + + + + com.google.guava + guava + + + + diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiAccessLogCoreConvert.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiAccessLogCoreConvert.java new file mode 100644 index 000000000..4bfb4941c --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiAccessLogCoreConvert.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.coreservice.modules.infra.convert.logger; + +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface InfApiAccessLogCoreConvert { + + InfApiAccessLogCoreConvert INSTANCE = Mappers.getMapper(InfApiAccessLogCoreConvert.class); + + InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiErrorLogCoreConvert.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiErrorLogCoreConvert.java new file mode 100644 index 000000000..8979013d5 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiErrorLogCoreConvert.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.coreservice.modules.infra.convert.logger; + +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface InfApiErrorLogCoreConvert { + + InfApiErrorLogCoreConvert INSTANCE = Mappers.getMapper(InfApiErrorLogCoreConvert.class); + + InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/package-info.java similarity index 56% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/package-info.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/package-info.java index d1aa5643a..bdb8ce7a3 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/package-info.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/package-info.java @@ -3,4 +3,4 @@ * * 目前使用 MapStruct 框架 */ -package cn.iocoder.yudao.userserver.modules.infra.convert; +package cn.iocoder.yudao.coreservice.modules.infra.convert; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md similarity index 100% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/config/InfConfigDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/config/InfConfigDO.java similarity index 94% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/config/InfConfigDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/config/InfConfigDO.java index a9ab432d6..5955fe18c 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/config/InfConfigDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/config/InfConfigDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.config; +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableField; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/file/InfFileDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java similarity index 93% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/file/InfFileDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java index 594ae4541..1b4a73328 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/file/InfFileDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file; +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.IdType; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java similarity index 97% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java index 229219e04..bd7554405 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger; +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java similarity index 95% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java index 6ed2b3150..114ebf23a 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger; +package cn.iocoder.yudao.coreservice.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 cn.iocoder.yudao.coreservice.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/config/InfConfigCoreDAOImpl.java similarity index 81% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/config/InfConfigCoreDAOImpl.java index a2e7b6f8a..f3d32513b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/config/InfConfigCoreDAOImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config; import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; @@ -12,15 +12,15 @@ import java.util.Date; import java.util.List; /** - * ConfigFrameworkDAO 实现类 + * ConfigFrameworkDAO Core 实现类 * * @author 芋道源码 */ -public class InfConfigDAOImpl implements ConfigFrameworkDAO { +public class InfConfigCoreDAOImpl implements ConfigFrameworkDAO { private final JdbcTemplate jdbcTemplate; - public InfConfigDAOImpl(String jdbcUrl, String username, String password) { + public InfConfigCoreDAOImpl(String jdbcUrl, String username, String password) { DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password); this.jdbcTemplate = new JdbcTemplate(dataSource); } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java new file mode 100644 index 000000000..180dc2d79 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface InfFileCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiAccessLogCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiAccessLogCoreMapper.java new file mode 100644 index 000000000..a18925489 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiAccessLogCoreMapper.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * API 访问日志 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface InfApiAccessLogCoreMapper extends BaseMapperX { +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiErrorLogCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiErrorLogCoreMapper.java new file mode 100644 index 000000000..1776c7887 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiErrorLogCoreMapper.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface InfApiErrorLogCoreMapper extends BaseMapperX { +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java similarity index 86% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java index 618d5d9be..cba1d02dd 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.infra.enums.logger; +package cn.iocoder.yudao.coreservice.modules.infra.enums.logger; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/package-info.java new file mode 100644 index 000000000..6231dae91 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位类,可以无视 + */ +package cn.iocoder.yudao.coreservice.modules.infra.enums; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/package-info.java similarity index 78% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/package-info.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/package-info.java index fdf89894e..1f011d6a1 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/package-info.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/package-info.java @@ -4,4 +4,4 @@ * * 缩写:inf */ -package cn.iocoder.yudao.userserver.modules.infra; +package cn.iocoder.yudao.coreservice.modules.infra; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiAccessLogService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreService.java similarity index 51% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiAccessLogService.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreService.java index bcc4f3a97..f5480572d 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiAccessLogService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreService.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.infra.service.logger; +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServi * * @author 芋道源码 */ -public interface InfApiAccessLogService extends ApiAccessLogFrameworkService { +public interface InfApiAccessLogCoreService extends ApiAccessLogFrameworkService { } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiErrorLogService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreService.java similarity index 51% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiErrorLogService.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreService.java index 2c221604e..6c8d69201 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiErrorLogService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreService.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.infra.service.logger; +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServic * * @author 芋道源码 */ -public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { +public interface InfApiErrorLogCoreService extends ApiErrorLogFrameworkService { } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiAccessLogCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiAccessLogCoreServiceImpl.java new file mode 100644 index 000000000..6ef022b5a --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiAccessLogCoreServiceImpl.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl; + +import cn.iocoder.yudao.coreservice.modules.infra.convert.logger.InfApiAccessLogCoreConvert; +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiAccessLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.InfApiAccessLogCoreService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +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 InfApiAccessLogCoreServiceImpl implements InfApiAccessLogCoreService { + + @Resource + private InfApiAccessLogCoreMapper apiAccessLogMapper; + + @Override + @Async + public void createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { + InfApiAccessLogDO apiAccessLog = InfApiAccessLogCoreConvert.INSTANCE.convert(createDTO); + apiAccessLogMapper.insert(apiAccessLog); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiErrorLogCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiErrorLogCoreServiceImpl.java new file mode 100644 index 000000000..a11552bcb --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiErrorLogCoreServiceImpl.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl; + +import cn.iocoder.yudao.coreservice.modules.infra.convert.logger.InfApiErrorLogCoreConvert; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiErrorLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.InfApiErrorLogCoreService; +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +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 InfApiErrorLogCoreServiceImpl implements InfApiErrorLogCoreService { + + @Resource + private InfApiErrorLogCoreMapper apiErrorLogMapper; + + @Override + @Async + public void createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { + InfApiErrorLogDO apiErrorLog = InfApiErrorLogCoreConvert.INSTANCE.convert(createDTO); + apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); + apiErrorLogMapper.insert(apiErrorLog); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java new file mode 100644 index 000000000..230bbc092 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java @@ -0,0 +1,6 @@ +/** + * 提供 POJO 类的实体转换 + * + * 目前使用 MapStruct 框架 + */ +package cn.iocoder.yudao.coreservice.modules.member.convert; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md new file mode 100644 index 000000000..8153487b7 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md @@ -0,0 +1 @@ + diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java similarity index 95% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java index d5263d388..57221f614 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user; +package cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java new file mode 100644 index 000000000..27c0c9509 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MbrUserCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/package-info.java new file mode 100644 index 000000000..17abe90bd --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/package-info.java @@ -0,0 +1,7 @@ +/** + * member 包下,我们放会员业务. + * 例如说:会员中心等等 + * + * 缩写:mbr + */ +package cn.iocoder.yudao.coreservice.modules.member; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java new file mode 100644 index 000000000..934413956 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.coreservice.modules.member.service.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; + +/** + * 前台用户 Core Service 接口 + * + * @author 芋道源码 + */ +public interface MbrUserCoreService { + /** + * 通过用户 ID 查询用户 + * + * @param id 用户ID + * @return 用户对象信息 + */ + MbrUserDO getUser(Long id); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java new file mode 100644 index 000000000..08ee22c76 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.coreservice.modules.member.service.user.impl; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user.MbrUserCoreMapper; +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * User Core Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Slf4j +public class MbrUserCoreServiceImpl implements MbrUserCoreService { + + @Resource + private MbrUserCoreMapper userCoreMapper; + + @Override + public MbrUserDO getUser(Long id) { + return userCoreMapper.selectById(id); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/dict/SysDictDataConvert.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/dict/SysDictDataCoreConvert.java similarity index 53% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/dict/SysDictDataConvert.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/dict/SysDictDataCoreConvert.java index 02155f698..e68e165d3 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/dict/SysDictDataConvert.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/dict/SysDictDataCoreConvert.java @@ -1,7 +1,7 @@ -package cn.iocoder.yudao.userserver.modules.system.convert.dict; +package cn.iocoder.yudao.coreservice.modules.system.convert.dict; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -9,9 +9,9 @@ import java.util.Collection; import java.util.List; @Mapper -public interface SysDictDataConvert { +public interface SysDictDataCoreConvert { - SysDictDataConvert INSTANCE = Mappers.getMapper(SysDictDataConvert.class); + SysDictDataCoreConvert INSTANCE = Mappers.getMapper(SysDictDataCoreConvert.class); DictDataRespDTO convert02(SysDictDataDO bean); diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/logger/SysLoginLogCoreConvert.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/logger/SysLoginLogCoreConvert.java new file mode 100644 index 000000000..9c1992738 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/logger/SysLoginLogCoreConvert.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.coreservice.modules.system.convert.logger; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SysLoginLogCoreConvert { + + SysLoginLogCoreConvert INSTANCE = Mappers.getMapper(SysLoginLogCoreConvert.class); + + SysLoginLogDO convert(SysLoginLogCreateReqDTO bean); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/package-info.java new file mode 100644 index 000000000..87914750a --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/package-info.java @@ -0,0 +1,6 @@ +/** + * 提供 POJO 类的实体转换 + * + * 目前使用 MapStruct 框架 + */ +package cn.iocoder.yudao.coreservice.modules.system.convert; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md new file mode 100644 index 000000000..8153487b7 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md @@ -0,0 +1 @@ + diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/auth/SysUserSessionDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/auth/SysUserSessionDO.java similarity index 83% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/auth/SysUserSessionDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/auth/SysUserSessionDO.java index 8aa25a5b3..67e4fc2d9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/auth/SysUserSessionDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/auth/SysUserSessionDO.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -35,9 +35,15 @@ public class SysUserSessionDO extends BaseDO { /** * 用户编号 * - * 关联 {@link SysUserDO#getId()} + * 关联 SysUserDO.id 或者 MbrUserDO.id */ private Long userId; + /** + * 用户类型 + * + * 枚举 {@link UserTypeEnum} + */ + private Integer userType; /** * 用户账号 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dict/SysDictDataDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/dict/SysDictDataDO.java similarity index 94% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dict/SysDictDataDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/dict/SysDictDataDO.java index 22b072213..d398d5ef3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dict/SysDictDataDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/dict/SysDictDataDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/logger/SysLoginLogDO.java similarity index 85% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/logger/SysLoginLogDO.java index 8bb80aa7a..e7e7a4144 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/logger/SysLoginLogDO.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; -import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -14,7 +14,7 @@ import lombok.ToString; * * 注意,包括登录和登出两种行为 * - * @author ruoyi + * @author 芋道源码 */ @TableName("sys_login_log") @Data diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/package-info.java new file mode 100644 index 000000000..f2ed88035 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsChannelDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsChannelDO.java similarity index 94% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsChannelDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsChannelDO.java index 3a3b879b5..87b67cd7f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsChannelDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsChannelDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsLogDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsLogDO.java similarity index 95% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsLogDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsLogDO.java index 3ac39b040..6567ee215 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsLogDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsLogDO.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.sms.core.enums.SmsFrameworkErrorCodeConstants; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java similarity index 93% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java index e40976059..9e1dd35c7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/user/SysUserDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/user/SysUserDO.java similarity index 92% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/user/SysUserDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/user/SysUserDO.java index fded1c661..ef33f8d2a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/user/SysUserDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/user/SysUserDO.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user; +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user; +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -16,7 +16,7 @@ import java.util.Set; /** * 管理后台的用户 DO * - * @author ruoyi + * @author 芋道源码 */ @TableName(value = "sys_user", autoResultMap = true) @Data diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/auth/SysUserSessionCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/auth/SysUserSessionCoreMapper.java new file mode 100644 index 000000000..69b5c5acb --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/auth/SysUserSessionCoreMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysUserSessionCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/dict/SysDictDataCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/dict/SysDictDataCoreMapper.java new file mode 100644 index 000000000..bda1a9142 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/dict/SysDictDataCoreMapper.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict; + + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.ibatis.annotations.Mapper; + +import java.util.Date; + +@Mapper +public interface SysDictDataCoreMapper extends BaseMapperX { + + default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { + return selectOne(new QueryWrapper().select("id") + .gt("update_time", maxUpdateTime).last("LIMIT 1")) != null; + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/logger/SysLoginLogCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/logger/SysLoginLogCoreMapper.java new file mode 100644 index 000000000..e6dd1ff51 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/logger/SysLoginLogCoreMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysLoginLogCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/package-info.java new file mode 100644 index 000000000..144a05407 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsLogCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsLogCoreMapper.java new file mode 100644 index 000000000..d09554575 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsLogCoreMapper.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SysSmsLogCoreMapper extends BaseMapperX { +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsTemplateCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsTemplateCoreMapper.java new file mode 100644 index 000000000..4e064b40d --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsTemplateCoreMapper.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; + +@Mapper +public interface SysSmsTemplateCoreMapper extends BaseMapperX { + + @Select("SELECT id FROM sys_sms_template WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/user/SysUserCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/user/SysUserCoreMapper.java new file mode 100644 index 000000000..a59275b39 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/user/SysUserCoreMapper.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.user; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysUserCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/SysRedisKeyCoreConstants.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/SysRedisKeyCoreConstants.java new file mode 100644 index 000000000..fb4118874 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/SysRedisKeyCoreConstants.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.coreservice.modules.system.dal.redis; + +import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine; +import cn.iocoder.yudao.framework.security.core.LoginUser; + +import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.STRING; + +/** + * System Redis Key 枚举类 + * + * @author 芋道源码 + */ +public interface SysRedisKeyCoreConstants { + + RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", + "login_user:%s", // 参数为 sessionId + STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/auth/SysLoginUserRedisDAO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/auth/SysLoginUserCoreRedisDAO.java similarity index 69% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/auth/SysLoginUserRedisDAO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/auth/SysLoginUserCoreRedisDAO.java index 6ca358a4a..921492c9d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/auth/SysLoginUserRedisDAO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/auth/SysLoginUserCoreRedisDAO.java @@ -1,15 +1,14 @@ -package cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth; +package cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth; -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.security.config.SecurityProperties; +import cn.iocoder.yudao.framework.security.core.LoginUser; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Repository; import javax.annotation.Resource; -import java.time.Duration; -import static cn.iocoder.yudao.adminserver.modules.system.dal.redis.SysRedisKeyConstants.LOGIN_USER; +import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.LOGIN_USER; /** * {@link LoginUser} 的 RedisDAO @@ -17,12 +16,13 @@ import static cn.iocoder.yudao.adminserver.modules.system.dal.redis.SysRedisKeyC * @author 芋道源码 */ @Repository -public class SysLoginUserRedisDAO { +public class SysLoginUserCoreRedisDAO { @Resource private StringRedisTemplate stringRedisTemplate; + @Resource - private SysUserSessionService sysUserSessionService; // TODO 芋艿:得看看怎么拿出去 + private SecurityProperties securityProperties; public LoginUser get(String sessionId) { String redisKey = formatKey(sessionId); @@ -32,7 +32,7 @@ public class SysLoginUserRedisDAO { public void set(String sessionId, LoginUser loginUser) { String redisKey = formatKey(sessionId); stringRedisTemplate.opsForValue().set(redisKey, JsonUtils.toJsonString(loginUser), - Duration.ofMillis(sysUserSessionService.getSessionTimeoutMillis())); + securityProperties.getSessionTimeout()); } public void delete(String sessionId) { diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java new file mode 100644 index 000000000..3c1fc87ef --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.coreservice.modules.system.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * System 错误码枚举类 + * + * system 系统,使用 1-006-000-000 段 + */ +public interface SysErrorCodeConstants { + + // ========== 短信发送 1006000000 ========== + ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1006000000, "手机号不存在"); + ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失"); + ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在"); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/common/SysSexEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/common/SysSexEnum.java similarity index 83% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/common/SysSexEnum.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/common/SysSexEnum.java index f5f55e7dd..a7b0a9c29 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/common/SysSexEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/common/SysSexEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.enums.common; +package cn.iocoder.yudao.coreservice.modules.system.enums.common; import lombok.AllArgsConstructor; import lombok.Getter; @@ -11,12 +11,14 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum SysSexEnum { + /** 男 */ MALE(1), /** 女 */ FEMALE(2), /* 未知 */ UNKNOWN(3); + /** * 性别 */ diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginLogTypeEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginLogTypeEnum.java new file mode 100644 index 000000000..5a844f181 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginLogTypeEnum.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.coreservice.modules.system.enums.logger; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 登录日志的类型枚举 + */ +@Getter +@AllArgsConstructor +public enum SysLoginLogTypeEnum { + + LOGIN_USERNAME(100), // 使用账号登录 + LOGIN_SOCIAL(101), // 使用社交登录 + LOGIN_MOCK(102), // 使用 Mock 登录 + LOGIN_MOBILE(103), // 使用手机登陆 + LOGIN_SMS(104), // 使用短信登陆 + + LOGOUT_SELF(200), // 自己主动登出 + LOGOUT_TIMEOUT(201), // 超时登出 + LOGOUT_DELETE(202), // 强制退出 + ; + + /** + * 日志类型 + */ + private final Integer type; + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginResultEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginResultEnum.java new file mode 100644 index 000000000..290931038 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginResultEnum.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.coreservice.modules.system.enums.logger; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 登录结果的枚举类 + */ +@Getter +@AllArgsConstructor +public enum SysLoginResultEnum { + + SUCCESS(0), // 成功 + BAD_CREDENTIALS(10), // 账号或密码不正确 + USER_DISABLED(20), // 用户被禁用 + CAPTCHA_NOT_FOUND(30), // 图片验证码不存在 + CAPTCHA_CODE_ERROR(31), // 图片验证码不正确 + + UNKNOWN_ERROR(100), // 未知异常 + ; + + /** + * 结果 + */ + private final Integer result; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsReceiveStatusEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsReceiveStatusEnum.java similarity index 84% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsReceiveStatusEnum.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsReceiveStatusEnum.java index 54b6d4d78..48fd0c84c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsReceiveStatusEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsReceiveStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.enums.sms; +package cn.iocoder.yudao.coreservice.modules.system.enums.sms; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsSendStatusEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsSendStatusEnum.java similarity index 85% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsSendStatusEnum.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsSendStatusEnum.java index de8ed505c..f30e61301 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsSendStatusEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsSendStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.enums.sms; +package cn.iocoder.yudao.coreservice.modules.system.enums.sms; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsTemplateTypeEnum.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsTemplateTypeEnum.java similarity index 84% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsTemplateTypeEnum.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsTemplateTypeEnum.java index 779e79950..b3811e5ec 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsTemplateTypeEnum.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsTemplateTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.enums.sms; +package cn.iocoder.yudao.coreservice.modules.system.enums.sms; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/package-info.java new file mode 100644 index 000000000..2e18f1adf --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.yudao.coreservice.modules.system.mq.message; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/message/sms/SysSmsSendMessage.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/sms/SysSmsSendMessage.java similarity index 94% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/message/sms/SysSmsSendMessage.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/sms/SysSmsSendMessage.java index 34ebf9101..db4d1140c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/message/sms/SysSmsSendMessage.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/sms/SysSmsSendMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.system.mq.message.sms; +package cn.iocoder.yudao.coreservice.modules.system.mq.message.sms; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.mq.core.stream.StreamMessage; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/package-info.java new file mode 100644 index 000000000..2fe4aa305 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.yudao.coreservice.modules.system.mq.producer; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/sms/SysSmsCoreProducer.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/sms/SysSmsCoreProducer.java new file mode 100644 index 000000000..bd4d7c36a --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/sms/SysSmsCoreProducer.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms; + +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * Sms 短信相关消息的 Core Producer + * + * @author zzf + * @date 2021/3/9 16:35 + */ +@Slf4j +@Component +public class SysSmsCoreProducer { + + @Resource + private StringRedisTemplate stringRedisTemplate; + + /** + * 发送 {@link SysSmsSendMessage} 消息 + * + * @param logId 短信日志编号 + * @param mobile 手机号 + * @param channelId 渠道编号 + * @param apiTemplateId 短信模板编号 + * @param templateParams 短信模板参数 + */ + public void sendSmsSendMessage(Long logId, String mobile, + Long channelId, String apiTemplateId, List> templateParams) { + SysSmsSendMessage message = new SysSmsSendMessage().setLogId(logId).setMobile(mobile); + message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams); + RedisMessageUtils.sendStreamMessage(stringRedisTemplate, message); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/package-info.java new file mode 100644 index 000000000..3b8777935 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/package-info.java @@ -0,0 +1,7 @@ +/** + * system 包下,我们放通用业务,支撑上层的核心业务。 + * 例如说:用户、部门、权限、数据字典等等 + * + * 缩写:sys + */ +package cn.iocoder.yudao.coreservice.modules.system; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreService.java new file mode 100644 index 000000000..5106af7a3 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreService.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.auth; + +import cn.iocoder.yudao.framework.security.core.LoginUser; + +/** + * 在线用户 Session Core Service 接口 + * + * @author 芋道源码 + */ +public interface SysUserSessionCoreService { + + /** + * 创建在线用户 Session + * + * @param loginUser 登录用户 + * @param userIp 用户 IP + * @param userAgent 用户 UA + * @return Session 编号 + */ + String createUserSession(LoginUser loginUser, String userIp, String userAgent); + + /** + * 刷新在线用户 Session 的更新时间 + * + * @param sessionId Session 编号 + * @param loginUser 登录用户 + */ + void refreshUserSession(String sessionId, LoginUser loginUser); + + /** + * 删除在线用户 Session + * + * @param sessionId Session 编号 + */ + void deleteUserSession(String sessionId); + + /** + * 获得 Session 编号对应的在线用户 + * + * @param sessionId Session 编号 + * @return 在线用户 + */ + LoginUser getLoginUser(String sessionId); + + /** + * 获得 Session 超时时间,单位:毫秒 + * + * @return 超时时间 + */ + Long getSessionTimeoutMillis(); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/impl/SysUserSessionCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/impl/SysUserSessionCoreServiceImpl.java new file mode 100644 index 000000000..f26c6afc3 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/impl/SysUserSessionCoreServiceImpl.java @@ -0,0 +1,93 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.auth.impl; + +import cn.hutool.core.util.IdUtil; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth.SysUserSessionCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; +import cn.iocoder.yudao.framework.security.config.SecurityProperties; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.Duration; +import java.util.Date; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; + +/** + * 在线用户 Session Core Service 实现类 + * + * @author 芋道源码 + */ +@Service +public class SysUserSessionCoreServiceImpl implements SysUserSessionCoreService { + + @Resource + private SysUserSessionCoreMapper userSessionCoreMapper; + + @Resource + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; + + @Resource + private SecurityProperties securityProperties; + + @Override + public String createUserSession(LoginUser loginUser, String userIp, String userAgent) { + // 生成 Session 编号 + String sessionId = generateSessionId(); + // 写入 Redis 缓存 + loginUser.setUpdateTime(new Date()); + loginUserCoreRedisDAO.set(sessionId, loginUser); + // 写入 DB 中 + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) + .userId(loginUser.getId()).userType(loginUser.getUserType()) + .userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) + .sessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))) + .build(); + userSessionCoreMapper.insert(userSession); + // 返回 Session 编号 + return sessionId; + } + + @Override + public void refreshUserSession(String sessionId, LoginUser loginUser) { + // 写入 Redis 缓存 + loginUser.setUpdateTime(new Date()); + loginUserCoreRedisDAO.set(sessionId, loginUser); + // 更新 DB 中 + SysUserSessionDO updateObj = SysUserSessionDO.builder().id(sessionId).build(); + updateObj.setUsername(loginUser.getUsername()); + updateObj.setUpdateTime(new Date()); + updateObj.setSessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))); + userSessionCoreMapper.updateById(updateObj); + } + + @Override + public void deleteUserSession(String sessionId) { + // 删除 Redis 缓存 + loginUserCoreRedisDAO.delete(sessionId); + // 删除 DB 记录 + userSessionCoreMapper.deleteById(sessionId); + } + + @Override + public LoginUser getLoginUser(String sessionId) { + return loginUserCoreRedisDAO.get(sessionId); + } + + @Override + public Long getSessionTimeoutMillis() { + return securityProperties.getSessionTimeout().toMillis(); + } + + /** + * 生成 Session 编号,目前采用 UUID 算法 + * + * @return Session 编号 + */ + private static String generateSessionId() { + return IdUtil.fastSimpleUUID(); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/SysDictDataService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreService.java similarity index 56% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/SysDictDataService.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreService.java index 6bdab683c..d88695621 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/SysDictDataService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreService.java @@ -1,13 +1,13 @@ -package cn.iocoder.yudao.userserver.modules.system.service.dict; +package cn.iocoder.yudao.coreservice.modules.system.service.dict; import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; /** * 字典数据 Service 接口 * - * @author ruoyi + * @author 芋道源码 */ -public interface SysDictDataService extends DictDataFrameworkService { +public interface SysDictDataCoreService extends DictDataFrameworkService { /** * 初始化字典数据的本地缓存 diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/impl/SysDictDataCoreServiceImpl.java similarity index 79% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/impl/SysDictDataCoreServiceImpl.java index 2fc230f9b..98607163d 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/impl/SysDictDataCoreServiceImpl.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.userserver.modules.system.service.dict.impl; +package cn.iocoder.yudao.coreservice.modules.system.service.dict.impl; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.coreservice.modules.system.convert.dict.SysDictDataCoreConvert; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict.SysDictDataCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.service.dict.SysDictDataCoreService; import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.userserver.modules.system.convert.dict.SysDictDataConvert; -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; -import cn.iocoder.yudao.userserver.modules.system.dal.mysql.dict.SysDictDataMapper; -import cn.iocoder.yudao.userserver.modules.system.service.dict.SysDictDataService; import com.google.common.collect.ImmutableTable; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; @@ -21,11 +21,11 @@ import java.util.List; /** * 字典数据 Service 实现类 * - * @author ruoyi + * @author 芋道源码 */ @Service @Slf4j -public class SysDictDataServiceImpl implements SysDictDataService { +public class SysDictDataCoreServiceImpl implements SysDictDataCoreService { /** * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 @@ -53,7 +53,7 @@ public class SysDictDataServiceImpl implements SysDictDataService { private volatile Date maxUpdateTime; @Resource - private SysDictDataMapper dictDataMapper; + private SysDictDataCoreMapper dictDataCoreMapper; @Override @PostConstruct @@ -95,28 +95,28 @@ public class SysDictDataServiceImpl implements SysDictDataService { if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 log.info("[loadDictDataIfUpdate][首次加载全量字典数据]"); } else { // 判断数据库中是否有更新的字典数据 - if (!dictDataMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { + if (!dictDataCoreMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { return null; } log.info("[loadDictDataIfUpdate][增量加载全量字典数据]"); } // 第二步,如果有更新,则从数据库加载所有字典数据 - return dictDataMapper.selectList(); + return dictDataCoreMapper.selectList(); } @Override public DictDataRespDTO getDictDataFromCache(String type, String value) { - return SysDictDataConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); + return SysDictDataCoreConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); } @Override public DictDataRespDTO parseDictDataFromCache(String type, String label) { - return SysDictDataConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); + return SysDictDataCoreConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); } @Override public List listDictDatasFromCache(String type) { - return SysDictDataConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); + return SysDictDataCoreConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); } } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogCoreService.java new file mode 100644 index 000000000..decc2739e --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogCoreService.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.logger; + +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; + +/** + * 登录日志 Core Service 接口 + */ +public interface SysLoginLogCoreService { + + /** + * 创建登录日志 + * + * @param reqDTO 日志信息 + */ + void createLoginLog(SysLoginLogCreateReqDTO reqDTO); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/dto/SysLoginLogCreateReqDTO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/dto/SysLoginLogCreateReqDTO.java new file mode 100644 index 000000000..4dddf9df8 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/dto/SysLoginLogCreateReqDTO.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.logger.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 登录日志创建 Request DTO + * + * @author 芋道源码 + */ +@Data +public class SysLoginLogCreateReqDTO { + + /** + * 日志类型 + */ + @NotNull(message = "日志类型不能为空") + private Integer logType; + /** + * 链路追踪编号 + */ + @NotEmpty(message = "链路追踪编号不能为空") + private String traceId; + + /** + * 用户编号 + */ + private Long userId; + /** + * 用户类型 + */ + @NotNull(message = "用户类型不能为空") + private Integer userType; + /** + * 用户账号 + */ + @NotBlank(message = "用户账号不能为空") + @Size(max = 30, message = "用户账号长度不能超过30个字符") + private String username; + + /** + * 登录结果 + */ + @NotNull(message = "登录结果不能为空") + private Integer result; + + /** + * 用户 IP + */ + @NotEmpty(message = "用户 IP 不能为空") + private String userIp; + /** + * 浏览器 UserAgent + */ + @NotEmpty(message = "浏览器 UserAgent 不能为空") + private String userAgent; + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/impl/SysLoginLogCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/impl/SysLoginLogCoreServiceImpl.java new file mode 100644 index 000000000..7c866e8d6 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/impl/SysLoginLogCoreServiceImpl.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.logger.impl; + +import cn.iocoder.yudao.coreservice.modules.system.convert.logger.SysLoginLogCoreConvert; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger.SysLoginLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 登录日志 Service Core 实现 + * + * @author 芋道源码 + */ +@Service +public class SysLoginLogCoreServiceImpl implements SysLoginLogCoreService { + + @Resource + private SysLoginLogCoreMapper loginLogMapper; + + @Override + public void createLoginLog(SysLoginLogCreateReqDTO reqDTO) { + SysLoginLogDO loginLog = SysLoginLogCoreConvert.INSTANCE.convert(reqDTO); + // 插入 + loginLogMapper.insert(loginLog); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreService.java similarity index 73% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsService.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreService.java index 70d32c127..55f4d41e0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsService.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreService.java @@ -1,21 +1,22 @@ -package cn.iocoder.yudao.adminserver.modules.system.service.sms; +package cn.iocoder.yudao.coreservice.modules.system.service.sms; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; import java.util.List; import java.util.Map; /** - * 短信Service接口 - * 只支持异步,因此没有返回值 + * 短信 Service Core 接口 * - * @author zzf - * @date 2021/1/25 9:24 + * 接入方,通过调用 send 开头的方法,创建发送短信的任务到 MQ 中 + * 后续,yudao-admin-server 监听 MQ,执行真正的短信发送逻辑 + * + * @author 芋道源码 */ -public interface SysSmsService { +public interface SysSmsCoreService { /** - * 发送单条短信给用户(管理员) + * 发送单条短信给后台用户 * * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 * @@ -29,7 +30,7 @@ public interface SysSmsService { String templateCode, Map templateParams); /** - * 发送单条短信给用户(会员) + * 发送单条短信给前台用户 * * 在 mobile 为空时,使用 userId 加载对应会员的手机号 * @@ -40,7 +41,7 @@ public interface SysSmsService { * @return 发送日志编号 */ Long sendSingleSmsToMember(String mobile, Long userId, - String templateCode, Map templateParams); + String templateCode, Map templateParams); Long sendSingleSms(String mobile, Long userId, Integer userType, String templateCode, Map templateParams); diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreService.java new file mode 100644 index 000000000..02a8c2696 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreService.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; + +import java.util.Date; +import java.util.Map; + +/** + * 短信日志 Core Service 接口 + * + * @author zzf + * @date 13:48 2021/3/2 + */ +public interface SysSmsLogCoreService { + + /** + * 创建短信日志 + * + * @param mobile 手机号 + * @param userId 用户编号 + * @param userType 用户类型 + * @param isSend 是否发送 + * @param template 短信模板 + * @param templateContent 短信内容 + * @param templateParams 短信参数 + * @return 发送日志编号 + */ + Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, + SysSmsTemplateDO template, String templateContent, Map templateParams); + + /** + * 更新日志的发送结果 + * + * @param id 日志编号 + * @param sendCode 发送结果的编码 + * @param sendMsg 发送结果的提示 + * @param apiSendCode 短信 API 发送结果的编码 + * @param apiSendMsg 短信 API 发送失败的提示 + * @param apiRequestId 短信 API 发送返回的唯一请求 ID + * @param apiSerialNo 短信 API 发送返回的序号 + */ + void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, + String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo); + + /** + * 更新日志的接收结果 + * + * @param id 日志编号 + * @param success 是否接收成功 + * @param receiveTime 用户接收时间 + * @param apiReceiveCode API 接收结果的编码 + * @param apiReceiveMsg API 接收结果的说明 + */ + void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateCoreService.java new file mode 100644 index 000000000..9a3a16099 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateCoreService.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; + +import java.util.Map; + +/** + * 短信模板 Core Service 接口 + * + * @author 芋道源码 + */ +public interface SysSmsTemplateCoreService { + + /** + * 初始化短信模板的本地缓存 + */ + void initLocalCache(); + + /** + * 获得短信模板,从缓存中 + * + * @param code 模板编码 + * @return 短信模板 + */ + SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code); + + /** + * 格式化短信内容 + * + * @param content 短信模板的内容 + * @param params 内容的参数 + * @return 格式化后的内容 + */ + String formatSmsTemplateContent(String content, Map params); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java similarity index 67% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsServiceImpl.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java index 9fced9b8f..3893ba340 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsServiceImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java @@ -1,7 +1,17 @@ -package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms.SysSmsCoreProducer; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; @@ -10,16 +20,7 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; -import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import com.google.common.annotations.VisibleForTesting; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.Assert; @@ -28,36 +29,37 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; /** - * 短信日志Service实现类 + * 短信 Service Core 实现 * - * @author zzf - * @date 2021/1/25 9:25 + * @author 芋道源码 */ @Service -@Slf4j -public class SysSmsServiceImpl implements SysSmsService { +public class SysSmsCoreServiceImpl implements SysSmsCoreService { @Resource - private SysSmsTemplateService smsTemplateService; + private SysUserCoreService sysUserCoreService; @Resource - private SysSmsLogService smsLogService; + private MbrUserCoreService mbrUserCoreService; @Resource - private SysSmsProducer smsProducer; + private SysSmsTemplateCoreService smsTemplateCoreService; + @Resource + private SysSmsLogCoreService smsLogCoreService; + @Resource private SmsClientFactory smsClientFactory; @Resource - private SysUserService userService; + private SysSmsCoreProducer smsCoreProducer; @Override public Long sendSingleSmsToAdmin(String mobile, Long userId, String templateCode, Map templateParams) { // 如果 mobile 为空,则加载用户编号对应的手机号 if (StrUtil.isEmpty(mobile)) { - SysUserDO user = userService.getUser(userId); + SysUserDO user = sysUserCoreService.getUser(userId); if (user != null) { mobile = user.getMobile(); } @@ -68,7 +70,15 @@ public class SysSmsServiceImpl implements SysSmsService { @Override public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map templateParams) { - throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!"); + // 如果 mobile 为空,则加载用户编号对应的手机号 + if (StrUtil.isEmpty(mobile)) { + MbrUserDO user = mbrUserCoreService.getUser(userId); + if (user != null) { + mobile = user.getMobile(); + } + } + // 执行发送 + return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); } @Override @@ -83,12 +93,13 @@ public class SysSmsServiceImpl implements SysSmsService { // 创建发送日志 Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); // 如果模板被禁用,则不发送短信,只记录日志 - String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams); - Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); + String content = smsTemplateCoreService.formatSmsTemplateContent(template.getContent(), templateParams); + Long sendLogId = smsLogCoreService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); // 发送 MQ 消息,异步执行发送短信 if (isSend) { - smsProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), template.getApiTemplateId(), newTemplateParams); + smsCoreProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), + template.getApiTemplateId(), newTemplateParams); } return sendLogId; } @@ -102,10 +113,10 @@ public class SysSmsServiceImpl implements SysSmsService { @VisibleForTesting public SysSmsTemplateDO checkSmsTemplateValid(String templateCode) { // 获得短信模板。考虑到效率,从缓存中获取 - SysSmsTemplateDO template = smsTemplateService.getSmsTemplateByCodeFromCache(templateCode); + SysSmsTemplateDO template = smsTemplateCoreService.getSmsTemplateByCodeFromCache(templateCode); // 短信模板不存在 if (template == null) { - throw exception(SMS_TEMPLATE_NOT_EXISTS); + throw exception(SMS_SEND_TEMPLATE_NOT_EXISTS); } return template; } @@ -138,6 +149,7 @@ public class SysSmsServiceImpl implements SysSmsService { return mobile; } + @Override public void doSendSms(SysSmsSendMessage message) { // 获得渠道对应的 SmsClient 客户端 @@ -146,7 +158,7 @@ public class SysSmsServiceImpl implements SysSmsService { // 发送短信 SmsCommonResult sendResult = smsClient.sendSms(message.getLogId(), message.getMobile(), message.getApiTemplateId(), message.getTemplateParams()); - smsLogService.updateSmsSendResult(message.getLogId(), sendResult.getCode(), sendResult.getMsg(), + smsLogCoreService.updateSmsSendResult(message.getLogId(), sendResult.getCode(), sendResult.getMsg(), sendResult.getApiCode(), sendResult.getApiMsg(), sendResult.getApiRequestId(), sendResult.getData() != null ? sendResult.getData().getSerialNo() : null); } @@ -161,11 +173,9 @@ public class SysSmsServiceImpl implements SysSmsService { if (CollUtil.isEmpty(receiveResults)) { return; } - // 更新短信日志的接收结果. 因为量一般不打,所以先使用 for 循环更新 - receiveResults.forEach(result -> { - smsLogService.updateSmsReceiveResult(result.getLogId(), result.getSuccess(), result.getReceiveTime(), - result.getErrorCode(), result.getErrorCode()); - }); + // 更新短信日志的接收结果. 因为量一般不大,所以先使用 for 循环更新 + receiveResults.forEach(result -> smsLogCoreService.updateSmsReceiveResult(result.getLogId(), + result.getSuccess(), result.getReceiveTime(), result.getErrorCode(), result.getErrorCode())); } } diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsLogCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsLogCoreServiceImpl.java new file mode 100644 index 000000000..de318ed62 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsLogCoreServiceImpl.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsLogCoreService; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Map; +import java.util.Objects; + +/** + * 短信日志 Core Service 实现类 + * + * @author zzf + * @date 2021/1/25 9:25 + */ +@Slf4j +@Service +public class SysSmsLogCoreServiceImpl implements SysSmsLogCoreService { + + @Resource + private SysSmsLogCoreMapper smsLogCoreMapper; + + @Override + public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, + SysSmsTemplateDO template, String templateContent, Map templateParams) { + SysSmsLogDO.SysSmsLogDOBuilder logBuilder = SysSmsLogDO.builder(); + // 根据是否要发送,设置状态 + logBuilder.sendStatus(Objects.equals(isSend, true) ? SysSmsSendStatusEnum.INIT.getStatus() + : SysSmsSendStatusEnum.IGNORE.getStatus()); + // 设置手机相关字段 + logBuilder.mobile(mobile).userId(userId).userType(userType); + // 设置模板相关字段 + logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); + logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId()); + // 设置渠道相关字段 + logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); + // 设置接收相关字段 + logBuilder.receiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus()); + + // 插入数据库 + SysSmsLogDO logDO = logBuilder.build(); + smsLogCoreMapper.insert(logDO); + return logDO.getId(); + } + + @Override + public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, + String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) { + SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS + : SysSmsSendStatusEnum.FAILURE; + smsLogCoreMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date()) + .sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg) + .apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build()); + } + + @Override + public void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg) { + SysSmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? SysSmsReceiveStatusEnum.SUCCESS + : SysSmsReceiveStatusEnum.FAILURE; + smsLogCoreMapper.updateById(SysSmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()).receiveTime(receiveTime) + .apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build()); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsTemplateCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsTemplateCoreServiceImpl.java new file mode 100644 index 000000000..aa1a28b38 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsTemplateCoreServiceImpl.java @@ -0,0 +1,105 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsTemplateCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.google.common.collect.ImmutableMap; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 短信模板 Core Service 接口 + * + * @author 芋道源码 + */ +@Service +@Slf4j +public class SysSmsTemplateCoreServiceImpl implements SysSmsTemplateCoreService { + + /** + * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 + * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 + */ + private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; + + /** + * 短信模板缓存 + * key:短信模板编码 {@link SysSmsTemplateDO#getCode()} + * + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 + */ + private volatile Map smsTemplateCache; + /** + * 缓存短信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 + */ + private volatile Date maxUpdateTime; + + @Resource + private SysSmsTemplateCoreMapper smsTemplateCoreMapper; + + @Override + @PostConstruct + public void initLocalCache() { + // 获取短信模板列表,如果有更新 + List smsTemplateList = this.loadSmsTemplateIfUpdate(maxUpdateTime); + if (CollUtil.isEmpty(smsTemplateList)) { + return; + } + + // 写入缓存 + ImmutableMap.Builder builder = ImmutableMap.builder(); + smsTemplateList.forEach(sysSmsTemplateDO -> builder.put(sysSmsTemplateDO.getCode(), sysSmsTemplateDO)); + smsTemplateCache = builder.build(); + assert smsTemplateList.size() > 0; // 断言,避免告警 + maxUpdateTime = smsTemplateList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); + log.info("[initLocalCache][初始化 SmsTemplate 数量为 {}]", smsTemplateList.size()); + } + + /** + * 如果短信模板发生变化,从数据库中获取最新的全量短信模板。 + * 如果未发生变化,则返回空 + * + * @param maxUpdateTime 当前短信模板的最大更新时间 + * @return 短信模板列表 + */ + private List loadSmsTemplateIfUpdate(Date maxUpdateTime) { + // 第一步,判断是否要更新。 + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 + log.info("[loadSmsTemplateIfUpdate][首次加载全量短信模板]"); + } else { // 判断数据库中是否有更新的短信模板 + if (smsTemplateCoreMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) { + return null; + } + log.info("[loadSmsTemplateIfUpdate][增量加载全量短信模板]"); + } + // 第二步,如果有更新,则从数据库加载所有短信模板 + return smsTemplateCoreMapper.selectList(); + } + + @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) + public void schedulePeriodicRefresh() { + initLocalCache(); + } + + @Override + public SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code) { + return smsTemplateCache.get(code); + } + + @Override + public String formatSmsTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/SysUserCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/SysUserCoreService.java new file mode 100644 index 000000000..bc95e343e --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/SysUserCoreService.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.user; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; + +/** + * 后台用户 Service Core 接口 + * + * @author 芋道源码 + */ +public interface SysUserCoreService { + + /** + * 通过用户 ID 查询用户 + * + * @param id 用户ID + * @return 用户对象信息 + */ + SysUserDO getUser(Long id); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/impl/SysUserCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/impl/SysUserCoreServiceImpl.java new file mode 100644 index 000000000..ff203bdc4 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/impl/SysUserCoreServiceImpl.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.user.impl; + +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.user.SysUserCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 后台用户 Service Core 实现 + * + * @author 芋道源码 + */ +@Service +public class SysUserCoreServiceImpl implements SysUserCoreService { + + @Resource + private SysUserCoreMapper userCoreMapper; + + @Override + public SysUserDO getUser(Long id) { + return userCoreMapper.selectById(id); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/tool/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/tool/package-info.java new file mode 100644 index 000000000..dd3c3e913 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/tool/package-info.java @@ -0,0 +1,7 @@ +/** + * tool 包下,我们放研发工具,提升研发效率与质量。 + * 例如说:代码生成器、接口文档等等 + * + * 缩写:tool + */ +package cn.iocoder.yudao.coreservice.modules.tool; diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbAndRedisUnitTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbAndRedisUnitTest.java new file mode 100644 index 000000000..8b9177cf5 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbAndRedisUnitTest.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.coreservice; + +import cn.iocoder.yudao.coreservice.config.RedisTestConfiguration; +import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; +import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; +import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; +import org.redisson.spring.starter.RedissonAutoConfiguration; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; + +/** + * 依赖内存 DB + Redis 的单元测试 + * + * 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis + * + * @author 芋道源码 + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisUnitTest.Application.class) +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 +@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB +public class BaseDbAndRedisUnitTest { + + @Import({ + // DB 配置类 + YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类 + DataSourceAutoConfiguration.class, // Spring DB 自动配置类 + DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类 + DruidDataSourceAutoConfigure.class, // Druid 自动配置类 + // MyBatis 配置类 + YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类 + MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 + // Redis 配置类 + RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer + RedisAutoConfiguration.class, // Spring Redis 自动配置类 + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 + RedissonAutoConfiguration.class, // Redisson 自动高配置类 + }) + public static class Application { + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbUnitTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbUnitTest.java new file mode 100644 index 000000000..94d6d3107 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbUnitTest.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.coreservice; + +import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; +import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; + +/** + * 依赖内存 DB 的单元测试 + * + * 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法 + * + * @author 芋道源码 + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbUnitTest.Application.class) +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 +@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB +public class BaseDbUnitTest { + + @Import({ + // DB 配置类 + YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类 + DataSourceAutoConfiguration.class, // Spring DB 自动配置类 + DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类 + DruidDataSourceAutoConfigure.class, // Druid 自动配置类 + // MyBatis 配置类 + YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类 + MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 + }) + public static class Application { + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseRedisUnitTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseRedisUnitTest.java new file mode 100644 index 000000000..e95e6d787 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseRedisUnitTest.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.coreservice; + +import cn.iocoder.yudao.coreservice.config.RedisTestConfiguration; +import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; +import org.redisson.spring.starter.RedissonAutoConfiguration; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +/** + * 依赖内存 Redis 的单元测试 + * + * 相比 {@link BaseDbUnitTest} 来说,从内存 DB 改成了内存 Redis + * + * @author 芋道源码 + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisUnitTest.Application.class) +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 +public class BaseRedisUnitTest { + + @Import({ + // Redis 配置类 + RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer + RedisAutoConfiguration.class, // Spring Redis 自动配置类 + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 + RedissonAutoConfiguration.class, // Redisson 自动高配置类 + }) + public static class Application { + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/config/RedisTestConfiguration.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/config/RedisTestConfiguration.java new file mode 100644 index 000000000..eb0791974 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/config/RedisTestConfiguration.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.coreservice.config; + +import com.github.fppt.jedismock.RedisServer; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +import java.io.IOException; + +@Configuration(proxyBeanMethods = false) +@Lazy(false) // 禁止延迟加载 +@EnableConfigurationProperties(RedisProperties.class) +public class RedisTestConfiguration { + + /** + * 创建模拟的 Redis Server 服务器 + */ + @Bean + public RedisServer redisServer(RedisProperties properties) throws IOException { + RedisServer redisServer = new RedisServer(properties.getPort()); + // TODO 芋艿:一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样,就导致端口被占用,无法启动。。。 + try { + redisServer.start(); + } catch (Exception ignore) {} + return redisServer; + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreServiceTest.java new file mode 100644 index 000000000..b634cc3c2 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreServiceTest.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; + +import cn.hutool.core.util.RandomUtil; +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiAccessLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl.InfApiAccessLogCoreServiceImpl; +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.concurrent.Future; + +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * {@link InfApiAccessLogCoreServiceImpl} 单元测试 + */ +@Import(InfApiAccessLogCoreServiceImpl.class) +public class InfApiAccessLogCoreServiceTest extends BaseDbUnitTest { + + @Resource + private InfApiAccessLogCoreService apiAccessLogCoreService; + + @Resource + private InfApiAccessLogCoreMapper apiAccessLogCoreMapper; + + @Test + public void testCreateApiAccessLogAsync() { + // 准备参数 + ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(ApiAccessLogCreateDTO.class, + dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())); + + // 调用 + apiAccessLogCoreService.createApiAccessLogAsync(createDTO); + // 断言 + InfApiAccessLogDO infApiAccessLogDO = apiAccessLogCoreMapper.selectOne(null); + assertNotNull(infApiAccessLogDO); + assertPojoEquals(createDTO, infApiAccessLogDO); + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreServiceTest.java new file mode 100644 index 000000000..5ca6449a1 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreServiceTest.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; + +import cn.hutool.core.util.RandomUtil; +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiErrorLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl.InfApiErrorLogCoreServiceImpl; +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * {@link InfApiErrorLogCoreServiceImpl} 单元测试 + */ +@Import(InfApiErrorLogCoreServiceImpl.class) +public class InfApiErrorLogCoreServiceTest extends BaseDbUnitTest { + + @Resource + private InfApiErrorLogCoreService apiErrorLogCoreService; + + @Resource + private InfApiErrorLogCoreMapper infApiErrorLogCoreMapper; + + @Test + public void testCreateApiErrorLogAsync() { + // 准备参数 + ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo(ApiErrorLogCreateDTO.class, + dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())); + + // 调用 + apiErrorLogCoreService.createApiErrorLogAsync(createDTO); + // 断言 + InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogCoreMapper.selectOne(null); + assertNotNull(infApiErrorLogDO); + assertPojoEquals(createDTO, infApiErrorLogDO); + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/package-info.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/package-info.java new file mode 100644 index 000000000..c3da3526c --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.coreservice.modules.infra.service; diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreServiceTest.java new file mode 100644 index 000000000..0dd0c1a0c --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreServiceTest.java @@ -0,0 +1,122 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.auth; + +import cn.iocoder.yudao.coreservice.BaseDbAndRedisUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth.SysUserSessionCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.impl.SysUserSessionCoreServiceImpl; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.security.config.SecurityProperties; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.time.Duration; +import java.util.Date; + +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; + +@Import({SysUserSessionCoreServiceImpl.class, SysLoginUserCoreRedisDAO.class}) +public class SysUserSessionCoreServiceTest extends BaseDbAndRedisUnitTest { + + @Resource + private SysUserSessionCoreServiceImpl userSessionCoreService; + + @Resource + private SysUserSessionCoreMapper userSessionCoreMapper; + @Resource + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; + + @MockBean + private SecurityProperties securityProperties; + + @Test + public void testCreateUserSession_success() { + // 准备参数 + String userIp = randomString(); + String userAgent = randomString(); + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); + // mock 方法 + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); + + // 调用 + String sessionId = userSessionCoreService.createUserSession(loginUser, userIp, userAgent); + // 校验 SysUserSessionDO 记录 + SysUserSessionDO userSessionDO = userSessionCoreMapper.selectById(sessionId); + assertPojoEquals(loginUser, userSessionDO, "id", "updateTime"); + assertEquals(sessionId, userSessionDO.getId()); + assertEquals(userIp, userSessionDO.getUserIp()); + assertEquals(userAgent, userSessionDO.getUserAgent()); + // 校验 LoginUser 缓存 + LoginUser redisLoginUser = loginUserCoreRedisDAO.get(sessionId); + assertPojoEquals(loginUser, redisLoginUser, "username", "password"); + } + + @Test + public void testCreateRefreshUserSession_success() { + // 准备参数 + String sessionId = randomString(); + String userIp = randomString(); + String userAgent = randomString(); + long timeLong = randomLongId(); + String userName = randomString(); + Date date = randomDate(); + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); + // mock 方法 + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); + // mock 数据 + loginUser.setUpdateTime(date); + loginUserCoreRedisDAO.set(sessionId, loginUser); + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) + .userId(loginUser.getId()).userType(loginUser.getUserType()) + .userIp(userIp).userAgent(userAgent).username(userName) + .sessionTimeout(addTime(Duration.ofMillis(timeLong))) + .build(); + userSessionCoreMapper.insert(userSession); + + // 调用 + userSessionCoreService.refreshUserSession(sessionId, loginUser); + // 校验 LoginUser 缓存 + LoginUser redisLoginUser = loginUserCoreRedisDAO.get(sessionId); + assertNotEquals(redisLoginUser.getUpdateTime(), date); + // 校验 SysUserSessionDO 记录 + SysUserSessionDO updateDO = userSessionCoreMapper.selectById(sessionId); + assertEquals(updateDO.getUsername(), loginUser.getUsername()); + assertNotEquals(updateDO.getUpdateTime(), userSession.getUpdateTime()); + assertNotEquals(updateDO.getSessionTimeout(), addTime(Duration.ofMillis(timeLong))); + } + + @Test + public void testDeleteUserSession_success() { + // 准备参数 + String sessionId = randomString(); + String userIp = randomString(); + String userAgent = randomString(); + Long timeLong = randomLongId(); + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); + // mock 存入 Redis + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); + // mock 数据 + loginUserCoreRedisDAO.set(sessionId, loginUser); + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) + .userId(loginUser.getId()).userType(loginUser.getUserType()) + .userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) + .sessionTimeout(addTime(Duration.ofMillis(timeLong))) + .build(); + userSessionCoreMapper.insert(userSession); + + // 调用 + userSessionCoreService.deleteUserSession(sessionId); + // 校验数据不存在了 + assertNull(loginUserCoreRedisDAO.get(sessionId)); + assertNull(userSessionCoreMapper.selectById(sessionId)); + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreServiceTest.java new file mode 100644 index 000000000..410c592f5 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreServiceTest.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.dict; + +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict.SysDictDataCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.service.dict.impl.SysDictDataCoreServiceImpl; +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import com.google.common.collect.ImmutableTable; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.function.Consumer; + +import static cn.hutool.core.bean.BeanUtil.getFieldValue; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomCommonStatus; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** +* {@link SysDictDataCoreServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SysDictDataCoreServiceImpl.class) +public class SysDictDataCoreServiceTest extends BaseDbUnitTest { + + @Resource + private SysDictDataCoreServiceImpl dictDataCoreService; + + @Resource + private SysDictDataCoreMapper dictDataMapper; + + /** + * 测试加载到新的字典数据的情况 + */ + @Test + @SuppressWarnings("unchecked") + public void testInitLocalCache() { + // mock 数据 + SysDictDataDO dictData01 = randomDictDataDO(); + dictDataMapper.insert(dictData01); + SysDictDataDO dictData02 = randomDictDataDO(); + dictDataMapper.insert(dictData02); + + // 调用 + dictDataCoreService.initLocalCache(); + // 断言 labelDictDataCache 缓存 + ImmutableTable labelDictDataCache = + (ImmutableTable) getFieldValue(dictDataCoreService, "labelDictDataCache"); + assertEquals(2, labelDictDataCache.size()); + assertPojoEquals(dictData01, labelDictDataCache.get(dictData01.getDictType(), dictData01.getLabel())); + assertPojoEquals(dictData02, labelDictDataCache.get(dictData02.getDictType(), dictData02.getLabel())); + // 断言 valueDictDataCache 缓存 + ImmutableTable valueDictDataCache = + (ImmutableTable) getFieldValue(dictDataCoreService, "valueDictDataCache"); + assertEquals(2, valueDictDataCache.size()); + assertPojoEquals(dictData01, valueDictDataCache.get(dictData01.getDictType(), dictData01.getValue())); + assertPojoEquals(dictData02, valueDictDataCache.get(dictData02.getDictType(), dictData02.getValue())); + // 断言 maxUpdateTime 缓存 + Date maxUpdateTime = (Date) getFieldValue(dictDataCoreService, "maxUpdateTime"); + assertEquals(ObjectUtils.max(dictData01.getUpdateTime(), dictData02.getUpdateTime()), maxUpdateTime); + } + + // ========== 随机对象 ========== + + @SafeVarargs + private static SysDictDataDO randomDictDataDO(Consumer... consumers) { + Consumer consumer = (o) -> { + o.setStatus(randomCommonStatus()); // 保证 status 的范围 + }; + return randomPojo(SysDictDataDO.class, ArrayUtils.append(consumer, consumers)); + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogServiceImplTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogServiceImplTest.java new file mode 100644 index 000000000..1da56c264 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogServiceImplTest.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.logger; + +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger.SysLoginLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.impl.SysLoginLogCoreServiceImpl; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; + +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; + +@Import(SysLoginLogCoreServiceImpl.class) +public class SysLoginLogServiceImplTest extends BaseDbUnitTest { + + @Resource + private SysLoginLogCoreServiceImpl loginLogCoreService; + + @Resource + private SysLoginLogCoreMapper loginLogCoreMapper; + + @Test + public void testCreateLoginLog() { + SysLoginLogCreateReqDTO reqDTO = RandomUtils.randomPojo(SysLoginLogCreateReqDTO.class, vo -> { + // 指定随机的范围,避免超出范围入库失败 + vo.setUserType(randomEle(UserTypeEnum.values()).getValue()); + vo.setLogType(randomEle(SysLoginLogTypeEnum.values()).getType()); + vo.setResult(randomEle(SysLoginResultEnum.values()).getResult()); + vo.setTraceId(TracerUtils.getTraceId()); + }); + + // 调用 + loginLogCoreService.createLoginLog(reqDTO); + // 断言,忽略基本字段 + SysLoginLogDO sysLoginLogDO = loginLogCoreMapper.selectOne(null); + assertPojoEquals(reqDTO, sysLoginLogDO); + } + +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/package-info.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/package-info.java new file mode 100644 index 000000000..8b5f8b010 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.coreservice.modules.system.service; diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreServiceTest.java similarity index 71% rename from yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceTest.java rename to yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreServiceTest.java index 75b34afba..97e1e3703 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceTest.java +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreServiceTest.java @@ -1,6 +1,10 @@ -package cn.iocoder.yudao.adminserver.modules.system.service.sms; +package cn.iocoder.yudao.coreservice.modules.system.service.sms; import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; +import cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms.SysSmsCoreProducer; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsCoreServiceImpl; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; @@ -9,10 +13,6 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; -import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; -import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsServiceImpl; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import org.assertj.core.util.Lists; import org.junit.jupiter.api.Test; @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import static cn.hutool.core.util.RandomUtil.randomEle; -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -32,21 +32,21 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; /** - * {@link SysSmsServiceImpl} 的单元测试类 + * {@link SysSmsCoreService} 的单元测试类 * * @author 芋道源码 */ -public class SysSmsServiceTest extends BaseMockitoUnitTest { +public class SysSmsCoreServiceTest extends BaseMockitoUnitTest { @InjectMocks - private SysSmsServiceImpl smsService; + private SysSmsCoreServiceImpl smsCoreService; @Mock - private SysSmsTemplateService smsTemplateService; + private SysSmsTemplateCoreService smsTemplateCoreService; @Mock - private SysSmsLogService smsLogService; + private SysSmsLogCoreService smsLogCoreService; @Mock - private SysSmsProducer smsProducer; + private SysSmsCoreProducer smsCoreProducer; @Mock private SmsClientFactory smsClientFactory; @@ -68,21 +68,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { o.setContent("验证码为{code}, 操作为{op}"); o.setParams(Lists.newArrayList("code", "op")); }); - when(smsTemplateService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); + when(smsTemplateCoreService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); String content = randomString(); - when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) + when(smsTemplateCoreService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) .thenReturn(content); // mock SmsLogService 的方法 Long smsLogId = randomLongId(); - when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template), + when(smsLogCoreService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template), eq(content), eq(templateParams))).thenReturn(smsLogId); // 调用 - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); + Long resultSmsLogId = smsCoreService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); // 断言 assertEquals(smsLogId, resultSmsLogId); // 断言调用 - verify(smsProducer, times(1)).sendSmsSendMessage(eq(smsLogId), eq(mobile), + verify(smsCoreProducer, times(1)).sendSmsSendMessage(eq(smsLogId), eq(mobile), eq(template.getChannelId()), eq(template.getApiTemplateId()), eq(Lists.newArrayList(new KeyValue<>("code", "1234"), new KeyValue<>("op", "login")))); } @@ -105,21 +105,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { o.setContent("验证码为{code}, 操作为{op}"); o.setParams(Lists.newArrayList("code", "op")); }); - when(smsTemplateService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); + when(smsTemplateCoreService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); String content = randomString(); - when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) + when(smsTemplateCoreService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) .thenReturn(content); // mock SmsLogService 的方法 Long smsLogId = randomLongId(); - when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template), + when(smsLogCoreService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template), eq(content), eq(templateParams))).thenReturn(smsLogId); // 调用 - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); + Long resultSmsLogId = smsCoreService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); // 断言 assertEquals(smsLogId, resultSmsLogId); // 断言调用 - verify(smsProducer, times(0)).sendSmsSendMessage(anyLong(), anyString(), + verify(smsCoreProducer, times(0)).sendSmsSendMessage(anyLong(), anyString(), anyLong(), any(), anyList()); } @@ -130,8 +130,8 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { // mock 方法 // 调用,并断言异常 - assertServiceException(() -> smsService.checkSmsTemplateValid(templateCode), - SMS_TEMPLATE_NOT_EXISTS); + assertServiceException(() -> smsCoreService.checkSmsTemplateValid(templateCode), + SMS_SEND_TEMPLATE_NOT_EXISTS); } @Test @@ -143,7 +143,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { // mock 方法 // 调用,并断言异常 - assertServiceException(() -> smsService.buildTemplateParams(template, templateParams), + assertServiceException(() -> smsCoreService.buildTemplateParams(template, templateParams), SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code"); } @@ -153,7 +153,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { // mock 方法 // 调用,并断言异常 - assertServiceException(() -> smsService.checkMobile(null), + assertServiceException(() -> smsCoreService.checkMobile(null), SMS_SEND_MOBILE_NOT_EXISTS); } @@ -171,9 +171,9 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { eq(message.getTemplateParams()))).thenReturn(sendResult); // 调用 - smsService.doSendSms(message); + smsCoreService.doSendSms(message); // 断言 - verify(smsLogService, times(1)).updateSmsSendResult(eq(message.getLogId()), + verify(smsLogCoreService, times(1)).updateSmsSendResult(eq(message.getLogId()), eq(sendResult.getCode()), eq(sendResult.getMsg()), eq(sendResult.getApiCode()), eq(sendResult.getApiMsg()), eq(sendResult.getApiRequestId()), eq(sendResult.getData().getSerialNo())); } @@ -190,12 +190,10 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { List receiveResults = randomPojoList(SmsReceiveRespDTO.class); // 调用 - smsService.receiveSmsStatus(channelCode, text); + smsCoreService.receiveSmsStatus(channelCode, text); // 断言 - receiveResults.forEach(result -> { - smsLogService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), - eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode())); - }); + receiveResults.forEach(result -> smsLogCoreService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), + eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode()))); } } diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreServiceTest.java new file mode 100644 index 000000000..896f0c6d3 --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreServiceTest.java @@ -0,0 +1,149 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms; + +import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsLogCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsLogCoreServiceImpl; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Map; +import java.util.function.Consumer; + +import static cn.hutool.core.util.RandomUtil.randomBoolean; +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** +* {@link SysSmsLogCoreServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SysSmsLogCoreServiceImpl.class) +public class SysSmsLogCoreServiceTest extends BaseDbUnitTest { + + @Resource + private SysSmsLogCoreServiceImpl smsLogCoreService; + + @Resource + private SysSmsLogCoreMapper smsLogCoreMapper; + + @Test + public void testCreateSmsLog() { + // 准备参数 + String mobile = randomString(); + Long userId = randomLongId(); + Integer userType = randomEle(UserTypeEnum.values()).getValue(); + Boolean isSend = randomBoolean(); + SysSmsTemplateDO templateDO = randomPojo(SysSmsTemplateDO.class, + o -> o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType())); + String templateContent = randomString(); + Map templateParams = randomTemplateParams(); + // mock 方法 + + // 调用 + Long logId = smsLogCoreService.createSmsLog(mobile, userId, userType, isSend, + templateDO, templateContent, templateParams); + // 断言 + SysSmsLogDO logDO = smsLogCoreMapper.selectById(logId); + assertEquals(isSend ? SysSmsSendStatusEnum.INIT.getStatus() : SysSmsSendStatusEnum.IGNORE.getStatus(), + logDO.getSendStatus()); + assertEquals(mobile, logDO.getMobile()); + assertEquals(userType, logDO.getUserType()); + assertEquals(userId, logDO.getUserId()); + assertEquals(templateDO.getId(), logDO.getTemplateId()); + assertEquals(templateDO.getCode(), logDO.getTemplateCode()); + assertEquals(templateDO.getType(), logDO.getTemplateType()); + assertEquals(templateDO.getChannelId(), logDO.getChannelId()); + assertEquals(templateDO.getChannelCode(), logDO.getChannelCode()); + assertEquals(templateContent, logDO.getTemplateContent()); + assertEquals(templateParams, logDO.getTemplateParams()); + assertEquals(SysSmsReceiveStatusEnum.INIT.getStatus(), logDO.getReceiveStatus()); + } + + @Test + public void testUpdateSmsSendResult() { + // mock 数据 + SysSmsLogDO dbSmsLog = randomSmsLogDO( + o -> o.setSendStatus(SysSmsSendStatusEnum.IGNORE.getStatus())); + smsLogCoreMapper.insert(dbSmsLog); + // 准备参数 + Long id = dbSmsLog.getId(); + Integer sendCode = randomInteger(); + String sendMsg = randomString(); + String apiSendCode = randomString(); + String apiSendMsg = randomString(); + String apiRequestId = randomString(); + String apiSerialNo = randomString(); + + // 调用 + smsLogCoreService.updateSmsSendResult(id, sendCode, sendMsg, + apiSendCode, apiSendMsg, apiRequestId, apiSerialNo); + // 断言 + dbSmsLog = smsLogCoreMapper.selectById(id); + assertEquals(CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS.getStatus() + : SysSmsSendStatusEnum.FAILURE.getStatus(), dbSmsLog.getSendStatus()); + assertNotNull(dbSmsLog.getSendTime()); + assertEquals(sendMsg, dbSmsLog.getSendMsg()); + assertEquals(apiSendCode, dbSmsLog.getApiSendCode()); + assertEquals(apiSendMsg, dbSmsLog.getApiSendMsg()); + assertEquals(apiRequestId, dbSmsLog.getApiRequestId()); + assertEquals(apiSerialNo, dbSmsLog.getApiSerialNo()); + } + + @Test + public void testUpdateSmsReceiveResult() { + // mock 数据 + SysSmsLogDO dbSmsLog = randomSmsLogDO( + o -> o.setReceiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus())); + smsLogCoreMapper.insert(dbSmsLog); + // 准备参数 + Long id = dbSmsLog.getId(); + Boolean success = randomBoolean(); + Date receiveTime = randomDate(); + String apiReceiveCode = randomString(); + String apiReceiveMsg = randomString(); + + // 调用 + smsLogCoreService.updateSmsReceiveResult(id, success, receiveTime, apiReceiveCode, apiReceiveMsg); + // 断言 + dbSmsLog = smsLogCoreMapper.selectById(id); + assertEquals(success ? SysSmsReceiveStatusEnum.SUCCESS.getStatus() + : SysSmsReceiveStatusEnum.FAILURE.getStatus(), dbSmsLog.getReceiveStatus()); + assertEquals(receiveTime, dbSmsLog.getReceiveTime()); + assertEquals(apiReceiveCode, dbSmsLog.getApiReceiveCode()); + assertEquals(apiReceiveMsg, dbSmsLog.getApiReceiveMsg()); + } + + // ========== 随机对象 ========== + + @SafeVarargs + private static SysSmsLogDO randomSmsLogDO(Consumer... consumers) { + Consumer consumer = (o) -> { + o.setTemplateParams(randomTemplateParams()); + o.setTemplateType(randomEle(SysSmsTemplateTypeEnum.values()).getType()); // 保证 templateType 的范围 + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); // 保证 userType 的范围 + o.setSendStatus(randomEle(SysSmsSendStatusEnum.values()).getStatus()); // 保证 sendStatus 的范围 + o.setReceiveStatus(randomEle(SysSmsReceiveStatusEnum.values()).getStatus()); // 保证 receiveStatus 的范围 + }; + return randomPojo(SysSmsLogDO.class, ArrayUtils.append(consumer, consumers)); + } + + + private static Map randomTemplateParams() { + return MapUtil.builder().put(randomString(), randomString()) + .put(randomString(), randomString()).build(); + } +} diff --git a/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateServiceTest.java b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateServiceTest.java new file mode 100644 index 000000000..1bcdb442d --- /dev/null +++ b/yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateServiceTest.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.coreservice.modules.system.service.sms; + +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsTemplateCoreMapper; +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsTemplateCoreServiceImpl; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Map; +import java.util.function.Consumer; + +import static cn.hutool.core.bean.BeanUtil.getFieldValue; +import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** +* {@link SysSmsTemplateCoreServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(SysSmsTemplateCoreServiceImpl.class) +public class SysSmsTemplateServiceTest extends BaseDbUnitTest { + + @Resource + private SysSmsTemplateCoreServiceImpl smsTemplateCoreService; + + @Resource + private SysSmsTemplateCoreMapper smsTemplateCoreMapper; + + @Test + @SuppressWarnings("unchecked") + void testInitLocalCache() { + // mock 数据 + SysSmsTemplateDO smsTemplate01 = randomSmsTemplateDO(); + smsTemplateCoreMapper.insert(smsTemplate01); + SysSmsTemplateDO smsTemplate02 = randomSmsTemplateDO(); + smsTemplateCoreMapper.insert(smsTemplate02); + + // 调用 + smsTemplateCoreService.initLocalCache(); + // 断言 deptCache 缓存 + Map smsTemplateCache = (Map) getFieldValue(smsTemplateCoreService, "smsTemplateCache"); + assertEquals(2, smsTemplateCache.size()); + assertPojoEquals(smsTemplate01, smsTemplateCache.get(smsTemplate01.getCode())); + assertPojoEquals(smsTemplate02, smsTemplateCache.get(smsTemplate02.getCode())); + // 断言 maxUpdateTime 缓存 + Date maxUpdateTime = (Date) getFieldValue(smsTemplateCoreService, "maxUpdateTime"); + assertEquals(max(smsTemplate01.getUpdateTime(), smsTemplate02.getUpdateTime()), maxUpdateTime); + } + + // ========== 随机对象 ========== + + @SafeVarargs + private static SysSmsTemplateDO randomSmsTemplateDO(Consumer... consumers) { + Consumer consumer = (o) -> { + o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 + o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType()); // 保证 type 的 范围 + }; + return randomPojo(SysSmsTemplateDO.class, ArrayUtils.append(consumer, consumers)); + } + +} diff --git a/yudao-core-service/src/test/resources/application-unit-test.yaml b/yudao-core-service/src/test/resources/application-unit-test.yaml new file mode 100644 index 000000000..d306a7af4 --- /dev/null +++ b/yudao-core-service/src/test/resources/application-unit-test.yaml @@ -0,0 +1,44 @@ +spring: + main: + lazy-initialization: true # 开启懒加载,加快速度 + banner-mode: off # 单元测试,禁用 Banner + +--- #################### 数据库相关配置 #################### + +spring: + # 数据源配置项 + datasource: + name: ruoyi-vue-pro + url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写 + driver-class-name: org.h2.Driver + username: sa + password: + schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具 + druid: + async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度 + initial-size: 1 # 单元测试,配置为 1,提升启动速度 + + # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 + redis: + host: 127.0.0.1 # 地址 + port: 16379 # 端口(单元测试,使用 16379 端口) + database: 0 # 数据库索引 + +mybatis: + lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试 + +--- #################### 定时任务相关配置 #################### + +--- #################### 配置中心相关配置 #################### + +--- #################### 服务保障相关配置 #################### + +# Lock4j 配置项(单元测试,禁用 Lock4j) + +# Resilience4j 配置项 + +--- #################### 监控相关配置 #################### + +--- #################### 芋道相关配置 #################### + +# 芋道配置项,设置当前项目所有自定义的配置 diff --git a/yudao-core-service/src/test/resources/application.yaml b/yudao-core-service/src/test/resources/application.yaml new file mode 100644 index 000000000..4db8b273c --- /dev/null +++ b/yudao-core-service/src/test/resources/application.yaml @@ -0,0 +1,35 @@ +spring: + application: + name: yudao-core-service + + # Jackson 配置项 + jackson: + serialization: + write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳 + write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401 + write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳 + fail-on-empty-beans: false # 允许序列化无属性的 Bean + +# MyBatis Plus 的配置项 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志 + global-config: + db-config: + id-type: AUTO # 自增 ID + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) + mapper-locations: classpath*:mapper/*.xml + type-aliases-package: ${yudao.core-service.base-package}.modules.*.dal.dataobject + +--- #################### 芋道相关配置 #################### + +yudao: + info: + version: 1.0.0 + base-package: cn.iocoder.yudao.coreservice + core-service: + base-package: cn.iocoder.yudao.coreservice + +debug: false diff --git a/yudao-core-service/src/test/resources/logback-spring.xml b/yudao-core-service/src/test/resources/logback-spring.xml new file mode 100644 index 000000000..daf756bff --- /dev/null +++ b/yudao-core-service/src/test/resources/logback-spring.xml @@ -0,0 +1,4 @@ + + + + diff --git a/yudao-core-service/src/test/resources/sql/clean.sql b/yudao-core-service/src/test/resources/sql/clean.sql new file mode 100644 index 000000000..855ccf7eb --- /dev/null +++ b/yudao-core-service/src/test/resources/sql/clean.sql @@ -0,0 +1,9 @@ +-- inf 开头的 DB +DELETE FROM "inf_api_access_log"; +DELETE FROM "inf_api_error_log"; + +-- sys 开头的 DB +DELETE FROM "sys_user_session"; +DELETE FROM "sys_dict_data"; +DELETE FROM "sys_sms_template"; +DELETE FROM "sys_sms_log"; diff --git a/yudao-core-service/src/test/resources/sql/create_tables.sql b/yudao-core-service/src/test/resources/sql/create_tables.sql new file mode 100644 index 000000000..2076e0c5d --- /dev/null +++ b/yudao-core-service/src/test/resources/sql/create_tables.sql @@ -0,0 +1,161 @@ +-- inf 开头的 DB + +-- sys 开头的 DB + +CREATE TABLE IF NOT EXISTS `sys_user_session` ( + `id` varchar(32) NOT NULL, + `user_id` bigint DEFAULT NULL, + "user_type" tinyint NOT NULL, + `username` varchar(50) NOT NULL DEFAULT '', + `user_ip` varchar(50) DEFAULT NULL, + `user_agent` varchar(512) DEFAULT NULL, + `session_timeout` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updater` varchar(64) DEFAULT '' , + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY (`id`) +) COMMENT '用户在线 Session'; + +CREATE TABLE IF NOT EXISTS "sys_dict_data" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "sort" int NOT NULL DEFAULT '0', + "label" varchar(100) NOT NULL DEFAULT '', + "value" varchar(100) NOT NULL DEFAULT '', + "dict_type" varchar(100) NOT NULL DEFAULT '', + "status" tinyint NOT NULL DEFAULT '0', + "remark" varchar(500) DEFAULT NULL, + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '字典数据表'; + +CREATE TABLE IF NOT EXISTS "inf_api_access_log" ( + "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, + "trace_id" varchar(64) not null default '', + "user_id" bigint not null default '0', + "user_type" tinyint not null default '0', + "application_name" varchar(50) not null, + "request_method" varchar(16) not null default '', + "request_url" varchar(255) not null default '', + "request_params" varchar(8000) not null default '', + "user_ip" varchar(50) not null, + "user_agent" varchar(512) not null, + "begin_time" timestamp not null, + "end_time" timestamp not null, + "duration" integer not null, + "result_code" integer not null default '0', + "result_msg" varchar(512) default '', + "creator" varchar(64) default '', + "create_time" timestamp not null default current_timestamp, + "updater" varchar(64) default '', + "update_time" timestamp not null default current_timestamp, + "deleted" bit not null default false, + primary key ("id") +) COMMENT 'API 访问日志表'; + +CREATE TABLE IF NOT EXISTS "inf_api_error_log" ( + "id" integer not null GENERATED BY DEFAULT AS IDENTITY, + "trace_id" varchar(64) not null, + "user_id" bigint not null default '0', + "user_type" tinyint not null default '0', + "application_name" varchar(50) not null, + "request_method" varchar(16) not null, + "request_url" varchar(255) not null, + "request_params" varchar(8000) not null, + "user_ip" varchar(50) not null, + "user_agent" varchar(512) not null, + "exception_time" timestamp not null, + "exception_name" varchar(128) not null default '', + "exception_message" clob not null, + "exception_root_cause_message" clob not null, + "exception_stack_trace" clob not null, + "exception_class_name" varchar(512) not null, + "exception_file_name" varchar(512) not null, + "exception_method_name" varchar(512) not null, + "exception_line_number" integer not null, + "process_status" tinyint not null, + "process_time" timestamp default null, + "process_user_id" bigint default '0', + "creator" varchar(64) default '', + "create_time" timestamp not null default current_timestamp, + "updater" varchar(64) default '', + "update_time" timestamp not null default current_timestamp, + "deleted" bit not null default false, + primary key ("id") +) COMMENT '系统异常日志'; + +CREATE TABLE IF NOT EXISTS "sys_sms_template" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "type" tinyint NOT NULL, + "status" tinyint NOT NULL, + "code" varchar(63) NOT NULL, + "name" varchar(63) NOT NULL, + "content" varchar(255) NOT NULL, + "params" varchar(255) NOT NULL, + "remark" varchar(255) DEFAULT NULL, + "api_template_id" varchar(63) NOT NULL, + "channel_id" bigint NOT NULL, + "channel_code" varchar(63) NOT NULL, + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '短信模板'; + +CREATE TABLE IF NOT EXISTS "sys_sms_log" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "channel_id" bigint NOT NULL, + "channel_code" varchar(63) NOT NULL, + "template_id" bigint NOT NULL, + "template_code" varchar(63) NOT NULL, + "template_type" tinyint NOT NULL, + "template_content" varchar(255) NOT NULL, + "template_params" varchar(255) NOT NULL, + "api_template_id" varchar(63) NOT NULL, + "mobile" varchar(11) NOT NULL, + "user_id" bigint DEFAULT '0', + "user_type" tinyint DEFAULT '0', + "send_status" tinyint NOT NULL DEFAULT '0', + "send_time" timestamp DEFAULT NULL, + "send_code" int DEFAULT NULL, + "send_msg" varchar(255) DEFAULT NULL, + "api_send_code" varchar(63) DEFAULT NULL, + "api_send_msg" varchar(255) DEFAULT NULL, + "api_request_id" varchar(255) DEFAULT NULL, + "api_serial_no" varchar(255) DEFAULT NULL, + "receive_status" tinyint NOT NULL DEFAULT '0', + "receive_time" timestamp DEFAULT NULL, + "api_receive_code" varchar(63) DEFAULT NULL, + "api_receive_msg" varchar(255) DEFAULT NULL, + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '短信日志'; + +CREATE TABLE IF NOT EXISTS `sys_login_log` ( + `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `log_type` bigint(4) NOT NULL, + "user_id" bigint not null default '0', + "user_type" tinyint NOT NULL, + `trace_id` varchar(64) NOT NULL DEFAULT '', + `username` varchar(50) NOT NULL DEFAULT '', + `result` tinyint(4) NOT NULL, + `user_ip` varchar(50) NOT NULL, + `user_agent` varchar(512) NOT NULL, + `creator` varchar(64) DEFAULT '', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updater` varchar(64) DEFAULT '', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted` bit(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) COMMENT ='系统访问记录'; diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index acb5dd270..125d3bdaf 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -26,7 +26,7 @@ 1.2.4 3.4.2 3.3.2 - 3.15.1 + 3.16.3 1.7.0 @@ -34,9 +34,9 @@ 2.2.0 1.7.0 - 8.5.0 + 8.7.0 2.3.1 - 0.30.0 + 0.31.0 7.2.6.RELEASE 0.1.16 @@ -49,7 +49,7 @@ 1.0.5 30.1.1-jre - 4.5.18 + 4.5.25 2.1.0 1.2.7 @@ -72,6 +72,11 @@
+ + cn.iocoder.boot + yudao-core-service + ${revision} + cn.iocoder.boot yudao-spring-boot-starter-biz-operatelog @@ -252,12 +257,32 @@ org.apache.skywalking apm-toolkit-opentracing ${skywalking.version} + + + + + + + + + + + + + io.opentracing + opentracing-api + ${opentracing.version} io.opentracing opentracing-util ${opentracing.version} + + io.opentracing + opentracing-noop + ${opentracing.version} + de.codecentric diff --git a/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml b/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml index 0fa5ac5d5..8088520e1 100644 --- a/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-monitor/pom.xml @@ -41,6 +41,10 @@ + + io.opentracing + opentracing-util + org.apache.skywalking apm-toolkit-trace @@ -53,10 +57,6 @@ org.apache.skywalking apm-toolkit-opentracing - - io.opentracing - opentracing-util - de.codecentric diff --git a/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java index 6979d8e18..ac76b9ed7 100644 --- a/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java @@ -1,13 +1,9 @@ package cn.iocoder.yudao.framework.tracer.config; +import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; import cn.iocoder.yudao.framework.tracer.core.aop.BizTraceAspect; import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter; -import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; -import io.opentracing.Tracer; -import io.opentracing.util.GlobalTracer; -import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -25,24 +21,25 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(prefix = "yudao.tracer", value = "enable", matchIfMissing = true) public class YudaoTracerAutoConfiguration { - @Bean - public TracerProperties bizTracerProperties() { - return new TracerProperties(); - } - - @Bean - public BizTraceAspect bizTracingAop() { - return new BizTraceAspect(tracer()); - } - - @Bean - public Tracer tracer() { - // 创建 SkywalkingTracer 对象 - SkywalkingTracer tracer = new SkywalkingTracer(); - // 设置为 GlobalTracer 的追踪器 - GlobalTracer.register(tracer); - return tracer; - } + // TODO @芋艿:重要。目前 opentracing 版本存在冲突,要么保证 skywalking,要么保证阿里云短信 sdk +// @Bean +// public TracerProperties bizTracerProperties() { +// return new TracerProperties(); +// } +// +// @Bean +// public BizTraceAspect bizTracingAop() { +// return new BizTraceAspect(tracer()); +// } +// +// @Bean +// public Tracer tracer() { +// // 创建 SkywalkingTracer 对象 +// SkywalkingTracer tracer = new SkywalkingTracer(); +// // 设置为 GlobalTracer 的追踪器 +// GlobalTracer.register(tracer); +// return tracer; +// } /** * 创建 TraceFilter 过滤器,响应 header 设置 traceId diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java index f8eeeef87..b03fc58e4 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java @@ -15,7 +15,7 @@ import org.springframework.context.annotation.Configuration; * @author 芋道源码 */ @Configuration -@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class, +@MapperScan(value = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}, annotationClass = Mapper.class, lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 public class YudaoMybatisAutoConfiguration { diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java index 86c82319e..4e49f66bc 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.framework.security.core; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import org.springframework.security.core.GrantedAuthority; @@ -24,7 +25,13 @@ public class LoginUser implements UserDetails { */ private Long id; /** - * 科室编号 + * 用户类型 + * + * 关联 {@link UserTypeEnum} + */ + private Integer userType; + /** + * 部门编号 */ private Long deptId; /** @@ -49,6 +56,8 @@ public class LoginUser implements UserDetails { */ private Integer status; + // TODO @芋艿:怎么去掉 deptId + @Override @JsonIgnore// 避免序列化 public String getPassword() { diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java index f9b0bb0a5..eb5f4935c 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java @@ -97,6 +97,7 @@ public class SecurityFrameworkUtils { // 额外设置到 request 中,用于 ApiAccessLogFilter 可以获取到用户编号; // 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息 WebFrameworkUtils.setLoginUserId(request, loginUser.getId()); + WebFrameworkUtils.setLoginUserType(request, loginUser.getUserType()); } } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java index 49f54fe25..008d6ca6a 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java @@ -81,7 +81,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { Map queryString, String requestBody, Exception ex) { // 处理用户信息 accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); - accessLog.setUserType(WebFrameworkUtils.getUserType(request)); + accessLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); // 设置访问结果 CommonResult result = WebFrameworkUtils.getCommonResult(request); if (result != null) { diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java index fd7c22ed8..a999e8339 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java @@ -16,8 +16,7 @@ public interface ApiAccessLogFrameworkService { * 创建 API 访问日志 * * @param createDTO 创建信息 - * @return 是否创建成功 */ - Future createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); + void createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java index 1c55adb4f..55733e95f 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java @@ -16,8 +16,7 @@ public interface ApiErrorLogFrameworkService { * 创建 API 错误日志 * * @param createDTO 创建信息 - * @return 是否创建成功 */ - Future createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); + void createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index a27d87a82..cb0aefd8d 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -245,7 +245,7 @@ public class GlobalExceptionHandler { private void initExceptionLog(ApiErrorLogCreateDTO errorLog, HttpServletRequest request, Throwable e) { // 处理用户信息 errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); - errorLog.setUserType(WebFrameworkUtils.getUserType(request)); + errorLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); // 设置异常字段 errorLog.setExceptionName(e.getClass().getName()); errorLog.setExceptionMessage(ExceptionUtil.getMessage(e)); diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java index 2bf5c2ff8..acbfb9c2b 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java @@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletRequest; public class WebFrameworkUtils { private static final String REQUEST_ATTRIBUTE_LOGIN_USER_ID = "login_user_id"; + private static final String REQUEST_ATTRIBUTE_LOGIN_USER_TYPE = "login_user_type"; private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result"; @@ -24,6 +25,10 @@ public class WebFrameworkUtils { request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId); } + public static void setLoginUserType(ServletRequest request, Integer userType) { + request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE, userType); + } + /** * 获得当前用户的编号,从请求中 * @@ -37,15 +42,24 @@ public class WebFrameworkUtils { return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID); } + /** + * 获得当前用户的类型,从请求中 + * + * @param request 请求 + * @return 用户编号 + */ + public static Integer getLoginUserType(HttpServletRequest request) { + if (request == null) { + return null; + } + return (Integer) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE); + } + public static Long getLoginUserId() { HttpServletRequest request = getRequest(); return getLoginUserId(request); } - public static Integer getUserType(HttpServletRequest request) { - return UserTypeEnum.ADMIN.getValue(); // TODO 芋艿:等后续优化 - } - public static void setCommonResult(ServletRequest request, CommonResult result) { request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); } diff --git a/yudao-user-server/pom.xml b/yudao-user-server/pom.xml index 4bd1c5857..fe55b34f9 100644 --- a/yudao-user-server/pom.xml +++ b/yudao-user-server/pom.xml @@ -18,6 +18,11 @@ + + cn.iocoder.boot + yudao-core-service + + cn.iocoder.boot yudao-spring-boot-starter-biz-dict diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/UserServerApplication.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/UserServerApplication.java index edfbc63dc..18a927afc 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/UserServerApplication.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/UserServerApplication.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.userserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication -public class UserServerApplication { +@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} +@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"})public class UserServerApplication { public static void main(String[] args) { SpringApplication.run(UserServerApplication.class, args); diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/framework/security/SecurityConfiguration.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/framework/security/SecurityConfiguration.java index e43f5e3e6..66a0ae718 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/framework/security/SecurityConfiguration.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/framework/security/SecurityConfiguration.java @@ -18,7 +18,7 @@ public class SecurityConfiguration { @Bean public Customizer.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { return registry -> { - registry.antMatchers(api("/**")).anonymous(); // 默认 API 都是用户可访问 + registry.antMatchers(api("/**")).permitAll(); // 默认 API 都是用户可访问 }; } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/controller/HelloController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/controller/HelloController.java deleted file mode 100644 index 6a3270fc2..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/controller/HelloController.java +++ /dev/null @@ -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"; - } - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiAccessLogConvert.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiAccessLogConvert.java deleted file mode 100644 index 3ddbbf65b..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiAccessLogConvert.java +++ /dev/null @@ -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); - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiErrorLogConvert.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiErrorLogConvert.java deleted file mode 100644 index 51c6c3eef..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiErrorLogConvert.java +++ /dev/null @@ -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); - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/file/InfFileDO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/file/InfFileDO.java deleted file mode 100644 index 604a888c2..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/file/InfFileDO.java +++ /dev/null @@ -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; - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java deleted file mode 100644 index 2548ec469..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java +++ /dev/null @@ -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; - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java deleted file mode 100644 index 5453c05a2..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java +++ /dev/null @@ -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 selectList() { - return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class)); - } - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/file/InfFileMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/file/InfFileMapper.java deleted file mode 100644 index 1db7d311b..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/file/InfFileMapper.java +++ /dev/null @@ -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 { - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java deleted file mode 100644 index cf7f6e92c..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java +++ /dev/null @@ -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 { -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java deleted file mode 100644 index 9e9124267..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java +++ /dev/null @@ -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 { -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/package-info.java deleted file mode 100644 index 3a03078cb..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位类,可以无视 - */ -package cn.iocoder.yudao.userserver.modules.infra.enums; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/SysAuthService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/SysAuthService.java deleted file mode 100644 index ba3defa61..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/SysAuthService.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.userserver.modules.infra.service.auth; - -import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; - -/** - * 认证 Service 接口 - * - * 提供用户的账号密码登录、token 的校验等认证相关的功能 - * - * @author 芋道源码 - */ -public interface SysAuthService extends SecurityAuthFrameworkService { - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/impl/SysAuthServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/impl/SysAuthServiceImpl.java deleted file mode 100644 index 6ab606c59..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/impl/SysAuthServiceImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.userserver.modules.infra.service.auth.impl; - -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.userserver.modules.infra.service.auth.SysAuthService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; - -/** - * Auth Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Slf4j -public class SysAuthServiceImpl implements SysAuthService { - - @Override - public LoginUser verifyTokenAndRefresh(String token) { - return null; - } - - @Override - public LoginUser mockLogin(Long userId) { - return null; - } - - @Override - public void logout(String token) { - - } - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - return null; - } -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java deleted file mode 100644 index 1b0f2611c..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java +++ /dev/null @@ -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 createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { - InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO); - int insert = apiAccessLogMapper.insert(apiAccessLog); - return new AsyncResult<>(insert > 1); - } - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java deleted file mode 100644 index 05bddb7d9..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java +++ /dev/null @@ -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 createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { - InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); - apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); - int insert = apiErrorLogMapper.insert(apiErrorLog); - return new AsyncResult<>(insert == 1); - } - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/package-info.java new file mode 100644 index 000000000..148c73cf3 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.userserver.modules.member.controller; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http new file mode 100644 index 000000000..72cf861b8 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http @@ -0,0 +1,3 @@ +### 请求 /system/user/profile/get 接口 => 没有权限 +GET {{userServerUrl}}/system/user/profile/get +Authorization: Bearer test245 diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java new file mode 100644 index 000000000..4b66b4e18 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java @@ -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 profile() { + return null; + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/package-info.java new file mode 100644 index 000000000..5877b74c1 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/package-info.java @@ -0,0 +1,6 @@ +/** + * 提供 POJO 类的实体转换 + * + * 目前使用 MapStruct 框架 + */ +package cn.iocoder.yudao.userserver.modules.member.convert; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md new file mode 100644 index 000000000..8153487b7 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md @@ -0,0 +1 @@ + diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java new file mode 100644 index 000000000..35546f1d8 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; + +/** + * MbrUserDO Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface MbrUserMapper extends BaseMapperX { + + default MbrUserDO selectByMobile(String mobile) { + return selectOne("mobile", mobile); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java new file mode 100644 index 000000000..265d1d485 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java @@ -0,0 +1,12 @@ +package cn.iocoder.yudao.userserver.modules.member.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * Member 错误码枚举类 + * + * member 系统,使用 1-004-000-000 段 + */ +public interface MbrErrorCodeConstants { + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/package-info.java new file mode 100644 index 000000000..b12c6427a --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.userserver.modules.member.service; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java new file mode 100644 index 000000000..2d5466865 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.userserver.modules.member.service.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.common.validation.Mobile; + +/** + * 前台用户 Service 接口 + * + * @author 芋道源码 + */ +public interface MbrUserService { + + /** + * 通过手机查询用户 + * + * @param mobile 手机 + * @return 用户对象 + */ + MbrUserDO getUserByMobile(String mobile); + + /** + * 基于手机号创建用户。 + * 如果用户已经存在,则直接进行返回 + * + * @param mobile 手机号 + * @param registerIp 注册 IP + * @return 用户对象 + */ + MbrUserDO createUserIfAbsent(@Mobile String mobile, String registerIp); + + /** + * 更新用户的最后登陆信息 + * + * @param id 用户编号 + * @param loginIp 登陆 IP + */ + void updateUserLogin(Long id, String loginIp); + + /** + * 通过用户 ID 查询用户 + * + * @param id 用户ID + * @return 用户对象信息 + */ + MbrUserDO getUser(Long id); + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java new file mode 100644 index 000000000..71fb9dd88 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.userserver.modules.member.service.user.impl; + +import cn.hutool.core.util.IdUtil; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.Date; + +/** + * User Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Valid +@Slf4j +public class MbrUserServiceImpl implements MbrUserService { + + @Resource + private MbrUserMapper userMapper; + + @Resource + private PasswordEncoder passwordEncoder; + + @Override + public MbrUserDO getUserByMobile(String mobile) { + return userMapper.selectByMobile(mobile); + } + + @Override + public MbrUserDO createUserIfAbsent(String mobile, String registerIp) { + // 用户已经存在 + MbrUserDO user = userMapper.selectByMobile(mobile); + if (user != null) { + return user; + } + // 用户不存在,则进行创建 + return this.createUser(mobile, registerIp); + } + + private MbrUserDO createUser(String mobile, String registerIp) { + // 生成密码 + String password = IdUtil.fastSimpleUUID(); + // 插入用户 + MbrUserDO user = new MbrUserDO(); + user.setMobile(mobile); + user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 + user.setPassword(passwordEncoder.encode(password)); // 加密密码 + user.setRegisterIp(registerIp); + userMapper.insert(user); + return user; + } + + @Override + public void updateUserLogin(Long id, String loginIp) { + userMapper.updateById(new MbrUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); + } + + @Override + public MbrUserDO getUser(Long id) { + return userMapper.selectById(id); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/package-info.java deleted file mode 100644 index 430f6c945..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package cn.iocoder.yudao.userserver.modules; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http new file mode 100644 index 000000000..c9cadedcc --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http @@ -0,0 +1,31 @@ +### 请求 /login 接口 => 成功 +POST {{userServerUrl}}/login +Content-Type: application/json + +{ + "mobile": "15601691300", + "password": "admin123" +} + +### 请求 /send-sms-code 接口 => 成功 +POST {{userServerUrl}}/send-sms-code +Content-Type: application/json + +{ + "mobile": "15601691399", + "scene": 1 +} + +### 请求 /sms-login 接口 => 成功 +POST {{userServerUrl}}/sms-login +Content-Type: application/json + +{ + "mobile": "15601691301", + "code": 9999 +} + +### 请求 /logout 接口 => 成功 +POST {{userServerUrl}}/logout +Content-Type: application/json +Authorization: Bearer c1b76bdaf2c146c581caa4d7fd81ee66 diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/MbrAuthController.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java similarity index 67% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/MbrAuthController.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java index 95f8b6510..2b1fd6161 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/MbrAuthController.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java @@ -1,7 +1,9 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth; +package cn.iocoder.yudao.userserver.modules.system.controller.auth; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.*; +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; +import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -10,37 +12,46 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getUserAgent; + @Api(tags = "认证") @RestController @RequestMapping("/") @Validated @Slf4j -public class MbrAuthController { +public class SysAuthController { + + @Resource + private SysAuthService authService; + @Resource + private SysSmsCodeService smsCodeService; @PostMapping("/login") @ApiOperation("使用手机 + 密码登录") - public CommonResult login(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { -// String token = authService.login(reqVO, getClientIP(), getUserAgent()); -// // 返回结果 -// return success(MbrAuthLoginRespVO.builder().token(token).build()); - return null; + public CommonResult login(@RequestBody @Valid SysAuthLoginReqVO reqVO) { + String token = authService.login(reqVO, getClientIP(), getUserAgent()); + // 返回结果 + return success(SysAuthLoginRespVO.builder().token(token).build()); } @PostMapping("/sms-login") @ApiOperation("使用手机 + 验证码登录") - public CommonResult smsLogin(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { - return null; + public CommonResult smsLogin(@RequestBody @Valid SysAuthSmsLoginReqVO reqVO) { + String token = authService.smsLogin(reqVO, getClientIP(), getUserAgent()); + // 返回结果 + return success(SysAuthLoginRespVO.builder().token(token).build()); } @PostMapping("/send-sms-code") @ApiOperation("发送手机验证码") - public CommonResult sendSmsCode(@RequestBody @Valid MbrAuthSendSmsReqVO reqVO) { -// passportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); -// // 返回成功 -// return success(true); - return null; + public CommonResult sendSmsCode(@RequestBody @Valid SysAuthSendSmsReqVO reqVO) { + smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP()); + return success(true); } @PostMapping("/reset-password") @@ -65,7 +76,7 @@ public class MbrAuthController { @PostMapping("/social-login") @ApiOperation("社交登录,使用 code 授权码") - public CommonResult socialLogin(@RequestBody @Valid MbrAuthSocialLoginReqVO reqVO) { + public CommonResult socialLogin(@RequestBody @Valid MbrAuthSocialLoginReqVO reqVO) { // String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); // // 返回结果 // return success(MbrAuthLoginRespVO.builder().token(token).build()); @@ -74,7 +85,7 @@ public class MbrAuthController { @PostMapping("/social-login2") @ApiOperation("社交登录,使用 code 授权码 + 账号密码") - public CommonResult socialLogin2(@RequestBody @Valid MbrAuthSocialLogin2ReqVO reqVO) { + public CommonResult socialLogin2(@RequestBody @Valid MbrAuthSocialLogin2ReqVO reqVO) { // String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); // // 返回结果 // return success(MbrAuthLoginRespVO.builder().token(token).build()); diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthResetPasswordReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthResetPasswordReqVO.java similarity index 94% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthResetPasswordReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthResetPasswordReqVO.java index ef24af7b7..3b3556fdb 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthResetPasswordReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthResetPasswordReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialBindReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialBindReqVO.java similarity index 94% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialBindReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialBindReqVO.java index 44f16dcfa..d866411d2 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialBindReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialBindReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java similarity index 96% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java index 1769fe2ef..371e7e9b3 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLoginReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLoginReqVO.java similarity index 94% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLoginReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLoginReqVO.java index 96fd0f661..5fdd424c1 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLoginReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLoginReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialUnbindReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialUnbindReqVO.java similarity index 94% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialUnbindReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialUnbindReqVO.java index cb798cb49..ea9050a29 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialUnbindReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialUnbindReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginReqVO.java similarity index 89% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginReqVO.java index 1b2e9b52a..1d51f8001 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.Mobile; import io.swagger.annotations.ApiModel; @@ -16,7 +16,7 @@ import javax.validation.constraints.NotEmpty; @NoArgsConstructor @AllArgsConstructor @Builder -public class MbrAuthLoginReqVO { +public class SysAuthLoginReqVO { @ApiModelProperty(value = "手机号", required = true, example = "15601691300") @NotEmpty(message = "手机号不能为空") diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginRespVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginRespVO.java similarity index 80% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginRespVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginRespVO.java index fcc7e09c9..95c69c754 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginRespVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor @Builder -public class MbrAuthLoginRespVO { +public class SysAuthLoginRespVO { @ApiModelProperty(value = "token", required = true, example = "yudaoyuanma") private String token; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSendSmsReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSendSmsReqVO.java similarity index 69% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSendSmsReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSendSmsReqVO.java index d3ceecf9c..d8c6c983f 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSendSmsReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSendSmsReqVO.java @@ -1,6 +1,8 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; +import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.Mobile; +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,7 +13,7 @@ import javax.validation.constraints.NotNull; @ApiModel("发送手机验证码 Response VO") @Data @Accessors(chain = true) -public class MbrAuthSendSmsReqVO { +public class SysAuthSendSmsReqVO { @ApiModelProperty(value = "手机号", example = "15601691234") @Mobile @@ -19,6 +21,7 @@ public class MbrAuthSendSmsReqVO { @ApiModelProperty(value = "发送场景", example = "1", notes = "对应 MbrSmsSceneEnum 枚举") @NotNull(message = "发送场景不能为空") + @InEnum(SysSmsSceneEnum.class) private Integer scene; -} \ No newline at end of file +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSmsLoginReqVO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSmsLoginReqVO.java similarity index 75% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSmsLoginReqVO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSmsLoginReqVO.java index 6c07e5e72..a7b36bb54 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSmsLoginReqVO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSmsLoginReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; import cn.iocoder.yudao.framework.common.validation.Mobile; import io.swagger.annotations.ApiModel; @@ -17,18 +17,13 @@ import javax.validation.constraints.Pattern; @NoArgsConstructor @AllArgsConstructor @Builder -public class MbrAuthSmsLoginReqVO { +public class SysAuthSmsLoginReqVO { @ApiModelProperty(value = "手机号", required = true, example = "15601691300") @NotEmpty(message = "手机号不能为空") @Mobile private String mobile; - @ApiModelProperty(value = "密码", required = true, example = "buzhidao") - @NotEmpty(message = "密码不能为空") - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") - private String password; - @ApiModelProperty(value = "手机验证码", required = true, example = "1024") @NotEmpty(message = "手机验证码不能为空") @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/package-info.java new file mode 100644 index 000000000..aa4f746ad --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.yudao.userserver.modules.system.controller; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java new file mode 100644 index 000000000..f2af81257 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.userserver.modules.system.convert.auth; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SysAuthConvert { + + SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); + + @Mapping(source = "mobile", target = "username") + LoginUser convert0(MbrUserDO bean); + + default LoginUser convert(MbrUserDO bean) { + // 目的,为了设置 UserTypeEnum.MEMBER.getValue() + return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue()); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/package-info.java index 65ad8dc88..d7da621f0 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/package-info.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/package-info.java @@ -1 +1,6 @@ +/** + * 提供 POJO 类的实体转换 + * + * 目前使用 MapStruct 框架 + */ package cn.iocoder.yudao.userserver.modules.system.convert; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md new file mode 100644 index 000000000..8153487b7 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md @@ -0,0 +1 @@ + diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/dict/SysDictDataDO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/dict/SysDictDataDO.java deleted file mode 100644 index eacec758f..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/dict/SysDictDataDO.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 字典数据表 - * - * @author ruoyi - */ -@TableName("sys_dict_data") -@Data -@EqualsAndHashCode(callSuper = true) -public class SysDictDataDO extends BaseDO { - - /** - * 字典数据编号 - */ - @TableId - private Long id; - /** - * 字典排序 - */ - private Integer sort; - /** - * 字典标签 - */ - private String label; - /** - * 字典值 - */ - private String value; - /** - * 字典类型 - * - * 冗余 {@link SysDictDataDO#getDictType()} - */ - private String dictType; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - /** - * 备注 - */ - private String remark; - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/sms/MbrSmsCodeDO.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/sms/SysSmsCodeDO.java similarity index 78% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/sms/MbrSmsCodeDO.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/sms/SysSmsCodeDO.java index 775d34e2a..8cce25f42 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/sms/MbrSmsCodeDO.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/sms/SysSmsCodeDO.java @@ -1,9 +1,8 @@ -package cn.iocoder.yudao.userserver.modules.member.dal.mysql.sms; +package cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import lombok.experimental.Accessors; import java.util.Date; @@ -15,11 +14,13 @@ import java.util.Date; * * @author 芋道源码 */ -@TableName("mbr_sms_code") +@TableName("sys_sms_code") @Data @EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -public class MbrSmsCodeDO extends BaseDO { +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SysSmsCodeDO extends BaseDO { /** * 编号 @@ -36,7 +37,7 @@ public class MbrSmsCodeDO extends BaseDO { /** * 发送场景 * - * 枚举 {@link MbrSmsCodeDO} + * 枚举 {@link SysSmsCodeDO} */ private Integer scene; /** diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/dict/SysDictDataMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/dict/SysDictDataMapper.java deleted file mode 100644 index 928a53f7d..000000000 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/dict/SysDictDataMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.userserver.modules.system.dal.mysql.dict; - - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import java.util.Date; - -@Mapper -public interface SysDictDataMapper extends BaseMapperX { - - default SysDictDataDO selectByDictTypeAndValue(String dictType, String value) { - return selectOne(new QueryWrapper().eq("dict_type", dictType) - .eq("value", value)); - } - - default int selectCountByDictType(String dictType) { - return selectCount("dict_type", dictType); - } - - default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new QueryWrapper().select("id") - .gt("update_time", maxUpdateTime).last("LIMIT 1")) != null; - } - -} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/sms/SysSmsCodeMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/sms/SysSmsCodeMapper.java new file mode 100644 index 000000000..6ef96ca1f --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/sms/SysSmsCodeMapper.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysSmsCodeMapper extends BaseMapperX { + + /** + * 获得手机号的最后一个手机验证码 + * + * @param mobile 手机号 + * @param scene 发送场景,选填 + * @return 手机验证码 + */ + default SysSmsCodeDO selectLastByMobile(String mobile, Integer scene) { + return selectOne(new QueryWrapperX() + .eq("mobile", mobile) + .eqIfPresent("scene", scene) + .orderByDesc("id") + .last("LIMIT 1")); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/redis/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/redis/package-info.java new file mode 100644 index 000000000..bb5083518 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/redis/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.userserver.modules.system.dal.redis; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/SysErrorCodeConstants.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/SysErrorCodeConstants.java new file mode 100644 index 000000000..e5f4ac678 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/SysErrorCodeConstants.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.userserver.modules.system.enums; + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * System 错误码枚举类 + * + * system 系统,使用 1-005-000-000 段 + */ +public interface SysErrorCodeConstants { + + // ========== AUTH 模块 1005000000 ========== + ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1005000000, "登录失败,账号密码不正确"); + ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1005000001, "登录失败,账号被禁用"); + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1005000002, "登录失败"); // 登录失败的兜底,未知原因 + ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1005000003, "Token 已经过期"); + + // ========== SMS CODE 模块 1005001000 ========== + ErrorCode USER_SMS_CODE_NOT_FOUND = new ErrorCode(1005001000, "验证码不存在"); + ErrorCode USER_SMS_CODE_EXPIRED = new ErrorCode(1005001001, "验证码已过期"); + ErrorCode USER_SMS_CODE_USED = new ErrorCode(1005001002, "验证码已使用"); + ErrorCode USER_SMS_CODE_NOT_CORRECT = new ErrorCode(1005001003, "验证码不正确"); + ErrorCode USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY = new ErrorCode(1005001004, "超过每日短信发送数量"); + ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1005001005, "短信发送过于频率"); +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/sms/MbrSmsSceneEnum.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsSceneEnum.java similarity index 77% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/sms/MbrSmsSceneEnum.java rename to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsSceneEnum.java index 246e5df19..6f5ce3daa 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/sms/MbrSmsSceneEnum.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsSceneEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.enums.sms; +package cn.iocoder.yudao.userserver.modules.system.enums.sms; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; @@ -13,13 +13,13 @@ import java.util.Arrays; */ @Getter @AllArgsConstructor -public enum MbrSmsSceneEnum implements IntArrayValuable { +public enum SysSmsSceneEnum implements IntArrayValuable { LOGIN_BY_SMS(1, "手机号登陆"), CHANGE_MOBILE_BY_SMS(2, "更换手机号"), ; - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MbrSmsSceneEnum::getScene).toArray(); + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSmsSceneEnum::getScene).toArray(); private final Integer scene; private final String name; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java new file mode 100644 index 000000000..5529a0741 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.userserver.modules.system.enums.sms; + +/** + * yudao-user-server 使用到的短信模板的 Code 编码的枚举 + * + * @author 芋道源码 + */ +public interface SysSmsTemplateCodeConstants { + + /** + * 前台用户短信登录 + */ + String USER_SMS_LOGIN = "user-sms-login"; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/package-info.java new file mode 100644 index 000000000..cb0def51f --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/package-info.java @@ -0,0 +1,6 @@ +/** + * 属于 system 模块的 framework 封装 + * + * @author 芋道源码 + */ +package cn.iocoder.yudao.userserver.modules.system.framework; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeConfiguration.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeConfiguration.java new file mode 100644 index 000000000..a4510ea47 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeConfiguration.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.userserver.modules.system.framework.sms; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(SmsCodeProperties.class) +public class SmsCodeConfiguration { +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeProperties.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeProperties.java new file mode 100644 index 000000000..b600c28dc --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeProperties.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.userserver.modules.system.framework.sms; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.time.Duration; +import java.util.Collection; + +@ConfigurationProperties(prefix = "yudao.sms-code") +@Validated +@Data +public class SmsCodeProperties { + + /** + * 过期时间 + */ + @NotNull(message = "过期时间不能为空") + private Duration expireTimes; + /** + * 短信发送频率 + */ + @NotNull(message = "短信发送频率不能为空") + private Duration sendFrequency; + /** + * 每日发送最大数量 + */ + @NotNull(message = "每日发送最大数量不能为空") + private Integer sendMaximumQuantityPerDay; + /** + * 验证码最小值 + */ + @NotNull(message = "验证码最小值不能为空") + private Integer beginCode; + /** + * 验证码最大值 + */ + @NotNull(message = "验证码最大值不能为空") + private Integer endCode; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java new file mode 100644 index 000000000..b35d1c27a --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.userserver.modules.system.service.auth; + +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthSmsLoginReqVO; + +import javax.validation.Valid; + +/** + * 用户前台的认证 Service 接口 + * + * 提供用户的账号密码登录、token 的校验等认证相关的功能 + * + * @author 芋道源码 + */ +public interface SysAuthService extends SecurityAuthFrameworkService { + + /** + * 手机 + 密码登录 + * + * @param reqVO 登录信息 + * @param userIp 用户 IP + * @param userAgent 用户 UA + * @return 身份令牌,使用 JWT 方式 + */ + String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); + + /** + * 手机 + 验证码登陆 + * + * @param reqVO 登陆信息 + * @param userIp 用户 IP + * @param userAgent 用户 UA + * @return 身份令牌,使用 JWT 方式 + */ + String smsLogin(@Valid SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent); + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java new file mode 100644 index 000000000..0199c078e --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -0,0 +1,218 @@ +package cn.iocoder.yudao.userserver.modules.system.service.auth.impl; + +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +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.member.service.user.MbrUserService; +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthSmsLoginReqVO; +import cn.iocoder.yudao.userserver.modules.system.convert.auth.SysAuthConvert; +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; +import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Objects; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; + +/** + * Auth Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Slf4j +public class SysAuthServiceImpl implements SysAuthService { + + @Resource + @Lazy // 延迟加载,因为存在相互依赖的问题 + private AuthenticationManager authenticationManager; + + @Resource + private MbrUserService userService; + @Resource + private SysSmsCodeService smsCodeService; + @Resource + private SysLoginLogCoreService loginLogCoreService; + @Resource + private SysUserSessionCoreService userSessionCoreService; + + @Override + public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { + // 获取 username 对应的 SysUserDO + MbrUserDO user = userService.getUserByMobile(mobile); + if (user == null) { + throw new UsernameNotFoundException(mobile); + } + // 创建 LoginUser 对象 + return SysAuthConvert.INSTANCE.convert(user); + } + + @Override + public String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent) { + // 使用手机 + 密码,进行登录。 + LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); + + // 缓存登录用户到 Redis 中,返回 sessionId 编号 + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); + } + + @Override + @Transactional + public String smsLogin(SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent) { + // 校验验证码 + smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(), + reqVO.getCode(), userIp); + + // 获得获得注册用户 + MbrUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp); + Assert.notNull(user, "获取用户失败,结果为空"); + + // 执行登陆 + this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SMS, SysLoginResultEnum.SUCCESS); + LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); + + // 缓存登录用户到 Redis 中,返回 sessionId 编号 + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); + } + + private LoginUser login0(String username, String password) { + final SysLoginLogTypeEnum logTypeEnum = SysLoginLogTypeEnum.LOGIN_USERNAME; + // 用户验证 + Authentication authentication; + try { + // 调用 Spring Security 的 AuthenticationManager#authenticate(...) 方法,使用账号密码进行认证 + // 在其内部,会调用到 loadUserByUsername 方法,获取 User 信息 + authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); + } catch (BadCredentialsException badCredentialsException) { + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.BAD_CREDENTIALS); + throw exception(AUTH_LOGIN_BAD_CREDENTIALS); + } catch (DisabledException disabledException) { + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.USER_DISABLED); + throw exception(AUTH_LOGIN_USER_DISABLED); + } catch (AuthenticationException authenticationException) { + log.error("[login0][username({}) 发生未知异常]", username, authenticationException); + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); + throw exception(AUTH_LOGIN_FAIL_UNKNOWN); + } + // 登录成功的日志 + Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.SUCCESS); + return (LoginUser) authentication.getPrincipal(); + } + + private void createLoginLog(String mobile, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { + // 获得用户 + MbrUserDO user = userService.getUserByMobile(mobile); + // 插入登录日志 + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); + reqDTO.setLogType(logTypeEnum.getType()); + reqDTO.setTraceId(TracerUtils.getTraceId()); + if (user != null) { + reqDTO.setUserId(user.getId()); + } + reqDTO.setUsername(mobile); + reqDTO.setUserAgent(ServletUtils.getUserAgent()); + reqDTO.setUserIp(ServletUtils.getClientIP()); + reqDTO.setResult(loginResult.getResult()); + loginLogCoreService.createLoginLog(reqDTO); + // 更新最后登录时间 + if (user != null && Objects.equals(SysLoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) { + userService.updateUserLogin(user.getId(), ServletUtils.getClientIP()); + } + } + + @Override + public LoginUser verifyTokenAndRefresh(String token) { + // 获得 LoginUser + LoginUser loginUser = userSessionCoreService.getLoginUser(token); + if (loginUser == null) { + return null; + } + // 刷新 LoginUser 缓存 + this.refreshLoginUserCache(token, loginUser); + return loginUser; + } + + private void refreshLoginUserCache(String token, LoginUser loginUser) { + // 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存 + if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() < + userSessionCoreService.getSessionTimeoutMillis() / 3) { + return; + } + + // 重新加载 MbrUserDO 信息 + MbrUserDO user = userService.getUser(loginUser.getId()); + if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { + throw exception(AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 + } + + // 刷新 LoginUser 缓存 + userSessionCoreService.refreshUserSession(token, loginUser); + } + + @Override + public LoginUser mockLogin(Long userId) { + // 获取用户编号对应的 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 + public void logout(String token) { + // 查询用户信息 + LoginUser loginUser = userSessionCoreService.getLoginUser(token); + if (loginUser == null) { + return; + } + // 删除 session + userSessionCoreService.deleteUserSession(token); + // 记录登出日志 + this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); + } + + private void createLogoutLog(Long userId, String username) { + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); + reqDTO.setTraceId(TracerUtils.getTraceId()); + reqDTO.setUserId(userId); + reqDTO.setUserType(UserTypeEnum.MEMBER.getValue()); + reqDTO.setUsername(username); + reqDTO.setUserAgent(ServletUtils.getUserAgent()); + reqDTO.setUserIp(ServletUtils.getClientIP()); + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); + loginLogCoreService.createLoginLog(reqDTO); + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/package-info.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/package-info.java index 34d162dc3..d1896cb92 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/package-info.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/package-info.java @@ -1 +1 @@ -package cn.iocoder.yudao.userserver.modules.system.service; \ No newline at end of file +package cn.iocoder.yudao.userserver.modules.system.service; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/SysSmsCodeService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/SysSmsCodeService.java new file mode 100644 index 000000000..5ee81b67c --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/SysSmsCodeService.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.userserver.modules.system.service.sms; + +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.framework.common.validation.Mobile; +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; + +/** + * 短信验证码 Service 接口 + * + * @author 芋道源码 + */ +public interface SysSmsCodeService { + + /** + * 创建短信验证码,并进行发送 + * + * @param mobile 手机号 + * @param scene 发送场景 {@link SysSmsSceneEnum} + * @param createIp 发送 IP + */ + void sendSmsCode(@Mobile String mobile, Integer scene, String createIp); + + /** + * 验证短信验证码,并进行使用 + * 如果正确,则将验证码标记成已使用 + * 如果错误,则抛出 {@link ServiceException} 异常 + * + * @param mobile 手机号 + * @param scene 发送场景 + * @param code 验证码 + * @param usedIp 使用 IP + */ + void useSmsCode(@Mobile String mobile, Integer scene, String code, String usedIp); + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java new file mode 100644 index 000000000..6ad132aa5 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java @@ -0,0 +1,94 @@ +package cn.iocoder.yudao.userserver.modules.system.service.sms.impl; + +import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; +import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; +import cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms.SysSmsCodeMapper; +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsTemplateCodeConstants; +import cn.iocoder.yudao.userserver.modules.system.framework.sms.SmsCodeProperties; +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Date; + +import static cn.hutool.core.util.RandomUtil.randomInt; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; + +/** + * 短信验证码 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SysSmsCodeServiceImpl implements SysSmsCodeService { + + @Resource + private SmsCodeProperties smsCodeProperties; + + @Resource + private SysSmsCodeMapper smsCodeMapper; + + @Resource + private SysSmsCoreService smsCoreService; + + @Override + public void sendSmsCode(String mobile, Integer scene, String createIp) { + // 创建验证码 + String code = this.createSmsCode(mobile, scene, createIp); + // 发送验证码 + smsCoreService.sendSingleSmsToMember(mobile, null, SysSmsTemplateCodeConstants.USER_SMS_LOGIN, + MapUtil.of("code", code)); + } + + private String createSmsCode(String mobile, Integer scene, String ip) { + // 校验是否可以发送验证码,不用筛选场景 + SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null); + if (lastSmsCode != null) { + if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 + throw exception(USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); + } + if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() + < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 + throw exception(USER_SMS_CODE_SEND_TOO_FAST); + } + // TODO 芋艿:提升,每个 IP 每天可发送数量 + // TODO 芋艿:提升,每个 IP 每小时可发送数量 + } + + // 创建验证码记录 + String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1)); + SysSmsCodeDO newSmsCode = SysSmsCodeDO.builder().mobile(mobile).code(code) + .scene(scene).todayIndex(lastSmsCode != null ? lastSmsCode.getTodayIndex() + 1 : 1) + .createIp(ip).used(false).build(); + smsCodeMapper.insert(newSmsCode); + return code; + } + + @Override + public void useSmsCode(String mobile, Integer scene, String code, String usedIp) { + // 校验验证码 + SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, scene); + if (lastSmsCode == null) { // 若验证码不存在,抛出异常 + throw exception(USER_SMS_CODE_NOT_FOUND); + } + if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() + >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 + throw exception(USER_SMS_CODE_EXPIRED); + } + if (lastSmsCode.getUsed()) { // 验证码已使用 + throw exception(USER_SMS_CODE_USED); + } + if (!lastSmsCode.getCode().equals(code)) { + throw exception(USER_SMS_CODE_NOT_CORRECT); + } + + // 使用验证码 + smsCodeMapper.updateById(SysSmsCodeDO.builder().id(lastSmsCode.getId()) + .used(true).usedTime(new Date()).usedIp(usedIp).build()); + } + +} diff --git a/yudao-user-server/src/main/resources/application-dev.yaml b/yudao-user-server/src/main/resources/application-dev.yaml index b85826169..b6bfbd1dd 100644 --- a/yudao-user-server/src/main/resources/application-dev.yaml +++ b/yudao-user-server/src/main/resources/application-dev.yaml @@ -72,7 +72,7 @@ apollo: eagerLoad: enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 - dao: cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config.InfConfigDAOImpl + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl url: ${spring.datasource.dynamic.datasource.master.url} username: ${spring.datasource.dynamic.datasource.master.username} password: ${spring.datasource.dynamic.datasource.master.password} diff --git a/yudao-user-server/src/main/resources/application-local.yaml b/yudao-user-server/src/main/resources/application-local.yaml index 927c17e17..506ee19f6 100644 --- a/yudao-user-server/src/main/resources/application-local.yaml +++ b/yudao-user-server/src/main/resources/application-local.yaml @@ -72,7 +72,7 @@ apollo: eagerLoad: enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 - dao: cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config.InfConfigDAOImpl + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl url: ${spring.datasource.dynamic.datasource.master.url} username: ${spring.datasource.dynamic.datasource.master.username} password: ${spring.datasource.dynamic.datasource.master.password} diff --git a/yudao-user-server/src/main/resources/application.yaml b/yudao-user-server/src/main/resources/application.yaml index 573a9a5e1..4e1d1f279 100644 --- a/yudao-user-server/src/main/resources/application.yaml +++ b/yudao-user-server/src/main/resources/application.yaml @@ -31,7 +31,7 @@ mybatis-plus: logic-delete-value: 1 # 逻辑已删除值(默认为 1) logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) mapper-locations: classpath*:mapper/*.xml - type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject + type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject --- #################### 芋道相关配置 #################### @@ -39,6 +39,8 @@ yudao: info: version: 1.0.0 base-package: cn.iocoder.yudao.userserver + core-service: + base-package: cn.iocoder.yudao.coreservice web: api-prefix: /api controller-package: ${yudao.info.base-package} @@ -56,5 +58,13 @@ yudao: db-schemas: ${spring.datasource.dynamic.datasource.master.name} error-code: # 错误码相关配置项 constants-class-list: + - cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants + - cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants + sms-code: # 短信验证码相关的配置项 + expire-times: 10m + send-frequency: 1m + send-maximum-quantity-per-day: 10 + begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 + end-code: 9999 # 这里配置 9999 的原因是,测试方便。 debug: false diff --git a/更新日志.md b/更新日志.md index bcf809395..206599b25 100644 --- a/更新日志.md +++ b/更新日志.md @@ -7,10 +7,20 @@ * 工作流 -## [v1.1.0] 待定 +## [v1.1.1] 待定 * 支付 -* 三方平台接入 +* 用户前台的社交登陆 + +## [v1.1.0] 进行中 + +* 新增管理后台的企业微信、钉钉等社交登录 +* 新增用户前台(例如说,用户使用的小程序)的后端项目 `yudao-user-server` +* 新增公共服务 `yudao-core-service` 项目,通过 Jar 包的方式,提供 `yudao-user-server` 和 `yudao-admin-server` 的共享逻辑的复用 +* 新增用户前台的手机登录、验证码登录 +* 修复管理后台的用户头像上传 404 的问题,原因是请求路径不对 +* 修复用户导入失败的问题,原因是 Lombok 链式与 cglib 读取属性有冲突 +* 修复阿里云短信发送失败的问题,原因是 Opentracing 依赖的版本太低,调整成 0.31.0 ## [v1.0.0] 2021.05.03