package com.sckw.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sckw.core.exception.SystemException;
import com.sckw.core.model.page.PageHelperUtil;
import com.sckw.core.model.page.PageResult;
import com.sckw.core.utils.BeanUtils;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.KwsRole;
import com.sckw.system.model.vo.req.EditRoleReqVo;
import com.sckw.system.model.vo.req.UserBindRoleReqVo;
import com.sckw.system.model.vo.res.RoleResVo;
import com.sckw.system.service.KwsRoleService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;

/**
 * 角色
 * @author zk
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/kwsRole")
public class KwsRoleController {

    @Autowired
    private KwsRoleService kwsRoleService;

    /**
     * @param id 主键ID
     * @return
     * @description 根据主键查询
     * @author zk
     * @date 2023/5/30
     **/
    @GetMapping("/detail")
    public HttpResult selectByKey(Long id) throws SystemException {
        return HttpResult.ok(kwsRoleService.selectByKey(id));
    }

    /**
     * @param params {page：页数、pageSize：每页条数、。。。}
     * @return
     * @description 分页查询
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/select")
    public HttpResult select(@RequestBody HashMap params) throws SystemException {
        return HttpResult.ok(kwsRoleService.findPage(params));
    }

    /**
     * @param reqVo {name:角色名称}
     * @return
     * @description 新增
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/add")
    public HttpResult add(@Valid @RequestBody EditRoleReqVo reqVo) throws SystemException {
        kwsRoleService.add(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param reqVo {id：主键ID、name:角色名称}
     * @return
     * @description 更新
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/update")
    public HttpResult update(@Valid @RequestBody EditRoleReqVo reqVo) throws SystemException {
        kwsRoleService.update(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param ids {ids：主键ID（多个以逗号隔开）}
     * @return
     * @description 更新
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/dels")
    public HttpResult del(@RequestParam String ids) throws SystemException {
        kwsRoleService.deleteByKey(ids);
        return HttpResult.ok(HttpStatus.MSG_008);
    }

    /**
     * @param  reqVo 多个角色用","隔开
     * @return HttpResult
     * @desc: 用戶分配角色
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("userBindRole")
    public HttpResult userBindRole(@RequestBody UserBindRoleReqVo reqVo) throws SystemException {
        kwsRoleService.userBindRole(reqVo);
        return HttpResult.ok(HttpStatus.MSG_010);
    }
}
