Your Name il y a 4 ans
Parent
révision
dc6a3b3067

+ 41
- 12
src/main/java/com/yunzhi/demo/controller/SysRoleController.java Voir le fichier

6
 import com.yunzhi.demo.common.BaseController;
6
 import com.yunzhi.demo.common.BaseController;
7
 import com.yunzhi.demo.common.Constants;
7
 import com.yunzhi.demo.common.Constants;
8
 import com.yunzhi.demo.common.ResponseBean;
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
 import com.yunzhi.demo.service.ISysUserRoleService;
12
 import com.yunzhi.demo.service.ISysUserRoleService;
13
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.Api;
14
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiOperation;
22
 import org.springframework.web.bind.annotation.RequestMethod;
22
 import org.springframework.web.bind.annotation.RequestMethod;
23
 import org.springframework.web.bind.annotation.RequestParam;
23
 import org.springframework.web.bind.annotation.RequestParam;
24
 import com.yunzhi.demo.service.ISysRoleService;
24
 import com.yunzhi.demo.service.ISysRoleService;
25
-import com.yunzhi.demo.entity.SysRole;
26
 import org.springframework.web.bind.annotation.RestController;
25
 import org.springframework.web.bind.annotation.RestController;
27
 
26
 
28
 import java.util.ArrayList;
27
 import java.util.ArrayList;
50
     @Autowired
49
     @Autowired
51
     ISysUserRoleService iSysUserRoleService;
50
     ISysUserRoleService iSysUserRoleService;
52
 
51
 
52
+    @Autowired
53
+    ISysMenuService iSysMenuService;
54
+
53
     /**
55
     /**
54
      * 分页查询列表
56
      * 分页查询列表
55
      * @param pageNum
57
      * @param pageNum
95
      * @param sysRole 实体对象
97
      * @param sysRole 实体对象
96
      * @return
98
      * @return
97
      */
99
      */
98
-    @RequestMapping(value="/sysRole",method= RequestMethod.POST)
100
+    @RequestMapping(value="/admin/role",method= RequestMethod.POST)
99
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
101
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
100
     public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
102
     public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
103
+        if (StringUtils.isEmpty(sysRole.getName())) {
104
+            throw new Exception("角色名称不能为空");
105
+        }
101
 
106
 
102
         if (iSysRoleService.save(sysRole)){
107
         if (iSysRoleService.save(sysRole)){
103
             return ResponseBean.success(sysRole);
108
             return ResponseBean.success(sysRole);
110
      * 根据id删除对象
115
      * 根据id删除对象
111
      * @param id  实体ID
116
      * @param id  实体ID
112
      */
117
      */
113
-    @RequestMapping(value="/sysRole/{id}", method= RequestMethod.DELETE)
118
+    @RequestMapping(value="/admin/role/{id}", method= RequestMethod.DELETE)
114
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
119
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
115
     public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
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
             return ResponseBean.success("success");
129
             return ResponseBean.success("success");
118
         }else {
130
         }else {
119
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
131
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
126
      * @param sysRole 实体对象
138
      * @param sysRole 实体对象
127
      * @return
139
      * @return
128
      */
140
      */
129
-    @RequestMapping(value="/sysRole/{id}",method= RequestMethod.PUT)
141
+    @RequestMapping(value="/admin/role/{id}",method= RequestMethod.PUT)
130
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
142
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
131
     public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable Integer id,
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
         if (iSysRoleService.updateById(sysRole)){
153
         if (iSysRoleService.updateById(sysRole)){
135
             return ResponseBean.success(iSysRoleService.getById(id));
154
             return ResponseBean.success(iSysRoleService.getById(id));
142
      * 根据id查询对象
161
      * 根据id查询对象
143
      * @param id  实体ID
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
     public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
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 Voir le fichier

125
     @RequestMapping(value="/admin/user/{id}", method= RequestMethod.DELETE)
125
     @RequestMapping(value="/admin/user/{id}", method= RequestMethod.DELETE)
126
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
126
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
127
     public ResponseBean sysUserDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
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
             return ResponseBean.success("success");
136
             return ResponseBean.success("success");
130
         }else {
137
         }else {
131
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
138
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 5
- 1
src/main/java/com/yunzhi/demo/entity/SysRole.java Voir le fichier

5
 import com.baomidou.mybatisplus.annotation.TableId;
5
 import com.baomidou.mybatisplus.annotation.TableId;
6
 import java.time.LocalDateTime;
6
 import java.time.LocalDateTime;
7
 import java.io.Serializable;
7
 import java.io.Serializable;
8
+import java.util.List;
9
+
8
 import io.swagger.annotations.ApiModel;
10
 import io.swagger.annotations.ApiModel;
9
 import io.swagger.annotations.ApiModelProperty;
11
 import io.swagger.annotations.ApiModelProperty;
10
 import lombok.Data;
12
 import lombok.Data;
50
     @ApiModelProperty(value = "更新时间")
52
     @ApiModelProperty(value = "更新时间")
51
     private LocalDateTime updateDate;
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 Voir le fichier

18
 public interface SysMenuMapper extends BaseMapper<SysMenu> {
18
 public interface SysMenuMapper extends BaseMapper<SysMenu> {
19
 
19
 
20
     List<SysMenu> getListWithRoles();
20
     List<SysMenu> getListWithRoles();
21
+
22
+    List<SysMenu> getMenuListByRole(Integer roleId);
21
 }
23
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/service/ISysMenuService.java Voir le fichier

16
 public interface ISysMenuService extends IService<SysMenu> {
16
 public interface ISysMenuService extends IService<SysMenu> {
17
 
17
 
18
     List<SysMenu> getListWithRoles();
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 Voir le fichier

26
     public List<SysMenu> getListWithRoles() {
26
     public List<SysMenu> getListWithRoles() {
27
         return sysMenuMapper.getListWithRoles();
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 Voir le fichier

14
         GROUP BY
14
         GROUP BY
15
             t.menu_id
15
             t.menu_id
16
     </select>
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
 </mapper>
30
 </mapper>