|
@@ -1,163 +1,173 @@
|
|
|
-//package com.gis.web.controller;
|
|
|
-//
|
|
|
-//
|
|
|
-//import com.gis.common.util.PasswordUtils;
|
|
|
-//import com.gis.common.util.Result;
|
|
|
-//import com.gis.domain.po.SysUserEntity;
|
|
|
-//import com.gis.domain.dto.PageDto;
|
|
|
-//import com.gis.domain.dto.PasswordRequest;
|
|
|
-//import com.gis.domain.dto.UserDto;
|
|
|
-//import com.gis.service.SysUserService;
|
|
|
-//import com.github.pagehelper.PageInfo;
|
|
|
-//import io.swagger.annotations.Api;
|
|
|
-//import io.swagger.annotations.ApiOperation;
|
|
|
-//import lombok.extern.log4j.Log4j2;
|
|
|
-//import org.apache.shiro.authz.annotation.Logical;
|
|
|
-//import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
-//import org.springframework.beans.BeanUtils;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-//import org.springframework.transaction.annotation.Transactional;
|
|
|
-//import org.springframework.web.bind.annotation.*;
|
|
|
-//import springfox.documentation.annotations.ApiIgnore;
|
|
|
-//
|
|
|
-//import javax.validation.Valid;
|
|
|
-//import java.util.Date;
|
|
|
-//
|
|
|
-//
|
|
|
-///**
|
|
|
-// * Created by owen on 2020/2/18 0018 12:17
|
|
|
-// */
|
|
|
-//@ApiIgnore
|
|
|
-//@Log4j2
|
|
|
-//@Api(tags = "s用户管理")
|
|
|
-//@RestController
|
|
|
-//@RequestMapping("manage/user")
|
|
|
-//@Transactional
|
|
|
-//public class SysUserController extends BaseController {
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// public SysUserService userService;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// public RedisTemplate<Object, Object> redisTemplate;
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
-// @ApiOperation("用户列表")
|
|
|
-// @PostMapping("list")
|
|
|
-// public Result<SysUserEntity> list(@RequestBody PageDto param) {
|
|
|
-// startPage(param);
|
|
|
-// PageInfo<SysUserEntity> page = new PageInfo<>(userService.findAll());
|
|
|
-// return Result.success(page);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
-// @ApiOperation("新增/修改用户信息")
|
|
|
-// @PostMapping("save")
|
|
|
-// public Result save(@Valid @RequestBody UserDto param) {
|
|
|
-//
|
|
|
-// SysUserEntity entity = null;
|
|
|
-// if (param.getId() == null) {
|
|
|
-// entity = userService.findByUserName(param.getUserName());
|
|
|
-// if (entity != null) {
|
|
|
-// return Result.failure("用户名已存在");
|
|
|
-// }
|
|
|
-// entity = new SysUserEntity();
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
-// userService.save(entity);
|
|
|
-// } else {
|
|
|
-// entity = userService.findById(param.getId());
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("用户不存在: {}", param.getId());
|
|
|
-// return Result.failure("用户不存在");
|
|
|
-// }
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// entity.setUpdateTime(new Date());
|
|
|
-// userService.update(entity);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// @ApiOperation("查询用户信息")
|
|
|
-// @GetMapping("detail/{id}")
|
|
|
-// public Result<SysUserEntity> detail(@PathVariable Long id) {
|
|
|
-// SysUserEntity user = userService.findById(id);
|
|
|
-//
|
|
|
-// if (user == null) {
|
|
|
-// log.error("用户不存在: {}", id);
|
|
|
-// return Result.failure("用户不存在");
|
|
|
-// }
|
|
|
-// return Result.success(user);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("修改密码")
|
|
|
-// @PostMapping("updatePwd")
|
|
|
-// public Result updatePwd(@Valid @RequestBody PasswordRequest param) {
|
|
|
-//
|
|
|
-// SysUserEntity user = userService.findByUserName(getTokenUserName());
|
|
|
-//
|
|
|
-// // 验证原密码
|
|
|
-// Boolean isBoolean = PasswordUtils.decrypt(user.getPassword(), param.getOldPassword(), PasswordUtils.getStaticSalt());
|
|
|
-// if (!isBoolean) {
|
|
|
-// log.error("原始密码错误");
|
|
|
-// return Result.failure("原始密码错误");
|
|
|
-// }
|
|
|
-//
|
|
|
-// user.setPassword(PasswordUtils.encrypt(user.getUserName(), param.getNewPassword(), PasswordUtils.getStaticSalt()));
|
|
|
-// user.setUpdateTime(new Date());
|
|
|
-// userService.update(user);
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
-// @ApiOperation("重置密码")
|
|
|
-// @GetMapping("resetPass/{id}")
|
|
|
-// public Result resetPass(@PathVariable Long id) {
|
|
|
-// SysUserEntity user = userService.findById(id);
|
|
|
-//
|
|
|
-// if (user == null) {
|
|
|
-// log.error("用户不存在: {}", id);
|
|
|
-// return Result.failure("用户不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-// user.setPassword(PasswordUtils.encrypt(user.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
-// user.setUpdateTime(new Date());
|
|
|
-// userService.update(user);
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
-// @ApiOperation("启用、停用、注销账户")
|
|
|
-// @GetMapping("setStatus/{id}/{status}")
|
|
|
-// public Result setStatus(@PathVariable Long id, @PathVariable Integer status) {
|
|
|
-//
|
|
|
-// SysUserEntity user = userService.findById(id);
|
|
|
-// if (user == null) {
|
|
|
-// log.error("用户不存在: {}", id);
|
|
|
-// return Result.failure("用户不存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//// if (user.getSysManager() == 1) {
|
|
|
-//// log.error("管理员账户不能停用/注销: {}", id);
|
|
|
-//// return Result.failure("管理员账户不能停用/注销");
|
|
|
-//// }
|
|
|
-//
|
|
|
-// if ("sys_admin".equals(user.getRole())) {
|
|
|
+package com.gis.web.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.gis.common.util.PasswordUtils;
|
|
|
+import com.gis.common.util.Result;
|
|
|
+import com.gis.domain.po.SysUserEntity;
|
|
|
+import com.gis.domain.dto.PageDto;
|
|
|
+import com.gis.domain.dto.PasswordRequest;
|
|
|
+import com.gis.domain.dto.UserDto;
|
|
|
+import com.gis.service.SysUserService;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.shiro.authz.annotation.Logical;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
+import org.junit.Test;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import springfox.documentation.annotations.ApiIgnore;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by owen on 2020/2/18 0018 12:17
|
|
|
+ */
|
|
|
+@ApiIgnore
|
|
|
+@Log4j2
|
|
|
+@Api(tags = "s用户管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("manage/user")
|
|
|
+@Transactional
|
|
|
+public class SysUserController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public SysUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RedisTemplate<Object, Object> redisTemplate;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
+ @ApiOperation("用户列表")
|
|
|
+ @PostMapping("list")
|
|
|
+ public Result<SysUserEntity> list(@RequestBody PageDto param) {
|
|
|
+ startPage(param);
|
|
|
+ PageInfo<SysUserEntity> page = new PageInfo<>(userService.findAll());
|
|
|
+ return Result.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
+ @ApiOperation("新增/修改用户信息")
|
|
|
+ @PostMapping("save")
|
|
|
+ public Result save(@Valid @RequestBody UserDto param) {
|
|
|
+
|
|
|
+ SysUserEntity entity = null;
|
|
|
+ if (param.getId() == null) {
|
|
|
+ entity = userService.findByUserName(param.getUserName());
|
|
|
+ if (entity != null) {
|
|
|
+ return Result.failure("用户名已存在");
|
|
|
+ }
|
|
|
+ entity = new SysUserEntity();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
+ userService.save(entity);
|
|
|
+ } else {
|
|
|
+ entity = userService.findById(param.getId());
|
|
|
+ if (entity == null) {
|
|
|
+ log.error("用户不存在: {}", param.getId());
|
|
|
+ return Result.failure("用户不存在");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ userService.update(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("查询用户信息")
|
|
|
+ @GetMapping("detail/{id}")
|
|
|
+ public Result<SysUserEntity> detail(@PathVariable Long id) {
|
|
|
+ SysUserEntity user = userService.findById(id);
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
+ log.error("用户不存在: {}", id);
|
|
|
+ return Result.failure("用户不存在");
|
|
|
+ }
|
|
|
+ return Result.success(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("修改密码")
|
|
|
+ @PostMapping("updatePwd")
|
|
|
+ public Result updatePwd(@Valid @RequestBody PasswordRequest param) {
|
|
|
+
|
|
|
+ SysUserEntity user = userService.findByUserName(getTokenUserName());
|
|
|
+
|
|
|
+ // 验证原密码
|
|
|
+ Boolean isBoolean = PasswordUtils.decrypt(user.getPassword(), param.getOldPassword(), PasswordUtils.getStaticSalt());
|
|
|
+ if (!isBoolean) {
|
|
|
+ log.error("原始密码错误");
|
|
|
+ return Result.failure("原始密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setPassword(PasswordUtils.encrypt(user.getUserName(), param.getNewPassword(), PasswordUtils.getStaticSalt()));
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ userService.update(user);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
+ @ApiOperation("重置密码")
|
|
|
+ @GetMapping("resetPass/{id}")
|
|
|
+ public Result resetPass(@PathVariable Long id) {
|
|
|
+ SysUserEntity user = userService.findById(id);
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
+ log.error("用户不存在: {}", id);
|
|
|
+ return Result.failure("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setPassword(PasswordUtils.encrypt(user.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ userService.update(user);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresRoles(value = {"sys_admin"}, logical = Logical.OR)
|
|
|
+ @ApiOperation("启用、停用、注销账户")
|
|
|
+ @GetMapping("setStatus/{id}/{status}")
|
|
|
+ public Result setStatus(@PathVariable Long id, @PathVariable Integer status) {
|
|
|
+
|
|
|
+ SysUserEntity user = userService.findById(id);
|
|
|
+ if (user == null) {
|
|
|
+ log.error("用户不存在: {}", id);
|
|
|
+ return Result.failure("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// if (user.getSysManager() == 1) {
|
|
|
// log.error("管理员账户不能停用/注销: {}", id);
|
|
|
// return Result.failure("管理员账户不能停用/注销");
|
|
|
// }
|
|
|
-//
|
|
|
-// user.setStatus(status);
|
|
|
-// user.setUpdateTime(new Date());
|
|
|
-// userService.update(user);
|
|
|
-// return Result.success();
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//}
|
|
|
+
|
|
|
+ if ("sys_admin".equals(user.getRole())) {
|
|
|
+ log.error("管理员账户不能停用/注销: {}", id);
|
|
|
+ return Result.failure("管理员账户不能停用/注销");
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setStatus(status);
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ userService.update(user);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdatePwd(){
|
|
|
+ String userName = "admin";
|
|
|
+ String password = "4dage168";
|
|
|
+ String encrypt = PasswordUtils.encrypt(userName, password, PasswordUtils.getStaticSalt());
|
|
|
+ System.out.println(encrypt);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|