RoleController.java 2.5 KB
Newer Older
X
xiongchun 已提交
1 2
package com.pulanit.pangu.admin.web.system;

X
xiongchun 已提交
3
import cn.hutool.core.lang.Assert;
X
xiongchun 已提交
4
import cn.hutool.core.lang.Console;
X
xiongchun 已提交
5
import com.gitee.pulanos.pangu.framework.common.model.PageResult;
X
xiongchun 已提交
6
import com.gitee.pulanos.pangu.framework.common.model.Result;
X
xiongchun 已提交
7 8 9
import com.pulanit.pangu.admin.system.api.entity.RoleEntity;
import com.pulanit.pangu.admin.system.api.param.RoleIn;
import com.pulanit.pangu.admin.system.api.service.RoleService;
X
xiongchun 已提交
10
import lombok.extern.slf4j.Slf4j;
X
xiongchun 已提交
11 12 13 14
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
X
xiongchun 已提交
15 16 17 18 19 20 21 22 23 24 25

/**
 * 角色
 *
 * @author xiongchun
 */
@Slf4j
@RestController
@RequestMapping("/api/system/role")
public class RoleController {

X
xiongchun 已提交
26 27 28
    @Reference(version = "1.0.0", group = "pangu-admin-system-app")
    private RoleService roleService;

X
xiongchun 已提交
29 30 31 32 33
    /**
     * 获取角色
     * @return
     */
    @GetMapping("/list")
X
xiongchun 已提交
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
    public Result<PageResult<RoleEntity>> list(RoleIn roleIn) {
        PageResult<RoleEntity> pageResult = roleService.list(roleIn);
        return Result.success(pageResult);
    }

    /**
     * 新增
     *
     * @param roleEntity
     * @return
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestBody RoleEntity roleEntity) {
        roleService.add(roleEntity);
        return Result.success();
    }


    /**
     * 修改
     *
     * @param roleEntity
     * @return
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody RoleEntity roleEntity) {
X
xiongchun 已提交
60
        Assert.notNull(roleEntity.getId(), "角色 ID 不能为空");
X
xiongchun 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
        roleService.update(roleEntity);
        return Result.success();
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result<Void> delete(@RequestParam Long id) {
        Assert.notNull(id, "角色 ID 不能为空");
        roleService.delete(id);
        return Result.success();
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchDelete")
    public Result<Void> batchDelete(@RequestParam List<Long> ids) {
        Assert.notEmpty(ids, "角色 ID 不能为空");
        roleService.batchDelete(ids);
        return Result.success();
X
xiongchun 已提交
90 91
    }

X
xiongchun 已提交
92 93 94 95 96 97 98 99 100 101 102
    /**
     * 校验角色标识字段
     *
     * @return
     */
    @GetMapping("/validateRoleKey")
    public Result<Long> validateRoleKey(@RequestParam  String roleKey, @RequestParam  Long id) {
        long cnt = roleService.validateRoleKey(roleKey, id);
        return Result.success(cnt);
    }

X
xiongchun 已提交
103
}