VrRoleController.java 2.53 KB
package com.glsx.usedcar.controller;

import com.glsx.usedcar.module.vrsystem.service.VrRoleService;
import com.glsx.usedcar.module.vrsystem.vo.VrRoleAddVO;
import com.glsx.usedcar.module.vrsystem.vo.VrRoleRespVO;
import com.glsx.usedcar.module.vrsystem.vo.VrRoleUpdateVO;
import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * VR角色管理接口
 */
@Slf4j
@RestController
@RequestMapping("/rest/system/role")
@RequiredArgsConstructor
@Tag(name = "角色管理接口", description = "角色(账号类型)的增删改查操作")
public class VrRoleController {

    private final VrRoleService vrRoleService;

    @GetMapping("/list")
    @Operation(summary = "角色列表", description = "查询所有角色列表(按排序字段升序)")
    public BaseResp<List<VrRoleRespVO>> listRoles() {
        return BaseResp.success(vrRoleService.listRoles());
    }

    @GetMapping("/detail")
    @Operation(summary = "角色详情", description = "根据ID查询角色详情")
    public BaseResp<VrRoleRespVO> getRoleDetail(
            @Parameter(description = "角色ID", required = true, example = "1") @RequestParam Long id) {
        return BaseResp.success(vrRoleService.getRoleById(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增角色", description = "新增角色,角色编码需唯一")
    public BaseResp<Void> addRole(@Valid @RequestBody VrRoleAddVO addVO) {
        vrRoleService.addRole(addVO);
        return BaseResp.success();
    }

    @PostMapping("/update/{id}")
    @Operation(summary = "修改角色", description = "修改角色信息(不支持修改角色编码)")
    public BaseResp<Void> updateRole(
            @Parameter(description = "角色ID", required = true, example = "1") @PathVariable Long id,
            @RequestBody VrRoleUpdateVO updateVO) {
        vrRoleService.updateRole(id, updateVO);
        return BaseResp.success();
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除角色", description = "逻辑删除角色,角色下有用户时不可删除")
    public BaseResp<Void> deleteRole(
            @Parameter(description = "角色ID", required = true, example = "1") @PathVariable Long id) {
        vrRoleService.deleteRole(id);
        return BaseResp.success();
    }
}