package com.dk.mdm.controller.mst;

import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.model.pojo.mst.Role;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.query.mst.RoleQuery;
import com.dk.mdm.model.response.mst.RoleResponse;

import com.dk.mdm.model.vo.mst.RoleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.dk.mdm.service.mst.RoleService;

import java.util.List;

import static net.sf.jsqlparser.util.validation.metadata.NamedObject.role;


@Api(tags = "角色API接口")
@RestController
@RequestMapping("/mst/role")
public class RoleController{

    public BaseService<Role> getService() {
        return roleService;
    }

    @Autowired
    private RoleService roleService;

    /**
     * @desc : 条件查询
     * @author : 于继渤
     * @date : 2024/2/26 10:36
     */
    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<RoleResponse>> selectByCond(@RequestBody RoleQuery roleQuery) {
        return roleService.selectByCond(roleQuery);
    }

    /**
     * @desc : 新建角色权限
     * @author : 于继渤
     * @date : 2023/1/5 9:39
     */
    @ApiOperation( value = "新建角色(权限)", notes = "新建角色权限" )
    @PostMapping({"insert"})
    public ResponseResultVO<?> insert(@RequestBody RoleVo roleVO) {
        return roleService.saveRole(roleVO);
    }

    /**
     * @desc : 编辑角色权限
     * @author : 于继渤
     * @date : 2023/1/5 9:39
     */
    @ApiOperation( value = "编辑角色权限(编辑角色权限)", notes = "编辑角色权限" )
    @PostMapping({"update"})
    public ResponseResultVO<?> update(@RequestBody RoleVo roleVO) {
        return roleService.updateRole(roleVO);
    }
    /**
     * @desc : 查询
     * @author : 于继渤
     * @date : 2023/1/5 9:39
     */
    @PostMapping({"/{id}"})
    public ResponseResultVO<?> selectById(@PathVariable String id) {
        return roleService.selectById(id);
    }




    /**
     * @desc : 停用
     * @author : 于继渤
     * @date :  2023/1/4 9:39
     */
    @PostMapping("disable/{id}")
    public ResponseResultVO<Boolean> disable(@PathVariable String id) {
        return roleService.disable(id);
    }

    /**
     * @desc : 启用
     * @author : 于继渤
     * @date :  2023/1/4 9:39
     */
    @PostMapping("enable/{id}")
    public ResponseResultVO<Boolean> enable(@PathVariable String id) {
        return roleService.enable(id);
    }

    /**
     * @desc   : 新建角色
     * @author : 常皓宁
     * @date   : 2024/3/7 8:37
     */
    @ApiOperation( value = "新建角色(权限)", notes = "新建角色权限" )
    @PostMapping({"insert_web"})
    public ResponseResultVO<?> insertWeb(@RequestBody RoleVo roleVO) {
        return roleService.insert(roleVO);
    }

    /**
     * @desc   : 编辑角色
     * @author : 常皓宁
     * @date   : 2024/3/7 8:37
     */
    @ApiOperation( value = "新建角色(权限)", notes = "新建角色权限" )
        @PostMapping({"update_web"})
    public ResponseResultVO<?> updateWeb(@RequestBody RoleVo roleVO) {
        return roleService.update(roleVO);
    }

    /**
     * @desc : 批量启用
     * @author : 周兴
     * @date : 2023/3/7 10:34
     */
    @ApiOperation(value = "批量启用", notes = "批量启用")
    @PostMapping("enable_batch")
    public ResponseResultVO<Boolean> enableBatch(@RequestBody List<String> ids) {
        return this.getService().enableBatch(ids);
    }

    /**
     * @desc : 批量停用
     * @author : 周兴
     * @date : 2023/3/7 10:34
     */
    @ApiOperation(value = "批量停用", notes = "批量停用")
    @PostMapping("disable_batch")
    public ResponseResultVO<Boolean> disableBatch(@RequestBody List<String> ids) {
        return this.getService().disableBatch(ids);
    }
}
