Your Name 4 gadus atpakaļ
vecāks
revīzija
dc6a3b3067

+ 41
- 12
src/main/java/com/yunzhi/demo/controller/SysRoleController.java Parādīt failu

@@ -6,9 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.demo.common.BaseController;
7 7
 import com.yunzhi.demo.common.Constants;
8 8
 import com.yunzhi.demo.common.ResponseBean;
9
-import com.yunzhi.demo.entity.SysLogin;
10
-import com.yunzhi.demo.entity.SysUser;
11
-import com.yunzhi.demo.entity.SysUserRole;
9
+import com.yunzhi.demo.common.StringUtils;
10
+import com.yunzhi.demo.entity.*;
11
+import com.yunzhi.demo.service.ISysMenuService;
12 12
 import com.yunzhi.demo.service.ISysUserRoleService;
13 13
 import io.swagger.annotations.Api;
14 14
 import io.swagger.annotations.ApiOperation;
@@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
22 22
 import org.springframework.web.bind.annotation.RequestMethod;
23 23
 import org.springframework.web.bind.annotation.RequestParam;
24 24
 import com.yunzhi.demo.service.ISysRoleService;
25
-import com.yunzhi.demo.entity.SysRole;
26 25
 import org.springframework.web.bind.annotation.RestController;
27 26
 
28 27
 import java.util.ArrayList;
@@ -50,6 +49,9 @@ public class SysRoleController extends BaseController {
50 49
     @Autowired
51 50
     ISysUserRoleService iSysUserRoleService;
52 51
 
52
+    @Autowired
53
+    ISysMenuService iSysMenuService;
54
+
53 55
     /**
54 56
      * 分页查询列表
55 57
      * @param pageNum
@@ -95,9 +97,12 @@ public class SysRoleController extends BaseController {
95 97
      * @param sysRole 实体对象
96 98
      * @return
97 99
      */
98
-    @RequestMapping(value="/sysRole",method= RequestMethod.POST)
100
+    @RequestMapping(value="/admin/role",method= RequestMethod.POST)
99 101
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
100 102
     public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
103
+        if (StringUtils.isEmpty(sysRole.getName())) {
104
+            throw new Exception("角色名称不能为空");
105
+        }
101 106
 
102 107
         if (iSysRoleService.save(sysRole)){
103 108
             return ResponseBean.success(sysRole);
@@ -110,10 +115,17 @@ public class SysRoleController extends BaseController {
110 115
      * 根据id删除对象
111 116
      * @param id  实体ID
112 117
      */
113
-    @RequestMapping(value="/sysRole/{id}", method= RequestMethod.DELETE)
118
+    @RequestMapping(value="/admin/role/{id}", method= RequestMethod.DELETE)
114 119
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
115 120
     public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
116
-        if(iSysRoleService.removeById(id)){
121
+        SysRole sysRole = iSysRoleService.getById(id);
122
+        if (null == sysRole || Constants.STATUS_DELETED.equals(sysRole.getStatus())) {
123
+            return ResponseBean.success("success");
124
+        }
125
+
126
+        sysRole.setStatus(Constants.STATUS_DELETED);
127
+
128
+        if(iSysRoleService.updateById(sysRole)){
117 129
             return ResponseBean.success("success");
118 130
         }else {
119 131
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -126,10 +138,17 @@ public class SysRoleController extends BaseController {
126 138
      * @param sysRole 实体对象
127 139
      * @return
128 140
      */
129
-    @RequestMapping(value="/sysRole/{id}",method= RequestMethod.PUT)
141
+    @RequestMapping(value="/admin/role/{id}",method= RequestMethod.PUT)
130 142
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
131 143
     public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable Integer id,
132
-                                        @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
144
+                                      @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
145
+        if (StringUtils.isEmpty(sysRole.getName())) {
146
+            throw new Exception("角色名称不能为空");
147
+        }
148
+
149
+        if (!id.equals(sysRole.getRoleId())) {
150
+            throw new Exception("校验角色信息失败");
151
+        }
133 152
 
134 153
         if (iSysRoleService.updateById(sysRole)){
135 154
             return ResponseBean.success(iSysRoleService.getById(id));
@@ -142,9 +161,19 @@ public class SysRoleController extends BaseController {
142 161
      * 根据id查询对象
143 162
      * @param id  实体ID
144 163
      */
145
-    @RequestMapping(value="/sysRole/{id}",method= RequestMethod.GET)
146
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
164
+    @RequestMapping(value="/admin/role/{id}",method= RequestMethod.GET)
165
+    @ApiOperation(value="查询角色信息", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
147 166
     public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
148
-        return ResponseBean.success(iSysRoleService.getById(id));
167
+        SysRole sysRole = iSysRoleService.getById(id);
168
+        if (null == sysRole || Constants.STATUS_DELETED.equals(sysRole.getStatus())) {
169
+            throw new Exception("未找到指定的角色信息");
170
+        }
171
+
172
+        List<SysMenu> menuList = iSysMenuService.getListByRole(id);
173
+        if (null != menuList) {
174
+            sysRole.setMenuList(menuList);
175
+        }
176
+
177
+        return ResponseBean.success(sysRole);
149 178
     }
150 179
 }

+ 8
- 1
src/main/java/com/yunzhi/demo/controller/SysUserController.java Parādīt failu

@@ -125,7 +125,14 @@ public class SysUserController extends BaseController {
125 125
     @RequestMapping(value="/admin/user/{id}", method= RequestMethod.DELETE)
126 126
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
127 127
     public ResponseBean sysUserDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
128
-        if(iSysUserService.removeById(id)){
128
+        SysUser sysUser = iSysUserService.getById(id);
129
+        if (null == sysUser || Constants.STATUS_DELETED.equals(sysUser.getStatus())) {
130
+            return ResponseBean.success("success");
131
+        }
132
+
133
+        sysUser.setStatus(Constants.STATUS_DELETED);
134
+
135
+        if(iSysUserService.updateById(sysUser)){
129 136
             return ResponseBean.success("success");
130 137
         }else {
131 138
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 5
- 1
src/main/java/com/yunzhi/demo/entity/SysRole.java Parādīt failu

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
5 5
 import com.baomidou.mybatisplus.annotation.TableId;
6 6
 import java.time.LocalDateTime;
7 7
 import java.io.Serializable;
8
+import java.util.List;
9
+
8 10
 import io.swagger.annotations.ApiModel;
9 11
 import io.swagger.annotations.ApiModelProperty;
10 12
 import lombok.Data;
@@ -50,5 +52,7 @@ public class SysRole implements Serializable {
50 52
     @ApiModelProperty(value = "更新时间")
51 53
     private LocalDateTime updateDate;
52 54
 
53
-
55
+    @ApiModelProperty("授权菜单")
56
+    @TableField(exist = false)
57
+    private List<SysMenu> menuList;
54 58
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/mapper/SysMenuMapper.java Parādīt failu

@@ -18,4 +18,6 @@ import java.util.List;
18 18
 public interface SysMenuMapper extends BaseMapper<SysMenu> {
19 19
 
20 20
     List<SysMenu> getListWithRoles();
21
+
22
+    List<SysMenu> getMenuListByRole(Integer roleId);
21 23
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/service/ISysMenuService.java Parādīt failu

@@ -16,4 +16,6 @@ import java.util.List;
16 16
 public interface ISysMenuService extends IService<SysMenu> {
17 17
 
18 18
     List<SysMenu> getListWithRoles();
19
+
20
+    List<SysMenu> getListByRole(Integer roleId);
19 21
 }

+ 5
- 0
src/main/java/com/yunzhi/demo/service/impl/SysMenuServiceImpl.java Parādīt failu

@@ -26,4 +26,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
26 26
     public List<SysMenu> getListWithRoles() {
27 27
         return sysMenuMapper.getListWithRoles();
28 28
     }
29
+
30
+    @Override
31
+    public List<SysMenu> getListByRole(Integer roleId) {
32
+        return sysMenuMapper.getMenuListByRole(roleId);
33
+    }
29 34
 }

+ 13
- 0
src/main/resources/mapper/SysMenuMapper.xml Parādīt failu

@@ -14,4 +14,17 @@
14 14
         GROUP BY
15 15
             t.menu_id
16 16
     </select>
17
+    <select id="getMenuListByRole" resultType="com.yunzhi.demo.entity.SysMenu">
18
+        SELECT
19
+            t.*
20
+        FROM
21
+            sys_menu t
22
+                INNER JOIN sys_role_menu s ON t.menu_id = s.menu_id
23
+        WHERE
24
+            t.`status` > - 1
25
+          AND s.role_id = #{roleId}
26
+        ORDER BY
27
+            t.menu_p_id,
28
+            t.menu_id
29
+    </select>
17 30
 </mapper>