package com.zjrs.zwnw.sxgl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.sxgl.bpo.DictBPO;
import com.zjrs.zwnw.sxgl.dto.CllbDTO;
import com.zjrs.zwnw.sxgl.dto.DictDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Api("字典")
@RestController
@RequestMapping("/api/sxgl/dict")
public class DictController {
    private static final Logger LOG = LoggerFactory.getLogger(DictController.class);

    @Resource
    private DictBPO dictBPO;

    @ApiOperation(value = "获取字典", notes = "获取字典")
    @PostMapping("/getDicts")
    public AjaxResponse getDicts(@RequestBody DictDTO dto) {
        LOG.info("获取字典开始：" + Arrays.toString(dto.getDictArr()));
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, List> result = this.dictBPO.getDicts(dto);
            ajaxResponse.setData("data", result);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("获取字典结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "获取动态字典材料类别", notes = "获取动态字典材料类别")
    @GetMapping("/getCllb")
    public AjaxResponse getCllb(String ssbmmc) {
        LOG.info("获取动态字典材料类别开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<CllbDTO> result = this.dictBPO.getCllb(ssbmmc);
            ajaxResponse.setData("data", result);
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("获取动态字典材料类别结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "获取动态字典用户", notes = "获取动态字典用户")
    @GetMapping("/getOpers")
    public AjaxResponse getOpers(String ssbmmc) {
        LOG.info("获取动态字典用户开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        List<CllbDTO> result = this.dictBPO.getOpers(ssbmmc);
        ajaxResponse.setData("data", result);
        LOG.info("获取动态字典用户结束");
        return ajaxResponse;
    }

}
