upms用户注册,异常处理功能编写
This commit is contained in:
@@ -104,7 +104,7 @@ var activeTableTab = "activeTableTab";
|
||||
<li>java.lang.Enum<<a href="../../../../../com/micro/fast/common/response/Const.ServerResponseCode.html" title="com.micro.fast.common.response中的枚举">Const.ServerResponseCode</a>></li>
|
||||
<li>
|
||||
<ul class="inheritance">
|
||||
<li>com.micro.fast.common.response.Const.ServerResponseCode</li>
|
||||
<li>com.micro.fast.common.response.BaseConst.ServerResponseCode</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<li>java.lang.Object</li>
|
||||
<li>
|
||||
<ul class="inheritance">
|
||||
<li>com.micro.fast.common.response.Const</li>
|
||||
<li>com.micro.fast.common.response.BaseConst</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<!-- Generated by javadoc (1.8.0_144) on Mon Oct 02 18:41:08 CST 2017 -->
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>类 com.micro.fast.common.response.Const.ServerResponseCode的使用</title>
|
||||
<title>类 com.micro.fast.common.response.BaseConst.ServerResponseCode的使用</title>
|
||||
<meta name="date" content="2017-10-02">
|
||||
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
|
||||
<script type="text/javascript" src="../../../../../../script.js"></script>
|
||||
@@ -13,7 +13,7 @@
|
||||
<script type="text/javascript"><!--
|
||||
try {
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="\u7C7B com.micro.fast.common.response.Const.ServerResponseCode\u7684\u4F7F\u7528";
|
||||
parent.document.title="\u7C7B com.micro.fast.common.response.BaseConst.ServerResponseCode\u7684\u4F7F\u7528";
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
@@ -71,7 +71,7 @@
|
||||
</a></div>
|
||||
<!-- ========= END OF TOP NAVBAR ========= -->
|
||||
<div class="header">
|
||||
<h2 title="类的使用 com.micro.fast.common.response.Const.ServerResponseCode" class="title">类的使用<br>com.micro.fast.common.response.Const.ServerResponseCode</h2>
|
||||
<h2 title="类的使用 com.micro.fast.common.response.BaseConst.ServerResponseCode" class="title">类的使用<br>com.micro.fast.common.response.BaseConst.ServerResponseCode</h2>
|
||||
</div>
|
||||
<div class="classUseContainer">
|
||||
<ul class="blockList">
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<script type="text/javascript"><!--
|
||||
try {
|
||||
if (location.href.indexOf('is-external=true') == -1) {
|
||||
parent.document.title="\u7C7B com.micro.fast.common.response.Const\u7684\u4F7F\u7528";
|
||||
parent.document.title="\u7C7B com.micro.fast.common.response.BaseConst\u7684\u4F7F\u7528";
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
@@ -71,7 +71,7 @@
|
||||
</a></div>
|
||||
<!-- ========= END OF TOP NAVBAR ========= -->
|
||||
<div class="header">
|
||||
<h2 title="类的使用 com.micro.fast.common.response.Const" class="title">类的使用<br>com.micro.fast.common.response.Const</h2>
|
||||
<h2 title="类的使用 com.micro.fast.common.response.BaseConst" class="title">类的使用<br>com.micro.fast.common.response.BaseConst</h2>
|
||||
</div>
|
||||
<div class="classUseContainer">没有com.micro.fast.common.response.Const的用法</div>
|
||||
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
||||
|
||||
@@ -121,7 +121,9 @@ public class BrowserSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
, SecurityConstants.GET_VALIDATE_CODE_URI
|
||||
, SecurityConstants.LOGIN_PAGE
|
||||
, DRUID
|
||||
, securityProperties.getBrowser().getHtml())
|
||||
, securityProperties.getBrowser().getHtml()
|
||||
//upms系统用户注册
|
||||
, "/upms/user")
|
||||
.permitAll()
|
||||
//任何请求
|
||||
.anyRequest()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.micro.fast.common.exception;
|
||||
|
||||
|
||||
/**
|
||||
* 系统级别的异常,比如数据哭插入失败
|
||||
* @author lsy
|
||||
*/
|
||||
public class SystemException extends RuntimeException {
|
||||
public SystemException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.micro.fast.common.exception;
|
||||
|
||||
/**
|
||||
* 用户异常类
|
||||
* @author lsy
|
||||
*/
|
||||
public class UserException extends RuntimeException{
|
||||
public UserException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.micro.fast.common.response;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
public class BaseConst {
|
||||
|
||||
public static final String DEFAULT_VALIDATE_CODE = "888888";
|
||||
/**
|
||||
* 服务器响应数据字典
|
||||
*/
|
||||
public enum ServerResponseCode {
|
||||
/**
|
||||
* 获取数据成功
|
||||
*/
|
||||
SUCCESS(0, "SUCCESS"),
|
||||
/**
|
||||
* 获取数据失败
|
||||
*/
|
||||
ERROR(1, "ERROR");
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
ServerResponseCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统响应码
|
||||
*/
|
||||
public enum SystemResponse {
|
||||
DATABASE_INSERT_FAILURE(00000, "系统错误,请稍后重试");
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
SystemResponse(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户操作响应码
|
||||
*/
|
||||
public enum UserResponse {
|
||||
USERNAME_IS_HAVE(10000, "用户名被占用"),
|
||||
EMAIL_IS_HAVE(10001, "邮箱被占用"),
|
||||
TWO_PASSWORD_NOT_SAME(10002,"两次密码不一致");
|
||||
public Integer code;
|
||||
private String msg;
|
||||
|
||||
UserResponse(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.micro.fast.common.response;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Const {
|
||||
/**
|
||||
* 服务器响应数据字典
|
||||
*/
|
||||
public enum ServerResponseCode{
|
||||
/**
|
||||
* 获取数据成功
|
||||
*/
|
||||
SUCCESS(0,"SUCCESS"),
|
||||
/**
|
||||
* 获取数据失败
|
||||
*/
|
||||
ERROR(1,"ERROR");
|
||||
private Integer code;
|
||||
private String msg;
|
||||
ServerResponseCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
* 统一服务响应类
|
||||
* 统一服务响应类,方法返回值
|
||||
*
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
@@ -13,109 +14,119 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)//序列化中不包含为空的字段
|
||||
public class ServerResponse<T> {
|
||||
private Integer code;//获取数据返回的提示数据字典码
|
||||
private String msg; //获取数据成功或者失败的时候提示的消息
|
||||
T data;
|
||||
/**
|
||||
* 获取数据返回的提示数据字典码
|
||||
*/
|
||||
private Integer code;
|
||||
/**
|
||||
* 获取数据成功或者失败的时候提示的消息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 返回的数据
|
||||
*/
|
||||
T data;
|
||||
|
||||
/**
|
||||
* 所有的构造方法均为私有,不允许外部直接调用构造方法
|
||||
*/
|
||||
public ServerResponse() {
|
||||
/**
|
||||
* 所有的构造方法均为私有,不允许外部直接调用构造方法
|
||||
*/
|
||||
public ServerResponse() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ServerResponse(Integer code) {
|
||||
this(code, null, null);
|
||||
}
|
||||
private ServerResponse(Integer code) {
|
||||
this(code, null, null);
|
||||
}
|
||||
|
||||
private ServerResponse(Integer code, String msg) {
|
||||
this(code, msg, null);
|
||||
}
|
||||
private ServerResponse(Integer code, String msg) {
|
||||
this(code, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为了避免T 为string的时候调用的是 上面的构造方法,需要对构造方法进行包装。构造方法设置为私有,不允许外部调用
|
||||
*
|
||||
* @param code 响应代码
|
||||
* @param data 相应数据
|
||||
*/
|
||||
private ServerResponse(Integer code, T data) {
|
||||
this(code, null, data);
|
||||
}
|
||||
/**
|
||||
* 为了避免T 为string的时候调用的是 上面的构造方法,需要对构造方法进行包装。构造方法设置为私有,不允许外部调用
|
||||
*
|
||||
* @param code 响应代码
|
||||
* @param data 相应数据
|
||||
*/
|
||||
private ServerResponse(Integer code, T data) {
|
||||
this(code, null, data);
|
||||
}
|
||||
|
||||
private ServerResponse(Integer code, String msg, T data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
private ServerResponse(Integer code, String msg, T data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回代码是小于等于0的时候表示请求数据失败,或者进行验证时失败
|
||||
* @return 是否成功
|
||||
*/
|
||||
@JsonIgnore //使其不再json序列化结果之中
|
||||
public boolean isSuccess() {
|
||||
return Const.ServerResponseCode.SUCCESS.getCode().intValue() == this.code;
|
||||
}
|
||||
/**
|
||||
* 返回代码是小于等于0的时候表示请求数据失败,或者进行验证时失败
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
@JsonIgnore //使其不再json序列化结果之中
|
||||
public boolean isSuccess() {
|
||||
return BaseConst.ServerResponseCode.SUCCESS.getCode().intValue() == this.code;
|
||||
}
|
||||
|
||||
//请求成功
|
||||
public static <T> ServerResponse<T> success() {
|
||||
//请求成功
|
||||
public static <T> ServerResponse<T> success() {
|
||||
|
||||
return new ServerResponse<T>(Const.ServerResponseCode.SUCCESS.getCode());
|
||||
}
|
||||
return new ServerResponse<T>(BaseConst.ServerResponseCode.SUCCESS.getCode());
|
||||
}
|
||||
|
||||
public static <T> ServerResponse<T> successMsg(String msg) {
|
||||
public static <T> ServerResponse<T> successMsg(String msg) {
|
||||
|
||||
return new ServerResponse<T>(
|
||||
Const.ServerResponseCode.SUCCESS.getCode(),
|
||||
msg);
|
||||
}
|
||||
return new ServerResponse<T>(
|
||||
BaseConst.ServerResponseCode.SUCCESS.getCode(),
|
||||
msg);
|
||||
}
|
||||
|
||||
public static <T> ServerResponse<T> successData(T data) {
|
||||
public static <T> ServerResponse<T> successData(T data) {
|
||||
|
||||
return new ServerResponse<T>(Const.ServerResponseCode.SUCCESS.getCode(),
|
||||
data);
|
||||
}
|
||||
return new ServerResponse<T>(BaseConst.ServerResponseCode.SUCCESS.getCode(),
|
||||
data);
|
||||
}
|
||||
|
||||
public static <T> ServerResponse<T> successMsgData(String msg, T data) {
|
||||
public static <T> ServerResponse<T> successMsgData(String msg, T data) {
|
||||
|
||||
return new ServerResponse<T>(Const.ServerResponseCode.SUCCESS.getCode(),
|
||||
msg, data);
|
||||
}
|
||||
return new ServerResponse<T>(BaseConst.ServerResponseCode.SUCCESS.getCode(),
|
||||
msg, data);
|
||||
}
|
||||
|
||||
//请求失败
|
||||
public static <T> ServerResponse<T> error() {
|
||||
return new ServerResponse<T>(Const.ServerResponseCode.ERROR.getCode());
|
||||
}
|
||||
//请求失败
|
||||
public static <T> ServerResponse<T> error() {
|
||||
return new ServerResponse<T>(BaseConst.ServerResponseCode.ERROR.getCode());
|
||||
}
|
||||
|
||||
public static <T> ServerResponse<T> errorMsg(String msg) {
|
||||
return new ServerResponse<T>(Const.ServerResponseCode.ERROR.getCode(), msg);
|
||||
}
|
||||
public static <T> ServerResponse<T> errorMsg(String msg) {
|
||||
return new ServerResponse<T>(BaseConst.ServerResponseCode.ERROR.getCode(), msg);
|
||||
}
|
||||
|
||||
public static <T> ServerResponse<T> errorCodeMsg(Integer code, String msg) {
|
||||
return new ServerResponse<T>(code, msg);
|
||||
}
|
||||
public static <T> ServerResponse<T> errorCodeMsg(Integer code, String msg) {
|
||||
return new ServerResponse<T>(code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.micro.fast.common.util;
|
||||
|
||||
import com.micro.fast.util.ExceptionUtil;
|
||||
|
||||
/**
|
||||
* 对于基础异常工具类进行封装
|
||||
* @author lsy
|
||||
*/
|
||||
public class ExceptionHandlerUtil {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.micro.fast.util;
|
||||
|
||||
/**
|
||||
* 对异常处理的工具类
|
||||
* @author lsy
|
||||
*/
|
||||
public class ExceptionUtil {
|
||||
/**
|
||||
* 分隔符
|
||||
*/
|
||||
public static final String split = "::::";
|
||||
|
||||
/**
|
||||
* 合并异常代码和描述
|
||||
* @param code
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static String contactCodeMsg(Integer code,String msg){
|
||||
return String.valueOf(code)+ExceptionUtil.split+msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拆分异常描述
|
||||
* @return
|
||||
*/
|
||||
public static String[] splitCodeMsg(String codeMsg){
|
||||
String[] split = codeMsg.split(ExceptionUtil.split);
|
||||
return split;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* 修改xml某一节点的值
|
||||
*/
|
||||
public class XmlUtil {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = {
|
||||
proxyTable: {},
|
||||
|
||||
// Various Dev Server settings
|
||||
host: 'localhost', // can be overwritten by process.env.HOST
|
||||
host: 'fthipw.natappfree.cc', // can be overwritten by process.env.HOST
|
||||
port: 80, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
|
||||
autoOpenBrowser: false,
|
||||
errorOverlay: true,
|
||||
|
||||
@@ -75,7 +75,8 @@
|
||||
},
|
||||
methods: {
|
||||
signUp () {
|
||||
this.$http.post('', this.$querystring.stringify(signUp))
|
||||
let that = this
|
||||
this.$http.post(that.$msConfig.reqUpms + '/upms/user', signUp)
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
}, error => {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.micro.fast.upms.controller;
|
||||
|
||||
import com.micro.fast.common.exception.UserException;
|
||||
import com.micro.fast.common.response.ServerResponse;
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
import com.micro.fast.upms.service.UpmsUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 权限管理系统用户管理
|
||||
*
|
||||
* @author lsy
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/upms/user")
|
||||
public class UpmsUserController {
|
||||
|
||||
/**
|
||||
* 用户服务接口
|
||||
*/
|
||||
@Autowired
|
||||
private UpmsUserService upmsUserService;
|
||||
|
||||
/**
|
||||
* 用户注册,使用Valid注解对upmsUser进行参数校验
|
||||
* BindingResult一定要紧跟校验的对象
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public ServerResponse<UpmsUser> register(@Valid UpmsUser upmsUser,BindingResult errors
|
||||
, @RequestParam(defaultValue = "") String repeatPassword) {
|
||||
//对参数的校验抛出异常
|
||||
if (errors.hasErrors()) {
|
||||
errors.getAllErrors().stream().forEach(objectError -> {
|
||||
FieldError fieldError = (FieldError) objectError;
|
||||
throw new UserException(fieldError.getDefaultMessage());
|
||||
});
|
||||
}
|
||||
ServerResponse<UpmsUser> register = upmsUserService.register(upmsUser, repeatPassword);
|
||||
return register;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.micro.fast.upms.controller.handler;
|
||||
|
||||
import com.micro.fast.common.exception.SystemException;
|
||||
import com.micro.fast.common.exception.UserException;
|
||||
import com.micro.fast.util.ExceptionUtil;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 异常处理类
|
||||
* @author lsy
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class ExceptionHandlerController {
|
||||
/**
|
||||
* 处理系统异常
|
||||
* @param se
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(SystemException.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public Map<String, String> handlerSystemException(SystemException se) {
|
||||
String[] strings = ExceptionUtil.splitCodeMsg(se.getMessage());
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put(strings[0],strings[1]);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理用户异常
|
||||
* @param se
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(UserException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Map<String, String> handlerUserException(UserException se) {
|
||||
String[] strings = ExceptionUtil.splitCodeMsg(se.getMessage());
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put(strings[0],strings[1]);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.micro.fast.upms.dao;
|
||||
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
import feign.Param;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
@@ -10,13 +11,36 @@ public interface UpmsUserMapper {
|
||||
|
||||
int insert(UpmsUser record);
|
||||
|
||||
UpmsUser selectByUsername(String username);
|
||||
|
||||
|
||||
int insertSelective(UpmsUser record);
|
||||
|
||||
UpmsUser selectByPrimaryKey(Integer id);
|
||||
|
||||
/**
|
||||
* 根据用户名查找用户
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
UpmsUser selectByUsername(@Param("username") String username);
|
||||
|
||||
/**
|
||||
* 检查用户名是否存在
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
int countUsername(String username);
|
||||
|
||||
/**
|
||||
* 检查邮箱是否被占用
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
int countEmail(String email);
|
||||
|
||||
int updateByPrimaryKeySelective(UpmsUser record);
|
||||
|
||||
int updateByPrimaryKey(UpmsUser record);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.micro.fast.upms.pojo;
|
||||
|
||||
import com.micro.fast.common.response.BaseConst;
|
||||
import com.micro.fast.util.ExceptionUtil;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UpmsUser implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
@NotBlank(message = BaseConst.DEFAULT_VALIDATE_CODE+ExceptionUtil.split+"请按提示输入用户名")
|
||||
private String username;
|
||||
|
||||
@NotBlank(message = BaseConst.DEFAULT_VALIDATE_CODE+ExceptionUtil.split+"请按提示输入密码")
|
||||
private String password;
|
||||
|
||||
private String salt;
|
||||
@@ -17,6 +23,7 @@ public class UpmsUser implements Serializable {
|
||||
|
||||
private String phone;
|
||||
|
||||
@NotBlank(message = BaseConst.DEFAULT_VALIDATE_CODE+ExceptionUtil.split+"请按照提示输入邮箱")
|
||||
private String email;
|
||||
|
||||
private Byte sex;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.micro.fast.upms.service;
|
||||
|
||||
import com.micro.fast.common.response.ServerResponse;
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
|
||||
/**
|
||||
* 权限管理系统用户服务接口
|
||||
* @author lsy
|
||||
*/
|
||||
public interface UpmsUserService {
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
* @param upmsUser 用户对象
|
||||
* @param repeatPassword 确认密码
|
||||
* @return
|
||||
*/
|
||||
ServerResponse<UpmsUser> register(UpmsUser upmsUser,String repeatPassword);
|
||||
|
||||
/**
|
||||
* 检查用户名是否被占用
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
ServerResponse checkUsername(String username);
|
||||
|
||||
/**
|
||||
* 检查邮箱是否被占用
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
ServerResponse checkEmail(String email);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.micro.fast.upms.service.impl;
|
||||
|
||||
import com.micro.fast.security.browser.service.UserService;
|
||||
import com.micro.fast.upms.dao.UpmsUserMapper;
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 后台权限管理系统用户操作接口实现类
|
||||
* @author lsy
|
||||
*/
|
||||
@Service("userServiceImpl")
|
||||
public class UpmsUserAuthenticationServiceImpl implements UserService{
|
||||
|
||||
@Autowired
|
||||
private UpmsUserMapper upmsUserMapper;
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
UpmsUser upmsUser = upmsUserMapper.selectByUsername(username);
|
||||
//将根据用户名查询出来的用户信息填入springSecurity的User对象中,默认是admin权限 todo 需要进行完善
|
||||
User user = new User(username,upmsUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,39 +1,82 @@
|
||||
package com.micro.fast.upms.service.impl;
|
||||
|
||||
import com.micro.fast.security.browser.service.UserService;
|
||||
import com.micro.fast.common.exception.SystemException;
|
||||
import com.micro.fast.common.response.ServerResponse;
|
||||
import com.micro.fast.upms.dao.UpmsUserMapper;
|
||||
import com.micro.fast.common.exception.UserException;
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
import com.micro.fast.upms.service.UpmsUserService;
|
||||
import com.micro.fast.util.ExceptionUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.micro.fast.common.response.BaseConst.*;
|
||||
|
||||
/**
|
||||
* 后台权限管理系统用户操作接口实现类
|
||||
* @author lsy
|
||||
*/
|
||||
@Service("userServiceImpl")
|
||||
public class UpmsUserServiceImpl implements UserService{
|
||||
@Service(value = "upmsUserServiceImpl")
|
||||
public class UpmsUserServiceImpl implements UpmsUserService {
|
||||
|
||||
@Autowired
|
||||
private UpmsUserMapper upmsUserMapper;
|
||||
@Autowired
|
||||
private UpmsUserMapper upmsUserMapper;
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
UpmsUser upmsUser = upmsUserMapper.selectByUsername(username);
|
||||
//将根据用户名查询出来的用户信息填入springSecurity的User对象中,默认是admin权限 todo 需要进行完善
|
||||
User user = new User(username,upmsUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
|
||||
return user;
|
||||
@Override
|
||||
public ServerResponse<UpmsUser> register(UpmsUser upmsUser, String repeatPassword){
|
||||
ServerResponse checkUsername = checkUsername(upmsUser.getUsername());
|
||||
ServerResponse checkEmail = checkEmail(upmsUser.getEmail());
|
||||
//校验两次输入密码是否一致
|
||||
if (upmsUser.getPassword().equals(repeatPassword)){
|
||||
throw new UserException(ExceptionUtil.contactCodeMsg(
|
||||
UserResponse.TWO_PASSWORD_NOT_SAME.getCode(),
|
||||
UserResponse.TWO_PASSWORD_NOT_SAME.getMsg()
|
||||
));
|
||||
}
|
||||
|
||||
//todo 添加用户
|
||||
public int addUser(String username,String password){
|
||||
UpmsUser upmsUser = new UpmsUser();
|
||||
upmsUser.setUsername(username);
|
||||
upmsUser.setPassword(password);
|
||||
int insert = upmsUserMapper.insert(upmsUser);
|
||||
return insert;
|
||||
//校验用户名,邮箱是否存在
|
||||
boolean success = checkUsername.isSuccess();
|
||||
boolean success1 = checkEmail.isSuccess();
|
||||
if (!success){
|
||||
throw new UserException(ExceptionUtil.contactCodeMsg(
|
||||
UserResponse.USERNAME_IS_HAVE.getCode()
|
||||
,UserResponse.USERNAME_IS_HAVE.getMsg()));
|
||||
}
|
||||
if (!success1){
|
||||
throw new UserException(ExceptionUtil.contactCodeMsg(
|
||||
UserResponse.EMAIL_IS_HAVE.getCode()
|
||||
,UserResponse.EMAIL_IS_HAVE.getMsg()));
|
||||
}
|
||||
upmsUser.setCtime(Long.valueOf(System.currentTimeMillis()));
|
||||
int i = upmsUserMapper.insertSelective(upmsUser);
|
||||
//是否插入成功
|
||||
if (i<1){
|
||||
throw new SystemException(ExceptionUtil.contactCodeMsg(
|
||||
SystemResponse.DATABASE_INSERT_FAILURE.getCode()
|
||||
,SystemResponse.DATABASE_INSERT_FAILURE.getMsg()));
|
||||
}
|
||||
return ServerResponse.successData(upmsUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse checkUsername(String username) {
|
||||
int i = upmsUserMapper.countUsername(username);
|
||||
if (i>0){
|
||||
//用户名被占用
|
||||
return ServerResponse.error();
|
||||
}else{
|
||||
//用户名没被占用
|
||||
return ServerResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse checkEmail(String email) {
|
||||
int i = upmsUserMapper.countEmail(email);
|
||||
if (i>0){
|
||||
//邮箱已被占用
|
||||
return ServerResponse.error();
|
||||
}else{
|
||||
//邮箱没被占用
|
||||
return ServerResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
FROM upms_user
|
||||
WHERE username = #{username}
|
||||
</select>
|
||||
<select id="countUsername" resultType="java.lang.Integer">
|
||||
SELECT COUNT(username) FROM upms_user WHERE username = #{username}
|
||||
</select>
|
||||
<select id="countEmail" resultType="java.lang.Integer">
|
||||
SELECT COUNT(email) FROM upms_user WHERE email = #{email}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
delete from upms_user
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.micro.fast.upms.service.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class UpmsUserServiceImplTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void checkUsername() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkEmail() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user