|
@@ -0,0 +1,248 @@
|
|
|
+package com.hcloud.microserver.bank.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.hcloud.microserver.bank.bo.CarbonBaseController;
|
|
|
+import com.hcloud.microserver.commoncore.annotation.AuthCarbonValidate;
|
|
|
+import com.hcloud.microserver.commoncore.base.ResponseBase;
|
|
|
+import com.hcloud.microserver.commoncore.base.ResultVO;
|
|
|
+import com.hcloud.microserver.commoncore.enums.CarbonAuthEnum;
|
|
|
+import com.hcloud.microserver.commoncore.enums.ResultEnum;
|
|
|
+import com.hcloud.microserver.commoncore.service.RedisUtils;
|
|
|
+import com.hcloud.microserver.commoncore.util.string.StringUtils;
|
|
|
+import com.hcloud.microserver.sys.facade.entity.SysUser;
|
|
|
+import com.hcloud.microserver.sys.facade.forms.SysMangerForm;
|
|
|
+import com.hcloud.microserver.sys.facade.forms.SysUserForm;
|
|
|
+import com.hcloud.microserver.sys.facade.vo.SysTreeNode;
|
|
|
+import com.hcloud.microserver.sys.service.biz.LoginSystemService;
|
|
|
+import com.hcloud.microserver.sys.service.service.SysPermissionService;
|
|
|
+import com.hcloud.microserver.sys.service.service.SysUserService;
|
|
|
+import com.hcloud.microserver.sys.service.service.UserManagerCacheService;
|
|
|
+import com.hcloud.microserver.sys.service.util.CurrUserUtil;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.core.userdetails.UserDetails;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.security.Principal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xiezt
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sys/user")
|
|
|
+@Api(description = "系统用户服务")
|
|
|
+public class SysUserController extends CarbonBaseController {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoginSystemService loginService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private com.hcloud.microserver.sys.service.service.SysPermissionService SysPermissionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserManagerCacheService userManagerCacheService;
|
|
|
+
|
|
|
+ @Value("${jwt.tokenHead}")
|
|
|
+ private String tokenHead;
|
|
|
+ @Value("${jwt.tokenHeader}")
|
|
|
+ private String tokenHeader;
|
|
|
+ @GetMapping("/findUserByAccount")
|
|
|
+
|
|
|
+ public ResultVO<SysUser> queryUserInfoByAccount(@RequestParam("account") String account) {
|
|
|
+ log.info("account=====================>{}", account);
|
|
|
+ return success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/login")
|
|
|
+
|
|
|
+ public ResponseBase login(@RequestParam("account") String account, @RequestParam("password") String password) {
|
|
|
+ log.info("登录的用户名:[{}]", account);
|
|
|
+ String token = loginService.login(account, password);
|
|
|
+ Map<String, String> tokenMap = new HashMap<>();
|
|
|
+ tokenMap.put("token", token);
|
|
|
+ tokenMap.put("tokenHead", tokenHead);
|
|
|
+ if (StringUtils.isNotEmpty(token)){
|
|
|
+ return responseSuccess(success(tokenMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseError(failure());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "登出功能")
|
|
|
+ @RequestMapping(value = "/logout", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResponseBase logout() {
|
|
|
+ userManagerCacheService.delToken(CurrUserUtil.getUmsAdmin().getCname());
|
|
|
+ return responseSuccess(success());
|
|
|
+ }
|
|
|
+ @ApiOperation(value = "刷新token")
|
|
|
+ @RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public ResponseBase refreshToken(HttpServletRequest request) {
|
|
|
+ String token = request.getHeader(tokenHeader);
|
|
|
+ String refreshToken = loginService.refreshToken(token);
|
|
|
+ UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
+ if (refreshToken == null) {
|
|
|
+ userManagerCacheService.delToken(userDetails.getUsername());
|
|
|
+ return responseSuccess(failure("token已经过期!"));
|
|
|
+ }
|
|
|
+ Map<String, String> tokenMap = new HashMap<>();
|
|
|
+ tokenMap.put("token", refreshToken);
|
|
|
+ tokenMap.put("tokenHead", tokenHead);
|
|
|
+ userManagerCacheService.setToken(userDetails.getUsername(), tokenHead + refreshToken);
|
|
|
+ return responseSuccess(success(tokenMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取当前登录用户信息")
|
|
|
+ @RequestMapping(value = "/info", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public ResponseBase getAdminInfo(Principal principal) {
|
|
|
+ if (principal == null) {
|
|
|
+ return responseError(failure());
|
|
|
+ }
|
|
|
+ String username = principal.getName();
|
|
|
+ Map<String, Object> userByUsername = loginService.getUserByUsername(username);
|
|
|
+ return responseSuccess(success(userByUsername));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "保存用户信息", notes = "保存用户信息时,添加用户所选角色的相应权限")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysMangerForm", value = "用户管理页面参数对象", dataType = "DefinedObject")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @RequestMapping("/add")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_USER_CREATE)
|
|
|
+ public ResponseBase addUser(@RequestBody SysUserForm sysUserForm){
|
|
|
+ ResultVO resultVO = sysUserService.saveUserInfoAndPermission(sysUserForm);
|
|
|
+ if(resultVO.getCode()==0){return responseSuccess(resultVO);}
|
|
|
+ return responseError(resultVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新用户信息", notes = "更新用户信息时,变更角色后会删除缓存信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysMangerForm", value = "用户管理页面参数对象", dataType = "DefinedObject")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @RequestMapping("/update")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_USER_EDIT)
|
|
|
+ public ResponseBase modifiedUser(@RequestBody SysUserForm sysUserForm){
|
|
|
+ ResultVO resultVO = sysUserService.modifyUserInfoAndPermission(sysUserForm);
|
|
|
+ if(resultVO.getCode()==0){return responseSuccess(resultVO);}
|
|
|
+ return responseError(resultVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页查询用户基本信息", notes = "分页查询用户信息,默认每页每页10")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysMangerForm", value = "用户管理页面参数对象", dataType = "DefinedObject")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @RequestMapping("/searchByPage")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_USER_QUERY)
|
|
|
+ public ResponseBase searchByPage(@RequestBody SysMangerForm sysMangerForm){
|
|
|
+ PageInfo<Page<Map>> pageInfo = sysUserService.queryUserInfoByPage(sysMangerForm);
|
|
|
+ return responseSuccess(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询用户基本权限信息", notes = "以树型结构递归显示")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysMangerForm", value = "用户管理页面参数对象", dataType = "DefinedObject")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @PostMapping("/getAuthTreeById")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_PERMISSION_USER_QUERY)
|
|
|
+ public ResponseBase searchUserAuthById(@RequestBody SysMangerForm sysMangerForm){
|
|
|
+ List<SysTreeNode> list = SysPermissionService.selectPermTree(sysMangerForm.getUserId(), "user");
|
|
|
+ return responseResultSuccess(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询部门及角色信息", notes = "系统内所有部门及角色信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "refSysApp", value = "引用系统app标记,默认是1", dataType = "String")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @GetMapping("/selectList")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_DEPT_ROLE_INFO)
|
|
|
+ public ResponseBase getDeptAndRoleInfo(@RequestParam("sysApp") String refSysApp){
|
|
|
+ Map resMap = loginService.getAllDeptAndRole();
|
|
|
+ if (resMap != null){
|
|
|
+ return responseSuccess(success(resMap));
|
|
|
+ }
|
|
|
+ return responseError(new ResultVO(ResultEnum.SYS_ERROR));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新用户权限信息", notes = "根据用户变更的权限列表,更新用户权限")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysUserForm", value = "用户管理页面参数对象", dataType = "String")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @RequestMapping("/updateAuth")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_PERMISSION_USER_UPDATE)
|
|
|
+ public ResponseBase modifiedUserAuth(@RequestBody SysUserForm sysUserForm){
|
|
|
+ if (null != sysUserForm) {
|
|
|
+ int success = sysUserService.updateUserPermission(sysUserForm);
|
|
|
+ if (success > 0) {
|
|
|
+ return responseSuccess(success());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return responseError(new ResultVO(ResultEnum.SYS_ERROR));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除用户信息", notes = "根据用户id删除用户信息,含权限信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysUserForm", value = "用户管理页面参数对象", dataType = "String")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @PostMapping("/del")
|
|
|
+ @AuthCarbonValidate(CarbonAuthEnum.SYS_USER_DELETE)
|
|
|
+ public ResponseBase delUserInfo(@RequestBody SysUserForm sysUserForm){
|
|
|
+ if (null != sysUserForm) {
|
|
|
+ String guid = sysUserForm.getGuid();
|
|
|
+ int success = loginService.deluserInfo(guid);
|
|
|
+ if (success > 0) {
|
|
|
+ return responseSuccess(success());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return responseError(new ResultVO(ResultEnum.SYS_ERROR));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "禁用(启用)用户信息", notes = "根据用户id启用(禁用)用户信息,不删除权限信息")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sysUserForm", value = "用户管理页面参数对象", dataType = "String")
|
|
|
+ })
|
|
|
+ @ApiResponse(code = 0, message = "操作成功")
|
|
|
+ @RequestMapping("/forbidden")
|
|
|
+ @AuthCarbonValidate
|
|
|
+ public ResponseBase forbiddenUser(@RequestBody SysUserForm sysUserForm){
|
|
|
+ if (null != sysUserForm) {
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setGuid(sysUserForm.getUserId());
|
|
|
+ user.setCstatus(sysUserForm.getCstatus());
|
|
|
+ int success = sysUserService.modifyByPrimaryKeySelective(user);
|
|
|
+ if (success > 0) {
|
|
|
+ return responseSuccess(success());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return responseError(new ResultVO(ResultEnum.SYS_ERROR));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|