Compare commits
No commits in common. "a0c6c39c03d897fd8d456bcd770a4387a4576f1e" and "8f80a6ea4f09cbd70a04134eccf751b1d48b1f23" have entirely different histories.
a0c6c39c03
...
8f80a6ea4f
|
@ -1,5 +1,18 @@
|
||||||
package com.mcwl.web.controller.system;
|
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.annotation.Log;
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.controller.BaseController;
|
import com.mcwl.common.core.controller.BaseController;
|
||||||
|
@ -8,17 +21,10 @@ import com.mcwl.common.core.domain.entity.SysDept;
|
||||||
import com.mcwl.common.enums.BusinessType;
|
import com.mcwl.common.enums.BusinessType;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.system.service.ISysDeptService;
|
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
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
|
|
@ -1,38 +1,29 @@
|
||||||
package com.mcwl.web.controller.system;
|
package com.mcwl.web.controller.system;
|
||||||
|
|
||||||
import com.mcwl.common.annotation.Anonymous;
|
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.constant.Constants;
|
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.AjaxResult;
|
||||||
import com.mcwl.common.core.domain.entity.SysMenu;
|
import com.mcwl.common.core.domain.entity.SysMenu;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
import com.mcwl.common.core.domain.model.LoginBody;
|
import com.mcwl.common.core.domain.model.LoginBody;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
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.SecurityUtils;
|
||||||
import com.mcwl.common.utils.uuid.TelSmsUtils;
|
|
||||||
import com.mcwl.framework.web.service.SysLoginService;
|
import com.mcwl.framework.web.service.SysLoginService;
|
||||||
import com.mcwl.framework.web.service.SysPermissionService;
|
import com.mcwl.framework.web.service.SysPermissionService;
|
||||||
import com.mcwl.framework.web.service.TokenService;
|
import com.mcwl.framework.web.service.TokenService;
|
||||||
import com.mcwl.system.service.ISysMenuService;
|
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
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@RestController
|
@RestController
|
||||||
public class SysLoginController
|
public class SysLoginController
|
||||||
{
|
{
|
||||||
|
@ -48,31 +39,6 @@ public class SysLoginController
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录方法
|
* 登录方法
|
||||||
*
|
*
|
||||||
|
@ -90,20 +56,6 @@ public class SysLoginController
|
||||||
return ajax;
|
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,5 +1,21 @@
|
||||||
package com.mcwl.web.controller.system;
|
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.annotation.Log;
|
||||||
import com.mcwl.common.core.controller.BaseController;
|
import com.mcwl.common.core.controller.BaseController;
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
@ -15,16 +31,6 @@ import com.mcwl.system.service.ISysDeptService;
|
||||||
import com.mcwl.system.service.ISysPostService;
|
import com.mcwl.system.service.ISysPostService;
|
||||||
import com.mcwl.system.service.ISysRoleService;
|
import com.mcwl.system.service.ISysRoleService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
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,13 +286,6 @@
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 阿里大鱼 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.aliyun</groupId>
|
|
||||||
<artifactId>dysmsapi20170525</artifactId>
|
|
||||||
<version>2.0.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.mcwl.common.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* redis存储前缀常量
|
|
||||||
*
|
|
||||||
* @author DaiZibo
|
|
||||||
* @date 2024/12/28
|
|
||||||
* @apiNote
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class RedisConstants {
|
|
||||||
|
|
||||||
public static final String CODE_PHONE = "code_phone:";
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
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,11 +1,5 @@
|
||||||
package com.mcwl.framework.config;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -22,6 +16,10 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
||||||
import org.springframework.web.filter.CorsFilter;
|
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配置
|
* spring security配置
|
||||||
|
@ -38,13 +36,6 @@ public class SecurityConfig
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDetailsService userDetailsService;
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义用户(手机号验证码)认证逻辑
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private OtherUserDetailsService userDetailsServiceByPhone;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认证失败处理类
|
* 认证失败处理类
|
||||||
*/
|
*/
|
||||||
|
@ -87,15 +78,6 @@ public class SecurityConfig
|
||||||
return new ProviderManager(daoAuthenticationProvider);
|
return new ProviderManager(daoAuthenticationProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public AuthenticationManager authenticationManagerPhone() {
|
|
||||||
SmsCodeByEmailAuthenticationProvider daoAuthenticationProvider = new SmsCodeByEmailAuthenticationProvider();
|
|
||||||
daoAuthenticationProvider.setUserDetailsService(userDetailsServiceByPhone);
|
|
||||||
return new ProviderManager(daoAuthenticationProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* anyRequest | 匹配所有请求路径
|
* anyRequest | 匹配所有请求路径
|
||||||
* access | SpringEl表达式结果为true时可以访问
|
* access | SpringEl表达式结果为true时可以访问
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
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,13 +1,6 @@
|
||||||
package com.mcwl.framework.web.exception;
|
package com.mcwl.framework.web.exception;
|
||||||
|
|
||||||
import com.mcwl.common.constant.HttpStatus;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
@ -18,8 +11,13 @@ import org.springframework.web.bind.MissingPathVariableException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
|
import com.mcwl.common.constant.HttpStatus;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器
|
* 全局异常处理器
|
||||||
|
@ -31,21 +29,6 @@ public class GlobalExceptionHandler
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
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,16 +1,24 @@
|
||||||
package com.mcwl.framework.web.service;
|
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.CacheConstants;
|
||||||
import com.mcwl.common.constant.Constants;
|
import com.mcwl.common.constant.Constants;
|
||||||
import com.mcwl.common.constant.RedisConstants;
|
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
import com.mcwl.common.core.redis.RedisCache;
|
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.ServiceException;
|
||||||
import com.mcwl.common.exception.user.*;
|
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.utils.DateUtils;
|
import com.mcwl.common.utils.DateUtils;
|
||||||
import com.mcwl.common.utils.MessageUtils;
|
import com.mcwl.common.utils.MessageUtils;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
@ -18,17 +26,8 @@ import com.mcwl.common.utils.ip.IpUtils;
|
||||||
import com.mcwl.framework.manager.AsyncManager;
|
import com.mcwl.framework.manager.AsyncManager;
|
||||||
import com.mcwl.framework.manager.factory.AsyncFactory;
|
import com.mcwl.framework.manager.factory.AsyncFactory;
|
||||||
import com.mcwl.framework.security.context.AuthenticationContextHolder;
|
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.ISysConfigService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
|
@ -38,19 +37,12 @@ import javax.annotation.Resource;
|
||||||
@Component
|
@Component
|
||||||
public class SysLoginService
|
public class SysLoginService
|
||||||
{
|
{
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserDetailsServiceImpl userDetailsService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private AuthenticationManager authenticationManagerPhone;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@ -186,81 +178,4 @@ public class SysLoginService
|
||||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||||
userService.updateUserProfile(sysUser);
|
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,13 +1,5 @@
|
||||||
package com.mcwl.framework.web.service;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -15,6 +7,13 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户验证处理
|
* 用户验证处理
|
||||||
|
@ -22,12 +21,10 @@ import org.springframework.stereotype.Service;
|
||||||
* @author mcwl
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserDetailsServiceImpl implements UserDetailsService, OtherUserDetailsService {
|
public class UserDetailsServiceImpl implements UserDetailsService
|
||||||
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
||||||
|
|
||||||
private int num = 0;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@ -38,41 +35,32 @@ public class UserDetailsServiceImpl implements UserDetailsService, OtherUserDeta
|
||||||
private SysPermissionService permissionService;
|
private SysPermissionService permissionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
|
||||||
SysUser user = null;
|
{
|
||||||
if (num == 0 ){
|
SysUser user = userService.selectUserByUserName(username);
|
||||||
user = userService.selectUserByUserName(username);
|
if (StringUtils.isNull(user))
|
||||||
}else {
|
{
|
||||||
user = userService.selectUserByPhone(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNull(user)) {
|
|
||||||
log.info("登录用户:{} 不存在.", username);
|
log.info("登录用户:{} 不存在.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
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);
|
log.info("登录用户:{} 已被删除.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
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);
|
log.info("登录用户:{} 已被停用.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// passwordService.validate(user);
|
passwordService.validate(user);
|
||||||
if (num == 0) {
|
|
||||||
passwordService.validate(user);
|
|
||||||
}
|
|
||||||
num = 0;
|
|
||||||
|
|
||||||
return createLoginUser(user);
|
return createLoginUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDetails createLoginUser(SysUser user) {
|
public UserDetails createLoginUser(SysUser user)
|
||||||
|
{
|
||||||
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(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,9 +1,8 @@
|
||||||
package com.mcwl.system.mapper;
|
package com.mcwl.system.mapper;
|
||||||
|
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户表 数据层
|
* 用户表 数据层
|
||||||
|
@ -125,7 +124,4 @@ public interface SysUserMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public SysUser checkEmailUnique(String email);
|
public SysUser checkEmailUnique(String email);
|
||||||
|
|
||||||
SysUser selectUserByPhone(@Param("phone") String phone);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package com.mcwl.system.service;
|
package com.mcwl.system.service;
|
||||||
|
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 业务层
|
* 用户 业务层
|
||||||
*
|
*
|
||||||
* @author mcwl
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
public interface ISysUserService
|
public interface ISysUserService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询用户列表
|
* 根据条件分页查询用户列表
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +20,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询已分配用户角色列表
|
* 根据条件分页查询已分配用户角色列表
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +28,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询未分配用户角色列表
|
* 根据条件分页查询未分配用户角色列表
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +36,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户
|
* 通过用户名查询用户
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
* @return 用户对象信息
|
* @return 用户对象信息
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +44,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户
|
* 通过用户ID查询用户
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 用户对象信息
|
* @return 用户对象信息
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +52,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询用户所属角色组
|
* 根据用户ID查询用户所属角色组
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +60,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询用户所属岗位组
|
* 根据用户ID查询用户所属岗位组
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +68,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验用户名称是否唯一
|
* 校验用户名称是否唯一
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -93,21 +92,21 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验用户是否允许操作
|
* 校验用户是否允许操作
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
*/
|
*/
|
||||||
public void checkUserAllowed(SysUser user);
|
public void checkUserAllowed(SysUser user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验用户是否有数据权限
|
* 校验用户是否有数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
*/
|
*/
|
||||||
public void checkUserDataScope(Long userId);
|
public void checkUserDataScope(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增用户信息
|
* 新增用户信息
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -115,7 +114,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -123,7 +122,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户信息
|
* 修改用户信息
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -131,7 +130,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户授权角色
|
* 用户授权角色
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param roleIds 角色组
|
* @param roleIds 角色组
|
||||||
*/
|
*/
|
||||||
|
@ -139,7 +138,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户状态
|
* 修改用户状态
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +146,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户基本信息
|
* 修改用户基本信息
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -155,7 +154,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户头像
|
* 修改用户头像
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
* @param avatar 头像地址
|
* @param avatar 头像地址
|
||||||
* @return 结果
|
* @return 结果
|
||||||
|
@ -164,7 +163,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置用户密码
|
* 重置用户密码
|
||||||
*
|
*
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -172,7 +171,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置用户密码
|
* 重置用户密码
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
* @param password 密码
|
* @param password 密码
|
||||||
* @return 结果
|
* @return 结果
|
||||||
|
@ -181,7 +180,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID删除用户
|
* 通过用户ID删除用户
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -189,7 +188,7 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除用户信息
|
* 批量删除用户信息
|
||||||
*
|
*
|
||||||
* @param userIds 需要删除的用户ID
|
* @param userIds 需要删除的用户ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -197,14 +196,11 @@ public interface ISysUserService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入用户数据
|
* 导入用户数据
|
||||||
*
|
*
|
||||||
* @param userList 用户数据列表
|
* @param userList 用户数据列表
|
||||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||||
* @param operName 操作用户
|
* @param operName 操作用户
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||||
|
|
||||||
SysUser selectUserByPhone(String phone);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package com.mcwl.system.service.impl;
|
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.annotation.DataScope;
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.domain.entity.SysRole;
|
import com.mcwl.common.core.domain.entity.SysRole;
|
||||||
|
@ -12,21 +22,14 @@ import com.mcwl.common.utils.spring.SpringUtils;
|
||||||
import com.mcwl.system.domain.SysPost;
|
import com.mcwl.system.domain.SysPost;
|
||||||
import com.mcwl.system.domain.SysUserPost;
|
import com.mcwl.system.domain.SysUserPost;
|
||||||
import com.mcwl.system.domain.SysUserRole;
|
import com.mcwl.system.domain.SysUserRole;
|
||||||
import com.mcwl.system.mapper.*;
|
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.service.ISysConfigService;
|
import com.mcwl.system.service.ISysConfigService;
|
||||||
import com.mcwl.system.service.ISysDeptService;
|
import com.mcwl.system.service.ISysDeptService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 业务层处理
|
* 用户 业务层处理
|
||||||
|
@ -544,10 +547,4 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
}
|
}
|
||||||
return successMsg.toString();
|
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" />
|
<association property="dept" javaType="SysDept" resultMap="deptResult" />
|
||||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
|
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap id="deptResult" type="SysDept">
|
<resultMap id="deptResult" type="SysDept">
|
||||||
<id property="deptId" column="dept_id" />
|
<id property="deptId" column="dept_id" />
|
||||||
<result property="parentId" column="parent_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="leader" column="leader" />
|
||||||
<result property="status" column="dept_status" />
|
<result property="status" column="dept_status" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap id="RoleResult" type="SysRole">
|
<resultMap id="RoleResult" type="SysRole">
|
||||||
<id property="roleId" column="role_id" />
|
<id property="roleId" column="role_id" />
|
||||||
<result property="roleName" column="role_name" />
|
<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="dataScope" column="data_scope" />
|
||||||
<result property="status" column="role_status" />
|
<result property="status" column="role_status" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectUserVo">
|
<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,
|
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
|
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
|
||||||
from sys_user u
|
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_user_role ur on u.user_id = ur.user_id
|
||||||
left join sys_role r on r.role_id = ur.role_id
|
left join sys_role r on r.role_id = ur.role_id
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
<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
|
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
|
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}
|
${params.dataScope}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
<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
|
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
|
from sys_user u
|
||||||
|
@ -101,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<!-- 数据范围过滤 -->
|
<!-- 数据范围过滤 -->
|
||||||
${params.dataScope}
|
${params.dataScope}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
<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
|
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
|
from sys_user u
|
||||||
|
@ -119,34 +119,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<!-- 数据范围过滤 -->
|
<!-- 数据范围过滤 -->
|
||||||
${params.dataScope}
|
${params.dataScope}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||||
<include refid="selectUserVo"/>
|
<include refid="selectUserVo"/>
|
||||||
where u.user_name = #{userName} and u.del_flag = '0'
|
where u.user_name = #{userName} and u.del_flag = '0'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||||
<include refid="selectUserVo"/>
|
<include refid="selectUserVo"/>
|
||||||
where u.user_id = #{userId}
|
where u.user_id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
|
<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 user_id, user_name from sys_user where user_name = #{userName} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
|
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
|
||||||
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
|
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
||||||
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
||||||
</select>
|
</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 id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
insert into sys_user(
|
insert into sys_user(
|
||||||
<if test="userId != null and userId != 0">user_id,</if>
|
<if test="userId != null and userId != 0">user_id,</if>
|
||||||
|
@ -178,7 +173,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateUser" parameterType="SysUser">
|
<update id="updateUser" parameterType="SysUser">
|
||||||
update sys_user
|
update sys_user
|
||||||
<set>
|
<set>
|
||||||
|
@ -199,28 +194,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</set>
|
</set>
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateUserStatus" parameterType="SysUser">
|
<update id="updateUserStatus" parameterType="SysUser">
|
||||||
update sys_user set status = #{status} where user_id = #{userId}
|
update sys_user set status = #{status} where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateUserAvatar" parameterType="SysUser">
|
<update id="updateUserAvatar" parameterType="SysUser">
|
||||||
update sys_user set avatar = #{avatar} where user_name = #{userName}
|
update sys_user set avatar = #{avatar} where user_name = #{userName}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="resetUserPwd" parameterType="SysUser">
|
<update id="resetUserPwd" parameterType="SysUser">
|
||||||
update sys_user set password = #{password} where user_name = #{userName}
|
update sys_user set password = #{password} where user_name = #{userName}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteUserById" parameterType="Long">
|
<delete id="deleteUserById" parameterType="Long">
|
||||||
update sys_user set del_flag = '2' where user_id = #{userId}
|
update sys_user set del_flag = '2' where user_id = #{userId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="deleteUserByIds" parameterType="Long">
|
<delete id="deleteUserByIds" parameterType="Long">
|
||||||
update sys_user set del_flag = '2' where user_id in
|
update sys_user set del_flag = '2' where user_id in
|
||||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||||
#{userId}
|
#{userId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue