package com.hz.pm.api.meta.controller;


import com.hz.pm.api.meta.manage.MetaManage;
import com.hz.pm.api.meta.model.po.ReqAddDictionaryPO;
import com.hz.pm.api.meta.model.po.ReqDictionaryListPO;
import com.hz.pm.api.meta.model.vo.ResDictionaryListVO;
import com.hz.pm.api.meta.validate.DictParamValidator;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liuxinxin
 * @since 2022-07-21
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/api/v1/meta/dictionary")
@Api(tags = "基础数据接口")
public class MetaDictionaryManageController {

    private final MetaManage metaManage;

    @PostMapping("/list")
    @ApiOperation("字典筛选数据返回")
    public List<ResDictionaryListVO> expertDictList(@RequestBody ReqDictionaryListPO request) {
        DictParamValidator.dictionaryRequestValidator(request);
        return metaManage.getDictionaryList(request);
    }

    @PostMapping("/common/list")
    @ApiOperation("通用字典筛选数据返回")
    public List<ResDictionaryListVO> commonDictList(@RequestBody ReqDictionaryListPO request) {
        DictParamValidator.dictionaryRequestValidator(request);
        return metaManage.commonDictList(request);
    }

    @PostMapping("/add/dictionary")
    @ApiOperation("添加字典值")
    @WebLog("添加字典值")
    public void addDictionary(@Valid @RequestBody ReqAddDictionaryPO req) {
        metaManage.addDictionary(req);
    }

    @PostMapping("/remove/dictionary/{dictionaryCode}")
    @ApiOperation("删除字典值")
    @WebLog("删除字典值")
    public void removeDictionary(@PathVariable String dictionaryCode) {
        metaManage.removeDictionary(dictionaryCode);
    }

}
