| | |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | | import com.sandu.common.enums.ResponseStatusEnums; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.log.Log; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.security.LoginUserInfo; |
| | |
| | | import com.sandu.ximon.admin.param.AdminLoginParam; |
| | | import com.sandu.ximon.admin.param.AdminParam; |
| | | import com.sandu.ximon.admin.param.PwdParam; |
| | | import com.sandu.ximon.admin.param.ReceiveParam; |
| | | import com.sandu.ximon.admin.security.PermissionConfig; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.*; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.enums.AdministratorEnums; |
| | | import com.sandu.ximon.dao.enums.MenuEnum; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | |
| | | private final RoleService roleService; |
| | | private final TokenProvider tokenProvider; |
| | | private final AdminRoleRelationService adminRoleRelationService; |
| | | private PermissionConfig permissionConfig; |
| | | |
| | | @Log("后台用户登录") |
| | | @AnonymousAccess |
| | |
| | | return ResponseUtil.success(authInfo); |
| | | } |
| | | |
| | | // @Log("后台用户信息") |
| | | @GetMapping(value = "/info") |
| | | public ResponseVO<Object> getUserInfo() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<Role> roles; |
| | | MapBuilder<Object, Object> builder; |
| | | if (AdministratorEnums.ADMIN.equals(SecurityUtils.getAdministratorIdentity()) |
| | | || AdministratorEnums.CUSTOMER.equals(SecurityUtils.getAdministratorIdentity())) { |
| | | if (AdministratorEnums.ADMIN.getCode().equals(SecurityUtils.getAdministratorIdentity()) |
| | | || AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) { |
| | | Admin admin = adminService.getById(userId); |
| | | roles = roleService.listByAdminId(admin.getId()); |
| | | builder = MapUtil.builder().put("admin", admin); |
| | |
| | | return ResponseUtil.success(builder.build()); |
| | | } |
| | | |
| | | @Log("后台用户列表") |
| | | @GetMapping(value = "/list") |
| | | public ResponseVO<Object> listAdmin(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery(Admin.class); |
| | | if (keyword != null) { |
| | |
| | | return ResponseUtil.successPage(adminDtoList); |
| | | } |
| | | |
| | | @Log("后台用户注册") |
| | | @PostMapping("/register") |
| | | public ResponseVO<Object> register(@Validated @RequestBody AdminParam param) { |
| | | boolean result = adminService.register(param); |
| | |
| | | /** |
| | | * 修改管理员信息 |
| | | */ |
| | | @Log("后台用户修改信息") |
| | | @PostMapping("/update/{adminId}") |
| | | public ResponseVO<Object> updateAdmin(@RequestBody AdminParam param, @PathVariable Long adminId) { |
| | | boolean result = adminService.updateAdmin(adminId, param); |
| | |
| | | /** |
| | | * 修改我的密码 |
| | | */ |
| | | @Log("后台用户修改密码") |
| | | @PutMapping("/updateMyPassword") |
| | | public ResponseVO<Object> updateMyPassword(@Validated @RequestBody PwdParam param) { |
| | | boolean result = adminService.updateMyPassword(param); |
| | |
| | | // return ResponseUtil.success(null); |
| | | // } |
| | | |
| | | @Log("后台用户删除") |
| | | @PostMapping("/del/{adminId}") |
| | | public ResponseVO<Object> deleteAdmin(@PathVariable Long adminId) { |
| | | boolean result = adminService.deleteAdmin(adminId); |
| | |
| | | } |
| | | } |
| | | |
| | | @Log("用户修改头像") |
| | | @PostMapping("/updateIcon") |
| | | public ResponseVO<Object> updateIcon(@RequestBody ReceiveParam receiveParam) { |
| | | if (receiveParam.getIconUrl().trim() == null) { |
| | | throw new BusinessException("头像URL不能为空!"); |
| | | } |
| | | boolean result; |
| | | //普通用户修改头像 |
| | | if (SecurityUtils.getAdministratorIdentity().equals(AdministratorEnums.NORMAL.getCode())) { |
| | | result = clientService.updateIcon(SecurityUtils.getUserId(), receiveParam.getIconUrl()); |
| | | } else { |
| | | //超级管理员、管理员修改头像 |
| | | result = adminService.updateIcon(SecurityUtils.getUserId(), receiveParam.getIconUrl()); |
| | | } |
| | | |
| | | if (result) { |
| | | return ResponseUtil.success("修改成功"); |
| | | } else { |
| | | return ResponseUtil.fail("修改失败"); |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 给管理员分配角色 |
| | | // * |