Browse Source

feat: 实现角色相关接口

weijianghai 2 years ago
parent
commit
d55d9729c1

+ 46 - 0
src/main/java/com/nokia/controller/web/WebRoleController.java

@@ -0,0 +1,46 @@
+package com.nokia.controller.web;
+
+import com.nokia.common.R;
+import com.nokia.service.RoleService;
+import com.nokia.vo.AllRoleVo;
+import com.nokia.vo.ListRoleDto;
+import com.nokia.vo.ListRoleVo;
+import com.nokia.vo.PageVo;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.util.List;
+
+@Tag(name = "角色")
+@RequestMapping("api/web/role")
+@RestController
+public class WebRoleController {
+    private final RoleService roleService;
+
+    public WebRoleController(RoleService roleService) {
+        this.roleService = roleService;
+    }
+
+    /**
+     * 查询角色说明
+     */
+    @Operation(summary = "查询角色说明列表")
+    @PostMapping("list")
+    public R<PageVo<ListRoleVo>> list(@Valid @RequestBody ListRoleDto dto) {
+        return roleService.list(dto);
+    }
+
+    /**
+     * 查询所有角色
+     */
+    @Operation(summary = "查询所有角色")
+    @PostMapping("all")
+    public R<List<AllRoleVo>> all() {
+        return roleService.all();
+    }
+}

+ 47 - 7
src/main/java/com/nokia/dao/RoleDao.java

@@ -1,19 +1,59 @@
 package com.nokia.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.nokia.pojo.Role;
-
-import java.util.List;
-
+import com.nokia.vo.AllRoleVo;
+import com.nokia.vo.ListRoleDto;
+import com.nokia.vo.ListRoleVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
 
 @Mapper
 public interface RoleDao extends BaseMapper<Role> {
+    /**
+     * 查询角色说明列表
+     */
+    @Select("<script> " +
+            "select ar.role_name, ar.\"system\", ar.role_description, as2.system_name from sqmdb_rpt.acl_role ar " +
+            "inner join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\" " +
+            "<where> " +
+            "    <if test='dto.system'> " +
+            "         ar.\"system\" = #{dto.system} " +
+            "    </if> " +
+            "    <if test='dto.roleName'> " +
+            "         and ar.role_name like concat('%', #{dto.roleName}, '%') " +
+            "    </if> " +
+            "</where> " +
+            "</script>")
+    List<ListRoleVo> list(Page<ListRoleVo> page, ListRoleDto dto);
 
-    @Select("select r.role_id, r.role_name, r.system from sqmdb_rpt.acl_role r, sqmdb_rpt.acl_user_role ur where r.role_id = ur.role_id and ur.user_id = #{userId}")
-    List<Role> findByUserId(Integer userId);
+    /**
+     * 查询所有角色,除了权限
+     *
+     * @return {@link List}<{@link AllRoleVo}>
+     */
+    @Select("select ar.role_id, ar.role_name, ar.function_id, ar.\"system\", as2.system_name " +
+            "from sqmdb_rpt.acl_role ar " +
+            "left join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\" " +
+            "where ar.role_id != -1 " +
+            "order by ar.\"system\"")
+    List<AllRoleVo> all();
 
-    @Select("select * from sqmdb_rpt.acl_role where role_name like concat('%',#{roleName},'%')")
-    List<Role> findRoleNameLike(String roleName);
+    /**
+     * 重置function_id
+     *
+     */
+    @Update("<script> " +
+            "update sqmdb_rpt.acl_role " +
+            "set function_id = null " +
+            "where function_id in " +
+            "<foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\"> " +
+            "  #{item} " +
+            "</foreach> " +
+            "</script>")
+    int resetFunctionId(List<Integer> list);
 }

+ 21 - 13
src/main/java/com/nokia/service/RoleService.java

@@ -1,16 +1,19 @@
 package com.nokia.service;
 
-import java.util.List;
-
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.nokia.common.R;
+import com.nokia.dao.RoleDao;
+import com.nokia.vo.AllRoleVo;
+import com.nokia.vo.ListRoleDto;
+import com.nokia.vo.ListRoleVo;
+import com.nokia.vo.PageVo;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.nokia.dao.RoleDao;
-import com.nokia.pojo.Role;
+import java.util.List;
 
 @Service
-public class RoleService extends ServiceImpl<RoleDao, Role> {
+public class RoleService {
 
     private final RoleDao roleDao;
 
@@ -18,13 +21,18 @@ public class RoleService extends ServiceImpl<RoleDao, Role> {
         this.roleDao = roleDao;
     }
 
-    public Role getByRoleName(String roleName) {
-        Role roleEntity = new Role();
-        roleEntity.setRoleName(roleName);
-        return getOne(Wrappers.query(roleEntity));
+    public R<PageVo<ListRoleVo>> list(ListRoleDto dto) {
+        PageVo<ListRoleVo> vo = new PageVo<>();
+        Page<ListRoleVo> page = new Page<>(dto.getCurrent(), dto.getPageSize());
+        page.addOrder(OrderItem.asc("ar.\"system\""));
+        List<ListRoleVo> list = roleDao.list(page, dto);
+        vo.setList(list);
+        vo.setTotal(page.getTotal());
+        return R.ok(vo);
     }
 
-    public List<Role> getRoleNameLike(String roleName) {
-        return roleDao.findRoleNameLike(roleName);
+    public R<List<AllRoleVo>> all() {
+        List<AllRoleVo> list = roleDao.all();
+        return R.ok(list);
     }
 }

+ 22 - 0
src/main/java/com/nokia/vo/AllRoleVo.java

@@ -0,0 +1,22 @@
+package com.nokia.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class AllRoleVo {
+    @Schema(description = "角色id")
+    private Integer roleId;
+    @Schema(description = "功能id")
+    private Integer functionId;
+    @Schema(description = "角色名称", example = "工单查询")
+    private String roleName;
+    @Schema(description = "系统id", example = "flow")
+    private String system;
+    @Schema(description = "系统名称", example = "流程")
+    private String systemName;
+}

+ 18 - 0
src/main/java/com/nokia/vo/ListRoleDto.java

@@ -0,0 +1,18 @@
+package com.nokia.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class ListRoleDto extends PageDto {
+    @Schema(description = "角色名称", example = "工单")
+    private String roleName;
+    @Schema(description = "系统id", example = "flow")
+    private String system;
+}

+ 20 - 0
src/main/java/com/nokia/vo/ListRoleVo.java

@@ -0,0 +1,20 @@
+package com.nokia.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class ListRoleVo {
+    @Schema(description = "角色名称", example = "工单查询")
+    private String roleName;
+    @Schema(description = "系统id", example = "flow")
+    private String system;
+    @Schema(description = "系统名称", example = "流程")
+    private String systemName;
+    @Schema(description = "角色说明")
+    private String roleDescription;
+}