package com.gz.controller.system;

import cn.hutool.core.lang.tree.Tree;
import com.github.pagehelper.PageInfo;
import com.gz.core.annotation.TraceLog;
import com.gz.core.exception.BusinessException;
import com.gz.dto.system.DictDTO;
import com.gz.service.system.DictService;
import com.gz.vo.system.DictVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author LiuchangLan
 * @date 2020/9/7 10:21
 */
@RestController
@RequestMapping("system/dict")
public class DictController {

    @Resource
    private DictService dictService;

    /**
     * @description 增
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("insert")
    @TraceLog(module = "字典管理",business = "新增字典")
    public Integer insert(@RequestBody DictDTO dictDTO) throws BusinessException {
        return dictService.insert(dictDTO);
    }

    /**
     * @description 删
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @DeleteMapping("delete")
    @TraceLog(module = "字典管理",business = "删除字典")
    public Integer delete(Integer id){
        return dictService.delete(id);
    }

    /**
     * @description 改
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("update")
    @TraceLog(module = "字典管理",business = "修改字典")
    public Integer update(@RequestBody DictDTO dictDTO) throws BusinessException {
        return dictService.update(dictDTO);
    }

    /**
     * @description 查(给分页参数查分页 没给查全部)
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @GetMapping("selectByPage")
    @TraceLog(module = "字典管理",business = "查找字典列表")
    public PageInfo<DictDTO> select(DictVO dictVO){
        return dictService.selectByPage(dictVO);
    }

    /**
     * @description 根据主键查询
     * @author LiuChangLan
     * @since 2020/9/4 16:36
     */
    @GetMapping("selectByPrimaryKey")
    @TraceLog(module = "字典管理",business = "查询字典详细信息")
    public DictDTO selectByPrimaryKey(Integer id){
        return dictService.selectByPrimaryKey(id);
    }

    /**
     * @description 查
     * @author LiuChangLan
     * @since 2020/9/7 10:28
     */
    @GetMapping("select")
    @TraceLog(module = "字典管理",business = "查询素有字典")
    public List<DictDTO> select(){
        return dictService.select();
    }

    /**
     * @description 获取字典树
     * @author LiuChangLan
     * @since 2020/9/7 14:36
     */
    @GetMapping("getDictTree")
    @TraceLog(module = "字典管理",business = "查询字典树列表")
    List<Tree<String>> getDictTree(){
        return dictService.getDictTree();
    }

    /**
     * @description 根据code查询所有选项
     * @author LiuChangLan
     * @since 2020/9/7 16:57
     */
    @GetMapping("selectDictByCode")
    @TraceLog(module = "字典管理",business = "查询固定code的子字典")
    List<DictDTO> selectDictByCode(String code){
        return dictService.selectDictByCode(code);
    }

    @GetMapping("selectMiJiRole")
    List<Map> selectMiJiRole(Integer roleId){
        return dictService.selectMiJiRole(roleId);
    }
}
