|  |  |  | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.BaseParam; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.KeyValVo; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.PageParam; | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.PageResult; | 
|---|
|  |  |  | import com.zy.acs.manager.common.utils.ExcelUtil; | 
|---|
|  |  |  | import com.zy.acs.manager.system.controller.param.ResetPwdParam; | 
|---|
|  |  |  | import com.zy.acs.manager.system.entity.User; | 
|---|
|  |  |  | 
|---|
|  |  |  | public R page(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<User, BaseParam> pageParam = new PageParam<>(baseParam, User.class); | 
|---|
|  |  |  | PageParam<User, BaseParam> page = userService.page(pageParam, pageParam.buildWrapper(true, wrapper -> wrapper.orderByAsc("create_time"))); | 
|---|
|  |  |  | for (User record : page.getRecords()) { | 
|---|
|  |  |  | PageResult<User> pageResult = userService.pageRel(pageParam); | 
|---|
|  |  |  | for (User record : pageResult.getRecords()) { | 
|---|
|  |  |  | record.setRoles(userRoleService.listByUserId(record.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(page); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('system:user:list')") | 
|---|
|  |  |  | @PostMapping("/user/page1") | 
|---|
|  |  |  | public R page1(@RequestBody Map<String, Object> map) { | 
|---|
|  |  |  | BaseParam baseParam = buildParam(map, BaseParam.class); | 
|---|
|  |  |  | PageParam<User, BaseParam> pageParam = new PageParam<>(baseParam, User.class); | 
|---|
|  |  |  | return R.ok().add(userService.pageRel(pageParam)); | 
|---|
|  |  |  | return R.ok().add(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('system:user:list')") | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.error("the phone already exist"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | user.setPassword(userService.encodePassword(COMMON_PASSWORD)); | 
|---|
|  |  |  | if (Cools.isEmpty(user.getPassword())) { | 
|---|
|  |  |  | user.setPassword(userService.encodePassword(COMMON_PASSWORD)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | user.setCreateBy(getLoginUserId()); | 
|---|
|  |  |  | user.setCreateTime(new Date()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId())); | 
|---|
|  |  |  | for (Long roleId : user.getRoleIds()) { | 
|---|
|  |  |  | if (!userRoleService.save(new UserRole(user.getId(), roleId))) { | 
|---|
|  |  |  | throw new CoolException("Internal Server Error"); | 
|---|
|  |  |  | if (!Cools.isEmpty((Object) user.getRoleIds())) { | 
|---|
|  |  |  | for (Long roleId : user.getRoleIds()) { | 
|---|
|  |  |  | if (!userRoleService.save(new UserRole(user.getId(), roleId))) { | 
|---|
|  |  |  | throw new CoolException("Internal Server Error"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok("Save Success"); | 
|---|
|  |  |  | return R.ok("Save Success").add(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('system:user:update')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping("/user/update") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R update(@RequestBody User user) { | 
|---|
|  |  |  | if (user.getPassword() != null && user.getPassword().equals("")) { | 
|---|
|  |  |  | user.setPassword(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(user.getUsername()) && userService.count(new LambdaQueryWrapper<User>() | 
|---|
|  |  |  | .eq(User::getUsername, user.getUsername()) | 
|---|
|  |  |  | .ne(User::getId, user.getId())) > 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok("Update Success"); | 
|---|
|  |  |  | return R.ok("Update Success").add(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('system:user:remove')") | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!userService.removeById(userId)) { | 
|---|
|  |  |  | throw new CoolException("Internal Server Error"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId))) { | 
|---|
|  |  |  | throw new CoolException("Internal Server Error"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Delete Success"); | 
|---|
|  |  |  | return R.ok("Delete Success").add(ids); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreAuthorize("hasAuthority('system:user:list')") | 
|---|