package com.gkhy.hazmat.admin.controller.system; import com.gkhy.hazmat.common.annotation.Log; import com.gkhy.hazmat.common.annotation.RepeatSubmit; import com.gkhy.hazmat.common.api.CommonResult; import com.gkhy.hazmat.common.domain.entity.SysRole; import com.gkhy.hazmat.common.domain.entity.SysUser; import com.gkhy.hazmat.common.enums.BusinessType; import com.gkhy.hazmat.system.domain.SysDept; import com.gkhy.hazmat.system.service.ISysRoleService; import com.gkhy.hazmat.system.service.SysDeptService; import com.gkhy.hazmat.system.service.SysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; 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.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static com.gkhy.hazmat.common.api.CommonResult.success; @Api(tags = "用户前端控制器") @RestController @RequestMapping("/system/user") public class SysUserController { @Autowired private SysUserService sysUserService; @Autowired private ISysRoleService roleService; @Autowired private SysDeptService deptService; // @PreAuthorize("hasAuthority('hazmat:manage:company')") // @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company')") @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company','hazmat:manage:common')") @ApiOperation(value = "用户列表(分页)") @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", name = "pageNum", dataType = "int", required = false, value = "当前页,默认1"), @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", required = false, value = "每页数目,默认10") }) @GetMapping("/list") public CommonResult list(SysUser user){ return success(sysUserService.selectUserList(user)); } @ApiOperation(value = "根据用户id获取用户信息") @GetMapping(value = { "/{userId}" }) public CommonResult getUserInfo(@PathVariable(value = "userId", required = false) Long userId) { return success(sysUserService.selectUserById(userId)); } @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company')") @RepeatSubmit @Log(title = "用户管理", businessType = BusinessType.INSERT) @ApiOperation(value = "新增用户") @PostMapping public CommonResult add(@Validated @RequestBody SysUser user){ return success(sysUserService.addUser(user)); } @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company','hazmat:manage:common')") @RepeatSubmit @Log(title = "用户管理", businessType = BusinessType.UPDATE) @ApiOperation(value = "编辑用户") @PutMapping public CommonResult edit(@RequestBody SysUser user){ return success(sysUserService.updateUser(user)); } @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company')") @RepeatSubmit @Log(title = "用户管理", businessType = BusinessType.DELETE) @ApiOperation(value = "删除用户") @PutMapping("/{userId}") public CommonResult delete(@PathVariable(value = "userId" ,required = true)Long userId){ return success(sysUserService.deleteUserById(userId)); } @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company','hazmat:manage:common')") @RepeatSubmit @Log(title = "用户管理", businessType = BusinessType.UPDATE) @ApiOperation(value = "重置密码") @PutMapping(value = "/resetPwd") public CommonResult restPwd(@RequestBody SysUser user){ sysUserService.resetUserPwd(user); return success(); } @PreAuthorize("hasAnyAuthority('hazmat:manage:system','hazmat:manage:company')") @RepeatSubmit @Log(title = "用户管理", businessType = BusinessType.UPDATE) @ApiOperation(value = "修改用户状态") @PutMapping(value = "/changeStatus") public CommonResult changeStatus(@RequestBody SysUser user){ sysUserService.updateUserStatus(user); return success(); } /** * 根据用户编号获取授权角色 */ // @PreAuthorize("@ss.hasPermi('system:user:query')") @GetMapping("/authRole/{userId}") public CommonResult authRole(@PathVariable("userId") Long userId) { Map ajax = new HashMap<>(); SysUser user = sysUserService.selectUserById(userId); List roles = roleService.selectRolesByUserId(userId); ajax.put("user", user); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); return CommonResult.success(ajax); } /** * 用户授权角色 */ // @PreAuthorize("@ss.hasPermi('system:user:edit')") @Log(title = "用户管理", businessType = BusinessType.GRANT) @PutMapping("/authRole") public CommonResult insertAuthRole(Long userId, Long[] roleIds) { sysUserService.checkUserDataScope(userId); roleService.checkRoleDataScope(roleIds); sysUserService.insertUserAuth(userId, roleIds); return success(); } /** * 获取部门树列表 */ // @PreAuthorize("@ss.hasPermi('system:user:list')") @GetMapping("/deptTree") public CommonResult deptTree(SysDept dept) { return success(deptService.selectDeptTreeList(dept)); } }