mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
多模块重构 4:system 模块的调整,实现 social API~~
This commit is contained in:
parent
ab6ec2f0ed
commit
add08b1ecd
@ -1,20 +1,24 @@
|
||||
package cn.iocoder.yudao.framework.common.enums;
|
||||
|
||||
import cn.hutool.core.lang.Matcher;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 全局用户类型枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum UserTypeEnum {
|
||||
public enum UserTypeEnum implements IntArrayValuable {
|
||||
|
||||
MEMBER(1, "会员"), // 面向 c 端,普通用户
|
||||
ADMIN(2, "管理员"); // 面向 b 端,管理后台
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserTypeEnum::getValue).toArray();
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@ -28,4 +32,8 @@ public enum UserTypeEnum {
|
||||
return ArrayUtil.firstMatch(userType -> userType.getValue().equals(value), UserTypeEnum.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface UserApi {
|
||||
public interface MemberUserApi {
|
||||
|
||||
/**
|
||||
* 获得会员用户信息
|
@ -1,12 +1,14 @@
|
||||
package cn.iocoder.yudao.module.member.api.user.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户信息 Response DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class UserRespDTO {
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.member.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* Member 错误码枚举类
|
||||
*
|
||||
* member 系统,使用 1-004-000-000 段
|
||||
*/
|
||||
public interface ErrorCodeConstants {
|
||||
|
||||
// ========== 用户相关 1004001000============
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在");
|
||||
ErrorCode USER_PASSWORD_FAILED = new ErrorCode(1004001001, "密码校验失败");
|
||||
|
||||
// ========== 文件相关 1004002000 ===========
|
||||
// TODO 芋艿:可以删除
|
||||
ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件为空");
|
||||
|
||||
// ========== AUTH 模块 1004003000 ==========
|
||||
ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确");
|
||||
ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1004003001, "登录失败,账号被禁用");
|
||||
ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1004003002, "登录失败"); // 登录失败的兜底,未知原因
|
||||
ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1004003004, "Token 已经过期");
|
||||
ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1004003005, "未绑定账号,需要进行绑定");
|
||||
|
||||
}
|
@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.member.api.user;
|
||||
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
|
||||
import cn.iocoder.yudao.module.member.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -16,14 +16,14 @@ import javax.annotation.Resource;
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class UserApiImpl implements UserApi {
|
||||
public class MemberUserApiImpl implements MemberUserApi {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private MemberUserService userService;
|
||||
|
||||
@Override
|
||||
public UserRespDTO getUser(Long id) {
|
||||
UserDO user = userService.getUser(id);
|
||||
MemberUserDO user = userService.getUser(id);
|
||||
return UserConvert.INSTANCE.convert2(user);
|
||||
}
|
||||
|
@ -1,18 +1,15 @@
|
||||
package cn.iocoder.yudao.module.member.controller.app.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.*;
|
||||
import cn.iocoder.yudao.module.member.service.auth.AuthService;
|
||||
import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService;
|
||||
import cn.iocoder.yudao.module.member.service.auth.MemberAuthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -31,14 +28,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
||||
@Slf4j
|
||||
public class AppAuthController {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // AuthService 存在重名
|
||||
private AuthService authService;
|
||||
|
||||
@Resource
|
||||
private SysSmsCodeService smsCodeService;
|
||||
@Resource
|
||||
private SysSocialCoreService socialService;
|
||||
private MemberAuthService authService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("使用手机 + 密码登录")
|
||||
@ -62,14 +53,7 @@ public class AppAuthController {
|
||||
@ApiOperation(value = "发送手机验证码")
|
||||
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
||||
public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid AppAuthSendSmsReqVO reqVO) {
|
||||
smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/send-sms-code-login") // TODO 芋艿:post 比较合理
|
||||
@ApiOperation(value = "向已登录用户发送验证码",notes = "修改手机时验证原手机号使用")
|
||||
public CommonResult<Boolean> sendSmsCodeLogin() {
|
||||
smsCodeService.sendSmsCodeLogin(getLoginUserId());
|
||||
authService.sendSmsCode(getLoginUserId(), reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -100,18 +84,18 @@ public class AppAuthController {
|
||||
})
|
||||
public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type,
|
||||
@RequestParam("redirectUri") String redirectUri) {
|
||||
return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri));
|
||||
return CommonResult.success(authService.getSocialAuthorizeUrl(type, redirectUri));
|
||||
}
|
||||
|
||||
@PostMapping("/social-login")
|
||||
@ApiOperation("社交登录,使用 code 授权码")
|
||||
@ApiOperation(value = "社交登录,使用 code 授权码", notes = "适合未登录的用户,但是社交账号已绑定用户")
|
||||
public CommonResult<AppAuthLoginRespVO> socialLogin(@RequestBody @Valid AppAuthSocialLoginReqVO reqVO) {
|
||||
String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent());
|
||||
return success(AppAuthLoginRespVO.builder().token(token).build());
|
||||
}
|
||||
|
||||
@PostMapping("/social-login2")
|
||||
@ApiOperation("社交登录,使用 手机号 + 手机验证码")
|
||||
@ApiOperation(value = "社交登录,使用 手机号 + 手机验证码", notes = "适合未登录的用户,进行登录 + 绑定")
|
||||
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
||||
public CommonResult<AppAuthLoginRespVO> socialLogin2(@RequestBody @Valid AppAuthSocialLogin2ReqVO reqVO) {
|
||||
String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent());
|
||||
@ -119,7 +103,7 @@ public class AppAuthController {
|
||||
}
|
||||
|
||||
@PostMapping("/social-bind")
|
||||
@ApiOperation("社交绑定,使用 code 授权码")
|
||||
@ApiOperation(value = "社交绑定,使用 code 授权码", notes = "使用在用户已经登录的情况下")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> socialBind(@RequestBody @Valid AppAuthSocialBindReqVO reqVO) {
|
||||
authService.socialBind(getLoginUserId(), reqVO);
|
||||
@ -130,7 +114,7 @@ public class AppAuthController {
|
||||
@ApiOperation("取消社交绑定")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> socialUnbind(@RequestBody AppAuthSocialUnbindReqVO reqVO) {
|
||||
socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.MEMBER);
|
||||
authService.unbindSocialUser(getLoginUserId(), reqVO);
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -36,7 +36,7 @@ public class AppAuthCheckCodeReqVO {
|
||||
|
||||
@ApiModelProperty(value = "发送场景", example = "1", notes = "对应 MbrSmsSceneEnum 枚举")
|
||||
@NotNull(message = "发送场景不能为空")
|
||||
@InEnum(SysSmsSceneEnum.class)
|
||||
@InEnum(SmsSceneEnum.class)
|
||||
private Integer scene;
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -21,7 +21,7 @@ public class AppAuthSendSmsReqVO {
|
||||
|
||||
@ApiModelProperty(value = "发送场景", example = "1", notes = "对应 MbrSmsSceneEnum 枚举")
|
||||
@NotNull(message = "发送场景不能为空")
|
||||
@InEnum(SysSmsSceneEnum.class)
|
||||
@InEnum(SmsSceneEnum.class)
|
||||
private Integer scene;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.member.controller.app.auth.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -19,7 +20,7 @@ import javax.validation.constraints.NotNull;
|
||||
public class AppAuthSocialBindReqVO {
|
||||
|
||||
@ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值")
|
||||
@InEnum(SysSocialTypeEnum.class)
|
||||
@InEnum(SocialTypeEnum.class)
|
||||
@NotNull(message = "社交平台的类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
|
@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -21,7 +21,7 @@ import java.io.IOException;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.member.enums.MemberErrorCodeConstants.FILE_IS_EMPTY;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
@Api(tags = "用户 APP - 用户个人中心")
|
||||
@RestController
|
||||
@ -31,7 +31,7 @@ import static cn.iocoder.yudao.module.member.enums.MemberErrorCodeConstants.FILE
|
||||
public class AppUserController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private MemberUserService userService;
|
||||
|
||||
@PutMapping("/update-nickname")
|
||||
@ApiOperation("修改用户昵称")
|
||||
@ -56,7 +56,7 @@ public class AppUserController {
|
||||
@ApiOperation("获得基本信息")
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppUserInfoRespVO> getUserInfo() {
|
||||
UserDO user = userService.getUser(getLoginUserId());
|
||||
MemberUserDO user = userService.getUser(getLoginUserId());
|
||||
return success(UserConvert.INSTANCE.convert(user));
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,13 @@ package cn.iocoder.yudao.module.member.convert.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthSocialBindReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthSocialLogin2ReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthSocialLoginReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthSocialUnbindReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@ -13,11 +19,16 @@ public interface AuthConvert {
|
||||
AuthConvert INSTANCE = Mappers.getMapper(AuthConvert.class);
|
||||
|
||||
@Mapping(source = "mobile", target = "username")
|
||||
LoginUser convert0(UserDO bean);
|
||||
LoginUser convert0(MemberUserDO bean);
|
||||
|
||||
default LoginUser convert(UserDO bean) {
|
||||
default LoginUser convert(MemberUserDO bean) {
|
||||
// 目的,为了设置 UserTypeEnum.MEMBER.getValue()
|
||||
return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue());
|
||||
}
|
||||
|
||||
SocialUserBindReqDTO convert(Long userId, Integer value, AppAuthSocialBindReqVO reqVO);
|
||||
SocialUserBindReqDTO convert(Long userId, Integer value, AppAuthSocialLogin2ReqVO reqVO);
|
||||
SocialUserBindReqDTO convert(Long userId, Integer value, AppAuthSocialLoginReqVO reqVO);
|
||||
SocialUserUnbindReqDTO convert(Long userId, Integer value, AppAuthSocialUnbindReqVO reqVO);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.convert.user;
|
||||
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -11,7 +11,7 @@ public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
AppUserInfoRespVO convert(UserDO bean);
|
||||
AppUserInfoRespVO convert(MemberUserDO bean);
|
||||
|
||||
UserRespDTO convert2(UserDO bean);
|
||||
UserRespDTO convert2(MemberUserDO bean);
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
package cn.iocoder.yudao.module.member.dal.dataobject.address;
|
@ -22,7 +22,7 @@ import java.util.Date;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserDO extends TenantBaseDO {
|
||||
public class MemberUserDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* 用户ID
|
@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.dal.mysql.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
// TODO @芋艿:拿到 system 模块下
|
||||
@Mapper
|
||||
public interface SysSmsCodeMapper extends BaseMapperX<SysSmsCodeDO> {
|
||||
|
||||
/**
|
||||
* 获得手机号的最后一个手机验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param scene 发送场景,选填
|
||||
* @param code 验证码 选填
|
||||
* @return 手机验证码
|
||||
*/
|
||||
default SysSmsCodeDO selectLastByMobile(String mobile,String code,Integer scene) {
|
||||
return selectOne(new QueryWrapperX<SysSmsCodeDO>()
|
||||
.eq("mobile", mobile)
|
||||
.eqIfPresent("scene", scene)
|
||||
.eqIfPresent("code", code)
|
||||
.orderByDesc("id")
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.member.dal.mysql.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 会员 User Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface MemberUserMapper extends BaseMapperX<MemberUserDO> {
|
||||
|
||||
default MemberUserDO selectByMobile(String mobile) {
|
||||
return selectOne(MemberUserDO::getMobile, mobile);
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.dal.mysql.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 会员 User Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapperX<UserDO> {
|
||||
|
||||
default UserDO selectByMobile(String mobile) {
|
||||
return selectOne(UserDO::getMobile, mobile);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* Member 错误码枚举类
|
||||
*
|
||||
* member 系统,使用 1-004-000-000 段
|
||||
*/
|
||||
public interface MemberErrorCodeConstants {
|
||||
|
||||
// ==========用户相关 1004001000============
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在");
|
||||
|
||||
// ==========文件相关 1004002000 ===========
|
||||
ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件为空");
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* System 错误码枚举类
|
||||
*
|
||||
* system 系统,使用 1-005-000-000 段
|
||||
*/
|
||||
public interface SysErrorCodeConstants {
|
||||
|
||||
// ========== AUTH 模块 1005000000 ==========
|
||||
ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1005000000, "登录失败,账号密码不正确");
|
||||
ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1005000001, "登录失败,账号被禁用");
|
||||
ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1005000002, "登录失败"); // 登录失败的兜底,未知原因
|
||||
ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1005000003, "Token 已经过期");
|
||||
ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1005000004, "未绑定账号,需要进行绑定");
|
||||
|
||||
// ========== SMS CODE 模块 1005001000 ==========
|
||||
ErrorCode USER_SMS_CODE_NOT_FOUND = new ErrorCode(1005001000, "验证码不存在");
|
||||
ErrorCode USER_SMS_CODE_EXPIRED = new ErrorCode(1005001001, "验证码已过期");
|
||||
ErrorCode USER_SMS_CODE_USED = new ErrorCode(1005001002, "验证码已使用");
|
||||
ErrorCode USER_SMS_CODE_NOT_CORRECT = new ErrorCode(1005001003, "验证码不正确");
|
||||
ErrorCode USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY = new ErrorCode(1005001004, "超过每日短信发送数量");
|
||||
ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1005001005, "短信发送过于频率");
|
||||
ErrorCode USER_SMS_CODE_IS_EXISTS = new ErrorCode(1005001006, "手机号已被使用");
|
||||
ErrorCode USER_SMS_CODE_IS_UNUSED = new ErrorCode(1005001006, "验证码未被使用");
|
||||
|
||||
// ========== 用户模块 1005002000 ==========
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1005002001, "用户不存在");
|
||||
ErrorCode USER_PASSWORD_FAILED = new ErrorCode(1005002003, "密码校验失败");
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package cn.iocoder.yudao.module.member.enums;
|
@ -1,54 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.enums.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 用户短信验证码发送场景的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SysSmsSceneEnum implements IntArrayValuable {
|
||||
|
||||
LOGIN_BY_SMS(1,SysSmsTemplateCodeConstants.USER_SMS_LOGIN, "手机号登陆"),
|
||||
CHANGE_MOBILE_BY_SMS(2,SysSmsTemplateCodeConstants.USER_SMS_UPDATE_MOBILE, "更换手机号"),
|
||||
FORGET_MOBILE_BY_SMS(3,SysSmsTemplateCodeConstants.USER_SMS_RESET_PASSWORD, "忘记密码"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSmsSceneEnum::getScene).toArray();
|
||||
|
||||
/**
|
||||
* 验证那场景编号
|
||||
*/
|
||||
private final Integer scene;
|
||||
|
||||
/**
|
||||
* 模版编码
|
||||
*/
|
||||
private final String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static String getCodeByScene(Integer scene){
|
||||
for (SysSmsSceneEnum value : values()) {
|
||||
if (value.getScene().equals(scene)){
|
||||
return value.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.enums.sms;
|
||||
|
||||
/**
|
||||
* yudao-user-server 使用到的短信模板的 Code 编码的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysSmsTemplateCodeConstants {
|
||||
|
||||
/**
|
||||
* 前台用户短信登录
|
||||
*/
|
||||
String USER_SMS_LOGIN = "user-sms-login";
|
||||
|
||||
/**
|
||||
* 用户忘记密码
|
||||
*/
|
||||
String USER_SMS_RESET_PASSWORD = "user-sms-reset-password";
|
||||
|
||||
/**
|
||||
* 用户更新手机号
|
||||
*/
|
||||
String USER_SMS_UPDATE_MOBILE = "user-sms-update-mobile";
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import javax.validation.Valid;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface AuthService extends SecurityAuthFrameworkService {
|
||||
public interface MemberAuthService extends SecurityAuthFrameworkService {
|
||||
|
||||
/**
|
||||
* 手机 + 密码登录
|
||||
@ -63,6 +63,23 @@ public interface AuthService extends SecurityAuthFrameworkService {
|
||||
*/
|
||||
void socialBind(Long userId, @Valid AppAuthSocialBindReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 取消社交绑定
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 解绑信息
|
||||
*/
|
||||
void unbindSocialUser(Long userId, @Valid AppAuthSocialUnbindReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得社交认证 URL
|
||||
*
|
||||
* @param type 社交平台类型
|
||||
* @param redirectUri 跳转地址
|
||||
* @return 认证 URL
|
||||
*/
|
||||
String getSocialAuthorizeUrl(Integer type, String redirectUri);
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param userId 用户id
|
||||
@ -76,4 +93,12 @@ public interface AuthService extends SecurityAuthFrameworkService {
|
||||
*/
|
||||
void resetPassword(AppAuthResetPasswordReqVO userReqVO);
|
||||
|
||||
/**
|
||||
* 给用户发送短信验证码
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 发送信息
|
||||
*/
|
||||
void sendSmsCode(Long userId, AppAuthSendSmsReqVO reqVO);
|
||||
|
||||
}
|
@ -1,14 +1,6 @@
|
||||
package cn.iocoder.yudao.module.member.service.auth;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.SysLoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.SysLoginResultEnum;
|
||||
import cn.iocoder.yudao.module.system.service.auth.SysUserSessionCoreService;
|
||||
import cn.iocoder.yudao.module.system.service.logger.SysLoginLogCoreService;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.SysLoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.service.social.SysSocialCoreService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
|
||||
@ -17,14 +9,18 @@ import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.*;
|
||||
import cn.iocoder.yudao.module.member.convert.auth.AuthConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService;
|
||||
import cn.iocoder.yudao.module.member.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import cn.iocoder.yudao.module.system.api.auth.UserSessionApi;
|
||||
import cn.iocoder.yudao.module.system.api.logger.LoginLogApi;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
@ -38,46 +34,45 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 会员的认证 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service("memberAuthService")
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
public class MemberAuthServiceImpl implements MemberAuthService {
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,因为存在相互依赖的问题
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private MemberUserService userService;
|
||||
@Resource
|
||||
private SysSmsCodeService smsCodeService;
|
||||
@Resource
|
||||
private SysLoginLogCoreService loginLogCoreService;
|
||||
private LoginLogApi loginLogApi;
|
||||
@Resource
|
||||
private SysUserSessionCoreService userSessionCoreService;
|
||||
private UserSessionApi userSessionApi;
|
||||
@Resource
|
||||
private SysSocialCoreService socialService;
|
||||
private SocialUserApi socialUserApi;
|
||||
|
||||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
private MemberUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
|
||||
// 获取 username 对应的 SysUserDO
|
||||
UserDO user = userService.getUserByMobile(mobile);
|
||||
MemberUserDO user = userService.getUserByMobile(mobile);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(mobile);
|
||||
}
|
||||
@ -91,86 +86,87 @@ public class AuthServiceImpl implements AuthService {
|
||||
LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword());
|
||||
|
||||
// 缓存登录用户到 Redis 中,返回 sessionId 编号
|
||||
return userSessionCoreService.createUserSession(loginUser, userIp, userAgent);
|
||||
return userSessionApi.createUserSession(loginUser, userIp, userAgent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String smsLogin(AppAuthSmsLoginReqVO reqVO, String userIp, String userAgent) {
|
||||
// 校验验证码
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(),
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(), SmsSceneEnum.MEMBER_LOGIN.getScene(),
|
||||
reqVO.getCode(), userIp);
|
||||
|
||||
// 获得获得注册用户
|
||||
UserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp);
|
||||
MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp);
|
||||
Assert.notNull(user, "获取用户失败,结果为空");
|
||||
|
||||
// 执行登陆
|
||||
this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SMS, SysLoginResultEnum.SUCCESS);
|
||||
this.createLoginLog(user.getMobile(), LoginLogTypeEnum.LOGIN_SMS, LoginResultEnum.SUCCESS);
|
||||
LoginUser loginUser = AuthConvert.INSTANCE.convert(user);
|
||||
|
||||
// 缓存登录用户到 Redis 中,返回 sessionId 编号
|
||||
return userSessionCoreService.createUserSession(loginUser, userIp, userAgent);
|
||||
return userSessionApi.createUserSession(loginUser, userIp, userAgent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String socialLogin(AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent) {
|
||||
// 使用 code 授权码,进行登录
|
||||
AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState());
|
||||
org.springframework.util.Assert.notNull(authUser, "授权用户不为空");
|
||||
|
||||
// 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错
|
||||
String unionId = socialService.getAuthUserUnionId(authUser);
|
||||
List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, getUserType());
|
||||
if (CollUtil.isEmpty(socialUsers)) {
|
||||
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
||||
Long userId = socialUserApi.getBindUserId(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
||||
reqVO.getCode(), reqVO.getState());
|
||||
if (userId == null) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
|
||||
// 自动登录
|
||||
UserDO user = userService.getUser(socialUsers.get(0).getUserId());
|
||||
MemberUserDO user = userService.getUser(userId);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SOCIAL, SysLoginResultEnum.SUCCESS);
|
||||
this.createLoginLog(user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, LoginResultEnum.SUCCESS);
|
||||
|
||||
// 创建 LoginUser 对象
|
||||
LoginUser loginUser = AuthConvert.INSTANCE.convert(user);
|
||||
|
||||
// 绑定社交用户(更新)
|
||||
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType());
|
||||
socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO));
|
||||
|
||||
// 缓存登录用户到 Redis 中,返回 sessionId 编号
|
||||
return userSessionCoreService.createUserSession(loginUser, userIp, userAgent);
|
||||
return userSessionApi.createUserSession(loginUser, userIp, userAgent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String socialLogin2(AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) {
|
||||
AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState());
|
||||
org.springframework.util.Assert.notNull(authUser, "授权用户不为空");
|
||||
// 校验社交平台的认证信息是否正确
|
||||
socialUserApi.checkSocialUser(reqVO.getType(), reqVO.getCode(), reqVO.getState());
|
||||
|
||||
// 使用手机号、手机验证码登录
|
||||
AppAuthSmsLoginReqVO loginReqVO = AppAuthSmsLoginReqVO.builder()
|
||||
.mobile(reqVO.getMobile()).code(reqVO.getSmsCode()).build();
|
||||
String sessionId = this.smsLogin(loginReqVO, userIp, userAgent);
|
||||
LoginUser loginUser = userSessionCoreService.getLoginUser(sessionId);
|
||||
LoginUser loginUser = userSessionApi.getLoginUser(sessionId);
|
||||
|
||||
// 绑定社交用户(新增)
|
||||
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType());
|
||||
socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO));
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void socialBind(Long userId, AppAuthSocialBindReqVO reqVO) {
|
||||
// 使用 code 授权码,进行登录
|
||||
AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState());
|
||||
org.springframework.util.Assert.notNull(authUser, "授权用户不为空");
|
||||
socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO));
|
||||
}
|
||||
|
||||
// 绑定社交用户(新增)
|
||||
socialService.bindSocialUser(userId, reqVO.getType(), authUser, getUserType());
|
||||
@Override
|
||||
public void unbindSocialUser(Long userId, AppAuthSocialUnbindReqVO reqVO) {
|
||||
socialUserApi.unbindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSocialAuthorizeUrl(Integer type, String redirectUri) {
|
||||
return socialUserApi.getAuthorizeUrl(type, redirectUri);
|
||||
}
|
||||
|
||||
private LoginUser login0(String username, String password) {
|
||||
final SysLoginLogTypeEnum logTypeEnum = SysLoginLogTypeEnum.LOGIN_USERNAME;
|
||||
final LoginLogTypeEnum logType = LoginLogTypeEnum.LOGIN_USERNAME;
|
||||
// 用户验证
|
||||
Authentication authentication;
|
||||
try {
|
||||
@ -179,28 +175,28 @@ public class AuthServiceImpl implements AuthService {
|
||||
authentication = authenticationManager.authenticate(new MultiUsernamePasswordAuthenticationToken(
|
||||
username, password, getUserType()));
|
||||
} catch (BadCredentialsException badCredentialsException) {
|
||||
this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.BAD_CREDENTIALS);
|
||||
this.createLoginLog(username, logType, LoginResultEnum.BAD_CREDENTIALS);
|
||||
throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
||||
} catch (DisabledException disabledException) {
|
||||
this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.USER_DISABLED);
|
||||
this.createLoginLog(username, logType, LoginResultEnum.USER_DISABLED);
|
||||
throw exception(AUTH_LOGIN_USER_DISABLED);
|
||||
} catch (AuthenticationException authenticationException) {
|
||||
log.error("[login0][username({}) 发生未知异常]", username, authenticationException);
|
||||
this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR);
|
||||
this.createLoginLog(username, logType, LoginResultEnum.UNKNOWN_ERROR);
|
||||
throw exception(AUTH_LOGIN_FAIL_UNKNOWN);
|
||||
}
|
||||
// 登录成功的日志
|
||||
Assert.notNull(authentication.getPrincipal(), "Principal 不会为空");
|
||||
this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.SUCCESS);
|
||||
this.createLoginLog(username, logType, LoginResultEnum.SUCCESS);
|
||||
return (LoginUser) authentication.getPrincipal();
|
||||
}
|
||||
|
||||
private void createLoginLog(String mobile, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) {
|
||||
private void createLoginLog(String mobile, LoginLogTypeEnum logType, LoginResultEnum loginResult) {
|
||||
// 获得用户
|
||||
UserDO user = userService.getUserByMobile(mobile);
|
||||
MemberUserDO user = userService.getUserByMobile(mobile);
|
||||
// 插入登录日志
|
||||
SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(logTypeEnum.getType());
|
||||
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(logType.getType());
|
||||
reqDTO.setTraceId(TracerUtils.getTraceId());
|
||||
if (user != null) {
|
||||
reqDTO.setUserId(user.getId());
|
||||
@ -209,9 +205,9 @@ public class AuthServiceImpl implements AuthService {
|
||||
reqDTO.setUserAgent(ServletUtils.getUserAgent());
|
||||
reqDTO.setUserIp(getClientIP());
|
||||
reqDTO.setResult(loginResult.getResult());
|
||||
loginLogCoreService.createLoginLog(reqDTO);
|
||||
loginLogApi.createLoginLog(reqDTO);
|
||||
// 更新最后登录时间
|
||||
if (user != null && Objects.equals(SysLoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
||||
if (user != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
||||
userService.updateUserLogin(user.getId(), getClientIP());
|
||||
}
|
||||
}
|
||||
@ -219,7 +215,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public LoginUser verifyTokenAndRefresh(String token) {
|
||||
// 获得 LoginUser
|
||||
LoginUser loginUser = userSessionCoreService.getLoginUser(token);
|
||||
LoginUser loginUser = userSessionApi.getLoginUser(token);
|
||||
if (loginUser == null) {
|
||||
return null;
|
||||
}
|
||||
@ -231,31 +227,31 @@ public class AuthServiceImpl implements AuthService {
|
||||
private void refreshLoginUserCache(String token, LoginUser loginUser) {
|
||||
// 每 1/3 的 Session 超时时间,刷新 LoginUser 缓存
|
||||
if (System.currentTimeMillis() - loginUser.getUpdateTime().getTime() <
|
||||
userSessionCoreService.getSessionTimeoutMillis() / 3) {
|
||||
userSessionApi.getSessionTimeoutMillis() / 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 重新加载 UserDO 信息
|
||||
UserDO user = userService.getUser(loginUser.getId());
|
||||
MemberUserDO user = userService.getUser(loginUser.getId());
|
||||
if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) {
|
||||
// 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面
|
||||
throw exception(AUTH_TOKEN_EXPIRED);
|
||||
}
|
||||
|
||||
// 刷新 LoginUser 缓存
|
||||
userSessionCoreService.refreshUserSession(token, loginUser);
|
||||
userSessionApi.refreshUserSession(token, loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser mockLogin(Long userId) {
|
||||
// 获取用户编号对应的 UserDO
|
||||
UserDO user = userService.getUser(userId);
|
||||
MemberUserDO user = userService.getUser(userId);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(String.valueOf(userId));
|
||||
}
|
||||
|
||||
// 执行登陆
|
||||
this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS);
|
||||
this.createLoginLog(user.getMobile(), LoginLogTypeEnum.LOGIN_MOCK, LoginResultEnum.SUCCESS);
|
||||
|
||||
// 创建 LoginUser 对象
|
||||
return AuthConvert.INSTANCE.convert(user);
|
||||
@ -264,12 +260,12 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public void logout(String token) {
|
||||
// 查询用户信息
|
||||
LoginUser loginUser = userSessionCoreService.getLoginUser(token);
|
||||
LoginUser loginUser = userSessionApi.getLoginUser(token);
|
||||
if (loginUser == null) {
|
||||
return;
|
||||
}
|
||||
// 删除 session
|
||||
userSessionCoreService.deleteUserSession(token);
|
||||
userSessionApi.deleteUserSession(token);
|
||||
// 记录登出日志
|
||||
this.createLogoutLog(loginUser.getId(), loginUser.getUsername());
|
||||
}
|
||||
@ -282,10 +278,10 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public void updatePassword(Long userId, AppAuthUpdatePasswordReqVO reqVO) {
|
||||
// 检验旧密码
|
||||
UserDO userDO = checkOldPassword(userId, reqVO.getOldPassword());
|
||||
MemberUserDO userDO = checkOldPassword(userId, reqVO.getOldPassword());
|
||||
|
||||
// 更新用户密码
|
||||
UserDO mbrUserDO = UserDO.builder().id(userDO.getId())
|
||||
MemberUserDO mbrUserDO = MemberUserDO.builder().id(userDO.getId())
|
||||
.password(passwordEncoder.encode(reqVO.getPassword())).build();
|
||||
userMapper.updateById(mbrUserDO);
|
||||
}
|
||||
@ -293,19 +289,24 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public void resetPassword(AppAuthResetPasswordReqVO reqVO) {
|
||||
// 检验用户是否存在
|
||||
UserDO userDO = checkUserIfExists(reqVO.getMobile());
|
||||
MemberUserDO userDO = checkUserIfExists(reqVO.getMobile());
|
||||
|
||||
// 使用验证码
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(),SysSmsSceneEnum.FORGET_MOBILE_BY_SMS.getScene(), reqVO.getCode(),
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(), SmsSceneEnum.MEMBER_FORGET_PASSWORD.getScene(), reqVO.getCode(),
|
||||
getClientIP());
|
||||
|
||||
// 更新密码
|
||||
UserDO mbrUserDO = UserDO.builder().build();
|
||||
MemberUserDO mbrUserDO = MemberUserDO.builder().build();
|
||||
mbrUserDO.setId(userDO.getId());
|
||||
mbrUserDO.setPassword(passwordEncoder.encode(reqVO.getPassword()));
|
||||
userMapper.updateById(mbrUserDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSmsCode(Long userId, AppAuthSendSmsReqVO reqVO) {
|
||||
// TODO 芋艿:修改
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验旧密码
|
||||
*
|
||||
@ -314,8 +315,8 @@ public class AuthServiceImpl implements AuthService {
|
||||
* @return MemberUserDO 用户实体
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public UserDO checkOldPassword(Long id, String oldPassword) {
|
||||
UserDO user = userMapper.selectById(id);
|
||||
public MemberUserDO checkOldPassword(Long id, String oldPassword) {
|
||||
MemberUserDO user = userMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
@ -326,8 +327,8 @@ public class AuthServiceImpl implements AuthService {
|
||||
return user;
|
||||
}
|
||||
|
||||
public UserDO checkUserIfExists(String mobile) {
|
||||
UserDO user = userMapper.selectByMobile(mobile);
|
||||
public MemberUserDO checkUserIfExists(String mobile) {
|
||||
MemberUserDO user = userMapper.selectByMobile(mobile);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
@ -335,16 +336,16 @@ public class AuthServiceImpl implements AuthService {
|
||||
}
|
||||
|
||||
private void createLogoutLog(Long userId, String username) {
|
||||
SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType());
|
||||
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(LoginLogTypeEnum.LOGOUT_SELF.getType());
|
||||
reqDTO.setTraceId(TracerUtils.getTraceId());
|
||||
reqDTO.setUserId(userId);
|
||||
reqDTO.setUserType(getUserType().getValue());
|
||||
reqDTO.setUsername(username);
|
||||
reqDTO.setUserAgent(ServletUtils.getUserAgent());
|
||||
reqDTO.setUserIp(getClientIP());
|
||||
reqDTO.setResult(SysLoginResultEnum.SUCCESS.getResult());
|
||||
loginLogCoreService.createLoginLog(reqDTO);
|
||||
reqDTO.setResult(LoginResultEnum.SUCCESS.getResult());
|
||||
loginLogApi.createLoginLog(reqDTO);
|
||||
}
|
||||
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
package cn.iocoder.yudao.module.member.service.sms;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SysSmsCoreService;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.sms.SysSmsCodeMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.member.framework.sms.SmsCodeProperties;
|
||||
import cn.iocoder.yudao.module.member.service.user.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomInt;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 短信验证码 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class SysSmsCodeServiceImpl implements SysSmsCodeService {
|
||||
|
||||
@Resource
|
||||
private SmsCodeProperties smsCodeProperties;
|
||||
|
||||
@Resource
|
||||
private SysSmsCodeMapper smsCodeMapper;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private SysSmsCoreService smsCoreService;
|
||||
|
||||
@Override
|
||||
public void sendSmsCode(String mobile, Integer scene, String createIp) {
|
||||
// 创建验证码
|
||||
String code = this.createSmsCode(mobile, scene, createIp);
|
||||
|
||||
// 获取发送模板
|
||||
String codeTemplate = SysSmsSceneEnum.getCodeByScene(scene);
|
||||
|
||||
// 如果是更换手机号发送验证码,则需要检测手机号是否被注册
|
||||
if (SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene().equals(scene)){
|
||||
this.checkMobileIsRegister(mobile,scene);
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
smsCoreService.sendSingleSmsToMember(mobile, null, codeTemplate,
|
||||
MapUtil.of("code", code));
|
||||
}
|
||||
|
||||
public void checkMobileIsRegister(String mobile, Integer scene) {
|
||||
// 检测手机号是否已被使用
|
||||
UserDO user = userService.getUserByMobile(mobile);
|
||||
if (user != null) {
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_IS_EXISTS);
|
||||
}
|
||||
|
||||
// 发送短信
|
||||
this.sendSmsCode(mobile,scene,getClientIP());
|
||||
}
|
||||
|
||||
private String createSmsCode(String mobile, Integer scene, String ip) {
|
||||
// 校验是否可以发送验证码,不用筛选场景
|
||||
SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null,null);
|
||||
if (lastSmsCode != null) {
|
||||
if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY);
|
||||
}
|
||||
if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime()
|
||||
< smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_SEND_TOO_FAST);
|
||||
}
|
||||
// TODO 芋艿:提升,每个 IP 每天可发送数量
|
||||
// TODO 芋艿:提升,每个 IP 每小时可发送数量
|
||||
}
|
||||
|
||||
// 创建验证码记录
|
||||
String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1));
|
||||
SysSmsCodeDO newSmsCode = SysSmsCodeDO.builder().mobile(mobile).code(code)
|
||||
.scene(scene).todayIndex(lastSmsCode != null ? lastSmsCode.getTodayIndex() + 1 : 1)
|
||||
.createIp(ip).used(false).build();
|
||||
smsCodeMapper.insert(newSmsCode);
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useSmsCode(String mobile, Integer scene, String code, String usedIp) {
|
||||
// 检测验证码是否有效
|
||||
SysSmsCodeDO lastSmsCode = this.checkCodeIsExpired(mobile, code, scene);
|
||||
|
||||
// 判断验证码是否已被使用
|
||||
if (Boolean.TRUE.equals(lastSmsCode.getUsed())) {
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_USED);
|
||||
}
|
||||
|
||||
// 使用验证码
|
||||
smsCodeMapper.updateById(SysSmsCodeDO.builder().id(lastSmsCode.getId())
|
||||
.used(true).usedTime(new Date()).usedIp(usedIp).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSmsCodeLogin(Long userId) {
|
||||
UserDO user = userService.getUser(userId);
|
||||
if (user == null){
|
||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||
}
|
||||
// 发送验证码
|
||||
this.sendSmsCode(user.getMobile(),SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), getClientIP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSmsCodeDO checkCodeIsExpired(String mobile, String code, Integer scene) {
|
||||
// 校验验证码
|
||||
SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile,code,scene);
|
||||
|
||||
// 若验证码不存在,抛出异常
|
||||
if (lastSmsCode == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_NOT_FOUND);
|
||||
}
|
||||
if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime()
|
||||
>= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期
|
||||
throw ServiceExceptionUtil.exception(USER_SMS_CODE_EXPIRED);
|
||||
}
|
||||
return lastSmsCode;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.member.service.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -12,7 +11,7 @@ import java.io.InputStream;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface UserService {
|
||||
public interface MemberUserService {
|
||||
|
||||
/**
|
||||
* 通过手机查询用户
|
||||
@ -20,7 +19,7 @@ public interface UserService {
|
||||
* @param mobile 手机
|
||||
* @return 用户对象
|
||||
*/
|
||||
UserDO getUserByMobile(String mobile);
|
||||
MemberUserDO getUserByMobile(String mobile);
|
||||
|
||||
/**
|
||||
* 基于手机号创建用户。
|
||||
@ -30,7 +29,7 @@ public interface UserService {
|
||||
* @param registerIp 注册 IP
|
||||
* @return 用户对象
|
||||
*/
|
||||
UserDO createUserIfAbsent(@Mobile String mobile, String registerIp);
|
||||
MemberUserDO createUserIfAbsent(@Mobile String mobile, String registerIp);
|
||||
|
||||
/**
|
||||
* 更新用户的最后登陆信息
|
||||
@ -46,7 +45,7 @@ public interface UserService {
|
||||
* @param id 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
UserDO getUser(Long id);
|
||||
MemberUserDO getUser(Long id);
|
||||
|
||||
/**
|
||||
* 修改用户昵称
|
@ -6,11 +6,11 @@ import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreServic
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SmsCodeDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -25,20 +25,20 @@ import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.module.member.enums.MemberErrorCodeConstants.USER_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 会员 User Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service("memberUserService")
|
||||
@Service
|
||||
@Valid
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService {
|
||||
public class MemberUserServiceImpl implements MemberUserService {
|
||||
|
||||
@Resource
|
||||
private UserMapper memberUserMapper;
|
||||
private MemberUserMapper memberUserMapper;
|
||||
|
||||
@Resource
|
||||
private InfFileCoreService fileCoreService;
|
||||
@ -49,14 +49,14 @@ public class UserServiceImpl implements UserService {
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public UserDO getUserByMobile(String mobile) {
|
||||
public MemberUserDO getUserByMobile(String mobile) {
|
||||
return memberUserMapper.selectByMobile(mobile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDO createUserIfAbsent(String mobile, String registerIp) {
|
||||
public MemberUserDO createUserIfAbsent(String mobile, String registerIp) {
|
||||
// 用户已经存在
|
||||
UserDO user = memberUserMapper.selectByMobile(mobile);
|
||||
MemberUserDO user = memberUserMapper.selectByMobile(mobile);
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
@ -64,11 +64,11 @@ public class UserServiceImpl implements UserService {
|
||||
return this.createUser(mobile, registerIp);
|
||||
}
|
||||
|
||||
private UserDO createUser(String mobile, String registerIp) {
|
||||
private MemberUserDO createUser(String mobile, String registerIp) {
|
||||
// 生成密码
|
||||
String password = IdUtil.fastSimpleUUID();
|
||||
// 插入用户
|
||||
UserDO user = new UserDO();
|
||||
MemberUserDO user = new MemberUserDO();
|
||||
user.setMobile(mobile);
|
||||
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
||||
user.setPassword(passwordEncoder.encode(password)); // 加密密码
|
||||
@ -79,23 +79,23 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public void updateUserLogin(Long id, String loginIp) {
|
||||
memberUserMapper.updateById(new UserDO().setId(id)
|
||||
memberUserMapper.updateById(new MemberUserDO().setId(id)
|
||||
.setLoginIp(loginIp).setLoginDate(new Date()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDO getUser(Long id) {
|
||||
public MemberUserDO getUser(Long id) {
|
||||
return memberUserMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserNickname(Long userId, String nickname) {
|
||||
UserDO user = this.checkUserExists(userId);
|
||||
MemberUserDO user = this.checkUserExists(userId);
|
||||
// 仅当新昵称不等于旧昵称时进行修改
|
||||
if (nickname.equals(user.getNickname())){
|
||||
return;
|
||||
}
|
||||
UserDO userDO = new UserDO();
|
||||
MemberUserDO userDO = new MemberUserDO();
|
||||
userDO.setId(user.getId());
|
||||
userDO.setNickname(nickname);
|
||||
memberUserMapper.updateById(userDO);
|
||||
@ -107,7 +107,7 @@ public class UserServiceImpl implements UserService {
|
||||
// 创建文件
|
||||
String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
|
||||
// 更新头像路径
|
||||
memberUserMapper.updateById(UserDO.builder().id(userId).avatar(avatar).build());
|
||||
memberUserMapper.updateById(MemberUserDO.builder().id(userId).avatar(avatar).build());
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@ -117,27 +117,27 @@ public class UserServiceImpl implements UserService {
|
||||
checkUserExists(userId);
|
||||
|
||||
// 校验旧手机和旧验证码
|
||||
SysSmsCodeDO sysSmsCodeDO = smsCodeService.checkCodeIsExpired(reqVO.getOldMobile(), reqVO.getOldCode(),
|
||||
SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene());
|
||||
SmsCodeDO sysSmsCodeDO = smsCodeService.checkCodeIsExpired(reqVO.getOldMobile(), reqVO.getOldCode(),
|
||||
SmsSceneEnum.MEMBER_UPDATE_MOBILE.getScene());
|
||||
// 判断旧 code 是否未被使用,如果是,抛出异常
|
||||
if (Boolean.FALSE.equals(sysSmsCodeDO.getUsed())){
|
||||
throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_IS_UNUSED);
|
||||
}
|
||||
|
||||
// 使用新验证码
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(),
|
||||
smsCodeService.useSmsCode(reqVO.getMobile(), SmsSceneEnum.MEMBER_UPDATE_MOBILE.getScene(),
|
||||
reqVO.getCode(),getClientIP());
|
||||
|
||||
// 更新用户手机
|
||||
memberUserMapper.updateById(UserDO.builder().id(userId).mobile(reqVO.getMobile()).build());
|
||||
memberUserMapper.updateById(MemberUserDO.builder().id(userId).mobile(reqVO.getMobile()).build());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public UserDO checkUserExists(Long id) {
|
||||
public MemberUserDO checkUserExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
UserDO user = memberUserMapper.selectById(id);
|
||||
MemberUserDO user = memberUserMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.member.service.auth;
|
||||
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.auth.SysUserSessionCoreService;
|
||||
import cn.iocoder.yudao.module.system.service.logger.SysLoginLogCoreService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SysSocialCoreService;
|
||||
@ -8,10 +9,9 @@ import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthResetPasswordReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService;
|
||||
import cn.iocoder.yudao.module.member.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import cn.iocoder.yudao.module.member.test.BaseDbAndRedisUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@ -32,17 +32,17 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
// TODO @芋艿:单测的 review,等逻辑都达成一致后
|
||||
/**
|
||||
* {@link AuthService} 的单元测试类
|
||||
* {@link MemberAuthService} 的单元测试类
|
||||
*
|
||||
* @author 宋天
|
||||
*/
|
||||
@Import({AuthServiceImpl.class, YudaoRedisAutoConfiguration.class})
|
||||
@Import({MemberAuthServiceImpl.class, YudaoRedisAutoConfiguration.class})
|
||||
public class SysAuthServiceTest extends BaseDbAndRedisUnitTest {
|
||||
|
||||
@MockBean
|
||||
private AuthenticationManager authenticationManager;
|
||||
@MockBean
|
||||
private UserService userService;
|
||||
private MemberUserService userService;
|
||||
@MockBean
|
||||
private SysSmsCodeService smsCodeService;
|
||||
@MockBean
|
||||
@ -56,14 +56,14 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest {
|
||||
@MockBean
|
||||
private PasswordEncoder passwordEncoder;
|
||||
@Resource
|
||||
private UserMapper mbrUserMapper;
|
||||
private MemberUserMapper mbrUserMapper;
|
||||
@Resource
|
||||
private AuthServiceImpl authService;
|
||||
private MemberAuthServiceImpl authService;
|
||||
|
||||
@Test
|
||||
public void testUpdatePassword_success(){
|
||||
// 准备参数
|
||||
UserDO userDO = randomUserDO();
|
||||
MemberUserDO userDO = randomUserDO();
|
||||
mbrUserMapper.insert(userDO);
|
||||
|
||||
// 新密码
|
||||
@ -88,7 +88,7 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest {
|
||||
@Test
|
||||
public void testResetPassword_success(){
|
||||
// 准备参数
|
||||
UserDO userDO = randomUserDO();
|
||||
MemberUserDO userDO = randomUserDO();
|
||||
mbrUserMapper.insert(userDO);
|
||||
|
||||
// 随机密码
|
||||
@ -113,12 +113,12 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest {
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
private static UserDO randomUserDO(Consumer<UserDO>... consumers) {
|
||||
Consumer<UserDO> consumer = (o) -> {
|
||||
private static MemberUserDO randomUserDO(Consumer<MemberUserDO>... consumers) {
|
||||
Consumer<MemberUserDO> consumer = (o) -> {
|
||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||
o.setPassword(randomString());
|
||||
};
|
||||
return randomPojo(UserDO.class, ArrayUtils.append(consumer, consumers));
|
||||
return randomPojo(MemberUserDO.class, ArrayUtils.append(consumer, consumers));
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,11 +6,11 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.member.service.auth.AuthServiceImpl;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.sms.SmsCodeDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
import cn.iocoder.yudao.module.member.service.auth.MemberAuthServiceImpl;
|
||||
import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService;
|
||||
import cn.iocoder.yudao.module.member.test.BaseDbAndRedisUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -31,24 +31,24 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
// TODO @芋艿:单测的 review,等逻辑都达成一致后
|
||||
/**
|
||||
* {@link UserServiceImpl} 的单元测试类
|
||||
* {@link MemberUserServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 宋天
|
||||
*/
|
||||
@Import({UserServiceImpl.class, YudaoRedisAutoConfiguration.class})
|
||||
public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
@Import({MemberUserServiceImpl.class, YudaoRedisAutoConfiguration.class})
|
||||
public class UserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
|
||||
@Resource
|
||||
private UserServiceImpl mbrUserService;
|
||||
private MemberUserServiceImpl mbrUserService;
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
private MemberUserMapper userMapper;
|
||||
|
||||
@MockBean
|
||||
private AuthServiceImpl authService;
|
||||
private MemberAuthServiceImpl authService;
|
||||
|
||||
@MockBean
|
||||
private InfFileCoreService fileCoreService;
|
||||
@ -57,12 +57,12 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@MockBean
|
||||
private SysSmsCodeService sysSmsCodeService;
|
||||
private SmsCodeService smsCodeService;
|
||||
|
||||
@Test
|
||||
public void testUpdateNickName_success(){
|
||||
// mock 数据
|
||||
UserDO userDO = randomUserDO();
|
||||
MemberUserDO userDO = randomUserDO();
|
||||
userMapper.insert(userDO);
|
||||
|
||||
// 随机昵称
|
||||
@ -79,7 +79,7 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
@Test
|
||||
public void testUpdateAvatar_success(){
|
||||
// mock 数据
|
||||
UserDO dbUser = randomUserDO();
|
||||
MemberUserDO dbUser = randomUserDO();
|
||||
userMapper.insert(dbUser);
|
||||
|
||||
// 准备参数
|
||||
@ -99,18 +99,18 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
public void updateMobile_success(){
|
||||
// mock数据
|
||||
String oldMobile = randomNumbers(11);
|
||||
UserDO userDO = randomUserDO();
|
||||
MemberUserDO userDO = randomUserDO();
|
||||
userDO.setMobile(oldMobile);
|
||||
userMapper.insert(userDO);
|
||||
|
||||
// 旧手机和旧验证码
|
||||
SysSmsCodeDO codeDO = new SysSmsCodeDO();
|
||||
SmsCodeDO codeDO = new SmsCodeDO();
|
||||
String oldCode = RandomUtil.randomString(4);
|
||||
codeDO.setMobile(userDO.getMobile());
|
||||
codeDO.setCode(oldCode);
|
||||
codeDO.setScene(SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene());
|
||||
codeDO.setScene(SmsSceneEnum.MEMBER_UPDATE_MOBILE.getScene());
|
||||
codeDO.setUsed(Boolean.FALSE);
|
||||
when(sysSmsCodeService.checkCodeIsExpired(codeDO.getMobile(),codeDO.getCode(),codeDO.getScene())).thenReturn(codeDO);
|
||||
when(smsCodeService.checkCodeIsExpired(codeDO.getMobile(),codeDO.getCode(),codeDO.getScene())).thenReturn(codeDO);
|
||||
|
||||
// 更新手机号
|
||||
String newMobile = randomNumbers(11);
|
||||
@ -128,11 +128,11 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
private static UserDO randomUserDO(Consumer<UserDO>... consumers) {
|
||||
Consumer<UserDO> consumer = (o) -> {
|
||||
private static MemberUserDO randomUserDO(Consumer<MemberUserDO>... consumers) {
|
||||
Consumer<MemberUserDO> consumer = (o) -> {
|
||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||
};
|
||||
return randomPojo(UserDO.class, ArrayUtils.append(consumer, consumers));
|
||||
return randomPojo(MemberUserDO.class, ArrayUtils.append(consumer, consumers));
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,20 @@
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 参数校验 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- 用户信息 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-security</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.system.api.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 在线用户 Session API 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface UserSessionApi {
|
||||
|
||||
/**
|
||||
* 创建在线用户 Session
|
||||
*
|
||||
* @param loginUser 登录用户
|
||||
* @param userIp 用户 IP
|
||||
* @param userAgent 用户 UA
|
||||
* @return Session 编号
|
||||
*/
|
||||
String createUserSession(@NotNull(message = "登录用户不能为空") LoginUser loginUser, String userIp, String userAgent);
|
||||
|
||||
/**
|
||||
* 刷新在线用户 Session 的更新时间
|
||||
*
|
||||
* @param sessionId Session 编号
|
||||
* @param loginUser 登录用户
|
||||
*/
|
||||
void refreshUserSession(@NotEmpty(message = "Session编号不能为空") String sessionId,
|
||||
@NotNull(message = "登录用户不能为空") LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 删除在线用户 Session
|
||||
*
|
||||
* @param sessionId Session 编号
|
||||
*/
|
||||
void deleteUserSession(String sessionId);
|
||||
|
||||
/**
|
||||
* 获得 Session 编号对应的在线用户
|
||||
*
|
||||
* @param sessionId Session 编号
|
||||
* @return 在线用户
|
||||
*/
|
||||
LoginUser getLoginUser(String sessionId);
|
||||
|
||||
/**
|
||||
* 获得 Session 超时时间,单位:毫秒
|
||||
*
|
||||
* @return 超时时间
|
||||
*/
|
||||
Long getSessionTimeoutMillis();
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 登录日志的 API 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface LoginLogApi {
|
||||
|
||||
/**
|
||||
* 创建登录日志
|
||||
*
|
||||
* @param reqDTO 日志信息
|
||||
*/
|
||||
void createLoginLog(@Valid LoginLogCreateReqDTO reqDTO);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.system.service.logger.dto;
|
||||
package cn.iocoder.yudao.module.system.api.logger.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* System API 包,定义暴露给其它模块的 API
|
||||
*/
|
||||
package cn.iocoder.yudao.module.system.api;
|
@ -0,0 +1,64 @@
|
||||
package cn.iocoder.yudao.module.system.api.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 社交用户的 API 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SocialUserApi {
|
||||
|
||||
/**
|
||||
* 获得社交平台的授权 URL
|
||||
*
|
||||
* @param type 社交平台的类型 {@link SocialTypeEnum}
|
||||
* @param redirectUri 重定向 URL
|
||||
* @return 社交平台的授权 URL
|
||||
*/
|
||||
String getAuthorizeUrl(Integer type, String redirectUri);
|
||||
|
||||
/**
|
||||
* 绑定社交用户
|
||||
*
|
||||
* @param reqDTO 绑定信息
|
||||
*/
|
||||
void bindSocialUser(@Valid SocialUserBindReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 取消绑定社交用户
|
||||
*
|
||||
* @param reqDTO 解绑
|
||||
*/
|
||||
void unbindSocialUser(@Valid SocialUserUnbindReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 校验社交用户的认证信息是否正确
|
||||
* 如果校验不通过,则抛出 {@link ServiceException} 业务异常
|
||||
*
|
||||
* @param type 社交平台的类型
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
*/
|
||||
void checkSocialUser(Integer type, String code, String state);
|
||||
|
||||
/**
|
||||
* 获得社交用户的绑定用户编号
|
||||
* 注意,返回的是 MemberUser 或者 AdminUser 的 id 编号!
|
||||
* 该方法会执行和 {@link #checkSocialUser(Integer, String, String)} 一样的逻辑。
|
||||
* 所以在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param type 社交平台的类型
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
* @return 绑定用户编号
|
||||
*/
|
||||
Long getBindUserId(Integer userType, Integer type, String code, String state);
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package cn.iocoder.yudao.module.system.api.social.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 取消绑定社交用户 Request DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class SocialUserBindReqDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@InEnum(UserTypeEnum.class)
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 社交平台的类型
|
||||
*/
|
||||
@InEnum(SocialTypeEnum.class)
|
||||
@NotNull(message = "社交平台的类型不能为空")
|
||||
private Integer type;
|
||||
/**
|
||||
* 授权码
|
||||
*/
|
||||
@NotEmpty(message = "授权码不能为空")
|
||||
private String code;
|
||||
/**
|
||||
* state
|
||||
*/
|
||||
@NotEmpty(message = "state 不能为空")
|
||||
private String state;
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.system.api.social.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 社交绑定 Request DTO,使用 code 授权码
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class SocialUserUnbindReqDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@InEnum(UserTypeEnum.class)
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 社交平台的类型
|
||||
*/
|
||||
@InEnum(SocialTypeEnum.class)
|
||||
@NotNull(message = "社交平台的类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 社交平台的 unionId
|
||||
*/
|
||||
@NotEmpty(message = "社交平台的 unionId 不能为空")
|
||||
private String unionId;
|
||||
|
||||
}
|
@ -87,12 +87,31 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在");
|
||||
ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}】的短信模板");
|
||||
|
||||
// ========== 租户模块 1002012000 ==========
|
||||
ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1002012000, "租户不存在");
|
||||
// ========== 短信发送 1002012000 ==========
|
||||
ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1002012000, "手机号不存在");
|
||||
ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1002012001, "模板参数({})缺失");
|
||||
ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1002012002, "短信模板不存在");
|
||||
|
||||
// ========== 错误码模块 1002013000 ==========
|
||||
ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002013000, "错误码不存在");
|
||||
ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002013001, "已经存在编码为【{}】的错误码");
|
||||
// ========== 短信验证码 1002013000 ==========
|
||||
ErrorCode SMS_CODE_NOT_FOUND = new ErrorCode(1002013000, "验证码不存在");
|
||||
ErrorCode SMS_CODE_EXPIRED = new ErrorCode(1002013001, "验证码已过期");
|
||||
ErrorCode SMS_CODE_USED = new ErrorCode(1002013002, "验证码已使用");
|
||||
ErrorCode SMS_CODE_NOT_CORRECT = new ErrorCode(1002013004, "验证码不正确");
|
||||
ErrorCode SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY = new ErrorCode(1002013005, "超过每日短信发送数量");
|
||||
ErrorCode SMS_CODE_SEND_TOO_FAST = new ErrorCode(1002013006, "短信发送过于频率");
|
||||
ErrorCode SMS_CODE_IS_EXISTS = new ErrorCode(1002013007, "手机号已被使用");
|
||||
ErrorCode SMS_CODE_IS_UNUSED = new ErrorCode(1002013008, "验证码未被使用");
|
||||
|
||||
// ========== 租户模块 1002014000 ==========
|
||||
ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1002014000, "租户不存在");
|
||||
|
||||
// ========== 错误码模块 1002015000 ==========
|
||||
ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002015000, "错误码不存在");
|
||||
ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002015001, "已经存在编码为【{}】的错误码");
|
||||
|
||||
// ========== 社交用户 1002015000 ==========
|
||||
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1002015000, "社交授权失败,原因是:{}");
|
||||
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002015001, "社交解绑失败,非当前用户绑定");
|
||||
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002015001, "社交授权失败,找不到对应的用户");
|
||||
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* System 错误码枚举类
|
||||
*
|
||||
* system 系统,使用 1-006-000-000 段
|
||||
*/
|
||||
public interface SysErrorCodeConstants {
|
||||
|
||||
// ========== 短信发送 1006000000 ==========
|
||||
ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1006000000, "手机号不存在");
|
||||
ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失");
|
||||
ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在");
|
||||
|
||||
// ========== 社交模块 1006002000 ==========
|
||||
ErrorCode SOCIAL_AUTH_FAILURE = new ErrorCode(1006002000, "社交授权失败,原因是:{}");
|
||||
ErrorCode SOCIAL_UNBIND_NOT_SELF = new ErrorCode(1006002001, "社交解绑失败,非当前用户绑定");
|
||||
|
||||
// ========== 用户模块 1006003000 ==========
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1006003000, "用户不存在");
|
||||
ErrorCode USER_IS_DISABLE = new ErrorCode(1006003001, "名字为【{}】的用户已被禁用");
|
||||
|
||||
// ========== 部门模块 1006004000 ==========
|
||||
ErrorCode DEPT_NOT_FOUND = new ErrorCode(1006004000, "当前部门不存在");
|
||||
ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1006004001, "部门不处于开启状态,不允许选择");
|
||||
|
||||
// ========== 角色模块 1006005000 ==========
|
||||
ErrorCode ROLE_NOT_EXISTS = new ErrorCode(1006005000, "角色不存在");
|
||||
ErrorCode ROLE_IS_DISABLE = new ErrorCode(1006005001, "名字为【{}】的角色已被禁用");
|
||||
|
||||
// ========== 岗位模块 1006007000 ==========
|
||||
ErrorCode POST_NOT_FOUND = new ErrorCode(1006007000, "当前岗位不存在");
|
||||
ErrorCode POST_NOT_ENABLE = new ErrorCode(1006007001, "岗位({}) 不处于开启状态,不允许选择");
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SysLoginLogTypeEnum {
|
||||
public enum LoginLogTypeEnum {
|
||||
|
||||
LOGIN_USERNAME(100), // 使用账号登录
|
||||
LOGIN_SOCIAL(101), // 使用社交登录
|
@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SysLoginResultEnum {
|
||||
public enum LoginResultEnum {
|
||||
|
||||
SUCCESS(0), // 成功
|
||||
BAD_CREDENTIALS(10), // 账号或密码不正确
|
@ -0,0 +1,49 @@
|
||||
package cn.iocoder.yudao.module.system.enums.sms;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 用户短信验证码发送场景的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SmsSceneEnum implements IntArrayValuable {
|
||||
|
||||
MEMBER_LOGIN(1, "user-sms-login", "会员用户 - 手机号登陆"),
|
||||
MEMBER_UPDATE_MOBILE(2, "user-sms-reset-password", "会员用户 - 修改手机"),
|
||||
MEMBER_FORGET_PASSWORD(3, "user-sms-update-mobile", "会员用户 - 忘记密码");
|
||||
|
||||
// 如果未来希望管理后台支持手机验证码登陆,可以通过添加 ADMIN_MEMBER_LOGIN 枚举
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsSceneEnum::getScene).toArray();
|
||||
|
||||
/**
|
||||
* 验证场景的编号
|
||||
*/
|
||||
private final Integer scene;
|
||||
/**
|
||||
* 模版编码
|
||||
*/
|
||||
private final String templateCode;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static SmsSceneEnum getCodeByScene(Integer scene) {
|
||||
return ArrayUtil.firstMatch(sceneEnum -> sceneEnum.getScene().equals(scene));
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,11 @@
|
||||
<artifactId>yudao-module-system-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-module-member-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<dependency>
|
||||
|
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.system.api.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.module.system.service.auth.UserSessionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 在线用户 Session API 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class UserSessionApiImpl implements UserSessionApi {
|
||||
|
||||
@Resource
|
||||
private UserSessionService userSessionService;
|
||||
|
||||
@Override
|
||||
public String createUserSession(LoginUser loginUser, String userIp, String userAgent) {
|
||||
return userSessionService.createUserSession(loginUser, userIp, userAgent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUserSession(String sessionId, LoginUser loginUser) {
|
||||
userSessionService.refreshUserSession(sessionId, loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserSession(String sessionId) {
|
||||
userSessionService.deleteUserSession(sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getLoginUser(String sessionId) {
|
||||
return userSessionService.getLoginUser(sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSessionTimeoutMillis() {
|
||||
return userSessionService.getSessionTimeoutMillis();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 登录日志的 API 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class LoginLogApiImpl implements LoginLogApi {
|
||||
|
||||
@Resource
|
||||
private LoginLogService loginLogService;
|
||||
|
||||
@Override
|
||||
public void createLoginLog(LoginLogCreateReqDTO reqDTO) {
|
||||
loginLogService.createLoginLog(reqDTO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
package cn.iocoder.yudao.module.system.api;
|
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.system.api.social;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* 社交用户的 API 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class SocialUserApiImpl implements SocialUserApi {
|
||||
|
||||
@Resource
|
||||
private SocialUserService socialUserService;
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(Integer type, String redirectUri) {
|
||||
return socialUserService.getAuthorizeUrl(type, redirectUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindSocialUser(SocialUserBindReqDTO reqDTO) {
|
||||
// 使用 code 授权
|
||||
AuthUser authUser = socialUserService.getAuthUser(reqDTO.getType(), reqDTO.getCode(),
|
||||
reqDTO.getState());
|
||||
if (authUser == null) {
|
||||
throw exception(SOCIAL_USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 绑定社交用户(新增)
|
||||
socialUserService.bindSocialUser(reqDTO.getUserId(), reqDTO.getUserType(),
|
||||
reqDTO.getType(), authUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbindSocialUser(SocialUserUnbindReqDTO reqDTO) {
|
||||
socialUserService.unbindSocialUser(reqDTO.getUserId(), reqDTO.getUserType(),
|
||||
reqDTO.getType(), reqDTO.getUnionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSocialUser(Integer type, String code, String state) {
|
||||
AuthUser authUser = socialUserService.getAuthUser(type, code, state);
|
||||
if (authUser == null) {
|
||||
throw exception(SOCIAL_USER_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getBindUserId(Integer userType, Integer type, String code, String state) {
|
||||
AuthUser authUser = socialUserService.getAuthUser(type, code, state);
|
||||
if (authUser == null) {
|
||||
throw exception(SOCIAL_USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.auth;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*;
|
||||
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.service.auth.AuthService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*;
|
||||
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -42,12 +41,10 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
||||
@Slf4j
|
||||
public class AuthController {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // AuthService 存在重名
|
||||
private AuthService authService;
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private AdminAuthService authService;
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
@ -68,12 +65,12 @@ public class AuthController {
|
||||
@ApiOperation("获取登录用户的权限信息")
|
||||
public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() {
|
||||
// 获得用户信息
|
||||
UserDO user = userService.getUser(getLoginUserId());
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
// 获得角色列表
|
||||
List<SysRoleDO> roleList = roleService.getRolesFromCache(getLoginUserRoleIds());
|
||||
List<RoleDO> roleList = roleService.getRolesFromCache(getLoginUserRoleIds());
|
||||
// 获得菜单列表
|
||||
List<MenuDO> menuList = permissionService.getRoleMenusFromCache(
|
||||
getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它
|
||||
@ -136,7 +133,7 @@ public class AuthController {
|
||||
@DeleteMapping("/social-unbind")
|
||||
@ApiOperation("取消社交绑定")
|
||||
public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) {
|
||||
socialCoreService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN);
|
||||
socialCoreService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId());
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,15 @@ import cn.iocoder.yudao.module.system.convert.auth.UserSessionConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.service.auth.UserSessionService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.auth.SysUserSessionDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysDeptCoreService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -35,12 +34,11 @@ public class UserSessionController {
|
||||
|
||||
@Resource
|
||||
private UserSessionService userSessionService;
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
@Resource
|
||||
private SysDeptCoreService deptCoreService;
|
||||
private DeptService deptService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得 Session 分页列表")
|
||||
@ -50,10 +48,10 @@ public class UserSessionController {
|
||||
PageResult<SysUserSessionDO> pageResult = userSessionService.getUserSessionPage(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Map<Long, UserDO> userMap = userService.getUserMap(
|
||||
Map<Long, AdminUserDO> userMap = userService.getUserMap(
|
||||
convertList(pageResult.getList(), SysUserSessionDO::getUserId));
|
||||
Map<Long, SysDeptDO> deptMap = deptCoreService.getDeptMap(
|
||||
convertList(userMap.values(), UserDO::getDeptId));
|
||||
Map<Long, SysDeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(userMap.values(), AdminUserDO::getDeptId));
|
||||
// 拼接结果返回
|
||||
List<UserSessionPageItemRespVO> sessionList = new ArrayList<>(pageResult.getList().size());
|
||||
pageResult.getList().forEach(session -> {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dept;
|
||||
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysDeptCoreService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.*;
|
||||
@ -30,9 +29,6 @@ public class DeptController {
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@Resource
|
||||
private SysDeptCoreService deptCoreService;
|
||||
|
||||
@PostMapping("create")
|
||||
@ApiOperation("创建部门")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:create')")
|
||||
@ -84,7 +80,7 @@ public class DeptController {
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<DeptRespVO> getDept(@RequestParam("id") Long id) {
|
||||
return success(DeptConvert.INSTANCE.convert(deptCoreService.getDept(id)));
|
||||
return success(DeptConvert.INSTANCE.convert(deptService.getDept(id)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,18 +6,17 @@ import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.Oper
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -44,9 +43,8 @@ public class OperateLogController {
|
||||
|
||||
@Resource
|
||||
private OperateLogService operateLogService;
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("查看操作日志分页列表")
|
||||
@ -56,7 +54,7 @@ public class OperateLogController {
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> userIds = CollectionUtils.convertList(pageResult.getList(), OperateLogDO::getUserId);
|
||||
Map<Long, UserDO> userMap = userService.getUserMap(userIds);
|
||||
Map<Long, AdminUserDO> userMap = userService.getUserMap(userIds);
|
||||
// 拼接数据
|
||||
List<OperateLogRespVO> list = new ArrayList<>(pageResult.getList().size());
|
||||
pageResult.getList().forEach(operateLog -> {
|
||||
@ -77,7 +75,7 @@ public class OperateLogController {
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId);
|
||||
Map<Long, UserDO> userMap = userService.getUserMap(userIds);
|
||||
Map<Long, AdminUserDO> userMap = userService.getUserMap(userIds);
|
||||
// 拼接数据
|
||||
List<OperateLogExcelVO> excelDataList = OperateLogConvert.INSTANCE.convertList(list, userMap);
|
||||
// 输出
|
||||
|
@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*;
|
||||
import cn.iocoder.yudao.module.system.convert.permission.RoleConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -72,14 +72,14 @@ public class RoleController {
|
||||
@ApiOperation("获得角色信息")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:query')")
|
||||
public CommonResult<RoleRespVO> getRole(@RequestParam("id") Long id) {
|
||||
SysRoleDO role = roleService.getRole(id);
|
||||
RoleDO role = roleService.getRole(id);
|
||||
return success(RoleConvert.INSTANCE.convert(role));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得角色分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:query')")
|
||||
public CommonResult<PageResult<SysRoleDO>> getRolePage(RolePageReqVO reqVO) {
|
||||
public CommonResult<PageResult<RoleDO>> getRolePage(RolePageReqVO reqVO) {
|
||||
return success(roleService.getRolePage(reqVO));
|
||||
}
|
||||
|
||||
@ -87,9 +87,9 @@ public class RoleController {
|
||||
@ApiOperation(value = "获取角色精简信息列表", notes = "只包含被开启的角色,主要用于前端的下拉选项")
|
||||
public CommonResult<List<RoleSimpleRespVO>> getSimpleRoles() {
|
||||
// 获得角色列表,只要开启状态的
|
||||
List<SysRoleDO> list = roleService.getRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
List<RoleDO> list = roleService.getRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回个诶前端
|
||||
list.sort(Comparator.comparing(SysRoleDO::getSort));
|
||||
list.sort(Comparator.comparing(RoleDO::getSort));
|
||||
return success(RoleConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public class RoleController {
|
||||
@OperateLog(type = EXPORT)
|
||||
@PreAuthorize("@ss.hasPermission('system:role:export')")
|
||||
public void export(HttpServletResponse response, @Validated RoleExportReqVO reqVO) throws IOException {
|
||||
List<SysRoleDO> list = roleService.getRoleList(reqVO);
|
||||
List<RoleDO> list = roleService.getRoleList(reqVO);
|
||||
List<RoleExcelVO> data = RoleConvert.INSTANCE.convertList03(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "角色数据.xls", "角色列表", RoleExcelVO.class, data);
|
||||
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.system.controller.admin.sms;
|
||||
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SysSmsSendService;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.framework.sms.core.enums.SmsChannelEnum;
|
||||
@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
public class SmsCallbackController {
|
||||
|
||||
@Resource
|
||||
private SysSmsSendService smsCoreService;
|
||||
private SmsSendService smsCoreService;
|
||||
|
||||
@PostMapping("/sms/yunpian")
|
||||
@ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档")
|
||||
|
@ -4,7 +4,7 @@ import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.*;
|
||||
import cn.iocoder.yudao.module.system.convert.sms.SmsTemplateConvert;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SmsTemplateService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SysSmsTemplateDO;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SysSmsSendService;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
@ -32,7 +32,7 @@ public class SmsTemplateController {
|
||||
@Resource
|
||||
private SmsTemplateService smsTemplateService;
|
||||
@Resource
|
||||
private SysSmsSendService smsCoreService;
|
||||
private SmsSendService smsCoreService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建短信模板")
|
||||
@ -91,7 +91,7 @@ public class SmsTemplateController {
|
||||
@ApiOperation("发送短信")
|
||||
@PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')")
|
||||
public CommonResult<Long> sendSms(@Valid @RequestBody SmsTemplateSendReqVO sendReqVO) {
|
||||
return success(smsCoreService.sendSingleSms(sendReqVO.getMobile(), null, null,
|
||||
return success(smsCoreService.sendSingleSmsToAdmin(sendReqVO.getMobile(), null,
|
||||
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,10 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.enums.common.SysSexEnum;
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysDeptCoreService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
@ -18,7 +18,6 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -41,11 +40,10 @@ import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.E
|
||||
@Validated
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private SysDeptCoreService deptCoreService;
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("新增用户")
|
||||
@ -93,14 +91,14 @@ public class UserController {
|
||||
@PreAuthorize("@ss.hasPermission('system:user:list')")
|
||||
public CommonResult<PageResult<UserPageItemRespVO>> getUserPage(@Valid UserPageReqVO reqVO) {
|
||||
// 获得用户分页列表
|
||||
PageResult<UserDO> pageResult = userService.getUserPage(reqVO);
|
||||
PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(new PageResult<>(pageResult.getTotal())); // 返回空
|
||||
}
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = convertList(pageResult.getList(), UserDO::getDeptId);
|
||||
Map<Long, SysDeptDO> deptMap = deptCoreService.getDeptMap(deptIds);
|
||||
Collection<Long> deptIds = convertList(pageResult.getList(), AdminUserDO::getDeptId);
|
||||
Map<Long, SysDeptDO> deptMap = deptService.getDeptMap(deptIds);
|
||||
// 拼接结果返回
|
||||
List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.getList().size());
|
||||
pageResult.getList().forEach(user -> {
|
||||
@ -115,7 +113,7 @@ public class UserController {
|
||||
@ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项")
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUsers() {
|
||||
// 获用户门列表,只要开启状态的
|
||||
List<UserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<AdminUserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
// 排序后,返回给前端
|
||||
return success(UserConvert.INSTANCE.convertList04(list));
|
||||
}
|
||||
@ -135,12 +133,12 @@ public class UserController {
|
||||
public void exportUsers(@Validated UserExportReqVO reqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
// 获得用户列表
|
||||
List<UserDO> users = userService.getUsers(reqVO);
|
||||
List<AdminUserDO> users = userService.getUsers(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = convertList(users, UserDO::getDeptId);
|
||||
Map<Long, SysDeptDO> deptMap = deptCoreService.getDeptMap(deptIds);
|
||||
Map<Long, UserDO> deptLeaderUserMap = userService.getUserMap(
|
||||
Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId);
|
||||
Map<Long, SysDeptDO> deptMap = deptService.getDeptMap(deptIds);
|
||||
Map<Long, AdminUserDO> deptLeaderUserMap = userService.getUserMap(
|
||||
convertSet(deptMap.values(), SysDeptDO::getLeaderUserId));
|
||||
// 拼接数据
|
||||
List<UserExcelVO> excelUsers = new ArrayList<>(users.size());
|
||||
|
@ -5,16 +5,16 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfi
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysDeptCoreService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
@ -22,7 +22,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -43,11 +42,10 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
||||
@Slf4j
|
||||
public class UserProfileController {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private SysDeptCoreService deptCoreService;
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@Resource
|
||||
private PostService postService;
|
||||
@ -62,14 +60,14 @@ public class UserProfileController {
|
||||
@ApiOperation("获得登录用户信息")
|
||||
public CommonResult<UserProfileRespVO> profile() {
|
||||
// 获得用户基本信息
|
||||
UserDO user = userService.getUser(getLoginUserId());
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user);
|
||||
// 获得用户角色
|
||||
List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
|
||||
List<RoleDO> userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
|
||||
resp.setRoles(UserConvert.INSTANCE.convertList(userRoles));
|
||||
// 获得部门信息
|
||||
if (user.getDeptId() != null) {
|
||||
SysDeptDO dept = deptCoreService.getDept(user.getDeptId());
|
||||
SysDeptDO dept = deptService.getDept(user.getDeptId());
|
||||
resp.setDept(UserConvert.INSTANCE.convert02(dept));
|
||||
}
|
||||
// 获得岗位信息
|
||||
@ -78,7 +76,7 @@ public class UserProfileController {
|
||||
resp.setPosts(UserConvert.INSTANCE.convertList02(posts));
|
||||
}
|
||||
// 获得社交用户信息
|
||||
List<SysSocialUserDO> socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN);
|
||||
List<SysSocialUserDO> socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN.getValue());
|
||||
resp.setSocialUsers(UserConvert.INSTANCE.convertList03(socialUsers));
|
||||
return success(resp);
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.system.convert.auth;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthMenuRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthPermissionInfoRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
@ -22,17 +22,17 @@ public interface AuthConvert {
|
||||
AuthConvert INSTANCE = Mappers.getMapper(AuthConvert.class);
|
||||
|
||||
@Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略
|
||||
LoginUser convert0(UserDO bean);
|
||||
LoginUser convert0(AdminUserDO bean);
|
||||
|
||||
default LoginUser convert(UserDO bean) {
|
||||
default LoginUser convert(AdminUserDO bean) {
|
||||
// 目的,为了设置 UserTypeEnum.ADMIN.getValue()
|
||||
return convert0(bean).setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
}
|
||||
|
||||
default AuthPermissionInfoRespVO convert(UserDO user, List<SysRoleDO> roleList, List<MenuDO> menuList) {
|
||||
default AuthPermissionInfoRespVO convert(AdminUserDO user, List<RoleDO> roleList, List<MenuDO> menuList) {
|
||||
return AuthPermissionInfoRespVO.builder()
|
||||
.user(AuthPermissionInfoRespVO.UserVO.builder().id(user.getId()).nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
||||
.roles(CollectionUtils.convertSet(roleList, SysRoleDO::getCode))
|
||||
.roles(CollectionUtils.convertSet(roleList, RoleDO::getCode))
|
||||
.permissions(CollectionUtils.convertSet(menuList, MenuDO::getPermission))
|
||||
.build();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.convert.logger;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO;
|
||||
@ -27,7 +27,7 @@ public interface OperateLogConvert {
|
||||
|
||||
OperateLogRespVO convert(OperateLogDO bean);
|
||||
|
||||
default List<OperateLogExcelVO> convertList(List<OperateLogDO> list, Map<Long, UserDO> userMap) {
|
||||
default List<OperateLogExcelVO> convertList(List<OperateLogDO> list, Map<Long, AdminUserDO> userMap) {
|
||||
return list.stream().map(operateLog -> {
|
||||
OperateLogExcelVO excelVO = convert02(operateLog);
|
||||
MapUtils.findAndThen(userMap, operateLog.getId(), user -> excelVO.setUserNickname(user.getNickname()));
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.SysLoginLogDO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.convert.permission;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -12,14 +12,14 @@ public interface RoleConvert {
|
||||
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
|
||||
SysRoleDO convert(RoleUpdateReqVO bean);
|
||||
RoleDO convert(RoleUpdateReqVO bean);
|
||||
|
||||
RoleRespVO convert(SysRoleDO bean);
|
||||
RoleRespVO convert(RoleDO bean);
|
||||
|
||||
SysRoleDO convert(RoleCreateReqVO bean);
|
||||
RoleDO convert(RoleCreateReqVO bean);
|
||||
|
||||
List<RoleSimpleRespVO> convertList02(List<SysRoleDO> list);
|
||||
List<RoleSimpleRespVO> convertList02(List<RoleDO> list);
|
||||
|
||||
List<RoleExcelVO> convertList03(List<SysRoleDO> list);
|
||||
List<RoleExcelVO> convertList03(List<RoleDO> list);
|
||||
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfi
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -19,31 +19,31 @@ public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
UserPageItemRespVO convert(UserDO bean);
|
||||
UserPageItemRespVO convert(AdminUserDO bean);
|
||||
|
||||
UserPageItemRespVO.Dept convert(SysDeptDO bean);
|
||||
|
||||
UserDO convert(UserCreateReqVO bean);
|
||||
AdminUserDO convert(UserCreateReqVO bean);
|
||||
|
||||
UserDO convert(UserUpdateReqVO bean);
|
||||
AdminUserDO convert(UserUpdateReqVO bean);
|
||||
|
||||
UserExcelVO convert02(UserDO bean);
|
||||
UserExcelVO convert02(AdminUserDO bean);
|
||||
|
||||
UserDO convert(UserImportExcelVO bean);
|
||||
AdminUserDO convert(UserImportExcelVO bean);
|
||||
|
||||
UserProfileRespVO convert03(UserDO bean);
|
||||
UserProfileRespVO convert03(AdminUserDO bean);
|
||||
|
||||
List<UserProfileRespVO.Role> convertList(List<SysRoleDO> list);
|
||||
List<UserProfileRespVO.Role> convertList(List<RoleDO> list);
|
||||
|
||||
UserProfileRespVO.Dept convert02(SysDeptDO bean);
|
||||
|
||||
UserDO convert(UserProfileUpdateReqVO bean);
|
||||
AdminUserDO convert(UserProfileUpdateReqVO bean);
|
||||
|
||||
UserDO convert(UserProfileUpdatePasswordReqVO bean);
|
||||
AdminUserDO convert(UserProfileUpdatePasswordReqVO bean);
|
||||
|
||||
List<UserProfileRespVO.Post> convertList02(List<SysPostDO> list);
|
||||
|
||||
List<UserProfileRespVO.SocialUser> convertList03(List<SysSocialUserDO> list);
|
||||
|
||||
List<UserSimpleRespVO> convertList04(List<UserDO> list);
|
||||
List<UserSimpleRespVO> convertList04(List<AdminUserDO> list);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.dept;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@ -41,7 +41,7 @@ public class SysDeptDO extends TenantBaseDO {
|
||||
/**
|
||||
* 负责人
|
||||
*
|
||||
* 关联 {@link UserDO#getId()}
|
||||
* 关联 {@link AdminUserDO#getId()}
|
||||
*/
|
||||
private Long leaderUserId;
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.logger;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum;
|
||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||
@ -48,7 +48,7 @@ public class OperateLogDO extends TenantBaseDO {
|
||||
/**
|
||||
* 用户编号
|
||||
*
|
||||
* {@link UserDO#getId()}
|
||||
* {@link AdminUserDO#getId()}
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
|
@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.system.dal.dataobject.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.SysLoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.SysLoginResultEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -29,7 +29,7 @@ public class SysLoginLogDO extends BaseDO {
|
||||
/**
|
||||
* 日志类型
|
||||
*
|
||||
* 枚举 {@link SysLoginLogTypeEnum}
|
||||
* 枚举 {@link LoginLogTypeEnum}
|
||||
*/
|
||||
private Integer logType;
|
||||
/**
|
||||
@ -55,7 +55,7 @@ public class SysLoginLogDO extends BaseDO {
|
||||
/**
|
||||
* 登录结果
|
||||
*
|
||||
* 枚举 {@link SysLoginResultEnum}
|
||||
* 枚举 {@link LoginResultEnum}
|
||||
*/
|
||||
private Integer result;
|
||||
/**
|
||||
|
@ -17,10 +17,10 @@ import java.util.Set;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@TableName(value = "sys_role", autoResultMap = true)
|
||||
@TableName(value = "system_role", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysRoleDO extends BaseDO {
|
||||
public class RoleDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 角色ID
|
@ -11,10 +11,10 @@ import lombok.EqualsAndHashCode;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@TableName("sys_user_role")
|
||||
@TableName("system_user_role")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysUserRoleDO extends BaseDO {
|
||||
public class UserRoleDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 自增主键
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.member.dal.dataobject.sms;
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@ -13,13 +13,13 @@ import java.util.Date;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("sys_sms_code")
|
||||
@TableName("system_sms_code")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysSmsCodeDO extends BaseDO {
|
||||
public class SmsCodeDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
@ -36,7 +36,7 @@ public class SysSmsCodeDO extends BaseDO {
|
||||
/**
|
||||
* 发送场景
|
||||
*
|
||||
* 枚举 {@link SysSmsCodeDO}
|
||||
* 枚举 {@link SmsCodeDO}
|
||||
*/
|
||||
private Integer scene;
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.social;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@ -9,7 +9,7 @@ import lombok.*;
|
||||
|
||||
/**
|
||||
* 社交用户
|
||||
* 通过 {@link SysSocialUserDO#getUserId()} 关联到对应的 {@link UserDO}
|
||||
* 通过 {@link SysSocialUserDO#getUserId()} 关联到对应的 {@link AdminUserDO}
|
||||
*
|
||||
* @author weir
|
||||
*/
|
||||
|
@ -24,7 +24,7 @@ import java.util.Set;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserDO extends TenantBaseDO {
|
||||
public class AdminUserDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* 用户ID
|
@ -12,7 +12,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysMenuMapper extends BaseMapperX<MenuDO> {
|
||||
public interface MenuMapper extends BaseMapperX<MenuDO> {
|
||||
|
||||
default MenuDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(new LambdaQueryWrapper<MenuDO>().eq(MenuDO::getParentId, parentId)
|
@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.lang.Nullable;
|
||||
@ -15,36 +15,36 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends BaseMapperX<SysRoleDO> {
|
||||
public interface RoleMapper extends BaseMapperX<RoleDO> {
|
||||
|
||||
default PageResult<SysRoleDO> selectPage(RolePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<SysRoleDO>().likeIfPresent("name", reqVO.getName())
|
||||
default PageResult<RoleDO> selectPage(RolePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<RoleDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("code", reqVO.getCode())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default List<SysRoleDO> listRoles(RoleExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<SysRoleDO>().likeIfPresent("name", reqVO.getName())
|
||||
default List<RoleDO> listRoles(RoleExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<RoleDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("code", reqVO.getCode())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default SysRoleDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapperX<SysRoleDO>().eq("name", name));
|
||||
default RoleDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapperX<RoleDO>().eq("name", name));
|
||||
}
|
||||
|
||||
default SysRoleDO selectByCode(String code) {
|
||||
return selectOne(new QueryWrapperX<SysRoleDO>().eq("code", code));
|
||||
default RoleDO selectByCode(String code) {
|
||||
return selectOne(new QueryWrapperX<RoleDO>().eq("code", code));
|
||||
}
|
||||
|
||||
default List<SysRoleDO> selectListByStatus(@Nullable Collection<Integer> statuses) {
|
||||
return selectList(new QueryWrapperX<SysRoleDO>().in("status", statuses));
|
||||
default List<RoleDO> selectListByStatus(@Nullable Collection<Integer> statuses) {
|
||||
return selectList(new QueryWrapperX<RoleDO>().in("status", statuses));
|
||||
}
|
||||
|
||||
default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) {
|
||||
return selectOne(new QueryWrapper<SysRoleDO>().select("id")
|
||||
return selectOne(new QueryWrapper<RoleDO>().select("id")
|
||||
.gt("update_time", maxUpdateTime).last("LIMIT 1")) != null;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper extends BaseMapperX<RoleMenuDO> {
|
||||
public interface RoleMenuMapper extends BaseMapperX<RoleMenuDO> {
|
||||
|
||||
default List<RoleMenuDO> selectListByRoleId(Long roleId) {
|
||||
return selectList(new QueryWrapper<RoleMenuDO>().eq("role_id", roleId));
|
@ -1,9 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.permission;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleCoreMapper extends BaseMapperX<SysRoleDO> {
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.permission;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysUserRoleDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserRoleCoreMapper extends BaseMapperX<SysUserRoleDO> {
|
||||
|
||||
default List<SysUserRoleDO> selectListByRoleIds(Collection<Long> roleIds) {
|
||||
return selectList(SysUserRoleDO::getRoleId, roleIds);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.permission;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysUserRoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@ -10,20 +10,20 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapperX<SysUserRoleDO> {
|
||||
public interface UserRoleMapper extends BaseMapperX<UserRoleDO> {
|
||||
|
||||
default List<SysUserRoleDO> selectListByUserId(Long userId) {
|
||||
return selectList(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
|
||||
default List<UserRoleDO> selectListByUserId(Long userId) {
|
||||
return selectList(new QueryWrapper<UserRoleDO>().eq("user_id", userId));
|
||||
}
|
||||
|
||||
default List<SysUserRoleDO> selectListByRoleId(Long roleId) {
|
||||
return selectList(new QueryWrapper<SysUserRoleDO>().eq("role_id", roleId));
|
||||
default List<UserRoleDO> selectListByRoleId(Long roleId) {
|
||||
return selectList(new QueryWrapper<UserRoleDO>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
|
||||
default void insertList(Long userId, Collection<Long> roleIds) {
|
||||
List<SysUserRoleDO> list = roleIds.stream().map(roleId -> {
|
||||
SysUserRoleDO entity = new SysUserRoleDO();
|
||||
List<UserRoleDO> list = roleIds.stream().map(roleId -> {
|
||||
UserRoleDO entity = new UserRoleDO();
|
||||
entity.setUserId(userId);
|
||||
entity.setRoleId(roleId);
|
||||
return entity;
|
||||
@ -32,16 +32,20 @@ public interface SysUserRoleMapper extends BaseMapperX<SysUserRoleDO> {
|
||||
}
|
||||
|
||||
default void deleteListByUserIdAndRoleIdIds(Long userId, Collection<Long> roleIds) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId)
|
||||
delete(new QueryWrapper<UserRoleDO>().eq("user_id", userId)
|
||||
.in("role_id", roleIds));
|
||||
}
|
||||
|
||||
default void deleteListByUserId(Long userId) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
|
||||
delete(new QueryWrapper<UserRoleDO>().eq("user_id", userId));
|
||||
}
|
||||
|
||||
default void deleteListByRoleId(Long roleId) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("role_id", roleId));
|
||||
delete(new QueryWrapper<UserRoleDO>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
|
||||
default List<UserRoleDO> selectListByRoleIds(Collection<Long> roleIds) {
|
||||
return selectList(UserRoleDO::getRoleId, roleIds);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Select;
|
||||
import java.util.Date;
|
||||
|
||||
@Mapper
|
||||
public interface SysSmsChannelMapper extends BaseMapperX<SysSmsChannelDO> {
|
||||
public interface SmsChannelMapper extends BaseMapperX<SysSmsChannelDO> {
|
||||
|
||||
default PageResult<SysSmsChannelDO> selectPage(SmsChannelPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<SysSmsChannelDO>()
|
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SmsCodeMapper extends BaseMapperX<SmsCodeDO> {
|
||||
|
||||
/**
|
||||
* 获得手机号的最后一个手机验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param scene 发送场景,选填
|
||||
* @param code 验证码 选填
|
||||
* @return 手机验证码
|
||||
*/
|
||||
default SmsCodeDO selectLastByMobile(String mobile, String code, Integer scene) {
|
||||
return selectOne(new QueryWrapperX<SmsCodeDO>()
|
||||
.eq("mobile", mobile).eqIfPresent("scene", scene).eqIfPresent("code", code)
|
||||
.orderByDesc("id").last(SqlConstants.LIMIT1));
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysSmsLogMapper extends BaseMapperX<SysSmsLogDO> {
|
||||
public interface SmsLogMapper extends BaseMapperX<SysSmsLogDO> {
|
||||
|
||||
default PageResult<SysSmsLogDO> selectPage(SmsLogPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<SysSmsLogDO>()
|
@ -13,7 +13,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysSmsTemplateMapper extends BaseMapperX<SysSmsTemplateDO> {
|
||||
public interface SmsTemplateMapper extends BaseMapperX<SysSmsTemplateDO> {
|
||||
|
||||
@Select("SELECT id FROM sys_sms_template WHERE update_time > #{maxUpdateTime} LIMIT 1")
|
||||
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.user;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
|
||||
default AdminUserDO selectByUsername(String username) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getUsername, username));
|
||||
}
|
||||
|
||||
default AdminUserDO selectByEmail(String email) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getEmail, email));
|
||||
}
|
||||
|
||||
default AdminUserDO selectByMobile(String mobile) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getMobile, mobile));
|
||||
}
|
||||
|
||||
default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime())
|
||||
.inIfPresent(AdminUserDO::getDeptId, deptIds));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectList(UserExportReqVO reqVO, Collection<Long> deptIds) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime())
|
||||
.inIfPresent(AdminUserDO::getDeptId, deptIds));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByNickname(String nickname) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByUsername(String username) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getUsername, username));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByStatus(Integer status) {
|
||||
return selectList(AdminUserDO::getStatus, status);
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByDeptIds(Collection<Long> deptIds) {
|
||||
return selectList(AdminUserDO::getDeptId, deptIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.user;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jodd.util.StringPool;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapperX<UserDO> {
|
||||
|
||||
default UserDO selectByUsername(String username) {
|
||||
return selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getUsername, username));
|
||||
}
|
||||
|
||||
default UserDO selectByEmail(String email) {
|
||||
return selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getEmail, email));
|
||||
}
|
||||
|
||||
default UserDO selectByMobile(String mobile) {
|
||||
return selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getMobile, mobile));
|
||||
}
|
||||
|
||||
default PageResult<UserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<UserDO>()
|
||||
.likeIfPresent(UserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(UserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(UserDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(UserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime())
|
||||
.inIfPresent(UserDO::getDeptId, deptIds));
|
||||
}
|
||||
|
||||
default List<UserDO> selectList(UserExportReqVO reqVO, Collection<Long> deptIds) {
|
||||
return selectList(new LambdaQueryWrapperX<UserDO>()
|
||||
.likeIfPresent(UserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(UserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(UserDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(UserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime())
|
||||
.inIfPresent(UserDO::getDeptId, deptIds));
|
||||
}
|
||||
|
||||
default List<UserDO> selectListByNickname(String nickname) {
|
||||
return selectList(new LambdaQueryWrapperX<UserDO>().like(UserDO::getNickname, nickname));
|
||||
}
|
||||
|
||||
default List<UserDO> selectListByUsername(String username) {
|
||||
return selectList(new LambdaQueryWrapperX<UserDO>().like(UserDO::getUsername, username));
|
||||
}
|
||||
|
||||
default List<UserDO> selectListByStatus(Integer status) {
|
||||
return selectList(UserDO::getStatus, status);
|
||||
}
|
||||
|
||||
default List<UserDO> selectListByDeptIds(Collection<Long> deptIds) {
|
||||
return selectList(UserDO::getDeptId, deptIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.framework.datapermission.config;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.dept.rule.DeptDataPermissionRuleCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -17,7 +17,7 @@ public class DataPermissionConfiguration {
|
||||
@Bean
|
||||
public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
|
||||
return rule -> {
|
||||
rule.addDeptColumn(UserDO.class);
|
||||
rule.addDeptColumn(AdminUserDO.class);
|
||||
rule.addDeptColumn(SysDeptDO.class, "id");
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.member.framework.sms;
|
||||
package cn.iocoder.yudao.module.system.framework.sms;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
@ -1,13 +1,11 @@
|
||||
package cn.iocoder.yudao.module.member.framework.sms;
|
||||
package cn.iocoder.yudao.module.system.framework.sms;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
|
||||
@ConfigurationProperties(prefix = "yudao.sms-code")
|
||||
@Validated
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.mq.consumer.sms;
|
||||
|
||||
import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SysSmsSendService;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
||||
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -19,7 +19,7 @@ import javax.annotation.Resource;
|
||||
public class SmsSendConsumer extends AbstractStreamMessageListener<SmsSendMessage> {
|
||||
|
||||
@Resource
|
||||
private SysSmsSendService smsCoreService;
|
||||
private SmsSendService smsCoreService;
|
||||
|
||||
@Override
|
||||
public void onMessage(SmsSendMessage message) {
|
||||
|
@ -12,7 +12,7 @@ import javax.validation.Valid;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface AuthService extends SecurityAuthFrameworkService {
|
||||
public interface AdminAuthService extends SecurityAuthFrameworkService {
|
||||
|
||||
/**
|
||||
* 账号登录
|
@ -13,15 +13,15 @@ import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLo
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLoginReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
||||
import cn.iocoder.yudao.module.system.service.common.CaptchaService;
|
||||
import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -50,9 +50,9 @@ import static java.util.Collections.singleton;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service("adminAuthService")
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,因为存在相互依赖的问题
|
||||
@ -60,7 +60,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // UserService 存在重名
|
||||
private UserService userService;
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
@Resource
|
||||
@ -75,7 +75,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// 获取 username 对应的 SysUserDO
|
||||
UserDO user = userService.getUserByUsername(username);
|
||||
AdminUserDO user = userService.getUserByUsername(username);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Override
|
||||
public LoginUser mockLogin(Long userId) {
|
||||
// 获取用户编号对应的 SysUserDO
|
||||
UserDO user = userService.getUser(userId);
|
||||
AdminUserDO user = userService.getUser(userId);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(String.valueOf(userId));
|
||||
}
|
||||
@ -160,7 +160,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
private void createLoginLog(String username, LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) {
|
||||
// 获得用户
|
||||
UserDO user = userService.getUserByUsername(username);
|
||||
AdminUserDO user = userService.getUserByUsername(username);
|
||||
// 插入登录日志
|
||||
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(logTypeEnum.getType());
|
||||
@ -198,13 +198,13 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
// 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错
|
||||
String unionId = socialService.getAuthUserUnionId(authUser);
|
||||
List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, getUserType());
|
||||
List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, getUserType().getValue());
|
||||
if (CollUtil.isEmpty(socialUsers)) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
|
||||
// 自动登录
|
||||
UserDO user = userService.getUser(socialUsers.get(0).getUserId());
|
||||
AdminUserDO user = userService.getUser(socialUsers.get(0).getUserId());
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
@ -214,7 +214,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
LoginUser loginUser = this.buildLoginUser(user);
|
||||
|
||||
// 绑定社交用户(更新)
|
||||
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType());
|
||||
socialService.bindSocialUser(loginUser.getId(), getUserType().getValue(), reqVO.getType(), authUser);
|
||||
|
||||
// 缓存登录用户到 Redis 中,返回 sessionId 编号
|
||||
return userSessionService.createUserSession(loginUser, userIp, userAgent);
|
||||
@ -230,7 +230,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword());
|
||||
|
||||
// 绑定社交用户(新增)
|
||||
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType());
|
||||
socialService.bindSocialUser(loginUser.getId(), getUserType().getValue(), reqVO.getType(), authUser);
|
||||
|
||||
// 缓存登录用户到 Redis 中,返回 sessionId 编号
|
||||
return userSessionService.createUserSession(loginUser, userIp, userAgent);
|
||||
@ -243,7 +243,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
Assert.notNull(authUser, "授权用户不为空");
|
||||
|
||||
// 绑定社交用户(新增)
|
||||
socialService.bindSocialUser(userId, reqVO.getType(), authUser, getUserType());
|
||||
socialService.bindSocialUser(userId, getUserType().getValue(), reqVO.getType(), authUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -296,7 +296,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
}
|
||||
|
||||
// 重新加载 SysUserDO 信息
|
||||
UserDO user = userService.getUser(loginUser.getId());
|
||||
AdminUserDO user = userService.getUser(loginUser.getId());
|
||||
if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) {
|
||||
throw exception(AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面
|
||||
}
|
||||
@ -307,7 +307,7 @@ public class AuthServiceImpl implements AuthService {
|
||||
return newLoginUser;
|
||||
}
|
||||
|
||||
private LoginUser buildLoginUser(UserDO user) {
|
||||
private LoginUser buildLoginUser(AdminUserDO user) {
|
||||
LoginUser loginUser = AuthConvert.INSTANCE.convert(user);
|
||||
// 补全字段
|
||||
loginUser.setDeptId(user.getDeptId());
|
@ -6,15 +6,15 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.session.UserSessionPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.auth.SysUserSessionMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
||||
import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.auth.SysUserSessionDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.redis.auth.LoginUserRedisDAO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -42,7 +42,7 @@ public class UserSessionServiceImpl implements UserSessionService {
|
||||
private SysUserSessionMapper userSessionMapper;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private LoginLogService loginLogService;
|
||||
|
||||
@ -57,7 +57,7 @@ public class UserSessionServiceImpl implements UserSessionService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUsername())) {
|
||||
userIds = convertSet(userService.getUsersByUsername(reqVO.getUsername()), UserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByUsername(reqVO.getUsername()), AdminUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 部门 Service 接口
|
||||
@ -59,4 +64,50 @@ public interface DeptService {
|
||||
*/
|
||||
List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
/**
|
||||
* 获得部门信息数组
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门信息数组
|
||||
*/
|
||||
List<SysDeptDO> getDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
*
|
||||
* @param id 部门编号
|
||||
* @return 部门信息
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
/**
|
||||
* 校验部门们是否有效。如下情况,视为无效:
|
||||
* 1. 部门编号不存在
|
||||
* 2. 部门被禁用
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
*/
|
||||
void validDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门列表
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> getSimpleDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, SysDeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysDeptDO> list = getSimpleDepts(ids);
|
||||
return CollectionUtils.convertMap(list, SysDeptDO::getId);
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ package cn.iocoder.yudao.module.system.service.dept;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.dept.DeptConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysDeptMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysDeptMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.dept.DeptIdEnum;
|
||||
import cn.iocoder.yudao.module.system.mq.producer.dept.DeptProducer;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@ -24,8 +25,8 @@ import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 部门 Service 实现类
|
||||
@ -257,4 +258,39 @@ public class DeptServiceImpl implements DeptService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> getDepts(Collection<Long> ids) {
|
||||
return deptMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDeptDO getDept(Long id) {
|
||||
return deptMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validDepts(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得科室信息
|
||||
List<SysDeptDO> depts = deptMapper.selectBatchIds(ids);
|
||||
Map<Long, SysDeptDO> deptMap = CollectionUtils.convertMap(depts, SysDeptDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
SysDeptDO dept = deptMap.get(id);
|
||||
if (dept == null) {
|
||||
throw exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
|
||||
throw exception(DEPT_NOT_ENABLE, dept.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> getSimpleDepts(Collection<Long> ids) {
|
||||
return deptMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,4 +86,13 @@ public interface PostService {
|
||||
*/
|
||||
SysPostDO getPost(Long id);
|
||||
|
||||
/**
|
||||
* 校验岗位们是否有效。如下情况,视为无效:
|
||||
* 1. 岗位编号不存在
|
||||
* 2. 岗位被禁用
|
||||
*
|
||||
* @param ids 岗位编号数组
|
||||
*/
|
||||
void validPosts(Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO;
|
||||
@ -7,17 +9,19 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportRe
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.dept.PostConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysPostMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysPostMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 岗位 Service 实现类
|
||||
@ -125,4 +129,23 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validPosts(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得岗位信息
|
||||
List<SysPostDO> posts = postMapper.selectBatchIds(ids);
|
||||
Map<Long, SysPostDO> postMap = convertMap(posts, SysPostDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
SysPostDO post = postMap.get(id);
|
||||
if (post == null) {
|
||||
throw exception(POST_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(post.getStatus())) {
|
||||
throw exception(POST_NOT_ENABLE, post.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SysDeptCoreService {
|
||||
/**
|
||||
* 获得部门信息数组
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门信息数组
|
||||
*/
|
||||
List<SysDeptDO> getDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
*
|
||||
* @param id 部门编号
|
||||
* @return 部门信息
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
/**
|
||||
* 校验部门们是否有效。如下情况,视为无效:
|
||||
* 1. 部门编号不存在
|
||||
* 2. 部门被禁用
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
*/
|
||||
void validDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门列表
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> getSimpleDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, SysDeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysDeptDO> list = getSimpleDepts(ids);
|
||||
return CollectionUtils.convertMap(list, SysDeptDO::getId);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 岗位 Core Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysPostCoreService {
|
||||
/**
|
||||
* 校验岗位们是否有效。如下情况,视为无效:
|
||||
* 1. 岗位编号不存在
|
||||
* 2. 岗位被禁用
|
||||
*
|
||||
* @param ids 岗位编号数组
|
||||
*/
|
||||
void validPosts(Collection<Long> ids);
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysDeptCoreMapper;
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysDeptCoreService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.module.system.enums.SysErrorCodeConstants.DEPT_NOT_ENABLE;
|
||||
import static cn.iocoder.yudao.module.system.enums.SysErrorCodeConstants.DEPT_NOT_FOUND;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 部门 Core Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysDeptCoreServiceImpl implements SysDeptCoreService {
|
||||
|
||||
@Resource
|
||||
private SysDeptCoreMapper deptCoreMapper;
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> getDepts(Collection<Long> ids) {
|
||||
return deptCoreMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDeptDO getDept(Long id) {
|
||||
return deptCoreMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validDepts(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得科室信息
|
||||
List<SysDeptDO> depts = deptCoreMapper.selectBatchIds(ids);
|
||||
Map<Long, SysDeptDO> deptMap = CollectionUtils.convertMap(depts, SysDeptDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
SysDeptDO dept = deptMap.get(id);
|
||||
if (dept == null) {
|
||||
throw exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
|
||||
throw exception(DEPT_NOT_ENABLE, dept.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> getSimpleDepts(Collection<Long> ids) {
|
||||
return deptCoreMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.SysPostCoreMapper;
|
||||
import cn.iocoder.yudao.module.system.service.dept.SysPostCoreService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.module.system.enums.SysErrorCodeConstants.POST_NOT_ENABLE;
|
||||
import static cn.iocoder.yudao.module.system.enums.SysErrorCodeConstants.POST_NOT_FOUND;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 岗位 Core Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class SysPostCoreServiceImpl implements SysPostCoreService {
|
||||
|
||||
@Resource
|
||||
private SysPostCoreMapper sysPostCoreMapper;
|
||||
|
||||
@Override
|
||||
public void validPosts(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得岗位信息
|
||||
List<SysPostDO> posts = sysPostCoreMapper.selectBatchIds(ids);
|
||||
Map<Long, SysPostDO> postMap = CollectionUtils.convertMap(posts, SysPostDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
SysPostDO post = postMap.get(id);
|
||||
if (post == null) {
|
||||
throw exception(POST_NOT_FOUND);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(post.getStatus())) {
|
||||
throw exception(POST_NOT_ENABLE, post.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -4,8 +4,9 @@ import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginL
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.SysLoginLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -34,6 +35,6 @@ public interface LoginLogService {
|
||||
*
|
||||
* @param reqDTO 日志信息
|
||||
*/
|
||||
void createLoginLog(LoginLogCreateReqDTO reqDTO);
|
||||
void createLoginLog(@Valid LoginLogCreateReqDTO reqDTO);
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.module.system.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.logger.SysLoginLogCoreConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.SysLoginLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.SysLoginLogCoreMapper;
|
||||
import cn.iocoder.yudao.module.system.service.logger.dto.LoginLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -35,7 +34,6 @@ public class LoginLogServiceImpl implements LoginLogService {
|
||||
@Override
|
||||
public void createLoginLog(LoginLogCreateReqDTO reqDTO) {
|
||||
SysLoginLogDO loginLog = SysLoginLogCoreConvert.INSTANCE.convert(reqDTO);
|
||||
// 插入
|
||||
loginLogMapper.insert(loginLog);
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@ import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.Oper
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper;
|
||||
import cn.iocoder.yudao.module.system.service.user.UserService;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.UserDO;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.string.StrUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO;
|
||||
@ -35,7 +35,7 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
private OperateLogMapper operateLogMapper;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private AdminUserService userService;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
@ -58,7 +58,7 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), UserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), UserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuLi
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.permission.MenuConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.permission.SysMenuMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.mq.producer.permission.MenuProducer;
|
||||
@ -67,7 +67,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
private volatile Date maxUpdateTime;
|
||||
|
||||
@Resource
|
||||
private SysMenuMapper menuMapper;
|
||||
private MenuMapper menuMapper;
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user