lrj
4 天以前 4fa9591629721797386fc11836e3a9deb69cd58c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.rongyichuang.role.api;
 
import com.rongyichuang.role.dto.response.RoleResponse;
import com.rongyichuang.role.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;
 
import java.util.List;
 
/**
 * 角色GraphQL API控制器
 */
@Controller
public class RoleGraphqlApi {
 
    @Autowired
    private RoleService roleService;
 
    /**
     * 获取所有角色列表
     */
    @QueryMapping
    public List<RoleResponse> roles() {
        return roleService.getAllRoles();
    }
 
    /**
     * 获取所有启用状态的角色
     */
    @QueryMapping
    public List<RoleResponse> activeRoles() {
        return roleService.getAllActiveRoles();
    }
 
    /**
     * 根据ID获取角色详情
     */
    @QueryMapping
    public RoleResponse role(@Argument Long id) {
        return roleService.getRoleById(id).orElse(null);
    }
 
    /**
     * 根据角色代码获取角色
     */
    @QueryMapping
    public RoleResponse roleByCode(@Argument String code) {
        return roleService.getRoleByCode(code).orElse(null);
    }
 
    /**
     * 根据状态获取角色
     */
    @QueryMapping
    public List<RoleResponse> rolesByState(@Argument Integer state) {
        return roleService.getRolesByState(state);
    }
 
    /**
     * 根据名称模糊查询角色
     */
    @QueryMapping
    public List<RoleResponse> rolesByName(@Argument String name) {
        return roleService.searchRolesByName(name);
    }
}