Commit ceef984d15c79a0f4aa8d14d6228365d28ec8afa
Merge remote-tracking branch 'origin/master'
Showing
267 changed files
with
3571 additions
and
2130 deletions
README.md
| @@ -88,6 +88,9 @@ | @@ -88,6 +88,9 @@ | ||
| 88 | | `yudao-admin-ui` | 管理后台的 UI 界面 | | 88 | | `yudao-admin-ui` | 管理后台的 UI 界面 | |
| 89 | | `yudao-user-server` | 用户前台的服务端 | | 89 | | `yudao-user-server` | 用户前台的服务端 | |
| 90 | | `yudao-user-ui` | 用户前台的 UI 界面 | | 90 | | `yudao-user-ui` | 用户前台的 UI 界面 | |
| 91 | +| `yudao-core-service` | 公共服务,提供共享逻辑 | | ||
| 92 | + | ||
| 93 | +> 友情提示:`yudao-admin-server` 和 `yudao-user-server` 会存在需要复用的逻辑,通过 `yudao-core-service` 实现。 | ||
| 91 | 94 | ||
| 92 | ### 后端 | 95 | ### 后端 |
| 93 | 96 |
http-client.env.json
pom.xml
| @@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
| 12 | <module>yudao-framework</module> | 12 | <module>yudao-framework</module> |
| 13 | <module>yudao-admin-server</module> | 13 | <module>yudao-admin-server</module> |
| 14 | <module>yudao-user-server</module> | 14 | <module>yudao-user-server</module> |
| 15 | + <module>yudao-core-service</module> | ||
| 15 | </modules> | 16 | </modules> |
| 16 | 17 | ||
| 17 | <name>${artifactId}</name> | 18 | <name>${artifactId}</name> |
yudao-admin-server/pom.xml
| @@ -20,6 +20,11 @@ | @@ -20,6 +20,11 @@ | ||
| 20 | <!-- 业务组件 --> | 20 | <!-- 业务组件 --> |
| 21 | <dependency> | 21 | <dependency> |
| 22 | <groupId>cn.iocoder.boot</groupId> | 22 | <groupId>cn.iocoder.boot</groupId> |
| 23 | + <artifactId>yudao-core-service</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + | ||
| 26 | + <dependency> | ||
| 27 | + <groupId>cn.iocoder.boot</groupId> | ||
| 23 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> | 28 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> |
| 24 | </dependency> | 29 | </dependency> |
| 25 | <dependency> | 30 | <dependency> |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java
| @@ -3,7 +3,8 @@ package cn.iocoder.yudao.adminserver; | @@ -3,7 +3,8 @@ package cn.iocoder.yudao.adminserver; | ||
| 3 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | 5 | ||
| 6 | -@SpringBootApplication | 6 | +@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} |
| 7 | +@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}) | ||
| 7 | public class AdminServerApplication { | 8 | public class AdminServerApplication { |
| 8 | 9 | ||
| 9 | public static void main(String[] args) { | 10 | public static void main(String[] args) { |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/config/InfConfigController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.config; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.config; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 7 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*; |
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; |
| 11 | import io.swagger.annotations.Api; | 11 | import io.swagger.annotations.Api; |
| 12 | import io.swagger.annotations.ApiImplicitParam; | 12 | import io.swagger.annotations.ApiImplicitParam; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/file/InfFileController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.file; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.IoUtil; | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; |
| 11 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | 11 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 12 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiAccessLogController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccess | @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccess | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; | 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; |
| 14 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/logger/InfApiErrorLogController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.controller.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorl | @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorl | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; | 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; |
| 14 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiImplicitParam; | 15 | import io.swagger.annotations.ApiImplicitParam; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/config/InfConfigConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.config; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.config; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigRespVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigRespVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 9 | import org.mapstruct.Mapper; | 9 | import org.mapstruct.Mapper; |
| 10 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 11 | 11 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/file/InfFileConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.file; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFileRespVO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 6 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
| 7 | import org.mapstruct.factory.Mappers; | 7 | import org.mapstruct.factory.Mappers; |
| 8 | 8 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiAccessLogConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | 5 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExcelVO; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 8 | import org.mapstruct.Mapper; | 8 | import org.mapstruct.Mapper; |
| 9 | import org.mapstruct.factory.Mappers; | 9 | import org.mapstruct.factory.Mappers; |
| 10 | 10 | ||
| @@ -20,8 +20,6 @@ public interface InfApiAccessLogConvert { | @@ -20,8 +20,6 @@ public interface InfApiAccessLogConvert { | ||
| 20 | 20 | ||
| 21 | InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class); | 21 | InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class); |
| 22 | 22 | ||
| 23 | - InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); | ||
| 24 | - | ||
| 25 | InfApiAccessLogRespVO convert(InfApiAccessLogDO bean); | 23 | InfApiAccessLogRespVO convert(InfApiAccessLogDO bean); |
| 26 | 24 | ||
| 27 | List<InfApiAccessLogRespVO> convertList(List<InfApiAccessLogDO> list); | 25 | List<InfApiAccessLogRespVO> convertList(List<InfApiAccessLogDO> list); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/convert/logger/InfApiErrorLogConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.convert.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 8 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 9 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 10 | 9 | ||
| @@ -20,8 +19,6 @@ public interface InfApiErrorLogConvert { | @@ -20,8 +19,6 @@ public interface InfApiErrorLogConvert { | ||
| 20 | 19 | ||
| 21 | InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); | 20 | InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); |
| 22 | 21 | ||
| 23 | - InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); | ||
| 24 | - | ||
| 25 | InfApiErrorLogRespVO convert(InfApiErrorLogDO bean); | 22 | InfApiErrorLogRespVO convert(InfApiErrorLogDO bean); |
| 26 | 23 | ||
| 27 | PageResult<InfApiErrorLogRespVO> convertPage(PageResult<InfApiErrorLogDO> page); | 24 | PageResult<InfApiErrorLogRespVO> convertPage(PageResult<InfApiErrorLogDO> page); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/config/InfConfigDO.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | -import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.TableField; | ||
| 6 | -import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | -import lombok.Data; | ||
| 9 | -import lombok.EqualsAndHashCode; | ||
| 10 | -import lombok.ToString; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * 参数配置表 | ||
| 14 | - * | ||
| 15 | - * @author ruoyi | ||
| 16 | - */ | ||
| 17 | -@TableName("inf_config") | ||
| 18 | -@Data | ||
| 19 | -@EqualsAndHashCode(callSuper = true) | ||
| 20 | -@ToString(callSuper = true) | ||
| 21 | -public class InfConfigDO extends BaseDO { | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * 参数主键 | ||
| 25 | - */ | ||
| 26 | - @TableId | ||
| 27 | - private Long id; | ||
| 28 | - /** | ||
| 29 | - * 参数分组 | ||
| 30 | - */ | ||
| 31 | - @TableField("`group`") | ||
| 32 | - private String group; | ||
| 33 | - /** | ||
| 34 | - * 参数名称 | ||
| 35 | - */ | ||
| 36 | - private String name; | ||
| 37 | - /** | ||
| 38 | - * 参数键名 | ||
| 39 | - */ | ||
| 40 | - @TableField("`key`") | ||
| 41 | - private String key; | ||
| 42 | - /** | ||
| 43 | - * 参数键值 | ||
| 44 | - */ | ||
| 45 | - private String value; | ||
| 46 | - /** | ||
| 47 | - * 参数类型 | ||
| 48 | - * | ||
| 49 | - * 枚举 {@link InfConfigTypeEnum} | ||
| 50 | - */ | ||
| 51 | - @TableField("`type`") | ||
| 52 | - private Integer type; | ||
| 53 | - /** | ||
| 54 | - * 是否敏感 | ||
| 55 | - * | ||
| 56 | - * 对于敏感配置,需要管理权限才能查看 | ||
| 57 | - */ | ||
| 58 | - @TableField("`sensitive`") | ||
| 59 | - private Boolean sensitive; | ||
| 60 | - /** | ||
| 61 | - * 备注 | ||
| 62 | - */ | ||
| 63 | - private String remark; | ||
| 64 | - | ||
| 65 | -} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 5 | -import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | ||
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | -import lombok.*; | ||
| 9 | - | ||
| 10 | -import java.util.Date; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * API 异常数据 | ||
| 14 | - * | ||
| 15 | - * @author 芋道源码 | ||
| 16 | - */ | ||
| 17 | -@TableName("inf_api_error_log") | ||
| 18 | -@Data | ||
| 19 | -@EqualsAndHashCode(callSuper = true) | ||
| 20 | -@ToString(callSuper = true) | ||
| 21 | -@Builder | ||
| 22 | -@NoArgsConstructor | ||
| 23 | -@AllArgsConstructor | ||
| 24 | -public class InfApiErrorLogDO extends BaseDO { | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * 编号 | ||
| 28 | - */ | ||
| 29 | - private Long id; | ||
| 30 | - /** | ||
| 31 | - * 用户编号 | ||
| 32 | - */ | ||
| 33 | - private Long userId; | ||
| 34 | - /** | ||
| 35 | - * 链路追踪编号 | ||
| 36 | - * | ||
| 37 | - * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。 | ||
| 38 | - */ | ||
| 39 | - private String traceId; | ||
| 40 | - /** | ||
| 41 | - * 用户类型 | ||
| 42 | - * | ||
| 43 | - * 枚举 {@link UserTypeEnum} | ||
| 44 | - */ | ||
| 45 | - private Integer userType; | ||
| 46 | - /** | ||
| 47 | - * 应用名 | ||
| 48 | - * | ||
| 49 | - * 目前读取 spring.application.name | ||
| 50 | - */ | ||
| 51 | - private String applicationName; | ||
| 52 | - | ||
| 53 | - // ========== 请求相关字段 ========== | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * 请求方法名 | ||
| 57 | - */ | ||
| 58 | - private String requestMethod; | ||
| 59 | - /** | ||
| 60 | - * 访问地址 | ||
| 61 | - */ | ||
| 62 | - private String requestUrl; | ||
| 63 | - /** | ||
| 64 | - * 请求参数 | ||
| 65 | - * | ||
| 66 | - * query: Query String | ||
| 67 | - * body: Quest Body | ||
| 68 | - */ | ||
| 69 | - private String requestParams; | ||
| 70 | - /** | ||
| 71 | - * 用户 IP | ||
| 72 | - */ | ||
| 73 | - private String userIp; | ||
| 74 | - /** | ||
| 75 | - * 浏览器 UA | ||
| 76 | - */ | ||
| 77 | - private String userAgent; | ||
| 78 | - | ||
| 79 | - // ========== 异常相关字段 ========== | ||
| 80 | - | ||
| 81 | - /** | ||
| 82 | - * 异常发生时间 | ||
| 83 | - */ | ||
| 84 | - private Date exceptionTime; | ||
| 85 | - /** | ||
| 86 | - * 异常名 | ||
| 87 | - * | ||
| 88 | - * {@link Throwable#getClass()} 的类全名 | ||
| 89 | - */ | ||
| 90 | - private String exceptionName; | ||
| 91 | - /** | ||
| 92 | - * 异常导致的消息 | ||
| 93 | - * | ||
| 94 | - * {@link cn.hutool.core.exceptions.ExceptionUtil#getMessage(Throwable)} | ||
| 95 | - */ | ||
| 96 | - private String exceptionMessage; | ||
| 97 | - /** | ||
| 98 | - * 异常导致的根消息 | ||
| 99 | - * | ||
| 100 | - * {@link cn.hutool.core.exceptions.ExceptionUtil#getRootCauseMessage(Throwable)} | ||
| 101 | - */ | ||
| 102 | - private String exceptionRootCauseMessage; | ||
| 103 | - /** | ||
| 104 | - * 异常的栈轨迹 | ||
| 105 | - * | ||
| 106 | - * {@link org.apache.commons.lang3.exception.ExceptionUtils#getStackTrace(Throwable)} | ||
| 107 | - */ | ||
| 108 | - private String exceptionStackTrace; | ||
| 109 | - /** | ||
| 110 | - * 异常发生的类全名 | ||
| 111 | - * | ||
| 112 | - * {@link StackTraceElement#getClassName()} | ||
| 113 | - */ | ||
| 114 | - private String exceptionClassName; | ||
| 115 | - /** | ||
| 116 | - * 异常发生的类文件 | ||
| 117 | - * | ||
| 118 | - * {@link StackTraceElement#getFileName()} | ||
| 119 | - */ | ||
| 120 | - private String exceptionFileName; | ||
| 121 | - /** | ||
| 122 | - * 异常发生的方法名 | ||
| 123 | - * | ||
| 124 | - * {@link StackTraceElement#getMethodName()} | ||
| 125 | - */ | ||
| 126 | - private String exceptionMethodName; | ||
| 127 | - /** | ||
| 128 | - * 异常发生的方法所在行 | ||
| 129 | - * | ||
| 130 | - * {@link StackTraceElement#getLineNumber()} | ||
| 131 | - */ | ||
| 132 | - private Integer exceptionLineNumber; | ||
| 133 | - | ||
| 134 | - // ========== 处理相关字段 ========== | ||
| 135 | - | ||
| 136 | - /** | ||
| 137 | - * 处理状态 | ||
| 138 | - * | ||
| 139 | - * 枚举 {@link InfApiErrorLogProcessStatusEnum} | ||
| 140 | - */ | ||
| 141 | - private Integer processStatus; | ||
| 142 | - /** | ||
| 143 | - * 处理时间 | ||
| 144 | - */ | ||
| 145 | - private Date processTime; | ||
| 146 | - /** | ||
| 147 | - * 处理用户编号 | ||
| 148 | - * | ||
| 149 | - * 关联 {@link SysUserDO#getId()} | ||
| 150 | - */ | ||
| 151 | - private Long processUserId; | ||
| 152 | - | ||
| 153 | -} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/file/InfFileMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | @Mapper | 10 | @Mapper |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; | ||
| 4 | +import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 8 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 9 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 9 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 9 | 9 | ||
| 10 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 11 | import java.util.List; | 11 | import java.util.List; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/impl/InfConfigServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 4 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; | 6 | 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 | @@ -8,7 +9,6 @@ import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfig | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; |
| 13 | import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; | 13 | import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; |
| 14 | import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; | 14 | import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * 文件 Service 接口 | 8 | * 文件 Service 接口 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/impl/InfFileServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.FileTypeUtil; | 3 | import cn.hutool.core.io.FileTypeUtil; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; |
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; |
| 10 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiAccessLogService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | 7 | ||
| 9 | import java.util.List; | 8 | import java.util.List; |
| 10 | 9 | ||
| @@ -13,7 +12,7 @@ import java.util.List; | @@ -13,7 +12,7 @@ import java.util.List; | ||
| 13 | * | 12 | * |
| 14 | * @author 芋道源码 | 13 | * @author 芋道源码 |
| 15 | */ | 14 | */ |
| 16 | -public interface InfApiAccessLogService extends ApiAccessLogFrameworkService { | 15 | +public interface InfApiAccessLogService { |
| 17 | 16 | ||
| 18 | /** | 17 | /** |
| 19 | * 获得 API 访问日志分页 | 18 | * 获得 API 访问日志分页 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/InfApiErrorLogService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | 7 | ||
| 9 | import java.util.List; | 8 | import java.util.List; |
| 10 | 9 | ||
| @@ -13,7 +12,7 @@ import java.util.List; | @@ -13,7 +12,7 @@ import java.util.List; | ||
| 13 | * | 12 | * |
| 14 | * @author 芋道源码 | 13 | * @author 芋道源码 |
| 15 | */ | 14 | */ |
| 16 | -public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { | 15 | +public interface InfApiErrorLogService { |
| 17 | 16 | ||
| 18 | /** | 17 | /** |
| 19 | * 获得 API 错误日志分页 | 18 | * 获得 API 错误日志分页 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService; |
| 11 | -import org.springframework.scheduling.annotation.Async; | ||
| 12 | -import org.springframework.scheduling.annotation.AsyncResult; | 7 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 13 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 14 | import org.springframework.validation.annotation.Validated; | 10 | import org.springframework.validation.annotation.Validated; |
| 15 | 11 | ||
| 16 | import javax.annotation.Resource; | 12 | import javax.annotation.Resource; |
| 17 | import java.util.List; | 13 | import java.util.List; |
| 18 | -import java.util.concurrent.Future; | ||
| 19 | 14 | ||
| 20 | /** | 15 | /** |
| 21 | * API 访问日志 Service 实现类 | 16 | * API 访问日志 Service 实现类 |
| @@ -30,14 +25,6 @@ public class InfApiAccessLogServiceImpl implements InfApiAccessLogService { | @@ -30,14 +25,6 @@ public class InfApiAccessLogServiceImpl implements InfApiAccessLogService { | ||
| 30 | private InfApiAccessLogMapper apiAccessLogMapper; | 25 | private InfApiAccessLogMapper apiAccessLogMapper; |
| 31 | 26 | ||
| 32 | @Override | 27 | @Override |
| 33 | - @Async | ||
| 34 | - public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { | ||
| 35 | - InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO); | ||
| 36 | - int insert = apiAccessLogMapper.insert(apiAccessLog); | ||
| 37 | - return new AsyncResult<>(insert > 1); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | public PageResult<InfApiAccessLogDO> getApiAccessLogPage(InfApiAccessLogPageReqVO pageReqVO) { | 28 | public PageResult<InfApiAccessLogDO> getApiAccessLogPage(InfApiAccessLogPageReqVO pageReqVO) { |
| 42 | return apiAccessLogMapper.selectPage(pageReqVO); | 29 | return apiAccessLogMapper.selectPage(pageReqVO); |
| 43 | } | 30 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; | 5 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; |
| 11 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService; |
| 12 | -import org.springframework.scheduling.annotation.Async; | ||
| 13 | -import org.springframework.scheduling.annotation.AsyncResult; | 8 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 14 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 15 | import org.springframework.validation.annotation.Validated; | 11 | import org.springframework.validation.annotation.Validated; |
| 16 | 12 | ||
| 17 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 18 | import java.util.Date; | 14 | import java.util.Date; |
| 19 | import java.util.List; | 15 | import java.util.List; |
| 20 | -import java.util.concurrent.Future; | ||
| 21 | 16 | ||
| 22 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 23 | import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND; | 17 | import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND; |
| 24 | import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED; | 18 | import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED; |
| 19 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 25 | 20 | ||
| 26 | /** | 21 | /** |
| 27 | * API 错误日志 Service 实现类 | 22 | * API 错误日志 Service 实现类 |
| @@ -36,15 +31,6 @@ public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { | @@ -36,15 +31,6 @@ public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { | ||
| 36 | private InfApiErrorLogMapper apiErrorLogMapper; | 31 | private InfApiErrorLogMapper apiErrorLogMapper; |
| 37 | 32 | ||
| 38 | @Override | 33 | @Override |
| 39 | - @Async | ||
| 40 | - public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { | ||
| 41 | - InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); | ||
| 42 | - apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); | ||
| 43 | - int insert = apiErrorLogMapper.insert(apiErrorLog); | ||
| 44 | - return new AsyncResult<>(insert == 1); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - @Override | ||
| 48 | public PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO) { | 34 | public PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO) { |
| 49 | return apiErrorLogMapper.selectPage(pageReqVO); | 35 | return apiErrorLogMapper.selectPage(pageReqVO); |
| 50 | } | 36 | } |
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.*; | @@ -4,13 +4,13 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; | 4 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuTypeEnum; | 7 | import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuTypeEnum; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; |
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 14 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 14 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 15 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 15 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 16 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | 16 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| @@ -43,7 +43,7 @@ public class SysAuthController { | @@ -43,7 +43,7 @@ public class SysAuthController { | ||
| 43 | @Resource | 43 | @Resource |
| 44 | private SysAuthService authService; | 44 | private SysAuthService authService; |
| 45 | @Resource | 45 | @Resource |
| 46 | - private SysUserService userService; | 46 | + private SysUserCoreService userCoreService; |
| 47 | @Resource | 47 | @Resource |
| 48 | private SysRoleService roleService; | 48 | private SysRoleService roleService; |
| 49 | @Resource | 49 | @Resource |
| @@ -64,7 +64,7 @@ public class SysAuthController { | @@ -64,7 +64,7 @@ public class SysAuthController { | ||
| 64 | @ApiOperation("获取登录用户的权限信息") | 64 | @ApiOperation("获取登录用户的权限信息") |
| 65 | public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() { | 65 | public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() { |
| 66 | // 获得用户信息 | 66 | // 获得用户信息 |
| 67 | - SysUserDO user = userService.getUser(getLoginUserId()); | 67 | + SysUserDO user = userCoreService.getUser(getLoginUserId()); |
| 68 | if (user == null) { | 68 | if (user == null) { |
| 69 | return null; | 69 | return null; |
| 70 | } | 70 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysUserSessionController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.auth; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysUserSessionConvert; | 5 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysUserSessionConvert; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; | 7 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 14 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 15 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 15 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 16 | import io.swagger.annotations.ApiImplicitParam; | 17 | import io.swagger.annotations.ApiImplicitParam; |
| @@ -35,6 +36,8 @@ public class SysUserSessionController { | @@ -35,6 +36,8 @@ public class SysUserSessionController { | ||
| 35 | @Resource | 36 | @Resource |
| 36 | private SysUserSessionService userSessionService; | 37 | private SysUserSessionService userSessionService; |
| 37 | @Resource | 38 | @Resource |
| 39 | + private SysUserSessionCoreService userSessionCoreService; | ||
| 40 | + @Resource | ||
| 38 | private SysUserService userService; | 41 | private SysUserService userService; |
| 39 | @Resource | 42 | @Resource |
| 40 | private SysDeptService deptService; | 43 | private SysDeptService deptService; |
| @@ -72,7 +75,7 @@ public class SysUserSessionController { | @@ -72,7 +75,7 @@ public class SysUserSessionController { | ||
| 72 | example = "fe50b9f6-d177-44b1-8da9-72ea34f63db7") | 75 | example = "fe50b9f6-d177-44b1-8da9-72ea34f63db7") |
| 73 | @PreAuthorize("@ss.hasPermission('system:user-session:delete')") | 76 | @PreAuthorize("@ss.hasPermission('system:user-session:delete')") |
| 74 | public CommonResult<Boolean> deleteUserSession(@RequestParam("id") String id) { | 77 | public CommonResult<Boolean> deleteUserSession(@RequestParam("id") String id) { |
| 75 | - userSessionService.deleteUserSession(id); | 78 | + userSessionCoreService.deleteUserSession(id); |
| 76 | return success(true); | 79 | return success(true); |
| 77 | } | 80 | } |
| 78 | 81 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dict/SysDictDataController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 7 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; | 9 | import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; |
| 11 | import io.swagger.annotations.Api; | 11 | import io.swagger.annotations.Api; |
| 12 | import io.swagger.annotations.ApiImplicitParam; | 12 | import io.swagger.annotations.ApiImplicitParam; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog | @@ -9,7 +10,6 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; | 11 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysLoginLogConvert; | 12 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysLoginLogConvert; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; | 13 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; |
| 14 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysOperateLogController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 6 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; | 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; |
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; |
| 15 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 14 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 17 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 15 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 16 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 17 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 18 | import io.swagger.annotations.Api; | 18 | import io.swagger.annotations.Api; |
| 19 | import io.swagger.annotations.ApiOperation; | 19 | import io.swagger.annotations.ApiOperation; |
| 20 | import org.springframework.security.access.prepost.PreAuthorize; | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog; | ||
| 2 | - | ||
| 3 | -import io.swagger.annotations.ApiModel; | ||
| 4 | -import lombok.Data; | ||
| 5 | -import lombok.EqualsAndHashCode; | ||
| 6 | -import lombok.ToString; | ||
| 7 | - | ||
| 8 | -@ApiModel(value = "登录日志创建 Request VO", | ||
| 9 | - description = "暂时提供给前端,仅仅后端记录登录日志时,进行使用") | ||
| 10 | -@Data | ||
| 11 | -@EqualsAndHashCode(callSuper = true) | ||
| 12 | -@ToString(callSuper = true) | ||
| 13 | -public class SysLoginLogCreateReqVO extends SysLoginLogBaseVO { | ||
| 14 | -} |
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; | @@ -2,10 +2,10 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.sms; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.URLUtil; | 3 | import cn.hutool.core.util.URLUtil; |
| 4 | import cn.hutool.extra.servlet.ServletUtil; | 4 | import cn.hutool.extra.servlet.ServletUtil; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 7 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | import cn.iocoder.yudao.framework.sms.core.enums.SmsChannelEnum; | 8 | import cn.iocoder.yudao.framework.sms.core.enums.SmsChannelEnum; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; | ||
| 9 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
| 10 | import io.swagger.annotations.ApiImplicitParam; | 10 | import io.swagger.annotations.ApiImplicitParam; |
| 11 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
| @@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | @@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 25 | public class SmsCallbackController { | 25 | public class SmsCallbackController { |
| 26 | 26 | ||
| 27 | @Resource | 27 | @Resource |
| 28 | - private SysSmsService smsService; | 28 | + private SysSmsCoreService smsCoreService; |
| 29 | 29 | ||
| 30 | @PostMapping("/sms/yunpian") | 30 | @PostMapping("/sms/yunpian") |
| 31 | @ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档") | 31 | @ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档") |
| @@ -33,7 +33,7 @@ public class SmsCallbackController { | @@ -33,7 +33,7 @@ public class SmsCallbackController { | ||
| 33 | @OperateLog(enable = false) | 33 | @OperateLog(enable = false) |
| 34 | public String receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable { | 34 | public String receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable { |
| 35 | String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode | 35 | String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode |
| 36 | - smsService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text); | 36 | + smsCoreService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text); |
| 37 | return "SUCCESS"; // 约定返回 SUCCESS 为成功 | 37 | return "SUCCESS"; // 约定返回 SUCCESS 为成功 |
| 38 | } | 38 | } |
| 39 | 39 | ||
| @@ -42,7 +42,7 @@ public class SmsCallbackController { | @@ -42,7 +42,7 @@ public class SmsCallbackController { | ||
| 42 | @OperateLog(enable = false) | 42 | @OperateLog(enable = false) |
| 43 | public CommonResult<Boolean> receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable { | 43 | public CommonResult<Boolean> receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable { |
| 44 | String text = ServletUtil.getBody(request); | 44 | String text = ServletUtil.getBody(request); |
| 45 | - smsService.receiveSmsStatus(SmsChannelEnum.ALIYUN.getCode(), text); | 45 | + smsCoreService.receiveSmsStatus(SmsChannelEnum.ALIYUN.getCode(), text); |
| 46 | return success(true); | 46 | return success(true); |
| 47 | } | 47 | } |
| 48 | 48 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsChannelController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.*; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.*; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; | 4 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; | 5 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; |
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 7 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
| 10 | import io.swagger.annotations.ApiImplicitParam; | 10 | import io.swagger.annotations.ApiImplicitParam; |
| 11 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsLogController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 6 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsLogConvert; | 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsLogConvert; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; |
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 10 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 12 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 13 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 14 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | 16 | import org.springframework.security.access.prepost.PreAuthorize; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/sms/SysSmsTemplateController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.*; | ||
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; | ||
| 5 | +import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 10 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 11 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.*; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; | ||
| 9 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; | ||
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | ||
| 12 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 13 | import io.swagger.annotations.ApiImplicitParam; | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 14 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
| @@ -32,7 +32,7 @@ public class SysSmsTemplateController { | @@ -32,7 +32,7 @@ public class SysSmsTemplateController { | ||
| 32 | @Resource | 32 | @Resource |
| 33 | private SysSmsTemplateService smsTemplateService; | 33 | private SysSmsTemplateService smsTemplateService; |
| 34 | @Resource | 34 | @Resource |
| 35 | - private SysSmsService smsService; | 35 | + private SysSmsCoreService smsCoreService; |
| 36 | 36 | ||
| 37 | @PostMapping("/create") | 37 | @PostMapping("/create") |
| 38 | @ApiOperation("创建短信模板") | 38 | @ApiOperation("创建短信模板") |
| @@ -91,7 +91,7 @@ public class SysSmsTemplateController { | @@ -91,7 +91,7 @@ public class SysSmsTemplateController { | ||
| 91 | @ApiOperation("发送短信") | 91 | @ApiOperation("发送短信") |
| 92 | @PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')") | 92 | @PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')") |
| 93 | public CommonResult<Long> sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) { | 93 | public CommonResult<Long> sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) { |
| 94 | - return success(smsService.sendSingleSms(sendReqVO.getMobile(), null, null, | 94 | + return success(smsCoreService.sendSingleSms(sendReqVO.getMobile(), null, null, |
| 95 | sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams())); | 95 | sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams())); |
| 96 | } | 96 | } |
| 97 | 97 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.user; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.user; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 8 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; | 5 | import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; | ||
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | 7 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 15 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 12 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 15 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 17 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 16 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 17 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 18 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 18 | import io.swagger.annotations.Api; | 19 | import io.swagger.annotations.Api; |
| 19 | import io.swagger.annotations.ApiImplicitParam; | 20 | import io.swagger.annotations.ApiImplicitParam; |
| 20 | import io.swagger.annotations.ApiImplicitParams; | 21 | import io.swagger.annotations.ApiImplicitParams; |
| @@ -42,6 +43,8 @@ public class SysUserController { | @@ -42,6 +43,8 @@ public class SysUserController { | ||
| 42 | @Resource | 43 | @Resource |
| 43 | private SysUserService userService; | 44 | private SysUserService userService; |
| 44 | @Resource | 45 | @Resource |
| 46 | + private SysUserCoreService userCoreService; | ||
| 47 | + @Resource | ||
| 45 | private SysDeptService deptService; | 48 | private SysDeptService deptService; |
| 46 | 49 | ||
| 47 | @PostMapping("/create") | 50 | @PostMapping("/create") |
| @@ -113,7 +116,7 @@ public class SysUserController { | @@ -113,7 +116,7 @@ public class SysUserController { | ||
| 113 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 116 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 114 | @PreAuthorize("@ss.hasPermission('system:user:query')") | 117 | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| 115 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { | 118 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { |
| 116 | - return success(SysUserConvert.INSTANCE.convert(userService.getUser(id))); | 119 | + return success(SysUserConvert.INSTANCE.convert(userCoreService.getUser(id))); |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | @GetMapping("/export") | 122 | @GetMapping("/export") |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.user; | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.user; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; | ||
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | ||
| 6 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 7 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileRespVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; | 6 | 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; | @@ -12,12 +8,17 @@ import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; |
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | 11 | +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 16 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 17 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; | 13 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 14 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 19 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; |
| 16 | +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | ||
| 20 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 17 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 18 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 19 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 20 | +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 21 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 21 | import io.swagger.annotations.Api; | 22 | import io.swagger.annotations.Api; |
| 22 | import io.swagger.annotations.ApiOperation; | 23 | import io.swagger.annotations.ApiOperation; |
| 23 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| @@ -30,13 +31,10 @@ import javax.validation.Valid; | @@ -30,13 +31,10 @@ import javax.validation.Valid; | ||
| 30 | import java.io.IOException; | 31 | import java.io.IOException; |
| 31 | import java.util.List; | 32 | import java.util.List; |
| 32 | 33 | ||
| 34 | +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY; | ||
| 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 35 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 34 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 36 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 35 | -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY; | ||
| 36 | 37 | ||
| 37 | -/** | ||
| 38 | - * @author niudehua | ||
| 39 | - */ | ||
| 40 | @Api(tags = "用户个人中心") | 38 | @Api(tags = "用户个人中心") |
| 41 | @RestController | 39 | @RestController |
| 42 | @RequestMapping("/system/user/profile") | 40 | @RequestMapping("/system/user/profile") |
| @@ -47,6 +45,8 @@ public class SysUserProfileController { | @@ -47,6 +45,8 @@ public class SysUserProfileController { | ||
| 47 | @Resource | 45 | @Resource |
| 48 | private SysUserService userService; | 46 | private SysUserService userService; |
| 49 | @Resource | 47 | @Resource |
| 48 | + private SysUserCoreService userCoreService; | ||
| 49 | + @Resource | ||
| 50 | private SysDeptService deptService; | 50 | private SysDeptService deptService; |
| 51 | @Resource | 51 | @Resource |
| 52 | private SysPostService postService; | 52 | private SysPostService postService; |
| @@ -61,7 +61,7 @@ public class SysUserProfileController { | @@ -61,7 +61,7 @@ public class SysUserProfileController { | ||
| 61 | @ApiOperation("获得登录用户信息") | 61 | @ApiOperation("获得登录用户信息") |
| 62 | public CommonResult<SysUserProfileRespVO> profile() { | 62 | public CommonResult<SysUserProfileRespVO> profile() { |
| 63 | // 获得用户基本信息 | 63 | // 获得用户基本信息 |
| 64 | - SysUserDO user = userService.getUser(getLoginUserId()); | 64 | + SysUserDO user = userCoreService.getUser(getLoginUserId()); |
| 65 | SysUserProfileRespVO resp = SysUserConvert.INSTANCE.convert03(user); | 65 | SysUserProfileRespVO resp = SysUserConvert.INSTANCE.convert03(user); |
| 66 | // 获得用户角色 | 66 | // 获得用户角色 |
| 67 | List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(user.getId())); | 67 | List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(user.getId())); |
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; | @@ -8,6 +8,7 @@ import lombok.AllArgsConstructor; | ||
| 8 | import lombok.Builder; | 8 | import lombok.Builder; |
| 9 | import lombok.Data; | 9 | import lombok.Data; |
| 10 | import lombok.NoArgsConstructor; | 10 | import lombok.NoArgsConstructor; |
| 11 | +import lombok.experimental.Accessors; | ||
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| 13 | * 用户 Excel 导入 VO | 14 | * 用户 Excel 导入 VO |
| @@ -16,6 +17,7 @@ import lombok.NoArgsConstructor; | @@ -16,6 +17,7 @@ import lombok.NoArgsConstructor; | ||
| 16 | @Builder | 17 | @Builder |
| 17 | @AllArgsConstructor | 18 | @AllArgsConstructor |
| 18 | @NoArgsConstructor | 19 | @NoArgsConstructor |
| 20 | +@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题 | ||
| 19 | public class SysUserImportExcelVO { | 21 | public class SysUserImportExcelVO { |
| 20 | 22 | ||
| 21 | @ExcelProperty("登录名称") | 23 | @ExcelProperty("登录名称") |
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; | @@ -2,17 +2,13 @@ package cn.iocoder.yudao.adminserver.modules.system.convert.auth; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO; |
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; | ||
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuIdEnum; | 7 | import cn.iocoder.yudao.adminserver.modules.system.enums.permission.MenuIdEnum; |
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 9 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 13 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 14 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 11 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 15 | -import me.zhyd.oauth.model.AuthCallback; | ||
| 16 | import org.mapstruct.Mapper; | 12 | import org.mapstruct.Mapper; |
| 17 | import org.mapstruct.Mapping; | 13 | import org.mapstruct.Mapping; |
| 18 | import org.mapstruct.factory.Mappers; | 14 | import org.mapstruct.factory.Mappers; |
| @@ -25,9 +21,13 @@ public interface SysAuthConvert { | @@ -25,9 +21,13 @@ public interface SysAuthConvert { | ||
| 25 | 21 | ||
| 26 | SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); | 22 | SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); |
| 27 | 23 | ||
| 28 | - @Mapping(source = "updateTime", target = "updateTime", ignore = true) | ||
| 29 | - // 字段相同,但是含义不同,忽略 | ||
| 30 | - LoginUser convert(SysUserDO bean); | 24 | + @Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略 |
| 25 | + LoginUser convert0(SysUserDO bean); | ||
| 26 | + | ||
| 27 | + default LoginUser convert(SysUserDO bean) { | ||
| 28 | + // 目的,为了设置 UserTypeEnum.ADMIN.getValue() | ||
| 29 | + return convert0(bean).setUserType(UserTypeEnum.ADMIN.getValue()); | ||
| 30 | + } | ||
| 31 | 31 | ||
| 32 | default SysAuthPermissionInfoRespVO convert(SysUserDO user, List<SysRoleDO> roleList, List<SysMenuDO> menuList) { | 32 | default SysAuthPermissionInfoRespVO convert(SysUserDO user, List<SysRoleDO> roleList, List<SysMenuDO> menuList) { |
| 33 | return SysAuthPermissionInfoRespVO.builder() | 33 | return SysAuthPermissionInfoRespVO.builder() |
| @@ -39,10 +39,6 @@ public interface SysAuthConvert { | @@ -39,10 +39,6 @@ public interface SysAuthConvert { | ||
| 39 | 39 | ||
| 40 | SysAuthMenuRespVO convertTreeNode(SysMenuDO menu); | 40 | SysAuthMenuRespVO convertTreeNode(SysMenuDO menu); |
| 41 | 41 | ||
| 42 | - LoginUser convert(SysUserProfileUpdateReqVO reqVO); | ||
| 43 | - | ||
| 44 | - LoginUser convert(SysUserProfileUpdatePasswordReqVO reqVO); | ||
| 45 | - | ||
| 46 | /** | 42 | /** |
| 47 | * 将菜单列表,构建成菜单树 | 43 | * 将菜单列表,构建成菜单树 |
| 48 | * | 44 | * |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/auth/SysUserSessionConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.auth; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageItemRespVO; |
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; |
| 5 | import org.mapstruct.Mapper; | 5 | import org.mapstruct.Mapper; |
| 6 | import org.mapstruct.factory.Mappers; | 6 | import org.mapstruct.factory.Mappers; |
| 7 | 7 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/dict/SysDictDataConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; | 6 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.*; | ||
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 7 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysLoginLogConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExcelVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 9 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 10 | 9 | ||
| @@ -15,8 +14,6 @@ public interface SysLoginLogConvert { | @@ -15,8 +14,6 @@ public interface SysLoginLogConvert { | ||
| 15 | 14 | ||
| 16 | SysLoginLogConvert INSTANCE = Mappers.getMapper(SysLoginLogConvert.class); | 15 | SysLoginLogConvert INSTANCE = Mappers.getMapper(SysLoginLogConvert.class); |
| 17 | 16 | ||
| 18 | - SysLoginLogDO convert(SysLoginLogCreateReqVO bean); | ||
| 19 | - | ||
| 20 | PageResult<SysLoginLogRespVO> convertPage(PageResult<SysLoginLogDO> page); | 17 | PageResult<SysLoginLogRespVO> convertPage(PageResult<SysLoginLogDO> page); |
| 21 | 18 | ||
| 22 | List<SysLoginLogExcelVO> convertList(List<SysLoginLogDO> list); | 19 | List<SysLoginLogExcelVO> convertList(List<SysLoginLogDO> list); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/logger/SysOperateLogConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogRespVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 8 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 9 | +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 10 | import org.mapstruct.Mapper; | 10 | import org.mapstruct.Mapper; |
| 11 | import org.mapstruct.factory.Mappers; | 11 | import org.mapstruct.factory.Mappers; |
| 12 | 12 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsChannelConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelRespVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelSimpleRespVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelSimpleRespVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | +import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; | ||
| 10 | import org.mapstruct.Mapper; | 10 | import org.mapstruct.Mapper; |
| 11 | import org.mapstruct.factory.Mappers; | 11 | import org.mapstruct.factory.Mappers; |
| 12 | 12 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsLogConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExcelVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogRespVO; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/sms/SysSmsTemplateConvert.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.convert.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExcelVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExcelVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateRespVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateRespVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | import org.mapstruct.Mapper; | 9 | import org.mapstruct.Mapper; |
| 10 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 11 | 11 |
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 | @@ -8,7 +8,7 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 12 | import org.mapstruct.Mapper; | 12 | import org.mapstruct.Mapper; |
| 13 | import org.mapstruct.factory.Mappers; | 13 | import org.mapstruct.factory.Mappers; |
| 14 | 14 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysOperateLogDO.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; | 5 | import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 6 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 7 | import com.baomidou.mybatisplus.annotation.TableField; | 7 | import com.baomidou.mybatisplus.annotation.TableField; |
| 8 | import com.baomidou.mybatisplus.annotation.TableId; | 8 | import com.baomidou.mybatisplus.annotation.TableId; |
| 9 | import com.baomidou.mybatisplus.annotation.TableName; | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/social/SysSocialUserDO.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 6 | import com.baomidou.mybatisplus.annotation.TableId; | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/auth/SysUserSessionMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | import java.util.Collection; | 10 | import java.util.Collection; |
| @@ -23,4 +23,5 @@ public interface SysUserSessionMapper extends BaseMapperX<SysUserSessionDO> { | @@ -23,4 +23,5 @@ public interface SysUserSessionMapper extends BaseMapperX<SysUserSessionDO> { | ||
| 23 | default List<SysUserSessionDO> selectListBySessionTimoutLt() { | 23 | default List<SysUserSessionDO> selectListBySessionTimoutLt() { |
| 24 | return selectList(new QueryWrapperX<SysUserSessionDO>().lt("session_timeout",new Date())); | 24 | return selectList(new QueryWrapperX<SysUserSessionDO>().lt("session_timeout",new Date())); |
| 25 | } | 25 | } |
| 26 | + | ||
| 26 | } | 27 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; | ||
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 8 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/logger/SysLoginLogMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 9 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsChannelMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | import org.apache.ibatis.annotations.Select; | 9 | import org.apache.ibatis.annotations.Select; |
| 10 | 10 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsLogMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | ||
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 8 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 9 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; | ||
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 8 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 9 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | -import org.apache.ibatis.annotations.Select; | ||
| 11 | 10 | ||
| 12 | -import java.util.Date; | ||
| 13 | import java.util.List; | 11 | import java.util.List; |
| 14 | 12 | ||
| 15 | @Mapper | 13 | @Mapper |
| @@ -47,7 +45,4 @@ public interface SysSmsTemplateMapper extends BaseMapperX<SysSmsTemplateDO> { | @@ -47,7 +45,4 @@ public interface SysSmsTemplateMapper extends BaseMapperX<SysSmsTemplateDO> { | ||
| 47 | return selectCount("channel_id", channelId); | 45 | return selectCount("channel_id", channelId); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | - @Select("SELECT id FROM sys_sms_template WHERE update_time > #{maxUpdateTime} LIMIT 1") | ||
| 51 | - Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); | ||
| 52 | - | ||
| 53 | } | 48 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user; | 1 | package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 | ||
| @@ -19,14 +19,14 @@ public interface SysUserMapper extends BaseMapperX<SysUserDO> { | @@ -19,14 +19,14 @@ public interface SysUserMapper extends BaseMapperX<SysUserDO> { | ||
| 19 | return selectOne(new QueryWrapper<SysUserDO>().eq("username", username)); | 19 | return selectOne(new QueryWrapper<SysUserDO>().eq("username", username)); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | - default SysUserDO selectByMobile(String mobile) { | ||
| 23 | - return selectOne(new QueryWrapper<SysUserDO>().eq("mobile", mobile)); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | default SysUserDO selectByEmail(String email) { | 22 | default SysUserDO selectByEmail(String email) { |
| 27 | return selectOne(new QueryWrapper<SysUserDO>().eq("email", email)); | 23 | return selectOne(new QueryWrapper<SysUserDO>().eq("email", email)); |
| 28 | } | 24 | } |
| 29 | 25 | ||
| 26 | + default SysUserDO selectByMobile(String mobile) { | ||
| 27 | + return selectOne(new QueryWrapper<SysUserDO>().eq("mobile", mobile)); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | default PageResult<SysUserDO> selectPage(SysUserPageReqVO reqVO, Collection<Long> deptIds) { | 30 | default PageResult<SysUserDO> selectPage(SysUserPageReqVO reqVO, Collection<Long> deptIds) { |
| 31 | return selectPage(reqVO, new QueryWrapperX<SysUserDO>() | 31 | return selectPage(reqVO, new QueryWrapperX<SysUserDO>() |
| 32 | .likeIfPresent("username", reqVO.getUsername()) | 32 | .likeIfPresent("username", reqVO.getUsername()) |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/RedisKeyConstants.java deleted
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 | @@ -15,10 +15,6 @@ import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.S | ||
| 15 | */ | 15 | */ |
| 16 | public interface SysRedisKeyConstants { | 16 | public interface SysRedisKeyConstants { |
| 17 | 17 | ||
| 18 | - RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", | ||
| 19 | - "login_user:%s", // 参数为 sessionId | ||
| 20 | - STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); | ||
| 21 | - | ||
| 22 | RedisKeyDefine CAPTCHA_CODE = new RedisKeyDefine("验证码的缓存", | 18 | RedisKeyDefine CAPTCHA_CODE = new RedisKeyDefine("验证码的缓存", |
| 23 | "captcha_code:%s", // 参数为 uuid | 19 | "captcha_code:%s", // 参数为 uuid |
| 24 | STRING, String.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); | 20 | STRING, String.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.enums; | 1 | package cn.iocoder.yudao.adminserver.modules.system.enums; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.config.ErrorCodeConfiguration; | ||
| 4 | import cn.iocoder.yudao.framework.common.exception.ErrorCode; | 3 | import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
| 5 | -import org.springframework.validation.Errors; | 4 | +import javafx.beans.binding.MapExpression; |
| 6 | 5 | ||
| 7 | /** | 6 | /** |
| 8 | * System 错误码枚举类 | 7 | * System 错误码枚举类 |
| @@ -14,14 +13,11 @@ public interface SysErrorCodeConstants { | @@ -14,14 +13,11 @@ public interface SysErrorCodeConstants { | ||
| 14 | // ========== AUTH 模块 1002000000 ========== | 13 | // ========== AUTH 模块 1002000000 ========== |
| 15 | ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1002000000, "登录失败,账号密码不正确"); | 14 | ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1002000000, "登录失败,账号密码不正确"); |
| 16 | ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1002000001, "登录失败,账号被禁用"); | 15 | ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1002000001, "登录失败,账号被禁用"); |
| 17 | - ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,位置原因 | 16 | + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,未知原因 |
| 18 | ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); | 17 | ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); |
| 19 | ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); | 18 | ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); |
| 20 | ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); | 19 | ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); |
| 21 | - | ||
| 22 | - // ========== TOKEN 模块 1002001000 ========== | ||
| 23 | - ErrorCode TOKEN_EXPIRED = new ErrorCode(1002001000, "Token 已经过期"); | ||
| 24 | - ErrorCode TOKEN_PARSE_FAIL = new ErrorCode(1002001001, "Token 解析失败"); | 20 | + ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1002000006, "Token 已经过期"); |
| 25 | 21 | ||
| 26 | // ========== 菜单模块 1002002000 ========== | 22 | // ========== 菜单模块 1002002000 ========== |
| 27 | ErrorCode MENU_NAME_DUPLICATE = new ErrorCode(1002002000, "已经存在该名字的菜单"); | 23 | ErrorCode MENU_NAME_DUPLICATE = new ErrorCode(1002002000, "已经存在该名字的菜单"); |
| @@ -90,10 +86,6 @@ public interface SysErrorCodeConstants { | @@ -90,10 +86,6 @@ public interface SysErrorCodeConstants { | ||
| 90 | ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在"); | 86 | ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在"); |
| 91 | ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}】的短信模板"); | 87 | ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}】的短信模板"); |
| 92 | 88 | ||
| 93 | - // ========== 短信发送 1002012000 ========== | ||
| 94 | - ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1002012000, "手机号不存在"); | ||
| 95 | - ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1002012001, "模板参数({})缺失"); | ||
| 96 | - | ||
| 97 | // ========== 错误码模块 1002013000 ========== | 89 | // ========== 错误码模块 1002013000 ========== |
| 98 | ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002013000, "错误码不存在"); | 90 | ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002013000, "错误码不存在"); |
| 99 | ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002013001, "已经存在编码为【{}】的错误码"); | 91 | ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002013001, "已经存在编码为【{}】的错误码"); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java
| @@ -13,6 +13,8 @@ public enum SysLoginLogTypeEnum { | @@ -13,6 +13,8 @@ public enum SysLoginLogTypeEnum { | ||
| 13 | LOGIN_USERNAME(100), // 使用账号登录 | 13 | LOGIN_USERNAME(100), // 使用账号登录 |
| 14 | LOGIN_SOCIAL(101), // 使用社交登录 | 14 | LOGIN_SOCIAL(101), // 使用社交登录 |
| 15 | LOGIN_MOCK(102), // 使用 Mock 登录 | 15 | LOGIN_MOCK(102), // 使用 Mock 登录 |
| 16 | + LOGIN_MOBILE(103), // 使用手机登陆 | ||
| 17 | + LOGIN_SMS(104), // 使用短信登陆 | ||
| 16 | 18 | ||
| 17 | LOGOUT_SELF(200), // 自己主动登出 | 19 | LOGOUT_SELF(200), // 自己主动登出 |
| 18 | LOGOUT_TIMEOUT(201), // 超时登出 | 20 | LOGOUT_TIMEOUT(201), // 超时登出 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java
| @@ -13,8 +13,8 @@ public enum SysLoginResultEnum { | @@ -13,8 +13,8 @@ public enum SysLoginResultEnum { | ||
| 13 | SUCCESS(0), // 成功 | 13 | SUCCESS(0), // 成功 |
| 14 | BAD_CREDENTIALS(10), // 账号或密码不正确 | 14 | BAD_CREDENTIALS(10), // 账号或密码不正确 |
| 15 | USER_DISABLED(20), // 用户被禁用 | 15 | USER_DISABLED(20), // 用户被禁用 |
| 16 | - CAPTCHA_NOT_FOUND(30), // 验证码不存在 | ||
| 17 | - CAPTCHA_CODE_ERROR(31), // 验证码不正确 | 16 | + CAPTCHA_NOT_FOUND(30), // 图片验证码不存在 |
| 17 | + CAPTCHA_CODE_ERROR(31), // 图片验证码不正确 | ||
| 18 | 18 | ||
| 19 | UNKNOWN_ERROR(100), // 未知异常 | 19 | UNKNOWN_ERROR(100), // 未知异常 |
| 20 | ; | 20 | ; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.service.dict.SysDictDataCoreService; | ||
| 3 | import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; | 4 | import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; |
| 4 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.dict.SysDictDataRefreshMessage; | 5 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.dict.SysDictDataRefreshMessage; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; | 6 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; |
| @@ -18,12 +19,12 @@ import javax.annotation.Resource; | @@ -18,12 +19,12 @@ import javax.annotation.Resource; | ||
| 18 | public class SysDictDataRefreshConsumer extends AbstractChannelMessageListener<SysDictDataRefreshMessage> { | 19 | public class SysDictDataRefreshConsumer extends AbstractChannelMessageListener<SysDictDataRefreshMessage> { |
| 19 | 20 | ||
| 20 | @Resource | 21 | @Resource |
| 21 | - private SysDictDataService dictDataService; | 22 | + private SysDictDataCoreService dictDataCoreService; |
| 22 | 23 | ||
| 23 | @Override | 24 | @Override |
| 24 | public void onMessage(SysDictDataRefreshMessage message) { | 25 | public void onMessage(SysDictDataRefreshMessage message) { |
| 25 | log.info("[onMessage][收到 DictData 刷新消息]"); | 26 | log.info("[onMessage][收到 DictData 刷新消息]"); |
| 26 | - dictDataService.initLocalCache(); | 27 | + dictDataCoreService.initLocalCache(); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | } | 30 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsSendConsumer.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | ||
| 3 | import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; | 5 | import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; |
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; | ||
| 6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| 7 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 8 | 8 | ||
| @@ -19,12 +19,12 @@ import javax.annotation.Resource; | @@ -19,12 +19,12 @@ import javax.annotation.Resource; | ||
| 19 | public class SysSmsSendConsumer extends AbstractStreamMessageListener<SysSmsSendMessage> { | 19 | public class SysSmsSendConsumer extends AbstractStreamMessageListener<SysSmsSendMessage> { |
| 20 | 20 | ||
| 21 | @Resource | 21 | @Resource |
| 22 | - private SysSmsService smsService; | 22 | + private SysSmsCoreService smsCoreService; |
| 23 | 23 | ||
| 24 | @Override | 24 | @Override |
| 25 | public void onMessage(SysSmsSendMessage message) { | 25 | public void onMessage(SysSmsSendMessage message) { |
| 26 | log.info("[onMessage][消息内容({})]", message); | 26 | log.info("[onMessage][消息内容({})]", message); |
| 27 | - smsService.doSendSms(message); | 27 | + smsCoreService.doSendSms(message); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | } | 30 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/consumer/sms/SysSmsTemplateRefreshConsumer.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; | 3 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | 4 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; |
| 5 | +import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener; | ||
| 6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| 7 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 8 | 8 | ||
| @@ -18,12 +18,12 @@ import javax.annotation.Resource; | @@ -18,12 +18,12 @@ import javax.annotation.Resource; | ||
| 18 | public class SysSmsTemplateRefreshConsumer extends AbstractChannelMessageListener<SysSmsTemplateRefreshMessage> { | 18 | public class SysSmsTemplateRefreshConsumer extends AbstractChannelMessageListener<SysSmsTemplateRefreshMessage> { |
| 19 | 19 | ||
| 20 | @Resource | 20 | @Resource |
| 21 | - private SysSmsTemplateService smsTemplateService; | 21 | + private SysSmsTemplateCoreService smsTemplateCoreService; |
| 22 | 22 | ||
| 23 | @Override | 23 | @Override |
| 24 | public void onMessage(SysSmsTemplateRefreshMessage message) { | 24 | public void onMessage(SysSmsTemplateRefreshMessage message) { |
| 25 | log.info("[onMessage][收到 SmsTemplate 刷新消息]"); | 25 | log.info("[onMessage][收到 SmsTemplate 刷新消息]"); |
| 26 | - smsTemplateService.initLocalCache(); | 26 | + smsTemplateCoreService.initLocalCache(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | } | 29 | } |
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; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms; | ||
| 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; | 4 | import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsChannelRefreshMessage; | 5 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsChannelRefreshMessage; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 7 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; | 6 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsTemplateRefreshMessage; |
| 8 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
| 9 | import org.springframework.data.redis.core.StringRedisTemplate; | 8 | import org.springframework.data.redis.core.StringRedisTemplate; |
| @@ -26,22 +25,6 @@ public class SysSmsProducer { | @@ -26,22 +25,6 @@ public class SysSmsProducer { | ||
| 26 | private StringRedisTemplate stringRedisTemplate; | 25 | private StringRedisTemplate stringRedisTemplate; |
| 27 | 26 | ||
| 28 | /** | 27 | /** |
| 29 | - * 发送 {@link SysSmsSendMessage} 消息 | ||
| 30 | - * | ||
| 31 | - * @param logId 短信日志编号 | ||
| 32 | - * @param mobile 手机号 | ||
| 33 | - * @param channelId 渠道编号 | ||
| 34 | - * @param apiTemplateId 短信模板编号 | ||
| 35 | - * @param templateParams 短信模板参数 | ||
| 36 | - */ | ||
| 37 | - public void sendSmsSendMessage(Long logId, String mobile, | ||
| 38 | - Long channelId, String apiTemplateId, List<KeyValue<String, Object>> templateParams) { | ||
| 39 | - SysSmsSendMessage message = new SysSmsSendMessage().setLogId(logId).setMobile(mobile); | ||
| 40 | - message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams); | ||
| 41 | - RedisMessageUtils.sendStreamMessage(stringRedisTemplate, message); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - /** | ||
| 45 | * 发送 {@link SysSmsChannelRefreshMessage} 消息 | 28 | * 发送 {@link SysSmsChannelRefreshMessage} 消息 |
| 46 | */ | 29 | */ |
| 47 | public void sendSmsChannelRefreshMessage() { | 30 | public void sendSmsChannelRefreshMessage() { |
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 | @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkSer | ||
| 6 | import javax.validation.Valid; | 6 | import javax.validation.Valid; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | - * 认证 Service 接口 | 9 | + * 管理后台的认证 Service 接口 |
| 10 | * | 10 | * |
| 11 | * 提供用户的账号密码登录、token 的校验等认证相关的功能 | 11 | * 提供用户的账号密码登录、token 的校验等认证相关的功能 |
| 12 | * | 12 | * |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | 6 | ||
| 8 | /** | 7 | /** |
| 9 | * 在线用户 Session Service 接口 | 8 | * 在线用户 Session Service 接口 |
| @@ -13,53 +12,6 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSe | @@ -13,53 +12,6 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSe | ||
| 13 | public interface SysUserSessionService { | 12 | public interface SysUserSessionService { |
| 14 | 13 | ||
| 15 | /** | 14 | /** |
| 16 | - * 创建在线用户 Session | ||
| 17 | - * | ||
| 18 | - * @param loginUser 登录用户 | ||
| 19 | - * @param userIp 用户 IP | ||
| 20 | - * @param userAgent 用户 UA | ||
| 21 | - * @return Session 编号 | ||
| 22 | - */ | ||
| 23 | - String createUserSession(LoginUser loginUser, String userIp, String userAgent); | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * 刷新在线用户 Session 的更新时间 | ||
| 27 | - * | ||
| 28 | - * @param sessionId Session 编号 | ||
| 29 | - * @param loginUser 登录用户 | ||
| 30 | - */ | ||
| 31 | - void refreshUserSession(String sessionId, LoginUser loginUser); | ||
| 32 | - | ||
| 33 | - /** | ||
| 34 | - * 删除在线用户 Session | ||
| 35 | - * | ||
| 36 | - * @param sessionId Session 编号 | ||
| 37 | - */ | ||
| 38 | - void deleteUserSession(String sessionId); | ||
| 39 | - | ||
| 40 | - /** | ||
| 41 | - * 获得 Session 编号对应的在线用户 | ||
| 42 | - * | ||
| 43 | - * @param sessionId Session 编号 | ||
| 44 | - * @return 在线用户 | ||
| 45 | - */ | ||
| 46 | - LoginUser getLoginUser(String sessionId); | ||
| 47 | - | ||
| 48 | - /** | ||
| 49 | - * 获取当前登录用户信息 | ||
| 50 | - * @param username 用户名称 | ||
| 51 | - * @return 在线用户 | ||
| 52 | - */ | ||
| 53 | - String getSessionId(String username); | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * 获得 Session 超时时间,单位:毫秒 | ||
| 57 | - * | ||
| 58 | - * @return 超时时间 | ||
| 59 | - */ | ||
| 60 | - Long getSessionTimeoutMillis(); | ||
| 61 | - | ||
| 62 | - /** | ||
| 63 | * 获得在线用户分页列表 | 15 | * 获得在线用户分页列表 |
| 64 | * | 16 | * |
| 65 | * @param reqVO 分页条件 | 17 | * @param reqVO 分页条件 |
| @@ -73,4 +25,5 @@ public interface SysUserSessionService { | @@ -73,4 +25,5 @@ public interface SysUserSessionService { | ||
| 73 | * @return {@link Long } 移出的超时用户数量 | 25 | * @return {@link Long } 移出的超时用户数量 |
| 74 | **/ | 26 | **/ |
| 75 | long clearSessionTimeout(); | 27 | long clearSessionTimeout(); |
| 28 | + | ||
| 76 | } | 29 | } |
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 | @@ -5,20 +5,22 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAu | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; | 8 | import cn.iocoder.yudao.adminserver.modules.system.convert.auth.SysAuthConvert; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; | 10 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 11 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; |
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; | ||
| 16 | import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; | 13 | import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; |
| 17 | -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; | ||
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 14 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 19 | import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; |
| 20 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 16 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 17 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 18 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||
| 19 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 20 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 21 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 21 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 22 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 23 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 22 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | 24 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 23 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | 25 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 24 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 26 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| @@ -38,6 +40,7 @@ import org.springframework.util.Assert; | @@ -38,6 +40,7 @@ import org.springframework.util.Assert; | ||
| 38 | 40 | ||
| 39 | import javax.annotation.Resource; | 41 | import javax.annotation.Resource; |
| 40 | import java.util.List; | 42 | import java.util.List; |
| 43 | +import java.util.Objects; | ||
| 41 | import java.util.Set; | 44 | import java.util.Set; |
| 42 | 45 | ||
| 43 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 46 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| @@ -60,13 +63,15 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -60,13 +63,15 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 60 | @Resource | 63 | @Resource |
| 61 | private SysUserService userService; | 64 | private SysUserService userService; |
| 62 | @Resource | 65 | @Resource |
| 66 | + private SysUserCoreService userCoreService; | ||
| 67 | + @Resource | ||
| 63 | private SysPermissionService permissionService; | 68 | private SysPermissionService permissionService; |
| 64 | @Resource | 69 | @Resource |
| 65 | private SysCaptchaService captchaService; | 70 | private SysCaptchaService captchaService; |
| 66 | @Resource | 71 | @Resource |
| 67 | - private SysLoginLogService loginLogService; | 72 | + private SysLoginLogCoreService loginLogCoreService; |
| 68 | @Resource | 73 | @Resource |
| 69 | - private SysUserSessionService userSessionService; | 74 | + private SysUserSessionCoreService userSessionCoreService; |
| 70 | @Resource | 75 | @Resource |
| 71 | private SysSocialService socialService; | 76 | private SysSocialService socialService; |
| 72 | 77 | ||
| @@ -84,7 +89,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -84,7 +89,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 84 | @Override | 89 | @Override |
| 85 | public LoginUser mockLogin(Long userId) { | 90 | public LoginUser mockLogin(Long userId) { |
| 86 | // 获取用户编号对应的 SysUserDO | 91 | // 获取用户编号对应的 SysUserDO |
| 87 | - SysUserDO user = userService.getUser(userId); | 92 | + SysUserDO user = userCoreService.getUser(userId); |
| 88 | if (user == null) { | 93 | if (user == null) { |
| 89 | throw new UsernameNotFoundException(String.valueOf(userId)); | 94 | throw new UsernameNotFoundException(String.valueOf(userId)); |
| 90 | } | 95 | } |
| @@ -106,7 +111,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -106,7 +111,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 106 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 | 111 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 |
| 107 | 112 | ||
| 108 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 113 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 109 | - return userSessionService.createUserSession(loginUser, userIp, userAgent); | 114 | + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 110 | } | 115 | } |
| 111 | 116 | ||
| 112 | private void verifyCaptcha(String username, String captchaUUID, String captchaCode) { | 117 | private void verifyCaptcha(String username, String captchaUUID, String captchaCode) { |
| @@ -154,14 +159,25 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -154,14 +159,25 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 154 | } | 159 | } |
| 155 | 160 | ||
| 156 | private void createLoginLog(String username, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { | 161 | private void createLoginLog(String username, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { |
| 157 | - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); | ||
| 158 | - reqVO.setLogType(logTypeEnum.getType()); | ||
| 159 | - reqVO.setTraceId(TracerUtils.getTraceId()); | ||
| 160 | - reqVO.setUsername(username); | ||
| 161 | - reqVO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 162 | - reqVO.setUserIp(ServletUtils.getClientIP()); | ||
| 163 | - reqVO.setResult(loginResult.getResult()); | ||
| 164 | - loginLogService.createLoginLog(reqVO); | 162 | + // 获得用户 |
| 163 | + SysUserDO user = userService.getUserByUsername(username); | ||
| 164 | + // 插入登录日志 | ||
| 165 | + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | ||
| 166 | + reqDTO.setLogType(logTypeEnum.getType()); | ||
| 167 | + reqDTO.setTraceId(TracerUtils.getTraceId()); | ||
| 168 | + if (user != null) { | ||
| 169 | + reqDTO.setUserId(user.getId()); | ||
| 170 | + } | ||
| 171 | + reqDTO.setUserType(UserTypeEnum.ADMIN.getValue()); | ||
| 172 | + reqDTO.setUsername(username); | ||
| 173 | + reqDTO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 174 | + reqDTO.setUserIp(ServletUtils.getClientIP()); | ||
| 175 | + reqDTO.setResult(loginResult.getResult()); | ||
| 176 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 177 | + // 更新最后登录时间 | ||
| 178 | + if (user != null && Objects.equals(SysLoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) { | ||
| 179 | + userService.updateUserLogin(user.getId(), ServletUtils.getClientIP()); | ||
| 180 | + } | ||
| 165 | } | 181 | } |
| 166 | 182 | ||
| 167 | /** | 183 | /** |
| @@ -188,7 +204,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -188,7 +204,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 188 | } | 204 | } |
| 189 | 205 | ||
| 190 | // 自动登录 | 206 | // 自动登录 |
| 191 | - SysUserDO user = userService.getUser(socialUsers.get(0).getUserId()); | 207 | + SysUserDO user = userCoreService.getUser(socialUsers.get(0).getUserId()); |
| 192 | if (user == null) { | 208 | if (user == null) { |
| 193 | throw exception(USER_NOT_EXISTS); | 209 | throw exception(USER_NOT_EXISTS); |
| 194 | } | 210 | } |
| @@ -203,7 +219,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -203,7 +219,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 203 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); | 219 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); |
| 204 | 220 | ||
| 205 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 221 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 206 | - return userSessionService.createUserSession(loginUser, userIp, userAgent); | 222 | + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 207 | } | 223 | } |
| 208 | 224 | ||
| 209 | @Override | 225 | @Override |
| @@ -220,7 +236,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -220,7 +236,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 220 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); | 236 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); |
| 221 | 237 | ||
| 222 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 238 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 223 | - return userSessionService.createUserSession(loginUser, userIp, userAgent); | 239 | + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 224 | } | 240 | } |
| 225 | 241 | ||
| 226 | @Override | 242 | @Override |
| @@ -236,31 +252,33 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -236,31 +252,33 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 236 | @Override | 252 | @Override |
| 237 | public void logout(String token) { | 253 | public void logout(String token) { |
| 238 | // 查询用户信息 | 254 | // 查询用户信息 |
| 239 | - LoginUser loginUser = userSessionService.getLoginUser(token); | 255 | + LoginUser loginUser = userSessionCoreService.getLoginUser(token); |
| 240 | if (loginUser == null) { | 256 | if (loginUser == null) { |
| 241 | return; | 257 | return; |
| 242 | } | 258 | } |
| 243 | // 删除 session | 259 | // 删除 session |
| 244 | - userSessionService.deleteUserSession(token); | ||
| 245 | - // 记录登出日子和 | ||
| 246 | - this.createLogoutLog(loginUser.getUsername()); | 260 | + userSessionCoreService.deleteUserSession(token); |
| 261 | + // 记录登出日志 | ||
| 262 | + this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); | ||
| 247 | } | 263 | } |
| 248 | 264 | ||
| 249 | - private void createLogoutLog(String username) { | ||
| 250 | - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); | ||
| 251 | - reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | ||
| 252 | - reqVO.setTraceId(TracerUtils.getTraceId()); | ||
| 253 | - reqVO.setUsername(username); | ||
| 254 | - reqVO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 255 | - reqVO.setUserIp(ServletUtils.getClientIP()); | ||
| 256 | - reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult()); | ||
| 257 | - loginLogService.createLoginLog(reqVO); | 265 | + private void createLogoutLog(Long userId, String username) { |
| 266 | + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | ||
| 267 | + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | ||
| 268 | + reqDTO.setTraceId(TracerUtils.getTraceId()); | ||
| 269 | + reqDTO.setUserId(userId); | ||
| 270 | + reqDTO.setUserType(UserTypeEnum.ADMIN.getValue()); | ||
| 271 | + reqDTO.setUsername(username); | ||
| 272 | + reqDTO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 273 | + reqDTO.setUserIp(ServletUtils.getClientIP()); | ||
| 274 | + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); | ||
| 275 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 258 | } | 276 | } |
| 259 | 277 | ||
| 260 | @Override | 278 | @Override |
| 261 | public LoginUser verifyTokenAndRefresh(String token) { | 279 | public LoginUser verifyTokenAndRefresh(String token) { |
| 262 | // 获得 LoginUser | 280 | // 获得 LoginUser |
| 263 | - LoginUser loginUser = userSessionService.getLoginUser(token); | 281 | + LoginUser loginUser = userSessionCoreService.getLoginUser(token); |
| 264 | if (loginUser == null) { | 282 | if (loginUser == null) { |
| 265 | return null; | 283 | return null; |
| 266 | } | 284 | } |
| @@ -272,20 +290,20 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -272,20 +290,20 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 272 | private void refreshLoginUserCache(String token, LoginUser loginUser) { | 290 | private void refreshLoginUserCache(String token, LoginUser loginUser) { |
| 273 | // 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存 | 291 | // 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存 |
| 274 | if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() < | 292 | if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() < |
| 275 | - userSessionService.getSessionTimeoutMillis() / 3) { | 293 | + userSessionCoreService.getSessionTimeoutMillis() / 3) { |
| 276 | return; | 294 | return; |
| 277 | } | 295 | } |
| 278 | 296 | ||
| 279 | // 重新加载 SysUserDO 信息 | 297 | // 重新加载 SysUserDO 信息 |
| 280 | - SysUserDO user = userService.getUser(loginUser.getId()); | 298 | + SysUserDO user = userCoreService.getUser(loginUser.getId()); |
| 281 | if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { | 299 | if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { |
| 282 | - throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 | 300 | + throw exception(AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 |
| 283 | } | 301 | } |
| 284 | 302 | ||
| 285 | // 刷新 LoginUser 缓存 | 303 | // 刷新 LoginUser 缓存 |
| 286 | loginUser.setDeptId(user.getDeptId()); | 304 | loginUser.setDeptId(user.getDeptId()); |
| 287 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); | 305 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); |
| 288 | - userSessionService.refreshUserSession(token, loginUser); | 306 | + userSessionCoreService.refreshUserSession(token, loginUser); |
| 289 | } | 307 | } |
| 290 | 308 | ||
| 291 | } | 309 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysUserSessionServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.util.IdUtil; | ||
| 5 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | -import cn.iocoder.yudao.framework.security.config.SecurityProperties; | ||
| 8 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 9 | -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; |
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysLoginUserRedisDAO; | ||
| 16 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; | 7 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 17 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 8 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; |
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; |
| 19 | -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; | ||
| 20 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 21 | -import com.baomidou.mybatisplus.core.conditions.Wrapper; | ||
| 22 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 23 | -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; | ||
| 14 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 15 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 17 | +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 24 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
| 25 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 26 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 27 | 21 | ||
| 28 | import javax.annotation.Resource; | 22 | import javax.annotation.Resource; |
| 29 | -import java.time.Duration; | ||
| 30 | -import java.util.*; | 23 | +import java.util.ArrayList; |
| 24 | +import java.util.Collection; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.Map; | ||
| 31 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
| 32 | 28 | ||
| 33 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 29 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 34 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | ||
| 35 | 30 | ||
| 36 | /** | 31 | /** |
| 37 | * 在线用户 Session Service 实现类 | 32 | * 在线用户 Session Service 实现类 |
| @@ -43,72 +38,14 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | @@ -43,72 +38,14 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | ||
| 43 | public class SysUserSessionServiceImpl implements SysUserSessionService { | 38 | public class SysUserSessionServiceImpl implements SysUserSessionService { |
| 44 | 39 | ||
| 45 | @Resource | 40 | @Resource |
| 46 | - private SecurityProperties securityProperties; | ||
| 47 | - @Resource | ||
| 48 | - private SysLoginUserRedisDAO loginUserRedisDAO; | ||
| 49 | - @Resource | ||
| 50 | private SysUserSessionMapper userSessionMapper; | 41 | private SysUserSessionMapper userSessionMapper; |
| 51 | @Resource | 42 | @Resource |
| 52 | private SysUserService userService; | 43 | private SysUserService userService; |
| 53 | @Resource | 44 | @Resource |
| 54 | - private SysLoginLogService loginLogService; | ||
| 55 | - | ||
| 56 | - @Override | ||
| 57 | - public String createUserSession(LoginUser loginUser, String userIp, String userAgent) { | ||
| 58 | - // 生成 Session 编号 | ||
| 59 | - String sessionId = generateSessionId(); | ||
| 60 | - // 写入 Redis 缓存 | ||
| 61 | - loginUser.setUpdateTime(new Date()); | ||
| 62 | - loginUserRedisDAO.set(sessionId, loginUser); | ||
| 63 | - // 写入 DB 中 | ||
| 64 | - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 65 | - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) | ||
| 66 | - .sessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))) | ||
| 67 | - .build(); | ||
| 68 | - userSessionMapper.insert(userSession); | ||
| 69 | - // 返回 Session 编号 | ||
| 70 | - return sessionId; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - @Override | ||
| 74 | - public void refreshUserSession(String sessionId, LoginUser loginUser) { | ||
| 75 | - // 写入 Redis 缓存 | ||
| 76 | - loginUser.setUpdateTime(new Date()); | ||
| 77 | - loginUserRedisDAO.set(sessionId, loginUser); | ||
| 78 | - // 更新 DB 中 | ||
| 79 | - SysUserSessionDO updateObj = SysUserSessionDO.builder().id(sessionId).build(); | ||
| 80 | - updateObj.setUsername(loginUser.getUsername()); | ||
| 81 | - updateObj.setUpdateTime(new Date()); | ||
| 82 | - updateObj.setSessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))); | ||
| 83 | - userSessionMapper.updateById(updateObj); | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - @Override | ||
| 87 | - public void deleteUserSession(String sessionId) { | ||
| 88 | - // 删除 Redis 缓存 | ||
| 89 | - loginUserRedisDAO.delete(sessionId); | ||
| 90 | - // 删除 DB 记录 | ||
| 91 | - userSessionMapper.deleteById(sessionId); | ||
| 92 | - } | 45 | + private SysLoginLogCoreService loginLogCoreService; |
| 93 | 46 | ||
| 94 | - @Override | ||
| 95 | - public LoginUser getLoginUser(String sessionId) { | ||
| 96 | - return loginUserRedisDAO.get(sessionId); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - @Override | ||
| 100 | - public String getSessionId(String username) { | ||
| 101 | - QueryWrapper<SysUserSessionDO> wrapper = new QueryWrapper<>(); | ||
| 102 | - wrapper.eq("username", username); | ||
| 103 | - wrapper.orderByDesc("create_time"); | ||
| 104 | - SysUserSessionDO sysUserSessionDO = userSessionMapper.selectOne(wrapper); | ||
| 105 | - return sysUserSessionDO.getId(); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - @Override | ||
| 109 | - public Long getSessionTimeoutMillis() { | ||
| 110 | - return securityProperties.getSessionTimeout().toMillis(); | ||
| 111 | - } | 47 | + @Resource |
| 48 | + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; | ||
| 112 | 49 | ||
| 113 | @Override | 50 | @Override |
| 114 | public PageResult<SysUserSessionDO> getUserSessionPage(SysUserSessionPageReqVO reqVO) { | 51 | public PageResult<SysUserSessionDO> getUserSessionPage(SysUserSessionPageReqVO reqVO) { |
| @@ -123,18 +60,20 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { | @@ -123,18 +60,20 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { | ||
| 123 | return userSessionMapper.selectPage(reqVO, userIds); | 60 | return userSessionMapper.selectPage(reqVO, userIds); |
| 124 | } | 61 | } |
| 125 | 62 | ||
| 63 | + // TODO @芋艿:优化下该方法 | ||
| 126 | @Override | 64 | @Override |
| 127 | public long clearSessionTimeout() { | 65 | public long clearSessionTimeout() { |
| 128 | // 获取db里已经超时的用户列表 | 66 | // 获取db里已经超时的用户列表 |
| 129 | List<SysUserSessionDO> sessionTimeoutDOS = userSessionMapper.selectListBySessionTimoutLt(); | 67 | List<SysUserSessionDO> sessionTimeoutDOS = userSessionMapper.selectListBySessionTimoutLt(); |
| 130 | Map<String, SysUserSessionDO> timeoutSessionDOMap = sessionTimeoutDOS | 68 | Map<String, SysUserSessionDO> timeoutSessionDOMap = sessionTimeoutDOS |
| 131 | .stream() | 69 | .stream() |
| 132 | - .filter(sessionDO -> loginUserRedisDAO.get(sessionDO.getId()) == null) | 70 | + .filter(sessionDO -> loginUserCoreRedisDAO.get(sessionDO.getId()) == null) |
| 133 | .collect(Collectors.toMap(SysUserSessionDO::getId, o -> o)); | 71 | .collect(Collectors.toMap(SysUserSessionDO::getId, o -> o)); |
| 134 | // 确认已经超时,按批次移出在线用户列表 | 72 | // 确认已经超时,按批次移出在线用户列表 |
| 135 | if (CollUtil.isNotEmpty(timeoutSessionDOMap)) { | 73 | if (CollUtil.isNotEmpty(timeoutSessionDOMap)) { |
| 136 | - Lists.partition(new ArrayList<>(timeoutSessionDOMap.keySet()), 100).forEach(userSessionMapper::deleteBatchIds); | ||
| 137 | - //记录用户超时退出日志 | 74 | + Lists.partition(new ArrayList<>(timeoutSessionDOMap.keySet()), 100) |
| 75 | + .forEach(userSessionMapper::deleteBatchIds); | ||
| 76 | + // 记录用户超时退出日志 | ||
| 138 | createTimeoutLogoutLog(timeoutSessionDOMap.values()); | 77 | createTimeoutLogoutLog(timeoutSessionDOMap.values()); |
| 139 | } | 78 | } |
| 140 | return timeoutSessionDOMap.size(); | 79 | return timeoutSessionDOMap.size(); |
| @@ -142,24 +81,17 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { | @@ -142,24 +81,17 @@ public class SysUserSessionServiceImpl implements SysUserSessionService { | ||
| 142 | 81 | ||
| 143 | private void createTimeoutLogoutLog(Collection<SysUserSessionDO> timeoutSessionDOS) { | 82 | private void createTimeoutLogoutLog(Collection<SysUserSessionDO> timeoutSessionDOS) { |
| 144 | for (SysUserSessionDO timeoutSessionDO : timeoutSessionDOS) { | 83 | for (SysUserSessionDO timeoutSessionDO : timeoutSessionDOS) { |
| 145 | - SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); | ||
| 146 | - reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_TIMEOUT.getType()); | ||
| 147 | - reqVO.setTraceId(TracerUtils.getTraceId()); | ||
| 148 | - reqVO.setUsername(timeoutSessionDO.getUsername()); | ||
| 149 | - reqVO.setUserAgent(timeoutSessionDO.getUserAgent()); | ||
| 150 | - reqVO.setUserIp(timeoutSessionDO.getUserIp()); | ||
| 151 | - reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult()); | ||
| 152 | - loginLogService.createLoginLog(reqVO); | 84 | + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 85 | + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_TIMEOUT.getType()); | ||
| 86 | + reqDTO.setTraceId(TracerUtils.getTraceId()); | ||
| 87 | + reqDTO.setUserId(timeoutSessionDO.getUserId()); | ||
| 88 | + reqDTO.setUserType(timeoutSessionDO.getUserType()); | ||
| 89 | + reqDTO.setUsername(timeoutSessionDO.getUsername()); | ||
| 90 | + reqDTO.setUserAgent(timeoutSessionDO.getUserAgent()); | ||
| 91 | + reqDTO.setUserIp(timeoutSessionDO.getUserIp()); | ||
| 92 | + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); | ||
| 93 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 153 | } | 94 | } |
| 154 | } | 95 | } |
| 155 | 96 | ||
| 156 | - /** | ||
| 157 | - * 生成 Session 编号,目前采用 UUID 算法 | ||
| 158 | - * | ||
| 159 | - * @return Session 编号 | ||
| 160 | - */ | ||
| 161 | - private static String generateSessionId() { | ||
| 162 | - return IdUtil.fastSimpleUUID(); | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | } | 97 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; | 5 | import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 10 | 10 | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
| 12 | 12 | ||
| @@ -15,12 +15,7 @@ import java.util.List; | @@ -15,12 +15,7 @@ import java.util.List; | ||
| 15 | * | 15 | * |
| 16 | * @author ruoyi | 16 | * @author ruoyi |
| 17 | */ | 17 | */ |
| 18 | -public interface SysDictDataService extends DictDataFrameworkService { | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * 初始化字典数据的本地缓存 | ||
| 22 | - */ | ||
| 23 | - void initLocalCache(); | 18 | +public interface SysDictDataService { |
| 24 | 19 | ||
| 25 | /** | 20 | /** |
| 26 | * 创建字典数据 | 21 | * 创建字典数据 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict.impl; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | -import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; | ||
| 7 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; | 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.dict.SysDictDataConvert; |
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; |
| 15 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; |
| 16 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; | 10 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; |
| 17 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictDataService; |
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictTypeService; | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.dict.SysDictTypeService; |
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 14 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 15 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 19 | import com.google.common.annotations.VisibleForTesting; | 16 | import com.google.common.annotations.VisibleForTesting; |
| 20 | -import com.google.common.collect.ImmutableTable; | ||
| 21 | import lombok.extern.slf4j.Slf4j; | 17 | import lombok.extern.slf4j.Slf4j; |
| 22 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 23 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
| 24 | 19 | ||
| 25 | -import javax.annotation.PostConstruct; | ||
| 26 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 27 | import java.util.Comparator; | 21 | import java.util.Comparator; |
| 28 | import java.util.Date; | 22 | import java.util.Date; |
| 29 | import java.util.List; | 23 | import java.util.List; |
| 30 | 24 | ||
| 31 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 32 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 25 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 26 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 33 | 27 | ||
| 34 | /** | 28 | /** |
| 35 | * 字典数据 Service 实现类 | 29 | * 字典数据 Service 实现类 |
| @@ -47,31 +41,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -47,31 +41,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 47 | .comparing(SysDictDataDO::getDictType) | 41 | .comparing(SysDictDataDO::getDictType) |
| 48 | .thenComparingInt(SysDictDataDO::getSort); | 42 | .thenComparingInt(SysDictDataDO::getSort); |
| 49 | 43 | ||
| 50 | - /** | ||
| 51 | - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 | ||
| 52 | - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 | ||
| 53 | - */ | ||
| 54 | - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; | ||
| 55 | - | ||
| 56 | - /** | ||
| 57 | - * 字典数据缓存,第二个 key 使用 label | ||
| 58 | - * | ||
| 59 | - * key1:字典类型 dictType | ||
| 60 | - * key2:字典标签 label | ||
| 61 | - */ | ||
| 62 | - private ImmutableTable<String, String, SysDictDataDO> labelDictDataCache; | ||
| 63 | - /** | ||
| 64 | - * 字典数据缓存,第二个 key 使用 value | ||
| 65 | - * | ||
| 66 | - * key1:字典类型 dictType | ||
| 67 | - * key2:字典值 value | ||
| 68 | - */ | ||
| 69 | - private ImmutableTable<String, String, SysDictDataDO> valueDictDataCache; | ||
| 70 | - /** | ||
| 71 | - * 缓存字典数据的最大更新时间,用于后续的增量轮询,判断是否有更新 | ||
| 72 | - */ | ||
| 73 | - private volatile Date maxUpdateTime; | ||
| 74 | - | ||
| 75 | @Resource | 44 | @Resource |
| 76 | private SysDictTypeService dictTypeService; | 45 | private SysDictTypeService dictTypeService; |
| 77 | 46 | ||
| @@ -81,34 +50,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -81,34 +50,6 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 81 | @Resource | 50 | @Resource |
| 82 | private SysDictDataProducer dictDataProducer; | 51 | private SysDictDataProducer dictDataProducer; |
| 83 | 52 | ||
| 84 | - @Override | ||
| 85 | - @PostConstruct | ||
| 86 | - public synchronized void initLocalCache() { | ||
| 87 | - // 获取字典数据列表,如果有更新 | ||
| 88 | - List<SysDictDataDO> dataList = this.loadDictDataIfUpdate(maxUpdateTime); | ||
| 89 | - if (CollUtil.isEmpty(dataList)) { | ||
| 90 | - return; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - // 构建缓存 | ||
| 94 | - ImmutableTable.Builder<String, String, SysDictDataDO> labelDictDataBuilder = ImmutableTable.builder(); | ||
| 95 | - ImmutableTable.Builder<String, String, SysDictDataDO> valueDictDataBuilder = ImmutableTable.builder(); | ||
| 96 | - dataList.forEach(dictData -> { | ||
| 97 | - labelDictDataBuilder.put(dictData.getDictType(), dictData.getLabel(), dictData); | ||
| 98 | - valueDictDataBuilder.put(dictData.getDictType(), dictData.getValue(), dictData); | ||
| 99 | - }); | ||
| 100 | - labelDictDataCache = labelDictDataBuilder.build(); | ||
| 101 | - valueDictDataCache = valueDictDataBuilder.build(); | ||
| 102 | - assert dataList.size() > 0; // 断言,避免告警 | ||
| 103 | - maxUpdateTime = dataList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); | ||
| 104 | - log.info("[initLocalCache][缓存字典数据,数量为:{}]", dataList.size()); | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) | ||
| 108 | - public void schedulePeriodicRefresh() { | ||
| 109 | - initLocalCache(); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | /** | 53 | /** |
| 113 | * 如果字典数据发生变化,从数据库中获取最新的全量字典数据。 | 54 | * 如果字典数据发生变化,从数据库中获取最新的全量字典数据。 |
| 114 | * 如果未发生变化,则返回空 | 55 | * 如果未发生变化,则返回空 |
| @@ -238,19 +179,4 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -238,19 +179,4 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 238 | } | 179 | } |
| 239 | } | 180 | } |
| 240 | 181 | ||
| 241 | - @Override | ||
| 242 | - public DictDataRespDTO getDictDataFromCache(String type, String value) { | ||
| 243 | - return SysDictDataConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - @Override | ||
| 247 | - public DictDataRespDTO parseDictDataFromCache(String type, String label) { | ||
| 248 | - return SysDictDataConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); | ||
| 249 | - } | ||
| 250 | - | ||
| 251 | - @Override | ||
| 252 | - public List<DictDataRespDTO> listDictDatasFromCache(String type) { | ||
| 253 | - return SysDictDataConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); | ||
| 254 | - } | ||
| 255 | - | ||
| 256 | } | 182 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.logger; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.logger; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | 7 | ||
| 9 | import java.util.List; | 8 | import java.util.List; |
| 10 | 9 | ||
| @@ -14,13 +13,6 @@ import java.util.List; | @@ -14,13 +13,6 @@ import java.util.List; | ||
| 14 | public interface SysLoginLogService { | 13 | public interface SysLoginLogService { |
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| 17 | - * 创建登录日志 | ||
| 18 | - * | ||
| 19 | - * @param reqVO 日志信息 | ||
| 20 | - */ | ||
| 21 | - void createLoginLog(SysLoginLogCreateReqVO reqVO); | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | * 获得登录日志分页 | 16 | * 获得登录日志分页 |
| 25 | * | 17 | * |
| 26 | * @param reqVO 分页条件 | 18 | * @param reqVO 分页条件 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.logger.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.logger.impl; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | ||
| 5 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysLoginLogConvert; | ||
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; | 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; | 6 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; |
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 14 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 15 | 10 | ||
| 16 | import javax.annotation.Resource; | 11 | import javax.annotation.Resource; |
| @@ -24,21 +19,6 @@ public class SysLoginLogServiceImpl implements SysLoginLogService { | @@ -24,21 +19,6 @@ public class SysLoginLogServiceImpl implements SysLoginLogService { | ||
| 24 | 19 | ||
| 25 | @Resource | 20 | @Resource |
| 26 | private SysLoginLogMapper loginLogMapper; | 21 | private SysLoginLogMapper loginLogMapper; |
| 27 | - @Resource | ||
| 28 | - private SysUserService userService; | ||
| 29 | - | ||
| 30 | - @Override | ||
| 31 | - public void createLoginLog(SysLoginLogCreateReqVO reqVO) { | ||
| 32 | - SysLoginLogDO loginLog = SysLoginLogConvert.INSTANCE.convert(reqVO); | ||
| 33 | - // 获得用户 | ||
| 34 | - SysUserDO user = userService.getUserByUsername(reqVO.getUsername()); | ||
| 35 | - if (user != null) { | ||
| 36 | - loginLog.setUserId(user.getId()); | ||
| 37 | - } | ||
| 38 | - loginLog.setUserType(UserTypeEnum.ADMIN.getValue()); | ||
| 39 | - // 插入 | ||
| 40 | - loginLogMapper.insert(loginLog); | ||
| 41 | - } | ||
| 42 | 22 | ||
| 43 | @Override | 23 | @Override |
| 44 | public PageResult<SysLoginLogDO> getLoginLogPage(SysLoginLogPageReqVO reqVO) { | 24 | public PageResult<SysLoginLogDO> getLoginLogPage(SysLoginLogPageReqVO reqVO) { |
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; | @@ -2,17 +2,17 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger.impl; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; | 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.logger.SysOperateLogConvert; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysOperateLogService; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 15 | import cn.iocoder.yudao.framework.common.util.string.StrUtils; | 14 | import cn.iocoder.yudao.framework.common.util.string.StrUtils; |
| 15 | +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 16 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.springframework.scheduling.annotation.Async; | 17 | import org.springframework.scheduling.annotation.Async; |
| 18 | import org.springframework.scheduling.annotation.AsyncResult; | 18 | import org.springframework.scheduling.annotation.AsyncResult; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsChannelService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 8 | 8 | ||
| 9 | import javax.validation.Valid; | 9 | import javax.validation.Valid; |
| 10 | import java.util.Collection; | 10 | import java.util.Collection; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsLogService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | 7 | ||
| 9 | -import java.util.Date; | ||
| 10 | import java.util.List; | 8 | import java.util.List; |
| 11 | -import java.util.Map; | ||
| 12 | 9 | ||
| 13 | /** | 10 | /** |
| 14 | - * 短信日志 Service 实现类 | 11 | + * 短信日志 Service 接口 |
| 15 | * | 12 | * |
| 16 | * @author zzf | 13 | * @author zzf |
| 17 | * @date 13:48 2021/3/2 | 14 | * @date 13:48 2021/3/2 |
| @@ -19,46 +16,6 @@ import java.util.Map; | @@ -19,46 +16,6 @@ import java.util.Map; | ||
| 19 | public interface SysSmsLogService { | 16 | public interface SysSmsLogService { |
| 20 | 17 | ||
| 21 | /** | 18 | /** |
| 22 | - * 创建短信日志 | ||
| 23 | - * | ||
| 24 | - * @param mobile 手机号 | ||
| 25 | - * @param userId 用户编号 | ||
| 26 | - * @param userType 用户类型 | ||
| 27 | - * @param isSend 是否发送 | ||
| 28 | - * @param template 短信模板 | ||
| 29 | - * @param templateContent 短信内容 | ||
| 30 | - * @param templateParams 短信参数 | ||
| 31 | - * @return 发送日志编号 | ||
| 32 | - */ | ||
| 33 | - Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, | ||
| 34 | - SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams); | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * 更新日志的发送结果 | ||
| 38 | - * | ||
| 39 | - * @param id 日志编号 | ||
| 40 | - * @param sendCode 发送结果的编码 | ||
| 41 | - * @param sendMsg 发送结果的提示 | ||
| 42 | - * @param apiSendCode 短信 API 发送结果的编码 | ||
| 43 | - * @param apiSendMsg 短信 API 发送失败的提示 | ||
| 44 | - * @param apiRequestId 短信 API 发送返回的唯一请求 ID | ||
| 45 | - * @param apiSerialNo 短信 API 发送返回的序号 | ||
| 46 | - */ | ||
| 47 | - void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, | ||
| 48 | - String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo); | ||
| 49 | - | ||
| 50 | - /** | ||
| 51 | - * 更新日志的接收结果 | ||
| 52 | - * | ||
| 53 | - * @param id 日志编号 | ||
| 54 | - * @param success 是否接收成功 | ||
| 55 | - * @param receiveTime 用户接收时间 | ||
| 56 | - * @param apiReceiveCode API 接收结果的编码 | ||
| 57 | - * @param apiReceiveMsg API 接收结果的说明 | ||
| 58 | - */ | ||
| 59 | - void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg); | ||
| 60 | - | ||
| 61 | - /** | ||
| 62 | * 获得短信日志分页 | 19 | * 获得短信日志分页 |
| 63 | * | 20 | * |
| 64 | * @param pageReqVO 分页查询 | 21 | * @param pageReqVO 分页查询 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; |
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | 9 | ||
| 10 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 11 | import java.util.Collection; | 11 | import java.util.Collection; |
| 12 | import java.util.List; | 12 | import java.util.List; |
| 13 | -import java.util.Map; | ||
| 14 | 13 | ||
| 15 | /** | 14 | /** |
| 16 | * 短信模板 Service 接口 | 15 | * 短信模板 Service 接口 |
| @@ -21,11 +20,6 @@ import java.util.Map; | @@ -21,11 +20,6 @@ import java.util.Map; | ||
| 21 | public interface SysSmsTemplateService { | 20 | public interface SysSmsTemplateService { |
| 22 | 21 | ||
| 23 | /** | 22 | /** |
| 24 | - * 初始化短信模板的本地缓存 | ||
| 25 | - */ | ||
| 26 | - void initLocalCache(); | ||
| 27 | - | ||
| 28 | - /** | ||
| 29 | * 获得短信模板 | 23 | * 获得短信模板 |
| 30 | * | 24 | * |
| 31 | * @param code 模板编码 | 25 | * @param code 模板编码 |
| @@ -34,23 +28,6 @@ public interface SysSmsTemplateService { | @@ -34,23 +28,6 @@ public interface SysSmsTemplateService { | ||
| 34 | SysSmsTemplateDO getSmsTemplateByCode(String code); | 28 | SysSmsTemplateDO getSmsTemplateByCode(String code); |
| 35 | 29 | ||
| 36 | /** | 30 | /** |
| 37 | - * 获得短信模板,从缓存中 | ||
| 38 | - * | ||
| 39 | - * @param code 模板编码 | ||
| 40 | - * @return 短信模板 | ||
| 41 | - */ | ||
| 42 | - SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code); | ||
| 43 | - | ||
| 44 | - /** | ||
| 45 | - * 格式化短信内容 | ||
| 46 | - * | ||
| 47 | - * @param content 短信模板的内容 | ||
| 48 | - * @param params 内容的参数 | ||
| 49 | - * @return 格式化后的内容 | ||
| 50 | - */ | ||
| 51 | - String formatSmsTemplateContent(String content, Map<String, Object> params); | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | * 创建短信模板 | 31 | * 创建短信模板 |
| 55 | * | 32 | * |
| 56 | * @param createReqVO 创建信息 | 33 | * @param createReqVO 创建信息 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 6 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 7 | -import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; | 7 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsChannelConvert; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | 9 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; |
| 15 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; |
| 16 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 14 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 15 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 16 | +import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; | ||
| 17 | import lombok.extern.slf4j.Slf4j; | 17 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.springframework.scheduling.annotation.Scheduled; | 18 | import org.springframework.scheduling.annotation.Scheduled; |
| 19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| @@ -25,9 +25,9 @@ import java.util.Comparator; | @@ -25,9 +25,9 @@ import java.util.Comparator; | ||
| 25 | import java.util.Date; | 25 | import java.util.Date; |
| 26 | import java.util.List; | 26 | import java.util.List; |
| 27 | 27 | ||
| 28 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 29 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; | 28 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN; |
| 30 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; | 29 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS; |
| 30 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | * 短信渠道Service实现类 | 33 | * 短信渠道Service实现类 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsLogServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | 3 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; | 5 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; | 6 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; |
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 13 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
| 14 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 15 | 11 | ||
| 16 | import javax.annotation.Resource; | 12 | import javax.annotation.Resource; |
| 17 | -import java.util.Date; | ||
| 18 | import java.util.List; | 13 | import java.util.List; |
| 19 | -import java.util.Map; | ||
| 20 | -import java.util.Objects; | ||
| 21 | 14 | ||
| 22 | /** | 15 | /** |
| 23 | * 短信日志 Service 实现类 | 16 | * 短信日志 Service 实现类 |
| @@ -33,47 +26,6 @@ public class SysSmsLogServiceImpl implements SysSmsLogService { | @@ -33,47 +26,6 @@ public class SysSmsLogServiceImpl implements SysSmsLogService { | ||
| 33 | private SysSmsLogMapper smsLogMapper; | 26 | private SysSmsLogMapper smsLogMapper; |
| 34 | 27 | ||
| 35 | @Override | 28 | @Override |
| 36 | - public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, | ||
| 37 | - SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams) { | ||
| 38 | - SysSmsLogDO.SysSmsLogDOBuilder logBuilder = SysSmsLogDO.builder(); | ||
| 39 | - // 根据是否要发送,设置状态 | ||
| 40 | - logBuilder.sendStatus(Objects.equals(isSend, true) ? SysSmsSendStatusEnum.INIT.getStatus() | ||
| 41 | - : SysSmsSendStatusEnum.IGNORE.getStatus()); | ||
| 42 | - // 设置手机相关字段 | ||
| 43 | - logBuilder.mobile(mobile).userId(userId).userType(userType); | ||
| 44 | - // 设置模板相关字段 | ||
| 45 | - logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); | ||
| 46 | - logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId()); | ||
| 47 | - // 设置渠道相关字段 | ||
| 48 | - logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); | ||
| 49 | - // 设置接收相关字段 | ||
| 50 | - logBuilder.receiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus()); | ||
| 51 | - | ||
| 52 | - // 插入数据库 | ||
| 53 | - SysSmsLogDO logDO = logBuilder.build(); | ||
| 54 | - smsLogMapper.insert(logDO); | ||
| 55 | - return logDO.getId(); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, | ||
| 60 | - String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) { | ||
| 61 | - SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS | ||
| 62 | - : SysSmsSendStatusEnum.FAILURE; | ||
| 63 | - smsLogMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date()) | ||
| 64 | - .sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg) | ||
| 65 | - .apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build()); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - public void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg) { | ||
| 70 | - SysSmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? SysSmsReceiveStatusEnum.SUCCESS | ||
| 71 | - : SysSmsReceiveStatusEnum.FAILURE; | ||
| 72 | - smsLogMapper.updateById(SysSmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()).receiveTime(receiveTime) | ||
| 73 | - .apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build()); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - @Override | ||
| 77 | public PageResult<SysSmsLogDO> getSmsLogPage(SysSmsLogPageReqVO pageReqVO) { | 29 | public PageResult<SysSmsLogDO> getSmsLogPage(SysSmsLogPageReqVO pageReqVO) { |
| 78 | return smsLogMapper.selectPage(pageReqVO); | 30 | return smsLogMapper.selectPage(pageReqVO); |
| 79 | } | 31 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.util.ReUtil; | 3 | import cn.hutool.core.util.ReUtil; |
| 5 | -import cn.hutool.core.util.StrUtil; | ||
| 6 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 9 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | ||
| 10 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 11 | -import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | ||
| 12 | -import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; |
| 15 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; |
| 16 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; |
| 17 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; | 8 | import cn.iocoder.yudao.adminserver.modules.system.convert.sms.SysSmsTemplateConvert; |
| 18 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 19 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 20 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; |
| 21 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | 10 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; |
| 22 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsChannelService; |
| 23 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; |
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 14 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 15 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 17 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | ||
| 18 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 19 | +import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | ||
| 20 | +import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 24 | import com.google.common.annotations.VisibleForTesting; | 21 | import com.google.common.annotations.VisibleForTesting; |
| 25 | -import com.google.common.collect.ImmutableMap; | ||
| 26 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| 27 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 28 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
| 29 | import org.springframework.util.Assert; | 24 | import org.springframework.util.Assert; |
| 30 | 25 | ||
| 31 | -import javax.annotation.PostConstruct; | ||
| 32 | import javax.annotation.Resource; | 26 | import javax.annotation.Resource; |
| 33 | -import java.util.*; | 27 | +import java.util.Collection; |
| 28 | +import java.util.List; | ||
| 29 | +import java.util.Objects; | ||
| 34 | import java.util.regex.Pattern; | 30 | import java.util.regex.Pattern; |
| 35 | 31 | ||
| 36 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 37 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 32 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 33 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 38 | 34 | ||
| 39 | /** | 35 | /** |
| 40 | * 短信模板Service实现类 | 36 | * 短信模板Service实现类 |
| @@ -51,24 +47,6 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { | @@ -51,24 +47,6 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { | ||
| 51 | */ | 47 | */ |
| 52 | private static final Pattern PATTERN_PARAMS = Pattern.compile("\\{(.*?)}"); | 48 | private static final Pattern PATTERN_PARAMS = Pattern.compile("\\{(.*?)}"); |
| 53 | 49 | ||
| 54 | - /** | ||
| 55 | - * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 | ||
| 56 | - * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 | ||
| 57 | - */ | ||
| 58 | - private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; | ||
| 59 | - | ||
| 60 | - /** | ||
| 61 | - * 短信模板缓存 | ||
| 62 | - * key:短信模板编码 {@link SysSmsTemplateDO#getCode()} | ||
| 63 | - * | ||
| 64 | - * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 | ||
| 65 | - */ | ||
| 66 | - private volatile Map<String, SysSmsTemplateDO> smsTemplateCache; | ||
| 67 | - /** | ||
| 68 | - * 缓存短信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 | ||
| 69 | - */ | ||
| 70 | - private volatile Date maxUpdateTime; | ||
| 71 | - | ||
| 72 | @Resource | 50 | @Resource |
| 73 | private SysSmsTemplateMapper smsTemplateMapper; | 51 | private SysSmsTemplateMapper smsTemplateMapper; |
| 74 | 52 | ||
| @@ -81,68 +59,11 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { | @@ -81,68 +59,11 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { | ||
| 81 | @Resource | 59 | @Resource |
| 82 | private SysSmsProducer smsProducer; | 60 | private SysSmsProducer smsProducer; |
| 83 | 61 | ||
| 84 | - /** | ||
| 85 | - * 初始化 {@link #smsTemplateCache} 缓存 | ||
| 86 | - */ | ||
| 87 | - @Override | ||
| 88 | - @PostConstruct | ||
| 89 | - public void initLocalCache() { | ||
| 90 | - // 获取短信模板列表,如果有更新 | ||
| 91 | - List<SysSmsTemplateDO> smsTemplateList = this.loadSmsTemplateIfUpdate(maxUpdateTime); | ||
| 92 | - if (CollUtil.isEmpty(smsTemplateList)) { | ||
| 93 | - return; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - // 写入缓存 | ||
| 97 | - ImmutableMap.Builder<String, SysSmsTemplateDO> builder = ImmutableMap.builder(); | ||
| 98 | - smsTemplateList.forEach(sysSmsTemplateDO -> builder.put(sysSmsTemplateDO.getCode(), sysSmsTemplateDO)); | ||
| 99 | - smsTemplateCache = builder.build(); | ||
| 100 | - assert smsTemplateList.size() > 0; // 断言,避免告警 | ||
| 101 | - maxUpdateTime = smsTemplateList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); | ||
| 102 | - log.info("[initLocalCache][初始化 SmsTemplate 数量为 {}]", smsTemplateList.size()); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) | ||
| 106 | - public void schedulePeriodicRefresh() { | ||
| 107 | - initLocalCache(); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - /** | ||
| 111 | - * 如果短信模板发生变化,从数据库中获取最新的全量短信模板。 | ||
| 112 | - * 如果未发生变化,则返回空 | ||
| 113 | - * | ||
| 114 | - * @param maxUpdateTime 当前短信模板的最大更新时间 | ||
| 115 | - * @return 短信模板列表 | ||
| 116 | - */ | ||
| 117 | - private List<SysSmsTemplateDO> loadSmsTemplateIfUpdate(Date maxUpdateTime) { | ||
| 118 | - // 第一步,判断是否要更新。 | ||
| 119 | - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 | ||
| 120 | - log.info("[loadSmsTemplateIfUpdate][首次加载全量短信模板]"); | ||
| 121 | - } else { // 判断数据库中是否有更新的短信模板 | ||
| 122 | - if (smsTemplateMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) { | ||
| 123 | - return null; | ||
| 124 | - } | ||
| 125 | - log.info("[loadSmsTemplateIfUpdate][增量加载全量短信模板]"); | ||
| 126 | - } | ||
| 127 | - // 第二步,如果有更新,则从数据库加载所有短信模板 | ||
| 128 | - return smsTemplateMapper.selectList(); | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | @Override | 62 | @Override |
| 132 | public SysSmsTemplateDO getSmsTemplateByCode(String code) { | 63 | public SysSmsTemplateDO getSmsTemplateByCode(String code) { |
| 133 | return smsTemplateMapper.selectByCode(code); | 64 | return smsTemplateMapper.selectByCode(code); |
| 134 | } | 65 | } |
| 135 | 66 | ||
| 136 | - @Override | ||
| 137 | - public SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code) { | ||
| 138 | - return smsTemplateCache.get(code); | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - @Override | ||
| 142 | - public String formatSmsTemplateContent(String content, Map<String, Object> params) { | ||
| 143 | - return StrUtil.format(content, params); | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | @VisibleForTesting | 67 | @VisibleForTesting |
| 147 | public List<String> parseTemplateContentParams(String content) { | 68 | public List<String> parseTemplateContentParams(String content) { |
| 148 | return ReUtil.findAllGroup1(PATTERN_PARAMS, content); | 69 | return ReUtil.findAllGroup1(PATTERN_PARAMS, content); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.user; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.user; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserCreateReqVO; | ||
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; | ||
| 9 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportExcelVO; | ||
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserImportRespVO; | ||
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; | ||
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserUpdateReqVO; | ||
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | 6 | +import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; |
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 14 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 9 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 15 | 10 | ||
| 16 | import java.io.InputStream; | 11 | import java.io.InputStream; |
| @@ -20,7 +15,7 @@ import java.util.List; | @@ -20,7 +15,7 @@ import java.util.List; | ||
| 20 | import java.util.Map; | 15 | import java.util.Map; |
| 21 | 16 | ||
| 22 | /** | 17 | /** |
| 23 | - * 用户 Service 接口 | 18 | + * 后台用户 Service 接口 |
| 24 | * | 19 | * |
| 25 | * @author 芋道源码 | 20 | * @author 芋道源码 |
| 26 | */ | 21 | */ |
| @@ -42,6 +37,14 @@ public interface SysUserService { | @@ -42,6 +37,14 @@ public interface SysUserService { | ||
| 42 | void updateUser(SysUserUpdateReqVO reqVO); | 37 | void updateUser(SysUserUpdateReqVO reqVO); |
| 43 | 38 | ||
| 44 | /** | 39 | /** |
| 40 | + * 更新用户的最后登陆信息 | ||
| 41 | + * | ||
| 42 | + * @param id 用户编号 | ||
| 43 | + * @param loginIp 登陆 IP | ||
| 44 | + */ | ||
| 45 | + void updateUserLogin(Long id, String loginIp); | ||
| 46 | + | ||
| 47 | + /** | ||
| 45 | * 修改用户个人信息 | 48 | * 修改用户个人信息 |
| 46 | * | 49 | * |
| 47 | * @param id 用户编号 | 50 | * @param id 用户编号 |
| @@ -97,14 +100,6 @@ public interface SysUserService { | @@ -97,14 +100,6 @@ public interface SysUserService { | ||
| 97 | SysUserDO getUserByUsername(String username); | 100 | SysUserDO getUserByUsername(String username); |
| 98 | 101 | ||
| 99 | /** | 102 | /** |
| 100 | - * 通过用户 ID 查询用户 | ||
| 101 | - * | ||
| 102 | - * @param id 用户ID | ||
| 103 | - * @return 用户对象信息 | ||
| 104 | - */ | ||
| 105 | - SysUserDO getUser(Long id); | ||
| 106 | - | ||
| 107 | - /** | ||
| 108 | * 获得用户分页列表 | 103 | * 获得用户分页列表 |
| 109 | * | 104 | * |
| 110 | * @param reqVO 分页条件 | 105 | * @param reqVO 分页条件 |
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.*; | @@ -11,12 +11,12 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; | 11 | import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; | 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; | 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 14 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 15 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; | 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; |
| 16 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 17 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; | 16 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 17 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 19 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 18 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 19 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 20 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 20 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 21 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 21 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 22 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 22 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -85,6 +85,11 @@ public class SysUserServiceImpl implements SysUserService { | @@ -85,6 +85,11 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | @Override | 87 | @Override |
| 88 | + public void updateUserLogin(Long id, String loginIp) { | ||
| 89 | + userMapper.updateById(new SysUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 88 | public void updateUserProfile(Long id, SysUserProfileUpdateReqVO reqVO) { | 93 | public void updateUserProfile(Long id, SysUserProfileUpdateReqVO reqVO) { |
| 89 | // 校验正确性 | 94 | // 校验正确性 |
| 90 | this.checkUserExists(id); | 95 | this.checkUserExists(id); |
| @@ -155,11 +160,6 @@ public class SysUserServiceImpl implements SysUserService { | @@ -155,11 +160,6 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | @Override | 162 | @Override |
| 158 | - public SysUserDO getUser(Long id) { | ||
| 159 | - return userMapper.selectById(id); | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - @Override | ||
| 163 | public PageResult<SysUserDO> getUserPage(SysUserPageReqVO reqVO) { | 163 | public PageResult<SysUserDO> getUserPage(SysUserPageReqVO reqVO) { |
| 164 | return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId())); | 164 | return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId())); |
| 165 | } | 165 | } |
yudao-admin-server/src/main/resources/application-dev.yaml
| @@ -99,7 +99,7 @@ apollo: | @@ -99,7 +99,7 @@ apollo: | ||
| 99 | eagerLoad: | 99 | eagerLoad: |
| 100 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 | 100 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 |
| 101 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 | 101 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 |
| 102 | - dao: cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigDAOImpl | 102 | + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl |
| 103 | url: ${spring.datasource.dynamic.datasource.master.url} | 103 | url: ${spring.datasource.dynamic.datasource.master.url} |
| 104 | username: ${spring.datasource.dynamic.datasource.master.username} | 104 | username: ${spring.datasource.dynamic.datasource.master.username} |
| 105 | password: ${spring.datasource.dynamic.datasource.master.password} | 105 | password: ${spring.datasource.dynamic.datasource.master.password} |
yudao-admin-server/src/main/resources/application-local.yaml
| @@ -99,7 +99,7 @@ apollo: | @@ -99,7 +99,7 @@ apollo: | ||
| 99 | eagerLoad: | 99 | eagerLoad: |
| 100 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 | 100 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 |
| 101 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 | 101 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 |
| 102 | - dao: cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigDAOImpl | 102 | + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl |
| 103 | url: ${spring.datasource.dynamic.datasource.master.url} | 103 | url: ${spring.datasource.dynamic.datasource.master.url} |
| 104 | username: ${spring.datasource.dynamic.datasource.master.username} | 104 | username: ${spring.datasource.dynamic.datasource.master.username} |
| 105 | password: ${spring.datasource.dynamic.datasource.master.password} | 105 | password: ${spring.datasource.dynamic.datasource.master.password} |
yudao-admin-server/src/main/resources/application.yaml
| @@ -31,7 +31,7 @@ mybatis-plus: | @@ -31,7 +31,7 @@ mybatis-plus: | ||
| 31 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) | 31 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) |
| 32 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) | 32 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) |
| 33 | mapper-locations: classpath*:mapper/*.xml | 33 | mapper-locations: classpath*:mapper/*.xml |
| 34 | - type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject | 34 | + type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject |
| 35 | 35 | ||
| 36 | --- #################### 芋道相关配置 #################### | 36 | --- #################### 芋道相关配置 #################### |
| 37 | 37 | ||
| @@ -39,6 +39,8 @@ yudao: | @@ -39,6 +39,8 @@ yudao: | ||
| 39 | info: | 39 | info: |
| 40 | version: 1.0.0 | 40 | version: 1.0.0 |
| 41 | base-package: cn.iocoder.yudao.adminserver | 41 | base-package: cn.iocoder.yudao.adminserver |
| 42 | + core-service: | ||
| 43 | + base-package: cn.iocoder.yudao.coreservice | ||
| 42 | web: | 44 | web: |
| 43 | api-prefix: /api | 45 | api-prefix: /api |
| 44 | controller-package: ${yudao.info.base-package} | 46 | controller-package: ${yudao.info.base-package} |
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; | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.adminserver.BaseRedisIntegrationTest; | ||
| 5 | import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.mail.SysMailSendConsumer; | 5 | import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.mail.SysMailSendConsumer; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms.SysSmsSendConsumer; | 6 | import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms.SysSmsSendConsumer; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.mail.SysMailSendMessage; | 7 | import cn.iocoder.yudao.adminserver.modules.system.mq.message.mail.SysMailSendMessage; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | 8 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; |
| 9 | import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; | 9 | import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; |
| 10 | import org.junit.jupiter.api.Disabled; | 10 | import org.junit.jupiter.api.Disabled; |
| 11 | import org.junit.jupiter.api.Test; | 11 | import org.junit.jupiter.api.Test; |
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 | @@ -7,9 +7,9 @@ import cn.iocoder.yudao.adminserver.modules.system.mq.consumer.sms.SysSmsSendCon | ||
| 7 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | 7 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsServiceImpl; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsCoreServiceImpl; | ||
| 13 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 13 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 14 | import cn.iocoder.yudao.framework.sms.config.YudaoSmsAutoConfiguration; | 14 | import cn.iocoder.yudao.framework.sms.config.YudaoSmsAutoConfiguration; |
| 15 | import org.junit.jupiter.api.Test; | 15 | import org.junit.jupiter.api.Test; |
| @@ -20,13 +20,14 @@ import javax.annotation.Resource; | @@ -20,13 +20,14 @@ import javax.annotation.Resource; | ||
| 20 | import java.util.Map; | 20 | import java.util.Map; |
| 21 | import java.util.concurrent.TimeUnit; | 21 | import java.util.concurrent.TimeUnit; |
| 22 | 22 | ||
| 23 | +// TODO @芋艿:需要迁移 | ||
| 23 | @Import({YudaoSmsAutoConfiguration.class, | 24 | @Import({YudaoSmsAutoConfiguration.class, |
| 24 | - SysSmsChannelServiceImpl.class, SysSmsServiceImpl.class, SysSmsTemplateServiceImpl.class, SysSmsLogServiceImpl.class, | 25 | + SysSmsChannelServiceImpl.class, SysSmsCoreServiceImpl.class, SysSmsTemplateServiceImpl.class, SysSmsLogServiceImpl.class, |
| 25 | SysSmsProducer.class, SysSmsSendConsumer.class}) | 26 | SysSmsProducer.class, SysSmsSendConsumer.class}) |
| 26 | public class SysSmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest { | 27 | public class SysSmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest { |
| 27 | 28 | ||
| 28 | @Resource | 29 | @Resource |
| 29 | - private SysSmsServiceImpl smsService; | 30 | + private SysSmsCoreServiceImpl smsService; |
| 30 | @Resource | 31 | @Resource |
| 31 | private SysSmsChannelServiceImpl smsChannelService; | 32 | private SysSmsChannelServiceImpl smsChannelService; |
| 32 | 33 |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/BaseRedisUnitTest.java
| @@ -24,7 +24,7 @@ public class BaseRedisUnitTest { | @@ -24,7 +24,7 @@ public class BaseRedisUnitTest { | ||
| 24 | // Redis 配置类 | 24 | // Redis 配置类 |
| 25 | RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer | 25 | RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer |
| 26 | RedisAutoConfiguration.class, // Spring Redis 自动配置类 | 26 | RedisAutoConfiguration.class, // Spring Redis 自动配置类 |
| 27 | - YudaoTracerAutoConfiguration.class, // 自己的 Redis 配置类 | 27 | + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 |
| 28 | RedissonAutoConfiguration.class, // Redisson 自动高配置类 | 28 | RedissonAutoConfiguration.class, // Redisson 自动高配置类 |
| 29 | }) | 29 | }) |
| 30 | public static class Application { | 30 | public static class Application { |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/config/InfConfigServiceTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.config; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO; |
| 9 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.config.InfConfigDO; | ||
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper; |
| 11 | import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum; |
| 12 | import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer; |
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; | @@ -2,14 +2,15 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.resource.ResourceUtil; | 3 | import cn.hutool.core.io.resource.ResourceUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; | 7 | import cn.iocoder.yudao.adminserver.modules.infra.framework.file.config.FileProperties; |
| 7 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl; |
| 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 12 | import org.junit.jupiter.api.Test; | 12 | import org.junit.jupiter.api.Test; |
| 13 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 13 | import org.springframework.context.annotation.Import; | 14 | import org.springframework.context.annotation.Import; |
| 14 | 15 | ||
| 15 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| @@ -29,8 +30,9 @@ public class InfFileServiceTest extends BaseDbUnitTest { | @@ -29,8 +30,9 @@ public class InfFileServiceTest extends BaseDbUnitTest { | ||
| 29 | @Resource | 30 | @Resource |
| 30 | private InfFileServiceImpl fileService; | 31 | private InfFileServiceImpl fileService; |
| 31 | 32 | ||
| 32 | - @Resource | 33 | + @MockBean |
| 33 | private FileProperties fileProperties; | 34 | private FileProperties fileProperties; |
| 35 | + | ||
| 34 | @Resource | 36 | @Resource |
| 35 | private InfFileMapper fileMapper; | 37 | private InfFileMapper fileMapper; |
| 36 | 38 |
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; | @@ -2,13 +2,13 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.RandomUtil; | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | 7 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | 9 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; |
| 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl; | 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl; |
| 14 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | 14 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| @@ -39,26 +39,6 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest { | @@ -39,26 +39,6 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest { | ||
| 39 | private InfApiAccessLogMapper infApiAccessLogMapper; | 39 | private InfApiAccessLogMapper infApiAccessLogMapper; |
| 40 | 40 | ||
| 41 | @Test | 41 | @Test |
| 42 | - public void testCreateApiAccessLogAsync() throws Exception { | ||
| 43 | - ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo( | ||
| 44 | - ApiAccessLogCreateDTO.class, | ||
| 45 | - dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()) | ||
| 46 | - ); | ||
| 47 | - | ||
| 48 | - // 执行service方法 | ||
| 49 | - Future<Boolean> future = infApiAccessLogServiceImpl.createApiAccessLogAsync(createDTO); | ||
| 50 | - | ||
| 51 | - // 等异步执行完 | ||
| 52 | - future.get(); | ||
| 53 | - | ||
| 54 | - InfApiAccessLogDO infApiAccessLogDO = infApiAccessLogMapper.selectOne(null); | ||
| 55 | - // 断言 | ||
| 56 | - assertNotNull(infApiAccessLogDO); | ||
| 57 | - // 断言,忽略基本字段 | ||
| 58 | - assertPojoEquals(createDTO, infApiAccessLogDO); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Test | ||
| 62 | public void testGetApiAccessLogPage() { | 42 | public void testGetApiAccessLogPage() { |
| 63 | // 构造测试数据 | 43 | // 构造测试数据 |
| 64 | long userId = 2233L; | 44 | long userId = 2233L; |
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; | @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.logger; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.RandomUtil; | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | 8 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; | 11 | import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; |
| 12 | import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | 12 | import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; |
| 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl; | 13 | import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl; |
| @@ -41,28 +41,6 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { | @@ -41,28 +41,6 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { | ||
| 41 | @Resource | 41 | @Resource |
| 42 | private InfApiErrorLogMapper infApiErrorLogMapper; | 42 | private InfApiErrorLogMapper infApiErrorLogMapper; |
| 43 | 43 | ||
| 44 | - | ||
| 45 | - @Test | ||
| 46 | - public void testCreateApiErrorLogAsync() throws Exception { | ||
| 47 | - ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo( | ||
| 48 | - ApiErrorLogCreateDTO.class, | ||
| 49 | - dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()) | ||
| 50 | - ); | ||
| 51 | - | ||
| 52 | - // 执行service方法 | ||
| 53 | - Future<Boolean> future = infApiErrorLogServiceImpl.createApiErrorLogAsync(createDTO); | ||
| 54 | - | ||
| 55 | - // 等异步执行完 | ||
| 56 | - future.get(); | ||
| 57 | - | ||
| 58 | - InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogMapper.selectOne(null); | ||
| 59 | - // 断言 | ||
| 60 | - assertNotNull(infApiErrorLogDO); | ||
| 61 | - // 断言,忽略基本字段 | ||
| 62 | - assertPojoEquals(createDTO, infApiErrorLogDO); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - | ||
| 66 | @Test | 44 | @Test |
| 67 | public void testGetApiErrorLogPage() { | 45 | public void testGetApiErrorLogPage() { |
| 68 | // 构造测试数据 | 46 | // 构造测试数据 |
| @@ -204,4 +182,5 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { | @@ -204,4 +182,5 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest { | ||
| 204 | // 验证 progressUserId 是否修改成功 | 182 | // 验证 progressUserId 是否修改成功 |
| 205 | assertEquals(processUserId, secondSelect.getProcessUserId()); | 183 | assertEquals(processUserId, secondSelect.getProcessUserId()); |
| 206 | } | 184 | } |
| 185 | + | ||
| 207 | } | 186 | } |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 4 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; | 5 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 6 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysAuthServiceImpl; | 7 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysAuthServiceImpl; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.common.SysCaptchaService; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.service.logger.SysLoginLogService; | ||
| 13 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 10 | +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | ||
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||
| 14 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 15 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 16 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 17 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 15 | import cn.iocoder.yudao.framework.test.core.util.AssertUtils; | 18 | import cn.iocoder.yudao.framework.test.core.util.AssertUtils; |
| 16 | import org.junit.jupiter.api.Test; | 19 | import org.junit.jupiter.api.Test; |
| 17 | import org.springframework.boot.test.mock.mockito.MockBean; | 20 | import org.springframework.boot.test.mock.mockito.MockBean; |
| @@ -49,6 +52,8 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -49,6 +52,8 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 49 | @MockBean | 52 | @MockBean |
| 50 | private SysUserService userService; | 53 | private SysUserService userService; |
| 51 | @MockBean | 54 | @MockBean |
| 55 | + private SysUserCoreService userCoreService; | ||
| 56 | + @MockBean | ||
| 52 | private SysPermissionService permissionService; | 57 | private SysPermissionService permissionService; |
| 53 | @MockBean | 58 | @MockBean |
| 54 | private AuthenticationManager authenticationManager; | 59 | private AuthenticationManager authenticationManager; |
| @@ -57,9 +62,11 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -57,9 +62,11 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 57 | @MockBean | 62 | @MockBean |
| 58 | private SysCaptchaService captchaService; | 63 | private SysCaptchaService captchaService; |
| 59 | @MockBean | 64 | @MockBean |
| 60 | - private SysLoginLogService loginLogService; | 65 | + private SysLoginLogCoreService loginLogCoreService; |
| 66 | + @MockBean | ||
| 67 | + private SysUserSessionCoreService userSessionCoreService; | ||
| 61 | @MockBean | 68 | @MockBean |
| 62 | - private SysUserSessionService userSessionService; | 69 | + private SysSocialService socialService; |
| 63 | 70 | ||
| 64 | @Test | 71 | @Test |
| 65 | public void testLoadUserByUsername_success() { | 72 | public void testLoadUserByUsername_success() { |
| @@ -94,7 +101,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -94,7 +101,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 94 | Long userId = randomLongId(); | 101 | Long userId = randomLongId(); |
| 95 | // mock 方法 01 | 102 | // mock 方法 01 |
| 96 | SysUserDO user = randomPojo(SysUserDO.class, o -> o.setId(userId)); | 103 | SysUserDO user = randomPojo(SysUserDO.class, o -> o.setId(userId)); |
| 97 | - when(userService.getUser(eq(userId))).thenReturn(user); | 104 | + when(userCoreService.getUser(eq(userId))).thenReturn(user); |
| 98 | // mock 方法 02 | 105 | // mock 方法 02 |
| 99 | Set<Long> roleIds = randomSet(Long.class); | 106 | Set<Long> roleIds = randomSet(Long.class); |
| 100 | when(permissionService.getUserRoleIds(eq(userId), eq(singleton(CommonStatusEnum.ENABLE.getStatus())))) | 107 | when(permissionService.getUserRoleIds(eq(userId), eq(singleton(CommonStatusEnum.ENABLE.getStatus())))) |
| @@ -128,7 +135,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -128,7 +135,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 128 | // 调用, 并断言异常 | 135 | // 调用, 并断言异常 |
| 129 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_NOT_FOUND); | 136 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_NOT_FOUND); |
| 130 | // 校验调用参数 | 137 | // 校验调用参数 |
| 131 | - verify(loginLogService, times(1)).createLoginLog( | 138 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 132 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 139 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 133 | && o.getResult().equals(SysLoginResultEnum.CAPTCHA_NOT_FOUND.getResult())) | 140 | && o.getResult().equals(SysLoginResultEnum.CAPTCHA_NOT_FOUND.getResult())) |
| 134 | ); | 141 | ); |
| @@ -146,7 +153,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -146,7 +153,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 146 | // 调用, 并断言异常 | 153 | // 调用, 并断言异常 |
| 147 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_CODE_ERROR); | 154 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_CAPTCHA_CODE_ERROR); |
| 148 | // 校验调用参数 | 155 | // 校验调用参数 |
| 149 | - verify(loginLogService, times(1)).createLoginLog( | 156 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 150 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 157 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 151 | && o.getResult().equals(SysLoginResultEnum.CAPTCHA_CODE_ERROR.getResult())) | 158 | && o.getResult().equals(SysLoginResultEnum.CAPTCHA_CODE_ERROR.getResult())) |
| 152 | ); | 159 | ); |
| @@ -167,7 +174,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -167,7 +174,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 167 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_BAD_CREDENTIALS); | 174 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_BAD_CREDENTIALS); |
| 168 | // 校验调用参数 | 175 | // 校验调用参数 |
| 169 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); | 176 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); |
| 170 | - verify(loginLogService, times(1)).createLoginLog( | 177 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 171 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 178 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 172 | && o.getResult().equals(SysLoginResultEnum.BAD_CREDENTIALS.getResult())) | 179 | && o.getResult().equals(SysLoginResultEnum.BAD_CREDENTIALS.getResult())) |
| 173 | ); | 180 | ); |
| @@ -188,7 +195,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -188,7 +195,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 188 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_USER_DISABLED); | 195 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_USER_DISABLED); |
| 189 | // 校验调用参数 | 196 | // 校验调用参数 |
| 190 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); | 197 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); |
| 191 | - verify(loginLogService, times(1)).createLoginLog( | 198 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 192 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 199 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 193 | && o.getResult().equals(SysLoginResultEnum.USER_DISABLED.getResult())) | 200 | && o.getResult().equals(SysLoginResultEnum.USER_DISABLED.getResult())) |
| 194 | ); | 201 | ); |
| @@ -209,7 +216,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -209,7 +216,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 209 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_FAIL_UNKNOWN); | 216 | assertServiceException(() -> authService.login(reqVO, userIp, userAgent), AUTH_LOGIN_FAIL_UNKNOWN); |
| 210 | // 校验调用参数 | 217 | // 校验调用参数 |
| 211 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); | 218 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); |
| 212 | - verify(loginLogService, times(1)).createLoginLog( | 219 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 213 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 220 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 214 | && o.getResult().equals(SysLoginResultEnum.UNKNOWN_ERROR.getResult())) | 221 | && o.getResult().equals(SysLoginResultEnum.UNKNOWN_ERROR.getResult())) |
| 215 | ); | 222 | ); |
| @@ -237,13 +244,13 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -237,13 +244,13 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 237 | // mock 获得 User 拥有的角色编号数组 | 244 | // mock 获得 User 拥有的角色编号数组 |
| 238 | when(permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus()))).thenReturn(userRoleIds); | 245 | when(permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus()))).thenReturn(userRoleIds); |
| 239 | // mock 缓存登录用户到 Redis | 246 | // mock 缓存登录用户到 Redis |
| 240 | - when(userSessionService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); | 247 | + when(userSessionCoreService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); |
| 241 | // 调用, 并断言异常 | 248 | // 调用, 并断言异常 |
| 242 | String login = authService.login(reqVO, userIp, userAgent); | 249 | String login = authService.login(reqVO, userIp, userAgent); |
| 243 | assertEquals(sessionId, login); | 250 | assertEquals(sessionId, login); |
| 244 | // 校验调用参数 | 251 | // 校验调用参数 |
| 245 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); | 252 | verify(captchaService, times(1)).deleteCaptchaCode(reqVO.getUuid()); |
| 246 | - verify(loginLogService, times(1)).createLoginLog( | 253 | + verify(loginLogCoreService, times(1)).createLoginLog( |
| 247 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) | 254 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| 248 | && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) | 255 | && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) |
| 249 | ); | 256 | ); |
| @@ -255,12 +262,12 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | @@ -255,12 +262,12 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { | ||
| 255 | String token = randomString(); | 262 | String token = randomString(); |
| 256 | LoginUser loginUser = randomPojo(LoginUser.class); | 263 | LoginUser loginUser = randomPojo(LoginUser.class); |
| 257 | // mock | 264 | // mock |
| 258 | - when(userSessionService.getLoginUser(token)).thenReturn(loginUser); | 265 | + when(userSessionCoreService.getLoginUser(token)).thenReturn(loginUser); |
| 259 | // 调用 | 266 | // 调用 |
| 260 | authService.logout(token); | 267 | authService.logout(token); |
| 261 | // 校验调用参数 | 268 | // 校验调用参数 |
| 262 | - verify(userSessionService, times(1)).deleteUserSession(token); | ||
| 263 | - verify(loginLogService, times(1)).createLoginLog( | 269 | + verify(userSessionCoreService, times(1)).deleteUserSession(token); |
| 270 | + verify(loginLogCoreService, times(1)).createLoginLog( | ||
| 264 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGOUT_SELF.getType()) | 271 | argThat(o -> o.getLogType().equals(SysLoginLogTypeEnum.LOGOUT_SELF.getType()) |
| 265 | && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) | 272 | && o.getResult().equals(SysLoginResultEnum.SUCCESS.getResult())) |
| 266 | ); | 273 | ); |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionServiceImplTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; |
| 2 | 2 | ||
| 3 | -import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 4 | -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 5 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomDate; | ||
| 6 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | ||
| 7 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 8 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | ||
| 10 | -import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 11 | -import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| 12 | -import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| 13 | -import static org.junit.jupiter.api.Assertions.assertNull; | ||
| 14 | -import static org.mockito.Mockito.when; | ||
| 15 | - | ||
| 16 | -import java.time.Duration; | ||
| 17 | -import java.util.Date; | ||
| 18 | -import java.util.List; | ||
| 19 | -import java.util.stream.Collectors; | ||
| 20 | -import java.util.stream.Stream; | ||
| 21 | - | ||
| 22 | -import javax.annotation.Resource; | ||
| 23 | - | ||
| 24 | -import org.junit.jupiter.api.Test; | ||
| 25 | -import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 26 | -import org.springframework.context.annotation.Import; | ||
| 27 | - | ||
| 28 | import cn.hutool.core.date.DateUtil; | 3 | import cn.hutool.core.date.DateUtil; |
| 29 | import cn.iocoder.yudao.adminserver.BaseDbAndRedisUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbAndRedisUnitTest; |
| 30 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 31 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 32 | -import cn.iocoder.yudao.framework.security.config.SecurityProperties; | ||
| 33 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 34 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; |
| 35 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 36 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 37 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; | 6 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.auth.SysUserSessionMapper; |
| 38 | -import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; | ||
| 39 | -import cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth.SysLoginUserRedisDAO; | ||
| 40 | -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; | ||
| 41 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysUserSessionServiceImpl; | 7 | import cn.iocoder.yudao.adminserver.modules.system.service.auth.impl.SysUserSessionServiceImpl; |
| 42 | -import cn.iocoder.yudao.adminserver.modules.system.service.dept.impl.SysDeptServiceImpl; | ||
| 43 | -import cn.iocoder.yudao.adminserver.modules.system.service.logger.impl.SysLoginLogServiceImpl; | ||
| 44 | -import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; | ||
| 45 | -import cn.iocoder.yudao.framework.test.core.util.AssertUtils; | ||
| 46 | -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | 8 | +import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; | ||
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; | ||
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 14 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 15 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 47 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 17 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 18 | +import cn.iocoder.yudao.framework.test.core.util.AssertUtils; | ||
| 19 | +import org.junit.jupiter.api.Test; | ||
| 20 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 21 | +import org.springframework.context.annotation.Import; | ||
| 22 | + | ||
| 23 | +import javax.annotation.Resource; | ||
| 24 | +import java.util.Date; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.stream.Collectors; | ||
| 27 | +import java.util.stream.Stream; | ||
| 28 | + | ||
| 29 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 30 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 31 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 32 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||
| 33 | +import static java.util.Collections.singletonList; | ||
| 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 35 | +import static org.mockito.ArgumentMatchers.eq; | ||
| 36 | +import static org.mockito.Mockito.when; | ||
| 48 | 37 | ||
| 49 | /** | 38 | /** |
| 50 | - * SysUserSessionServiceImpl Tester. | 39 | + * {@link SysUserSessionServiceImpl} 的单元测试 |
| 51 | * | 40 | * |
| 52 | * @author Lyon | 41 | * @author Lyon |
| 53 | - * @version 1.0 | ||
| 54 | - * @since <pre>3月 8, 2021</pre> | ||
| 55 | */ | 42 | */ |
| 56 | -@Import({SysUserSessionServiceImpl.class, SysLoginUserRedisDAO.class}) | 43 | +@Import({SysUserSessionServiceImpl.class}) |
| 57 | public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { | 44 | public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { |
| 58 | 45 | ||
| 59 | @Resource | 46 | @Resource |
| 60 | - private SysUserSessionServiceImpl sysUserSessionService; | ||
| 61 | - @Resource | ||
| 62 | - private SysUserSessionMapper sysUserSessionMapper; | ||
| 63 | - @Resource | ||
| 64 | - private SysLoginUserRedisDAO sysLoginUserRedisDAO; | 47 | + private SysUserSessionServiceImpl userSessionService; |
| 48 | + | ||
| 65 | @Resource | 49 | @Resource |
| 66 | - private SysUserMapper sysUserMapper; | 50 | + private SysUserSessionMapper userSessionMapper; |
| 67 | 51 | ||
| 68 | @MockBean | 52 | @MockBean |
| 69 | - private SecurityProperties securityProperties; | 53 | + private SysUserService userService; |
| 70 | @MockBean | 54 | @MockBean |
| 71 | - private SysDeptServiceImpl sysDeptService; | 55 | + private SysLoginLogCoreService loginLogCoreService; |
| 72 | @MockBean | 56 | @MockBean |
| 73 | - private SysUserServiceImpl sysUserService; | ||
| 74 | - @MockBean | ||
| 75 | - private SysLoginLogServiceImpl sysLoginLogService; | ||
| 76 | - | ||
| 77 | - @Test | ||
| 78 | - public void testCreateUserSession_success() { | ||
| 79 | - // 准备参数 | ||
| 80 | - String userIp = randomString(); | ||
| 81 | - String userAgent = randomString(); | ||
| 82 | - LoginUser loginUser = randomPojo(LoginUser.class); | ||
| 83 | - // mock | ||
| 84 | - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 85 | - // 调用 | ||
| 86 | - String sessionId = sysUserSessionService.createUserSession(loginUser, userIp, userAgent); | ||
| 87 | - // 校验记录的属性是否正确 | ||
| 88 | - SysUserSessionDO sysUserSessionDO = sysUserSessionMapper.selectById(sessionId); | ||
| 89 | - assertEquals(sysUserSessionDO.getId(), sessionId); | ||
| 90 | - assertEquals(sysUserSessionDO.getUserId(), loginUser.getId()); | ||
| 91 | - assertEquals(sysUserSessionDO.getUserIp(), userIp); | ||
| 92 | - assertEquals(sysUserSessionDO.getUserAgent(), userAgent); | ||
| 93 | - assertEquals(sysUserSessionDO.getUsername(), loginUser.getUsername()); | ||
| 94 | - LoginUser redisLoginUser = sysLoginUserRedisDAO.get(sessionId); | ||
| 95 | - AssertUtils.assertPojoEquals(redisLoginUser, loginUser, "username","password"); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - @Test | ||
| 99 | - public void testCreateRefreshUserSession_success() { | ||
| 100 | - // 准备参数 | ||
| 101 | - String sessionId = randomString(); | ||
| 102 | - String userIp = randomString(); | ||
| 103 | - String userAgent = randomString(); | ||
| 104 | - Long timeLong = randomLongId(); | ||
| 105 | - String userName = randomString(); | ||
| 106 | - Date date = randomDate(); | ||
| 107 | - LoginUser loginUser = randomPojo(LoginUser.class); | ||
| 108 | - // mock | ||
| 109 | - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 110 | - loginUser.setUpdateTime(date); | ||
| 111 | - sysLoginUserRedisDAO.set(sessionId, loginUser); | ||
| 112 | - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 113 | - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(userName) | ||
| 114 | - .sessionTimeout(addTime(Duration.ofMillis(timeLong))) | ||
| 115 | - .build(); | ||
| 116 | - sysUserSessionMapper.insert(userSession); | ||
| 117 | - SysUserSessionDO insertDO = sysUserSessionMapper.selectById(sessionId); | ||
| 118 | - // 调用 | ||
| 119 | - sysUserSessionService.refreshUserSession(sessionId, loginUser); | ||
| 120 | - // 校验记录 redis | ||
| 121 | - LoginUser redisLoginUser = sysLoginUserRedisDAO.get(sessionId); | ||
| 122 | - assertNotEquals(redisLoginUser.getUpdateTime(), date); | ||
| 123 | - // 校验记录 SysUserSessionDO | ||
| 124 | - SysUserSessionDO updateDO = sysUserSessionMapper.selectById(sessionId); | ||
| 125 | - assertEquals(updateDO.getUsername(), loginUser.getUsername()); | ||
| 126 | - assertNotEquals(updateDO.getUpdateTime(), insertDO.getUpdateTime()); | ||
| 127 | - assertNotEquals(updateDO.getSessionTimeout(), addTime(Duration.ofMillis(timeLong))); | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - @Test | ||
| 131 | - public void testDeleteUserSession_success() { | ||
| 132 | - // 准备参数 | ||
| 133 | - String sessionId = randomString(); | ||
| 134 | - String userIp = randomString(); | ||
| 135 | - String userAgent = randomString(); | ||
| 136 | - Long timeLong = randomLongId(); | ||
| 137 | - LoginUser loginUser = randomPojo(LoginUser.class); | ||
| 138 | - // mock 存入 Redis | ||
| 139 | - when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 140 | - sysLoginUserRedisDAO.set(sessionId, loginUser); | ||
| 141 | - // mock 存入 db | ||
| 142 | - SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 143 | - .userId(loginUser.getId()).userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) | ||
| 144 | - .sessionTimeout(addTime(Duration.ofMillis(timeLong))) | ||
| 145 | - .build(); | ||
| 146 | - sysUserSessionMapper.insert(userSession); | ||
| 147 | - // 校验数据存在 | ||
| 148 | - assertNotNull(sysLoginUserRedisDAO.get(sessionId)); | ||
| 149 | - assertNotNull(sysUserSessionMapper.selectById(sessionId)); | ||
| 150 | - // 调用 | ||
| 151 | - sysUserSessionService.deleteUserSession(sessionId); | ||
| 152 | - // 校验数据不存在了 | ||
| 153 | - assertNull(sysLoginUserRedisDAO.get(sessionId)); | ||
| 154 | - assertNull(sysUserSessionMapper.selectById(sessionId)); | ||
| 155 | - } | 57 | + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; |
| 156 | 58 | ||
| 157 | @Test | 59 | @Test |
| 158 | public void testGetUserSessionPage_success() { | 60 | public void testGetUserSessionPage_success() { |
| 159 | // mock 数据 | 61 | // mock 数据 |
| 160 | - String userIp = randomString(); | ||
| 161 | - SysUserDO dbUser1 = randomPojo(SysUserDO.class, o -> { | ||
| 162 | - o.setUsername("testUsername1"); | ||
| 163 | - o.setSex(randomEle(SysSexEnum.values()).getSex()); | ||
| 164 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 165 | - }); | ||
| 166 | - SysUserDO dbUser2 = randomPojo(SysUserDO.class, o -> { | ||
| 167 | - o.setUsername("testUsername2"); | 62 | + SysUserDO dbUser = randomPojo(SysUserDO.class, o -> { |
| 168 | o.setSex(randomEle(SysSexEnum.values()).getSex()); | 63 | o.setSex(randomEle(SysSexEnum.values()).getSex()); |
| 169 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 64 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 170 | }); | 65 | }); |
| 66 | + when(userService.getUsersByUsername(eq(dbUser.getUsername()))).thenReturn(singletonList(dbUser)); | ||
| 67 | + // 插入可被查询到的数据 | ||
| 68 | + String userIp = randomString(); | ||
| 171 | SysUserSessionDO dbSession = randomPojo(SysUserSessionDO.class, o -> { | 69 | SysUserSessionDO dbSession = randomPojo(SysUserSessionDO.class, o -> { |
| 172 | - o.setUserId(dbUser1.getId()); | 70 | + o.setUserId(dbUser.getId()); |
| 71 | + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 173 | o.setUserIp(userIp); | 72 | o.setUserIp(userIp); |
| 174 | }); | 73 | }); |
| 175 | - sysUserMapper.insert(dbUser1); | ||
| 176 | - sysUserMapper.insert(dbUser2); | ||
| 177 | - sysUserSessionMapper.insert(dbSession); | ||
| 178 | - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { | 74 | + userSessionMapper.insert(dbSession); |
| 75 | + // 测试 username 不匹配 | ||
| 76 | + userSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { | ||
| 179 | o.setId(randomString()); | 77 | o.setId(randomString()); |
| 180 | - o.setUserId(dbUser2.getId()); | ||
| 181 | - })); | ||
| 182 | - // 测试 userId 不匹配 | ||
| 183 | - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { | ||
| 184 | - o.setId(randomString()); | ||
| 185 | - o.setUserId(123456l); | 78 | + o.setUserId(123456L); |
| 186 | })); | 79 | })); |
| 187 | // 测试 userIp 不匹配 | 80 | // 测试 userIp 不匹配 |
| 188 | - sysUserSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { | 81 | + userSessionMapper.insert(ObjectUtils.clone(dbSession, o -> { |
| 189 | o.setId(randomString()); | 82 | o.setId(randomString()); |
| 190 | o.setUserIp("testUserIp"); | 83 | o.setUserIp("testUserIp"); |
| 191 | })); | 84 | })); |
| 192 | // 准备参数 | 85 | // 准备参数 |
| 193 | - SysUserSessionPageReqVO reqVo = new SysUserSessionPageReqVO(); | ||
| 194 | - reqVo.setUserIp(userIp); | 86 | + SysUserSessionPageReqVO reqVO = new SysUserSessionPageReqVO(); |
| 87 | + reqVO.setUsername(dbUser.getUsername()); | ||
| 88 | + reqVO.setUserIp(userIp); | ||
| 89 | + | ||
| 195 | // 调用 | 90 | // 调用 |
| 196 | - PageResult<SysUserSessionDO> pageResult = sysUserSessionService.getUserSessionPage(reqVo); | 91 | + PageResult<SysUserSessionDO> pageResult = userSessionService.getUserSessionPage(reqVO); |
| 197 | // 断言 | 92 | // 断言 |
| 198 | - assertEquals(3, pageResult.getTotal()); | ||
| 199 | - assertEquals(3, pageResult.getList().size()); | 93 | + assertEquals(1, pageResult.getTotal()); |
| 94 | + assertEquals(1, pageResult.getList().size()); | ||
| 200 | assertPojoEquals(dbSession, pageResult.getList().get(0)); | 95 | assertPojoEquals(dbSession, pageResult.getList().get(0)); |
| 201 | } | 96 | } |
| 202 | 97 | ||
| 98 | + // TODO 芋艿:单测写的有问题 | ||
| 203 | @Test | 99 | @Test |
| 204 | - public void testClearSessionTimeout_success() throws Exception { | 100 | + public void testClearSessionTimeout_success() { |
| 205 | // 准备超时数据 120 条, 在线用户 1 条 | 101 | // 准备超时数据 120 条, 在线用户 1 条 |
| 206 | int expectedTimeoutCount = 120, expectedTotal = 1; | 102 | int expectedTimeoutCount = 120, expectedTotal = 1; |
| 207 | 103 | ||
| @@ -209,17 +105,23 @@ public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -209,17 +105,23 @@ public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 209 | List<SysUserSessionDO> prepareData = Stream | 105 | List<SysUserSessionDO> prepareData = Stream |
| 210 | .iterate(0, i -> i) | 106 | .iterate(0, i -> i) |
| 211 | .limit(expectedTimeoutCount) | 107 | .limit(expectedTimeoutCount) |
| 212 | - .map(i -> RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetSecond(new Date(), -1)))) | 108 | + .map(i -> randomPojo(SysUserSessionDO.class, o -> { |
| 109 | + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 110 | + o.setSessionTimeout(DateUtil.offsetSecond(new Date(), -1)); | ||
| 111 | + })) | ||
| 213 | .collect(Collectors.toList()); | 112 | .collect(Collectors.toList()); |
| 214 | - SysUserSessionDO sessionDO = RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30))); | 113 | + SysUserSessionDO sessionDO = randomPojo(SysUserSessionDO.class, o -> { |
| 114 | + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 115 | + o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30)); | ||
| 116 | + }); | ||
| 215 | prepareData.add(sessionDO); | 117 | prepareData.add(sessionDO); |
| 216 | - prepareData.forEach(sysUserSessionMapper::insert); | 118 | + prepareData.forEach(userSessionMapper::insert); |
| 217 | 119 | ||
| 218 | - //清空超时数据 | ||
| 219 | - long actualTimeoutCount = sysUserSessionService.clearSessionTimeout(); | ||
| 220 | - //校验 | 120 | + // 清空超时数据 |
| 121 | + long actualTimeoutCount = userSessionService.clearSessionTimeout(); | ||
| 122 | + // 校验 | ||
| 221 | assertEquals(expectedTimeoutCount, actualTimeoutCount); | 123 | assertEquals(expectedTimeoutCount, actualTimeoutCount); |
| 222 | - List<SysUserSessionDO> userSessionDOS = sysUserSessionMapper.selectList(); | 124 | + List<SysUserSessionDO> userSessionDOS = userSessionMapper.selectList(); |
| 223 | assertEquals(expectedTotal, userSessionDOS.size()); | 125 | assertEquals(expectedTotal, userSessionDOS.size()); |
| 224 | AssertUtils.assertPojoEquals(sessionDO, userSessionDOS.get(0), "updateTime"); | 126 | AssertUtils.assertPojoEquals(sessionDO, userSessionDOS.get(0), "updateTime"); |
| 225 | } | 127 | } |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/dict/SysDictDataServiceTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dict; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; | 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict.SysDictTypeDO; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; | 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict.SysDictDataMapper; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; | 13 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.dict.SysDictDataProducer; |
| @@ -51,37 +51,6 @@ public class SysDictDataServiceTest extends BaseDbUnitTest { | @@ -51,37 +51,6 @@ public class SysDictDataServiceTest extends BaseDbUnitTest { | ||
| 51 | @MockBean | 51 | @MockBean |
| 52 | private SysDictDataProducer dictDataProducer; | 52 | private SysDictDataProducer dictDataProducer; |
| 53 | 53 | ||
| 54 | - /** | ||
| 55 | - * 测试加载到新的字典数据的情况 | ||
| 56 | - */ | ||
| 57 | - @Test | ||
| 58 | - @SuppressWarnings("unchecked") | ||
| 59 | - public void testInitLocalCache() { | ||
| 60 | - // mock 数据 | ||
| 61 | - SysDictDataDO dictData01 = randomDictDataDO(); | ||
| 62 | - dictDataMapper.insert(dictData01); | ||
| 63 | - SysDictDataDO dictData02 = randomDictDataDO(); | ||
| 64 | - dictDataMapper.insert(dictData02); | ||
| 65 | - | ||
| 66 | - // 调用 | ||
| 67 | - dictDataService.initLocalCache(); | ||
| 68 | - // 断言 labelDictDataCache 缓存 | ||
| 69 | - ImmutableTable<String, String, SysDictDataDO> labelDictDataCache = | ||
| 70 | - (ImmutableTable<String, String, SysDictDataDO>) getFieldValue(dictDataService, "labelDictDataCache"); | ||
| 71 | - assertEquals(2, labelDictDataCache.size()); | ||
| 72 | - assertPojoEquals(dictData01, labelDictDataCache.get(dictData01.getDictType(), dictData01.getLabel())); | ||
| 73 | - assertPojoEquals(dictData02, labelDictDataCache.get(dictData02.getDictType(), dictData02.getLabel())); | ||
| 74 | - // 断言 valueDictDataCache 缓存 | ||
| 75 | - ImmutableTable<String, String, SysDictDataDO> valueDictDataCache = | ||
| 76 | - (ImmutableTable<String, String, SysDictDataDO>) getFieldValue(dictDataService, "valueDictDataCache"); | ||
| 77 | - assertEquals(2, valueDictDataCache.size()); | ||
| 78 | - assertPojoEquals(dictData01, valueDictDataCache.get(dictData01.getDictType(), dictData01.getValue())); | ||
| 79 | - assertPojoEquals(dictData02, valueDictDataCache.get(dictData02.getDictType(), dictData02.getValue())); | ||
| 80 | - // 断言 maxUpdateTime 缓存 | ||
| 81 | - Date maxUpdateTime = (Date) getFieldValue(dictDataService, "maxUpdateTime"); | ||
| 82 | - assertEquals(ObjectUtils.max(dictData01.getUpdateTime(), dictData02.getUpdateTime()), maxUpdateTime); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | @Test | 54 | @Test |
| 86 | public void testGetDictDataPage() { | 55 | public void testGetDictDataPage() { |
| 87 | // mock 数据 | 56 | // mock 数据 |
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; | @@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.RandomUtil; | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 6 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | 8 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; | 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysLoginLogMapper; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; | 12 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 13 | import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; |
| @@ -34,34 +34,13 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { | @@ -34,34 +34,13 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { | ||
| 34 | private SysLoginLogMapper loginLogMapper; | 34 | private SysLoginLogMapper loginLogMapper; |
| 35 | 35 | ||
| 36 | @Test | 36 | @Test |
| 37 | - public void testCreateLoginLog() { | ||
| 38 | - String traceId = TracerUtils.getTraceId(); | ||
| 39 | - SysLoginLogCreateReqVO reqVO = RandomUtils.randomPojo(SysLoginLogCreateReqVO.class, vo -> { | ||
| 40 | - // 指定随机的范围,避免超出范围入库失败 | ||
| 41 | - vo.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); | ||
| 42 | - vo.setResult(RandomUtil.randomEle(SysLoginResultEnum.values()).getResult()); | ||
| 43 | - // 使用TracerUtils生成的TraceId | ||
| 44 | - vo.setTraceId(traceId); | ||
| 45 | - }); | ||
| 46 | - | ||
| 47 | - // 执行service方法 | ||
| 48 | - sysLoginLogService.createLoginLog(reqVO); | ||
| 49 | - | ||
| 50 | - // 断言,忽略基本字段 | ||
| 51 | - SysLoginLogDO sysLoginLogDO = loginLogMapper.selectOne(null); | ||
| 52 | - assertPojoEquals(reqVO, sysLoginLogDO); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - @Test | ||
| 57 | public void testGetLoginLogPage() { | 37 | public void testGetLoginLogPage() { |
| 58 | - | ||
| 59 | // 构造测试数据 | 38 | // 构造测试数据 |
| 60 | - | ||
| 61 | // 登录成功的 | 39 | // 登录成功的 |
| 62 | SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { | 40 | SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { |
| 63 | logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); | 41 | logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); |
| 64 | logDO.setTraceId(TracerUtils.getTraceId()); | 42 | logDO.setTraceId(TracerUtils.getTraceId()); |
| 43 | + logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); | ||
| 65 | 44 | ||
| 66 | logDO.setUserIp("192.168.199.16"); | 45 | logDO.setUserIp("192.168.199.16"); |
| 67 | logDO.setUsername("wangkai"); | 46 | logDO.setUsername("wangkai"); |
| @@ -100,13 +79,13 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { | @@ -100,13 +79,13 @@ public class SysLoginLogServiceImplTest extends BaseDbUnitTest { | ||
| 100 | 79 | ||
| 101 | @Test | 80 | @Test |
| 102 | public void testGetLoginLogList() { | 81 | public void testGetLoginLogList() { |
| 103 | - | ||
| 104 | // 构造测试数据 | 82 | // 构造测试数据 |
| 105 | 83 | ||
| 106 | // 登录成功的 | 84 | // 登录成功的 |
| 107 | SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { | 85 | SysLoginLogDO loginLogDO = RandomUtils.randomPojo(SysLoginLogDO.class, logDO -> { |
| 108 | logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); | 86 | logDO.setLogType(RandomUtil.randomEle(SysLoginLogTypeEnum.values()).getType()); |
| 109 | logDO.setTraceId(TracerUtils.getTraceId()); | 87 | logDO.setTraceId(TracerUtils.getTraceId()); |
| 88 | + logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); | ||
| 110 | 89 | ||
| 111 | logDO.setUserIp("192.168.111.16"); | 90 | logDO.setUserIp("192.168.111.16"); |
| 112 | logDO.setUsername("wangxiaokai"); | 91 | logDO.setUsername("wangxiaokai"); |
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; | @@ -2,34 +2,35 @@ package cn.iocoder.yudao.adminserver.modules.system.service.logger; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 6 | -import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | ||
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | -import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; | ||
| 9 | -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 10 | -import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysOperateLogDO; |
| 14 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 15 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.logger.SysOperateLogMapper; |
| 16 | -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; | ||
| 17 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.impl.SysOperateLogServiceImpl; | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.logger.impl.SysOperateLogServiceImpl; |
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 19 | -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; | ||
| 13 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 14 | +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | ||
| 15 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 20 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 17 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 18 | +import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO; | ||
| 19 | +import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; | ||
| 20 | +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 21 | import org.junit.jupiter.api.Test; | 21 | import org.junit.jupiter.api.Test; |
| 22 | import org.springframework.boot.test.mock.mockito.MockBean; | 22 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 23 | import org.springframework.context.annotation.Import; | 23 | import org.springframework.context.annotation.Import; |
| 24 | 24 | ||
| 25 | import javax.annotation.Resource; | 25 | import javax.annotation.Resource; |
| 26 | -import java.util.*; | 26 | +import java.util.Collections; |
| 27 | +import java.util.List; | ||
| 27 | import java.util.concurrent.ExecutionException; | 28 | import java.util.concurrent.ExecutionException; |
| 28 | import java.util.concurrent.Future; | 29 | import java.util.concurrent.Future; |
| 29 | 30 | ||
| 31 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 30 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 32 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 31 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 33 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 32 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 33 | import static org.junit.jupiter.api.Assertions.assertEquals; | 34 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 34 | import static org.mockito.Mockito.when; | 35 | import static org.mockito.Mockito.when; |
| 35 | 36 |
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; | @@ -2,18 +2,18 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO; |
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsChannelMapper; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | 9 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsChannelServiceImpl; |
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 12 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 15 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 14 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 16 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 15 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 16 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 17 | import org.junit.jupiter.api.Test; | 17 | import org.junit.jupiter.api.Test; |
| 18 | import org.springframework.boot.test.mock.mockito.MockBean; | 18 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 19 | import org.springframework.context.annotation.Import; | 19 | import org.springframework.context.annotation.Import; |
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; | @@ -2,35 +2,32 @@ package cn.iocoder.yudao.adminserver.modules.system.service.sms; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 6 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogExportReqVO; |
| 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.log.SysSmsLogPageReqVO; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 11 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; | 7 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsLogMapper; |
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 14 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 16 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; | 8 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsLogServiceImpl; |
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 13 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 17 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 15 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 18 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 16 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 19 | import org.junit.jupiter.api.Test; | 17 | import org.junit.jupiter.api.Test; |
| 20 | import org.springframework.context.annotation.Import; | 18 | import org.springframework.context.annotation.Import; |
| 21 | 19 | ||
| 22 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 23 | -import java.util.Date; | ||
| 24 | import java.util.List; | 21 | import java.util.List; |
| 25 | import java.util.Map; | 22 | import java.util.Map; |
| 26 | import java.util.function.Consumer; | 23 | import java.util.function.Consumer; |
| 27 | 24 | ||
| 28 | -import static cn.hutool.core.util.RandomUtil.randomBoolean; | ||
| 29 | import static cn.hutool.core.util.RandomUtil.randomEle; | 25 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 30 | -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 31 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | 26 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; |
| 32 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 33 | -import static org.junit.jupiter.api.Assertions.*; | 27 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 28 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 29 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||
| 30 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 34 | 31 | ||
| 35 | /** | 32 | /** |
| 36 | * {@link SysSmsLogServiceImpl} 的单元测试类 | 33 | * {@link SysSmsLogServiceImpl} 的单元测试类 |
| @@ -47,93 +44,6 @@ public class SysSmsLogServiceTest extends BaseDbUnitTest { | @@ -47,93 +44,6 @@ public class SysSmsLogServiceTest extends BaseDbUnitTest { | ||
| 47 | private SysSmsLogMapper smsLogMapper; | 44 | private SysSmsLogMapper smsLogMapper; |
| 48 | 45 | ||
| 49 | @Test | 46 | @Test |
| 50 | - public void testCreateSmsLog() { | ||
| 51 | - // 准备参数 | ||
| 52 | - String mobile = randomString(); | ||
| 53 | - Long userId = randomLongId(); | ||
| 54 | - Integer userType = randomEle(UserTypeEnum.values()).getValue(); | ||
| 55 | - Boolean isSend = randomBoolean(); | ||
| 56 | - SysSmsTemplateDO templateDO = randomPojo(SysSmsTemplateDO.class, | ||
| 57 | - o -> o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType())); | ||
| 58 | - String templateContent = randomString(); | ||
| 59 | - Map<String, Object> templateParams = randomTemplateParams(); | ||
| 60 | - // mock 方法 | ||
| 61 | - | ||
| 62 | - // 调用 | ||
| 63 | - Long logId = smsLogService.createSmsLog(mobile, userId, userType, isSend, | ||
| 64 | - templateDO, templateContent, templateParams); | ||
| 65 | - // 断言 | ||
| 66 | - SysSmsLogDO logDO = smsLogMapper.selectById(logId); | ||
| 67 | - assertEquals(isSend ? SysSmsSendStatusEnum.INIT.getStatus() : SysSmsSendStatusEnum.IGNORE.getStatus(), | ||
| 68 | - logDO.getSendStatus()); | ||
| 69 | - assertEquals(mobile, logDO.getMobile()); | ||
| 70 | - assertEquals(userType, logDO.getUserType()); | ||
| 71 | - assertEquals(userId, logDO.getUserId()); | ||
| 72 | - assertEquals(templateDO.getId(), logDO.getTemplateId()); | ||
| 73 | - assertEquals(templateDO.getCode(), logDO.getTemplateCode()); | ||
| 74 | - assertEquals(templateDO.getType(), logDO.getTemplateType()); | ||
| 75 | - assertEquals(templateDO.getChannelId(), logDO.getChannelId()); | ||
| 76 | - assertEquals(templateDO.getChannelCode(), logDO.getChannelCode()); | ||
| 77 | - assertEquals(templateContent, logDO.getTemplateContent()); | ||
| 78 | - assertEquals(templateParams, logDO.getTemplateParams()); | ||
| 79 | - assertEquals(SysSmsReceiveStatusEnum.INIT.getStatus(), logDO.getReceiveStatus()); | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - @Test | ||
| 83 | - public void testUpdateSmsSendResult() { | ||
| 84 | - // mock 数据 | ||
| 85 | - SysSmsLogDO dbSmsLog = randomSmsLogDO( | ||
| 86 | - o -> o.setSendStatus(SysSmsSendStatusEnum.IGNORE.getStatus())); | ||
| 87 | - smsLogMapper.insert(dbSmsLog); | ||
| 88 | - // 准备参数 | ||
| 89 | - Long id = dbSmsLog.getId(); | ||
| 90 | - Integer sendCode = randomInteger(); | ||
| 91 | - String sendMsg = randomString(); | ||
| 92 | - String apiSendCode = randomString(); | ||
| 93 | - String apiSendMsg = randomString(); | ||
| 94 | - String apiRequestId = randomString(); | ||
| 95 | - String apiSerialNo = randomString(); | ||
| 96 | - | ||
| 97 | - // 调用 | ||
| 98 | - smsLogService.updateSmsSendResult(id, sendCode, sendMsg, | ||
| 99 | - apiSendCode, apiSendMsg, apiRequestId, apiSerialNo); | ||
| 100 | - // 断言 | ||
| 101 | - dbSmsLog = smsLogMapper.selectById(id); | ||
| 102 | - assertEquals(CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS.getStatus() | ||
| 103 | - : SysSmsSendStatusEnum.FAILURE.getStatus(), dbSmsLog.getSendStatus()); | ||
| 104 | - assertNotNull(dbSmsLog.getSendTime()); | ||
| 105 | - assertEquals(sendMsg, dbSmsLog.getSendMsg()); | ||
| 106 | - assertEquals(apiSendCode, dbSmsLog.getApiSendCode()); | ||
| 107 | - assertEquals(apiSendMsg, dbSmsLog.getApiSendMsg()); | ||
| 108 | - assertEquals(apiRequestId, dbSmsLog.getApiRequestId()); | ||
| 109 | - assertEquals(apiSerialNo, dbSmsLog.getApiSerialNo()); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - @Test | ||
| 113 | - public void testUpdateSmsReceiveResult() { | ||
| 114 | - // mock 数据 | ||
| 115 | - SysSmsLogDO dbSmsLog = randomSmsLogDO( | ||
| 116 | - o -> o.setReceiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus())); | ||
| 117 | - smsLogMapper.insert(dbSmsLog); | ||
| 118 | - // 准备参数 | ||
| 119 | - Long id = dbSmsLog.getId(); | ||
| 120 | - Boolean success = randomBoolean(); | ||
| 121 | - Date receiveTime = randomDate(); | ||
| 122 | - String apiReceiveCode = randomString(); | ||
| 123 | - String apiReceiveMsg = randomString(); | ||
| 124 | - | ||
| 125 | - // 调用 | ||
| 126 | - smsLogService.updateSmsReceiveResult(id, success, receiveTime, apiReceiveCode, apiReceiveMsg); | ||
| 127 | - // 断言 | ||
| 128 | - dbSmsLog = smsLogMapper.selectById(id); | ||
| 129 | - assertEquals(success ? SysSmsReceiveStatusEnum.SUCCESS.getStatus() | ||
| 130 | - : SysSmsReceiveStatusEnum.FAILURE.getStatus(), dbSmsLog.getReceiveStatus()); | ||
| 131 | - assertEquals(receiveTime, dbSmsLog.getReceiveTime()); | ||
| 132 | - assertEquals(apiReceiveCode, dbSmsLog.getApiReceiveCode()); | ||
| 133 | - assertEquals(apiReceiveMsg, dbSmsLog.getApiReceiveMsg()); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - @Test | ||
| 137 | public void testGetSmsLogPage() { | 47 | public void testGetSmsLogPage() { |
| 138 | // mock 数据 | 48 | // mock 数据 |
| 139 | SysSmsLogDO dbSmsLog = randomSmsLogDO(o -> { // 等会查询到 | 49 | SysSmsLogDO dbSmsLog = randomSmsLogDO(o -> { // 等会查询到 |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsTemplateServiceTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 4 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | -import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | ||
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | ||
| 8 | -import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 9 | -import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | ||
| 10 | -import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateCreateReqVO; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; | 5 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateExportReqVO; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplatePageReqVO; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.SysSmsTemplateUpdateReqVO; |
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 16 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 17 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.sms.SysSmsTemplateMapper; |
| 18 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 19 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | 9 | import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; |
| 20 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsTemplateServiceImpl; |
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsChannelDO; | ||
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 14 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 15 | +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | ||
| 16 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 21 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 17 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 22 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 18 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 19 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClient; | ||
| 20 | +import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 21 | +import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | ||
| 22 | +import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 23 | import com.google.common.collect.Lists; | 23 | import com.google.common.collect.Lists; |
| 24 | import org.junit.jupiter.api.Test; | 24 | import org.junit.jupiter.api.Test; |
| 25 | import org.springframework.boot.test.mock.mockito.MockBean; | 25 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 26 | import org.springframework.context.annotation.Import; | 26 | import org.springframework.context.annotation.Import; |
| 27 | 27 | ||
| 28 | import javax.annotation.Resource; | 28 | import javax.annotation.Resource; |
| 29 | -import java.util.Date; | ||
| 30 | import java.util.List; | 29 | import java.util.List; |
| 31 | -import java.util.Map; | ||
| 32 | import java.util.function.Consumer; | 30 | import java.util.function.Consumer; |
| 33 | 31 | ||
| 34 | -import static cn.hutool.core.bean.BeanUtil.getFieldValue; | ||
| 35 | import static cn.hutool.core.util.RandomUtil.randomEle; | 32 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 36 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 33 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 34 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 37 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 35 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 38 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 36 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 39 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 40 | -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; | ||
| 41 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 37 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 42 | import static org.junit.jupiter.api.Assertions.*; | 38 | import static org.junit.jupiter.api.Assertions.*; |
| 43 | import static org.mockito.ArgumentMatchers.eq; | 39 | import static org.mockito.ArgumentMatchers.eq; |
| @@ -67,27 +63,6 @@ public class SysSmsTemplateServiceTest extends BaseDbUnitTest { | @@ -67,27 +63,6 @@ public class SysSmsTemplateServiceTest extends BaseDbUnitTest { | ||
| 67 | private SysSmsProducer smsProducer; | 63 | private SysSmsProducer smsProducer; |
| 68 | 64 | ||
| 69 | @Test | 65 | @Test |
| 70 | - @SuppressWarnings("unchecked") | ||
| 71 | - void testInitLocalCache() { | ||
| 72 | - // mock 数据 | ||
| 73 | - SysSmsTemplateDO smsTemplate01 = randomSmsTemplateDO(); | ||
| 74 | - smsTemplateMapper.insert(smsTemplate01); | ||
| 75 | - SysSmsTemplateDO smsTemplate02 = randomSmsTemplateDO(); | ||
| 76 | - smsTemplateMapper.insert(smsTemplate02); | ||
| 77 | - | ||
| 78 | - // 调用 | ||
| 79 | - smsTemplateService.initLocalCache(); | ||
| 80 | - // 断言 deptCache 缓存 | ||
| 81 | - Map<String, SysSmsTemplateDO> smsTemplateCache = (Map<String, SysSmsTemplateDO>) getFieldValue(smsTemplateService, "smsTemplateCache"); | ||
| 82 | - assertEquals(2, smsTemplateCache.size()); | ||
| 83 | - assertPojoEquals(smsTemplate01, smsTemplateCache.get(smsTemplate01.getCode())); | ||
| 84 | - assertPojoEquals(smsTemplate02, smsTemplateCache.get(smsTemplate02.getCode())); | ||
| 85 | - // 断言 maxUpdateTime 缓存 | ||
| 86 | - Date maxUpdateTime = (Date) getFieldValue(smsTemplateService, "maxUpdateTime"); | ||
| 87 | - assertEquals(max(smsTemplate01.getUpdateTime(), smsTemplate02.getUpdateTime()), maxUpdateTime); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - @Test | ||
| 91 | public void testParseTemplateContentParams() { | 66 | public void testParseTemplateContentParams() { |
| 92 | // 准备参数 | 67 | // 准备参数 |
| 93 | String content = "正在进行登录操作{operation},您的验证码是{code}"; | 68 | String content = "正在进行登录操作{operation},您的验证码是{code}"; |
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; | @@ -3,21 +3,21 @@ package cn.iocoder.yudao.adminserver.modules.system.service.user; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.RandomUtil; | 4 | import cn.hutool.core.util.RandomUtil; |
| 5 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 5 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; | ||
| 7 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 8 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; | 6 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; |
| 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 11 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; |
| 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; | 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 16 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; | 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; |
| 17 | -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; | ||
| 18 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | 13 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 19 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; | 14 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 20 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 16 | +import cn.iocoder.yudao.adminserver.modules.system.service.user.impl.SysUserServiceImpl; | ||
| 17 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 18 | +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; | ||
| 19 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 20 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 21 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 21 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 22 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 22 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 23 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 23 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| @@ -36,9 +36,9 @@ import java.util.function.Consumer; | @@ -36,9 +36,9 @@ import java.util.function.Consumer; | ||
| 36 | import static cn.hutool.core.util.RandomUtil.randomBytes; | 36 | import static cn.hutool.core.util.RandomUtil.randomBytes; |
| 37 | import static cn.hutool.core.util.RandomUtil.randomEle; | 37 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 38 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 38 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 39 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 39 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 40 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 40 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 41 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 41 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 42 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 42 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 43 | import static org.assertj.core.util.Lists.newArrayList; | 43 | import static org.assertj.core.util.Lists.newArrayList; |
| 44 | import static org.junit.jupiter.api.Assertions.assertEquals; | 44 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| @@ -243,7 +243,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest { | @@ -243,7 +243,7 @@ public class SysUserServiceImplTest extends BaseDbUnitTest { | ||
| 243 | // 调用数据 | 243 | // 调用数据 |
| 244 | userService.deleteUser(userId); | 244 | userService.deleteUser(userId); |
| 245 | // 校验结果 | 245 | // 校验结果 |
| 246 | - assertNull(userService.getUser(userId)); | 246 | + assertNull(userMapper.selectById(userId)); |
| 247 | // 校验调用次数 | 247 | // 校验调用次数 |
| 248 | verify(permissionService, times(1)).processUserDeleted(eq(userId)); | 248 | verify(permissionService, times(1)).processUserDeleted(eq(userId)); |
| 249 | } | 249 | } |
yudao-admin-server/src/test/resources/application-unit-test.yaml
| @@ -36,34 +36,9 @@ mybatis: | @@ -36,34 +36,9 @@ mybatis: | ||
| 36 | # Lock4j 配置项(单元测试,禁用 Lock4j) | 36 | # Lock4j 配置项(单元测试,禁用 Lock4j) |
| 37 | 37 | ||
| 38 | # Resilience4j 配置项 | 38 | # Resilience4j 配置项 |
| 39 | -resilience4j: | ||
| 40 | - ratelimiter: | ||
| 41 | - instances: | ||
| 42 | - backendA: | ||
| 43 | - limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 | ||
| 44 | - limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 | ||
| 45 | - timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s | ||
| 46 | - register-health-indicator: true # 是否注册到健康监测 | ||
| 47 | 39 | ||
| 48 | --- #################### 监控相关配置 #################### | 40 | --- #################### 监控相关配置 #################### |
| 49 | 41 | ||
| 50 | --- #################### 芋道相关配置 #################### | 42 | --- #################### 芋道相关配置 #################### |
| 51 | 43 | ||
| 52 | # 芋道配置项,设置当前项目所有自定义的配置 | 44 | # 芋道配置项,设置当前项目所有自定义的配置 |
| 53 | -yudao: | ||
| 54 | - security: | ||
| 55 | - token-header: Authorization | ||
| 56 | - token-secret: abcdefghijklmnopqrstuvwxyz | ||
| 57 | - token-timeout: 1d | ||
| 58 | - session-timeout: 30m | ||
| 59 | - mock-enable: true | ||
| 60 | - mock-secret: test | ||
| 61 | - swagger: | ||
| 62 | - enable: false # 单元测试,禁用 Swagger | ||
| 63 | - file: | ||
| 64 | - base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ | ||
| 65 | - xss: | ||
| 66 | - enable: false | ||
| 67 | - exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 | ||
| 68 | - - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求 | ||
| 69 | - - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 |
yudao-admin-server/src/test/resources/sql/create_tables.sql
| @@ -179,6 +179,7 @@ CREATE TABLE IF NOT EXISTS "sys_dict_type" ( | @@ -179,6 +179,7 @@ CREATE TABLE IF NOT EXISTS "sys_dict_type" ( | ||
| 179 | CREATE TABLE IF NOT EXISTS `sys_user_session` ( | 179 | CREATE TABLE IF NOT EXISTS `sys_user_session` ( |
| 180 | `id` varchar(32) NOT NULL, | 180 | `id` varchar(32) NOT NULL, |
| 181 | `user_id` bigint DEFAULT NULL, | 181 | `user_id` bigint DEFAULT NULL, |
| 182 | + "user_type" tinyint NOT NULL, | ||
| 182 | `username` varchar(50) NOT NULL DEFAULT '', | 183 | `username` varchar(50) NOT NULL DEFAULT '', |
| 183 | `user_ip` varchar(50) DEFAULT NULL, | 184 | `user_ip` varchar(50) DEFAULT NULL, |
| 184 | `user_agent` varchar(512) DEFAULT NULL, | 185 | `user_agent` varchar(512) DEFAULT NULL, |
| @@ -223,6 +224,8 @@ CREATE TABLE IF NOT EXISTS "sys_notice" ( | @@ -223,6 +224,8 @@ CREATE TABLE IF NOT EXISTS "sys_notice" ( | ||
| 223 | CREATE TABLE IF NOT EXISTS `sys_login_log` ( | 224 | CREATE TABLE IF NOT EXISTS `sys_login_log` ( |
| 224 | `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | 225 | `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 225 | `log_type` bigint(4) NOT NULL, | 226 | `log_type` bigint(4) NOT NULL, |
| 227 | + "user_id" bigint not null default '0', | ||
| 228 | + "user_type" tinyint NOT NULL, | ||
| 226 | `trace_id` varchar(64) NOT NULL DEFAULT '', | 229 | `trace_id` varchar(64) NOT NULL DEFAULT '', |
| 227 | `username` varchar(50) NOT NULL DEFAULT '', | 230 | `username` varchar(50) NOT NULL DEFAULT '', |
| 228 | `result` tinyint(4) NOT NULL, | 231 | `result` tinyint(4) NOT NULL, |
yudao-core-service/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <parent> | ||
| 6 | + <artifactId>yudao</artifactId> | ||
| 7 | + <groupId>cn.iocoder.boot</groupId> | ||
| 8 | + <version>1.1.0-snapshot</version> | ||
| 9 | + </parent> | ||
| 10 | + <modelVersion>4.0.0</modelVersion> | ||
| 11 | + | ||
| 12 | + <artifactId>yudao-core-service</artifactId> | ||
| 13 | + <packaging>jar</packaging> | ||
| 14 | + | ||
| 15 | + <name>yudao-admin-server</name> | ||
| 16 | + <description> | ||
| 17 | + 公共服务,通过 jar 包的方式,被 yudao-admin-server、yudao-user-service 使用。例如说: | ||
| 18 | + 1. 日志相关:访问日志、登录日志、异常日志等等 | ||
| 19 | + 2. 认证相关:在线 Session | ||
| 20 | + 3. 短信相关:短信模板、短信日志 | ||
| 21 | + 等等 | ||
| 22 | + </description> | ||
| 23 | + <url>https://github.com/YunaiV/ruoyi-vue-pro</url> | ||
| 24 | + | ||
| 25 | + <dependencies> | ||
| 26 | + <!-- 业务组件 --> | ||
| 27 | + <dependency> | ||
| 28 | + <groupId>cn.iocoder.boot</groupId> | ||
| 29 | + <artifactId>yudao-spring-boot-starter-biz-dict</artifactId> | ||
| 30 | + </dependency> | ||
| 31 | + <dependency> | ||
| 32 | + <groupId>cn.iocoder.boot</groupId> | ||
| 33 | + <artifactId>yudao-spring-boot-starter-biz-sms</artifactId> | ||
| 34 | + </dependency> | ||
| 35 | + | ||
| 36 | + <!-- Web 相关 --> | ||
| 37 | + <dependency> | ||
| 38 | + <groupId>cn.iocoder.boot</groupId> | ||
| 39 | + <artifactId>yudao-spring-boot-starter-web</artifactId> | ||
| 40 | + </dependency> | ||
| 41 | + <!-- spring boot 配置所需依赖 --> | ||
| 42 | + <dependency> | ||
| 43 | + <groupId>org.springframework.boot</groupId> | ||
| 44 | + <artifactId>spring-boot-configuration-processor</artifactId> | ||
| 45 | + <optional>true</optional> | ||
| 46 | + </dependency> | ||
| 47 | + | ||
| 48 | + <dependency> | ||
| 49 | + <groupId>cn.iocoder.boot</groupId> | ||
| 50 | + <artifactId>yudao-spring-boot-starter-security</artifactId> | ||
| 51 | + </dependency> | ||
| 52 | + | ||
| 53 | + <!-- DB 相关 --> | ||
| 54 | + <dependency> | ||
| 55 | + <groupId>cn.iocoder.boot</groupId> | ||
| 56 | + <artifactId>yudao-spring-boot-starter-mybatis</artifactId> | ||
| 57 | + </dependency> | ||
| 58 | + | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>cn.iocoder.boot</groupId> | ||
| 61 | + <artifactId>yudao-spring-boot-starter-redis</artifactId> | ||
| 62 | + </dependency> | ||
| 63 | + | ||
| 64 | + <!-- Config 配置中心相关 --> | ||
| 65 | + <dependency> | ||
| 66 | + <groupId>cn.iocoder.boot</groupId> | ||
| 67 | + <artifactId>yudao-spring-boot-starter-config</artifactId> | ||
| 68 | + </dependency> | ||
| 69 | + | ||
| 70 | + <!-- 消息队列相关 --> | ||
| 71 | + <dependency> | ||
| 72 | + <groupId>cn.iocoder.boot</groupId> | ||
| 73 | + <artifactId>yudao-spring-boot-starter-mq</artifactId> | ||
| 74 | + </dependency> | ||
| 75 | + | ||
| 76 | + <!-- Test 测试相关 --> | ||
| 77 | + <dependency> | ||
| 78 | + <groupId>cn.iocoder.boot</groupId> | ||
| 79 | + <artifactId>yudao-spring-boot-starter-test</artifactId> | ||
| 80 | + <scope>test</scope> | ||
| 81 | + </dependency> | ||
| 82 | + | ||
| 83 | + <!-- 工具类相关 --> | ||
| 84 | + <dependency> | ||
| 85 | + <groupId>com.google.guava</groupId> | ||
| 86 | + <artifactId>guava</artifactId> | ||
| 87 | + </dependency> | ||
| 88 | + </dependencies> | ||
| 89 | + | ||
| 90 | +</project> |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiAccessLogCoreConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.convert.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 5 | +import org.mapstruct.Mapper; | ||
| 6 | +import org.mapstruct.factory.Mappers; | ||
| 7 | + | ||
| 8 | +@Mapper | ||
| 9 | +public interface InfApiAccessLogCoreConvert { | ||
| 10 | + | ||
| 11 | + InfApiAccessLogCoreConvert INSTANCE = Mappers.getMapper(InfApiAccessLogCoreConvert.class); | ||
| 12 | + | ||
| 13 | + InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); | ||
| 14 | + | ||
| 15 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/logger/InfApiErrorLogCoreConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.convert.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | +import org.mapstruct.Mapper; | ||
| 6 | +import org.mapstruct.factory.Mappers; | ||
| 7 | + | ||
| 8 | +@Mapper | ||
| 9 | +public interface InfApiErrorLogCoreConvert { | ||
| 10 | + | ||
| 11 | + InfApiErrorLogCoreConvert INSTANCE = Mappers.getMapper(InfApiErrorLogCoreConvert.class); | ||
| 12 | + | ||
| 13 | + InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); | ||
| 14 | + | ||
| 15 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/package-info.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/package-info.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/config/InfConfigDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/config/InfConfigDO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.config; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.TableField; | 4 | import com.baomidou.mybatisplus.annotation.TableField; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/file/InfFileDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/file/InfFileDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.file; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.IdType; | 4 | import com.baomidou.mybatisplus.annotation.IdType; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/dataobject/logger/InfApiErrorLogDO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | 5 | +import cn.iocoder.yudao.coreservice.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | import lombok.*; | 7 | import lombok.*; |
| 8 | 8 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/config/InfConfigCoreDAOImpl.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; | 3 | import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; |
| 4 | import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; | 4 | import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; |
| @@ -12,15 +12,15 @@ import java.util.Date; | @@ -12,15 +12,15 @@ import java.util.Date; | ||
| 12 | import java.util.List; | 12 | import java.util.List; |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | - * ConfigFrameworkDAO 实现类 | 15 | + * ConfigFrameworkDAO Core 实现类 |
| 16 | * | 16 | * |
| 17 | * @author 芋道源码 | 17 | * @author 芋道源码 |
| 18 | */ | 18 | */ |
| 19 | -public class InfConfigDAOImpl implements ConfigFrameworkDAO { | 19 | +public class InfConfigCoreDAOImpl implements ConfigFrameworkDAO { |
| 20 | 20 | ||
| 21 | private final JdbcTemplate jdbcTemplate; | 21 | private final JdbcTemplate jdbcTemplate; |
| 22 | 22 | ||
| 23 | - public InfConfigDAOImpl(String jdbcUrl, String username, String password) { | 23 | + public InfConfigCoreDAOImpl(String jdbcUrl, String username, String password) { |
| 24 | DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password); | 24 | DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password); |
| 25 | this.jdbcTemplate = new JdbcTemplate(dataSource); | 25 | this.jdbcTemplate = new JdbcTemplate(dataSource); |
| 26 | } | 26 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/file/InfFileMapper.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.file; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file.InfFileDO; | 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | ||
| 7 | @Mapper | 7 | @Mapper |
| 8 | -public interface InfFileMapper extends BaseMapperX<InfFileDO> { | 8 | +public interface InfFileCoreMapper extends BaseMapperX<InfFileDO> { |
| 9 | 9 | ||
| 10 | } | 10 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiAccessLogMapper.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiAccessLogCoreMapper.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; |
| 5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | ||
| 7 | -import java.util.List; | ||
| 8 | - | ||
| 9 | /** | 7 | /** |
| 10 | * API 访问日志 Mapper | 8 | * API 访问日志 Mapper |
| 11 | * | 9 | * |
| 12 | * @author 芋道源码 | 10 | * @author 芋道源码 |
| 13 | */ | 11 | */ |
| 14 | @Mapper | 12 | @Mapper |
| 15 | -public interface InfApiAccessLogMapper extends BaseMapperX<InfApiAccessLogDO> { | 13 | +public interface InfApiAccessLogCoreMapper extends BaseMapperX<InfApiAccessLogDO> { |
| 16 | } | 14 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/logger/InfApiErrorLogCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +@Mapper | ||
| 8 | +public interface InfApiErrorLogCoreMapper extends BaseMapperX<InfApiErrorLogDO> { | ||
| 9 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/logger/InfApiErrorLogProcessStatusEnum.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/enums/package-info.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/enums/package-info.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/package-info.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/package-info.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiAccessLogService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreService.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; | 3 | import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService; |
| 4 | 4 | ||
| @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServi | @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServi | ||
| 7 | * | 7 | * |
| 8 | * @author 芋道源码 | 8 | * @author 芋道源码 |
| 9 | */ | 9 | */ |
| 10 | -public interface InfApiAccessLogService extends ApiAccessLogFrameworkService { | 10 | +public interface InfApiAccessLogCoreService extends ApiAccessLogFrameworkService { |
| 11 | 11 | ||
| 12 | } | 12 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/InfApiErrorLogService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreService.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; | 3 | import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; |
| 4 | 4 | ||
| @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServic | @@ -7,6 +7,6 @@ import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServic | ||
| 7 | * | 7 | * |
| 8 | * @author 芋道源码 | 8 | * @author 芋道源码 |
| 9 | */ | 9 | */ |
| 10 | -public interface InfApiErrorLogService extends ApiErrorLogFrameworkService { | 10 | +public interface InfApiErrorLogCoreService extends ApiErrorLogFrameworkService { |
| 11 | 11 | ||
| 12 | } | 12 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiAccessLogServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiAccessLogCoreServiceImpl.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.convert.logger.InfApiAccessLogCoreConvert; | ||
| 3 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | 4 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; |
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiAccessLogConvert; | ||
| 5 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 6 | -import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper; | ||
| 7 | -import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiAccessLogService; | 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; |
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiAccessLogCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.InfApiAccessLogCoreService; | ||
| 8 | import lombok.extern.slf4j.Slf4j; | 8 | import lombok.extern.slf4j.Slf4j; |
| 9 | +import org.springframework.scheduling.annotation.Async; | ||
| 9 | import org.springframework.scheduling.annotation.AsyncResult; | 10 | import org.springframework.scheduling.annotation.AsyncResult; |
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| @@ -21,16 +22,16 @@ import java.util.concurrent.Future; | @@ -21,16 +22,16 @@ import java.util.concurrent.Future; | ||
| 21 | @Service | 22 | @Service |
| 22 | @Validated | 23 | @Validated |
| 23 | @Slf4j | 24 | @Slf4j |
| 24 | -public class InfApiAccessLogServiceImpl implements InfApiAccessLogService { | 25 | +public class InfApiAccessLogCoreServiceImpl implements InfApiAccessLogCoreService { |
| 25 | 26 | ||
| 26 | @Resource | 27 | @Resource |
| 27 | - private InfApiAccessLogMapper apiAccessLogMapper; | 28 | + private InfApiAccessLogCoreMapper apiAccessLogMapper; |
| 28 | 29 | ||
| 29 | @Override | 30 | @Override |
| 30 | - public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { | ||
| 31 | - InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO); | ||
| 32 | - int insert = apiAccessLogMapper.insert(apiAccessLog); | ||
| 33 | - return new AsyncResult<>(insert > 1); | 31 | + @Async |
| 32 | + public void createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) { | ||
| 33 | + InfApiAccessLogDO apiAccessLog = InfApiAccessLogCoreConvert.INSTANCE.convert(createDTO); | ||
| 34 | + apiAccessLogMapper.insert(apiAccessLog); | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | } | 37 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/logger/impl/InfApiErrorLogServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/impl/InfApiErrorLogCoreServiceImpl.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl; | 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.infra.convert.logger.InfApiErrorLogCoreConvert; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiErrorLogCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.InfApiErrorLogCoreService; | ||
| 3 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | 8 | import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; |
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiErrorLogConvert; | ||
| 5 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 6 | -import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper; | ||
| 7 | -import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum; | ||
| 8 | -import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiErrorLogService; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
| 10 | +import org.springframework.scheduling.annotation.Async; | ||
| 10 | import org.springframework.scheduling.annotation.AsyncResult; | 11 | import org.springframework.scheduling.annotation.AsyncResult; |
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| @@ -22,17 +23,17 @@ import java.util.concurrent.Future; | @@ -22,17 +23,17 @@ import java.util.concurrent.Future; | ||
| 22 | @Service | 23 | @Service |
| 23 | @Validated | 24 | @Validated |
| 24 | @Slf4j | 25 | @Slf4j |
| 25 | -public class InfApiErrorLogServiceImpl implements InfApiErrorLogService { | 26 | +public class InfApiErrorLogCoreServiceImpl implements InfApiErrorLogCoreService { |
| 26 | 27 | ||
| 27 | @Resource | 28 | @Resource |
| 28 | - private InfApiErrorLogMapper apiErrorLogMapper; | 29 | + private InfApiErrorLogCoreMapper apiErrorLogMapper; |
| 29 | 30 | ||
| 30 | @Override | 31 | @Override |
| 31 | - public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { | ||
| 32 | - InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO); | 32 | + @Async |
| 33 | + public void createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) { | ||
| 34 | + InfApiErrorLogDO apiErrorLog = InfApiErrorLogCoreConvert.INSTANCE.convert(createDTO); | ||
| 33 | apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); | 35 | apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus()); |
| 34 | - int insert = apiErrorLogMapper.insert(apiErrorLog); | ||
| 35 | - return new AsyncResult<>(insert == 1); | 36 | + apiErrorLogMapper.insert(apiErrorLog); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | } | 39 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java
0 → 100644
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md
0 → 100644
| 1 | +<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao> |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user; | 1 | +package cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +@Mapper | ||
| 8 | +public interface MbrUserCoreMapper extends BaseMapperX<MbrUserDO> { | ||
| 9 | + | ||
| 10 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/package-info.java
0 → 100644
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.member.service.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 前台用户 Core Service 接口 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public interface MbrUserCoreService { | ||
| 11 | + /** | ||
| 12 | + * 通过用户 ID 查询用户 | ||
| 13 | + * | ||
| 14 | + * @param id 用户ID | ||
| 15 | + * @return 用户对象信息 | ||
| 16 | + */ | ||
| 17 | + MbrUserDO getUser(Long id); | ||
| 18 | + | ||
| 19 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.member.service.user.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user.MbrUserCoreMapper; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; | ||
| 6 | +import lombok.extern.slf4j.Slf4j; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | + | ||
| 9 | +import javax.annotation.Resource; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * User Core Service 实现类 | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@Service | ||
| 17 | +@Slf4j | ||
| 18 | +public class MbrUserCoreServiceImpl implements MbrUserCoreService { | ||
| 19 | + | ||
| 20 | + @Resource | ||
| 21 | + private MbrUserCoreMapper userCoreMapper; | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public MbrUserDO getUser(Long id) { | ||
| 25 | + return userCoreMapper.selectById(id); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/dict/SysDictDataConvert.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/dict/SysDictDataCoreConvert.java
| 1 | -package cn.iocoder.yudao.userserver.modules.system.convert.dict; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.convert.dict; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 3 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; | 4 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; |
| 4 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 5 | import org.mapstruct.Mapper; | 5 | import org.mapstruct.Mapper; |
| 6 | import org.mapstruct.factory.Mappers; | 6 | import org.mapstruct.factory.Mappers; |
| 7 | 7 | ||
| @@ -9,9 +9,9 @@ import java.util.Collection; | @@ -9,9 +9,9 @@ import java.util.Collection; | ||
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | 10 | ||
| 11 | @Mapper | 11 | @Mapper |
| 12 | -public interface SysDictDataConvert { | 12 | +public interface SysDictDataCoreConvert { |
| 13 | 13 | ||
| 14 | - SysDictDataConvert INSTANCE = Mappers.getMapper(SysDictDataConvert.class); | 14 | + SysDictDataCoreConvert INSTANCE = Mappers.getMapper(SysDictDataCoreConvert.class); |
| 15 | 15 | ||
| 16 | DictDataRespDTO convert02(SysDictDataDO bean); | 16 | DictDataRespDTO convert02(SysDictDataDO bean); |
| 17 | 17 |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/logger/SysLoginLogCoreConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.convert.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 5 | +import org.mapstruct.Mapper; | ||
| 6 | +import org.mapstruct.factory.Mappers; | ||
| 7 | + | ||
| 8 | +@Mapper | ||
| 9 | +public interface SysLoginLogCoreConvert { | ||
| 10 | + | ||
| 11 | + SysLoginLogCoreConvert INSTANCE = Mappers.getMapper(SysLoginLogCoreConvert.class); | ||
| 12 | + | ||
| 13 | + SysLoginLogDO convert(SysLoginLogCreateReqDTO bean); | ||
| 14 | + | ||
| 15 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/package-info.java
0 → 100644
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md
0 → 100644
| 1 | +<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao> |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/auth/SysUserSessionDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/auth/SysUserSessionDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.auth; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 5 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 6 | import com.baomidou.mybatisplus.annotation.IdType; | 6 | import com.baomidou.mybatisplus.annotation.IdType; |
| 7 | import com.baomidou.mybatisplus.annotation.TableId; | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 8 | import com.baomidou.mybatisplus.annotation.TableName; | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -35,9 +35,15 @@ public class SysUserSessionDO extends BaseDO { | @@ -35,9 +35,15 @@ public class SysUserSessionDO extends BaseDO { | ||
| 35 | /** | 35 | /** |
| 36 | * 用户编号 | 36 | * 用户编号 |
| 37 | * | 37 | * |
| 38 | - * 关联 {@link SysUserDO#getId()} | 38 | + * 关联 SysUserDO.id 或者 MbrUserDO.id |
| 39 | */ | 39 | */ |
| 40 | private Long userId; | 40 | private Long userId; |
| 41 | + /** | ||
| 42 | + * 用户类型 | ||
| 43 | + * | ||
| 44 | + * 枚举 {@link UserTypeEnum} | ||
| 45 | + */ | ||
| 46 | + private Integer userType; | ||
| 41 | 47 | ||
| 42 | /** | 48 | /** |
| 43 | * 用户账号 | 49 | * 用户账号 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dict/SysDictDataDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/dict/SysDictDataDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dict; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/logger/SysLoginLogDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginLogTypeEnum; | ||
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.enums.logger.SysLoginResultEnum; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | ||
| 7 | import com.baomidou.mybatisplus.annotation.TableName; | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | import lombok.Data; | 8 | import lombok.Data; |
| 9 | import lombok.EqualsAndHashCode; | 9 | import lombok.EqualsAndHashCode; |
| @@ -14,7 +14,7 @@ import lombok.ToString; | @@ -14,7 +14,7 @@ import lombok.ToString; | ||
| 14 | * | 14 | * |
| 15 | * 注意,包括登录和登出两种行为 | 15 | * 注意,包括登录和登出两种行为 |
| 16 | * | 16 | * |
| 17 | - * @author ruoyi | 17 | + * @author 芋道源码 |
| 18 | */ | 18 | */ |
| 19 | @TableName("sys_login_log") | 19 | @TableName("sys_login_log") |
| 20 | @Data | 20 | @Data |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsChannelDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsChannelDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsLogDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsLogDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 6 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | import cn.iocoder.yudao.framework.sms.core.enums.SmsFrameworkErrorCodeConstants; | 7 | import cn.iocoder.yudao.framework.sms.core.enums.SmsFrameworkErrorCodeConstants; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 8 | import com.baomidou.mybatisplus.annotation.TableField; | 8 | import com.baomidou.mybatisplus.annotation.TableField; |
| 9 | import com.baomidou.mybatisplus.annotation.TableName; | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| 10 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | 10 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 6 | import com.baomidou.mybatisplus.annotation.TableField; | 6 | import com.baomidou.mybatisplus.annotation.TableField; |
| 7 | import com.baomidou.mybatisplus.annotation.TableName; | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | 8 | import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/user/SysUserDO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/dataobject/user/SysUserDO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.enums.common.SysSexEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; | 6 | import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.enums.common.SysSexEnum; | ||
| 7 | import com.baomidou.mybatisplus.annotation.TableField; | 7 | import com.baomidou.mybatisplus.annotation.TableField; |
| 8 | import com.baomidou.mybatisplus.annotation.TableId; | 8 | import com.baomidou.mybatisplus.annotation.TableId; |
| 9 | import com.baomidou.mybatisplus.annotation.TableName; | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -16,7 +16,7 @@ import java.util.Set; | @@ -16,7 +16,7 @@ import java.util.Set; | ||
| 16 | /** | 16 | /** |
| 17 | * 管理后台的用户 DO | 17 | * 管理后台的用户 DO |
| 18 | * | 18 | * |
| 19 | - * @author ruoyi | 19 | + * @author 芋道源码 |
| 20 | */ | 20 | */ |
| 21 | @TableName(value = "sys_user", autoResultMap = true) | 21 | @TableName(value = "sys_user", autoResultMap = true) |
| 22 | @Data | 22 | @Data |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/auth/SysUserSessionCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +@Mapper | ||
| 8 | +public interface SysUserSessionCoreMapper extends BaseMapperX<SysUserSessionDO> { | ||
| 9 | + | ||
| 10 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/dict/SysDictDataMapper.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/dict/SysDictDataCoreMapper.java
| 1 | -package cn.iocoder.yudao.userserver.modules.system.dal.mysql.dict; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; | 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; |
| 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 7 | import org.apache.ibatis.annotations.Mapper; | 7 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 8 | ||
| 9 | import java.util.Date; | 9 | import java.util.Date; |
| 10 | 10 | ||
| 11 | @Mapper | 11 | @Mapper |
| 12 | -public interface SysDictDataMapper extends BaseMapperX<SysDictDataDO> { | ||
| 13 | - | ||
| 14 | - default SysDictDataDO selectByDictTypeAndValue(String dictType, String value) { | ||
| 15 | - return selectOne(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType) | ||
| 16 | - .eq("value", value)); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - default int selectCountByDictType(String dictType) { | ||
| 20 | - return selectCount("dict_type", dictType); | ||
| 21 | - } | 12 | +public interface SysDictDataCoreMapper extends BaseMapperX<SysDictDataDO> { |
| 22 | 13 | ||
| 23 | default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { | 14 | default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { |
| 24 | return selectOne(new QueryWrapper<SysDictDataDO>().select("id") | 15 | return selectOne(new QueryWrapper<SysDictDataDO>().select("id") |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/logger/SysLoginLogCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +@Mapper | ||
| 8 | +public interface SysLoginLogCoreMapper extends BaseMapperX<SysLoginLogDO> { | ||
| 9 | + | ||
| 10 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsLogCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | ||
| 7 | +import org.apache.ibatis.annotations.Mapper; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Mapper | ||
| 12 | +public interface SysSmsLogCoreMapper extends BaseMapperX<SysSmsLogDO> { | ||
| 13 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/sms/SysSmsTemplateCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | +import org.apache.ibatis.annotations.Select; | ||
| 7 | + | ||
| 8 | +import java.util.Date; | ||
| 9 | + | ||
| 10 | +@Mapper | ||
| 11 | +public interface SysSmsTemplateCoreMapper extends BaseMapperX<SysSmsTemplateDO> { | ||
| 12 | + | ||
| 13 | + @Select("SELECT id FROM sys_sms_template WHERE update_time > #{maxUpdateTime} LIMIT 1") | ||
| 14 | + Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); | ||
| 15 | + | ||
| 16 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/user/SysUserCoreMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 6 | +import org.apache.ibatis.annotations.Mapper; | ||
| 7 | + | ||
| 8 | +@Mapper | ||
| 9 | +public interface SysUserCoreMapper extends BaseMapperX<SysUserDO> { | ||
| 10 | + | ||
| 11 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/SysRedisKeyCoreConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.redis; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine; | ||
| 4 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 5 | + | ||
| 6 | +import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.STRING; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * System Redis Key 枚举类 | ||
| 10 | + * | ||
| 11 | + * @author 芋道源码 | ||
| 12 | + */ | ||
| 13 | +public interface SysRedisKeyCoreConstants { | ||
| 14 | + | ||
| 15 | + RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", | ||
| 16 | + "login_user:%s", // 参数为 sessionId | ||
| 17 | + STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); | ||
| 18 | + | ||
| 19 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/auth/SysLoginUserRedisDAO.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/auth/SysLoginUserCoreRedisDAO.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.dal.redis.auth; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysUserSessionService; | ||
| 5 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | ||
| 5 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 6 | import org.springframework.data.redis.core.StringRedisTemplate; | 6 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 7 | import org.springframework.stereotype.Repository; | 7 | import org.springframework.stereotype.Repository; |
| 8 | 8 | ||
| 9 | import javax.annotation.Resource; | 9 | import javax.annotation.Resource; |
| 10 | -import java.time.Duration; | ||
| 11 | 10 | ||
| 12 | -import static cn.iocoder.yudao.adminserver.modules.system.dal.redis.SysRedisKeyConstants.LOGIN_USER; | 11 | +import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.LOGIN_USER; |
| 13 | 12 | ||
| 14 | /** | 13 | /** |
| 15 | * {@link LoginUser} 的 RedisDAO | 14 | * {@link LoginUser} 的 RedisDAO |
| @@ -17,12 +16,13 @@ import static cn.iocoder.yudao.adminserver.modules.system.dal.redis.SysRedisKeyC | @@ -17,12 +16,13 @@ import static cn.iocoder.yudao.adminserver.modules.system.dal.redis.SysRedisKeyC | ||
| 17 | * @author 芋道源码 | 16 | * @author 芋道源码 |
| 18 | */ | 17 | */ |
| 19 | @Repository | 18 | @Repository |
| 20 | -public class SysLoginUserRedisDAO { | 19 | +public class SysLoginUserCoreRedisDAO { |
| 21 | 20 | ||
| 22 | @Resource | 21 | @Resource |
| 23 | private StringRedisTemplate stringRedisTemplate; | 22 | private StringRedisTemplate stringRedisTemplate; |
| 23 | + | ||
| 24 | @Resource | 24 | @Resource |
| 25 | - private SysUserSessionService sysUserSessionService; // TODO 芋艿:得看看怎么拿出去 | 25 | + private SecurityProperties securityProperties; |
| 26 | 26 | ||
| 27 | public LoginUser get(String sessionId) { | 27 | public LoginUser get(String sessionId) { |
| 28 | String redisKey = formatKey(sessionId); | 28 | String redisKey = formatKey(sessionId); |
| @@ -32,7 +32,7 @@ public class SysLoginUserRedisDAO { | @@ -32,7 +32,7 @@ public class SysLoginUserRedisDAO { | ||
| 32 | public void set(String sessionId, LoginUser loginUser) { | 32 | public void set(String sessionId, LoginUser loginUser) { |
| 33 | String redisKey = formatKey(sessionId); | 33 | String redisKey = formatKey(sessionId); |
| 34 | stringRedisTemplate.opsForValue().set(redisKey, JsonUtils.toJsonString(loginUser), | 34 | stringRedisTemplate.opsForValue().set(redisKey, JsonUtils.toJsonString(loginUser), |
| 35 | - Duration.ofMillis(sysUserSessionService.getSessionTimeoutMillis())); | 35 | + securityProperties.getSessionTimeout()); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public void delete(String sessionId) { | 38 | public void delete(String sessionId) { |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.enums; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * System 错误码枚举类 | ||
| 7 | + * | ||
| 8 | + * system 系统,使用 1-006-000-000 段 | ||
| 9 | + */ | ||
| 10 | +public interface SysErrorCodeConstants { | ||
| 11 | + | ||
| 12 | + // ========== 短信发送 1006000000 ========== | ||
| 13 | + ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1006000000, "手机号不存在"); | ||
| 14 | + ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失"); | ||
| 15 | + ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在"); | ||
| 16 | + | ||
| 17 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/common/SysSexEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/common/SysSexEnum.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.enums.common; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.enums.common; |
| 2 | 2 | ||
| 3 | import lombok.AllArgsConstructor; | 3 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Getter; | 4 | import lombok.Getter; |
| @@ -11,12 +11,14 @@ import lombok.Getter; | @@ -11,12 +11,14 @@ import lombok.Getter; | ||
| 11 | @Getter | 11 | @Getter |
| 12 | @AllArgsConstructor | 12 | @AllArgsConstructor |
| 13 | public enum SysSexEnum { | 13 | public enum SysSexEnum { |
| 14 | + | ||
| 14 | /** 男 */ | 15 | /** 男 */ |
| 15 | MALE(1), | 16 | MALE(1), |
| 16 | /** 女 */ | 17 | /** 女 */ |
| 17 | FEMALE(2), | 18 | FEMALE(2), |
| 18 | /* 未知 */ | 19 | /* 未知 */ |
| 19 | UNKNOWN(3); | 20 | UNKNOWN(3); |
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * 性别 | 23 | * 性别 |
| 22 | */ | 24 | */ |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginLogTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.enums.logger; | ||
| 2 | + | ||
| 3 | +import lombok.AllArgsConstructor; | ||
| 4 | +import lombok.Getter; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 登录日志的类型枚举 | ||
| 8 | + */ | ||
| 9 | +@Getter | ||
| 10 | +@AllArgsConstructor | ||
| 11 | +public enum SysLoginLogTypeEnum { | ||
| 12 | + | ||
| 13 | + LOGIN_USERNAME(100), // 使用账号登录 | ||
| 14 | + LOGIN_SOCIAL(101), // 使用社交登录 | ||
| 15 | + LOGIN_MOCK(102), // 使用 Mock 登录 | ||
| 16 | + LOGIN_MOBILE(103), // 使用手机登陆 | ||
| 17 | + LOGIN_SMS(104), // 使用短信登陆 | ||
| 18 | + | ||
| 19 | + LOGOUT_SELF(200), // 自己主动登出 | ||
| 20 | + LOGOUT_TIMEOUT(201), // 超时登出 | ||
| 21 | + LOGOUT_DELETE(202), // 强制退出 | ||
| 22 | + ; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 日志类型 | ||
| 26 | + */ | ||
| 27 | + private final Integer type; | ||
| 28 | + | ||
| 29 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/logger/SysLoginResultEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.enums.logger; | ||
| 2 | + | ||
| 3 | +import lombok.AllArgsConstructor; | ||
| 4 | +import lombok.Getter; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 登录结果的枚举类 | ||
| 8 | + */ | ||
| 9 | +@Getter | ||
| 10 | +@AllArgsConstructor | ||
| 11 | +public enum SysLoginResultEnum { | ||
| 12 | + | ||
| 13 | + SUCCESS(0), // 成功 | ||
| 14 | + BAD_CREDENTIALS(10), // 账号或密码不正确 | ||
| 15 | + USER_DISABLED(20), // 用户被禁用 | ||
| 16 | + CAPTCHA_NOT_FOUND(30), // 图片验证码不存在 | ||
| 17 | + CAPTCHA_CODE_ERROR(31), // 图片验证码不正确 | ||
| 18 | + | ||
| 19 | + UNKNOWN_ERROR(100), // 未知异常 | ||
| 20 | + ; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 结果 | ||
| 24 | + */ | ||
| 25 | + private final Integer result; | ||
| 26 | + | ||
| 27 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsReceiveStatusEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsReceiveStatusEnum.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsSendStatusEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsSendStatusEnum.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/sms/SysSmsTemplateTypeEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/sms/SysSmsTemplateTypeEnum.java
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/package-info.java
0 → 100644
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/mq/message/sms/SysSmsSendMessage.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/message/sms/SysSmsSendMessage.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.mq.message.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.mq.message.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | import cn.iocoder.yudao.framework.mq.core.stream.StreamMessage; | 4 | import cn.iocoder.yudao.framework.mq.core.stream.StreamMessage; |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/package-info.java
0 → 100644
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/mq/producer/sms/SysSmsCoreProducer.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 4 | +import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 5 | +import cn.iocoder.yudao.framework.mq.core.util.RedisMessageUtils; | ||
| 6 | +import lombok.extern.slf4j.Slf4j; | ||
| 7 | +import org.springframework.data.redis.core.StringRedisTemplate; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | + | ||
| 10 | +import javax.annotation.Resource; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * Sms 短信相关消息的 Core Producer | ||
| 15 | + * | ||
| 16 | + * @author zzf | ||
| 17 | + * @date 2021/3/9 16:35 | ||
| 18 | + */ | ||
| 19 | +@Slf4j | ||
| 20 | +@Component | ||
| 21 | +public class SysSmsCoreProducer { | ||
| 22 | + | ||
| 23 | + @Resource | ||
| 24 | + private StringRedisTemplate stringRedisTemplate; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 发送 {@link SysSmsSendMessage} 消息 | ||
| 28 | + * | ||
| 29 | + * @param logId 短信日志编号 | ||
| 30 | + * @param mobile 手机号 | ||
| 31 | + * @param channelId 渠道编号 | ||
| 32 | + * @param apiTemplateId 短信模板编号 | ||
| 33 | + * @param templateParams 短信模板参数 | ||
| 34 | + */ | ||
| 35 | + public void sendSmsSendMessage(Long logId, String mobile, | ||
| 36 | + Long channelId, String apiTemplateId, List<KeyValue<String, Object>> templateParams) { | ||
| 37 | + SysSmsSendMessage message = new SysSmsSendMessage().setLogId(logId).setMobile(mobile); | ||
| 38 | + message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams); | ||
| 39 | + RedisMessageUtils.sendStreamMessage(stringRedisTemplate, message); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/package-info.java
0 → 100644
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.auth; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 在线用户 Session Core Service 接口 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public interface SysUserSessionCoreService { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 创建在线用户 Session | ||
| 14 | + * | ||
| 15 | + * @param loginUser 登录用户 | ||
| 16 | + * @param userIp 用户 IP | ||
| 17 | + * @param userAgent 用户 UA | ||
| 18 | + * @return Session 编号 | ||
| 19 | + */ | ||
| 20 | + String createUserSession(LoginUser loginUser, String userIp, String userAgent); | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 刷新在线用户 Session 的更新时间 | ||
| 24 | + * | ||
| 25 | + * @param sessionId Session 编号 | ||
| 26 | + * @param loginUser 登录用户 | ||
| 27 | + */ | ||
| 28 | + void refreshUserSession(String sessionId, LoginUser loginUser); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 删除在线用户 Session | ||
| 32 | + * | ||
| 33 | + * @param sessionId Session 编号 | ||
| 34 | + */ | ||
| 35 | + void deleteUserSession(String sessionId); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 获得 Session 编号对应的在线用户 | ||
| 39 | + * | ||
| 40 | + * @param sessionId Session 编号 | ||
| 41 | + * @return 在线用户 | ||
| 42 | + */ | ||
| 43 | + LoginUser getLoginUser(String sessionId); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 获得 Session 超时时间,单位:毫秒 | ||
| 47 | + * | ||
| 48 | + * @return 超时时间 | ||
| 49 | + */ | ||
| 50 | + Long getSessionTimeoutMillis(); | ||
| 51 | + | ||
| 52 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/impl/SysUserSessionCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.auth.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.IdUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth.SysUserSessionCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||
| 8 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | ||
| 9 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | + | ||
| 12 | +import javax.annotation.Resource; | ||
| 13 | +import java.time.Duration; | ||
| 14 | +import java.util.Date; | ||
| 15 | + | ||
| 16 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 在线用户 Session Core Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author 芋道源码 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +public class SysUserSessionCoreServiceImpl implements SysUserSessionCoreService { | ||
| 25 | + | ||
| 26 | + @Resource | ||
| 27 | + private SysUserSessionCoreMapper userSessionCoreMapper; | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private SecurityProperties securityProperties; | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public String createUserSession(LoginUser loginUser, String userIp, String userAgent) { | ||
| 37 | + // 生成 Session 编号 | ||
| 38 | + String sessionId = generateSessionId(); | ||
| 39 | + // 写入 Redis 缓存 | ||
| 40 | + loginUser.setUpdateTime(new Date()); | ||
| 41 | + loginUserCoreRedisDAO.set(sessionId, loginUser); | ||
| 42 | + // 写入 DB 中 | ||
| 43 | + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 44 | + .userId(loginUser.getId()).userType(loginUser.getUserType()) | ||
| 45 | + .userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) | ||
| 46 | + .sessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))) | ||
| 47 | + .build(); | ||
| 48 | + userSessionCoreMapper.insert(userSession); | ||
| 49 | + // 返回 Session 编号 | ||
| 50 | + return sessionId; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void refreshUserSession(String sessionId, LoginUser loginUser) { | ||
| 55 | + // 写入 Redis 缓存 | ||
| 56 | + loginUser.setUpdateTime(new Date()); | ||
| 57 | + loginUserCoreRedisDAO.set(sessionId, loginUser); | ||
| 58 | + // 更新 DB 中 | ||
| 59 | + SysUserSessionDO updateObj = SysUserSessionDO.builder().id(sessionId).build(); | ||
| 60 | + updateObj.setUsername(loginUser.getUsername()); | ||
| 61 | + updateObj.setUpdateTime(new Date()); | ||
| 62 | + updateObj.setSessionTimeout(addTime(Duration.ofMillis(getSessionTimeoutMillis()))); | ||
| 63 | + userSessionCoreMapper.updateById(updateObj); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public void deleteUserSession(String sessionId) { | ||
| 68 | + // 删除 Redis 缓存 | ||
| 69 | + loginUserCoreRedisDAO.delete(sessionId); | ||
| 70 | + // 删除 DB 记录 | ||
| 71 | + userSessionCoreMapper.deleteById(sessionId); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public LoginUser getLoginUser(String sessionId) { | ||
| 76 | + return loginUserCoreRedisDAO.get(sessionId); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public Long getSessionTimeoutMillis() { | ||
| 81 | + return securityProperties.getSessionTimeout().toMillis(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 生成 Session 编号,目前采用 UUID 算法 | ||
| 86 | + * | ||
| 87 | + * @return Session 编号 | ||
| 88 | + */ | ||
| 89 | + private static String generateSessionId() { | ||
| 90 | + return IdUtil.fastSimpleUUID(); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/SysDictDataService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreService.java
| 1 | -package cn.iocoder.yudao.userserver.modules.system.service.dict; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.dict; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; | 3 | import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * 字典数据 Service 接口 | 6 | * 字典数据 Service 接口 |
| 7 | * | 7 | * |
| 8 | - * @author ruoyi | 8 | + * @author 芋道源码 |
| 9 | */ | 9 | */ |
| 10 | -public interface SysDictDataService extends DictDataFrameworkService { | 10 | +public interface SysDictDataCoreService extends DictDataFrameworkService { |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * 初始化字典数据的本地缓存 | 13 | * 初始化字典数据的本地缓存 |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/dict/impl/SysDictDataServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/impl/SysDictDataCoreServiceImpl.java
| 1 | -package cn.iocoder.yudao.userserver.modules.system.service.dict.impl; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.dict.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.convert.dict.SysDictDataCoreConvert; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict.SysDictDataCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.dict.SysDictDataCoreService; | ||
| 4 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; | 8 | import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 9 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 6 | -import cn.iocoder.yudao.userserver.modules.system.convert.dict.SysDictDataConvert; | ||
| 7 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 8 | -import cn.iocoder.yudao.userserver.modules.system.dal.mysql.dict.SysDictDataMapper; | ||
| 9 | -import cn.iocoder.yudao.userserver.modules.system.service.dict.SysDictDataService; | ||
| 10 | import com.google.common.collect.ImmutableTable; | 10 | import com.google.common.collect.ImmutableTable; |
| 11 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| 12 | import org.springframework.scheduling.annotation.Scheduled; | 12 | import org.springframework.scheduling.annotation.Scheduled; |
| @@ -21,11 +21,11 @@ import java.util.List; | @@ -21,11 +21,11 @@ import java.util.List; | ||
| 21 | /** | 21 | /** |
| 22 | * 字典数据 Service 实现类 | 22 | * 字典数据 Service 实现类 |
| 23 | * | 23 | * |
| 24 | - * @author ruoyi | 24 | + * @author 芋道源码 |
| 25 | */ | 25 | */ |
| 26 | @Service | 26 | @Service |
| 27 | @Slf4j | 27 | @Slf4j |
| 28 | -public class SysDictDataServiceImpl implements SysDictDataService { | 28 | +public class SysDictDataCoreServiceImpl implements SysDictDataCoreService { |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 | 31 | * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 |
| @@ -53,7 +53,7 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -53,7 +53,7 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 53 | private volatile Date maxUpdateTime; | 53 | private volatile Date maxUpdateTime; |
| 54 | 54 | ||
| 55 | @Resource | 55 | @Resource |
| 56 | - private SysDictDataMapper dictDataMapper; | 56 | + private SysDictDataCoreMapper dictDataCoreMapper; |
| 57 | 57 | ||
| 58 | @Override | 58 | @Override |
| 59 | @PostConstruct | 59 | @PostConstruct |
| @@ -95,28 +95,28 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -95,28 +95,28 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 95 | if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 | 95 | if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 |
| 96 | log.info("[loadDictDataIfUpdate][首次加载全量字典数据]"); | 96 | log.info("[loadDictDataIfUpdate][首次加载全量字典数据]"); |
| 97 | } else { // 判断数据库中是否有更新的字典数据 | 97 | } else { // 判断数据库中是否有更新的字典数据 |
| 98 | - if (!dictDataMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { | 98 | + if (!dictDataCoreMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { |
| 99 | return null; | 99 | return null; |
| 100 | } | 100 | } |
| 101 | log.info("[loadDictDataIfUpdate][增量加载全量字典数据]"); | 101 | log.info("[loadDictDataIfUpdate][增量加载全量字典数据]"); |
| 102 | } | 102 | } |
| 103 | // 第二步,如果有更新,则从数据库加载所有字典数据 | 103 | // 第二步,如果有更新,则从数据库加载所有字典数据 |
| 104 | - return dictDataMapper.selectList(); | 104 | + return dictDataCoreMapper.selectList(); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | @Override | 107 | @Override |
| 108 | public DictDataRespDTO getDictDataFromCache(String type, String value) { | 108 | public DictDataRespDTO getDictDataFromCache(String type, String value) { |
| 109 | - return SysDictDataConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); | 109 | + return SysDictDataCoreConvert.INSTANCE.convert02(valueDictDataCache.get(type, value)); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | @Override | 112 | @Override |
| 113 | public DictDataRespDTO parseDictDataFromCache(String type, String label) { | 113 | public DictDataRespDTO parseDictDataFromCache(String type, String label) { |
| 114 | - return SysDictDataConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); | 114 | + return SysDictDataCoreConvert.INSTANCE.convert02(labelDictDataCache.get(type, label)); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | @Override | 117 | @Override |
| 118 | public List<DictDataRespDTO> listDictDatasFromCache(String type) { | 118 | public List<DictDataRespDTO> listDictDatasFromCache(String type) { |
| 119 | - return SysDictDataConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); | 119 | + return SysDictDataCoreConvert.INSTANCE.convertList03(labelDictDataCache.row(type).values()); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | } | 122 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 登录日志 Core Service 接口 | ||
| 7 | + */ | ||
| 8 | +public interface SysLoginLogCoreService { | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * 创建登录日志 | ||
| 12 | + * | ||
| 13 | + * @param reqDTO 日志信息 | ||
| 14 | + */ | ||
| 15 | + void createLoginLog(SysLoginLogCreateReqDTO reqDTO); | ||
| 16 | + | ||
| 17 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/dto/SysLoginLogCreateReqDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.logger.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import javax.validation.constraints.NotBlank; | ||
| 6 | +import javax.validation.constraints.NotEmpty; | ||
| 7 | +import javax.validation.constraints.NotNull; | ||
| 8 | +import javax.validation.constraints.Size; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 登录日志创建 Request DTO | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@Data | ||
| 16 | +public class SysLoginLogCreateReqDTO { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 日志类型 | ||
| 20 | + */ | ||
| 21 | + @NotNull(message = "日志类型不能为空") | ||
| 22 | + private Integer logType; | ||
| 23 | + /** | ||
| 24 | + * 链路追踪编号 | ||
| 25 | + */ | ||
| 26 | + @NotEmpty(message = "链路追踪编号不能为空") | ||
| 27 | + private String traceId; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 用户编号 | ||
| 31 | + */ | ||
| 32 | + private Long userId; | ||
| 33 | + /** | ||
| 34 | + * 用户类型 | ||
| 35 | + */ | ||
| 36 | + @NotNull(message = "用户类型不能为空") | ||
| 37 | + private Integer userType; | ||
| 38 | + /** | ||
| 39 | + * 用户账号 | ||
| 40 | + */ | ||
| 41 | + @NotBlank(message = "用户账号不能为空") | ||
| 42 | + @Size(max = 30, message = "用户账号长度不能超过30个字符") | ||
| 43 | + private String username; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 登录结果 | ||
| 47 | + */ | ||
| 48 | + @NotNull(message = "登录结果不能为空") | ||
| 49 | + private Integer result; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 用户 IP | ||
| 53 | + */ | ||
| 54 | + @NotEmpty(message = "用户 IP 不能为空") | ||
| 55 | + private String userIp; | ||
| 56 | + /** | ||
| 57 | + * 浏览器 UserAgent | ||
| 58 | + */ | ||
| 59 | + @NotEmpty(message = "浏览器 UserAgent 不能为空") | ||
| 60 | + private String userAgent; | ||
| 61 | + | ||
| 62 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/impl/SysLoginLogCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.logger.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.convert.logger.SysLoginLogCoreConvert; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger.SysLoginLogCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 8 | +import org.springframework.stereotype.Service; | ||
| 9 | + | ||
| 10 | +import javax.annotation.Resource; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 登录日志 Service Core 实现 | ||
| 14 | + * | ||
| 15 | + * @author 芋道源码 | ||
| 16 | + */ | ||
| 17 | +@Service | ||
| 18 | +public class SysLoginLogCoreServiceImpl implements SysLoginLogCoreService { | ||
| 19 | + | ||
| 20 | + @Resource | ||
| 21 | + private SysLoginLogCoreMapper loginLogMapper; | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public void createLoginLog(SysLoginLogCreateReqDTO reqDTO) { | ||
| 25 | + SysLoginLogDO loginLog = SysLoginLogCoreConvert.INSTANCE.convert(reqDTO); | ||
| 26 | + // 插入 | ||
| 27 | + loginLogMapper.insert(loginLog); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreService.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | 3 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; |
| 4 | 4 | ||
| 5 | import java.util.List; | 5 | import java.util.List; |
| 6 | import java.util.Map; | 6 | import java.util.Map; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | - * 短信Service接口 | ||
| 10 | - * 只支持异步,因此没有返回值 | 9 | + * 短信 Service Core 接口 |
| 11 | * | 10 | * |
| 12 | - * @author zzf | ||
| 13 | - * @date 2021/1/25 9:24 | 11 | + * 接入方,通过调用 send 开头的方法,创建发送短信的任务到 MQ 中 |
| 12 | + * 后续,yudao-admin-server 监听 MQ,执行真正的短信发送逻辑 | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 14 | */ | 15 | */ |
| 15 | -public interface SysSmsService { | 16 | +public interface SysSmsCoreService { |
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| 18 | - * 发送单条短信给用户(管理员) | 19 | + * 发送单条短信给后台用户 |
| 19 | * | 20 | * |
| 20 | * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 | 21 | * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 |
| 21 | * | 22 | * |
| @@ -29,7 +30,7 @@ public interface SysSmsService { | @@ -29,7 +30,7 @@ public interface SysSmsService { | ||
| 29 | String templateCode, Map<String, Object> templateParams); | 30 | String templateCode, Map<String, Object> templateParams); |
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| 32 | - * 发送单条短信给用户(会员) | 33 | + * 发送单条短信给前台用户 |
| 33 | * | 34 | * |
| 34 | * 在 mobile 为空时,使用 userId 加载对应会员的手机号 | 35 | * 在 mobile 为空时,使用 userId 加载对应会员的手机号 |
| 35 | * | 36 | * |
| @@ -40,7 +41,7 @@ public interface SysSmsService { | @@ -40,7 +41,7 @@ public interface SysSmsService { | ||
| 40 | * @return 发送日志编号 | 41 | * @return 发送日志编号 |
| 41 | */ | 42 | */ |
| 42 | Long sendSingleSmsToMember(String mobile, Long userId, | 43 | Long sendSingleSmsToMember(String mobile, Long userId, |
| 43 | - String templateCode, Map<String, Object> templateParams); | 44 | + String templateCode, Map<String, Object> templateParams); |
| 44 | 45 | ||
| 45 | Long sendSingleSms(String mobile, Long userId, Integer userType, | 46 | Long sendSingleSms(String mobile, Long userId, Integer userType, |
| 46 | String templateCode, Map<String, Object> templateParams); | 47 | String templateCode, Map<String, Object> templateParams); |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 4 | + | ||
| 5 | +import java.util.Date; | ||
| 6 | +import java.util.Map; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 短信日志 Core Service 接口 | ||
| 10 | + * | ||
| 11 | + * @author zzf | ||
| 12 | + * @date 13:48 2021/3/2 | ||
| 13 | + */ | ||
| 14 | +public interface SysSmsLogCoreService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 创建短信日志 | ||
| 18 | + * | ||
| 19 | + * @param mobile 手机号 | ||
| 20 | + * @param userId 用户编号 | ||
| 21 | + * @param userType 用户类型 | ||
| 22 | + * @param isSend 是否发送 | ||
| 23 | + * @param template 短信模板 | ||
| 24 | + * @param templateContent 短信内容 | ||
| 25 | + * @param templateParams 短信参数 | ||
| 26 | + * @return 发送日志编号 | ||
| 27 | + */ | ||
| 28 | + Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, | ||
| 29 | + SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 更新日志的发送结果 | ||
| 33 | + * | ||
| 34 | + * @param id 日志编号 | ||
| 35 | + * @param sendCode 发送结果的编码 | ||
| 36 | + * @param sendMsg 发送结果的提示 | ||
| 37 | + * @param apiSendCode 短信 API 发送结果的编码 | ||
| 38 | + * @param apiSendMsg 短信 API 发送失败的提示 | ||
| 39 | + * @param apiRequestId 短信 API 发送返回的唯一请求 ID | ||
| 40 | + * @param apiSerialNo 短信 API 发送返回的序号 | ||
| 41 | + */ | ||
| 42 | + void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, | ||
| 43 | + String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 更新日志的接收结果 | ||
| 47 | + * | ||
| 48 | + * @param id 日志编号 | ||
| 49 | + * @param success 是否接收成功 | ||
| 50 | + * @param receiveTime 用户接收时间 | ||
| 51 | + * @param apiReceiveCode API 接收结果的编码 | ||
| 52 | + * @param apiReceiveMsg API 接收结果的说明 | ||
| 53 | + */ | ||
| 54 | + void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg); | ||
| 55 | + | ||
| 56 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 4 | + | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 短信模板 Core Service 接口 | ||
| 9 | + * | ||
| 10 | + * @author 芋道源码 | ||
| 11 | + */ | ||
| 12 | +public interface SysSmsTemplateCoreService { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 初始化短信模板的本地缓存 | ||
| 16 | + */ | ||
| 17 | + void initLocalCache(); | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 获得短信模板,从缓存中 | ||
| 21 | + * | ||
| 22 | + * @param code 模板编码 | ||
| 23 | + * @return 短信模板 | ||
| 24 | + */ | ||
| 25 | + SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 格式化短信内容 | ||
| 29 | + * | ||
| 30 | + * @param content 短信模板的内容 | ||
| 31 | + * @param params 内容的参数 | ||
| 32 | + * @return 格式化后的内容 | ||
| 33 | + */ | ||
| 34 | + String formatSmsTemplateContent(String content, Map<String, Object> params); | ||
| 35 | + | ||
| 36 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.service.sms.impl; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms.SysSmsCoreProducer; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | ||
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsLogCoreService; | ||
| 13 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; | ||
| 14 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 5 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 15 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 16 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 17 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| @@ -10,16 +20,7 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | @@ -10,16 +20,7 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 10 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | 20 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; |
| 11 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; | 21 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 12 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; | 22 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; |
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 14 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; | ||
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 16 | -import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | ||
| 17 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsLogService; | ||
| 18 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsService; | ||
| 19 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.SysSmsTemplateService; | ||
| 20 | -import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | ||
| 21 | import com.google.common.annotations.VisibleForTesting; | 23 | import com.google.common.annotations.VisibleForTesting; |
| 22 | -import lombok.extern.slf4j.Slf4j; | ||
| 23 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
| 24 | import org.springframework.util.Assert; | 25 | import org.springframework.util.Assert; |
| 25 | 26 | ||
| @@ -28,36 +29,37 @@ import java.util.List; | @@ -28,36 +29,37 @@ import java.util.List; | ||
| 28 | import java.util.Map; | 29 | import java.util.Map; |
| 29 | import java.util.stream.Collectors; | 30 | import java.util.stream.Collectors; |
| 30 | 31 | ||
| 32 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*; | ||
| 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 32 | -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | ||
| 33 | 34 | ||
| 34 | /** | 35 | /** |
| 35 | - * 短信日志Service实现类 | 36 | + * 短信 Service Core 实现 |
| 36 | * | 37 | * |
| 37 | - * @author zzf | ||
| 38 | - * @date 2021/1/25 9:25 | 38 | + * @author 芋道源码 |
| 39 | */ | 39 | */ |
| 40 | @Service | 40 | @Service |
| 41 | -@Slf4j | ||
| 42 | -public class SysSmsServiceImpl implements SysSmsService { | 41 | +public class SysSmsCoreServiceImpl implements SysSmsCoreService { |
| 43 | 42 | ||
| 44 | @Resource | 43 | @Resource |
| 45 | - private SysSmsTemplateService smsTemplateService; | 44 | + private SysUserCoreService sysUserCoreService; |
| 46 | @Resource | 45 | @Resource |
| 47 | - private SysSmsLogService smsLogService; | 46 | + private MbrUserCoreService mbrUserCoreService; |
| 48 | @Resource | 47 | @Resource |
| 49 | - private SysSmsProducer smsProducer; | 48 | + private SysSmsTemplateCoreService smsTemplateCoreService; |
| 49 | + @Resource | ||
| 50 | + private SysSmsLogCoreService smsLogCoreService; | ||
| 51 | + | ||
| 50 | @Resource | 52 | @Resource |
| 51 | private SmsClientFactory smsClientFactory; | 53 | private SmsClientFactory smsClientFactory; |
| 52 | 54 | ||
| 53 | @Resource | 55 | @Resource |
| 54 | - private SysUserService userService; | 56 | + private SysSmsCoreProducer smsCoreProducer; |
| 55 | 57 | ||
| 56 | @Override | 58 | @Override |
| 57 | public Long sendSingleSmsToAdmin(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { | 59 | public Long sendSingleSmsToAdmin(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { |
| 58 | // 如果 mobile 为空,则加载用户编号对应的手机号 | 60 | // 如果 mobile 为空,则加载用户编号对应的手机号 |
| 59 | if (StrUtil.isEmpty(mobile)) { | 61 | if (StrUtil.isEmpty(mobile)) { |
| 60 | - SysUserDO user = userService.getUser(userId); | 62 | + SysUserDO user = sysUserCoreService.getUser(userId); |
| 61 | if (user != null) { | 63 | if (user != null) { |
| 62 | mobile = user.getMobile(); | 64 | mobile = user.getMobile(); |
| 63 | } | 65 | } |
| @@ -68,7 +70,15 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -68,7 +70,15 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 68 | 70 | ||
| 69 | @Override | 71 | @Override |
| 70 | public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { | 72 | public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { |
| 71 | - throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!"); | 73 | + // 如果 mobile 为空,则加载用户编号对应的手机号 |
| 74 | + if (StrUtil.isEmpty(mobile)) { | ||
| 75 | + MbrUserDO user = mbrUserCoreService.getUser(userId); | ||
| 76 | + if (user != null) { | ||
| 77 | + mobile = user.getMobile(); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + // 执行发送 | ||
| 81 | + return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); | ||
| 72 | } | 82 | } |
| 73 | 83 | ||
| 74 | @Override | 84 | @Override |
| @@ -83,12 +93,13 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -83,12 +93,13 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 83 | 93 | ||
| 84 | // 创建发送日志 | 94 | // 创建发送日志 |
| 85 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); // 如果模板被禁用,则不发送短信,只记录日志 | 95 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); // 如果模板被禁用,则不发送短信,只记录日志 |
| 86 | - String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams); | ||
| 87 | - Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); | 96 | + String content = smsTemplateCoreService.formatSmsTemplateContent(template.getContent(), templateParams); |
| 97 | + Long sendLogId = smsLogCoreService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); | ||
| 88 | 98 | ||
| 89 | // 发送 MQ 消息,异步执行发送短信 | 99 | // 发送 MQ 消息,异步执行发送短信 |
| 90 | if (isSend) { | 100 | if (isSend) { |
| 91 | - smsProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), template.getApiTemplateId(), newTemplateParams); | 101 | + smsCoreProducer.sendSmsSendMessage(sendLogId, mobile, template.getChannelId(), |
| 102 | + template.getApiTemplateId(), newTemplateParams); | ||
| 92 | } | 103 | } |
| 93 | return sendLogId; | 104 | return sendLogId; |
| 94 | } | 105 | } |
| @@ -102,10 +113,10 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -102,10 +113,10 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 102 | @VisibleForTesting | 113 | @VisibleForTesting |
| 103 | public SysSmsTemplateDO checkSmsTemplateValid(String templateCode) { | 114 | public SysSmsTemplateDO checkSmsTemplateValid(String templateCode) { |
| 104 | // 获得短信模板。考虑到效率,从缓存中获取 | 115 | // 获得短信模板。考虑到效率,从缓存中获取 |
| 105 | - SysSmsTemplateDO template = smsTemplateService.getSmsTemplateByCodeFromCache(templateCode); | 116 | + SysSmsTemplateDO template = smsTemplateCoreService.getSmsTemplateByCodeFromCache(templateCode); |
| 106 | // 短信模板不存在 | 117 | // 短信模板不存在 |
| 107 | if (template == null) { | 118 | if (template == null) { |
| 108 | - throw exception(SMS_TEMPLATE_NOT_EXISTS); | 119 | + throw exception(SMS_SEND_TEMPLATE_NOT_EXISTS); |
| 109 | } | 120 | } |
| 110 | return template; | 121 | return template; |
| 111 | } | 122 | } |
| @@ -138,6 +149,7 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -138,6 +149,7 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 138 | return mobile; | 149 | return mobile; |
| 139 | } | 150 | } |
| 140 | 151 | ||
| 152 | + | ||
| 141 | @Override | 153 | @Override |
| 142 | public void doSendSms(SysSmsSendMessage message) { | 154 | public void doSendSms(SysSmsSendMessage message) { |
| 143 | // 获得渠道对应的 SmsClient 客户端 | 155 | // 获得渠道对应的 SmsClient 客户端 |
| @@ -146,7 +158,7 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -146,7 +158,7 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 146 | // 发送短信 | 158 | // 发送短信 |
| 147 | SmsCommonResult<SmsSendRespDTO> sendResult = smsClient.sendSms(message.getLogId(), message.getMobile(), | 159 | SmsCommonResult<SmsSendRespDTO> sendResult = smsClient.sendSms(message.getLogId(), message.getMobile(), |
| 148 | message.getApiTemplateId(), message.getTemplateParams()); | 160 | message.getApiTemplateId(), message.getTemplateParams()); |
| 149 | - smsLogService.updateSmsSendResult(message.getLogId(), sendResult.getCode(), sendResult.getMsg(), | 161 | + smsLogCoreService.updateSmsSendResult(message.getLogId(), sendResult.getCode(), sendResult.getMsg(), |
| 150 | sendResult.getApiCode(), sendResult.getApiMsg(), sendResult.getApiRequestId(), | 162 | sendResult.getApiCode(), sendResult.getApiMsg(), sendResult.getApiRequestId(), |
| 151 | sendResult.getData() != null ? sendResult.getData().getSerialNo() : null); | 163 | sendResult.getData() != null ? sendResult.getData().getSerialNo() : null); |
| 152 | } | 164 | } |
| @@ -161,11 +173,9 @@ public class SysSmsServiceImpl implements SysSmsService { | @@ -161,11 +173,9 @@ public class SysSmsServiceImpl implements SysSmsService { | ||
| 161 | if (CollUtil.isEmpty(receiveResults)) { | 173 | if (CollUtil.isEmpty(receiveResults)) { |
| 162 | return; | 174 | return; |
| 163 | } | 175 | } |
| 164 | - // 更新短信日志的接收结果. 因为量一般不打,所以先使用 for 循环更新 | ||
| 165 | - receiveResults.forEach(result -> { | ||
| 166 | - smsLogService.updateSmsReceiveResult(result.getLogId(), result.getSuccess(), result.getReceiveTime(), | ||
| 167 | - result.getErrorCode(), result.getErrorCode()); | ||
| 168 | - }); | 176 | + // 更新短信日志的接收结果. 因为量一般不大,所以先使用 for 循环更新 |
| 177 | + receiveResults.forEach(result -> smsLogCoreService.updateSmsReceiveResult(result.getLogId(), | ||
| 178 | + result.getSuccess(), result.getReceiveTime(), result.getErrorCode(), result.getErrorCode())); | ||
| 169 | } | 179 | } |
| 170 | 180 | ||
| 171 | } | 181 | } |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsLogCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsLogCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsLogCoreService; | ||
| 9 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 10 | +import lombok.extern.slf4j.Slf4j; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Date; | ||
| 15 | +import java.util.Map; | ||
| 16 | +import java.util.Objects; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 短信日志 Core Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author zzf | ||
| 22 | + * @date 2021/1/25 9:25 | ||
| 23 | + */ | ||
| 24 | +@Slf4j | ||
| 25 | +@Service | ||
| 26 | +public class SysSmsLogCoreServiceImpl implements SysSmsLogCoreService { | ||
| 27 | + | ||
| 28 | + @Resource | ||
| 29 | + private SysSmsLogCoreMapper smsLogCoreMapper; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend, | ||
| 33 | + SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams) { | ||
| 34 | + SysSmsLogDO.SysSmsLogDOBuilder logBuilder = SysSmsLogDO.builder(); | ||
| 35 | + // 根据是否要发送,设置状态 | ||
| 36 | + logBuilder.sendStatus(Objects.equals(isSend, true) ? SysSmsSendStatusEnum.INIT.getStatus() | ||
| 37 | + : SysSmsSendStatusEnum.IGNORE.getStatus()); | ||
| 38 | + // 设置手机相关字段 | ||
| 39 | + logBuilder.mobile(mobile).userId(userId).userType(userType); | ||
| 40 | + // 设置模板相关字段 | ||
| 41 | + logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); | ||
| 42 | + logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId()); | ||
| 43 | + // 设置渠道相关字段 | ||
| 44 | + logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); | ||
| 45 | + // 设置接收相关字段 | ||
| 46 | + logBuilder.receiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus()); | ||
| 47 | + | ||
| 48 | + // 插入数据库 | ||
| 49 | + SysSmsLogDO logDO = logBuilder.build(); | ||
| 50 | + smsLogCoreMapper.insert(logDO); | ||
| 51 | + return logDO.getId(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg, | ||
| 56 | + String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) { | ||
| 57 | + SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS | ||
| 58 | + : SysSmsSendStatusEnum.FAILURE; | ||
| 59 | + smsLogCoreMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date()) | ||
| 60 | + .sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg) | ||
| 61 | + .apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build()); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg) { | ||
| 66 | + SysSmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? SysSmsReceiveStatusEnum.SUCCESS | ||
| 67 | + : SysSmsReceiveStatusEnum.FAILURE; | ||
| 68 | + smsLogCoreMapper.updateById(SysSmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()).receiveTime(receiveTime) | ||
| 69 | + .apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build()); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsTemplateCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsTemplateCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsTemplateCoreService; | ||
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 9 | +import com.google.common.collect.ImmutableMap; | ||
| 10 | +import lombok.extern.slf4j.Slf4j; | ||
| 11 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | + | ||
| 14 | +import javax.annotation.PostConstruct; | ||
| 15 | +import javax.annotation.Resource; | ||
| 16 | +import java.util.Comparator; | ||
| 17 | +import java.util.Date; | ||
| 18 | +import java.util.List; | ||
| 19 | +import java.util.Map; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 短信模板 Core Service 接口 | ||
| 23 | + * | ||
| 24 | + * @author 芋道源码 | ||
| 25 | + */ | ||
| 26 | +@Service | ||
| 27 | +@Slf4j | ||
| 28 | +public class SysSmsTemplateCoreServiceImpl implements SysSmsTemplateCoreService { | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 定时执行 {@link #schedulePeriodicRefresh()} 的周期 | ||
| 32 | + * 因为已经通过 Redis Pub/Sub 机制,所以频率不需要高 | ||
| 33 | + */ | ||
| 34 | + private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 短信模板缓存 | ||
| 38 | + * key:短信模板编码 {@link SysSmsTemplateDO#getCode()} | ||
| 39 | + * | ||
| 40 | + * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 | ||
| 41 | + */ | ||
| 42 | + private volatile Map<String, SysSmsTemplateDO> smsTemplateCache; | ||
| 43 | + /** | ||
| 44 | + * 缓存短信模板的最大更新时间,用于后续的增量轮询,判断是否有更新 | ||
| 45 | + */ | ||
| 46 | + private volatile Date maxUpdateTime; | ||
| 47 | + | ||
| 48 | + @Resource | ||
| 49 | + private SysSmsTemplateCoreMapper smsTemplateCoreMapper; | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + @PostConstruct | ||
| 53 | + public void initLocalCache() { | ||
| 54 | + // 获取短信模板列表,如果有更新 | ||
| 55 | + List<SysSmsTemplateDO> smsTemplateList = this.loadSmsTemplateIfUpdate(maxUpdateTime); | ||
| 56 | + if (CollUtil.isEmpty(smsTemplateList)) { | ||
| 57 | + return; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + // 写入缓存 | ||
| 61 | + ImmutableMap.Builder<String, SysSmsTemplateDO> builder = ImmutableMap.builder(); | ||
| 62 | + smsTemplateList.forEach(sysSmsTemplateDO -> builder.put(sysSmsTemplateDO.getCode(), sysSmsTemplateDO)); | ||
| 63 | + smsTemplateCache = builder.build(); | ||
| 64 | + assert smsTemplateList.size() > 0; // 断言,避免告警 | ||
| 65 | + maxUpdateTime = smsTemplateList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime(); | ||
| 66 | + log.info("[initLocalCache][初始化 SmsTemplate 数量为 {}]", smsTemplateList.size()); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 如果短信模板发生变化,从数据库中获取最新的全量短信模板。 | ||
| 71 | + * 如果未发生变化,则返回空 | ||
| 72 | + * | ||
| 73 | + * @param maxUpdateTime 当前短信模板的最大更新时间 | ||
| 74 | + * @return 短信模板列表 | ||
| 75 | + */ | ||
| 76 | + private List<SysSmsTemplateDO> loadSmsTemplateIfUpdate(Date maxUpdateTime) { | ||
| 77 | + // 第一步,判断是否要更新。 | ||
| 78 | + if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 | ||
| 79 | + log.info("[loadSmsTemplateIfUpdate][首次加载全量短信模板]"); | ||
| 80 | + } else { // 判断数据库中是否有更新的短信模板 | ||
| 81 | + if (smsTemplateCoreMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) { | ||
| 82 | + return null; | ||
| 83 | + } | ||
| 84 | + log.info("[loadSmsTemplateIfUpdate][增量加载全量短信模板]"); | ||
| 85 | + } | ||
| 86 | + // 第二步,如果有更新,则从数据库加载所有短信模板 | ||
| 87 | + return smsTemplateCoreMapper.selectList(); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) | ||
| 91 | + public void schedulePeriodicRefresh() { | ||
| 92 | + initLocalCache(); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public SysSmsTemplateDO getSmsTemplateByCodeFromCache(String code) { | ||
| 97 | + return smsTemplateCache.get(code); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Override | ||
| 101 | + public String formatSmsTemplateContent(String content, Map<String, Object> params) { | ||
| 102 | + return StrUtil.format(content, params); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/SysUserCoreService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 后台用户 Service Core 接口 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public interface SysUserCoreService { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 通过用户 ID 查询用户 | ||
| 14 | + * | ||
| 15 | + * @param id 用户ID | ||
| 16 | + * @return 用户对象信息 | ||
| 17 | + */ | ||
| 18 | + SysUserDO getUser(Long id); | ||
| 19 | + | ||
| 20 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/user/impl/SysUserCoreServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.user.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.user.SysUserCoreMapper; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import javax.annotation.Resource; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 后台用户 Service Core 实现 | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@Service | ||
| 16 | +public class SysUserCoreServiceImpl implements SysUserCoreService { | ||
| 17 | + | ||
| 18 | + @Resource | ||
| 19 | + private SysUserCoreMapper userCoreMapper; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public SysUserDO getUser(Long id) { | ||
| 23 | + return userCoreMapper.selectById(id); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | +} |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/tool/package-info.java
0 → 100644
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbAndRedisUnitTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.config.RedisTestConfiguration; | ||
| 4 | +import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; | ||
| 6 | +import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | ||
| 7 | +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; | ||
| 8 | +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; | ||
| 9 | +import org.redisson.spring.starter.RedissonAutoConfiguration; | ||
| 10 | +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||
| 11 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 12 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | ||
| 13 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 14 | +import org.springframework.context.annotation.Import; | ||
| 15 | +import org.springframework.test.context.ActiveProfiles; | ||
| 16 | +import org.springframework.test.context.jdbc.Sql; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 依赖内存 DB + Redis 的单元测试 | ||
| 20 | + * | ||
| 21 | + * 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis | ||
| 22 | + * | ||
| 23 | + * @author 芋道源码 | ||
| 24 | + */ | ||
| 25 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisUnitTest.Application.class) | ||
| 26 | +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 | ||
| 27 | +@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB | ||
| 28 | +public class BaseDbAndRedisUnitTest { | ||
| 29 | + | ||
| 30 | + @Import({ | ||
| 31 | + // DB 配置类 | ||
| 32 | + YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类 | ||
| 33 | + DataSourceAutoConfiguration.class, // Spring DB 自动配置类 | ||
| 34 | + DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类 | ||
| 35 | + DruidDataSourceAutoConfigure.class, // Druid 自动配置类 | ||
| 36 | + // MyBatis 配置类 | ||
| 37 | + YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类 | ||
| 38 | + MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 | ||
| 39 | + // Redis 配置类 | ||
| 40 | + RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer | ||
| 41 | + RedisAutoConfiguration.class, // Spring Redis 自动配置类 | ||
| 42 | + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 | ||
| 43 | + RedissonAutoConfiguration.class, // Redisson 自动高配置类 | ||
| 44 | + }) | ||
| 45 | + public static class Application { | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseDbUnitTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; | ||
| 5 | +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; | ||
| 6 | +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; | ||
| 7 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 8 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | ||
| 9 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 10 | +import org.springframework.context.annotation.Import; | ||
| 11 | +import org.springframework.test.context.ActiveProfiles; | ||
| 12 | +import org.springframework.test.context.jdbc.Sql; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 依赖内存 DB 的单元测试 | ||
| 16 | + * | ||
| 17 | + * 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法 | ||
| 18 | + * | ||
| 19 | + * @author 芋道源码 | ||
| 20 | + */ | ||
| 21 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbUnitTest.Application.class) | ||
| 22 | +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 | ||
| 23 | +@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB | ||
| 24 | +public class BaseDbUnitTest { | ||
| 25 | + | ||
| 26 | + @Import({ | ||
| 27 | + // DB 配置类 | ||
| 28 | + YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类 | ||
| 29 | + DataSourceAutoConfiguration.class, // Spring DB 自动配置类 | ||
| 30 | + DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类 | ||
| 31 | + DruidDataSourceAutoConfigure.class, // Druid 自动配置类 | ||
| 32 | + // MyBatis 配置类 | ||
| 33 | + YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类 | ||
| 34 | + MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 | ||
| 35 | + }) | ||
| 36 | + public static class Application { | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/BaseRedisUnitTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.config.RedisTestConfiguration; | ||
| 4 | +import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | ||
| 5 | +import org.redisson.spring.starter.RedissonAutoConfiguration; | ||
| 6 | +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; | ||
| 7 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 8 | +import org.springframework.context.annotation.Import; | ||
| 9 | +import org.springframework.test.context.ActiveProfiles; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 依赖内存 Redis 的单元测试 | ||
| 13 | + * | ||
| 14 | + * 相比 {@link BaseDbUnitTest} 来说,从内存 DB 改成了内存 Redis | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisUnitTest.Application.class) | ||
| 19 | +@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件 | ||
| 20 | +public class BaseRedisUnitTest { | ||
| 21 | + | ||
| 22 | + @Import({ | ||
| 23 | + // Redis 配置类 | ||
| 24 | + RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer | ||
| 25 | + RedisAutoConfiguration.class, // Spring Redis 自动配置类 | ||
| 26 | + YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类 | ||
| 27 | + RedissonAutoConfiguration.class, // Redisson 自动高配置类 | ||
| 28 | + }) | ||
| 29 | + public static class Application { | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/config/RedisTestConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.config; | ||
| 2 | + | ||
| 3 | +import com.github.fppt.jedismock.RedisServer; | ||
| 4 | +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
| 5 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| 6 | +import org.springframework.context.annotation.Bean; | ||
| 7 | +import org.springframework.context.annotation.Configuration; | ||
| 8 | +import org.springframework.context.annotation.Lazy; | ||
| 9 | + | ||
| 10 | +import java.io.IOException; | ||
| 11 | + | ||
| 12 | +@Configuration(proxyBeanMethods = false) | ||
| 13 | +@Lazy(false) // 禁止延迟加载 | ||
| 14 | +@EnableConfigurationProperties(RedisProperties.class) | ||
| 15 | +public class RedisTestConfiguration { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 创建模拟的 Redis Server 服务器 | ||
| 19 | + */ | ||
| 20 | + @Bean | ||
| 21 | + public RedisServer redisServer(RedisProperties properties) throws IOException { | ||
| 22 | + RedisServer redisServer = new RedisServer(properties.getPort()); | ||
| 23 | + // TODO 芋艿:一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样,就导致端口被占用,无法启动。。。 | ||
| 24 | + try { | ||
| 25 | + redisServer.start(); | ||
| 26 | + } catch (Exception ignore) {} | ||
| 27 | + return redisServer; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiAccessLogCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.RandomUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiAccessLogCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl.InfApiAccessLogCoreServiceImpl; | ||
| 8 | +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||
| 9 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 10 | +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 11 | +import org.junit.jupiter.api.Test; | ||
| 12 | +import org.springframework.context.annotation.Import; | ||
| 13 | + | ||
| 14 | +import javax.annotation.Resource; | ||
| 15 | +import java.util.concurrent.Future; | ||
| 16 | + | ||
| 17 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 18 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * {@link InfApiAccessLogCoreServiceImpl} 单元测试 | ||
| 22 | + */ | ||
| 23 | +@Import(InfApiAccessLogCoreServiceImpl.class) | ||
| 24 | +public class InfApiAccessLogCoreServiceTest extends BaseDbUnitTest { | ||
| 25 | + | ||
| 26 | + @Resource | ||
| 27 | + private InfApiAccessLogCoreService apiAccessLogCoreService; | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private InfApiAccessLogCoreMapper apiAccessLogCoreMapper; | ||
| 31 | + | ||
| 32 | + @Test | ||
| 33 | + public void testCreateApiAccessLogAsync() { | ||
| 34 | + // 准备参数 | ||
| 35 | + ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(ApiAccessLogCreateDTO.class, | ||
| 36 | + dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())); | ||
| 37 | + | ||
| 38 | + // 调用 | ||
| 39 | + apiAccessLogCoreService.createApiAccessLogAsync(createDTO); | ||
| 40 | + // 断言 | ||
| 41 | + InfApiAccessLogDO infApiAccessLogDO = apiAccessLogCoreMapper.selectOne(null); | ||
| 42 | + assertNotNull(infApiAccessLogDO); | ||
| 43 | + assertPojoEquals(createDTO, infApiAccessLogDO); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/logger/InfApiErrorLogCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.logger; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.RandomUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.logger.InfApiErrorLogCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.service.logger.impl.InfApiErrorLogCoreServiceImpl; | ||
| 8 | +import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||
| 9 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 10 | +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 11 | +import org.junit.jupiter.api.Test; | ||
| 12 | +import org.springframework.context.annotation.Import; | ||
| 13 | + | ||
| 14 | +import javax.annotation.Resource; | ||
| 15 | + | ||
| 16 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 17 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * {@link InfApiErrorLogCoreServiceImpl} 单元测试 | ||
| 21 | + */ | ||
| 22 | +@Import(InfApiErrorLogCoreServiceImpl.class) | ||
| 23 | +public class InfApiErrorLogCoreServiceTest extends BaseDbUnitTest { | ||
| 24 | + | ||
| 25 | + @Resource | ||
| 26 | + private InfApiErrorLogCoreService apiErrorLogCoreService; | ||
| 27 | + | ||
| 28 | + @Resource | ||
| 29 | + private InfApiErrorLogCoreMapper infApiErrorLogCoreMapper; | ||
| 30 | + | ||
| 31 | + @Test | ||
| 32 | + public void testCreateApiErrorLogAsync() { | ||
| 33 | + // 准备参数 | ||
| 34 | + ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo(ApiErrorLogCreateDTO.class, | ||
| 35 | + dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())); | ||
| 36 | + | ||
| 37 | + // 调用 | ||
| 38 | + apiErrorLogCoreService.createApiErrorLogAsync(createDTO); | ||
| 39 | + // 断言 | ||
| 40 | + InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogCoreMapper.selectOne(null); | ||
| 41 | + assertNotNull(infApiErrorLogDO); | ||
| 42 | + assertPojoEquals(createDTO, infApiErrorLogDO); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service; |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/auth/SysUserSessionCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.auth; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.BaseDbAndRedisUnitTest; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.auth.SysUserSessionDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.auth.SysUserSessionCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.redis.auth.SysLoginUserCoreRedisDAO; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.impl.SysUserSessionCoreServiceImpl; | ||
| 8 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 9 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | ||
| 10 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 11 | +import org.junit.jupiter.api.Test; | ||
| 12 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 13 | +import org.springframework.context.annotation.Import; | ||
| 14 | + | ||
| 15 | +import javax.annotation.Resource; | ||
| 16 | +import java.time.Duration; | ||
| 17 | +import java.util.Date; | ||
| 18 | + | ||
| 19 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; | ||
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 23 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 24 | +import static org.mockito.Mockito.when; | ||
| 25 | + | ||
| 26 | +@Import({SysUserSessionCoreServiceImpl.class, SysLoginUserCoreRedisDAO.class}) | ||
| 27 | +public class SysUserSessionCoreServiceTest extends BaseDbAndRedisUnitTest { | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private SysUserSessionCoreServiceImpl userSessionCoreService; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private SysUserSessionCoreMapper userSessionCoreMapper; | ||
| 34 | + @Resource | ||
| 35 | + private SysLoginUserCoreRedisDAO loginUserCoreRedisDAO; | ||
| 36 | + | ||
| 37 | + @MockBean | ||
| 38 | + private SecurityProperties securityProperties; | ||
| 39 | + | ||
| 40 | + @Test | ||
| 41 | + public void testCreateUserSession_success() { | ||
| 42 | + // 准备参数 | ||
| 43 | + String userIp = randomString(); | ||
| 44 | + String userAgent = randomString(); | ||
| 45 | + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); | ||
| 46 | + // mock 方法 | ||
| 47 | + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 48 | + | ||
| 49 | + // 调用 | ||
| 50 | + String sessionId = userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | ||
| 51 | + // 校验 SysUserSessionDO 记录 | ||
| 52 | + SysUserSessionDO userSessionDO = userSessionCoreMapper.selectById(sessionId); | ||
| 53 | + assertPojoEquals(loginUser, userSessionDO, "id", "updateTime"); | ||
| 54 | + assertEquals(sessionId, userSessionDO.getId()); | ||
| 55 | + assertEquals(userIp, userSessionDO.getUserIp()); | ||
| 56 | + assertEquals(userAgent, userSessionDO.getUserAgent()); | ||
| 57 | + // 校验 LoginUser 缓存 | ||
| 58 | + LoginUser redisLoginUser = loginUserCoreRedisDAO.get(sessionId); | ||
| 59 | + assertPojoEquals(loginUser, redisLoginUser, "username", "password"); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Test | ||
| 63 | + public void testCreateRefreshUserSession_success() { | ||
| 64 | + // 准备参数 | ||
| 65 | + String sessionId = randomString(); | ||
| 66 | + String userIp = randomString(); | ||
| 67 | + String userAgent = randomString(); | ||
| 68 | + long timeLong = randomLongId(); | ||
| 69 | + String userName = randomString(); | ||
| 70 | + Date date = randomDate(); | ||
| 71 | + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); | ||
| 72 | + // mock 方法 | ||
| 73 | + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 74 | + // mock 数据 | ||
| 75 | + loginUser.setUpdateTime(date); | ||
| 76 | + loginUserCoreRedisDAO.set(sessionId, loginUser); | ||
| 77 | + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 78 | + .userId(loginUser.getId()).userType(loginUser.getUserType()) | ||
| 79 | + .userIp(userIp).userAgent(userAgent).username(userName) | ||
| 80 | + .sessionTimeout(addTime(Duration.ofMillis(timeLong))) | ||
| 81 | + .build(); | ||
| 82 | + userSessionCoreMapper.insert(userSession); | ||
| 83 | + | ||
| 84 | + // 调用 | ||
| 85 | + userSessionCoreService.refreshUserSession(sessionId, loginUser); | ||
| 86 | + // 校验 LoginUser 缓存 | ||
| 87 | + LoginUser redisLoginUser = loginUserCoreRedisDAO.get(sessionId); | ||
| 88 | + assertNotEquals(redisLoginUser.getUpdateTime(), date); | ||
| 89 | + // 校验 SysUserSessionDO 记录 | ||
| 90 | + SysUserSessionDO updateDO = userSessionCoreMapper.selectById(sessionId); | ||
| 91 | + assertEquals(updateDO.getUsername(), loginUser.getUsername()); | ||
| 92 | + assertNotEquals(updateDO.getUpdateTime(), userSession.getUpdateTime()); | ||
| 93 | + assertNotEquals(updateDO.getSessionTimeout(), addTime(Duration.ofMillis(timeLong))); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Test | ||
| 97 | + public void testDeleteUserSession_success() { | ||
| 98 | + // 准备参数 | ||
| 99 | + String sessionId = randomString(); | ||
| 100 | + String userIp = randomString(); | ||
| 101 | + String userAgent = randomString(); | ||
| 102 | + Long timeLong = randomLongId(); | ||
| 103 | + LoginUser loginUser = randomPojo(LoginUser.class, o -> o.setUserType(randomEle(UserTypeEnum.values()).getValue())); | ||
| 104 | + // mock 存入 Redis | ||
| 105 | + when(securityProperties.getSessionTimeout()).thenReturn(Duration.ofDays(1)); | ||
| 106 | + // mock 数据 | ||
| 107 | + loginUserCoreRedisDAO.set(sessionId, loginUser); | ||
| 108 | + SysUserSessionDO userSession = SysUserSessionDO.builder().id(sessionId) | ||
| 109 | + .userId(loginUser.getId()).userType(loginUser.getUserType()) | ||
| 110 | + .userIp(userIp).userAgent(userAgent).username(loginUser.getUsername()) | ||
| 111 | + .sessionTimeout(addTime(Duration.ofMillis(timeLong))) | ||
| 112 | + .build(); | ||
| 113 | + userSessionCoreMapper.insert(userSession); | ||
| 114 | + | ||
| 115 | + // 调用 | ||
| 116 | + userSessionCoreService.deleteUserSession(sessionId); | ||
| 117 | + // 校验数据不存在了 | ||
| 118 | + assertNull(loginUserCoreRedisDAO.get(sessionId)); | ||
| 119 | + assertNull(userSessionCoreMapper.selectById(sessionId)); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/dict/SysDictDataCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.dict; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.dict.SysDictDataCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.service.dict.impl.SysDictDataCoreServiceImpl; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 8 | +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 9 | +import com.google.common.collect.ImmutableTable; | ||
| 10 | +import org.junit.jupiter.api.Test; | ||
| 11 | +import org.springframework.context.annotation.Import; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Date; | ||
| 15 | +import java.util.function.Consumer; | ||
| 16 | + | ||
| 17 | +import static cn.hutool.core.bean.BeanUtil.getFieldValue; | ||
| 18 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 19 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomCommonStatus; | ||
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | +* {@link SysDictDataCoreServiceImpl} 的单元测试类 | ||
| 25 | +* | ||
| 26 | +* @author 芋道源码 | ||
| 27 | +*/ | ||
| 28 | +@Import(SysDictDataCoreServiceImpl.class) | ||
| 29 | +public class SysDictDataCoreServiceTest extends BaseDbUnitTest { | ||
| 30 | + | ||
| 31 | + @Resource | ||
| 32 | + private SysDictDataCoreServiceImpl dictDataCoreService; | ||
| 33 | + | ||
| 34 | + @Resource | ||
| 35 | + private SysDictDataCoreMapper dictDataMapper; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 测试加载到新的字典数据的情况 | ||
| 39 | + */ | ||
| 40 | + @Test | ||
| 41 | + @SuppressWarnings("unchecked") | ||
| 42 | + public void testInitLocalCache() { | ||
| 43 | + // mock 数据 | ||
| 44 | + SysDictDataDO dictData01 = randomDictDataDO(); | ||
| 45 | + dictDataMapper.insert(dictData01); | ||
| 46 | + SysDictDataDO dictData02 = randomDictDataDO(); | ||
| 47 | + dictDataMapper.insert(dictData02); | ||
| 48 | + | ||
| 49 | + // 调用 | ||
| 50 | + dictDataCoreService.initLocalCache(); | ||
| 51 | + // 断言 labelDictDataCache 缓存 | ||
| 52 | + ImmutableTable<String, String, SysDictDataDO> labelDictDataCache = | ||
| 53 | + (ImmutableTable<String, String, SysDictDataDO>) getFieldValue(dictDataCoreService, "labelDictDataCache"); | ||
| 54 | + assertEquals(2, labelDictDataCache.size()); | ||
| 55 | + assertPojoEquals(dictData01, labelDictDataCache.get(dictData01.getDictType(), dictData01.getLabel())); | ||
| 56 | + assertPojoEquals(dictData02, labelDictDataCache.get(dictData02.getDictType(), dictData02.getLabel())); | ||
| 57 | + // 断言 valueDictDataCache 缓存 | ||
| 58 | + ImmutableTable<String, String, SysDictDataDO> valueDictDataCache = | ||
| 59 | + (ImmutableTable<String, String, SysDictDataDO>) getFieldValue(dictDataCoreService, "valueDictDataCache"); | ||
| 60 | + assertEquals(2, valueDictDataCache.size()); | ||
| 61 | + assertPojoEquals(dictData01, valueDictDataCache.get(dictData01.getDictType(), dictData01.getValue())); | ||
| 62 | + assertPojoEquals(dictData02, valueDictDataCache.get(dictData02.getDictType(), dictData02.getValue())); | ||
| 63 | + // 断言 maxUpdateTime 缓存 | ||
| 64 | + Date maxUpdateTime = (Date) getFieldValue(dictDataCoreService, "maxUpdateTime"); | ||
| 65 | + assertEquals(ObjectUtils.max(dictData01.getUpdateTime(), dictData02.getUpdateTime()), maxUpdateTime); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + // ========== 随机对象 ========== | ||
| 69 | + | ||
| 70 | + @SafeVarargs | ||
| 71 | + private static SysDictDataDO randomDictDataDO(Consumer<SysDictDataDO>... consumers) { | ||
| 72 | + Consumer<SysDictDataDO> consumer = (o) -> { | ||
| 73 | + o.setStatus(randomCommonStatus()); // 保证 status 的范围 | ||
| 74 | + }; | ||
| 75 | + return randomPojo(SysDictDataDO.class, ArrayUtils.append(consumer, consumers)); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/logger/SysLoginLogServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.logger; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.logger.SysLoginLogDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.logger.SysLoginLogCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.impl.SysLoginLogCoreServiceImpl; | ||
| 10 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 11 | +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 12 | +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 13 | +import org.junit.jupiter.api.Test; | ||
| 14 | +import org.springframework.context.annotation.Import; | ||
| 15 | + | ||
| 16 | +import javax.annotation.Resource; | ||
| 17 | + | ||
| 18 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 19 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 20 | + | ||
| 21 | +@Import(SysLoginLogCoreServiceImpl.class) | ||
| 22 | +public class SysLoginLogServiceImplTest extends BaseDbUnitTest { | ||
| 23 | + | ||
| 24 | + @Resource | ||
| 25 | + private SysLoginLogCoreServiceImpl loginLogCoreService; | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private SysLoginLogCoreMapper loginLogCoreMapper; | ||
| 29 | + | ||
| 30 | + @Test | ||
| 31 | + public void testCreateLoginLog() { | ||
| 32 | + SysLoginLogCreateReqDTO reqDTO = RandomUtils.randomPojo(SysLoginLogCreateReqDTO.class, vo -> { | ||
| 33 | + // 指定随机的范围,避免超出范围入库失败 | ||
| 34 | + vo.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 35 | + vo.setLogType(randomEle(SysLoginLogTypeEnum.values()).getType()); | ||
| 36 | + vo.setResult(randomEle(SysLoginResultEnum.values()).getResult()); | ||
| 37 | + vo.setTraceId(TracerUtils.getTraceId()); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + // 调用 | ||
| 41 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 42 | + // 断言,忽略基本字段 | ||
| 43 | + SysLoginLogDO sysLoginLogDO = loginLogCoreMapper.selectOne(null); | ||
| 44 | + assertPojoEquals(reqDTO, sysLoginLogDO); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service; |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceTest.java renamed to yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsCoreServiceTest.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.service.sms; | 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.mq.producer.sms.SysSmsCoreProducer; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsCoreServiceImpl; | ||
| 4 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 8 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 9 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 10 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| @@ -9,10 +13,6 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | @@ -9,10 +13,6 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 9 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | 13 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; |
| 10 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; | 14 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 11 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; | 15 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; |
| 12 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 13 | -import cn.iocoder.yudao.adminserver.modules.system.mq.message.sms.SysSmsSendMessage; | ||
| 14 | -import cn.iocoder.yudao.adminserver.modules.system.mq.producer.sms.SysSmsProducer; | ||
| 15 | -import cn.iocoder.yudao.adminserver.modules.system.service.sms.impl.SysSmsServiceImpl; | ||
| 16 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 16 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 17 | import org.assertj.core.util.Lists; | 17 | import org.assertj.core.util.Lists; |
| 18 | import org.junit.jupiter.api.Test; | 18 | import org.junit.jupiter.api.Test; |
| @@ -24,7 +24,7 @@ import java.util.List; | @@ -24,7 +24,7 @@ import java.util.List; | ||
| 24 | import java.util.Map; | 24 | import java.util.Map; |
| 25 | 25 | ||
| 26 | import static cn.hutool.core.util.RandomUtil.randomEle; | 26 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 27 | -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 27 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*; |
| 28 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 28 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 29 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 29 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 30 | import static org.junit.jupiter.api.Assertions.assertEquals; | 30 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| @@ -32,21 +32,21 @@ import static org.mockito.ArgumentMatchers.eq; | @@ -32,21 +32,21 @@ import static org.mockito.ArgumentMatchers.eq; | ||
| 32 | import static org.mockito.Mockito.*; | 32 | import static org.mockito.Mockito.*; |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | - * {@link SysSmsServiceImpl} 的单元测试类 | 35 | + * {@link SysSmsCoreService} 的单元测试类 |
| 36 | * | 36 | * |
| 37 | * @author 芋道源码 | 37 | * @author 芋道源码 |
| 38 | */ | 38 | */ |
| 39 | -public class SysSmsServiceTest extends BaseMockitoUnitTest { | 39 | +public class SysSmsCoreServiceTest extends BaseMockitoUnitTest { |
| 40 | 40 | ||
| 41 | @InjectMocks | 41 | @InjectMocks |
| 42 | - private SysSmsServiceImpl smsService; | 42 | + private SysSmsCoreServiceImpl smsCoreService; |
| 43 | 43 | ||
| 44 | @Mock | 44 | @Mock |
| 45 | - private SysSmsTemplateService smsTemplateService; | 45 | + private SysSmsTemplateCoreService smsTemplateCoreService; |
| 46 | @Mock | 46 | @Mock |
| 47 | - private SysSmsLogService smsLogService; | 47 | + private SysSmsLogCoreService smsLogCoreService; |
| 48 | @Mock | 48 | @Mock |
| 49 | - private SysSmsProducer smsProducer; | 49 | + private SysSmsCoreProducer smsCoreProducer; |
| 50 | @Mock | 50 | @Mock |
| 51 | private SmsClientFactory smsClientFactory; | 51 | private SmsClientFactory smsClientFactory; |
| 52 | 52 | ||
| @@ -68,21 +68,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -68,21 +68,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 68 | o.setContent("验证码为{code}, 操作为{op}"); | 68 | o.setContent("验证码为{code}, 操作为{op}"); |
| 69 | o.setParams(Lists.newArrayList("code", "op")); | 69 | o.setParams(Lists.newArrayList("code", "op")); |
| 70 | }); | 70 | }); |
| 71 | - when(smsTemplateService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | 71 | + when(smsTemplateCoreService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); |
| 72 | String content = randomString(); | 72 | String content = randomString(); |
| 73 | - when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) | 73 | + when(smsTemplateCoreService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) |
| 74 | .thenReturn(content); | 74 | .thenReturn(content); |
| 75 | // mock SmsLogService 的方法 | 75 | // mock SmsLogService 的方法 |
| 76 | Long smsLogId = randomLongId(); | 76 | Long smsLogId = randomLongId(); |
| 77 | - when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template), | 77 | + when(smsLogCoreService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template), |
| 78 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 78 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 79 | 79 | ||
| 80 | // 调用 | 80 | // 调用 |
| 81 | - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); | 81 | + Long resultSmsLogId = smsCoreService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); |
| 82 | // 断言 | 82 | // 断言 |
| 83 | assertEquals(smsLogId, resultSmsLogId); | 83 | assertEquals(smsLogId, resultSmsLogId); |
| 84 | // 断言调用 | 84 | // 断言调用 |
| 85 | - verify(smsProducer, times(1)).sendSmsSendMessage(eq(smsLogId), eq(mobile), | 85 | + verify(smsCoreProducer, times(1)).sendSmsSendMessage(eq(smsLogId), eq(mobile), |
| 86 | eq(template.getChannelId()), eq(template.getApiTemplateId()), | 86 | eq(template.getChannelId()), eq(template.getApiTemplateId()), |
| 87 | eq(Lists.newArrayList(new KeyValue<>("code", "1234"), new KeyValue<>("op", "login")))); | 87 | eq(Lists.newArrayList(new KeyValue<>("code", "1234"), new KeyValue<>("op", "login")))); |
| 88 | } | 88 | } |
| @@ -105,21 +105,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -105,21 +105,21 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 105 | o.setContent("验证码为{code}, 操作为{op}"); | 105 | o.setContent("验证码为{code}, 操作为{op}"); |
| 106 | o.setParams(Lists.newArrayList("code", "op")); | 106 | o.setParams(Lists.newArrayList("code", "op")); |
| 107 | }); | 107 | }); |
| 108 | - when(smsTemplateService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | 108 | + when(smsTemplateCoreService.getSmsTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); |
| 109 | String content = randomString(); | 109 | String content = randomString(); |
| 110 | - when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) | 110 | + when(smsTemplateCoreService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) |
| 111 | .thenReturn(content); | 111 | .thenReturn(content); |
| 112 | // mock SmsLogService 的方法 | 112 | // mock SmsLogService 的方法 |
| 113 | Long smsLogId = randomLongId(); | 113 | Long smsLogId = randomLongId(); |
| 114 | - when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template), | 114 | + when(smsLogCoreService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template), |
| 115 | eq(content), eq(templateParams))).thenReturn(smsLogId); | 115 | eq(content), eq(templateParams))).thenReturn(smsLogId); |
| 116 | 116 | ||
| 117 | // 调用 | 117 | // 调用 |
| 118 | - Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); | 118 | + Long resultSmsLogId = smsCoreService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); |
| 119 | // 断言 | 119 | // 断言 |
| 120 | assertEquals(smsLogId, resultSmsLogId); | 120 | assertEquals(smsLogId, resultSmsLogId); |
| 121 | // 断言调用 | 121 | // 断言调用 |
| 122 | - verify(smsProducer, times(0)).sendSmsSendMessage(anyLong(), anyString(), | 122 | + verify(smsCoreProducer, times(0)).sendSmsSendMessage(anyLong(), anyString(), |
| 123 | anyLong(), any(), anyList()); | 123 | anyLong(), any(), anyList()); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| @@ -130,8 +130,8 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -130,8 +130,8 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 130 | // mock 方法 | 130 | // mock 方法 |
| 131 | 131 | ||
| 132 | // 调用,并断言异常 | 132 | // 调用,并断言异常 |
| 133 | - assertServiceException(() -> smsService.checkSmsTemplateValid(templateCode), | ||
| 134 | - SMS_TEMPLATE_NOT_EXISTS); | 133 | + assertServiceException(() -> smsCoreService.checkSmsTemplateValid(templateCode), |
| 134 | + SMS_SEND_TEMPLATE_NOT_EXISTS); | ||
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | @Test | 137 | @Test |
| @@ -143,7 +143,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -143,7 +143,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 143 | // mock 方法 | 143 | // mock 方法 |
| 144 | 144 | ||
| 145 | // 调用,并断言异常 | 145 | // 调用,并断言异常 |
| 146 | - assertServiceException(() -> smsService.buildTemplateParams(template, templateParams), | 146 | + assertServiceException(() -> smsCoreService.buildTemplateParams(template, templateParams), |
| 147 | SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code"); | 147 | SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code"); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| @@ -153,7 +153,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -153,7 +153,7 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 153 | // mock 方法 | 153 | // mock 方法 |
| 154 | 154 | ||
| 155 | // 调用,并断言异常 | 155 | // 调用,并断言异常 |
| 156 | - assertServiceException(() -> smsService.checkMobile(null), | 156 | + assertServiceException(() -> smsCoreService.checkMobile(null), |
| 157 | SMS_SEND_MOBILE_NOT_EXISTS); | 157 | SMS_SEND_MOBILE_NOT_EXISTS); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| @@ -171,9 +171,9 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -171,9 +171,9 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 171 | eq(message.getTemplateParams()))).thenReturn(sendResult); | 171 | eq(message.getTemplateParams()))).thenReturn(sendResult); |
| 172 | 172 | ||
| 173 | // 调用 | 173 | // 调用 |
| 174 | - smsService.doSendSms(message); | 174 | + smsCoreService.doSendSms(message); |
| 175 | // 断言 | 175 | // 断言 |
| 176 | - verify(smsLogService, times(1)).updateSmsSendResult(eq(message.getLogId()), | 176 | + verify(smsLogCoreService, times(1)).updateSmsSendResult(eq(message.getLogId()), |
| 177 | eq(sendResult.getCode()), eq(sendResult.getMsg()), eq(sendResult.getApiCode()), | 177 | eq(sendResult.getCode()), eq(sendResult.getMsg()), eq(sendResult.getApiCode()), |
| 178 | eq(sendResult.getApiMsg()), eq(sendResult.getApiRequestId()), eq(sendResult.getData().getSerialNo())); | 178 | eq(sendResult.getApiMsg()), eq(sendResult.getApiRequestId()), eq(sendResult.getData().getSerialNo())); |
| 179 | } | 179 | } |
| @@ -190,12 +190,10 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | @@ -190,12 +190,10 @@ public class SysSmsServiceTest extends BaseMockitoUnitTest { | ||
| 190 | List<SmsReceiveRespDTO> receiveResults = randomPojoList(SmsReceiveRespDTO.class); | 190 | List<SmsReceiveRespDTO> receiveResults = randomPojoList(SmsReceiveRespDTO.class); |
| 191 | 191 | ||
| 192 | // 调用 | 192 | // 调用 |
| 193 | - smsService.receiveSmsStatus(channelCode, text); | 193 | + smsCoreService.receiveSmsStatus(channelCode, text); |
| 194 | // 断言 | 194 | // 断言 |
| 195 | - receiveResults.forEach(result -> { | ||
| 196 | - smsLogService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), | ||
| 197 | - eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode())); | ||
| 198 | - }); | 195 | + receiveResults.forEach(result -> smsLogCoreService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()), |
| 196 | + eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode()))); | ||
| 199 | } | 197 | } |
| 200 | 198 | ||
| 201 | } | 199 | } |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsLogCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.map.MapUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsLogDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsLogCoreMapper; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsReceiveStatusEnum; | ||
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsSendStatusEnum; | ||
| 10 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsLogCoreServiceImpl; | ||
| 12 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 13 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 14 | +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 15 | +import org.junit.jupiter.api.Test; | ||
| 16 | +import org.springframework.context.annotation.Import; | ||
| 17 | + | ||
| 18 | +import javax.annotation.Resource; | ||
| 19 | +import java.util.Date; | ||
| 20 | +import java.util.Map; | ||
| 21 | +import java.util.function.Consumer; | ||
| 22 | + | ||
| 23 | +import static cn.hutool.core.util.RandomUtil.randomBoolean; | ||
| 24 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 25 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | ||
| 26 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 27 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | +* {@link SysSmsLogCoreServiceImpl} 的单元测试类 | ||
| 31 | +* | ||
| 32 | +* @author 芋道源码 | ||
| 33 | +*/ | ||
| 34 | +@Import(SysSmsLogCoreServiceImpl.class) | ||
| 35 | +public class SysSmsLogCoreServiceTest extends BaseDbUnitTest { | ||
| 36 | + | ||
| 37 | + @Resource | ||
| 38 | + private SysSmsLogCoreServiceImpl smsLogCoreService; | ||
| 39 | + | ||
| 40 | + @Resource | ||
| 41 | + private SysSmsLogCoreMapper smsLogCoreMapper; | ||
| 42 | + | ||
| 43 | + @Test | ||
| 44 | + public void testCreateSmsLog() { | ||
| 45 | + // 准备参数 | ||
| 46 | + String mobile = randomString(); | ||
| 47 | + Long userId = randomLongId(); | ||
| 48 | + Integer userType = randomEle(UserTypeEnum.values()).getValue(); | ||
| 49 | + Boolean isSend = randomBoolean(); | ||
| 50 | + SysSmsTemplateDO templateDO = randomPojo(SysSmsTemplateDO.class, | ||
| 51 | + o -> o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType())); | ||
| 52 | + String templateContent = randomString(); | ||
| 53 | + Map<String, Object> templateParams = randomTemplateParams(); | ||
| 54 | + // mock 方法 | ||
| 55 | + | ||
| 56 | + // 调用 | ||
| 57 | + Long logId = smsLogCoreService.createSmsLog(mobile, userId, userType, isSend, | ||
| 58 | + templateDO, templateContent, templateParams); | ||
| 59 | + // 断言 | ||
| 60 | + SysSmsLogDO logDO = smsLogCoreMapper.selectById(logId); | ||
| 61 | + assertEquals(isSend ? SysSmsSendStatusEnum.INIT.getStatus() : SysSmsSendStatusEnum.IGNORE.getStatus(), | ||
| 62 | + logDO.getSendStatus()); | ||
| 63 | + assertEquals(mobile, logDO.getMobile()); | ||
| 64 | + assertEquals(userType, logDO.getUserType()); | ||
| 65 | + assertEquals(userId, logDO.getUserId()); | ||
| 66 | + assertEquals(templateDO.getId(), logDO.getTemplateId()); | ||
| 67 | + assertEquals(templateDO.getCode(), logDO.getTemplateCode()); | ||
| 68 | + assertEquals(templateDO.getType(), logDO.getTemplateType()); | ||
| 69 | + assertEquals(templateDO.getChannelId(), logDO.getChannelId()); | ||
| 70 | + assertEquals(templateDO.getChannelCode(), logDO.getChannelCode()); | ||
| 71 | + assertEquals(templateContent, logDO.getTemplateContent()); | ||
| 72 | + assertEquals(templateParams, logDO.getTemplateParams()); | ||
| 73 | + assertEquals(SysSmsReceiveStatusEnum.INIT.getStatus(), logDO.getReceiveStatus()); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Test | ||
| 77 | + public void testUpdateSmsSendResult() { | ||
| 78 | + // mock 数据 | ||
| 79 | + SysSmsLogDO dbSmsLog = randomSmsLogDO( | ||
| 80 | + o -> o.setSendStatus(SysSmsSendStatusEnum.IGNORE.getStatus())); | ||
| 81 | + smsLogCoreMapper.insert(dbSmsLog); | ||
| 82 | + // 准备参数 | ||
| 83 | + Long id = dbSmsLog.getId(); | ||
| 84 | + Integer sendCode = randomInteger(); | ||
| 85 | + String sendMsg = randomString(); | ||
| 86 | + String apiSendCode = randomString(); | ||
| 87 | + String apiSendMsg = randomString(); | ||
| 88 | + String apiRequestId = randomString(); | ||
| 89 | + String apiSerialNo = randomString(); | ||
| 90 | + | ||
| 91 | + // 调用 | ||
| 92 | + smsLogCoreService.updateSmsSendResult(id, sendCode, sendMsg, | ||
| 93 | + apiSendCode, apiSendMsg, apiRequestId, apiSerialNo); | ||
| 94 | + // 断言 | ||
| 95 | + dbSmsLog = smsLogCoreMapper.selectById(id); | ||
| 96 | + assertEquals(CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS.getStatus() | ||
| 97 | + : SysSmsSendStatusEnum.FAILURE.getStatus(), dbSmsLog.getSendStatus()); | ||
| 98 | + assertNotNull(dbSmsLog.getSendTime()); | ||
| 99 | + assertEquals(sendMsg, dbSmsLog.getSendMsg()); | ||
| 100 | + assertEquals(apiSendCode, dbSmsLog.getApiSendCode()); | ||
| 101 | + assertEquals(apiSendMsg, dbSmsLog.getApiSendMsg()); | ||
| 102 | + assertEquals(apiRequestId, dbSmsLog.getApiRequestId()); | ||
| 103 | + assertEquals(apiSerialNo, dbSmsLog.getApiSerialNo()); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Test | ||
| 107 | + public void testUpdateSmsReceiveResult() { | ||
| 108 | + // mock 数据 | ||
| 109 | + SysSmsLogDO dbSmsLog = randomSmsLogDO( | ||
| 110 | + o -> o.setReceiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus())); | ||
| 111 | + smsLogCoreMapper.insert(dbSmsLog); | ||
| 112 | + // 准备参数 | ||
| 113 | + Long id = dbSmsLog.getId(); | ||
| 114 | + Boolean success = randomBoolean(); | ||
| 115 | + Date receiveTime = randomDate(); | ||
| 116 | + String apiReceiveCode = randomString(); | ||
| 117 | + String apiReceiveMsg = randomString(); | ||
| 118 | + | ||
| 119 | + // 调用 | ||
| 120 | + smsLogCoreService.updateSmsReceiveResult(id, success, receiveTime, apiReceiveCode, apiReceiveMsg); | ||
| 121 | + // 断言 | ||
| 122 | + dbSmsLog = smsLogCoreMapper.selectById(id); | ||
| 123 | + assertEquals(success ? SysSmsReceiveStatusEnum.SUCCESS.getStatus() | ||
| 124 | + : SysSmsReceiveStatusEnum.FAILURE.getStatus(), dbSmsLog.getReceiveStatus()); | ||
| 125 | + assertEquals(receiveTime, dbSmsLog.getReceiveTime()); | ||
| 126 | + assertEquals(apiReceiveCode, dbSmsLog.getApiReceiveCode()); | ||
| 127 | + assertEquals(apiReceiveMsg, dbSmsLog.getApiReceiveMsg()); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + // ========== 随机对象 ========== | ||
| 131 | + | ||
| 132 | + @SafeVarargs | ||
| 133 | + private static SysSmsLogDO randomSmsLogDO(Consumer<SysSmsLogDO>... consumers) { | ||
| 134 | + Consumer<SysSmsLogDO> consumer = (o) -> { | ||
| 135 | + o.setTemplateParams(randomTemplateParams()); | ||
| 136 | + o.setTemplateType(randomEle(SysSmsTemplateTypeEnum.values()).getType()); // 保证 templateType 的范围 | ||
| 137 | + o.setUserType(randomEle(UserTypeEnum.values()).getValue()); // 保证 userType 的范围 | ||
| 138 | + o.setSendStatus(randomEle(SysSmsSendStatusEnum.values()).getStatus()); // 保证 sendStatus 的范围 | ||
| 139 | + o.setReceiveStatus(randomEle(SysSmsReceiveStatusEnum.values()).getStatus()); // 保证 receiveStatus 的范围 | ||
| 140 | + }; | ||
| 141 | + return randomPojo(SysSmsLogDO.class, ArrayUtils.append(consumer, consumers)); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + | ||
| 145 | + private static Map<String, Object> randomTemplateParams() { | ||
| 146 | + return MapUtil.<String, Object>builder().put(randomString(), randomString()) | ||
| 147 | + .put(randomString(), randomString()).build(); | ||
| 148 | + } | ||
| 149 | +} |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/SysSmsTemplateServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.sms.SysSmsTemplateCoreMapper; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.enums.sms.SysSmsTemplateTypeEnum; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.impl.SysSmsTemplateCoreServiceImpl; | ||
| 8 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 9 | +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 10 | +import org.junit.jupiter.api.Test; | ||
| 11 | +import org.springframework.context.annotation.Import; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Date; | ||
| 15 | +import java.util.Map; | ||
| 16 | +import java.util.function.Consumer; | ||
| 17 | + | ||
| 18 | +import static cn.hutool.core.bean.BeanUtil.getFieldValue; | ||
| 19 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max; | ||
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 23 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | +* {@link SysSmsTemplateCoreServiceImpl} 的单元测试类 | ||
| 27 | +* | ||
| 28 | +* @author 芋道源码 | ||
| 29 | +*/ | ||
| 30 | +@Import(SysSmsTemplateCoreServiceImpl.class) | ||
| 31 | +public class SysSmsTemplateServiceTest extends BaseDbUnitTest { | ||
| 32 | + | ||
| 33 | + @Resource | ||
| 34 | + private SysSmsTemplateCoreServiceImpl smsTemplateCoreService; | ||
| 35 | + | ||
| 36 | + @Resource | ||
| 37 | + private SysSmsTemplateCoreMapper smsTemplateCoreMapper; | ||
| 38 | + | ||
| 39 | + @Test | ||
| 40 | + @SuppressWarnings("unchecked") | ||
| 41 | + void testInitLocalCache() { | ||
| 42 | + // mock 数据 | ||
| 43 | + SysSmsTemplateDO smsTemplate01 = randomSmsTemplateDO(); | ||
| 44 | + smsTemplateCoreMapper.insert(smsTemplate01); | ||
| 45 | + SysSmsTemplateDO smsTemplate02 = randomSmsTemplateDO(); | ||
| 46 | + smsTemplateCoreMapper.insert(smsTemplate02); | ||
| 47 | + | ||
| 48 | + // 调用 | ||
| 49 | + smsTemplateCoreService.initLocalCache(); | ||
| 50 | + // 断言 deptCache 缓存 | ||
| 51 | + Map<String, SysSmsTemplateDO> smsTemplateCache = (Map<String, SysSmsTemplateDO>) getFieldValue(smsTemplateCoreService, "smsTemplateCache"); | ||
| 52 | + assertEquals(2, smsTemplateCache.size()); | ||
| 53 | + assertPojoEquals(smsTemplate01, smsTemplateCache.get(smsTemplate01.getCode())); | ||
| 54 | + assertPojoEquals(smsTemplate02, smsTemplateCache.get(smsTemplate02.getCode())); | ||
| 55 | + // 断言 maxUpdateTime 缓存 | ||
| 56 | + Date maxUpdateTime = (Date) getFieldValue(smsTemplateCoreService, "maxUpdateTime"); | ||
| 57 | + assertEquals(max(smsTemplate01.getUpdateTime(), smsTemplate02.getUpdateTime()), maxUpdateTime); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + // ========== 随机对象 ========== | ||
| 61 | + | ||
| 62 | + @SafeVarargs | ||
| 63 | + private static SysSmsTemplateDO randomSmsTemplateDO(Consumer<SysSmsTemplateDO>... consumers) { | ||
| 64 | + Consumer<SysSmsTemplateDO> consumer = (o) -> { | ||
| 65 | + o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 | ||
| 66 | + o.setType(randomEle(SysSmsTemplateTypeEnum.values()).getType()); // 保证 type 的 范围 | ||
| 67 | + }; | ||
| 68 | + return randomPojo(SysSmsTemplateDO.class, ArrayUtils.append(consumer, consumers)); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | +} |
yudao-core-service/src/test/resources/application-unit-test.yaml
0 → 100644
| 1 | +spring: | ||
| 2 | + main: | ||
| 3 | + lazy-initialization: true # 开启懒加载,加快速度 | ||
| 4 | + banner-mode: off # 单元测试,禁用 Banner | ||
| 5 | + | ||
| 6 | +--- #################### 数据库相关配置 #################### | ||
| 7 | + | ||
| 8 | +spring: | ||
| 9 | + # 数据源配置项 | ||
| 10 | + datasource: | ||
| 11 | + name: ruoyi-vue-pro | ||
| 12 | + url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写 | ||
| 13 | + driver-class-name: org.h2.Driver | ||
| 14 | + username: sa | ||
| 15 | + password: | ||
| 16 | + schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具 | ||
| 17 | + druid: | ||
| 18 | + async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度 | ||
| 19 | + initial-size: 1 # 单元测试,配置为 1,提升启动速度 | ||
| 20 | + | ||
| 21 | + # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | ||
| 22 | + redis: | ||
| 23 | + host: 127.0.0.1 # 地址 | ||
| 24 | + port: 16379 # 端口(单元测试,使用 16379 端口) | ||
| 25 | + database: 0 # 数据库索引 | ||
| 26 | + | ||
| 27 | +mybatis: | ||
| 28 | + lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试 | ||
| 29 | + | ||
| 30 | +--- #################### 定时任务相关配置 #################### | ||
| 31 | + | ||
| 32 | +--- #################### 配置中心相关配置 #################### | ||
| 33 | + | ||
| 34 | +--- #################### 服务保障相关配置 #################### | ||
| 35 | + | ||
| 36 | +# Lock4j 配置项(单元测试,禁用 Lock4j) | ||
| 37 | + | ||
| 38 | +# Resilience4j 配置项 | ||
| 39 | + | ||
| 40 | +--- #################### 监控相关配置 #################### | ||
| 41 | + | ||
| 42 | +--- #################### 芋道相关配置 #################### | ||
| 43 | + | ||
| 44 | +# 芋道配置项,设置当前项目所有自定义的配置 |
yudao-core-service/src/test/resources/application.yaml
0 → 100644
| 1 | +spring: | ||
| 2 | + application: | ||
| 3 | + name: yudao-core-service | ||
| 4 | + | ||
| 5 | + # Jackson 配置项 | ||
| 6 | + jackson: | ||
| 7 | + serialization: | ||
| 8 | + write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳 | ||
| 9 | + write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401 | ||
| 10 | + write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳 | ||
| 11 | + fail-on-empty-beans: false # 允许序列化无属性的 Bean | ||
| 12 | + | ||
| 13 | +# MyBatis Plus 的配置项 | ||
| 14 | +mybatis-plus: | ||
| 15 | + configuration: | ||
| 16 | + map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 | ||
| 17 | + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志 | ||
| 18 | + global-config: | ||
| 19 | + db-config: | ||
| 20 | + id-type: AUTO # 自增 ID | ||
| 21 | + logic-delete-value: 1 # 逻辑已删除值(默认为 1) | ||
| 22 | + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) | ||
| 23 | + mapper-locations: classpath*:mapper/*.xml | ||
| 24 | + type-aliases-package: ${yudao.core-service.base-package}.modules.*.dal.dataobject | ||
| 25 | + | ||
| 26 | +--- #################### 芋道相关配置 #################### | ||
| 27 | + | ||
| 28 | +yudao: | ||
| 29 | + info: | ||
| 30 | + version: 1.0.0 | ||
| 31 | + base-package: cn.iocoder.yudao.coreservice | ||
| 32 | + core-service: | ||
| 33 | + base-package: cn.iocoder.yudao.coreservice | ||
| 34 | + | ||
| 35 | +debug: false |
yudao-core-service/src/test/resources/logback-spring.xml
0 → 100644
yudao-core-service/src/test/resources/sql/clean.sql
0 → 100644
yudao-core-service/src/test/resources/sql/create_tables.sql
0 → 100644
| 1 | +-- inf 开头的 DB | ||
| 2 | + | ||
| 3 | +-- sys 开头的 DB | ||
| 4 | + | ||
| 5 | +CREATE TABLE IF NOT EXISTS `sys_user_session` ( | ||
| 6 | + `id` varchar(32) NOT NULL, | ||
| 7 | + `user_id` bigint DEFAULT NULL, | ||
| 8 | + "user_type" tinyint NOT NULL, | ||
| 9 | + `username` varchar(50) NOT NULL DEFAULT '', | ||
| 10 | + `user_ip` varchar(50) DEFAULT NULL, | ||
| 11 | + `user_agent` varchar(512) DEFAULT NULL, | ||
| 12 | + `session_timeout` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 13 | + "creator" varchar(64) DEFAULT '', | ||
| 14 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 15 | + `updater` varchar(64) DEFAULT '' , | ||
| 16 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 17 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 18 | + PRIMARY KEY (`id`) | ||
| 19 | +) COMMENT '用户在线 Session'; | ||
| 20 | + | ||
| 21 | +CREATE TABLE IF NOT EXISTS "sys_dict_data" ( | ||
| 22 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
| 23 | + "sort" int NOT NULL DEFAULT '0', | ||
| 24 | + "label" varchar(100) NOT NULL DEFAULT '', | ||
| 25 | + "value" varchar(100) NOT NULL DEFAULT '', | ||
| 26 | + "dict_type" varchar(100) NOT NULL DEFAULT '', | ||
| 27 | + "status" tinyint NOT NULL DEFAULT '0', | ||
| 28 | + "remark" varchar(500) DEFAULT NULL, | ||
| 29 | + "creator" varchar(64) DEFAULT '', | ||
| 30 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 31 | + "updater" varchar(64) DEFAULT '', | ||
| 32 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 33 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 34 | + PRIMARY KEY ("id") | ||
| 35 | +) COMMENT '字典数据表'; | ||
| 36 | + | ||
| 37 | +CREATE TABLE IF NOT EXISTS "inf_api_access_log" ( | ||
| 38 | + "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, | ||
| 39 | + "trace_id" varchar(64) not null default '', | ||
| 40 | + "user_id" bigint not null default '0', | ||
| 41 | + "user_type" tinyint not null default '0', | ||
| 42 | + "application_name" varchar(50) not null, | ||
| 43 | + "request_method" varchar(16) not null default '', | ||
| 44 | + "request_url" varchar(255) not null default '', | ||
| 45 | + "request_params" varchar(8000) not null default '', | ||
| 46 | + "user_ip" varchar(50) not null, | ||
| 47 | + "user_agent" varchar(512) not null, | ||
| 48 | + "begin_time" timestamp not null, | ||
| 49 | + "end_time" timestamp not null, | ||
| 50 | + "duration" integer not null, | ||
| 51 | + "result_code" integer not null default '0', | ||
| 52 | + "result_msg" varchar(512) default '', | ||
| 53 | + "creator" varchar(64) default '', | ||
| 54 | + "create_time" timestamp not null default current_timestamp, | ||
| 55 | + "updater" varchar(64) default '', | ||
| 56 | + "update_time" timestamp not null default current_timestamp, | ||
| 57 | + "deleted" bit not null default false, | ||
| 58 | + primary key ("id") | ||
| 59 | +) COMMENT 'API 访问日志表'; | ||
| 60 | + | ||
| 61 | +CREATE TABLE IF NOT EXISTS "inf_api_error_log" ( | ||
| 62 | + "id" integer not null GENERATED BY DEFAULT AS IDENTITY, | ||
| 63 | + "trace_id" varchar(64) not null, | ||
| 64 | + "user_id" bigint not null default '0', | ||
| 65 | + "user_type" tinyint not null default '0', | ||
| 66 | + "application_name" varchar(50) not null, | ||
| 67 | + "request_method" varchar(16) not null, | ||
| 68 | + "request_url" varchar(255) not null, | ||
| 69 | + "request_params" varchar(8000) not null, | ||
| 70 | + "user_ip" varchar(50) not null, | ||
| 71 | + "user_agent" varchar(512) not null, | ||
| 72 | + "exception_time" timestamp not null, | ||
| 73 | + "exception_name" varchar(128) not null default '', | ||
| 74 | + "exception_message" clob not null, | ||
| 75 | + "exception_root_cause_message" clob not null, | ||
| 76 | + "exception_stack_trace" clob not null, | ||
| 77 | + "exception_class_name" varchar(512) not null, | ||
| 78 | + "exception_file_name" varchar(512) not null, | ||
| 79 | + "exception_method_name" varchar(512) not null, | ||
| 80 | + "exception_line_number" integer not null, | ||
| 81 | + "process_status" tinyint not null, | ||
| 82 | + "process_time" timestamp default null, | ||
| 83 | + "process_user_id" bigint default '0', | ||
| 84 | + "creator" varchar(64) default '', | ||
| 85 | + "create_time" timestamp not null default current_timestamp, | ||
| 86 | + "updater" varchar(64) default '', | ||
| 87 | + "update_time" timestamp not null default current_timestamp, | ||
| 88 | + "deleted" bit not null default false, | ||
| 89 | + primary key ("id") | ||
| 90 | +) COMMENT '系统异常日志'; | ||
| 91 | + | ||
| 92 | +CREATE TABLE IF NOT EXISTS "sys_sms_template" ( | ||
| 93 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
| 94 | + "type" tinyint NOT NULL, | ||
| 95 | + "status" tinyint NOT NULL, | ||
| 96 | + "code" varchar(63) NOT NULL, | ||
| 97 | + "name" varchar(63) NOT NULL, | ||
| 98 | + "content" varchar(255) NOT NULL, | ||
| 99 | + "params" varchar(255) NOT NULL, | ||
| 100 | + "remark" varchar(255) DEFAULT NULL, | ||
| 101 | + "api_template_id" varchar(63) NOT NULL, | ||
| 102 | + "channel_id" bigint NOT NULL, | ||
| 103 | + "channel_code" varchar(63) NOT NULL, | ||
| 104 | + "creator" varchar(64) DEFAULT '', | ||
| 105 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 106 | + "updater" varchar(64) DEFAULT '', | ||
| 107 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 108 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 109 | + PRIMARY KEY ("id") | ||
| 110 | +) COMMENT '短信模板'; | ||
| 111 | + | ||
| 112 | +CREATE TABLE IF NOT EXISTS "sys_sms_log" ( | ||
| 113 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
| 114 | + "channel_id" bigint NOT NULL, | ||
| 115 | + "channel_code" varchar(63) NOT NULL, | ||
| 116 | + "template_id" bigint NOT NULL, | ||
| 117 | + "template_code" varchar(63) NOT NULL, | ||
| 118 | + "template_type" tinyint NOT NULL, | ||
| 119 | + "template_content" varchar(255) NOT NULL, | ||
| 120 | + "template_params" varchar(255) NOT NULL, | ||
| 121 | + "api_template_id" varchar(63) NOT NULL, | ||
| 122 | + "mobile" varchar(11) NOT NULL, | ||
| 123 | + "user_id" bigint DEFAULT '0', | ||
| 124 | + "user_type" tinyint DEFAULT '0', | ||
| 125 | + "send_status" tinyint NOT NULL DEFAULT '0', | ||
| 126 | + "send_time" timestamp DEFAULT NULL, | ||
| 127 | + "send_code" int DEFAULT NULL, | ||
| 128 | + "send_msg" varchar(255) DEFAULT NULL, | ||
| 129 | + "api_send_code" varchar(63) DEFAULT NULL, | ||
| 130 | + "api_send_msg" varchar(255) DEFAULT NULL, | ||
| 131 | + "api_request_id" varchar(255) DEFAULT NULL, | ||
| 132 | + "api_serial_no" varchar(255) DEFAULT NULL, | ||
| 133 | + "receive_status" tinyint NOT NULL DEFAULT '0', | ||
| 134 | + "receive_time" timestamp DEFAULT NULL, | ||
| 135 | + "api_receive_code" varchar(63) DEFAULT NULL, | ||
| 136 | + "api_receive_msg" varchar(255) DEFAULT NULL, | ||
| 137 | + "creator" varchar(64) DEFAULT '', | ||
| 138 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 139 | + "updater" varchar(64) DEFAULT '', | ||
| 140 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 141 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 142 | + PRIMARY KEY ("id") | ||
| 143 | +) COMMENT '短信日志'; | ||
| 144 | + | ||
| 145 | +CREATE TABLE IF NOT EXISTS `sys_login_log` ( | ||
| 146 | + `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
| 147 | + `log_type` bigint(4) NOT NULL, | ||
| 148 | + "user_id" bigint not null default '0', | ||
| 149 | + "user_type" tinyint NOT NULL, | ||
| 150 | + `trace_id` varchar(64) NOT NULL DEFAULT '', | ||
| 151 | + `username` varchar(50) NOT NULL DEFAULT '', | ||
| 152 | + `result` tinyint(4) NOT NULL, | ||
| 153 | + `user_ip` varchar(50) NOT NULL, | ||
| 154 | + `user_agent` varchar(512) NOT NULL, | ||
| 155 | + `creator` varchar(64) DEFAULT '', | ||
| 156 | + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 157 | + `updater` varchar(64) DEFAULT '', | ||
| 158 | + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| 159 | + `deleted` bit(1) NOT NULL DEFAULT '0', | ||
| 160 | + PRIMARY KEY (`id`) | ||
| 161 | +) COMMENT ='系统访问记录'; |
yudao-dependencies/pom.xml
| @@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
| 26 | <druid.version>1.2.4</druid.version> | 26 | <druid.version>1.2.4</druid.version> |
| 27 | <mybatis-plus.version>3.4.2</mybatis-plus.version> | 27 | <mybatis-plus.version>3.4.2</mybatis-plus.version> |
| 28 | <dynamic-datasource.version>3.3.2</dynamic-datasource.version> | 28 | <dynamic-datasource.version>3.3.2</dynamic-datasource.version> |
| 29 | - <redisson.version>3.15.1</redisson.version> | 29 | + <redisson.version>3.16.3</redisson.version> |
| 30 | <!-- Config 配置中心相关 --> | 30 | <!-- Config 配置中心相关 --> |
| 31 | <apollo.version>1.7.0</apollo.version> | 31 | <apollo.version>1.7.0</apollo.version> |
| 32 | <!-- Job 定时任务相关 --> | 32 | <!-- Job 定时任务相关 --> |
| @@ -34,9 +34,9 @@ | @@ -34,9 +34,9 @@ | ||
| 34 | <lock4j.version>2.2.0</lock4j.version> | 34 | <lock4j.version>2.2.0</lock4j.version> |
| 35 | <resilience4j.version>1.7.0</resilience4j.version> | 35 | <resilience4j.version>1.7.0</resilience4j.version> |
| 36 | <!-- 监控相关 --> | 36 | <!-- 监控相关 --> |
| 37 | - <skywalking.version>8.5.0</skywalking.version> | 37 | + <skywalking.version>8.7.0</skywalking.version> |
| 38 | <spring-boot-admin.version>2.3.1</spring-boot-admin.version> | 38 | <spring-boot-admin.version>2.3.1</spring-boot-admin.version> |
| 39 | - <opentracing.version>0.30.0</opentracing.version> | 39 | + <opentracing.version>0.31.0</opentracing.version> |
| 40 | <!-- Test 测试相关 --> | 40 | <!-- Test 测试相关 --> |
| 41 | <podam.version>7.2.6.RELEASE</podam.version> | 41 | <podam.version>7.2.6.RELEASE</podam.version> |
| 42 | <jedis-mock.version>0.1.16</jedis-mock.version> | 42 | <jedis-mock.version>0.1.16</jedis-mock.version> |
| @@ -49,7 +49,7 @@ | @@ -49,7 +49,7 @@ | ||
| 49 | <screw.version>1.0.5</screw.version> | 49 | <screw.version>1.0.5</screw.version> |
| 50 | <guava.version>30.1.1-jre</guava.version> | 50 | <guava.version>30.1.1-jre</guava.version> |
| 51 | <!-- 三方云服务相关 --> | 51 | <!-- 三方云服务相关 --> |
| 52 | - <aliyun-java-sdk-core.version>4.5.18</aliyun-java-sdk-core.version> | 52 | + <aliyun-java-sdk-core.version>4.5.25</aliyun-java-sdk-core.version> |
| 53 | <aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> | 53 | <aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> |
| 54 | <yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version> | 54 | <yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version> |
| 55 | </properties> | 55 | </properties> |
| @@ -74,6 +74,11 @@ | @@ -74,6 +74,11 @@ | ||
| 74 | <!-- 业务组件 --> | 74 | <!-- 业务组件 --> |
| 75 | <dependency> | 75 | <dependency> |
| 76 | <groupId>cn.iocoder.boot</groupId> | 76 | <groupId>cn.iocoder.boot</groupId> |
| 77 | + <artifactId>yudao-core-service</artifactId> | ||
| 78 | + <version>${revision}</version> | ||
| 79 | + </dependency> | ||
| 80 | + <dependency> | ||
| 81 | + <groupId>cn.iocoder.boot</groupId> | ||
| 77 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> | 82 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> |
| 78 | <version>${revision}</version> | 83 | <version>${revision}</version> |
| 79 | </dependency> | 84 | </dependency> |
| @@ -252,12 +257,32 @@ | @@ -252,12 +257,32 @@ | ||
| 252 | <groupId>org.apache.skywalking</groupId> | 257 | <groupId>org.apache.skywalking</groupId> |
| 253 | <artifactId>apm-toolkit-opentracing</artifactId> | 258 | <artifactId>apm-toolkit-opentracing</artifactId> |
| 254 | <version>${skywalking.version}</version> | 259 | <version>${skywalking.version}</version> |
| 260 | +<!-- <exclusions>--> | ||
| 261 | +<!-- <exclusion>--> | ||
| 262 | +<!-- <artifactId>opentracing-api</artifactId>--> | ||
| 263 | +<!-- <groupId>io.opentracing</groupId>--> | ||
| 264 | +<!-- </exclusion>--> | ||
| 265 | +<!-- <exclusion>--> | ||
| 266 | +<!-- <artifactId>opentracing-util</artifactId>--> | ||
| 267 | +<!-- <groupId>io.opentracing</groupId>--> | ||
| 268 | +<!-- </exclusion>--> | ||
| 269 | +<!-- </exclusions>--> | ||
| 270 | + </dependency> | ||
| 271 | + <dependency> | ||
| 272 | + <groupId>io.opentracing</groupId> | ||
| 273 | + <artifactId>opentracing-api</artifactId> | ||
| 274 | + <version>${opentracing.version}</version> | ||
| 255 | </dependency> | 275 | </dependency> |
| 256 | <dependency> | 276 | <dependency> |
| 257 | <groupId>io.opentracing</groupId> | 277 | <groupId>io.opentracing</groupId> |
| 258 | <artifactId>opentracing-util</artifactId> | 278 | <artifactId>opentracing-util</artifactId> |
| 259 | <version>${opentracing.version}</version> | 279 | <version>${opentracing.version}</version> |
| 260 | </dependency> | 280 | </dependency> |
| 281 | + <dependency> | ||
| 282 | + <groupId>io.opentracing</groupId> | ||
| 283 | + <artifactId>opentracing-noop</artifactId> | ||
| 284 | + <version>${opentracing.version}</version> | ||
| 285 | + </dependency> | ||
| 261 | 286 | ||
| 262 | <dependency> | 287 | <dependency> |
| 263 | <groupId>de.codecentric</groupId> | 288 | <groupId>de.codecentric</groupId> |
yudao-framework/yudao-spring-boot-starter-monitor/pom.xml
| @@ -42,6 +42,10 @@ | @@ -42,6 +42,10 @@ | ||
| 42 | 42 | ||
| 43 | <!-- 监控相关 --> | 43 | <!-- 监控相关 --> |
| 44 | <dependency> | 44 | <dependency> |
| 45 | + <groupId>io.opentracing</groupId> | ||
| 46 | + <artifactId>opentracing-util</artifactId> | ||
| 47 | + </dependency> | ||
| 48 | + <dependency> | ||
| 45 | <groupId>org.apache.skywalking</groupId> | 49 | <groupId>org.apache.skywalking</groupId> |
| 46 | <artifactId>apm-toolkit-trace</artifactId> | 50 | <artifactId>apm-toolkit-trace</artifactId> |
| 47 | </dependency> | 51 | </dependency> |
| @@ -53,10 +57,6 @@ | @@ -53,10 +57,6 @@ | ||
| 53 | <groupId>org.apache.skywalking</groupId> | 57 | <groupId>org.apache.skywalking</groupId> |
| 54 | <artifactId>apm-toolkit-opentracing</artifactId> | 58 | <artifactId>apm-toolkit-opentracing</artifactId> |
| 55 | </dependency> | 59 | </dependency> |
| 56 | - <dependency> | ||
| 57 | - <groupId>io.opentracing</groupId> | ||
| 58 | - <artifactId>opentracing-util</artifactId> | ||
| 59 | - </dependency> | ||
| 60 | 60 | ||
| 61 | <dependency> | 61 | <dependency> |
| 62 | <groupId>de.codecentric</groupId> | 62 | <groupId>de.codecentric</groupId> |
yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java
| 1 | package cn.iocoder.yudao.framework.tracer.config; | 1 | package cn.iocoder.yudao.framework.tracer.config; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; | ||
| 3 | import cn.iocoder.yudao.framework.tracer.core.aop.BizTraceAspect; | 4 | import cn.iocoder.yudao.framework.tracer.core.aop.BizTraceAspect; |
| 4 | import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter; | 5 | import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter; |
| 5 | -import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; | ||
| 6 | -import io.opentracing.Tracer; | ||
| 7 | -import io.opentracing.util.GlobalTracer; | ||
| 8 | -import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer; | ||
| 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 10 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 12 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 13 | import org.springframework.boot.web.servlet.FilterRegistrationBean; | 9 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| @@ -25,24 +21,25 @@ import org.springframework.context.annotation.Configuration; | @@ -25,24 +21,25 @@ import org.springframework.context.annotation.Configuration; | ||
| 25 | @ConditionalOnProperty(prefix = "yudao.tracer", value = "enable", matchIfMissing = true) | 21 | @ConditionalOnProperty(prefix = "yudao.tracer", value = "enable", matchIfMissing = true) |
| 26 | public class YudaoTracerAutoConfiguration { | 22 | public class YudaoTracerAutoConfiguration { |
| 27 | 23 | ||
| 28 | - @Bean | ||
| 29 | - public TracerProperties bizTracerProperties() { | ||
| 30 | - return new TracerProperties(); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - @Bean | ||
| 34 | - public BizTraceAspect bizTracingAop() { | ||
| 35 | - return new BizTraceAspect(tracer()); | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - @Bean | ||
| 39 | - public Tracer tracer() { | ||
| 40 | - // 创建 SkywalkingTracer 对象 | ||
| 41 | - SkywalkingTracer tracer = new SkywalkingTracer(); | ||
| 42 | - // 设置为 GlobalTracer 的追踪器 | ||
| 43 | - GlobalTracer.register(tracer); | ||
| 44 | - return tracer; | ||
| 45 | - } | 24 | + // TODO @芋艿:重要。目前 opentracing 版本存在冲突,要么保证 skywalking,要么保证阿里云短信 sdk |
| 25 | +// @Bean | ||
| 26 | +// public TracerProperties bizTracerProperties() { | ||
| 27 | +// return new TracerProperties(); | ||
| 28 | +// } | ||
| 29 | +// | ||
| 30 | +// @Bean | ||
| 31 | +// public BizTraceAspect bizTracingAop() { | ||
| 32 | +// return new BizTraceAspect(tracer()); | ||
| 33 | +// } | ||
| 34 | +// | ||
| 35 | +// @Bean | ||
| 36 | +// public Tracer tracer() { | ||
| 37 | +// // 创建 SkywalkingTracer 对象 | ||
| 38 | +// SkywalkingTracer tracer = new SkywalkingTracer(); | ||
| 39 | +// // 设置为 GlobalTracer 的追踪器 | ||
| 40 | +// GlobalTracer.register(tracer); | ||
| 41 | +// return tracer; | ||
| 42 | +// } | ||
| 46 | 43 | ||
| 47 | /** | 44 | /** |
| 48 | * 创建 TraceFilter 过滤器,响应 header 设置 traceId | 45 | * 创建 TraceFilter 过滤器,响应 header 设置 traceId |
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; | @@ -15,7 +15,7 @@ import org.springframework.context.annotation.Configuration; | ||
| 15 | * @author 芋道源码 | 15 | * @author 芋道源码 |
| 16 | */ | 16 | */ |
| 17 | @Configuration | 17 | @Configuration |
| 18 | -@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class, | 18 | +@MapperScan(value = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}, annotationClass = Mapper.class, |
| 19 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 | 19 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 |
| 20 | public class YudaoMybatisAutoConfiguration { | 20 | public class YudaoMybatisAutoConfiguration { |
| 21 | 21 |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java
| 1 | package cn.iocoder.yudao.framework.security.core; | 1 | package cn.iocoder.yudao.framework.security.core; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | import com.fasterxml.jackson.annotation.JsonIgnore; | 5 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import org.springframework.security.core.GrantedAuthority; | 7 | import org.springframework.security.core.GrantedAuthority; |
| @@ -24,7 +25,13 @@ public class LoginUser implements UserDetails { | @@ -24,7 +25,13 @@ public class LoginUser implements UserDetails { | ||
| 24 | */ | 25 | */ |
| 25 | private Long id; | 26 | private Long id; |
| 26 | /** | 27 | /** |
| 27 | - * 科室编号 | 28 | + * 用户类型 |
| 29 | + * | ||
| 30 | + * 关联 {@link UserTypeEnum} | ||
| 31 | + */ | ||
| 32 | + private Integer userType; | ||
| 33 | + /** | ||
| 34 | + * 部门编号 | ||
| 28 | */ | 35 | */ |
| 29 | private Long deptId; | 36 | private Long deptId; |
| 30 | /** | 37 | /** |
| @@ -49,6 +56,8 @@ public class LoginUser implements UserDetails { | @@ -49,6 +56,8 @@ public class LoginUser implements UserDetails { | ||
| 49 | */ | 56 | */ |
| 50 | private Integer status; | 57 | private Integer status; |
| 51 | 58 | ||
| 59 | + // TODO @芋艿:怎么去掉 deptId | ||
| 60 | + | ||
| 52 | @Override | 61 | @Override |
| 53 | @JsonIgnore// 避免序列化 | 62 | @JsonIgnore// 避免序列化 |
| 54 | public String getPassword() { | 63 | public String getPassword() { |
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 { | @@ -97,6 +97,7 @@ public class SecurityFrameworkUtils { | ||
| 97 | // 额外设置到 request 中,用于 ApiAccessLogFilter 可以获取到用户编号; | 97 | // 额外设置到 request 中,用于 ApiAccessLogFilter 可以获取到用户编号; |
| 98 | // 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息 | 98 | // 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息 |
| 99 | WebFrameworkUtils.setLoginUserId(request, loginUser.getId()); | 99 | WebFrameworkUtils.setLoginUserId(request, loginUser.getId()); |
| 100 | + WebFrameworkUtils.setLoginUserType(request, loginUser.getUserType()); | ||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | } | 103 | } |
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 { | @@ -81,7 +81,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | ||
| 81 | Map<String, String> queryString, String requestBody, Exception ex) { | 81 | Map<String, String> queryString, String requestBody, Exception ex) { |
| 82 | // 处理用户信息 | 82 | // 处理用户信息 |
| 83 | accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); | 83 | accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); |
| 84 | - accessLog.setUserType(WebFrameworkUtils.getUserType(request)); | 84 | + accessLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); |
| 85 | // 设置访问结果 | 85 | // 设置访问结果 |
| 86 | CommonResult<?> result = WebFrameworkUtils.getCommonResult(request); | 86 | CommonResult<?> result = WebFrameworkUtils.getCommonResult(request); |
| 87 | if (result != null) { | 87 | if (result != null) { |
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 { | @@ -16,8 +16,7 @@ public interface ApiAccessLogFrameworkService { | ||
| 16 | * 创建 API 访问日志 | 16 | * 创建 API 访问日志 |
| 17 | * | 17 | * |
| 18 | * @param createDTO 创建信息 | 18 | * @param createDTO 创建信息 |
| 19 | - * @return 是否创建成功 | ||
| 20 | */ | 19 | */ |
| 21 | - Future<Boolean> createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); | 20 | + void createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); |
| 22 | 21 | ||
| 23 | } | 22 | } |
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 { | @@ -16,8 +16,7 @@ public interface ApiErrorLogFrameworkService { | ||
| 16 | * 创建 API 错误日志 | 16 | * 创建 API 错误日志 |
| 17 | * | 17 | * |
| 18 | * @param createDTO 创建信息 | 18 | * @param createDTO 创建信息 |
| 19 | - * @return 是否创建成功 | ||
| 20 | */ | 19 | */ |
| 21 | - Future<Boolean> createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); | 20 | + void createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); |
| 22 | 21 | ||
| 23 | } | 22 | } |
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 { | @@ -245,7 +245,7 @@ public class GlobalExceptionHandler { | ||
| 245 | private void initExceptionLog(ApiErrorLogCreateDTO errorLog, HttpServletRequest request, Throwable e) { | 245 | private void initExceptionLog(ApiErrorLogCreateDTO errorLog, HttpServletRequest request, Throwable e) { |
| 246 | // 处理用户信息 | 246 | // 处理用户信息 |
| 247 | errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); | 247 | errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); |
| 248 | - errorLog.setUserType(WebFrameworkUtils.getUserType(request)); | 248 | + errorLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); |
| 249 | // 设置异常字段 | 249 | // 设置异常字段 |
| 250 | errorLog.setExceptionName(e.getClass().getName()); | 250 | errorLog.setExceptionName(e.getClass().getName()); |
| 251 | errorLog.setExceptionMessage(ExceptionUtil.getMessage(e)); | 251 | errorLog.setExceptionMessage(ExceptionUtil.getMessage(e)); |
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; | @@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletRequest; | ||
| 17 | public class WebFrameworkUtils { | 17 | public class WebFrameworkUtils { |
| 18 | 18 | ||
| 19 | private static final String REQUEST_ATTRIBUTE_LOGIN_USER_ID = "login_user_id"; | 19 | private static final String REQUEST_ATTRIBUTE_LOGIN_USER_ID = "login_user_id"; |
| 20 | + private static final String REQUEST_ATTRIBUTE_LOGIN_USER_TYPE = "login_user_type"; | ||
| 20 | 21 | ||
| 21 | private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result"; | 22 | private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result"; |
| 22 | 23 | ||
| @@ -24,6 +25,10 @@ public class WebFrameworkUtils { | @@ -24,6 +25,10 @@ public class WebFrameworkUtils { | ||
| 24 | request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId); | 25 | request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId); |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 28 | + public static void setLoginUserType(ServletRequest request, Integer userType) { | ||
| 29 | + request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE, userType); | ||
| 30 | + } | ||
| 31 | + | ||
| 27 | /** | 32 | /** |
| 28 | * 获得当前用户的编号,从请求中 | 33 | * 获得当前用户的编号,从请求中 |
| 29 | * | 34 | * |
| @@ -37,15 +42,24 @@ public class WebFrameworkUtils { | @@ -37,15 +42,24 @@ public class WebFrameworkUtils { | ||
| 37 | return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID); | 42 | return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID); |
| 38 | } | 43 | } |
| 39 | 44 | ||
| 45 | + /** | ||
| 46 | + * 获得当前用户的类型,从请求中 | ||
| 47 | + * | ||
| 48 | + * @param request 请求 | ||
| 49 | + * @return 用户编号 | ||
| 50 | + */ | ||
| 51 | + public static Integer getLoginUserType(HttpServletRequest request) { | ||
| 52 | + if (request == null) { | ||
| 53 | + return null; | ||
| 54 | + } | ||
| 55 | + return (Integer) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE); | ||
| 56 | + } | ||
| 57 | + | ||
| 40 | public static Long getLoginUserId() { | 58 | public static Long getLoginUserId() { |
| 41 | HttpServletRequest request = getRequest(); | 59 | HttpServletRequest request = getRequest(); |
| 42 | return getLoginUserId(request); | 60 | return getLoginUserId(request); |
| 43 | } | 61 | } |
| 44 | 62 | ||
| 45 | - public static Integer getUserType(HttpServletRequest request) { | ||
| 46 | - return UserTypeEnum.ADMIN.getValue(); // TODO 芋艿:等后续优化 | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | public static void setCommonResult(ServletRequest request, CommonResult<?> result) { | 63 | public static void setCommonResult(ServletRequest request, CommonResult<?> result) { |
| 50 | request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); | 64 | request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); |
| 51 | } | 65 | } |
yudao-user-server/pom.xml
| @@ -20,6 +20,11 @@ | @@ -20,6 +20,11 @@ | ||
| 20 | <!-- 业务组件 --> | 20 | <!-- 业务组件 --> |
| 21 | <dependency> | 21 | <dependency> |
| 22 | <groupId>cn.iocoder.boot</groupId> | 22 | <groupId>cn.iocoder.boot</groupId> |
| 23 | + <artifactId>yudao-core-service</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + | ||
| 26 | + <dependency> | ||
| 27 | + <groupId>cn.iocoder.boot</groupId> | ||
| 23 | <artifactId>yudao-spring-boot-starter-biz-dict</artifactId> | 28 | <artifactId>yudao-spring-boot-starter-biz-dict</artifactId> |
| 24 | </dependency> | 29 | </dependency> |
| 25 | <dependency> | 30 | <dependency> |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/UserServerApplication.java
| @@ -3,8 +3,8 @@ package cn.iocoder.yudao.userserver; | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.userserver; | ||
| 3 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | 5 | ||
| 6 | -@SpringBootApplication | ||
| 7 | -public class UserServerApplication { | 6 | +@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} |
| 7 | +@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"})public class UserServerApplication { | ||
| 8 | 8 | ||
| 9 | public static void main(String[] args) { | 9 | public static void main(String[] args) { |
| 10 | SpringApplication.run(UserServerApplication.class, args); | 10 | SpringApplication.run(UserServerApplication.class, args); |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/framework/security/SecurityConfiguration.java
| @@ -18,7 +18,7 @@ public class SecurityConfiguration { | @@ -18,7 +18,7 @@ public class SecurityConfiguration { | ||
| 18 | @Bean | 18 | @Bean |
| 19 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { | 19 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { |
| 20 | return registry -> { | 20 | return registry -> { |
| 21 | - registry.antMatchers(api("/**")).anonymous(); // 默认 API 都是用户可访问 | 21 | + registry.antMatchers(api("/**")).permitAll(); // 默认 API 都是用户可访问 |
| 22 | }; | 22 | }; |
| 23 | } | 23 | } |
| 24 | 24 |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/controller/HelloController.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.controller; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||
| 4 | -import lombok.extern.slf4j.Slf4j; | ||
| 5 | -import org.springframework.security.access.annotation.Secured; | ||
| 6 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 8 | -import org.springframework.web.bind.annotation.RestController; | ||
| 9 | - | ||
| 10 | -/** | ||
| 11 | - * @author weir | ||
| 12 | - */ | ||
| 13 | -@Slf4j | ||
| 14 | -@RestController | ||
| 15 | -public class HelloController { | ||
| 16 | - | ||
| 17 | - @RequestMapping("/user/hello") | ||
| 18 | - public String hello(String hello) { | ||
| 19 | - return "echo + " + hello; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - @RequestMapping("/user/info") | ||
| 23 | - @PreAuthenticated | ||
| 24 | - public String xx() { | ||
| 25 | - return "none"; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiAccessLogConvert.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.convert.logger; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO; | ||
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO; | ||
| 5 | -import org.mapstruct.Mapper; | ||
| 6 | -import org.mapstruct.factory.Mappers; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * API 访问日志 Convert | ||
| 10 | - * | ||
| 11 | - * @author 芋道源码 | ||
| 12 | - */ | ||
| 13 | -@Mapper | ||
| 14 | -public interface InfApiAccessLogConvert { | ||
| 15 | - | ||
| 16 | - InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class); | ||
| 17 | - | ||
| 18 | - InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean); | ||
| 19 | - | ||
| 20 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/convert/logger/InfApiErrorLogConvert.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.convert.logger; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO; | ||
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | -import org.mapstruct.Mapper; | ||
| 6 | -import org.mapstruct.factory.Mappers; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * API 错误日志 Convert | ||
| 10 | - * | ||
| 11 | - * @author 芋道源码 | ||
| 12 | - */ | ||
| 13 | -@Mapper | ||
| 14 | -public interface InfApiErrorLogConvert { | ||
| 15 | - | ||
| 16 | - InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class); | ||
| 17 | - | ||
| 18 | - InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean); | ||
| 19 | - | ||
| 20 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/file/InfFileDO.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | -import com.baomidou.mybatisplus.annotation.IdType; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.TableField; | ||
| 6 | -import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | -import lombok.*; | ||
| 9 | - | ||
| 10 | -import java.io.InputStream; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * 文件表 | ||
| 14 | - * | ||
| 15 | - * @author 芋道源码 | ||
| 16 | - */ | ||
| 17 | -@Data | ||
| 18 | -@TableName("inf_file") | ||
| 19 | -@EqualsAndHashCode(callSuper = true) | ||
| 20 | -@ToString(callSuper = true) | ||
| 21 | -@Builder | ||
| 22 | -@NoArgsConstructor | ||
| 23 | -@AllArgsConstructor | ||
| 24 | -public class InfFileDO extends BaseDO { | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * 文件路径 | ||
| 28 | - */ | ||
| 29 | - @TableId(type = IdType.INPUT) | ||
| 30 | - private String id; | ||
| 31 | - /** | ||
| 32 | - * 文件类型 | ||
| 33 | - * | ||
| 34 | - * 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取 | ||
| 35 | - */ | ||
| 36 | - @TableField(value = "`type`") | ||
| 37 | - private String type; | ||
| 38 | - /** | ||
| 39 | - * 文件内容 | ||
| 40 | - */ | ||
| 41 | - private byte[] content; | ||
| 42 | - | ||
| 43 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/dataobject/logger/InfApiAccessLogDO.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 6 | -import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | -import lombok.*; | ||
| 9 | - | ||
| 10 | -import java.util.Date; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * API 访问日志 | ||
| 14 | - * | ||
| 15 | - * @author 芋道源码 | ||
| 16 | - */ | ||
| 17 | -@TableName("inf_api_access_log") | ||
| 18 | -@Data | ||
| 19 | -@EqualsAndHashCode(callSuper = true) | ||
| 20 | -@ToString(callSuper = true) | ||
| 21 | -@Builder | ||
| 22 | -@NoArgsConstructor | ||
| 23 | -@AllArgsConstructor | ||
| 24 | -public class InfApiAccessLogDO extends BaseDO { | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * 编号 | ||
| 28 | - */ | ||
| 29 | - @TableId | ||
| 30 | - private Integer id; | ||
| 31 | - /** | ||
| 32 | - * 链路追踪编号 | ||
| 33 | - * | ||
| 34 | - * 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。 | ||
| 35 | - */ | ||
| 36 | - private String traceId; | ||
| 37 | - /** | ||
| 38 | - * 用户编号 | ||
| 39 | - */ | ||
| 40 | - private Long userId; | ||
| 41 | - /** | ||
| 42 | - * 用户类型 | ||
| 43 | - * | ||
| 44 | - * 枚举 {@link UserTypeEnum} | ||
| 45 | - */ | ||
| 46 | - private Integer userType; | ||
| 47 | - /** | ||
| 48 | - * 应用名 | ||
| 49 | - * | ||
| 50 | - * 目前读取 `spring.application.name` 配置项 | ||
| 51 | - */ | ||
| 52 | - private String applicationName; | ||
| 53 | - | ||
| 54 | - // ========== 请求相关字段 ========== | ||
| 55 | - | ||
| 56 | - /** | ||
| 57 | - * 请求方法名 | ||
| 58 | - */ | ||
| 59 | - private String requestMethod; | ||
| 60 | - /** | ||
| 61 | - * 访问地址 | ||
| 62 | - */ | ||
| 63 | - private String requestUrl; | ||
| 64 | - /** | ||
| 65 | - * 请求参数 | ||
| 66 | - * | ||
| 67 | - * query: Query String | ||
| 68 | - * body: Quest Body | ||
| 69 | - */ | ||
| 70 | - private String requestParams; | ||
| 71 | - /** | ||
| 72 | - * 用户 IP | ||
| 73 | - */ | ||
| 74 | - private String userIp; | ||
| 75 | - /** | ||
| 76 | - * 浏览器 UA | ||
| 77 | - */ | ||
| 78 | - private String userAgent; | ||
| 79 | - | ||
| 80 | - // ========== 执行相关字段 ========== | ||
| 81 | - | ||
| 82 | - /** | ||
| 83 | - * 开始请求时间 | ||
| 84 | - */ | ||
| 85 | - private Date beginTime; | ||
| 86 | - /** | ||
| 87 | - * 结束请求时间 | ||
| 88 | - */ | ||
| 89 | - private Date endTime; | ||
| 90 | - /** | ||
| 91 | - * 执行时长,单位:毫秒 | ||
| 92 | - */ | ||
| 93 | - private Integer duration; | ||
| 94 | - /** | ||
| 95 | - * 结果码 | ||
| 96 | - * | ||
| 97 | - * 目前使用的 {@link CommonResult#getCode()} 属性 | ||
| 98 | - */ | ||
| 99 | - private Integer resultCode; | ||
| 100 | - /** | ||
| 101 | - * 结果提示 | ||
| 102 | - * | ||
| 103 | - * 目前使用的 {@link CommonResult#getMsg()} 属性 | ||
| 104 | - */ | ||
| 105 | - private String resultMsg; | ||
| 106 | - | ||
| 107 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/config/InfConfigDAOImpl.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; | ||
| 4 | -import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; | ||
| 5 | -import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 6 | -import org.springframework.jdbc.core.JdbcTemplate; | ||
| 7 | -import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
| 8 | - | ||
| 9 | -import javax.sql.DataSource; | ||
| 10 | -import java.sql.ResultSet; | ||
| 11 | -import java.util.Date; | ||
| 12 | -import java.util.List; | ||
| 13 | - | ||
| 14 | -/** | ||
| 15 | - * ConfigFrameworkDAO 实现类 | ||
| 16 | - * | ||
| 17 | - * @author 芋道源码 | ||
| 18 | - */ | ||
| 19 | -public class InfConfigDAOImpl implements ConfigFrameworkDAO { | ||
| 20 | - | ||
| 21 | - private final JdbcTemplate jdbcTemplate; | ||
| 22 | - | ||
| 23 | - public InfConfigDAOImpl(String jdbcUrl, String username, String password) { | ||
| 24 | - DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password); | ||
| 25 | - this.jdbcTemplate = new JdbcTemplate(dataSource); | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - @Override | ||
| 29 | - public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { | ||
| 30 | - return jdbcTemplate.query("SELECT id FROM inf_config WHERE update_time > ? LIMIT 1", | ||
| 31 | - ResultSet::next, maxUpdateTime); | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public List<ConfigRespDTO> selectList() { | ||
| 36 | - return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class)); | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/SysAuthService.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.auth; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | ||
| 4 | - | ||
| 5 | -/** | ||
| 6 | - * 认证 Service 接口 | ||
| 7 | - * | ||
| 8 | - * 提供用户的账号密码登录、token 的校验等认证相关的功能 | ||
| 9 | - * | ||
| 10 | - * @author 芋道源码 | ||
| 11 | - */ | ||
| 12 | -public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 13 | - | ||
| 14 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/impl/SysAuthServiceImpl.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.service.auth.impl; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.service.auth.SysAuthService; | ||
| 5 | -import lombok.extern.slf4j.Slf4j; | ||
| 6 | -import org.springframework.security.core.userdetails.UserDetails; | ||
| 7 | -import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 8 | -import org.springframework.stereotype.Service; | ||
| 9 | - | ||
| 10 | -/** | ||
| 11 | - * Auth Service 实现类 | ||
| 12 | - * | ||
| 13 | - * @author 芋道源码 | ||
| 14 | - */ | ||
| 15 | -@Service | ||
| 16 | -@Slf4j | ||
| 17 | -public class SysAuthServiceImpl implements SysAuthService { | ||
| 18 | - | ||
| 19 | - @Override | ||
| 20 | - public LoginUser verifyTokenAndRefresh(String token) { | ||
| 21 | - return null; | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | - @Override | ||
| 25 | - public LoginUser mockLogin(Long userId) { | ||
| 26 | - return null; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - @Override | ||
| 30 | - public void logout(String token) { | ||
| 31 | - | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
| 36 | - return null; | ||
| 37 | - } | ||
| 38 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.member.controller; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.http
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/user/SysUserProfileController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.member.controller.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | ||
| 5 | +import io.swagger.annotations.Api; | ||
| 6 | +import io.swagger.annotations.ApiOperation; | ||
| 7 | +import lombok.extern.slf4j.Slf4j; | ||
| 8 | +import org.springframework.validation.annotation.Validated; | ||
| 9 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 11 | +import org.springframework.web.bind.annotation.RestController; | ||
| 12 | + | ||
| 13 | +@Api(tags = "用户个人中心") | ||
| 14 | +@RestController | ||
| 15 | +@RequestMapping("/system/user/profile") | ||
| 16 | +@Validated | ||
| 17 | +@Slf4j | ||
| 18 | +public class SysUserProfileController { | ||
| 19 | + | ||
| 20 | + @GetMapping("/get") | ||
| 21 | + @ApiOperation("获得登录用户信息") | ||
| 22 | + @PreAuthenticated | ||
| 23 | + public CommonResult<Boolean> profile() { | ||
| 24 | + return null; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/package-info.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md
0 → 100644
| 1 | +<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao> |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/dal/mysql/logger/InfApiErrorLogMapper.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java
| 1 | -package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger; | 1 | +package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | -import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO; | ||
| 5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | - * API 错误日志 Mapper | 8 | + * MbrUserDO Mapper |
| 9 | * | 9 | * |
| 10 | * @author 芋道源码 | 10 | * @author 芋道源码 |
| 11 | */ | 11 | */ |
| 12 | @Mapper | 12 | @Mapper |
| 13 | -public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> { | 13 | +public interface MbrUserMapper extends BaseMapperX<MbrUserDO> { |
| 14 | + | ||
| 15 | + default MbrUserDO selectByMobile(String mobile) { | ||
| 16 | + return selectOne("mobile", mobile); | ||
| 17 | + } | ||
| 18 | + | ||
| 14 | } | 19 | } |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/MbrErrorCodeConstants.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.member.service; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.member.service.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.Mobile; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 前台用户 Service 接口 | ||
| 8 | + * | ||
| 9 | + * @author 芋道源码 | ||
| 10 | + */ | ||
| 11 | +public interface MbrUserService { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 通过手机查询用户 | ||
| 15 | + * | ||
| 16 | + * @param mobile 手机 | ||
| 17 | + * @return 用户对象 | ||
| 18 | + */ | ||
| 19 | + MbrUserDO getUserByMobile(String mobile); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 基于手机号创建用户。 | ||
| 23 | + * 如果用户已经存在,则直接进行返回 | ||
| 24 | + * | ||
| 25 | + * @param mobile 手机号 | ||
| 26 | + * @param registerIp 注册 IP | ||
| 27 | + * @return 用户对象 | ||
| 28 | + */ | ||
| 29 | + MbrUserDO createUserIfAbsent(@Mobile String mobile, String registerIp); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 更新用户的最后登陆信息 | ||
| 33 | + * | ||
| 34 | + * @param id 用户编号 | ||
| 35 | + * @param loginIp 登陆 IP | ||
| 36 | + */ | ||
| 37 | + void updateUserLogin(Long id, String loginIp); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 通过用户 ID 查询用户 | ||
| 41 | + * | ||
| 42 | + * @param id 用户ID | ||
| 43 | + * @return 用户对象信息 | ||
| 44 | + */ | ||
| 45 | + MbrUserDO getUser(Long id); | ||
| 46 | + | ||
| 47 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.member.service.user.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.IdUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 5 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 6 | +import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||
| 7 | +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.springframework.security.crypto.password.PasswordEncoder; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | + | ||
| 12 | +import javax.annotation.Resource; | ||
| 13 | +import javax.validation.Valid; | ||
| 14 | +import java.util.Date; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * User Service 实现类 | ||
| 18 | + * | ||
| 19 | + * @author 芋道源码 | ||
| 20 | + */ | ||
| 21 | +@Service | ||
| 22 | +@Valid | ||
| 23 | +@Slf4j | ||
| 24 | +public class MbrUserServiceImpl implements MbrUserService { | ||
| 25 | + | ||
| 26 | + @Resource | ||
| 27 | + private MbrUserMapper userMapper; | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private PasswordEncoder passwordEncoder; | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public MbrUserDO getUserByMobile(String mobile) { | ||
| 34 | + return userMapper.selectByMobile(mobile); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public MbrUserDO createUserIfAbsent(String mobile, String registerIp) { | ||
| 39 | + // 用户已经存在 | ||
| 40 | + MbrUserDO user = userMapper.selectByMobile(mobile); | ||
| 41 | + if (user != null) { | ||
| 42 | + return user; | ||
| 43 | + } | ||
| 44 | + // 用户不存在,则进行创建 | ||
| 45 | + return this.createUser(mobile, registerIp); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private MbrUserDO createUser(String mobile, String registerIp) { | ||
| 49 | + // 生成密码 | ||
| 50 | + String password = IdUtil.fastSimpleUUID(); | ||
| 51 | + // 插入用户 | ||
| 52 | + MbrUserDO user = new MbrUserDO(); | ||
| 53 | + user.setMobile(mobile); | ||
| 54 | + user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 | ||
| 55 | + user.setPassword(passwordEncoder.encode(password)); // 加密密码 | ||
| 56 | + user.setRegisterIp(registerIp); | ||
| 57 | + userMapper.insert(user); | ||
| 58 | + return user; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public void updateUserLogin(Long id, String loginIp) { | ||
| 63 | + userMapper.updateById(new MbrUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public MbrUserDO getUser(Long id) { | ||
| 68 | + return userMapper.selectById(id); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/package-info.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http
0 → 100644
| 1 | +### 请求 /login 接口 => 成功 | ||
| 2 | +POST {{userServerUrl}}/login | ||
| 3 | +Content-Type: application/json | ||
| 4 | + | ||
| 5 | +{ | ||
| 6 | + "mobile": "15601691300", | ||
| 7 | + "password": "admin123" | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +### 请求 /send-sms-code 接口 => 成功 | ||
| 11 | +POST {{userServerUrl}}/send-sms-code | ||
| 12 | +Content-Type: application/json | ||
| 13 | + | ||
| 14 | +{ | ||
| 15 | + "mobile": "15601691399", | ||
| 16 | + "scene": 1 | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +### 请求 /sms-login 接口 => 成功 | ||
| 20 | +POST {{userServerUrl}}/sms-login | ||
| 21 | +Content-Type: application/json | ||
| 22 | + | ||
| 23 | +{ | ||
| 24 | + "mobile": "15601691301", | ||
| 25 | + "code": 9999 | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +### 请求 /logout 接口 => 成功 | ||
| 29 | +POST {{userServerUrl}}/logout | ||
| 30 | +Content-Type: application/json | ||
| 31 | +Authorization: Bearer c1b76bdaf2c146c581caa4d7fd81ee66 |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/MbrAuthController.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.*; | 4 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; |
| 5 | +import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||
| 6 | +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | ||
| 5 | import io.swagger.annotations.Api; | 7 | import io.swagger.annotations.Api; |
| 6 | import io.swagger.annotations.ApiImplicitParam; | 8 | import io.swagger.annotations.ApiImplicitParam; |
| 7 | import io.swagger.annotations.ApiImplicitParams; | 9 | import io.swagger.annotations.ApiImplicitParams; |
| @@ -10,37 +12,46 @@ import lombok.extern.slf4j.Slf4j; | @@ -10,37 +12,46 @@ import lombok.extern.slf4j.Slf4j; | ||
| 10 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| 11 | import org.springframework.web.bind.annotation.*; | 13 | import org.springframework.web.bind.annotation.*; |
| 12 | 14 | ||
| 15 | +import javax.annotation.Resource; | ||
| 13 | import javax.validation.Valid; | 16 | import javax.validation.Valid; |
| 14 | 17 | ||
| 18 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 19 | +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | ||
| 20 | +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getUserAgent; | ||
| 21 | + | ||
| 15 | @Api(tags = "认证") | 22 | @Api(tags = "认证") |
| 16 | @RestController | 23 | @RestController |
| 17 | @RequestMapping("/") | 24 | @RequestMapping("/") |
| 18 | @Validated | 25 | @Validated |
| 19 | @Slf4j | 26 | @Slf4j |
| 20 | -public class MbrAuthController { | 27 | +public class SysAuthController { |
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private SysAuthService authService; | ||
| 31 | + @Resource | ||
| 32 | + private SysSmsCodeService smsCodeService; | ||
| 21 | 33 | ||
| 22 | @PostMapping("/login") | 34 | @PostMapping("/login") |
| 23 | @ApiOperation("使用手机 + 密码登录") | 35 | @ApiOperation("使用手机 + 密码登录") |
| 24 | - public CommonResult<MbrAuthLoginRespVO> login(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { | ||
| 25 | -// String token = authService.login(reqVO, getClientIP(), getUserAgent()); | ||
| 26 | -// // 返回结果 | ||
| 27 | -// return success(MbrAuthLoginRespVO.builder().token(token).build()); | ||
| 28 | - return null; | 36 | + public CommonResult<SysAuthLoginRespVO> login(@RequestBody @Valid SysAuthLoginReqVO reqVO) { |
| 37 | + String token = authService.login(reqVO, getClientIP(), getUserAgent()); | ||
| 38 | + // 返回结果 | ||
| 39 | + return success(SysAuthLoginRespVO.builder().token(token).build()); | ||
| 29 | } | 40 | } |
| 30 | 41 | ||
| 31 | @PostMapping("/sms-login") | 42 | @PostMapping("/sms-login") |
| 32 | @ApiOperation("使用手机 + 验证码登录") | 43 | @ApiOperation("使用手机 + 验证码登录") |
| 33 | - public CommonResult<MbrAuthLoginRespVO> smsLogin(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { | ||
| 34 | - return null; | 44 | + public CommonResult<SysAuthLoginRespVO> smsLogin(@RequestBody @Valid SysAuthSmsLoginReqVO reqVO) { |
| 45 | + String token = authService.smsLogin(reqVO, getClientIP(), getUserAgent()); | ||
| 46 | + // 返回结果 | ||
| 47 | + return success(SysAuthLoginRespVO.builder().token(token).build()); | ||
| 35 | } | 48 | } |
| 36 | 49 | ||
| 37 | @PostMapping("/send-sms-code") | 50 | @PostMapping("/send-sms-code") |
| 38 | @ApiOperation("发送手机验证码") | 51 | @ApiOperation("发送手机验证码") |
| 39 | - public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid MbrAuthSendSmsReqVO reqVO) { | ||
| 40 | -// passportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); | ||
| 41 | -// // 返回成功 | ||
| 42 | -// return success(true); | ||
| 43 | - return null; | 52 | + public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid SysAuthSendSmsReqVO reqVO) { |
| 53 | + smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP()); | ||
| 54 | + return success(true); | ||
| 44 | } | 55 | } |
| 45 | 56 | ||
| 46 | @PostMapping("/reset-password") | 57 | @PostMapping("/reset-password") |
| @@ -65,7 +76,7 @@ public class MbrAuthController { | @@ -65,7 +76,7 @@ public class MbrAuthController { | ||
| 65 | 76 | ||
| 66 | @PostMapping("/social-login") | 77 | @PostMapping("/social-login") |
| 67 | @ApiOperation("社交登录,使用 code 授权码") | 78 | @ApiOperation("社交登录,使用 code 授权码") |
| 68 | - public CommonResult<MbrAuthLoginRespVO> socialLogin(@RequestBody @Valid MbrAuthSocialLoginReqVO reqVO) { | 79 | + public CommonResult<SysAuthLoginRespVO> socialLogin(@RequestBody @Valid MbrAuthSocialLoginReqVO reqVO) { |
| 69 | // String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); | 80 | // String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); |
| 70 | // // 返回结果 | 81 | // // 返回结果 |
| 71 | // return success(MbrAuthLoginRespVO.builder().token(token).build()); | 82 | // return success(MbrAuthLoginRespVO.builder().token(token).build()); |
| @@ -74,7 +85,7 @@ public class MbrAuthController { | @@ -74,7 +85,7 @@ public class MbrAuthController { | ||
| 74 | 85 | ||
| 75 | @PostMapping("/social-login2") | 86 | @PostMapping("/social-login2") |
| 76 | @ApiOperation("社交登录,使用 code 授权码 + 账号密码") | 87 | @ApiOperation("社交登录,使用 code 授权码 + 账号密码") |
| 77 | - public CommonResult<MbrAuthLoginRespVO> socialLogin2(@RequestBody @Valid MbrAuthSocialLogin2ReqVO reqVO) { | 88 | + public CommonResult<SysAuthLoginRespVO> socialLogin2(@RequestBody @Valid MbrAuthSocialLogin2ReqVO reqVO) { |
| 78 | // String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); | 89 | // String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); |
| 79 | // // 返回结果 | 90 | // // 返回结果 |
| 80 | // return success(MbrAuthLoginRespVO.builder().token(token).build()); | 91 | // return success(MbrAuthLoginRespVO.builder().token(token).build()); |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthResetPasswordReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthResetPasswordReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialBindReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialBindReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialLoginReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLoginReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSocialUnbindReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialUnbindReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | 4 | import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 4 | import io.swagger.annotations.ApiModel; | 4 | import io.swagger.annotations.ApiModel; |
| @@ -16,7 +16,7 @@ import javax.validation.constraints.NotEmpty; | @@ -16,7 +16,7 @@ import javax.validation.constraints.NotEmpty; | ||
| 16 | @NoArgsConstructor | 16 | @NoArgsConstructor |
| 17 | @AllArgsConstructor | 17 | @AllArgsConstructor |
| 18 | @Builder | 18 | @Builder |
| 19 | -public class MbrAuthLoginReqVO { | 19 | +public class SysAuthLoginReqVO { |
| 20 | 20 | ||
| 21 | @ApiModelProperty(value = "手机号", required = true, example = "15601691300") | 21 | @ApiModelProperty(value = "手机号", required = true, example = "15601691300") |
| 22 | @NotEmpty(message = "手机号不能为空") | 22 | @NotEmpty(message = "手机号不能为空") |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthLoginRespVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthLoginRespVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
| @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; | @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; | ||
| 12 | @NoArgsConstructor | 12 | @NoArgsConstructor |
| 13 | @AllArgsConstructor | 13 | @AllArgsConstructor |
| 14 | @Builder | 14 | @Builder |
| 15 | -public class MbrAuthLoginRespVO { | 15 | +public class SysAuthLoginRespVO { |
| 16 | 16 | ||
| 17 | @ApiModelProperty(value = "token", required = true, example = "yudaoyuanma") | 17 | @ApiModelProperty(value = "token", required = true, example = "yudaoyuanma") |
| 18 | private String token; | 18 | private String token; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSendSmsReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSendSmsReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 4 | import io.swagger.annotations.ApiModel; | 6 | import io.swagger.annotations.ApiModel; |
| 5 | import io.swagger.annotations.ApiModelProperty; | 7 | import io.swagger.annotations.ApiModelProperty; |
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| @@ -11,7 +13,7 @@ import javax.validation.constraints.NotNull; | @@ -11,7 +13,7 @@ import javax.validation.constraints.NotNull; | ||
| 11 | @ApiModel("发送手机验证码 Response VO") | 13 | @ApiModel("发送手机验证码 Response VO") |
| 12 | @Data | 14 | @Data |
| 13 | @Accessors(chain = true) | 15 | @Accessors(chain = true) |
| 14 | -public class MbrAuthSendSmsReqVO { | 16 | +public class SysAuthSendSmsReqVO { |
| 15 | 17 | ||
| 16 | @ApiModelProperty(value = "手机号", example = "15601691234") | 18 | @ApiModelProperty(value = "手机号", example = "15601691234") |
| 17 | @Mobile | 19 | @Mobile |
| @@ -19,6 +21,7 @@ public class MbrAuthSendSmsReqVO { | @@ -19,6 +21,7 @@ public class MbrAuthSendSmsReqVO { | ||
| 19 | 21 | ||
| 20 | @ApiModelProperty(value = "发送场景", example = "1", notes = "对应 MbrSmsSceneEnum 枚举") | 22 | @ApiModelProperty(value = "发送场景", example = "1", notes = "对应 MbrSmsSceneEnum 枚举") |
| 21 | @NotNull(message = "发送场景不能为空") | 23 | @NotNull(message = "发送场景不能为空") |
| 24 | + @InEnum(SysSmsSceneEnum.class) | ||
| 22 | private Integer scene; | 25 | private Integer scene; |
| 23 | 26 | ||
| 24 | -} | ||
| 25 | \ No newline at end of file | 27 | \ No newline at end of file |
| 28 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/controller/auth/vo/MbrAuthSmsLoginReqVO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/SysAuthSmsLoginReqVO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | 1 | +package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 4 | import io.swagger.annotations.ApiModel; | 4 | import io.swagger.annotations.ApiModel; |
| @@ -17,18 +17,13 @@ import javax.validation.constraints.Pattern; | @@ -17,18 +17,13 @@ import javax.validation.constraints.Pattern; | ||
| 17 | @NoArgsConstructor | 17 | @NoArgsConstructor |
| 18 | @AllArgsConstructor | 18 | @AllArgsConstructor |
| 19 | @Builder | 19 | @Builder |
| 20 | -public class MbrAuthSmsLoginReqVO { | 20 | +public class SysAuthSmsLoginReqVO { |
| 21 | 21 | ||
| 22 | @ApiModelProperty(value = "手机号", required = true, example = "15601691300") | 22 | @ApiModelProperty(value = "手机号", required = true, example = "15601691300") |
| 23 | @NotEmpty(message = "手机号不能为空") | 23 | @NotEmpty(message = "手机号不能为空") |
| 24 | @Mobile | 24 | @Mobile |
| 25 | private String mobile; | 25 | private String mobile; |
| 26 | 26 | ||
| 27 | - @ApiModelProperty(value = "密码", required = true, example = "buzhidao") | ||
| 28 | - @NotEmpty(message = "密码不能为空") | ||
| 29 | - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | ||
| 30 | - private String password; | ||
| 31 | - | ||
| 32 | @ApiModelProperty(value = "手机验证码", required = true, example = "1024") | 27 | @ApiModelProperty(value = "手机验证码", required = true, example = "1024") |
| 33 | @NotEmpty(message = "手机验证码不能为空") | 28 | @NotEmpty(message = "手机验证码不能为空") |
| 34 | @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") | 29 | @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/package-info.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.convert.auth; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 5 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 6 | +import org.mapstruct.Mapper; | ||
| 7 | +import org.mapstruct.Mapping; | ||
| 8 | +import org.mapstruct.factory.Mappers; | ||
| 9 | + | ||
| 10 | +@Mapper | ||
| 11 | +public interface SysAuthConvert { | ||
| 12 | + | ||
| 13 | + SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); | ||
| 14 | + | ||
| 15 | + @Mapping(source = "mobile", target = "username") | ||
| 16 | + LoginUser convert0(MbrUserDO bean); | ||
| 17 | + | ||
| 18 | + default LoginUser convert(MbrUserDO bean) { | ||
| 19 | + // 目的,为了设置 UserTypeEnum.MEMBER.getValue() | ||
| 20 | + return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue()); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/package-info.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md
0 → 100644
| 1 | +<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao> |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/dict/SysDictDataDO.java deleted
| 1 | -package cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | -import lombok.Data; | ||
| 8 | -import lombok.EqualsAndHashCode; | ||
| 9 | - | ||
| 10 | -/** | ||
| 11 | - * 字典数据表 | ||
| 12 | - * | ||
| 13 | - * @author ruoyi | ||
| 14 | - */ | ||
| 15 | -@TableName("sys_dict_data") | ||
| 16 | -@Data | ||
| 17 | -@EqualsAndHashCode(callSuper = true) | ||
| 18 | -public class SysDictDataDO extends BaseDO { | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * 字典数据编号 | ||
| 22 | - */ | ||
| 23 | - @TableId | ||
| 24 | - private Long id; | ||
| 25 | - /** | ||
| 26 | - * 字典排序 | ||
| 27 | - */ | ||
| 28 | - private Integer sort; | ||
| 29 | - /** | ||
| 30 | - * 字典标签 | ||
| 31 | - */ | ||
| 32 | - private String label; | ||
| 33 | - /** | ||
| 34 | - * 字典值 | ||
| 35 | - */ | ||
| 36 | - private String value; | ||
| 37 | - /** | ||
| 38 | - * 字典类型 | ||
| 39 | - * | ||
| 40 | - * 冗余 {@link SysDictDataDO#getDictType()} | ||
| 41 | - */ | ||
| 42 | - private String dictType; | ||
| 43 | - /** | ||
| 44 | - * 状态 | ||
| 45 | - * | ||
| 46 | - * 枚举 {@link CommonStatusEnum} | ||
| 47 | - */ | ||
| 48 | - private Integer status; | ||
| 49 | - /** | ||
| 50 | - * 备注 | ||
| 51 | - */ | ||
| 52 | - private String remark; | ||
| 53 | - | ||
| 54 | -} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/sms/MbrSmsCodeDO.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/dataobject/sms/SysSmsCodeDO.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.dal.mysql.sms; | 1 | +package cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.TableName; | 4 | import com.baomidou.mybatisplus.annotation.TableName; |
| 5 | -import lombok.Data; | ||
| 6 | -import lombok.EqualsAndHashCode; | 5 | +import lombok.*; |
| 7 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
| 8 | 7 | ||
| 9 | import java.util.Date; | 8 | import java.util.Date; |
| @@ -15,11 +14,13 @@ import java.util.Date; | @@ -15,11 +14,13 @@ import java.util.Date; | ||
| 15 | * | 14 | * |
| 16 | * @author 芋道源码 | 15 | * @author 芋道源码 |
| 17 | */ | 16 | */ |
| 18 | -@TableName("mbr_sms_code") | 17 | +@TableName("sys_sms_code") |
| 19 | @Data | 18 | @Data |
| 20 | @EqualsAndHashCode(callSuper = true) | 19 | @EqualsAndHashCode(callSuper = true) |
| 21 | -@Accessors(chain = true) | ||
| 22 | -public class MbrSmsCodeDO extends BaseDO { | 20 | +@Builder |
| 21 | +@NoArgsConstructor | ||
| 22 | +@AllArgsConstructor | ||
| 23 | +public class SysSmsCodeDO extends BaseDO { | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * 编号 | 26 | * 编号 |
| @@ -36,7 +37,7 @@ public class MbrSmsCodeDO extends BaseDO { | @@ -36,7 +37,7 @@ public class MbrSmsCodeDO extends BaseDO { | ||
| 36 | /** | 37 | /** |
| 37 | * 发送场景 | 38 | * 发送场景 |
| 38 | * | 39 | * |
| 39 | - * 枚举 {@link MbrSmsCodeDO} | 40 | + * 枚举 {@link SysSmsCodeDO} |
| 40 | */ | 41 | */ |
| 41 | private Integer scene; | 42 | private Integer scene; |
| 42 | /** | 43 | /** |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/mysql/sms/SysSmsCodeMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | ||
| 5 | +import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 6 | +import org.apache.ibatis.annotations.Mapper; | ||
| 7 | + | ||
| 8 | +@Mapper | ||
| 9 | +public interface SysSmsCodeMapper extends BaseMapperX<SysSmsCodeDO> { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * 获得手机号的最后一个手机验证码 | ||
| 13 | + * | ||
| 14 | + * @param mobile 手机号 | ||
| 15 | + * @param scene 发送场景,选填 | ||
| 16 | + * @return 手机验证码 | ||
| 17 | + */ | ||
| 18 | + default SysSmsCodeDO selectLastByMobile(String mobile, Integer scene) { | ||
| 19 | + return selectOne(new QueryWrapperX<SysSmsCodeDO>() | ||
| 20 | + .eq("mobile", mobile) | ||
| 21 | + .eqIfPresent("scene", scene) | ||
| 22 | + .orderByDesc("id") | ||
| 23 | + .last("LIMIT 1")); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/dal/redis/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.dal.redis; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/SysErrorCodeConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.enums; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * System 错误码枚举类 | ||
| 7 | + * | ||
| 8 | + * system 系统,使用 1-005-000-000 段 | ||
| 9 | + */ | ||
| 10 | +public interface SysErrorCodeConstants { | ||
| 11 | + | ||
| 12 | + // ========== AUTH 模块 1005000000 ========== | ||
| 13 | + ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1005000000, "登录失败,账号密码不正确"); | ||
| 14 | + ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1005000001, "登录失败,账号被禁用"); | ||
| 15 | + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1005000002, "登录失败"); // 登录失败的兜底,未知原因 | ||
| 16 | + ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1005000003, "Token 已经过期"); | ||
| 17 | + | ||
| 18 | + // ========== SMS CODE 模块 1005001000 ========== | ||
| 19 | + ErrorCode USER_SMS_CODE_NOT_FOUND = new ErrorCode(1005001000, "验证码不存在"); | ||
| 20 | + ErrorCode USER_SMS_CODE_EXPIRED = new ErrorCode(1005001001, "验证码已过期"); | ||
| 21 | + ErrorCode USER_SMS_CODE_USED = new ErrorCode(1005001002, "验证码已使用"); | ||
| 22 | + ErrorCode USER_SMS_CODE_NOT_CORRECT = new ErrorCode(1005001003, "验证码不正确"); | ||
| 23 | + ErrorCode USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY = new ErrorCode(1005001004, "超过每日短信发送数量"); | ||
| 24 | + ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1005001005, "短信发送过于频率"); | ||
| 25 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/enums/sms/MbrSmsSceneEnum.java renamed to yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsSceneEnum.java
| 1 | -package cn.iocoder.yudao.userserver.modules.member.enums.sms; | 1 | +package cn.iocoder.yudao.userserver.modules.system.enums.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | 3 | import cn.iocoder.yudao.framework.common.core.IntArrayValuable; |
| 4 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
| @@ -13,13 +13,13 @@ import java.util.Arrays; | @@ -13,13 +13,13 @@ import java.util.Arrays; | ||
| 13 | */ | 13 | */ |
| 14 | @Getter | 14 | @Getter |
| 15 | @AllArgsConstructor | 15 | @AllArgsConstructor |
| 16 | -public enum MbrSmsSceneEnum implements IntArrayValuable { | 16 | +public enum SysSmsSceneEnum implements IntArrayValuable { |
| 17 | 17 | ||
| 18 | LOGIN_BY_SMS(1, "手机号登陆"), | 18 | LOGIN_BY_SMS(1, "手机号登陆"), |
| 19 | CHANGE_MOBILE_BY_SMS(2, "更换手机号"), | 19 | CHANGE_MOBILE_BY_SMS(2, "更换手机号"), |
| 20 | ; | 20 | ; |
| 21 | 21 | ||
| 22 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MbrSmsSceneEnum::getScene).toArray(); | 22 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSmsSceneEnum::getScene).toArray(); |
| 23 | 23 | ||
| 24 | private final Integer scene; | 24 | private final Integer scene; |
| 25 | private final String name; | 25 | private final String name; |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/package-info.java
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.framework.sms; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| 4 | +import org.springframework.context.annotation.Configuration; | ||
| 5 | + | ||
| 6 | +@Configuration | ||
| 7 | +@EnableConfigurationProperties(SmsCodeProperties.class) | ||
| 8 | +public class SmsCodeConfiguration { | ||
| 9 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/framework/sms/SmsCodeProperties.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.framework.sms; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | + | ||
| 7 | +import javax.validation.constraints.NotEmpty; | ||
| 8 | +import javax.validation.constraints.NotNull; | ||
| 9 | +import java.time.Duration; | ||
| 10 | +import java.util.Collection; | ||
| 11 | + | ||
| 12 | +@ConfigurationProperties(prefix = "yudao.sms-code") | ||
| 13 | +@Validated | ||
| 14 | +@Data | ||
| 15 | +public class SmsCodeProperties { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 过期时间 | ||
| 19 | + */ | ||
| 20 | + @NotNull(message = "过期时间不能为空") | ||
| 21 | + private Duration expireTimes; | ||
| 22 | + /** | ||
| 23 | + * 短信发送频率 | ||
| 24 | + */ | ||
| 25 | + @NotNull(message = "短信发送频率不能为空") | ||
| 26 | + private Duration sendFrequency; | ||
| 27 | + /** | ||
| 28 | + * 每日发送最大数量 | ||
| 29 | + */ | ||
| 30 | + @NotNull(message = "每日发送最大数量不能为空") | ||
| 31 | + private Integer sendMaximumQuantityPerDay; | ||
| 32 | + /** | ||
| 33 | + * 验证码最小值 | ||
| 34 | + */ | ||
| 35 | + @NotNull(message = "验证码最小值不能为空") | ||
| 36 | + private Integer beginCode; | ||
| 37 | + /** | ||
| 38 | + * 验证码最大值 | ||
| 39 | + */ | ||
| 40 | + @NotNull(message = "验证码最大值不能为空") | ||
| 41 | + private Integer endCode; | ||
| 42 | + | ||
| 43 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.service.auth; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | ||
| 4 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; | ||
| 5 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthSmsLoginReqVO; | ||
| 6 | + | ||
| 7 | +import javax.validation.Valid; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 用户前台的认证 Service 接口 | ||
| 11 | + * | ||
| 12 | + * 提供用户的账号密码登录、token 的校验等认证相关的功能 | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 手机 + 密码登录 | ||
| 20 | + * | ||
| 21 | + * @param reqVO 登录信息 | ||
| 22 | + * @param userIp 用户 IP | ||
| 23 | + * @param userAgent 用户 UA | ||
| 24 | + * @return 身份令牌,使用 JWT 方式 | ||
| 25 | + */ | ||
| 26 | + String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 手机 + 验证码登陆 | ||
| 30 | + * | ||
| 31 | + * @param reqVO 登陆信息 | ||
| 32 | + * @param userIp 用户 IP | ||
| 33 | + * @param userAgent 用户 UA | ||
| 34 | + * @return 身份令牌,使用 JWT 方式 | ||
| 35 | + */ | ||
| 36 | + String smsLogin(@Valid SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent); | ||
| 37 | + | ||
| 38 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.service.auth.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.lang.Assert; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||
| 9 | +import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; | ||
| 10 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 11 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 12 | +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 13 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||
| 14 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 15 | +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 16 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; | ||
| 17 | +import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthSmsLoginReqVO; | ||
| 18 | +import cn.iocoder.yudao.userserver.modules.system.convert.auth.SysAuthConvert; | ||
| 19 | +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 20 | +import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||
| 21 | +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | ||
| 22 | +import lombok.extern.slf4j.Slf4j; | ||
| 23 | +import org.springframework.context.annotation.Lazy; | ||
| 24 | +import org.springframework.security.authentication.AuthenticationManager; | ||
| 25 | +import org.springframework.security.authentication.BadCredentialsException; | ||
| 26 | +import org.springframework.security.authentication.DisabledException; | ||
| 27 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
| 28 | +import org.springframework.security.core.Authentication; | ||
| 29 | +import org.springframework.security.core.AuthenticationException; | ||
| 30 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 31 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 32 | +import org.springframework.stereotype.Service; | ||
| 33 | +import org.springframework.transaction.annotation.Transactional; | ||
| 34 | + | ||
| 35 | +import javax.annotation.Resource; | ||
| 36 | +import java.util.Objects; | ||
| 37 | + | ||
| 38 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 39 | +import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * Auth Service 实现类 | ||
| 43 | + * | ||
| 44 | + * @author 芋道源码 | ||
| 45 | + */ | ||
| 46 | +@Service | ||
| 47 | +@Slf4j | ||
| 48 | +public class SysAuthServiceImpl implements SysAuthService { | ||
| 49 | + | ||
| 50 | + @Resource | ||
| 51 | + @Lazy // 延迟加载,因为存在相互依赖的问题 | ||
| 52 | + private AuthenticationManager authenticationManager; | ||
| 53 | + | ||
| 54 | + @Resource | ||
| 55 | + private MbrUserService userService; | ||
| 56 | + @Resource | ||
| 57 | + private SysSmsCodeService smsCodeService; | ||
| 58 | + @Resource | ||
| 59 | + private SysLoginLogCoreService loginLogCoreService; | ||
| 60 | + @Resource | ||
| 61 | + private SysUserSessionCoreService userSessionCoreService; | ||
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { | ||
| 65 | + // 获取 username 对应的 SysUserDO | ||
| 66 | + MbrUserDO user = userService.getUserByMobile(mobile); | ||
| 67 | + if (user == null) { | ||
| 68 | + throw new UsernameNotFoundException(mobile); | ||
| 69 | + } | ||
| 70 | + // 创建 LoginUser 对象 | ||
| 71 | + return SysAuthConvert.INSTANCE.convert(user); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent) { | ||
| 76 | + // 使用手机 + 密码,进行登录。 | ||
| 77 | + LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); | ||
| 78 | + | ||
| 79 | + // 缓存登录用户到 Redis 中,返回 sessionId 编号 | ||
| 80 | + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + @Transactional | ||
| 85 | + public String smsLogin(SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent) { | ||
| 86 | + // 校验验证码 | ||
| 87 | + smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(), | ||
| 88 | + reqVO.getCode(), userIp); | ||
| 89 | + | ||
| 90 | + // 获得获得注册用户 | ||
| 91 | + MbrUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp); | ||
| 92 | + Assert.notNull(user, "获取用户失败,结果为空"); | ||
| 93 | + | ||
| 94 | + // 执行登陆 | ||
| 95 | + this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SMS, SysLoginResultEnum.SUCCESS); | ||
| 96 | + LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); | ||
| 97 | + | ||
| 98 | + // 缓存登录用户到 Redis 中,返回 sessionId 编号 | ||
| 99 | + return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + private LoginUser login0(String username, String password) { | ||
| 103 | + final SysLoginLogTypeEnum logTypeEnum = SysLoginLogTypeEnum.LOGIN_USERNAME; | ||
| 104 | + // 用户验证 | ||
| 105 | + Authentication authentication; | ||
| 106 | + try { | ||
| 107 | + // 调用 Spring Security 的 AuthenticationManager#authenticate(...) 方法,使用账号密码进行认证 | ||
| 108 | + // 在其内部,会调用到 loadUserByUsername 方法,获取 User 信息 | ||
| 109 | + authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); | ||
| 110 | + } catch (BadCredentialsException badCredentialsException) { | ||
| 111 | + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.BAD_CREDENTIALS); | ||
| 112 | + throw exception(AUTH_LOGIN_BAD_CREDENTIALS); | ||
| 113 | + } catch (DisabledException disabledException) { | ||
| 114 | + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.USER_DISABLED); | ||
| 115 | + throw exception(AUTH_LOGIN_USER_DISABLED); | ||
| 116 | + } catch (AuthenticationException authenticationException) { | ||
| 117 | + log.error("[login0][username({}) 发生未知异常]", username, authenticationException); | ||
| 118 | + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); | ||
| 119 | + throw exception(AUTH_LOGIN_FAIL_UNKNOWN); | ||
| 120 | + } | ||
| 121 | + // 登录成功的日志 | ||
| 122 | + Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); | ||
| 123 | + this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.SUCCESS); | ||
| 124 | + return (LoginUser) authentication.getPrincipal(); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + private void createLoginLog(String mobile, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { | ||
| 128 | + // 获得用户 | ||
| 129 | + MbrUserDO user = userService.getUserByMobile(mobile); | ||
| 130 | + // 插入登录日志 | ||
| 131 | + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | ||
| 132 | + reqDTO.setLogType(logTypeEnum.getType()); | ||
| 133 | + reqDTO.setTraceId(TracerUtils.getTraceId()); | ||
| 134 | + if (user != null) { | ||
| 135 | + reqDTO.setUserId(user.getId()); | ||
| 136 | + } | ||
| 137 | + reqDTO.setUsername(mobile); | ||
| 138 | + reqDTO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 139 | + reqDTO.setUserIp(ServletUtils.getClientIP()); | ||
| 140 | + reqDTO.setResult(loginResult.getResult()); | ||
| 141 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 142 | + // 更新最后登录时间 | ||
| 143 | + if (user != null && Objects.equals(SysLoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) { | ||
| 144 | + userService.updateUserLogin(user.getId(), ServletUtils.getClientIP()); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public LoginUser verifyTokenAndRefresh(String token) { | ||
| 150 | + // 获得 LoginUser | ||
| 151 | + LoginUser loginUser = userSessionCoreService.getLoginUser(token); | ||
| 152 | + if (loginUser == null) { | ||
| 153 | + return null; | ||
| 154 | + } | ||
| 155 | + // 刷新 LoginUser 缓存 | ||
| 156 | + this.refreshLoginUserCache(token, loginUser); | ||
| 157 | + return loginUser; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + private void refreshLoginUserCache(String token, LoginUser loginUser) { | ||
| 161 | + // 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存 | ||
| 162 | + if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() < | ||
| 163 | + userSessionCoreService.getSessionTimeoutMillis() / 3) { | ||
| 164 | + return; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + // 重新加载 MbrUserDO 信息 | ||
| 168 | + MbrUserDO user = userService.getUser(loginUser.getId()); | ||
| 169 | + if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { | ||
| 170 | + throw exception(AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + // 刷新 LoginUser 缓存 | ||
| 174 | + userSessionCoreService.refreshUserSession(token, loginUser); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public LoginUser mockLogin(Long userId) { | ||
| 179 | + // 获取用户编号对应的 MbrUserDO | ||
| 180 | + MbrUserDO user = userService.getUser(userId); | ||
| 181 | + if (user == null) { | ||
| 182 | + throw new UsernameNotFoundException(String.valueOf(userId)); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + // 执行登陆 | ||
| 186 | + this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS); | ||
| 187 | + | ||
| 188 | + // 创建 LoginUser 对象 | ||
| 189 | + return SysAuthConvert.INSTANCE.convert(user); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + @Override | ||
| 193 | + public void logout(String token) { | ||
| 194 | + // 查询用户信息 | ||
| 195 | + LoginUser loginUser = userSessionCoreService.getLoginUser(token); | ||
| 196 | + if (loginUser == null) { | ||
| 197 | + return; | ||
| 198 | + } | ||
| 199 | + // 删除 session | ||
| 200 | + userSessionCoreService.deleteUserSession(token); | ||
| 201 | + // 记录登出日志 | ||
| 202 | + this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + private void createLogoutLog(Long userId, String username) { | ||
| 206 | + SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | ||
| 207 | + reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | ||
| 208 | + reqDTO.setTraceId(TracerUtils.getTraceId()); | ||
| 209 | + reqDTO.setUserId(userId); | ||
| 210 | + reqDTO.setUserType(UserTypeEnum.MEMBER.getValue()); | ||
| 211 | + reqDTO.setUsername(username); | ||
| 212 | + reqDTO.setUserAgent(ServletUtils.getUserAgent()); | ||
| 213 | + reqDTO.setUserIp(ServletUtils.getClientIP()); | ||
| 214 | + reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult()); | ||
| 215 | + loginLogCoreService.createLoginLog(reqDTO); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/package-info.java
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/SysSmsCodeService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.service.sms; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.exception.ServiceException; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.Mobile; | ||
| 5 | +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 短信验证码 Service 接口 | ||
| 9 | + * | ||
| 10 | + * @author 芋道源码 | ||
| 11 | + */ | ||
| 12 | +public interface SysSmsCodeService { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 创建短信验证码,并进行发送 | ||
| 16 | + * | ||
| 17 | + * @param mobile 手机号 | ||
| 18 | + * @param scene 发送场景 {@link SysSmsSceneEnum} | ||
| 19 | + * @param createIp 发送 IP | ||
| 20 | + */ | ||
| 21 | + void sendSmsCode(@Mobile String mobile, Integer scene, String createIp); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 验证短信验证码,并进行使用 | ||
| 25 | + * 如果正确,则将验证码标记成已使用 | ||
| 26 | + * 如果错误,则抛出 {@link ServiceException} 异常 | ||
| 27 | + * | ||
| 28 | + * @param mobile 手机号 | ||
| 29 | + * @param scene 发送场景 | ||
| 30 | + * @param code 验证码 | ||
| 31 | + * @param usedIp 使用 IP | ||
| 32 | + */ | ||
| 33 | + void useSmsCode(@Mobile String mobile, Integer scene, String code, String usedIp); | ||
| 34 | + | ||
| 35 | +} |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.userserver.modules.system.service.sms.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.map.MapUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | ||
| 5 | +import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 6 | +import cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms.SysSmsCodeMapper; | ||
| 7 | +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsTemplateCodeConstants; | ||
| 8 | +import cn.iocoder.yudao.userserver.modules.system.framework.sms.SmsCodeProperties; | ||
| 9 | +import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.util.Date; | ||
| 15 | + | ||
| 16 | +import static cn.hutool.core.util.RandomUtil.randomInt; | ||
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 18 | +import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 短信验证码 Service 实现类 | ||
| 22 | + * | ||
| 23 | + * @author 芋道源码 | ||
| 24 | + */ | ||
| 25 | +@Service | ||
| 26 | +@Validated | ||
| 27 | +public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private SmsCodeProperties smsCodeProperties; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private SysSmsCodeMapper smsCodeMapper; | ||
| 34 | + | ||
| 35 | + @Resource | ||
| 36 | + private SysSmsCoreService smsCoreService; | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + public void sendSmsCode(String mobile, Integer scene, String createIp) { | ||
| 40 | + // 创建验证码 | ||
| 41 | + String code = this.createSmsCode(mobile, scene, createIp); | ||
| 42 | + // 发送验证码 | ||
| 43 | + smsCoreService.sendSingleSmsToMember(mobile, null, SysSmsTemplateCodeConstants.USER_SMS_LOGIN, | ||
| 44 | + MapUtil.of("code", code)); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + private String createSmsCode(String mobile, Integer scene, String ip) { | ||
| 48 | + // 校验是否可以发送验证码,不用筛选场景 | ||
| 49 | + SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null); | ||
| 50 | + if (lastSmsCode != null) { | ||
| 51 | + if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 | ||
| 52 | + throw exception(USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); | ||
| 53 | + } | ||
| 54 | + if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() | ||
| 55 | + < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 | ||
| 56 | + throw exception(USER_SMS_CODE_SEND_TOO_FAST); | ||
| 57 | + } | ||
| 58 | + // TODO 芋艿:提升,每个 IP 每天可发送数量 | ||
| 59 | + // TODO 芋艿:提升,每个 IP 每小时可发送数量 | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + // 创建验证码记录 | ||
| 63 | + String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1)); | ||
| 64 | + SysSmsCodeDO newSmsCode = SysSmsCodeDO.builder().mobile(mobile).code(code) | ||
| 65 | + .scene(scene).todayIndex(lastSmsCode != null ? lastSmsCode.getTodayIndex() + 1 : 1) | ||
| 66 | + .createIp(ip).used(false).build(); | ||
| 67 | + smsCodeMapper.insert(newSmsCode); | ||
| 68 | + return code; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void useSmsCode(String mobile, Integer scene, String code, String usedIp) { | ||
| 73 | + // 校验验证码 | ||
| 74 | + SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, scene); | ||
| 75 | + if (lastSmsCode == null) { // 若验证码不存在,抛出异常 | ||
| 76 | + throw exception(USER_SMS_CODE_NOT_FOUND); | ||
| 77 | + } | ||
| 78 | + if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() | ||
| 79 | + >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 | ||
| 80 | + throw exception(USER_SMS_CODE_EXPIRED); | ||
| 81 | + } | ||
| 82 | + if (lastSmsCode.getUsed()) { // 验证码已使用 | ||
| 83 | + throw exception(USER_SMS_CODE_USED); | ||
| 84 | + } | ||
| 85 | + if (!lastSmsCode.getCode().equals(code)) { | ||
| 86 | + throw exception(USER_SMS_CODE_NOT_CORRECT); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // 使用验证码 | ||
| 90 | + smsCodeMapper.updateById(SysSmsCodeDO.builder().id(lastSmsCode.getId()) | ||
| 91 | + .used(true).usedTime(new Date()).usedIp(usedIp).build()); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | +} |
yudao-user-server/src/main/resources/application-dev.yaml
| @@ -72,7 +72,7 @@ apollo: | @@ -72,7 +72,7 @@ apollo: | ||
| 72 | eagerLoad: | 72 | eagerLoad: |
| 73 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 | 73 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 |
| 74 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 | 74 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 |
| 75 | - dao: cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config.InfConfigDAOImpl | 75 | + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl |
| 76 | url: ${spring.datasource.dynamic.datasource.master.url} | 76 | url: ${spring.datasource.dynamic.datasource.master.url} |
| 77 | username: ${spring.datasource.dynamic.datasource.master.username} | 77 | username: ${spring.datasource.dynamic.datasource.master.username} |
| 78 | password: ${spring.datasource.dynamic.datasource.master.password} | 78 | password: ${spring.datasource.dynamic.datasource.master.password} |
yudao-user-server/src/main/resources/application-local.yaml
| @@ -72,7 +72,7 @@ apollo: | @@ -72,7 +72,7 @@ apollo: | ||
| 72 | eagerLoad: | 72 | eagerLoad: |
| 73 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 | 73 | enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 |
| 74 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 | 74 | jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 |
| 75 | - dao: cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config.InfConfigDAOImpl | 75 | + dao: cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.config.InfConfigCoreDAOImpl |
| 76 | url: ${spring.datasource.dynamic.datasource.master.url} | 76 | url: ${spring.datasource.dynamic.datasource.master.url} |
| 77 | username: ${spring.datasource.dynamic.datasource.master.username} | 77 | username: ${spring.datasource.dynamic.datasource.master.username} |
| 78 | password: ${spring.datasource.dynamic.datasource.master.password} | 78 | password: ${spring.datasource.dynamic.datasource.master.password} |
yudao-user-server/src/main/resources/application.yaml
| @@ -31,7 +31,7 @@ mybatis-plus: | @@ -31,7 +31,7 @@ mybatis-plus: | ||
| 31 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) | 31 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) |
| 32 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) | 32 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) |
| 33 | mapper-locations: classpath*:mapper/*.xml | 33 | mapper-locations: classpath*:mapper/*.xml |
| 34 | - type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject | 34 | + type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject, ${yudao.core-service.base-package}.modules.*.dal.dataobject |
| 35 | 35 | ||
| 36 | --- #################### 芋道相关配置 #################### | 36 | --- #################### 芋道相关配置 #################### |
| 37 | 37 | ||
| @@ -39,6 +39,8 @@ yudao: | @@ -39,6 +39,8 @@ yudao: | ||
| 39 | info: | 39 | info: |
| 40 | version: 1.0.0 | 40 | version: 1.0.0 |
| 41 | base-package: cn.iocoder.yudao.userserver | 41 | base-package: cn.iocoder.yudao.userserver |
| 42 | + core-service: | ||
| 43 | + base-package: cn.iocoder.yudao.coreservice | ||
| 42 | web: | 44 | web: |
| 43 | api-prefix: /api | 45 | api-prefix: /api |
| 44 | controller-package: ${yudao.info.base-package} | 46 | controller-package: ${yudao.info.base-package} |
| @@ -56,5 +58,13 @@ yudao: | @@ -56,5 +58,13 @@ yudao: | ||
| 56 | db-schemas: ${spring.datasource.dynamic.datasource.master.name} | 58 | db-schemas: ${spring.datasource.dynamic.datasource.master.name} |
| 57 | error-code: # 错误码相关配置项 | 59 | error-code: # 错误码相关配置项 |
| 58 | constants-class-list: | 60 | constants-class-list: |
| 61 | + - cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants | ||
| 62 | + - cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants | ||
| 63 | + sms-code: # 短信验证码相关的配置项 | ||
| 64 | + expire-times: 10m | ||
| 65 | + send-frequency: 1m | ||
| 66 | + send-maximum-quantity-per-day: 10 | ||
| 67 | + begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 | ||
| 68 | + end-code: 9999 # 这里配置 9999 的原因是,测试方便。 | ||
| 59 | 69 | ||
| 60 | debug: false | 70 | debug: false |
更新日志.md
| @@ -7,10 +7,20 @@ | @@ -7,10 +7,20 @@ | ||
| 7 | 7 | ||
| 8 | * 工作流 | 8 | * 工作流 |
| 9 | 9 | ||
| 10 | -## [v1.1.0] 待定 | 10 | +## [v1.1.1] 待定 |
| 11 | 11 | ||
| 12 | * 支付 | 12 | * 支付 |
| 13 | -* 三方平台接入 | 13 | +* 用户前台的社交登陆 |
| 14 | + | ||
| 15 | +## [v1.1.0] 进行中 | ||
| 16 | + | ||
| 17 | +* 新增管理后台的企业微信、钉钉等社交登录 | ||
| 18 | +* 新增用户前台(例如说,用户使用的小程序)的后端项目 `yudao-user-server` | ||
| 19 | +* 新增公共服务 `yudao-core-service` 项目,通过 Jar 包的方式,提供 `yudao-user-server` 和 `yudao-admin-server` 的共享逻辑的复用 | ||
| 20 | +* 新增用户前台的手机登录、验证码登录 | ||
| 21 | +* 修复管理后台的用户头像上传 404 的问题,原因是请求路径不对 | ||
| 22 | +* 修复用户导入失败的问题,原因是 Lombok 链式与 cglib 读取属性有冲突 | ||
| 23 | +* 修复阿里云短信发送失败的问题,原因是 Opentracing 依赖的版本太低,调整成 0.31.0 | ||
| 14 | 24 | ||
| 15 | ## [v1.0.0] 2021.05.03 | 25 | ## [v1.0.0] 2021.05.03 |
| 16 | 26 |