package com.ruoyi.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.controller.req.WorksPageReq;
import com.ruoyi.response.ResponseData;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 字典值查询
 */
@Slf4j
@RestController
@RequestMapping("/api/dict")
@Api(tags = "字典值查询")
public class ApiDictController extends RyController {

    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 字典表详情
     * @param code
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/fineOne", method = RequestMethod.POST)
    @ApiOperation(value = "字典表详情")
    public ResponseData<SysDictData> fineOne(@RequestParam("code") @Valid @NotBlank(message = "code值不能为空") String code) {

        SysDictData sysDictData = new SysDictData();
        sysDictData.setCode(code);
        sysDictData.setStatus("0");
        List<SysDictData> list = iSysDictDataService.selectDictDataList(sysDictData);
        return ResponseData.success(list.isEmpty()?null:list.get(0));
    }

    /**
     * 字典表下级
     * @param code
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/fineList", method = RequestMethod.POST)
    @ApiOperation(value = "字典表下级")
    public ResponseData<List<SysDictData>> fineList(@RequestParam("code") @Valid @NotBlank(message = "code值不能为空") String code) {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(code);
        sysDictData.setStatus("0");
        List<SysDictData> list = iSysDictDataService.selectDictDataList(sysDictData);
        return ResponseData.success(list);
    }




}


