package com.energy.manage.service.controller.dict;


import com.energy.manage.common.constant.controller.WebApiConstant;
import com.energy.manage.common.po.dict.DictConstantsPO;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.config.annotations.PassToken;
import com.energy.manage.service.controller.base.BaseServiceController;
import com.energy.manage.service.domain.dto.dict.DictConstantsQueryDto;
import com.energy.manage.service.domain.vo.dict.DictParentVo;
import com.energy.manage.service.service.dict.DictConstantsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Api(value = "DictContentsController", tags = "字典管理")
public class DictContentsController extends BaseServiceController {


    @Autowired
    private DictConstantsService dictConstantsService;


    @PostMapping(WebApiConstant.Dist.QUERY_DICT_LIST)
    @PassToken
    @ApiOperation(value = "获取字典列表")
    public ResultResp<List<DictConstantsPO>> getDictList(@RequestBody DictConstantsQueryDto dictConstantsQueryDto) {

        List<DictConstantsPO> data = dictConstantsService.getDictListByType(dictConstantsQueryDto.getDictType());
        return ResultResp.SUCCESS(data);
    }


    @PostMapping(WebApiConstant.Dist.REFRESH_DICT_CACHE_DATA)
    @PassToken
    @ApiOperation(value = "刷新字典缓存")
    public ResultResp refreshDictListAllCache() {

        dictConstantsService.refreshDictListAllCache();
        return ResultResp.SUCCESS();
    }


    @GetMapping(WebApiConstant.Dist.DICT_CHAIN_LIST)
    @PassToken
    @ApiOperation(value = "获取及联树结构字典 1 强基工具 2 传统高考 3 课程产品服务，科目选择")
    public ResultResp getDictReachChain(@RequestParam Integer type) {

        List<DictParentVo>  list = dictConstantsService.getDictReachChain(type);
        return ResultResp.SUCCESS(list);
    }

}
