Commit 78e847a81adb0a267f4fc94e1522d08f1b6aa78f
1 parent
472ff81d
整理 dept、post 模块的 url 地址
Showing
17 changed files
with
256 additions
and
339 deletions
ruoyi-ui/src/api/system/dept.js
| ... | ... | @@ -46,7 +46,7 @@ export function addDept(data) { |
| 46 | 46 | export function updateDept(data) { |
| 47 | 47 | return request({ |
| 48 | 48 | url: '/system/dept/update', |
| 49 | - method: 'post', | |
| 49 | + method: 'put', | |
| 50 | 50 | data: data |
| 51 | 51 | }) |
| 52 | 52 | } |
| ... | ... | @@ -55,6 +55,6 @@ export function updateDept(data) { |
| 55 | 55 | export function delDept(id) { |
| 56 | 56 | return request({ |
| 57 | 57 | url: '/system/dept/delete?id=' + id, |
| 58 | - method: 'post' | |
| 58 | + method: 'delete' | |
| 59 | 59 | }) |
| 60 | 60 | } | ... | ... |
ruoyi-ui/src/api/system/post.js
| ... | ... | @@ -38,7 +38,7 @@ export function addPost(data) { |
| 38 | 38 | export function updatePost(data) { |
| 39 | 39 | return request({ |
| 40 | 40 | url: '/system/post/update', |
| 41 | - method: 'post', | |
| 41 | + method: 'put', | |
| 42 | 42 | data: data |
| 43 | 43 | }) |
| 44 | 44 | } |
| ... | ... | @@ -47,7 +47,7 @@ export function updatePost(data) { |
| 47 | 47 | export function delPost(postId) { |
| 48 | 48 | return request({ |
| 49 | 49 | url: '/system/post/delete?id=' + postId, |
| 50 | - method: 'post' | |
| 50 | + method: 'delete' | |
| 51 | 51 | }) |
| 52 | 52 | } |
| 53 | 53 | ... | ... |
ruoyi-ui/src/views/system/dept/index.vue
| ... | ... | @@ -2,22 +2,11 @@ |
| 2 | 2 | <div class="app-container"> |
| 3 | 3 | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"> |
| 4 | 4 | <el-form-item label="部门名称" prop="name"> |
| 5 | - <el-input | |
| 6 | - v-model="queryParams.name" | |
| 7 | - placeholder="请输入部门名称" | |
| 8 | - clearable | |
| 9 | - size="small" | |
| 10 | - @keyup.enter.native="handleQuery" | |
| 11 | - /> | |
| 5 | + <el-input v-model="queryParams.name" placeholder="请输入部门名称" clearable size="small" @keyup.enter.native="handleQuery"/> | |
| 12 | 6 | </el-form-item> |
| 13 | 7 | <el-form-item label="状态" prop="status"> |
| 14 | 8 | <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small"> |
| 15 | - <el-option | |
| 16 | - v-for="dict in statusDictDatas" | |
| 17 | - :key="parseInt(dict.value)" | |
| 18 | - :label="dict.label" | |
| 19 | - :value="parseInt(dict.value)" | |
| 20 | - /> | |
| 9 | + <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/> | |
| 21 | 10 | </el-select> |
| 22 | 11 | </el-form-item> |
| 23 | 12 | <el-form-item> |
| ... | ... | @@ -28,24 +17,13 @@ |
| 28 | 17 | |
| 29 | 18 | <el-row :gutter="10" class="mb8"> |
| 30 | 19 | <el-col :span="1.5"> |
| 31 | - <el-button | |
| 32 | - type="primary" | |
| 33 | - icon="el-icon-plus" | |
| 34 | - size="mini" | |
| 35 | - @click="handleAdd" | |
| 36 | - v-hasPermi="['system:dept:add']" | |
| 37 | - >新增</el-button> | |
| 20 | + <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:dept:create']">新增</el-button> | |
| 38 | 21 | </el-col> |
| 39 | 22 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 40 | 23 | </el-row> |
| 41 | 24 | |
| 42 | - <el-table | |
| 43 | - v-loading="loading" | |
| 44 | - :data="deptList" | |
| 45 | - row-key="id" | |
| 46 | - default-expand-all | |
| 47 | - :tree-props="{children: 'children', hasChildren: 'hasChildren'}" | |
| 48 | - > | |
| 25 | + <el-table v-loading="loading" :data="deptList" row-key="id" default-expand-all | |
| 26 | + :tree-props="{children: 'children', hasChildren: 'hasChildren'}"> | |
| 49 | 27 | <el-table-column prop="name" label="部门名称" width="260"></el-table-column> |
| 50 | 28 | <el-table-column prop="sort" label="排序" width="200"></el-table-column> |
| 51 | 29 | <el-table-column prop="status" label="状态" :formatter="statusFormat" width="100"></el-table-column> |
| ... | ... | @@ -56,28 +34,12 @@ |
| 56 | 34 | </el-table-column> |
| 57 | 35 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 58 | 36 | <template slot-scope="scope"> |
| 59 | - <el-button | |
| 60 | - size="mini" | |
| 61 | - type="text" | |
| 62 | - icon="el-icon-edit" | |
| 63 | - @click="handleUpdate(scope.row)" | |
| 64 | - v-hasPermi="['system:dept:edit']" | |
| 65 | - >修改</el-button> | |
| 66 | - <el-button | |
| 67 | - size="mini" | |
| 68 | - type="text" | |
| 69 | - icon="el-icon-plus" | |
| 70 | - @click="handleAdd(scope.row)" | |
| 71 | - v-hasPermi="['system:dept:add']" | |
| 72 | - >新增</el-button> | |
| 73 | - <el-button | |
| 74 | - v-if="scope.row.parentId !== 0" | |
| 75 | - size="mini" | |
| 76 | - type="text" | |
| 77 | - icon="el-icon-delete" | |
| 78 | - @click="handleDelete(scope.row)" | |
| 79 | - v-hasPermi="['system:dept:remove']" | |
| 80 | - >删除</el-button> | |
| 37 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 38 | + v-hasPermi="['system:dept:update']">修改</el-button> | |
| 39 | + <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)" | |
| 40 | + v-hasPermi="['system:dept:create']">新增</el-button> | |
| 41 | + <el-button v-if="scope.row.parentId !== 0" size="mini" type="text" icon="el-icon-delete" | |
| 42 | + @click="handleDelete(scope.row)" v-hasPermi="['system:dept:delete']">删除</el-button> | |
| 81 | 43 | </template> |
| 82 | 44 | </el-table-column> |
| 83 | 45 | </el-table> |
| ... | ... | @@ -119,11 +81,8 @@ |
| 119 | 81 | <el-col :span="12"> |
| 120 | 82 | <el-form-item label="部门状态" prop="status"> |
| 121 | 83 | <el-radio-group v-model="form.status"> |
| 122 | - <el-radio | |
| 123 | - v-for="dict in statusDictDatas" | |
| 124 | - :key="parseInt(dict.value)" | |
| 125 | - :label="parseInt(dict.value)" | |
| 126 | - >{{dict.label}}</el-radio> | |
| 84 | + <el-radio v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="parseInt(dict.value)"> | |
| 85 | + {{dict.label}}</el-radio> | |
| 127 | 86 | </el-radio-group> |
| 128 | 87 | </el-form-item> |
| 129 | 88 | </el-col> | ... | ... |
ruoyi-ui/src/views/system/post/index.vue
| ... | ... | @@ -2,31 +2,14 @@ |
| 2 | 2 | <div class="app-container"> |
| 3 | 3 | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> |
| 4 | 4 | <el-form-item label="岗位编码" prop="code"> |
| 5 | - <el-input | |
| 6 | - v-model="queryParams.code" | |
| 7 | - placeholder="请输入岗位编码" | |
| 8 | - clearable | |
| 9 | - size="small" | |
| 10 | - @keyup.enter.native="handleQuery" | |
| 11 | - /> | |
| 5 | + <el-input v-model="queryParams.code" placeholder="请输入岗位编码" clearable size="small" @keyup.enter.native="handleQuery"/> | |
| 12 | 6 | </el-form-item> |
| 13 | 7 | <el-form-item label="岗位名称" prop="name"> |
| 14 | - <el-input | |
| 15 | - v-model="queryParams.name" | |
| 16 | - placeholder="请输入岗位名称" | |
| 17 | - clearable | |
| 18 | - size="small" | |
| 19 | - @keyup.enter.native="handleQuery" | |
| 20 | - /> | |
| 8 | + <el-input v-model="queryParams.name" placeholder="请输入岗位名称" clearable size="small" @keyup.enter.native="handleQuery"/> | |
| 21 | 9 | </el-form-item> |
| 22 | 10 | <el-form-item label="状态" prop="status"> |
| 23 | 11 | <el-select v-model="queryParams.status" placeholder="岗位状态" clearable size="small"> |
| 24 | - <el-option | |
| 25 | - v-for="dict in statusDictDatas" | |
| 26 | - :key="parseInt(dict.value)" | |
| 27 | - :label="dict.label" | |
| 28 | - :value="parseInt(dict.value)" | |
| 29 | - /> | |
| 12 | + <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/> | |
| 30 | 13 | </el-select> |
| 31 | 14 | </el-form-item> |
| 32 | 15 | <el-form-item> |
| ... | ... | @@ -37,22 +20,12 @@ |
| 37 | 20 | |
| 38 | 21 | <el-row :gutter="10" class="mb8"> |
| 39 | 22 | <el-col :span="1.5"> |
| 40 | - <el-button | |
| 41 | - type="primary" | |
| 42 | - icon="el-icon-plus" | |
| 43 | - size="mini" | |
| 44 | - @click="handleAdd" | |
| 45 | - v-hasPermi="['system:post:add']" | |
| 46 | - >新增</el-button> | |
| 23 | + <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 24 | + v-hasPermi="['system:post:create']">新增</el-button> | |
| 47 | 25 | </el-col> |
| 48 | 26 | <el-col :span="1.5"> |
| 49 | - <el-button | |
| 50 | - type="warning" | |
| 51 | - icon="el-icon-download" | |
| 52 | - size="mini" | |
| 53 | - @click="handleExport" | |
| 54 | - v-hasPermi="['system:post:export']" | |
| 55 | - >导出</el-button> | |
| 27 | + <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" | |
| 28 | + v-hasPermi="['system:post:export']">导出</el-button> | |
| 56 | 29 | </el-col> |
| 57 | 30 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 58 | 31 | </el-row> |
| ... | ... | @@ -70,31 +43,16 @@ |
| 70 | 43 | </el-table-column> |
| 71 | 44 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 72 | 45 | <template slot-scope="scope"> |
| 73 | - <el-button | |
| 74 | - size="mini" | |
| 75 | - type="text" | |
| 76 | - icon="el-icon-edit" | |
| 77 | - @click="handleUpdate(scope.row)" | |
| 78 | - v-hasPermi="['system:post:edit']" | |
| 79 | - >修改</el-button> | |
| 80 | - <el-button | |
| 81 | - size="mini" | |
| 82 | - type="text" | |
| 83 | - icon="el-icon-delete" | |
| 84 | - @click="handleDelete(scope.row)" | |
| 85 | - v-hasPermi="['system:post:remove']" | |
| 86 | - >删除</el-button> | |
| 46 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 47 | + v-hasPermi="['system:post:update']">修改</el-button> | |
| 48 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 49 | + v-hasPermi="['system:post:delete']">删除</el-button> | |
| 87 | 50 | </template> |
| 88 | 51 | </el-table-column> |
| 89 | 52 | </el-table> |
| 90 | 53 | |
| 91 | - <pagination | |
| 92 | - v-show="total>0" | |
| 93 | - :total="total" | |
| 94 | - :page.sync="queryParams.pageNo" | |
| 95 | - :limit.sync="queryParams.pageSize" | |
| 96 | - @pagination="getList" | |
| 97 | - /> | |
| 54 | + <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 55 | + @pagination="getList"/> | |
| 98 | 56 | |
| 99 | 57 | <!-- 添加或修改岗位对话框 --> |
| 100 | 58 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| ... | ... | @@ -110,11 +68,8 @@ |
| 110 | 68 | </el-form-item> |
| 111 | 69 | <el-form-item label="岗位状态" prop="status"> |
| 112 | 70 | <el-radio-group v-model="form.status"> |
| 113 | - <el-radio | |
| 114 | - v-for="dict in statusDictDatas" | |
| 115 | - :key="parseInt(dict.value)" | |
| 116 | - :label="parseInt(dict.value)" | |
| 117 | - >{{dict.label}}</el-radio> | |
| 71 | + <el-radio v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="parseInt(dict.value)"> | |
| 72 | + {{dict.label}}</el-radio> | |
| 118 | 73 | </el-radio-group> |
| 119 | 74 | </el-form-item> |
| 120 | 75 | <el-form-item label="备注" prop="remark"> | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysAuthController.java
| ... | ... | @@ -19,6 +19,7 @@ import cn.iocoder.dashboard.modules.system.service.user.SysUserService; |
| 19 | 19 | import cn.iocoder.dashboard.util.collection.SetUtils; |
| 20 | 20 | import io.swagger.annotations.Api; |
| 21 | 21 | import io.swagger.annotations.ApiOperation; |
| 22 | +import org.springframework.validation.annotation.Validated; | |
| 22 | 23 | import org.springframework.web.bind.annotation.*; |
| 23 | 24 | |
| 24 | 25 | import javax.annotation.Resource; |
| ... | ... | @@ -34,6 +35,7 @@ import static cn.iocoder.dashboard.util.servlet.ServletUtils.getUserAgent; |
| 34 | 35 | @Api(tags = "认证") |
| 35 | 36 | @RestController |
| 36 | 37 | @RequestMapping("/") |
| 38 | +@Validated | |
| 37 | 39 | public class SysAuthController { |
| 38 | 40 | |
| 39 | 41 | @Resource |
| ... | ... | @@ -45,8 +47,8 @@ public class SysAuthController { |
| 45 | 47 | @Resource |
| 46 | 48 | private SysPermissionService permissionService; |
| 47 | 49 | |
| 48 | - @ApiOperation("使用账号密码登录") | |
| 49 | 50 | @PostMapping("/login") |
| 51 | + @ApiOperation("使用账号密码登录") | |
| 50 | 52 | @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 |
| 51 | 53 | public CommonResult<SysAuthLoginRespVO> login(@RequestBody @Valid SysAuthLoginReqVO reqVO) { |
| 52 | 54 | String token = authService.login(reqVO, getClientIP(), getUserAgent()); |
| ... | ... | @@ -54,8 +56,8 @@ public class SysAuthController { |
| 54 | 56 | return success(SysAuthLoginRespVO.builder().token(token).build()); |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | - @ApiOperation("获取登陆用户的权限信息") | |
| 58 | 59 | @GetMapping("/get-permission-info") |
| 60 | + @ApiOperation("获取登陆用户的权限信息") | |
| 59 | 61 | public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() { |
| 60 | 62 | // 获得用户信息 |
| 61 | 63 | SysUserDO user = userService.getUser(getLoginUserId()); |
| ... | ... | @@ -65,7 +67,7 @@ public class SysAuthController { |
| 65 | 67 | // 获得角色列表 |
| 66 | 68 | List<SysRoleDO> roleList = roleService.listRolesFromCache(getLoginUserRoleIds()); |
| 67 | 69 | // 获得菜单列表 |
| 68 | - List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache( | |
| 70 | + List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache( | |
| 69 | 71 | getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 |
| 70 | 72 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()), |
| 71 | 73 | SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); |
| ... | ... | @@ -73,11 +75,11 @@ public class SysAuthController { |
| 73 | 75 | return success(SysAuthConvert.INSTANCE.convert(user, roleList, menuList)); |
| 74 | 76 | } |
| 75 | 77 | |
| 76 | - @ApiOperation("获得登陆用户的菜单列表") | |
| 77 | 78 | @GetMapping("list-menus") |
| 78 | - public CommonResult<List<SysAuthMenuRespVO>> listMenus() { | |
| 79 | + @ApiOperation("获得登陆用户的菜单列表") | |
| 80 | + public CommonResult<List<SysAuthMenuRespVO>> getMenus() { | |
| 79 | 81 | // 获得用户拥有的菜单列表 |
| 80 | - List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache( | |
| 82 | + List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache( | |
| 81 | 83 | getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 |
| 82 | 84 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型 |
| 83 | 85 | SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysUserSessionController.java
| ... | ... | @@ -39,9 +39,9 @@ public class SysUserSessionController { |
| 39 | 39 | @Resource |
| 40 | 40 | private SysDeptService deptService; |
| 41 | 41 | |
| 42 | + @GetMapping("/page") | |
| 42 | 43 | @ApiOperation("获得 Session 分页列表") |
| 43 | 44 | @PreAuthorize("@ss.hasPermission('system:user-session:page')") |
| 44 | - @GetMapping("/page") | |
| 45 | 45 | public CommonResult<PageResult<SysUserSessionPageItemRespVO>> getUserSessionPage(@Validated SysUserSessionPageReqVO reqVO) { |
| 46 | 46 | // 获得 Session 分页 |
| 47 | 47 | PageResult<SysUserSessionDO> pageResult = userSessionService.getUserSessionPage(reqVO); |
| ... | ... | @@ -66,12 +66,12 @@ public class SysUserSessionController { |
| 66 | 66 | return success(new PageResult<>(sessionList, pageResult.getTotal())); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - @ApiOperation("删除 Session") | |
| 70 | - @PreAuthorize("@ss.hasPermission('system:user-session:delete')") | |
| 71 | 69 | @DeleteMapping("/delete") |
| 70 | + @ApiOperation("删除 Session") | |
| 72 | 71 | @ApiImplicitParam(name = "id", value = "Session 编号", required = true, dataTypeClass = String.class, |
| 73 | 72 | example = "fe50b9f6-d177-44b1-8da9-72ea34f63db7") |
| 74 | - public CommonResult<Boolean> delete(@RequestParam("id") String id) { | |
| 73 | + @PreAuthorize("@ss.hasPermission('system:user-session:delete')") | |
| 74 | + public CommonResult<Boolean> deleteUserSession(@RequestParam("id") String id) { | |
| 75 | 75 | userSessionService.deleteUserSession(id); |
| 76 | 76 | return success(true); |
| 77 | 77 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java
| ... | ... | @@ -9,10 +9,12 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; |
| 9 | 9 | import io.swagger.annotations.Api; |
| 10 | 10 | import io.swagger.annotations.ApiImplicitParam; |
| 11 | 11 | import io.swagger.annotations.ApiOperation; |
| 12 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | 13 | import org.springframework.validation.annotation.Validated; |
| 13 | 14 | import org.springframework.web.bind.annotation.*; |
| 14 | 15 | |
| 15 | 16 | import javax.annotation.Resource; |
| 17 | +import javax.validation.Valid; | |
| 16 | 18 | import java.util.Comparator; |
| 17 | 19 | import java.util.List; |
| 18 | 20 | |
| ... | ... | @@ -21,65 +23,64 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success; |
| 21 | 23 | @Api(tags = "部门") |
| 22 | 24 | @RestController |
| 23 | 25 | @RequestMapping("/system/dept") |
| 26 | +@Validated | |
| 24 | 27 | public class SysDeptController { |
| 25 | 28 | |
| 26 | 29 | @Resource |
| 27 | 30 | private SysDeptService deptService; |
| 28 | 31 | |
| 29 | - @ApiOperation("获取部门列表") | |
| 30 | -// @PreAuthorize("@ss.hasPermi('system:dept:list')") | |
| 32 | + @PostMapping("create") | |
| 33 | + @ApiOperation("创建部门") | |
| 34 | + @PreAuthorize("@ss.hasPermission('system:dept:create')") | |
| 35 | + public CommonResult<Long> createDept(@Valid @RequestBody SysDeptCreateReqVO reqVO) { | |
| 36 | + Long deptId = deptService.createDept(reqVO); | |
| 37 | + return success(deptId); | |
| 38 | + } | |
| 39 | + | |
| 40 | + @PutMapping("update") | |
| 41 | + @ApiOperation("更新部门") | |
| 42 | + @PreAuthorize("@ss.hasPermission('system:dept:update')") | |
| 43 | + public CommonResult<Boolean> updateDept(@Valid @RequestBody SysDeptUpdateReqVO reqVO) { | |
| 44 | + deptService.updateDept(reqVO); | |
| 45 | + return success(true); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @DeleteMapping("delete") | |
| 49 | + @ApiOperation("删除部门") | |
| 50 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | |
| 51 | + @PreAuthorize("@ss.hasPermission('system:dept:delete')") | |
| 52 | + public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) { | |
| 53 | + deptService.deleteDept(id); | |
| 54 | + return success(true); | |
| 55 | + } | |
| 56 | + | |
| 31 | 57 | @GetMapping("/list") |
| 58 | + @ApiOperation("获取部门列表") | |
| 59 | + @PreAuthorize("@ss.hasPermission('system:dept:query')") | |
| 32 | 60 | public CommonResult<List<SysDeptRespVO>> listDepts(SysDeptListReqVO reqVO) { |
| 33 | - List<SysDeptDO> list = deptService.listDepts(reqVO); | |
| 61 | + List<SysDeptDO> list = deptService.getSimpleDepts(reqVO); | |
| 34 | 62 | list.sort(Comparator.comparing(SysDeptDO::getSort)); |
| 35 | 63 | return success(SysDeptConvert.INSTANCE.convertList(list)); |
| 36 | 64 | } |
| 37 | 65 | |
| 38 | - @ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项") | |
| 39 | 66 | @GetMapping("/list-all-simple") |
| 40 | - public CommonResult<List<SysDeptSimpleRespVO>> listSimpleDepts() { | |
| 67 | + @ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项") | |
| 68 | + public CommonResult<List<SysDeptSimpleRespVO>> getSimpleDepts() { | |
| 41 | 69 | // 获得部门列表,只要开启状态的 |
| 42 | 70 | SysDeptListReqVO reqVO = new SysDeptListReqVO(); |
| 43 | 71 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 44 | - List<SysDeptDO> list = deptService.listDepts(reqVO); | |
| 72 | + List<SysDeptDO> list = deptService.getSimpleDepts(reqVO); | |
| 45 | 73 | // 排序后,返回给前端 |
| 46 | 74 | list.sort(Comparator.comparing(SysDeptDO::getSort)); |
| 47 | 75 | return success(SysDeptConvert.INSTANCE.convertList02(list)); |
| 48 | 76 | } |
| 49 | 77 | |
| 78 | + @GetMapping("/get") | |
| 50 | 79 | @ApiOperation("获得部门信息") |
| 51 | 80 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 52 | -// @PreAuthorize("@ss.hasPermi('system:dept:query')") | |
| 53 | - @GetMapping("/get") | |
| 81 | + @PreAuthorize("@ss.hasPermission('system:dept:query')") | |
| 54 | 82 | public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) { |
| 55 | 83 | return success(SysDeptConvert.INSTANCE.convert(deptService.getDept(id))); |
| 56 | 84 | } |
| 57 | 85 | |
| 58 | - @ApiOperation("新增部门") | |
| 59 | - @PostMapping("create") | |
| 60 | -// @PreAuthorize("@ss.hasPermi('system:dept:add')") | |
| 61 | -// @Log(title = "部门管理", businessType = BusinessType.INSERT) | |
| 62 | - public CommonResult<Long> createDept(@Validated @RequestBody SysDeptCreateReqVO reqVO) { | |
| 63 | - Long deptId = deptService.createDept(reqVO); | |
| 64 | - return success(deptId); | |
| 65 | - } | |
| 66 | - | |
| 67 | - @ApiOperation("修改部门") | |
| 68 | - @PostMapping("update") | |
| 69 | -// @PreAuthorize("@ss.hasPermi('system:dept:edit')") | |
| 70 | -// @Log(title = "部门管理", businessType = BusinessType.UPDATE) | |
| 71 | - public CommonResult<Boolean> updateDept(@Validated @RequestBody SysDeptUpdateReqVO reqVO) { | |
| 72 | - deptService.updateDept(reqVO); | |
| 73 | - return success(true); | |
| 74 | - } | |
| 75 | - | |
| 76 | - @ApiOperation("删除部门") | |
| 77 | - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | |
| 78 | - @PostMapping("delete") | |
| 79 | -// @PreAuthorize("@ss.hasPermi('system:dept:remove')") | |
| 80 | -// @Log(title = "部门管理", businessType = BusinessType.DELETE) | |
| 81 | - public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) { | |
| 82 | - deptService.deleteDept(id); | |
| 83 | - return success(true); | |
| 84 | - } | |
| 85 | 86 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; |
| 7 | +import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; | |
| 7 | 8 | import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.*; |
| 8 | 9 | import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert; |
| 9 | 10 | import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO; |
| ... | ... | @@ -11,88 +12,88 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; |
| 11 | 12 | import io.swagger.annotations.Api; |
| 12 | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 13 | 14 | import io.swagger.annotations.ApiOperation; |
| 15 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | 16 | import org.springframework.validation.annotation.Validated; |
| 15 | 17 | import org.springframework.web.bind.annotation.*; |
| 16 | 18 | |
| 17 | 19 | import javax.annotation.Resource; |
| 18 | 20 | import javax.servlet.http.HttpServletResponse; |
| 21 | +import javax.validation.Valid; | |
| 19 | 22 | import java.io.IOException; |
| 20 | 23 | import java.util.Collections; |
| 21 | 24 | import java.util.Comparator; |
| 22 | 25 | import java.util.List; |
| 23 | 26 | |
| 24 | 27 | import static cn.iocoder.dashboard.common.pojo.CommonResult.success; |
| 28 | +import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 25 | 29 | |
| 26 | 30 | @Api(tags = "岗位") |
| 27 | 31 | @RestController |
| 28 | 32 | @RequestMapping("/system/post") |
| 33 | +@Valid | |
| 29 | 34 | public class SysPostController { |
| 30 | 35 | |
| 31 | 36 | @Resource |
| 32 | 37 | private SysPostService postService; |
| 33 | 38 | |
| 34 | - @ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项") | |
| 35 | - @GetMapping("/list-all-simple") | |
| 36 | - public CommonResult<List<SysPostSimpleRespVO>> listSimplePosts() { | |
| 37 | - // 获得岗位列表,只要开启状态的 | |
| 38 | - List<SysPostDO> list = postService.listPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | |
| 39 | - // 排序后,返回给前端 | |
| 40 | - list.sort(Comparator.comparing(SysPostDO::getSort)); | |
| 41 | - return success(SysPostConvert.INSTANCE.convertList02(list)); | |
| 42 | - } | |
| 43 | - | |
| 44 | - @ApiOperation("获得岗位分页列表") | |
| 45 | - @GetMapping("/page") | |
| 46 | -// @PreAuthorize("@ss.hasPermi('system:post:list')") | |
| 47 | - public CommonResult<PageResult<SysPostRespVO>> pagePosts(@Validated SysPostPageReqVO reqVO) { | |
| 48 | - return success(SysPostConvert.INSTANCE.convertPage(postService.pagePosts(reqVO))); | |
| 49 | - } | |
| 50 | - | |
| 51 | - @ApiOperation("新增岗位") | |
| 52 | 39 | @PostMapping("/create") |
| 53 | -// @PreAuthorize("@ss.hasPermi('system:post:add')") | |
| 54 | -// @Log(title = "岗位管理", businessType = BusinessType.INSERT) | |
| 55 | - public CommonResult<Long> createPost(@Validated @RequestBody SysPostCreateReqVO reqVO) { | |
| 40 | + @ApiOperation("创建岗位") | |
| 41 | + @PreAuthorize("@ss.hasPermission('system:post:create')") | |
| 42 | + public CommonResult<Long> createPost(@Valid @RequestBody SysPostCreateReqVO reqVO) { | |
| 56 | 43 | Long postId = postService.createPost(reqVO); |
| 57 | 44 | return success(postId); |
| 58 | 45 | } |
| 59 | 46 | |
| 47 | + @PutMapping("/update") | |
| 60 | 48 | @ApiOperation("修改岗位") |
| 61 | - @PostMapping("/update") | |
| 62 | -// @PreAuthorize("@ss.hasPermi('system:post:edit')") | |
| 63 | -// @Log(title = "岗位管理", businessType = BusinessType.UPDATE) | |
| 64 | - public CommonResult<Boolean> updatePost(@Validated @RequestBody SysPostUpdateReqVO reqVO) { | |
| 49 | + @PreAuthorize("@ss.hasPermission('system:post:update')") | |
| 50 | + public CommonResult<Boolean> updatePost(@Valid @RequestBody SysPostUpdateReqVO reqVO) { | |
| 65 | 51 | postService.updatePost(reqVO); |
| 66 | 52 | return success(true); |
| 67 | 53 | } |
| 68 | 54 | |
| 55 | + @DeleteMapping("/delete") | |
| 69 | 56 | @ApiOperation("删除岗位") |
| 70 | - @PostMapping("/delete") | |
| 71 | -// @PreAuthorize("@ss.hasPermi('system:post:remove')") | |
| 72 | -// @Log(title = "岗位管理", businessType = BusinessType.DELETE) | |
| 57 | + @PreAuthorize("@ss.hasPermission('system:post:delete')") | |
| 73 | 58 | public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) { |
| 74 | 59 | postService.deletePost(id); |
| 75 | 60 | return success(true); |
| 76 | 61 | } |
| 77 | 62 | |
| 63 | + @GetMapping(value = "/get") | |
| 78 | 64 | @ApiOperation("获得岗位信息") |
| 79 | 65 | @ApiImplicitParam(name = "id", value = "岗位编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 80 | -// @PreAuthorize("@ss.hasPermi('system:post:query')") | |
| 81 | - @GetMapping(value = "/get") | |
| 66 | + @PreAuthorize("@ss.hasPermission('system:post:query')") | |
| 82 | 67 | public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) { |
| 83 | 68 | return success(SysPostConvert.INSTANCE.convert(postService.getPost(id))); |
| 84 | 69 | } |
| 85 | 70 | |
| 71 | + @GetMapping("/list-all-simple") | |
| 72 | + @ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项") | |
| 73 | + public CommonResult<List<SysPostSimpleRespVO>> getSimplePosts() { | |
| 74 | + // 获得岗位列表,只要开启状态的 | |
| 75 | + List<SysPostDO> list = postService.getPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | |
| 76 | + // 排序后,返回给前端 | |
| 77 | + list.sort(Comparator.comparing(SysPostDO::getSort)); | |
| 78 | + return success(SysPostConvert.INSTANCE.convertList02(list)); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @GetMapping("/page") | |
| 82 | + @ApiOperation("获得岗位分页列表") | |
| 83 | + @PreAuthorize("@ss.hasPermission('system:post:query')") | |
| 84 | + public CommonResult<PageResult<SysPostRespVO>> getPostPage(@Validated SysPostPageReqVO reqVO) { | |
| 85 | + return success(SysPostConvert.INSTANCE.convertPage(postService.getPostPage(reqVO))); | |
| 86 | + } | |
| 87 | + | |
| 86 | 88 | @GetMapping("/export") |
| 87 | 89 | @ApiOperation("岗位管理") |
| 88 | -// @Log(title = "岗位管理", businessType = BusinessType.EXPORT) | |
| 89 | -// @PreAuthorize("@ss.hasPermi('system:post:export')") | |
| 90 | + @PreAuthorize("@ss.hasPermission('system:post:export')") | |
| 91 | + @OperateLog(type = EXPORT) | |
| 90 | 92 | public void export(HttpServletResponse response, @Validated SysPostExportReqVO reqVO) throws IOException { |
| 91 | - List<SysPostDO> posts = postService.listPosts(reqVO); | |
| 92 | - List<SysPostExcelVO> excelDataList = SysPostConvert.INSTANCE.convertList03(posts); | |
| 93 | + List<SysPostDO> posts = postService.getPosts(reqVO); | |
| 94 | + List<SysPostExcelVO> data = SysPostConvert.INSTANCE.convertList03(posts); | |
| 93 | 95 | // 输出 |
| 94 | - ExcelUtils.write(response, "岗位数据.xls", "岗位列表", | |
| 95 | - SysPostExcelVO.class, excelDataList); | |
| 96 | + ExcelUtils.write(response, "岗位数据.xls", "岗位列表", SysPostExcelVO.class, data); | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptService.java
| ... | ... | @@ -25,12 +25,34 @@ public interface SysDeptService { |
| 25 | 25 | void initLocalCache(); |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | + * 创建部门 | |
| 29 | + * | |
| 30 | + * @param reqVO 部门信息 | |
| 31 | + * @return 部门编号 | |
| 32 | + */ | |
| 33 | + Long createDept(SysDeptCreateReqVO reqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 更新部门 | |
| 37 | + * | |
| 38 | + * @param reqVO 部门信息 | |
| 39 | + */ | |
| 40 | + void updateDept(SysDeptUpdateReqVO reqVO); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 删除部门 | |
| 44 | + * | |
| 45 | + * @param id 部门编号 | |
| 46 | + */ | |
| 47 | + void deleteDept(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 28 | 50 | * 获得指定编号的部门列表 |
| 29 | 51 | * |
| 30 | 52 | * @param ids 部门编号数组 |
| 31 | 53 | * @return 部门列表 |
| 32 | 54 | */ |
| 33 | - List<SysDeptDO> listDepts(Collection<Long> ids); | |
| 55 | + List<SysDeptDO> getSimpleDepts(Collection<Long> ids); | |
| 34 | 56 | |
| 35 | 57 | /** |
| 36 | 58 | * 获得指定编号的部门 Map |
| ... | ... | @@ -42,7 +64,7 @@ public interface SysDeptService { |
| 42 | 64 | if (CollUtil.isEmpty(ids)) { |
| 43 | 65 | return Collections.emptyMap(); |
| 44 | 66 | } |
| 45 | - List<SysDeptDO> list = listDepts(ids); | |
| 67 | + List<SysDeptDO> list = getSimpleDepts(ids); | |
| 46 | 68 | return CollectionUtils.convertMap(list, SysDeptDO::getId); |
| 47 | 69 | } |
| 48 | 70 | |
| ... | ... | @@ -52,16 +74,7 @@ public interface SysDeptService { |
| 52 | 74 | * @param reqVO 筛选条件请求 VO |
| 53 | 75 | * @return 部门列表 |
| 54 | 76 | */ |
| 55 | - List<SysDeptDO> listDepts(SysDeptListReqVO reqVO); | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * 获得所有子部门,从缓存中 | |
| 59 | - * | |
| 60 | - * @param parentId 部门编号 | |
| 61 | - * @param recursive 是否递归获取所有 | |
| 62 | - * @return 子部门列表 | |
| 63 | - */ | |
| 64 | - List<SysDeptDO> listDeptsByParentIdFromCache(Long parentId, boolean recursive); | |
| 77 | + List<SysDeptDO> getSimpleDepts(SysDeptListReqVO reqVO); | |
| 65 | 78 | |
| 66 | 79 | /** |
| 67 | 80 | * 获得部门信息 |
| ... | ... | @@ -72,25 +85,12 @@ public interface SysDeptService { |
| 72 | 85 | SysDeptDO getDept(Long id); |
| 73 | 86 | |
| 74 | 87 | /** |
| 75 | - * 创建部门 | |
| 76 | - * | |
| 77 | - * @param reqVO 部门信息 | |
| 78 | - * @return 部门编号 | |
| 79 | - */ | |
| 80 | - Long createDept(SysDeptCreateReqVO reqVO); | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * 更新部门 | |
| 84 | - * | |
| 85 | - * @param reqVO 部门信息 | |
| 86 | - */ | |
| 87 | - void updateDept(SysDeptUpdateReqVO reqVO); | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * 删除部门 | |
| 88 | + * 获得所有子部门,从缓存中 | |
| 91 | 89 | * |
| 92 | - * @param id 部门编号 | |
| 90 | + * @param parentId 部门编号 | |
| 91 | + * @param recursive 是否递归获取所有 | |
| 92 | + * @return 子部门列表 | |
| 93 | 93 | */ |
| 94 | - void deleteDept(Long id); | |
| 94 | + List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive); | |
| 95 | 95 | |
| 96 | 96 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/SysPostService.java
| ... | ... | @@ -19,13 +19,35 @@ import java.util.List; |
| 19 | 19 | public interface SysPostService { |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | + * 创建岗位 | |
| 23 | + * | |
| 24 | + * @param reqVO 岗位信息 | |
| 25 | + * @return 岗位编号 | |
| 26 | + */ | |
| 27 | + Long createPost(SysPostCreateReqVO reqVO); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 更新岗位 | |
| 31 | + * | |
| 32 | + * @param reqVO 岗位信息 | |
| 33 | + */ | |
| 34 | + void updatePost(SysPostUpdateReqVO reqVO); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 删除岗位信息 | |
| 38 | + * | |
| 39 | + * @param id 岗位编号 | |
| 40 | + */ | |
| 41 | + void deletePost(Long id); | |
| 42 | + | |
| 43 | + /** | |
| 22 | 44 | * 获得符合条件的岗位列表 |
| 23 | 45 | * |
| 24 | 46 | * @param ids 岗位编号数组。如果为空,不进行筛选 |
| 25 | 47 | * @param statuses 状态数组。如果为空,不进行筛选 |
| 26 | 48 | * @return 部门列表 |
| 27 | 49 | */ |
| 28 | - List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); | |
| 50 | + List<SysPostDO> getPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); | |
| 29 | 51 | |
| 30 | 52 | /** |
| 31 | 53 | * 获得岗位分页列表 |
| ... | ... | @@ -33,7 +55,7 @@ public interface SysPostService { |
| 33 | 55 | * @param reqVO 分页条件 |
| 34 | 56 | * @return 部门分页列表 |
| 35 | 57 | */ |
| 36 | - PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO); | |
| 58 | + PageResult<SysPostDO> getPostPage(SysPostPageReqVO reqVO); | |
| 37 | 59 | |
| 38 | 60 | /** |
| 39 | 61 | * 获得岗位列表 |
| ... | ... | @@ -41,7 +63,7 @@ public interface SysPostService { |
| 41 | 63 | * @param reqVO 查询条件 |
| 42 | 64 | * @return 部门列表 |
| 43 | 65 | */ |
| 44 | - List<SysPostDO> listPosts(SysPostExportReqVO reqVO); | |
| 66 | + List<SysPostDO> getPosts(SysPostExportReqVO reqVO); | |
| 45 | 67 | |
| 46 | 68 | /** |
| 47 | 69 | * 获得岗位信息 |
| ... | ... | @@ -51,26 +73,4 @@ public interface SysPostService { |
| 51 | 73 | */ |
| 52 | 74 | SysPostDO getPost(Long id); |
| 53 | 75 | |
| 54 | - /** | |
| 55 | - * 创建岗位 | |
| 56 | - * | |
| 57 | - * @param reqVO 岗位信息 | |
| 58 | - * @return 岗位编号 | |
| 59 | - */ | |
| 60 | - Long createPost(SysPostCreateReqVO reqVO); | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * 更新岗位 | |
| 64 | - * | |
| 65 | - * @param reqVO 岗位信息 | |
| 66 | - */ | |
| 67 | - void updatePost(SysPostUpdateReqVO reqVO); | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * 删除岗位信息 | |
| 71 | - * | |
| 72 | - * @param id 岗位编号 | |
| 73 | - */ | |
| 74 | - void deletePost(Long id); | |
| 75 | - | |
| 76 | 76 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java
| ... | ... | @@ -19,6 +19,7 @@ import com.google.common.collect.Multimap; |
| 19 | 19 | import lombok.extern.slf4j.Slf4j; |
| 20 | 20 | import org.springframework.scheduling.annotation.Scheduled; |
| 21 | 21 | import org.springframework.stereotype.Service; |
| 22 | +import org.springframework.validation.annotation.Validated; | |
| 22 | 23 | |
| 23 | 24 | import javax.annotation.PostConstruct; |
| 24 | 25 | import javax.annotation.Resource; |
| ... | ... | @@ -32,6 +33,7 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; |
| 32 | 33 | * @author 芋道源码 |
| 33 | 34 | */ |
| 34 | 35 | @Service |
| 36 | +@Validated | |
| 35 | 37 | @Slf4j |
| 36 | 38 | public class SysDeptServiceImpl implements SysDeptService { |
| 37 | 39 | |
| ... | ... | @@ -47,6 +49,7 @@ public class SysDeptServiceImpl implements SysDeptService { |
| 47 | 49 | * |
| 48 | 50 | * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 |
| 49 | 51 | */ |
| 52 | + @SuppressWarnings("FieldCanBeLocal") | |
| 50 | 53 | private volatile Map<Long, SysDeptDO> deptCache; |
| 51 | 54 | /** |
| 52 | 55 | * 父部门缓存 |
| ... | ... | @@ -118,17 +121,55 @@ public class SysDeptServiceImpl implements SysDeptService { |
| 118 | 121 | } |
| 119 | 122 | |
| 120 | 123 | @Override |
| 121 | - public List<SysDeptDO> listDepts(Collection<Long> ids) { | |
| 124 | + public Long createDept(SysDeptCreateReqVO reqVO) { | |
| 125 | + // 校验正确性 | |
| 126 | + checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); | |
| 127 | + // 插入部门 | |
| 128 | + SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO); | |
| 129 | + deptMapper.insert(dept); | |
| 130 | + // 发送刷新消息 | |
| 131 | + deptProducer.sendDeptRefreshMessage(); | |
| 132 | + return dept.getId(); | |
| 133 | + } | |
| 134 | + | |
| 135 | + @Override | |
| 136 | + public void updateDept(SysDeptUpdateReqVO reqVO) { | |
| 137 | + // 校验正确性 | |
| 138 | + checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); | |
| 139 | + // 更新部门 | |
| 140 | + SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO); | |
| 141 | + deptMapper.updateById(updateObj); | |
| 142 | + // 发送刷新消息 | |
| 143 | + deptProducer.sendDeptRefreshMessage(); | |
| 144 | + } | |
| 145 | + | |
| 146 | + @Override | |
| 147 | + public void deleteDept(Long id) { | |
| 148 | + // 校验是否存在 | |
| 149 | + checkDeptExists(id); | |
| 150 | + // 校验是否有子部门 | |
| 151 | + if (deptMapper.selectCountByParentId(id) > 0) { | |
| 152 | + throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN); | |
| 153 | + } | |
| 154 | + // 删除部门 | |
| 155 | + deptMapper.deleteById(id); | |
| 156 | + // TODO 需要处理下与角色的数据权限关联,等做数据权限一起处理下 | |
| 157 | + // 发送刷新消息 | |
| 158 | + deptProducer.sendDeptRefreshMessage(); | |
| 159 | + } | |
| 160 | + | |
| 161 | + @Override | |
| 162 | + public List<SysDeptDO> getSimpleDepts(Collection<Long> ids) { | |
| 122 | 163 | return deptMapper.selectBatchIds(ids); |
| 123 | 164 | } |
| 124 | 165 | |
| 125 | 166 | @Override |
| 126 | - public List<SysDeptDO> listDepts(SysDeptListReqVO reqVO) { | |
| 167 | + public List<SysDeptDO> getSimpleDepts(SysDeptListReqVO reqVO) { | |
| 127 | 168 | return deptMapper.selectList(reqVO); |
| 128 | 169 | } |
| 129 | 170 | |
| 130 | 171 | @Override |
| 131 | - public List<SysDeptDO> listDeptsByParentIdFromCache(Long parentId, boolean recursive) { | |
| 172 | + public List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive) { | |
| 132 | 173 | List<SysDeptDO> result = new ArrayList<>(); |
| 133 | 174 | // 递归,简单粗暴 |
| 134 | 175 | this.listDeptsByParentIdFromCache(result, parentId, |
| ... | ... | @@ -167,44 +208,6 @@ public class SysDeptServiceImpl implements SysDeptService { |
| 167 | 208 | return deptMapper.selectById(id); |
| 168 | 209 | } |
| 169 | 210 | |
| 170 | - @Override | |
| 171 | - public Long createDept(SysDeptCreateReqVO reqVO) { | |
| 172 | - // 校验正确性 | |
| 173 | - checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); | |
| 174 | - // 插入部门 | |
| 175 | - SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO); | |
| 176 | - deptMapper.insert(dept); | |
| 177 | - // 发送刷新消息 | |
| 178 | - deptProducer.sendDeptRefreshMessage(); | |
| 179 | - return dept.getId(); | |
| 180 | - } | |
| 181 | - | |
| 182 | - @Override | |
| 183 | - public void updateDept(SysDeptUpdateReqVO reqVO) { | |
| 184 | - // 校验正确性 | |
| 185 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); | |
| 186 | - // 更新部门 | |
| 187 | - SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO); | |
| 188 | - deptMapper.updateById(updateObj); | |
| 189 | - // 发送刷新消息 | |
| 190 | - deptProducer.sendDeptRefreshMessage(); | |
| 191 | - } | |
| 192 | - | |
| 193 | - @Override | |
| 194 | - public void deleteDept(Long id) { | |
| 195 | - // 校验是否存在 | |
| 196 | - checkDeptExists(id); | |
| 197 | - // 校验是否有子部门 | |
| 198 | - if (deptMapper.selectCountByParentId(id) > 0) { | |
| 199 | - throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN); | |
| 200 | - } | |
| 201 | - // 删除部门 | |
| 202 | - deptMapper.deleteById(id); | |
| 203 | - // TODO 需要处理下与角色的数据权限关联,等做数据权限一起处理下 | |
| 204 | - // 发送刷新消息 | |
| 205 | - deptProducer.sendDeptRefreshMessage(); | |
| 206 | - } | |
| 207 | - | |
| 208 | 211 | private void checkCreateOrUpdate(Long id, Long parentId, String name) { |
| 209 | 212 | // 校验自己存在 |
| 210 | 213 | checkDeptExists(id); |
| ... | ... | @@ -232,7 +235,7 @@ public class SysDeptServiceImpl implements SysDeptService { |
| 232 | 235 | throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE); |
| 233 | 236 | } |
| 234 | 237 | // 父部门不能是原来的子部门 |
| 235 | - List<SysDeptDO> children = this.listDeptsByParentIdFromCache(id, true); | |
| 238 | + List<SysDeptDO> children = this.getDeptsByParentIdFromCache(id, true); | |
| 236 | 239 | if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) { |
| 237 | 240 | throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD); |
| 238 | 241 | } |
| ... | ... | @@ -262,12 +265,6 @@ public class SysDeptServiceImpl implements SysDeptService { |
| 262 | 265 | } |
| 263 | 266 | } |
| 264 | 267 | |
| 265 | -// /** | |
| 266 | -// * 查询部门管理数据 | |
| 267 | -// * | |
| 268 | -// * @param dept 部门信息 | |
| 269 | -// * @return 部门信息集合 | |
| 270 | -// */ | |
| 271 | 268 | // @Override |
| 272 | 269 | // @DataScope(deptAlias = "d") |
| 273 | 270 | // public List<SysDept> selectDeptList(SysDept dept) | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysPostServiceImpl.java
| ... | ... | @@ -11,6 +11,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dept.SysPostMapper; |
| 11 | 11 | import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO; |
| 12 | 12 | import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; |
| 13 | 13 | import org.springframework.stereotype.Service; |
| 14 | +import org.springframework.validation.annotation.Validated; | |
| 14 | 15 | |
| 15 | 16 | import javax.annotation.Resource; |
| 16 | 17 | import java.util.Collection; |
| ... | ... | @@ -24,32 +25,13 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; |
| 24 | 25 | * @author 芋道源码 |
| 25 | 26 | */ |
| 26 | 27 | @Service |
| 28 | +@Validated | |
| 27 | 29 | public class SysPostServiceImpl implements SysPostService { |
| 28 | 30 | |
| 29 | 31 | @Resource |
| 30 | 32 | private SysPostMapper postMapper; |
| 31 | 33 | |
| 32 | 34 | @Override |
| 33 | - public List<SysPostDO> listPosts(Collection<Long> ids, Collection<Integer> statuses) { | |
| 34 | - return postMapper.selectList(ids, statuses); | |
| 35 | - } | |
| 36 | - | |
| 37 | - @Override | |
| 38 | - public PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO) { | |
| 39 | - return postMapper.selectPage(reqVO); | |
| 40 | - } | |
| 41 | - | |
| 42 | - @Override | |
| 43 | - public List<SysPostDO> listPosts(SysPostExportReqVO reqVO) { | |
| 44 | - return postMapper.selectList(reqVO); | |
| 45 | - } | |
| 46 | - | |
| 47 | - @Override | |
| 48 | - public SysPostDO getPost(Long id) { | |
| 49 | - return postMapper.selectById(id); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | 35 | public Long createPost(SysPostCreateReqVO reqVO) { |
| 54 | 36 | // 校验正确性 |
| 55 | 37 | this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getCode()); |
| ... | ... | @@ -68,6 +50,34 @@ public class SysPostServiceImpl implements SysPostService { |
| 68 | 50 | postMapper.updateById(updateObj); |
| 69 | 51 | } |
| 70 | 52 | |
| 53 | + @Override | |
| 54 | + public void deletePost(Long id) { | |
| 55 | + // 校验是否存在 | |
| 56 | + this.checkPostExists(id); | |
| 57 | + // 删除部门 | |
| 58 | + postMapper.deleteById(id); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public List<SysPostDO> getPosts(Collection<Long> ids, Collection<Integer> statuses) { | |
| 63 | + return postMapper.selectList(ids, statuses); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public PageResult<SysPostDO> getPostPage(SysPostPageReqVO reqVO) { | |
| 68 | + return postMapper.selectPage(reqVO); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public List<SysPostDO> getPosts(SysPostExportReqVO reqVO) { | |
| 73 | + return postMapper.selectList(reqVO); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public SysPostDO getPost(Long id) { | |
| 78 | + return postMapper.selectById(id); | |
| 79 | + } | |
| 80 | + | |
| 71 | 81 | private void checkCreateOrUpdate(Long id, String name, String code) { |
| 72 | 82 | // 校验自己存在 |
| 73 | 83 | checkPostExists(id); |
| ... | ... | @@ -105,14 +115,6 @@ public class SysPostServiceImpl implements SysPostService { |
| 105 | 115 | } |
| 106 | 116 | } |
| 107 | 117 | |
| 108 | - @Override | |
| 109 | - public void deletePost(Long id) { | |
| 110 | - // 校验是否存在 | |
| 111 | - this.checkPostExists(id); | |
| 112 | - // 删除部门 | |
| 113 | - postMapper.deleteById(id); | |
| 114 | - } | |
| 115 | - | |
| 116 | 118 | private void checkPostExists(Long id) { |
| 117 | 119 | if (id == null) { |
| 118 | 120 | return; | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java
| ... | ... | @@ -32,8 +32,8 @@ public interface SysPermissionService extends SecurityPermissionFrameworkService |
| 32 | 32 | * @param menusStatuses 菜单状态数组 |
| 33 | 33 | * @return 菜单列表 |
| 34 | 34 | */ |
| 35 | - List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes, | |
| 36 | - Collection<Integer> menusStatuses); | |
| 35 | + List<SysMenuDO> getRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes, | |
| 36 | + Collection<Integer> menusStatuses); | |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * 获得用户拥有的角色编号集合 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java
| ... | ... | @@ -133,8 +133,8 @@ public class SysPermissionServiceImpl implements SysPermissionService { |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | @Override |
| 136 | - public List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes, | |
| 137 | - Collection<Integer> menusStatuses) { | |
| 136 | + public List<SysMenuDO> getRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes, | |
| 137 | + Collection<Integer> menusStatuses) { | |
| 138 | 138 | // 任一一个参数为空时,不返回任何菜单 |
| 139 | 139 | if (CollectionUtils.isAnyEmpty(roleIds, menusStatuses, menusStatuses)) { |
| 140 | 140 | return Collections.emptyList(); | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java
| ... | ... | @@ -113,7 +113,7 @@ public class SysUserServiceImpl implements SysUserService { |
| 113 | 113 | if (deptId == null) { |
| 114 | 114 | return Collections.emptySet(); |
| 115 | 115 | } |
| 116 | - Set<Long> deptIds = CollectionUtils.convertSet(deptService.listDeptsByParentIdFromCache( | |
| 116 | + Set<Long> deptIds = CollectionUtils.convertSet(deptService.getDeptsByParentIdFromCache( | |
| 117 | 117 | deptId, true), SysDeptDO::getId); |
| 118 | 118 | deptIds.add(deptId); // 包括自身 |
| 119 | 119 | return deptIds; |
| ... | ... | @@ -287,7 +287,7 @@ public class SysUserServiceImpl implements SysUserService { |
| 287 | 287 | if (CollUtil.isEmpty(postIds)) { // 允许不选择 |
| 288 | 288 | return; |
| 289 | 289 | } |
| 290 | - List<SysPostDO> posts = postService.listPosts(postIds, null); | |
| 290 | + List<SysPostDO> posts = postService.getPosts(postIds, null); | |
| 291 | 291 | if (CollUtil.isEmpty(posts)) { |
| 292 | 292 | throw ServiceExceptionUtil.exception(POST_NOT_FOUND); |
| 293 | 293 | } | ... | ... |
src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptServiceTest.java
| ... | ... | @@ -92,7 +92,7 @@ class SysDeptServiceTest extends BaseDbUnitTest { |
| 92 | 92 | reqVO.setName("开"); |
| 93 | 93 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 94 | 94 | // 调用 |
| 95 | - List<SysDeptDO> sysDeptDOS = deptService.listDepts(reqVO); | |
| 95 | + List<SysDeptDO> sysDeptDOS = deptService.getSimpleDepts(reqVO); | |
| 96 | 96 | // 断言 |
| 97 | 97 | assertEquals(1, sysDeptDOS.size()); |
| 98 | 98 | assertPojoEquals(dept, sysDeptDOS.get(0)); | ... | ... |
src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysPostServiceTest.java
| ... | ... | @@ -59,7 +59,7 @@ class SysPostServiceTest extends BaseDbUnitTest { |
| 59 | 59 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 60 | 60 | |
| 61 | 61 | // 调用 |
| 62 | - PageResult<SysPostDO> pageResult = postService.pagePosts(reqVO); | |
| 62 | + PageResult<SysPostDO> pageResult = postService.getPostPage(reqVO); | |
| 63 | 63 | |
| 64 | 64 | // 断言 |
| 65 | 65 | assertEquals(1, pageResult.getTotal()); |
| ... | ... | @@ -85,7 +85,7 @@ class SysPostServiceTest extends BaseDbUnitTest { |
| 85 | 85 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 86 | 86 | |
| 87 | 87 | // 调用 |
| 88 | - List<SysPostDO> list = postService.listPosts(reqVO); | |
| 88 | + List<SysPostDO> list = postService.getPosts(reqVO); | |
| 89 | 89 | // 断言 |
| 90 | 90 | assertEquals(1, list.size()); |
| 91 | 91 | assertPojoEquals(postDO, list.get(0)); | ... | ... |