merge
This commit is contained in:
+23
-56
@@ -3,13 +3,15 @@ package com.xwbing.controller;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.entity.SysUser;
|
||||
import com.xwbing.service.UserService;
|
||||
import com.xwbing.service.SysUserLoginInOutService;
|
||||
import com.xwbing.service.SysUserService;
|
||||
import com.xwbing.util.JSONObjResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,112 +23,77 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/")
|
||||
public class UserControl {
|
||||
public class SysUserControl {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private SysUserService sysUserService;
|
||||
@Resource
|
||||
private SysUserLoginInOutService loginInOutService;
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("添加用户")
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody @Valid SysUser sysUser) {
|
||||
RestMessage result = userService.save(sysUser);
|
||||
RestMessage result = sysUserService.save(sysUser);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("删除用户")
|
||||
@GetMapping("removeById")
|
||||
public JSONObject removeById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = userService.removeById(id);
|
||||
RestMessage result = sysUserService.removeById(id);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("修改用户信息")
|
||||
@PostMapping("update")
|
||||
public JSONObject update(@RequestBody @Valid SysUser sysUser) {
|
||||
if (StringUtils.isEmpty(sysUser.getId())) {
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = userService.update(sysUser);
|
||||
RestMessage result = sysUserService.update(sysUser);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("获取用户详情")
|
||||
@GetMapping("findById")
|
||||
public JSONObject findById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
SysUser sysUser = userService.findOne(id);
|
||||
SysUser sysUser = sysUserService.findOne(id);
|
||||
if (sysUser == null) {
|
||||
return JSONObjResult.toJSONObj("未查到该对象");
|
||||
}
|
||||
return JSONObjResult.toJSONObj(sysUser, true, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询所有用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("列表查询所有用户")
|
||||
@GetMapping("findList")
|
||||
public JSONObject findList() {
|
||||
List<SysUser> list = userService.listAll();
|
||||
List<SysUser> list = sysUserService.listAll();
|
||||
return JSONObjResult.toJSONObj(list, true, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param userName
|
||||
* @param passWord
|
||||
* @param checkCode
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("登录")
|
||||
@GetMapping("login")
|
||||
public JSONObject login(@RequestParam String userName, @RequestParam String passWord, @RequestParam String checkCode) {
|
||||
public JSONObject login(HttpServletRequest request, @RequestParam String userName, @RequestParam String passWord, @RequestParam String checkCode) {
|
||||
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(passWord))
|
||||
return JSONObjResult.toJSONObj("用户名或密码不能为空");
|
||||
if (StringUtils.isEmpty(checkCode))
|
||||
return JSONObjResult.toJSONObj("请输入验证码");
|
||||
RestMessage login = userService.login(userName, passWord, checkCode);
|
||||
RestMessage login = sysUserService.login(request, userName, passWord, checkCode);
|
||||
return JSONObjResult.toJSONObj(login);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param newPassWord
|
||||
* @param oldPassWord
|
||||
* @return
|
||||
*/
|
||||
@LogInfo("登出")
|
||||
@GetMapping("logout")
|
||||
public JSONObject logout(HttpServletRequest request) {
|
||||
RestMessage logout = sysUserService.logout(request);
|
||||
return JSONObjResult.toJSONObj(logout);
|
||||
}
|
||||
|
||||
@LogInfo("修改密码")
|
||||
@GetMapping("updatePassWord")
|
||||
public JSONObject updatePassWord(@RequestParam String newPassWord, @RequestParam String oldPassWord, @RequestParam String id) {
|
||||
@@ -134,7 +101,7 @@ public class UserControl {
|
||||
return JSONObjResult.toJSONObj("原密码或新密码不能为空");
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
RestMessage restMessage = userService.updatePassWord(newPassWord, oldPassWord, id);
|
||||
RestMessage restMessage = sysUserService.updatePassWord(newPassWord, oldPassWord, id);
|
||||
return JSONObjResult.toJSONObj(restMessage);
|
||||
}
|
||||
|
||||
@@ -143,7 +110,7 @@ public class UserControl {
|
||||
public JSONObject resetPassWord(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
RestMessage restMessage = userService.resetPassWord(id);
|
||||
RestMessage restMessage = sysUserService.resetPassWord(id);
|
||||
return JSONObjResult.toJSONObj(restMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.xwbing.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.entity.SysUserLoginInOut;
|
||||
import com.xwbing.service.SysUserLoginInOutService;
|
||||
import com.xwbing.util.JSONObjResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/11/7 11:16
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/inout/")
|
||||
public class SysUserLoginInOutControl {
|
||||
@Resource
|
||||
private SysUserLoginInOutService inOutService;
|
||||
|
||||
@LogInfo("获取登录或登出信息")
|
||||
@GetMapping("listByType")
|
||||
public JSONObject listByType(@RequestParam int inout) {
|
||||
List<SysUserLoginInOut> sysUserLoginInOuts = inOutService.listByType(inout);
|
||||
return JSONObjResult.toJSONObj(sysUserLoginInOuts, true, "获取列表成功");
|
||||
}
|
||||
}
|
||||
@@ -102,8 +102,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseBody
|
||||
public JSONObject handlerException(HttpServletRequest request,
|
||||
Exception ex) {
|
||||
public JSONObject handlerException(HttpServletRequest request, Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return JSONObjResult.toJSONObj("系统异常,请联系管理员");
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.xwbing.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xwbing.configuration.DispatcherServletConfig;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -39,10 +42,14 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
|
||||
// return false;
|
||||
// }
|
||||
if (CommonDataUtil.getToken(CommonConstant.CURRENT_USER) != null) {
|
||||
// TODO: 2017/10/3
|
||||
return true;
|
||||
} else {
|
||||
// TODO: 2017/10/3
|
||||
logger.info("用户未登录");
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
RestMessage restMessage = new RestMessage();
|
||||
restMessage.setMessage("请登录");
|
||||
outputStream.write(JSON.toJSONString(restMessage).getBytes("utf-8"));
|
||||
outputStream.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user