package com.cm.common.plugin.oauth.controller.apis.role;

import com.alibaba.fastjson.JSONArray;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.oauth.service.role.IRoleService;
import com.cm.common.result.ErrorResult;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: RoleController
 * @Description: 角色管理
 * @Author: WangGeng
 * @Date: 2020/1/9 17:04
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "职位管理")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/role")
public class RoleController extends AbstractController {

    @Autowired
    private IRoleService roleService;

    @ApiOperation(value = "zTree列表", notes = "zTree列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "上级ID", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listztreerole")
    public JSONArray listZTreeRole() throws SearchException {
        Map<String, Object> params = requestParams();
        String roleParentId = "0";
        if (!StringUtils.isBlank(params.get("id") == null ? null : params.get("id").toString())) {
            roleParentId = params.get("id").toString();
        }
        return roleService.listZTreeRole(roleParentId);
    }

}
