Merge branch 'feature/admin' into preview
commit
a0c6c39c03
|
@ -1,18 +1,5 @@
|
|||
package com.mcwl.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
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.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.mcwl.common.annotation.Log;
|
||||
import com.mcwl.common.constant.UserConstants;
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
|
@ -21,10 +8,17 @@ import com.mcwl.common.core.domain.entity.SysDept;
|
|||
import com.mcwl.common.enums.BusinessType;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.system.service.ISysDeptService;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门信息
|
||||
*
|
||||
*
|
||||
* @author mcwl
|
||||
*/
|
||||
@RestController
|
||||
|
|
|
@ -1,29 +1,38 @@
|
|||
package com.mcwl.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.mcwl.common.annotation.Anonymous;
|
||||
import com.mcwl.common.constant.Constants;
|
||||
import com.mcwl.common.constant.RedisConstants;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.entity.SysMenu;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.domain.model.LoginBody;
|
||||
import com.mcwl.common.core.domain.model.LoginUser;
|
||||
import com.mcwl.common.core.domain.model.PhoneLoginBody;
|
||||
import com.mcwl.common.core.redis.RedisCache;
|
||||
import com.mcwl.common.utils.CodeUtils;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.common.utils.uuid.TelSmsUtils;
|
||||
import com.mcwl.framework.web.service.SysLoginService;
|
||||
import com.mcwl.framework.web.service.SysPermissionService;
|
||||
import com.mcwl.framework.web.service.TokenService;
|
||||
import com.mcwl.system.service.ISysMenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
* @author mcwl
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SysLoginController
|
||||
{
|
||||
|
@ -39,6 +48,31 @@ public class SysLoginController
|
|||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
|
||||
@Anonymous
|
||||
@GetMapping("/getCode")
|
||||
public AjaxResult code(@RequestParam String phone){
|
||||
|
||||
//生成验证码
|
||||
String s = CodeUtils.generateCaptcha();
|
||||
|
||||
log.info("获取到的验证码:{}",s);
|
||||
//存储redis
|
||||
redisCache.setCacheObject(RedisConstants.CODE_PHONE+phone,s,1, TimeUnit.MINUTES);
|
||||
|
||||
//发送短信服务
|
||||
// 构建 sendDataMap
|
||||
Map<String, String> sendDataMap = new HashMap<>();
|
||||
sendDataMap.put("code:", s);
|
||||
TelSmsUtils.sendSms(phone,"SMS_460535072",sendDataMap);
|
||||
|
||||
return AjaxResult.success();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
|
@ -56,6 +90,20 @@ public class SysLoginController
|
|||
return ajax;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/phoneLogin")
|
||||
@Anonymous
|
||||
public AjaxResult phoneLogin(@RequestBody PhoneLoginBody phoneLoginBody){
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.phoneLogin(phoneLoginBody.getPhone(),phoneLoginBody.getCode());
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
|
|
|
@ -1,21 +1,5 @@
|
|||
package com.mcwl.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
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.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.mcwl.common.annotation.Log;
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
|
@ -31,6 +15,16 @@ import com.mcwl.system.service.ISysDeptService;
|
|||
import com.mcwl.system.service.ISysPostService;
|
||||
import com.mcwl.system.service.ISysRoleService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
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.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
|
|
|
@ -286,6 +286,13 @@
|
|||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里大鱼 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.mcwl.common.constant;
|
||||
|
||||
/**
|
||||
* redis存储前缀常量
|
||||
*
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/28
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public class RedisConstants {
|
||||
|
||||
public static final String CODE_PHONE = "code_phone:";
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.mcwl.common.core.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 手机号登录对象
|
||||
*
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/28
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class PhoneLoginBody {
|
||||
|
||||
private String phone;
|
||||
|
||||
private String code;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.mcwl.common.enums;
|
||||
|
||||
/**
|
||||
* 返回值状态码
|
||||
*
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public enum ResultCode {
|
||||
|
||||
SUCCESS(200),//成功
|
||||
|
||||
FAIL(400),//失败
|
||||
|
||||
FAIL_SIGN_IN(401),//登录失败
|
||||
|
||||
TOKEN_OVERDUE(402),//token过期
|
||||
|
||||
NOT_FOUND(404),//接口不存在
|
||||
|
||||
INTERNAL_SERVICE_ERROR(500);//服务器内部错误
|
||||
|
||||
private final Integer code;
|
||||
|
||||
ResultCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
private Integer code() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.mcwl.common.exception;
|
||||
|
||||
import com.mcwl.common.enums.ResultCode;
|
||||
|
||||
/**
|
||||
* 自定义异常类
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public class ErrorCodeException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
|
||||
public ErrorCodeException(ResultCode resultCode, String msg) {
|
||||
this.code = resultCode.getCode();
|
||||
this.message = msg;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.mcwl.common.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 验证码工具类
|
||||
*
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/28
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public class CodeUtils {
|
||||
|
||||
/**
|
||||
* 生成一个随机的4位数验证码
|
||||
*
|
||||
* @return 返回生成的验证码字符串
|
||||
*/
|
||||
public static String generateCaptcha() {
|
||||
// 创建Random对象用于生成随机数
|
||||
Random random = new Random();
|
||||
// 生成1000到9999之间的随机整数(包括1000和9999)
|
||||
int captcha = 1000 + random.nextInt(9000);
|
||||
// 将整数转换为字符串并返回
|
||||
return String.valueOf(captcha);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.mcwl.common.utils.uuid;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class TelSmsUtils {
|
||||
|
||||
/**
|
||||
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||
*/
|
||||
private static String accessKeyId = "LTAIEVXszCmcd1T5";
|
||||
private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd";
|
||||
|
||||
/**
|
||||
* 短信访问域名
|
||||
*/
|
||||
private static String endpoint = "dysmsapi.aliyuncs.com";
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private static String signName = "帝宇";
|
||||
|
||||
/**
|
||||
* 实例化短信对象
|
||||
*/
|
||||
private static Client client;
|
||||
|
||||
static {
|
||||
log.info("初始化短信服务开始");
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
client = initClient();
|
||||
log.info("初始化短信成功:{}",signName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("初始化短信服务结束:耗时:{}MS",(System.currentTimeMillis()-startTime));
|
||||
}
|
||||
/**
|
||||
* 初始化短信对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Client initClient() throws Exception{
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = endpoint;
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送单条短信
|
||||
* @param tel
|
||||
* @param templateCode SMS_153991546
|
||||
* @param sendDataMap
|
||||
*/
|
||||
public static String sendSms(String tel , String templateCode , Map<String,String> sendDataMap){
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setPhoneNumbers(tel)
|
||||
.setSignName(signName)
|
||||
.setTemplateCode(templateCode)
|
||||
.setTemplateParam(JSONObject.toJSONString(sendDataMap));
|
||||
SendSmsResponse sendSmsResponse = null;
|
||||
try {
|
||||
log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap));
|
||||
sendSmsResponse = client.sendSms(sendSmsRequest);
|
||||
} catch (Exception e) {
|
||||
log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e);
|
||||
}
|
||||
return JSONObject.toJSONString(sendSmsResponse.getBody());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,11 @@
|
|||
package com.mcwl.framework.config;
|
||||
|
||||
import com.mcwl.framework.config.properties.PermitAllUrlProperties;
|
||||
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||
import com.mcwl.framework.security.filter.JwtAuthenticationTokenFilter;
|
||||
import com.mcwl.framework.security.handle.AuthenticationEntryPointImpl;
|
||||
import com.mcwl.framework.security.handle.LogoutSuccessHandlerImpl;
|
||||
import com.mcwl.framework.security.sms.SmsCodeByEmailAuthenticationProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -16,10 +22,6 @@ import org.springframework.security.web.SecurityFilterChain;
|
|||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import com.mcwl.framework.config.properties.PermitAllUrlProperties;
|
||||
import com.mcwl.framework.security.filter.JwtAuthenticationTokenFilter;
|
||||
import com.mcwl.framework.security.handle.AuthenticationEntryPointImpl;
|
||||
import com.mcwl.framework.security.handle.LogoutSuccessHandlerImpl;
|
||||
|
||||
/**
|
||||
* spring security配置
|
||||
|
@ -36,6 +38,13 @@ public class SecurityConfig
|
|||
@Autowired
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
/**
|
||||
* 自定义用户(手机号验证码)认证逻辑
|
||||
*/
|
||||
@Autowired
|
||||
private OtherUserDetailsService userDetailsServiceByPhone;
|
||||
|
||||
|
||||
/**
|
||||
* 认证失败处理类
|
||||
*/
|
||||
|
@ -78,6 +87,15 @@ public class SecurityConfig
|
|||
return new ProviderManager(daoAuthenticationProvider);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public AuthenticationManager authenticationManagerPhone() {
|
||||
SmsCodeByEmailAuthenticationProvider daoAuthenticationProvider = new SmsCodeByEmailAuthenticationProvider();
|
||||
daoAuthenticationProvider.setUserDetailsService(userDetailsServiceByPhone);
|
||||
return new ProviderManager(daoAuthenticationProvider);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* anyRequest | 匹配所有请求路径
|
||||
* access | SpringEl表达式结果为true时可以访问
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.mcwl.framework.security.core;
|
||||
|
||||
import com.mcwl.framework.security.core.otherUserdetails.OtherLoginNotFoundException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
/**
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public interface OtherUserDetailsService {
|
||||
|
||||
UserDetails otherLoadUser(String o, int num) throws OtherLoginNotFoundException;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.mcwl.framework.security.core.otherUserdetails;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
/**
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
|
||||
public class OtherLoginNotFoundException extends AuthenticationException {
|
||||
public OtherLoginNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public OtherLoginNotFoundException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.mcwl.framework.security.sms;
|
||||
|
||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 短信登录 AuthenticationToken,模仿 UsernamePasswordAuthenticationToken 实现
|
||||
*
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {
|
||||
|
||||
private static final long serialVersionUID = 550L;
|
||||
|
||||
/**
|
||||
* 在 UsernamePasswordAuthenticationToken 中该字段代表登录的用户名,
|
||||
* 在这里就代表登录的手机号码或邮箱
|
||||
*/
|
||||
private final Object principal;
|
||||
|
||||
/**
|
||||
* 构建一个没有鉴权的 SmsCodeAuthenticationToken
|
||||
*/
|
||||
public SmsCodeAuthenticationToken(Object principal) {
|
||||
super(null);
|
||||
this.principal = principal;
|
||||
setAuthenticated(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建拥有鉴权的 SmsCodeAuthenticationToken
|
||||
*/
|
||||
public SmsCodeAuthenticationToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
|
||||
super(authorities);
|
||||
this.principal = principal;
|
||||
super.setAuthenticated(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return this.principal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
|
||||
if (isAuthenticated) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
||||
}
|
||||
|
||||
super.setAuthenticated(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseCredentials() {
|
||||
super.eraseCredentials();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implies(Subject subject) {
|
||||
return super.implies(subject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.mcwl.framework.security.sms;
|
||||
|
||||
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
/**
|
||||
* @author DaiZibo
|
||||
* @date 2024/12/30
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
|
||||
public class SmsCodeByEmailAuthenticationProvider implements AuthenticationProvider {
|
||||
private OtherUserDetailsService userDetailsService;
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
SmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication;
|
||||
|
||||
String email = (String) authenticationToken.getPrincipal();
|
||||
UserDetails userDetails = userDetailsService.otherLoadUser(email, 1);
|
||||
|
||||
// 此时鉴权成功后,应当重新 new 一个拥有鉴权的 authenticationResult 返回
|
||||
SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(userDetails, userDetails.getAuthorities());
|
||||
authenticationResult.setDetails(authenticationToken.getDetails());
|
||||
|
||||
return authenticationResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> authentication) {
|
||||
// 判断 authentication 是不是 SmsCodeAuthenticationToken 的子类或子接口
|
||||
return SmsCodeAuthenticationToken.class.isAssignableFrom(authentication);
|
||||
}
|
||||
|
||||
public OtherUserDetailsService getUserDetailsService() {
|
||||
return userDetailsService;
|
||||
}
|
||||
|
||||
public void setUserDetailsService(OtherUserDetailsService userDetailsService) {
|
||||
this.userDetailsService = userDetailsService;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,13 @@
|
|||
package com.mcwl.framework.web.exception;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.text.Convert;
|
||||
import com.mcwl.common.exception.DemoModeException;
|
||||
import com.mcwl.common.exception.ErrorCodeException;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.common.utils.html.EscapeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
|
@ -11,13 +18,8 @@ import org.springframework.web.bind.MissingPathVariableException;
|
|||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.text.Convert;
|
||||
import com.mcwl.common.exception.DemoModeException;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.common.utils.html.EscapeUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
|
@ -29,6 +31,21 @@ public class GlobalExceptionHandler
|
|||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
|
||||
/**
|
||||
* 仿照业务异常——自定义异常抛出
|
||||
*/
|
||||
@ExceptionHandler(ErrorCodeException.class)
|
||||
public AjaxResult UserDefinedException(ErrorCodeException e){
|
||||
System.out.println("StringUtils.isNull(e.getCode()):"+StringUtils.isNull(e.getCode()));
|
||||
if (StringUtils.isNull(e.getCode()))
|
||||
{
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
return AjaxResult.error(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限校验异常
|
||||
*/
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
package com.mcwl.framework.web.service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.mcwl.common.constant.CacheConstants;
|
||||
import com.mcwl.common.constant.Constants;
|
||||
import com.mcwl.common.constant.RedisConstants;
|
||||
import com.mcwl.common.constant.UserConstants;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.domain.model.LoginUser;
|
||||
import com.mcwl.common.core.redis.RedisCache;
|
||||
import com.mcwl.common.enums.ResultCode;
|
||||
import com.mcwl.common.exception.ErrorCodeException;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.exception.user.BlackListException;
|
||||
import com.mcwl.common.exception.user.CaptchaException;
|
||||
import com.mcwl.common.exception.user.CaptchaExpireException;
|
||||
import com.mcwl.common.exception.user.UserNotExistsException;
|
||||
import com.mcwl.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.mcwl.common.exception.user.*;
|
||||
import com.mcwl.common.utils.DateUtils;
|
||||
import com.mcwl.common.utils.MessageUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
|
@ -26,8 +18,17 @@ import com.mcwl.common.utils.ip.IpUtils;
|
|||
import com.mcwl.framework.manager.AsyncManager;
|
||||
import com.mcwl.framework.manager.factory.AsyncFactory;
|
||||
import com.mcwl.framework.security.context.AuthenticationContextHolder;
|
||||
import com.mcwl.framework.security.sms.SmsCodeAuthenticationToken;
|
||||
import com.mcwl.system.service.ISysConfigService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
|
@ -37,12 +38,19 @@ import com.mcwl.system.service.ISysUserService;
|
|||
@Component
|
||||
public class SysLoginService
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private UserDetailsServiceImpl userDetailsService;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@Resource
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Resource
|
||||
private AuthenticationManager authenticationManagerPhone;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
|
@ -178,4 +186,81 @@ public class SysLoginService
|
|||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
userService.updateUserProfile(sysUser);
|
||||
}
|
||||
|
||||
public String phoneLogin(String phone, String code) {
|
||||
|
||||
//校验验证码
|
||||
validateCaptcha(phone, code);
|
||||
|
||||
//根据手机号查询数据
|
||||
SysUser sysUser = userService.selectUserByPhone(phone);
|
||||
if (sysUser == null){
|
||||
throw new UserNotExistsException();
|
||||
}
|
||||
|
||||
// 登录前置校验
|
||||
otherLoginPreCheck(sysUser.getUserName());
|
||||
|
||||
// 用户验证
|
||||
Authentication authentication;
|
||||
try {
|
||||
SmsCodeAuthenticationToken smsCodeAuthenticationToken = new SmsCodeAuthenticationToken(sysUser.getPhonenumber());
|
||||
System.out.println(smsCodeAuthenticationToken);
|
||||
AuthenticationContextHolder.setContext(smsCodeAuthenticationToken);
|
||||
authentication = authenticationManagerPhone.authenticate(smsCodeAuthenticationToken);
|
||||
}
|
||||
// SmsCodeAuthenticationToken [Principal=admin, Credentials=[PROTECTED], Authenticated=false, Details=null, Granted Authorities=[]]
|
||||
catch (Exception e) {
|
||||
if (e instanceof BadCredentialsException) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
throw new UserPasswordNotMatchException();
|
||||
} else {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, e.getMessage()));
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
AuthenticationContextHolder.clearContext();
|
||||
}
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
private void validateCaptcha(String phone, String code) {
|
||||
//校验验证码
|
||||
Object cacheObject = redisCache.getCacheObject(RedisConstants.CODE_PHONE + phone);
|
||||
System.out.println("验证码:"+cacheObject);
|
||||
if (cacheObject == null) {
|
||||
// 处理未找到验证码的情况
|
||||
throw new ErrorCodeException(ResultCode.FAIL,"验证码已过期或未发送");
|
||||
}
|
||||
|
||||
String c = (String) cacheObject;
|
||||
if (!c.equals(code)){
|
||||
//验证码错误
|
||||
throw new ErrorCodeException(ResultCode.FAIL,"验证码错误");
|
||||
}
|
||||
}
|
||||
|
||||
public void otherLoginPreCheck(String username) {
|
||||
// 用户名为空 错误
|
||||
if (StringUtils.isEmpty(username)) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
|
||||
throw new UserNotExistsException();
|
||||
}
|
||||
// 用户名不在指定范围内 错误
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
throw new UserPasswordNotMatchException();
|
||||
}
|
||||
// IP黑名单校验
|
||||
String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
|
||||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked")));
|
||||
throw new BlackListException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
package com.mcwl.framework.web.service;
|
||||
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.domain.model.LoginUser;
|
||||
import com.mcwl.common.enums.UserStatus;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.MessageUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -7,13 +15,6 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.domain.model.LoginUser;
|
||||
import com.mcwl.common.enums.UserStatus;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.MessageUtils;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
|
||||
/**
|
||||
* 用户验证处理
|
||||
|
@ -21,10 +22,12 @@ import com.mcwl.system.service.ISysUserService;
|
|||
* @author mcwl
|
||||
*/
|
||||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService
|
||||
{
|
||||
public class UserDetailsServiceImpl implements UserDetailsService, OtherUserDetailsService {
|
||||
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
||||
|
||||
private int num = 0;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
|
@ -35,32 +38,41 @@ public class UserDetailsServiceImpl implements UserDetailsService
|
|||
private SysPermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
|
||||
{
|
||||
SysUser user = userService.selectUserByUserName(username);
|
||||
if (StringUtils.isNull(user))
|
||||
{
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
SysUser user = null;
|
||||
if (num == 0 ){
|
||||
user = userService.selectUserByUserName(username);
|
||||
}else {
|
||||
user = userService.selectUserByPhone(username);
|
||||
}
|
||||
|
||||
if (StringUtils.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
||||
}
|
||||
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||
{
|
||||
} else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||
log.info("登录用户:{} 已被删除.", username);
|
||||
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
||||
}
|
||||
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||
{
|
||||
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||
}
|
||||
|
||||
passwordService.validate(user);
|
||||
// passwordService.validate(user);
|
||||
if (num == 0) {
|
||||
passwordService.validate(user);
|
||||
}
|
||||
num = 0;
|
||||
|
||||
return createLoginUser(user);
|
||||
}
|
||||
|
||||
public UserDetails createLoginUser(SysUser user)
|
||||
{
|
||||
public UserDetails createLoginUser(SysUser user) {
|
||||
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails otherLoadUser(String username, int num) throws UsernameNotFoundException {
|
||||
this.num = num;
|
||||
return loadUserByUsername(username);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.mcwl.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户表 数据层
|
||||
|
@ -124,4 +125,7 @@ public interface SysUserMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public SysUser checkEmailUnique(String email);
|
||||
|
||||
SysUser selectUserByPhone(@Param("phone") String phone);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.mcwl.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 业务层
|
||||
*
|
||||
*
|
||||
* @author mcwl
|
||||
*/
|
||||
public interface ISysUserService
|
||||
{
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -20,7 +21,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 根据条件分页查询已分配用户角色列表
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -28,7 +29,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 根据条件分页查询未分配用户角色列表
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
|
@ -36,7 +37,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
|
@ -44,7 +45,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 通过用户ID查询用户
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
|
@ -52,7 +53,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 根据用户ID查询用户所属角色组
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -60,7 +61,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 根据用户ID查询用户所属岗位组
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -68,7 +69,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 校验用户名称是否唯一
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -92,21 +93,21 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 校验用户是否允许操作
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
*/
|
||||
public void checkUserAllowed(SysUser user);
|
||||
|
||||
/**
|
||||
* 校验用户是否有数据权限
|
||||
*
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
public void checkUserDataScope(Long userId);
|
||||
|
||||
/**
|
||||
* 新增用户信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -114,7 +115,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 注册用户信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -122,7 +123,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -130,7 +131,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 用户授权角色
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param roleIds 角色组
|
||||
*/
|
||||
|
@ -138,7 +139,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -146,7 +147,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 修改用户基本信息
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -154,7 +155,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 修改用户头像
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param avatar 头像地址
|
||||
* @return 结果
|
||||
|
@ -163,7 +164,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
*
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -171,7 +172,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 重置用户密码
|
||||
*
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @return 结果
|
||||
|
@ -180,7 +181,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -188,7 +189,7 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 批量删除用户信息
|
||||
*
|
||||
*
|
||||
* @param userIds 需要删除的用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -196,11 +197,14 @@ public interface ISysUserService
|
|||
|
||||
/**
|
||||
* 导入用户数据
|
||||
*
|
||||
*
|
||||
* @param userList 用户数据列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operName 操作用户
|
||||
* @return 结果
|
||||
*/
|
||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||
|
||||
SysUser selectUserByPhone(String phone);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
package com.mcwl.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.Validator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import com.mcwl.common.annotation.DataScope;
|
||||
import com.mcwl.common.constant.UserConstants;
|
||||
import com.mcwl.common.core.domain.entity.SysRole;
|
||||
|
@ -22,14 +12,21 @@ import com.mcwl.common.utils.spring.SpringUtils;
|
|||
import com.mcwl.system.domain.SysPost;
|
||||
import com.mcwl.system.domain.SysUserPost;
|
||||
import com.mcwl.system.domain.SysUserRole;
|
||||
import com.mcwl.system.mapper.SysPostMapper;
|
||||
import com.mcwl.system.mapper.SysRoleMapper;
|
||||
import com.mcwl.system.mapper.SysUserMapper;
|
||||
import com.mcwl.system.mapper.SysUserPostMapper;
|
||||
import com.mcwl.system.mapper.SysUserRoleMapper;
|
||||
import com.mcwl.system.mapper.*;
|
||||
import com.mcwl.system.service.ISysConfigService;
|
||||
import com.mcwl.system.service.ISysDeptService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户 业务层处理
|
||||
|
@ -547,4 +544,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser selectUserByPhone(String phone) {
|
||||
|
||||
return userMapper.selectUserByPhone(phone);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<association property="dept" javaType="SysDept" resultMap="deptResult" />
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<resultMap id="deptResult" type="SysDept">
|
||||
<id property="deptId" column="dept_id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
|
@ -36,7 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="leader" column="leader" />
|
||||
<result property="status" column="dept_status" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<resultMap id="RoleResult" type="SysRole">
|
||||
<id property="roleId" column="role_id" />
|
||||
<result property="roleName" column="role_name" />
|
||||
|
@ -45,9 +45,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="dataScope" column="data_scope" />
|
||||
<result property="status" column="role_status" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<sql id="selectUserVo">
|
||||
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
|
||||
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
|
||||
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
|
||||
from sys_user u
|
||||
|
@ -55,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
left join sys_user_role ur on u.user_id = ur.user_id
|
||||
left join sys_role r on r.role_id = ur.role_id
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
|
@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
|
@ -101,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
|
||||
from sys_user u
|
||||
|
@ -119,29 +119,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_name = #{userName} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, user_name from sys_user where user_name = #{userName} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserByPhone" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.phonenumber = #{phone} and u.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into sys_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
|
@ -173,7 +178,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateUser" parameterType="SysUser">
|
||||
update sys_user
|
||||
<set>
|
||||
|
@ -194,28 +199,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</set>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateUserStatus" parameterType="SysUser">
|
||||
update sys_user set status = #{status} where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateUserAvatar" parameterType="SysUser">
|
||||
update sys_user set avatar = #{avatar} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
|
||||
<update id="resetUserPwd" parameterType="SysUser">
|
||||
update sys_user set password = #{password} where user_name = #{userName}
|
||||
</update>
|
||||
|
||||
|
||||
<delete id="deleteUserById" parameterType="Long">
|
||||
update sys_user set del_flag = '2' where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
|
||||
<delete id="deleteUserByIds" parameterType="Long">
|
||||
update sys_user set del_flag = '2' where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue