完成用户的添加和修改的逻辑
This commit is contained in:
@@ -26,13 +26,13 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
public class SysDeptController {
|
||||
|
||||
@Resource
|
||||
private SysDeptService sysDeptService;
|
||||
private SysDeptService deptService;
|
||||
|
||||
@ApiOperation("获取部门列表")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:list')")
|
||||
@GetMapping("/list")
|
||||
public CommonResult<List<SysDeptRespVO>> listDepts(SysDeptListReqVO reqVO) {
|
||||
List<SysDeptDO> list = sysDeptService.listDepts(reqVO);
|
||||
List<SysDeptDO> list = deptService.listDepts(reqVO);
|
||||
list.sort(Comparator.comparing(SysDeptDO::getSort));
|
||||
return success(SysDeptConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
@@ -43,8 +43,8 @@ public class SysDeptController {
|
||||
// 获得部门列表,只要开启状态的
|
||||
SysDeptListReqVO reqVO = new SysDeptListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<SysDeptDO> list = sysDeptService.listDepts(reqVO);
|
||||
// 排序后,返回个诶前端
|
||||
List<SysDeptDO> list = deptService.listDepts(reqVO);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SysDeptDO::getSort));
|
||||
return success(SysDeptConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dept;
|
||||
|
||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "岗位 API")
|
||||
@RestController
|
||||
@RequestMapping("/system/post")
|
||||
public class SysPostController {
|
||||
|
||||
@Resource
|
||||
private SysPostService postService;
|
||||
|
||||
@ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项")
|
||||
@GetMapping("/list-all-simple")
|
||||
public CommonResult<List<SysPostSimpleRespVO>> listSimplePosts() {
|
||||
// 获得岗位列表,只要开启状态的
|
||||
List<SysPostDO> list = postService.listPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SysPostDO::getSort));
|
||||
return success(SysPostConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package cn.iocoder.dashboard.modules.system.controller.user;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageItemRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
|
||||
@@ -12,10 +11,10 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@@ -59,7 +58,36 @@ public class SysUserController {
|
||||
});
|
||||
return success(new PageResult<>(userList, pageResult.getTotal()));
|
||||
}
|
||||
//
|
||||
|
||||
/**
|
||||
* 根据用户编号获取详细信息
|
||||
*/
|
||||
@ApiOperation("获得用户详情")
|
||||
@ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
|
||||
@GetMapping("/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:query')")
|
||||
public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) {
|
||||
return success(SysUserConvert.INSTANCE.convert(userService.getUser(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增用户")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:add')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createUser(@Validated @RequestBody SysUserCreateReqVO reqVO) {
|
||||
Long id = userService.createUser(reqVO);
|
||||
return success(id);
|
||||
}
|
||||
|
||||
@ApiOperation("修改用户")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateUser(@Validated @RequestBody SysUserUpdateReqVO reqVO) {
|
||||
userService.updateUser(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
// @Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:export')")
|
||||
// @GetMapping("/export")
|
||||
@@ -90,76 +118,8 @@ public class SysUserController {
|
||||
// return util.importTemplateExcel("用户数据");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据用户编号获取详细信息
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:query')")
|
||||
// @GetMapping(value = { "/", "/{userId}" })
|
||||
// public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
||||
// {
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// List<SysRole> roles = roleService.selectRoleAll();
|
||||
// ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||
// ajax.put("posts", postService.selectPostAll());
|
||||
// if (StringUtils.isNotNull(userId))
|
||||
// {
|
||||
// ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
|
||||
// ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||
// ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
|
||||
// }
|
||||
// return ajax;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 新增用户
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:add')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
// @PostMapping
|
||||
// public AjaxResult add(@Validated @RequestBody SysUser user)
|
||||
// {
|
||||
// if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
|
||||
// {
|
||||
// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||
// }
|
||||
// else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
// && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
||||
// {
|
||||
// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
// }
|
||||
// else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
// && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
||||
// {
|
||||
// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
// }
|
||||
// user.setCreateBy(SecurityUtils.getUsername());
|
||||
// user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
// return toAjax(userService.insertUser(user));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
// @PutMapping
|
||||
// public AjaxResult edit(@Validated @RequestBody SysUser user)
|
||||
// {
|
||||
// userService.checkUserAllowed(user);
|
||||
// if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
// && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
||||
// {
|
||||
// return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
// }
|
||||
// else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
// && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
||||
// {
|
||||
// return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
// }
|
||||
// user.setUpdateBy(SecurityUtils.getUsername());
|
||||
// return toAjax(userService.updateUser(user));
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
// /**
|
||||
// * 删除用户
|
||||
// */
|
||||
|
||||
@@ -2,11 +2,21 @@ package cn.iocoder.dashboard.modules.system.controller.user.vo.user;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@ApiModel("用户创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysUserCreateReqVO extends SysUserBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "密码", required = true, example = "123456")
|
||||
@NotEmpty(message = "密码不能为空")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user