Commit e3884ee57f12bb2e884ff625118da364b520e769
1 parent
855327de
完成用户的添加和修改的逻辑
Showing
22 changed files
with
479 additions
and
449 deletions
ruoyi-ui/src/api/system/post.js
| ... | ... | @@ -9,6 +9,14 @@ export function listPost(query) { |
| 9 | 9 | }) |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | +// 获取岗位精简信息列表 | |
| 13 | +export function listSimplePosts() { | |
| 14 | + return request({ | |
| 15 | + url: '/system/post/list-all-simple', | |
| 16 | + method: 'get' | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 12 | 20 | // 查询岗位详细 |
| 13 | 21 | export function getPost(postId) { |
| 14 | 22 | return request({ |
| ... | ... | @@ -50,4 +58,4 @@ export function exportPost(query) { |
| 50 | 58 | method: 'get', |
| 51 | 59 | params: query |
| 52 | 60 | }) |
| 53 | -} | |
| 54 | 61 | \ No newline at end of file |
| 62 | +} | ... | ... |
ruoyi-ui/src/api/system/user.js
ruoyi-ui/src/utils/dict.js
ruoyi-ui/src/views/system/user/index.vue
| ... | ... | @@ -188,7 +188,9 @@ |
| 188 | 188 | </el-col> |
| 189 | 189 | <el-col :span="12"> |
| 190 | 190 | <el-form-item label="归属部门" prop="deptId"> |
| 191 | - <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" /> | |
| 191 | + <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" | |
| 192 | + placeholder="请选择归属部门" :normalizer="normalizer" | |
| 193 | + /> | |
| 192 | 194 | </el-form-item> |
| 193 | 195 | </el-col> |
| 194 | 196 | </el-row> |
| ... | ... | @@ -221,49 +223,22 @@ |
| 221 | 223 | <el-form-item label="用户性别"> |
| 222 | 224 | <el-select v-model="form.sex" placeholder="请选择"> |
| 223 | 225 | <el-option |
| 224 | - v-for="dict in sexOptions" | |
| 225 | - :key="dict.dictValue" | |
| 226 | - :label="dict.dictLabel" | |
| 227 | - :value="dict.dictValue" | |
| 226 | + v-for="dict in sexDictDatas" | |
| 227 | + :key="parseInt(dict.value)" | |
| 228 | + :label="dict.label" | |
| 229 | + :value="parseInt(dict.value)" | |
| 228 | 230 | ></el-option> |
| 229 | 231 | </el-select> |
| 230 | 232 | </el-form-item> |
| 231 | 233 | </el-col> |
| 232 | 234 | <el-col :span="12"> |
| 233 | - <el-form-item label="状态"> | |
| 234 | - <el-radio-group v-model="form.status"> | |
| 235 | - <el-radio | |
| 236 | - v-for="dict in statusOptions" | |
| 237 | - :key="dict.dictValue" | |
| 238 | - :label="dict.dictValue" | |
| 239 | - >{{dict.dictLabel}}</el-radio> | |
| 240 | - </el-radio-group> | |
| 241 | - </el-form-item> | |
| 242 | - </el-col> | |
| 243 | - </el-row> | |
| 244 | - <el-row> | |
| 245 | - <el-col :span="12"> | |
| 246 | 235 | <el-form-item label="岗位"> |
| 247 | 236 | <el-select v-model="form.postIds" multiple placeholder="请选择"> |
| 248 | 237 | <el-option |
| 249 | - v-for="item in postOptions" | |
| 250 | - :key="item.postId" | |
| 251 | - :label="item.postName" | |
| 252 | - :value="item.postId" | |
| 253 | - :disabled="item.status == 1" | |
| 254 | - ></el-option> | |
| 255 | - </el-select> | |
| 256 | - </el-form-item> | |
| 257 | - </el-col> | |
| 258 | - <el-col :span="12"> | |
| 259 | - <el-form-item label="角色"> | |
| 260 | - <el-select v-model="form.roleIds" multiple placeholder="请选择"> | |
| 261 | - <el-option | |
| 262 | - v-for="item in roleOptions" | |
| 263 | - :key="item.roleId" | |
| 264 | - :label="item.roleName" | |
| 265 | - :value="item.roleId" | |
| 266 | - :disabled="item.status == 1" | |
| 238 | + v-for="item in postOptions" | |
| 239 | + :key="item.id" | |
| 240 | + :label="item.name" | |
| 241 | + :value="item.id" | |
| 267 | 242 | ></el-option> |
| 268 | 243 | </el-select> |
| 269 | 244 | </el-form-item> |
| ... | ... | @@ -313,17 +288,45 @@ |
| 313 | 288 | <el-button @click="upload.open = false">取 消</el-button> |
| 314 | 289 | </div> |
| 315 | 290 | </el-dialog> |
| 291 | + | |
| 292 | + <!-- 分配角色 --> | |
| 293 | +<!-- <el-dialog title="分配角色" :visible.sync="openMenu" width="500px" append-to-body>--> | |
| 294 | +<!-- <el-form :model="form" label-width="80px">--> | |
| 295 | +<!-- <el-form-item label="用户名称">--> | |
| 296 | +<!-- <el-input v-model="form.username" :disabled="true" />--> | |
| 297 | +<!-- </el-form-item>--> | |
| 298 | +<!-- <el-form-item label="用户昵称">--> | |
| 299 | +<!-- <el-input v-model="form.nickname" :disabled="true" />--> | |
| 300 | +<!-- </el-form-item>--> | |
| 301 | +<!-- <el-form-item label="角色">--> | |
| 302 | +<!-- <el-select v-model="form.roleIds" multiple placeholder="请选择">--> | |
| 303 | +<!-- <el-option--> | |
| 304 | +<!-- v-for="item in roleOptions"--> | |
| 305 | +<!-- :key="item.roleId"--> | |
| 306 | +<!-- :label="item.roleName"--> | |
| 307 | +<!-- :value="item.roleId"--> | |
| 308 | +<!-- :disabled="item.status == 1"--> | |
| 309 | +<!-- ></el-option>--> | |
| 310 | +<!-- </el-select>--> | |
| 311 | +<!-- </el-form-item>--> | |
| 312 | +<!-- </el-form>--> | |
| 313 | +<!-- <div slot="footer" class="dialog-footer">--> | |
| 314 | +<!-- <el-button type="primary" @click="submitMenu">确 定</el-button>--> | |
| 315 | +<!-- <el-button @click="cancelMenu">取 消</el-button>--> | |
| 316 | +<!-- </div>--> | |
| 317 | +<!-- </el-dialog>--> | |
| 318 | + | |
| 316 | 319 | </div> |
| 317 | 320 | </template> |
| 318 | 321 | |
| 319 | 322 | <script> |
| 320 | 323 | import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user"; |
| 321 | 324 | import { getToken } from "@/utils/auth"; |
| 322 | -import { treeselect } from "@/api/system/dept"; | |
| 323 | 325 | import Treeselect from "@riophae/vue-treeselect"; |
| 324 | 326 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| 325 | 327 | |
| 326 | 328 | import {listSimpleDepts} from "@/api/system/dept"; |
| 329 | +import {listSimplePosts} from "@/api/system/post"; | |
| 327 | 330 | |
| 328 | 331 | import {SysCommonStatusEnum} from "@/utils/constants"; |
| 329 | 332 | import {DICT_TYPE, getDictDatas} from "@/utils/dict"; |
| ... | ... | @@ -422,6 +425,7 @@ export default { |
| 422 | 425 | SysCommonStatusEnum: SysCommonStatusEnum, |
| 423 | 426 | // 数据字典 |
| 424 | 427 | statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS), |
| 428 | + sexDictDatas: getDictDatas(DICT_TYPE.SYS_USER_SEX), | |
| 425 | 429 | }; |
| 426 | 430 | }, |
| 427 | 431 | watch: { |
| ... | ... | @@ -446,18 +450,23 @@ export default { |
| 446 | 450 | this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined, |
| 447 | 451 | ])).then(response => { |
| 448 | 452 | this.userList = response.data.list; |
| 449 | - this.total = response.data.list; | |
| 453 | + this.total = response.data.total; | |
| 450 | 454 | this.loading = false; |
| 451 | 455 | } |
| 452 | 456 | ); |
| 453 | 457 | }, |
| 454 | - /** 查询部门下拉树结构 */ | |
| 458 | + /** 查询部门下拉树结构 + 岗位下拉 */ | |
| 455 | 459 | getTreeselect() { |
| 456 | 460 | listSimpleDepts().then(response => { |
| 457 | - // 处理 menuOptions 参数 | |
| 461 | + // 处理 deptOptions 参数 | |
| 458 | 462 | this.deptOptions = []; |
| 459 | 463 | this.deptOptions.push(...this.handleTree(response.data, "id")); |
| 460 | 464 | }); |
| 465 | + listSimplePosts().then(response => { | |
| 466 | + // 处理 postOptions 参数 | |
| 467 | + this.postOptions = []; | |
| 468 | + this.postOptions.push(...response.data); | |
| 469 | + }); | |
| 461 | 470 | }, |
| 462 | 471 | // 筛选节点 |
| 463 | 472 | filterNode(value, data) { |
| ... | ... | @@ -521,14 +530,12 @@ export default { |
| 521 | 530 | /** 新增按钮操作 */ |
| 522 | 531 | handleAdd() { |
| 523 | 532 | this.reset(); |
| 533 | + // 获得下拉数据 | |
| 524 | 534 | this.getTreeselect(); |
| 525 | - getUser().then(response => { | |
| 526 | - this.postOptions = response.posts; | |
| 527 | - this.roleOptions = response.roles; | |
| 528 | - this.open = true; | |
| 529 | - this.title = "添加用户"; | |
| 530 | - this.form.password = this.initPassword; | |
| 531 | - }); | |
| 535 | + // 打开表单,并设置初始化 | |
| 536 | + this.open = true; | |
| 537 | + this.title = "添加用户"; | |
| 538 | + this.form.password = this.initPassword; | |
| 532 | 539 | }, |
| 533 | 540 | /** 修改按钮操作 */ |
| 534 | 541 | handleUpdate(row) { |
| ... | ... | @@ -537,10 +544,6 @@ export default { |
| 537 | 544 | const id = row.id; |
| 538 | 545 | getUser(id).then(response => { |
| 539 | 546 | this.form = response.data; |
| 540 | - this.postOptions = response.posts; | |
| 541 | - this.roleOptions = response.roles; | |
| 542 | - this.form.postIds = response.postIds; | |
| 543 | - this.form.roleIds = response.roleIds; | |
| 544 | 547 | this.open = true; |
| 545 | 548 | this.title = "修改用户"; |
| 546 | 549 | this.form.password = ""; |
| ... | ... | @@ -561,7 +564,7 @@ export default { |
| 561 | 564 | submitForm: function() { |
| 562 | 565 | this.$refs["form"].validate(valid => { |
| 563 | 566 | if (valid) { |
| 564 | - if (this.form.id != undefined) { | |
| 567 | + if (this.form.id !== undefined) { | |
| 565 | 568 | updateUser(this.form).then(response => { |
| 566 | 569 | this.msgSuccess("修改成功"); |
| 567 | 570 | this.open = false; |
| ... | ... | @@ -630,6 +633,14 @@ export default { |
| 630 | 633 | // 提交上传文件 |
| 631 | 634 | submitFileForm() { |
| 632 | 635 | this.$refs.upload.submit(); |
| 636 | + }, | |
| 637 | + // 格式化部门的下拉框 | |
| 638 | + normalizer(node) { | |
| 639 | + return { | |
| 640 | + id: node.id, | |
| 641 | + label: node.name, | |
| 642 | + children: node.children | |
| 643 | + } | |
| 633 | 644 | } |
| 634 | 645 | } |
| 635 | 646 | }; | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java
| ... | ... | @@ -26,13 +26,13 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success; |
| 26 | 26 | public class SysDeptController { |
| 27 | 27 | |
| 28 | 28 | @Resource |
| 29 | - private SysDeptService sysDeptService; | |
| 29 | + private SysDeptService deptService; | |
| 30 | 30 | |
| 31 | 31 | @ApiOperation("获取部门列表") |
| 32 | 32 | // @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| 33 | 33 | @GetMapping("/list") |
| 34 | 34 | public CommonResult<List<SysDeptRespVO>> listDepts(SysDeptListReqVO reqVO) { |
| 35 | - List<SysDeptDO> list = sysDeptService.listDepts(reqVO); | |
| 35 | + List<SysDeptDO> list = deptService.listDepts(reqVO); | |
| 36 | 36 | list.sort(Comparator.comparing(SysDeptDO::getSort)); |
| 37 | 37 | return success(SysDeptConvert.INSTANCE.convertList(list)); |
| 38 | 38 | } |
| ... | ... | @@ -43,8 +43,8 @@ public class SysDeptController { |
| 43 | 43 | // 获得部门列表,只要开启状态的 |
| 44 | 44 | SysDeptListReqVO reqVO = new SysDeptListReqVO(); |
| 45 | 45 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 46 | - List<SysDeptDO> list = sysDeptService.listDepts(reqVO); | |
| 47 | - // 排序后,返回个诶前端 | |
| 46 | + List<SysDeptDO> list = deptService.listDepts(reqVO); | |
| 47 | + // 排序后,返回给前端 | |
| 48 | 48 | list.sort(Comparator.comparing(SysDeptDO::getSort)); |
| 49 | 49 | return success(SysDeptConvert.INSTANCE.convertList02(list)); |
| 50 | 50 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.controller.dept; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.dashboard.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; | |
| 6 | +import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert; | |
| 7 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 8 | +import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; | |
| 9 | +import io.swagger.annotations.Api; | |
| 10 | +import io.swagger.annotations.ApiOperation; | |
| 11 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | +import org.springframework.web.bind.annotation.RestController; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.util.Collections; | |
| 17 | +import java.util.Comparator; | |
| 18 | +import java.util.List; | |
| 19 | + | |
| 20 | +import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | |
| 21 | + | |
| 22 | +@Api(tags = "岗位 API") | |
| 23 | +@RestController | |
| 24 | +@RequestMapping("/system/post") | |
| 25 | +public class SysPostController { | |
| 26 | + | |
| 27 | + @Resource | |
| 28 | + private SysPostService postService; | |
| 29 | + | |
| 30 | + @ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项") | |
| 31 | + @GetMapping("/list-all-simple") | |
| 32 | + public CommonResult<List<SysPostSimpleRespVO>> listSimplePosts() { | |
| 33 | + // 获得岗位列表,只要开启状态的 | |
| 34 | + List<SysPostDO> list = postService.listPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | |
| 35 | + // 排序后,返回给前端 | |
| 36 | + list.sort(Comparator.comparing(SysPostDO::getSort)); | |
| 37 | + return success(SysPostConvert.INSTANCE.convertList02(list)); | |
| 38 | + } | |
| 39 | + | |
| 40 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java
| ... | ... | @@ -3,8 +3,7 @@ package cn.iocoder.dashboard.modules.system.controller.user; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 6 | -import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageItemRespVO; | |
| 7 | -import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO; | |
| 6 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*; | |
| 8 | 7 | import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert; |
| 9 | 8 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; |
| 10 | 9 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; |
| ... | ... | @@ -12,10 +11,10 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; |
| 12 | 11 | import cn.iocoder.dashboard.modules.system.service.user.SysUserService; |
| 13 | 12 | import cn.iocoder.dashboard.util.collection.CollectionUtils; |
| 14 | 13 | import io.swagger.annotations.Api; |
| 14 | +import io.swagger.annotations.ApiImplicitParam; | |
| 15 | 15 | import io.swagger.annotations.ApiOperation; |
| 16 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 18 | -import org.springframework.web.bind.annotation.RestController; | |
| 16 | +import org.springframework.validation.annotation.Validated; | |
| 17 | +import org.springframework.web.bind.annotation.*; | |
| 19 | 18 | |
| 20 | 19 | import javax.annotation.Resource; |
| 21 | 20 | import java.util.*; |
| ... | ... | @@ -59,7 +58,36 @@ public class SysUserController { |
| 59 | 58 | }); |
| 60 | 59 | return success(new PageResult<>(userList, pageResult.getTotal())); |
| 61 | 60 | } |
| 62 | -// | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * 根据用户编号获取详细信息 | |
| 64 | + */ | |
| 65 | + @ApiOperation("获得用户详情") | |
| 66 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 67 | + @GetMapping("/get") | |
| 68 | +// @PreAuthorize("@ss.hasPermi('system:user:query')") | |
| 69 | + public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { | |
| 70 | + return success(SysUserConvert.INSTANCE.convert(userService.getUser(id))); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @ApiOperation("新增用户") | |
| 74 | + @PostMapping("/create") | |
| 75 | +// @PreAuthorize("@ss.hasPermi('system:user:add')") | |
| 76 | +// @Log(title = "用户管理", businessType = BusinessType.INSERT) | |
| 77 | + public CommonResult<Long> createUser(@Validated @RequestBody SysUserCreateReqVO reqVO) { | |
| 78 | + Long id = userService.createUser(reqVO); | |
| 79 | + return success(id); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @ApiOperation("修改用户") | |
| 83 | + @PostMapping("update") | |
| 84 | +// @PreAuthorize("@ss.hasPermi('system:user:edit')") | |
| 85 | +// @Log(title = "用户管理", businessType = BusinessType.UPDATE) | |
| 86 | + public CommonResult<Boolean> updateUser(@Validated @RequestBody SysUserUpdateReqVO reqVO) { | |
| 87 | + userService.updateUser(reqVO); | |
| 88 | + return success(true); | |
| 89 | + } | |
| 90 | + | |
| 63 | 91 | // @Log(title = "用户管理", businessType = BusinessType.EXPORT) |
| 64 | 92 | // @PreAuthorize("@ss.hasPermi('system:user:export')") |
| 65 | 93 | // @GetMapping("/export") |
| ... | ... | @@ -90,76 +118,8 @@ public class SysUserController { |
| 90 | 118 | // return util.importTemplateExcel("用户数据"); |
| 91 | 119 | // } |
| 92 | 120 | // |
| 93 | -// /** | |
| 94 | -// * 根据用户编号获取详细信息 | |
| 95 | -// */ | |
| 96 | -// @PreAuthorize("@ss.hasPermi('system:user:query')") | |
| 97 | -// @GetMapping(value = { "/", "/{userId}" }) | |
| 98 | -// public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) | |
| 99 | -// { | |
| 100 | -// AjaxResult ajax = AjaxResult.success(); | |
| 101 | -// List<SysRole> roles = roleService.selectRoleAll(); | |
| 102 | -// ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); | |
| 103 | -// ajax.put("posts", postService.selectPostAll()); | |
| 104 | -// if (StringUtils.isNotNull(userId)) | |
| 105 | -// { | |
| 106 | -// ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId)); | |
| 107 | -// ajax.put("postIds", postService.selectPostListByUserId(userId)); | |
| 108 | -// ajax.put("roleIds", roleService.selectRoleListByUserId(userId)); | |
| 109 | -// } | |
| 110 | -// return ajax; | |
| 111 | -// } | |
| 112 | -// | |
| 113 | -// /** | |
| 114 | -// * 新增用户 | |
| 115 | -// */ | |
| 116 | -// @PreAuthorize("@ss.hasPermi('system:user:add')") | |
| 117 | -// @Log(title = "用户管理", businessType = BusinessType.INSERT) | |
| 118 | -// @PostMapping | |
| 119 | -// public AjaxResult add(@Validated @RequestBody SysUser user) | |
| 120 | -// { | |
| 121 | -// if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) | |
| 122 | -// { | |
| 123 | -// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); | |
| 124 | -// } | |
| 125 | -// else if (StringUtils.isNotEmpty(user.getPhonenumber()) | |
| 126 | -// && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) | |
| 127 | -// { | |
| 128 | -// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); | |
| 129 | -// } | |
| 130 | -// else if (StringUtils.isNotEmpty(user.getEmail()) | |
| 131 | -// && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) | |
| 132 | -// { | |
| 133 | -// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | |
| 134 | -// } | |
| 135 | -// user.setCreateBy(SecurityUtils.getUsername()); | |
| 136 | -// user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | |
| 137 | -// return toAjax(userService.insertUser(user)); | |
| 138 | -// } | |
| 139 | -// | |
| 140 | -// /** | |
| 141 | -// * 修改用户 | |
| 142 | -// */ | |
| 143 | -// @PreAuthorize("@ss.hasPermi('system:user:edit')") | |
| 144 | -// @Log(title = "用户管理", businessType = BusinessType.UPDATE) | |
| 145 | -// @PutMapping | |
| 146 | -// public AjaxResult edit(@Validated @RequestBody SysUser user) | |
| 147 | -// { | |
| 148 | -// userService.checkUserAllowed(user); | |
| 149 | -// if (StringUtils.isNotEmpty(user.getPhonenumber()) | |
| 150 | -// && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) | |
| 151 | -// { | |
| 152 | -// return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); | |
| 153 | -// } | |
| 154 | -// else if (StringUtils.isNotEmpty(user.getEmail()) | |
| 155 | -// && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) | |
| 156 | -// { | |
| 157 | -// return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); | |
| 158 | -// } | |
| 159 | -// user.setUpdateBy(SecurityUtils.getUsername()); | |
| 160 | -// return toAjax(userService.updateUser(user)); | |
| 161 | -// } | |
| 162 | -// | |
| 121 | + | |
| 122 | + | |
| 163 | 123 | // /** |
| 164 | 124 | // * 删除用户 |
| 165 | 125 | // */ | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserCreateReqVO.java
| ... | ... | @@ -2,11 +2,21 @@ package cn.iocoder.dashboard.modules.system.controller.user.vo.user; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | import io.swagger.annotations.ApiModel; |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | 6 | import lombok.Data; |
| 6 | 7 | import lombok.EqualsAndHashCode; |
| 8 | +import org.hibernate.validator.constraints.Length; | |
| 9 | + | |
| 10 | +import javax.validation.constraints.NotEmpty; | |
| 7 | 11 | |
| 8 | 12 | @ApiModel("用户创建 Request VO") |
| 9 | 13 | @Data |
| 10 | 14 | @EqualsAndHashCode(callSuper = true) |
| 11 | 15 | public class SysUserCreateReqVO extends SysUserBaseVO { |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "密码", required = true, example = "123456") | |
| 18 | + @NotEmpty(message = "密码不能为空") | |
| 19 | + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 20 | + private String password; | |
| 21 | + | |
| 12 | 22 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/convert/dept/SysPostConvert.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.convert.dept; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostSimpleRespVO; | |
| 4 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 5 | +import org.mapstruct.Mapper; | |
| 6 | +import org.mapstruct.factory.Mappers; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +@Mapper | |
| 11 | +public interface SysPostConvert { | |
| 12 | + | |
| 13 | + SysPostConvert INSTANCE = Mappers.getMapper(SysPostConvert.class); | |
| 14 | + | |
| 15 | + List<SysPostSimpleRespVO> convertList02(List<SysPostDO> list); | |
| 16 | + | |
| 17 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/convert/user/SysUserConvert.java
| 1 | 1 | package cn.iocoder.dashboard.modules.system.convert.user; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO; | |
| 4 | 5 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageItemRespVO; |
| 6 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; | |
| 5 | 7 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; |
| 6 | 8 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; |
| 7 | 9 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| ... | ... | @@ -21,4 +23,8 @@ public interface SysUserConvert { |
| 21 | 23 | @Mapping(source = "records", target = "list") |
| 22 | 24 | PageResult<SysUserDO> convertPage(IPage<SysUserDO> page); |
| 23 | 25 | |
| 26 | + SysUserDO convert(SysUserCreateReqVO bean); | |
| 27 | + | |
| 28 | + SysUserDO convert(SysUserUpdateReqVO bean); | |
| 29 | + | |
| 24 | 30 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dept/SysPostMapper.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; | |
| 4 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 5 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
| 6 | +import org.apache.ibatis.annotations.Mapper; | |
| 7 | + | |
| 8 | +import java.util.Collection; | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +@Mapper | |
| 12 | +public interface SysPostMapper extends BaseMapper<SysPostDO> { | |
| 13 | + | |
| 14 | + default List<SysPostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) { | |
| 15 | + return selectList(new QueryWrapperX<SysPostDO>().inIfPresent("id", ids) | |
| 16 | + .inIfPresent("status", statuses)); | |
| 17 | + } | |
| 18 | + | |
| 19 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/user/SysUserMapper.java
| ... | ... | @@ -18,6 +18,14 @@ public interface SysUserMapper extends BaseMapper<SysUserDO> { |
| 18 | 18 | return selectOne(new QueryWrapper<SysUserDO>().eq("username", username)); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | + default SysUserDO selectByMobile(String mobile) { | |
| 22 | + return selectOne(new QueryWrapper<SysUserDO>().eq("mobile", mobile)); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default SysUserDO selectByEmail(String email) { | |
| 26 | + return selectOne(new QueryWrapper<SysUserDO>().eq("email", email)); | |
| 27 | + } | |
| 28 | + | |
| 21 | 29 | default IPage<SysUserDO> selectList(SysUserPageReqVO reqVO, List<Long> deptIds) { |
| 22 | 30 | return selectPage(MyBatisUtils.buildPage(reqVO), |
| 23 | 31 | new QueryWrapperX<SysUserDO>().likeIfPresent("username", reqVO.getUsername()) | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dept/SysPostDO.java
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/user/SysUserDO.java
src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java
| ... | ... | @@ -32,4 +32,23 @@ public interface SysErrorCodeConstants { |
| 32 | 32 | ErrorCode ROLE_CODE_DUPLICATE = new ErrorCode(1002003002, "已经存在编码为【{}}】的角色"); |
| 33 | 33 | ErrorCode ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003004, "不能操作类型为系统内置的角色"); |
| 34 | 34 | |
| 35 | + // ========== 用户模块 1002004000 ========== | |
| 36 | + ErrorCode USER_USERNAME_EXISTS = new ErrorCode(1002004000, "用户账号已经存在"); | |
| 37 | + ErrorCode USER_MOBILE_EXISTS = new ErrorCode(1002004001, "手机号已经存在"); | |
| 38 | + ErrorCode USER_EMAIL_EXISTS = new ErrorCode(1002004002, "邮箱已经存在"); | |
| 39 | + ErrorCode USER_NOT_EXISTS = new ErrorCode(1002004003, "用户不存在"); | |
| 40 | + | |
| 41 | + // ========== 部门模块 1002005000 ========== | |
| 42 | + ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1002004001, "已经存在该名字的部门"); | |
| 43 | + ErrorCode DEPT_PARENT_NOT_EXITS = new ErrorCode(1002004002,"父级部门不存在"); | |
| 44 | + ErrorCode DEPT_NOT_FOUND = new ErrorCode(1002004003, "当前部门不存在"); | |
| 45 | + ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004004, "存在子部门,无法删除"); | |
| 46 | + ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004005, "不能设置自己为父资源"); | |
| 47 | + ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004006, "部门中存在员工,无法删除"); | |
| 48 | + ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004007, "部门不处于开启状态,不允许选择"); | |
| 49 | + | |
| 50 | + // ========== 岗位模块 1002005000 ========== | |
| 51 | + ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在"); | |
| 52 | + ErrorCode POST_NOT_ENABLE = new ErrorCode(1002005002, "岗位({}) 不处于开启状态,不允许选择"); | |
| 53 | + | |
| 35 | 54 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptService.java
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysPostService.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.service.dept; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 4 | + | |
| 5 | +import javax.annotation.Nullable; | |
| 6 | +import java.util.Collection; | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 岗位 Service 接口 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +public interface SysPostService { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 获得所有岗位列表 | |
| 18 | + * | |
| 19 | + * @param ids 岗位编号数组。如果为空,不进行筛选 | |
| 20 | + * @param statuses 状态数组。如果为空,不进行筛选 | |
| 21 | + * @return 部门列表 | |
| 22 | + */ | |
| 23 | + List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); | |
| 24 | + | |
| 25 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysPostServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.service.dept.impl; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept.SysPostMapper; | |
| 4 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 5 | +import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; | |
| 6 | +import org.springframework.stereotype.Service; | |
| 7 | + | |
| 8 | +import javax.annotation.Resource; | |
| 9 | +import java.util.Collection; | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 岗位 Service 实现类 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Service | |
| 18 | +public class SysPostServiceImpl implements SysPostService { | |
| 19 | + | |
| 20 | + @Resource | |
| 21 | + private SysPostMapper postMapper; | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + public List<SysPostDO> listPosts(Collection<Long> ids, Collection<Integer> statuses) { | |
| 25 | + return postMapper.selectList(ids, statuses); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java
| ... | ... | @@ -170,55 +170,6 @@ public class SysMenuServiceImpl implements SysMenuService { |
| 170 | 170 | return menuMapper.selectById(id); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | -// /** | |
| 174 | -// * 获得菜单列表 | |
| 175 | -// * | |
| 176 | -// * @param menuIds 菜单编号列表 | |
| 177 | -// * @return 菜单列表 | |
| 178 | -// */ | |
| 179 | -// public List<ResourceBO> listResources(List<Integer> menuIds) { | |
| 180 | -// List<ResourceDO> menuDOs = menuMapper.selectBatchIds(menuIds); | |
| 181 | -// return ResourceConvert.INSTANCE.convertList(menuDOs); | |
| 182 | -// } | |
| 183 | -// | |
| 184 | -// /** | |
| 185 | -// * 获得菜单全列表 | |
| 186 | -// * | |
| 187 | -// * @return 菜单全列表 | |
| 188 | -// */ | |
| 189 | -// public List<ResourceBO> listResources() { | |
| 190 | -// List<ResourceDO> menuDOs = menuMapper.selectList(null); | |
| 191 | -// return ResourceConvert.INSTANCE.convertList(menuDOs); | |
| 192 | -// } | |
| 193 | -// | |
| 194 | -// /** | |
| 195 | -// * 获得指定类型的菜单列表 | |
| 196 | -// * | |
| 197 | -// * @param type 菜单类型,允许空 | |
| 198 | -// * @return 菜单列表 | |
| 199 | -// */ | |
| 200 | -// public List<ResourceBO> listResourcesByType(Integer type) { | |
| 201 | -// List<ResourceDO> menuDOs = menuMapper.selectListByType(type); | |
| 202 | -// return ResourceConvert.INSTANCE.convertList(menuDOs); | |
| 203 | -// } | |
| 204 | -// | |
| 205 | -// /** | |
| 206 | -// * 获得角色拥有的菜单列表 | |
| 207 | -// * | |
| 208 | -// * @param roleIds 角色编号 | |
| 209 | -// * @param type 菜单类型,允许空 | |
| 210 | -// * @return 菜单列表 | |
| 211 | -// */ | |
| 212 | -// public List<ResourceBO> listRoleResourcesByType(Collection<Integer> roleIds, Integer type) { | |
| 213 | -// List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); | |
| 214 | -// if (CollectionUtils.isEmpty(roleResourceDOs)) { | |
| 215 | -// return Collections.emptyList(); | |
| 216 | -// } | |
| 217 | -// List<ResourceDO> menuDOs = menuMapper.selectListByIdsAndType( | |
| 218 | -// CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId), type); | |
| 219 | -// return ResourceConvert.INSTANCE.convertList(menuDOs); | |
| 220 | -// } | |
| 221 | -// | |
| 222 | 173 | /** |
| 223 | 174 | * 校验父菜单是否合法 |
| 224 | 175 | * |
| ... | ... | @@ -263,7 +214,7 @@ public class SysMenuServiceImpl implements SysMenuService { |
| 263 | 214 | if (menu == null) { |
| 264 | 215 | return; |
| 265 | 216 | } |
| 266 | - // 如果 menuId 为空,说明不用比较是否为相同 menuId 的菜单 | |
| 217 | + // 如果 id 为空,说明不用比较是否为相同 id 的菜单 | |
| 267 | 218 | if (id == null) { |
| 268 | 219 | throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE); |
| 269 | 220 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java
| 1 | 1 | package cn.iocoder.dashboard.modules.system.service.user; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO; | |
| 4 | 5 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO; |
| 6 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; | |
| 5 | 7 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; |
| 6 | 8 | |
| 7 | 9 | /** |
| ... | ... | @@ -29,10 +31,10 @@ public interface SysUserService { |
| 29 | 31 | /** |
| 30 | 32 | * 通过用户 ID 查询用户 |
| 31 | 33 | * |
| 32 | - * @param userId 用户ID | |
| 34 | + * @param id 用户ID | |
| 33 | 35 | * @return 用户对象信息 |
| 34 | 36 | */ |
| 35 | - SysUserDO getUser(Long userId); | |
| 37 | + SysUserDO getUser(Long id); | |
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * 获得用户分页列表 |
| ... | ... | @@ -42,6 +44,21 @@ public interface SysUserService { |
| 42 | 44 | */ |
| 43 | 45 | PageResult<SysUserDO> pageUsers(SysUserPageReqVO reqVO); |
| 44 | 46 | |
| 47 | + /** | |
| 48 | + * 创建用户 | |
| 49 | + * | |
| 50 | + * @param reqVO 用户信息 | |
| 51 | + * @return 用户编号 | |
| 52 | + */ | |
| 53 | + Long createUser(SysUserCreateReqVO reqVO); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * 修改用户 | |
| 57 | + * | |
| 58 | + * @param reqVO 用户信息 | |
| 59 | + */ | |
| 60 | + void updateUser(SysUserUpdateReqVO reqVO); | |
| 61 | + | |
| 45 | 62 | // |
| 46 | 63 | // /** |
| 47 | 64 | // * 根据用户ID查询用户所属角色组 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java
| 1 | 1 | package cn.iocoder.dashboard.modules.system.service.user; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.iocoder.dashboard.common.enums.CommonStatusEnum; | |
| 6 | +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | |
| 3 | 7 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 8 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO; | |
| 4 | 9 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO; |
| 10 | +import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; | |
| 5 | 11 | import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert; |
| 6 | 12 | import cn.iocoder.dashboard.modules.system.dal.mysql.dao.user.SysUserMapper; |
| 7 | 13 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO; |
| 14 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; | |
| 8 | 15 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; |
| 9 | 16 | import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; |
| 17 | +import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; | |
| 10 | 18 | import cn.iocoder.dashboard.util.collection.CollectionUtils; |
| 11 | 19 | import lombok.extern.slf4j.Slf4j; |
| 20 | +import org.springframework.security.crypto.password.PasswordEncoder; | |
| 12 | 21 | import org.springframework.stereotype.Service; |
| 13 | 22 | |
| 14 | 23 | import javax.annotation.Resource; |
| 15 | 24 | import java.util.Collections; |
| 16 | 25 | import java.util.List; |
| 26 | +import java.util.Map; | |
| 27 | +import java.util.Set; | |
| 28 | + | |
| 29 | +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; | |
| 17 | 30 | |
| 18 | 31 | |
| 19 | 32 | /** |
| ... | ... | @@ -30,16 +43,12 @@ public class SysUserServiceImpl implements SysUserService { |
| 30 | 43 | |
| 31 | 44 | @Resource |
| 32 | 45 | private SysDeptService deptService; |
| 46 | + @Resource | |
| 47 | + private SysPostService postService; | |
| 48 | + | |
| 49 | + @Resource | |
| 50 | + private PasswordEncoder passwordEncoder; | |
| 33 | 51 | |
| 34 | -// @Autowired | |
| 35 | -// private SysUserMapper userMapper; | |
| 36 | -// | |
| 37 | -// @Autowired | |
| 38 | -// private SysRoleMapper roleMapper; | |
| 39 | -// | |
| 40 | -// @Autowired | |
| 41 | -// private SysPostMapper postMapper; | |
| 42 | -// | |
| 43 | 52 | // @Autowired |
| 44 | 53 | // private SysUserRoleMapper userRoleMapper; |
| 45 | 54 | // |
| ... | ... | @@ -68,8 +77,8 @@ public class SysUserServiceImpl implements SysUserService { |
| 68 | 77 | } |
| 69 | 78 | |
| 70 | 79 | @Override |
| 71 | - public SysUserDO getUser(Long userId) { | |
| 72 | - return userMapper.selectById(userId); | |
| 80 | + public SysUserDO getUser(Long id) { | |
| 81 | + return userMapper.selectById(id); | |
| 73 | 82 | } |
| 74 | 83 | |
| 75 | 84 | @Override |
| ... | ... | @@ -77,240 +86,148 @@ public class SysUserServiceImpl implements SysUserService { |
| 77 | 86 | // 处理部门查询条件 |
| 78 | 87 | List<Long> deptIds = Collections.emptyList(); |
| 79 | 88 | if (reqVO.getDeptId() != null) { |
| 80 | - deptIds = CollectionUtils.convertList(deptService.listDeptsByParentIdFromCache(reqVO.getDeptId(), true), | |
| 81 | - SysDeptDO::getId); | |
| 89 | + deptIds = CollectionUtils.convertList(deptService.listDeptsByParentIdFromCache( | |
| 90 | + reqVO.getDeptId(), true), SysDeptDO::getId); | |
| 82 | 91 | deptIds.add(reqVO.getDeptId()); |
| 83 | 92 | } |
| 84 | 93 | // 执行查询 |
| 85 | 94 | return SysUserConvert.INSTANCE.convertPage(userMapper.selectList(reqVO, deptIds)); |
| 86 | 95 | } |
| 87 | 96 | |
| 88 | -// /** | |
| 89 | -// * 通过用户ID查询用户 | |
| 90 | -// * | |
| 91 | -// * @param userId 用户ID | |
| 92 | -// * @return 用户对象信息 | |
| 93 | -// */ | |
| 94 | -// @Override | |
| 95 | -// public SysUser selectUserById(Long userId) | |
| 96 | -// { | |
| 97 | -// return userMapper.selectUserById(userId); | |
| 98 | -// } | |
| 99 | -// | |
| 100 | -// /** | |
| 101 | -// * 查询用户所属角色组 | |
| 102 | -// * | |
| 103 | -// * @param userName 用户名 | |
| 104 | -// * @return 结果 | |
| 105 | -// */ | |
| 106 | -// @Override | |
| 107 | -// public String selectUserRoleGroup(String userName) | |
| 108 | -// { | |
| 109 | -// List<SysRole> list = roleMapper.selectRolesByUserName(userName); | |
| 110 | -// StringBuffer idsStr = new StringBuffer(); | |
| 111 | -// for (SysRole role : list) | |
| 112 | -// { | |
| 113 | -// idsStr.append(role.getRoleName()).append(","); | |
| 114 | -// } | |
| 115 | -// if (StringUtils.isNotEmpty(idsStr.toString())) | |
| 116 | -// { | |
| 117 | -// return idsStr.substring(0, idsStr.length() - 1); | |
| 118 | -// } | |
| 119 | -// return idsStr.toString(); | |
| 120 | -// } | |
| 121 | -// | |
| 122 | -// /** | |
| 123 | -// * 查询用户所属岗位组 | |
| 124 | -// * | |
| 125 | -// * @param userName 用户名 | |
| 126 | -// * @return 结果 | |
| 127 | -// */ | |
| 128 | -// @Override | |
| 129 | -// public String selectUserPostGroup(String userName) | |
| 130 | -// { | |
| 131 | -// List<SysPost> list = postMapper.selectPostsByUserName(userName); | |
| 132 | -// StringBuffer idsStr = new StringBuffer(); | |
| 133 | -// for (SysPost post : list) | |
| 134 | -// { | |
| 135 | -// idsStr.append(post.getPostName()).append(","); | |
| 136 | -// } | |
| 137 | -// if (StringUtils.isNotEmpty(idsStr.toString())) | |
| 138 | -// { | |
| 139 | -// return idsStr.substring(0, idsStr.length() - 1); | |
| 140 | -// } | |
| 141 | -// return idsStr.toString(); | |
| 142 | -// } | |
| 143 | -// | |
| 144 | -// /** | |
| 145 | -// * 校验用户名称是否唯一 | |
| 146 | -// * | |
| 147 | -// * @param userName 用户名称 | |
| 148 | -// * @return 结果 | |
| 149 | -// */ | |
| 150 | -// @Override | |
| 151 | -// public String checkUserNameUnique(String userName) | |
| 152 | -// { | |
| 153 | -// int count = userMapper.checkUserNameUnique(userName); | |
| 154 | -// if (count > 0) | |
| 155 | -// { | |
| 156 | -// return UserConstants.NOT_UNIQUE; | |
| 157 | -// } | |
| 158 | -// return UserConstants.UNIQUE; | |
| 159 | -// } | |
| 160 | -// | |
| 161 | -// /** | |
| 162 | -// * 校验用户名称是否唯一 | |
| 163 | -// * | |
| 164 | -// * @param user 用户信息 | |
| 165 | -// * @return | |
| 166 | -// */ | |
| 167 | -// @Override | |
| 168 | -// public String checkPhoneUnique(SysUser user) | |
| 169 | -// { | |
| 170 | -// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); | |
| 171 | -// SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber()); | |
| 172 | -// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) | |
| 173 | -// { | |
| 174 | -// return UserConstants.NOT_UNIQUE; | |
| 175 | -// } | |
| 176 | -// return UserConstants.UNIQUE; | |
| 177 | -// } | |
| 178 | -// | |
| 179 | -// /** | |
| 180 | -// * 校验email是否唯一 | |
| 181 | -// * | |
| 182 | -// * @param user 用户信息 | |
| 183 | -// * @return | |
| 184 | -// */ | |
| 185 | -// @Override | |
| 186 | -// public String checkEmailUnique(SysUser user) | |
| 187 | -// { | |
| 188 | -// Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); | |
| 189 | -// SysUser info = userMapper.checkEmailUnique(user.getEmail()); | |
| 190 | -// if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) | |
| 191 | -// { | |
| 192 | -// return UserConstants.NOT_UNIQUE; | |
| 193 | -// } | |
| 194 | -// return UserConstants.UNIQUE; | |
| 195 | -// } | |
| 196 | -// | |
| 197 | -// /** | |
| 198 | -// * 校验用户是否允许操作 | |
| 199 | -// * | |
| 200 | -// * @param user 用户信息 | |
| 201 | -// */ | |
| 202 | -// @Override | |
| 203 | -// public void checkUserAllowed(SysUser user) | |
| 204 | -// { | |
| 205 | -// if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) | |
| 206 | -// { | |
| 207 | -// throw new CustomException("不允许操作超级管理员用户"); | |
| 208 | -// } | |
| 209 | -// } | |
| 210 | -// | |
| 211 | -// /** | |
| 212 | -// * 新增保存用户信息 | |
| 213 | -// * | |
| 214 | -// * @param user 用户信息 | |
| 215 | -// * @return 结果 | |
| 216 | -// */ | |
| 217 | -// @Override | |
| 218 | -// @Transactional | |
| 219 | -// public int insertUser(SysUser user) | |
| 220 | -// { | |
| 221 | -// // 新增用户信息 | |
| 222 | -// int rows = userMapper.insertUser(user); | |
| 223 | -// // 新增用户岗位关联 | |
| 224 | -// insertUserPost(user); | |
| 225 | -// // 新增用户与角色管理 | |
| 226 | -// insertUserRole(user); | |
| 227 | -// return rows; | |
| 228 | -// } | |
| 229 | -// | |
| 230 | -// /** | |
| 231 | -// * 修改保存用户信息 | |
| 232 | -// * | |
| 233 | -// * @param user 用户信息 | |
| 234 | -// * @return 结果 | |
| 235 | -// */ | |
| 236 | -// @Override | |
| 237 | -// @Transactional | |
| 238 | -// public int updateUser(SysUser user) | |
| 239 | -// { | |
| 240 | -// Long userId = user.getUserId(); | |
| 241 | -// // 删除用户与角色关联 | |
| 242 | -// userRoleMapper.deleteUserRoleByUserId(userId); | |
| 243 | -// // 新增用户与角色管理 | |
| 244 | -// insertUserRole(user); | |
| 245 | -// // 删除用户与岗位关联 | |
| 246 | -// userPostMapper.deleteUserPostByUserId(userId); | |
| 247 | -// // 新增用户与岗位管理 | |
| 248 | -// insertUserPost(user); | |
| 249 | -// return userMapper.updateUser(user); | |
| 250 | -// } | |
| 251 | -// | |
| 252 | -// /** | |
| 253 | -// * 修改用户状态 | |
| 254 | -// * | |
| 255 | -// * @param user 用户信息 | |
| 256 | -// * @return 结果 | |
| 257 | -// */ | |
| 258 | -// @Override | |
| 259 | -// public int updateUserStatus(SysUser user) | |
| 260 | -// { | |
| 261 | -// return userMapper.updateUser(user); | |
| 262 | -// } | |
| 263 | -// | |
| 264 | -// /** | |
| 265 | -// * 修改用户基本信息 | |
| 266 | -// * | |
| 267 | -// * @param user 用户信息 | |
| 268 | -// * @return 结果 | |
| 269 | -// */ | |
| 270 | -// @Override | |
| 271 | -// public int updateUserProfile(SysUser user) | |
| 272 | -// { | |
| 273 | -// return userMapper.updateUser(user); | |
| 274 | -// } | |
| 275 | -// | |
| 276 | -// /** | |
| 277 | -// * 修改用户头像 | |
| 278 | -// * | |
| 279 | -// * @param userName 用户名 | |
| 280 | -// * @param avatar 头像地址 | |
| 281 | -// * @return 结果 | |
| 282 | -// */ | |
| 283 | -// @Override | |
| 284 | -// public boolean updateUserAvatar(String userName, String avatar) | |
| 285 | -// { | |
| 286 | -// return userMapper.updateUserAvatar(userName, avatar) > 0; | |
| 287 | -// } | |
| 288 | -// | |
| 289 | -// /** | |
| 290 | -// * 重置用户密码 | |
| 291 | -// * | |
| 292 | -// * @param user 用户信息 | |
| 293 | -// * @return 结果 | |
| 294 | -// */ | |
| 295 | -// @Override | |
| 296 | -// public int resetPwd(SysUser user) | |
| 297 | -// { | |
| 298 | -// return userMapper.updateUser(user); | |
| 299 | -// } | |
| 300 | -// | |
| 301 | -// /** | |
| 302 | -// * 重置用户密码 | |
| 303 | -// * | |
| 304 | -// * @param userName 用户名 | |
| 305 | -// * @param password 密码 | |
| 306 | -// * @return 结果 | |
| 307 | -// */ | |
| 308 | -// @Override | |
| 309 | -// public int resetUserPwd(String userName, String password) | |
| 310 | -// { | |
| 311 | -// return userMapper.resetUserPwd(userName, password); | |
| 312 | -// } | |
| 313 | -// | |
| 97 | + @Override | |
| 98 | + public Long createUser(SysUserCreateReqVO reqVO) { | |
| 99 | + // 校验正确性 | |
| 100 | + this.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 101 | + reqVO.getDeptId(), reqVO.getPostIds()); | |
| 102 | + // 插入用户 | |
| 103 | + SysUserDO user = SysUserConvert.INSTANCE.convert(reqVO); | |
| 104 | + user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 | |
| 105 | + user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码 | |
| 106 | + userMapper.insert(user); | |
| 107 | + return user.getId(); | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public void updateUser(SysUserUpdateReqVO reqVO) { | |
| 112 | + // 校验正确性 | |
| 113 | + this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 114 | + reqVO.getDeptId(), reqVO.getPostIds()); | |
| 115 | + // 更新用户 | |
| 116 | + SysUserDO updateObj = SysUserConvert.INSTANCE.convert(reqVO); | |
| 117 | + userMapper.updateById(updateObj); | |
| 118 | + } | |
| 119 | + | |
| 120 | + private void checkCreateOrUpdate(Long id, String username, String mobile, String email, | |
| 121 | + Long deptId, Set<Long> postIds) { | |
| 122 | + // 校验用户存在 | |
| 123 | + this.checkUserExists(id); | |
| 124 | + // 校验用户名唯一 | |
| 125 | + this.checkUsernameUnique(id, username); | |
| 126 | + // 校验手机号唯一 | |
| 127 | + this.checkMobileUnique(id, mobile); | |
| 128 | + // 校验邮箱唯一 | |
| 129 | + this.checkEmailUnique(id, email); | |
| 130 | + // 校验部门处于开启状态 | |
| 131 | + this.checkDeptEnable(deptId); | |
| 132 | + // 校验岗位处于开启状态 | |
| 133 | + this.checkPostEnable(postIds); | |
| 134 | + } | |
| 135 | + | |
| 136 | + private void checkUserExists(Long id) { | |
| 137 | + if (id == null) { | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + SysUserDO user = userMapper.selectById(id); | |
| 141 | + if (user == null) { | |
| 142 | + throw ServiceExceptionUtil.exception(USER_NOT_EXISTS); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + private void checkUsernameUnique(Long id, String username) { | |
| 147 | + if (StrUtil.isNotBlank(username)) { | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + SysUserDO user = userMapper.selectByUsername(username); | |
| 151 | + if (user == null) { | |
| 152 | + return; | |
| 153 | + } | |
| 154 | + // 如果 id 为空,说明不用比较是否为相同 id 的用户 | |
| 155 | + if (id == null) { | |
| 156 | + throw ServiceExceptionUtil.exception(USER_USERNAME_EXISTS); | |
| 157 | + } | |
| 158 | + if (!user.getId().equals(id)) { | |
| 159 | + throw ServiceExceptionUtil.exception(USER_USERNAME_EXISTS); | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + private void checkEmailUnique(Long id, String email) { | |
| 164 | + if (StrUtil.isNotBlank(email)) { | |
| 165 | + return; | |
| 166 | + } | |
| 167 | + SysUserDO user = userMapper.selectByEmail(email); | |
| 168 | + if (user == null) { | |
| 169 | + return; | |
| 170 | + } | |
| 171 | + // 如果 id 为空,说明不用比较是否为相同 id 的用户 | |
| 172 | + if (id == null) { | |
| 173 | + throw ServiceExceptionUtil.exception(USER_EMAIL_EXISTS); | |
| 174 | + } | |
| 175 | + if (!user.getId().equals(id)) { | |
| 176 | + throw ServiceExceptionUtil.exception(USER_EMAIL_EXISTS); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + private void checkMobileUnique(Long id, String email) { | |
| 181 | + if (StrUtil.isNotBlank(email)) { | |
| 182 | + return; | |
| 183 | + } | |
| 184 | + SysUserDO user = userMapper.selectByMobile(email); | |
| 185 | + if (user == null) { | |
| 186 | + return; | |
| 187 | + } | |
| 188 | + // 如果 id 为空,说明不用比较是否为相同 id 的用户 | |
| 189 | + if (id == null) { | |
| 190 | + throw ServiceExceptionUtil.exception(USER_MOBILE_EXISTS); | |
| 191 | + } | |
| 192 | + if (!user.getId().equals(id)) { | |
| 193 | + throw ServiceExceptionUtil.exception(USER_MOBILE_EXISTS); | |
| 194 | + } | |
| 195 | + } | |
| 196 | + | |
| 197 | + private void checkDeptEnable(Long deptId) { | |
| 198 | + if (deptId == null) { // 允许不选择 | |
| 199 | + return; | |
| 200 | + } | |
| 201 | + SysDeptDO dept = deptService.getDept(deptId); | |
| 202 | + if (dept == null) { | |
| 203 | + throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND); | |
| 204 | + } | |
| 205 | + if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) { | |
| 206 | + throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 210 | + private void checkPostEnable(Set<Long> postIds) { | |
| 211 | + if (CollUtil.isEmpty(postIds)) { // 允许不选择 | |
| 212 | + return; | |
| 213 | + } | |
| 214 | + List<SysPostDO> posts = postService.listPosts(postIds, null); | |
| 215 | + if (CollUtil.isEmpty(posts)) { | |
| 216 | + throw ServiceExceptionUtil.exception(POST_NOT_FOUND); | |
| 217 | + } | |
| 218 | + Map<Long, SysPostDO> postMap = CollectionUtils.convertMap(posts, SysPostDO::getId); | |
| 219 | + postIds.forEach(postId -> { | |
| 220 | + SysPostDO post = postMap.get(postId); | |
| 221 | + if (post == null) { | |
| 222 | + throw ServiceExceptionUtil.exception(POST_NOT_FOUND); | |
| 223 | + } | |
| 224 | + if (!CommonStatusEnum.ENABLE.getStatus().equals(post.getStatus())) { | |
| 225 | + throw ServiceExceptionUtil.exception(POST_NOT_ENABLE, post.getName()); | |
| 226 | + } | |
| 227 | + }); | |
| 228 | + } | |
| 229 | + | |
| 230 | + | |
| 314 | 231 | // /** |
| 315 | 232 | // * 新增用户角色信息 |
| 316 | 233 | // * |
| ... | ... | @@ -379,28 +296,8 @@ public class SysUserServiceImpl implements SysUserService { |
| 379 | 296 | // userPostMapper.deleteUserPostByUserId(userId); |
| 380 | 297 | // return userMapper.deleteUserById(userId); |
| 381 | 298 | // } |
| 382 | -// | |
| 383 | -// /** | |
| 384 | -// * 批量删除用户信息 | |
| 385 | -// * | |
| 386 | -// * @param userIds 需要删除的用户ID | |
| 387 | -// * @return 结果 | |
| 388 | -// */ | |
| 389 | -// @Override | |
| 390 | -// @Transactional | |
| 391 | -// public int deleteUserByIds(Long[] userIds) | |
| 392 | -// { | |
| 393 | -// for (Long userId : userIds) | |
| 394 | -// { | |
| 395 | -// checkUserAllowed(new SysUser(userId)); | |
| 396 | -// } | |
| 397 | -// // 删除用户与角色关联 | |
| 398 | -// userRoleMapper.deleteUserRole(userIds); | |
| 399 | -// // 删除用户与岗位关联 | |
| 400 | -// userPostMapper.deleteUserPost(userIds); | |
| 401 | -// return userMapper.deleteUserByIds(userIds); | |
| 402 | -// } | |
| 403 | -// | |
| 299 | + | |
| 300 | + | |
| 404 | 301 | // /** |
| 405 | 302 | // * 导入用户数据 |
| 406 | 303 | // * | ... | ... |