package com.njzscloud.supervisory.sys.dict.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.sys.dict.pojo.DictEntity;
import com.njzscloud.supervisory.sys.dict.pojo.ObtainDictDataResult;
import com.njzscloud.supervisory.sys.dict.service.DictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典表
 */
@Slf4j
@RestController
@RequestMapping("/dict")
@RequiredArgsConstructor
public class DictController {

    private final DictService dictService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody DictEntity dictEntity) {
        dictService.add(dictEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody DictEntity dictEntity) {
        dictService.modify(dictEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        dictService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<DictEntity> detail(@RequestParam Long id) {
        return R.success(dictService.detail(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<DictEntity>> paging(PageParam pageParam, DictEntity dictEntity) {
        return R.success(dictService.paging(pageParam, dictEntity));
    }


    /**
     * 获取字典数据
     */
    @GetMapping("/dict_data")
    public R<List<ObtainDictDataResult>> obtainDictData(@RequestParam String dictKey) {
        return R.success(dictService.obtainDictData(dictKey));
    }


}
