package com.zjrs.zwnw.jbxxgl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import org.mohrss.leaf.core.framework.web.exception.AppException;
import com.zjrs.zwnw.jbxxgl.bpo.JbxxglCommonBPO;
import com.zjrs.zwnw.jbxxgl.dto.AreaDTO;
import com.zjrs.zwnw.portal.dto.common.CommonDictDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Api("基本信息管理-公共")
@RestController
@RequestMapping("/api/jbxxgl/jbxxglcommon")
public class JbxxglCommonController {
    private static final Logger LOG = LoggerFactory.getLogger(JbxxglCommonController.class);

    @Resource
    private JbxxglCommonBPO commonBPO;

    @ApiOperation(value = "获取行政区划机构树", notes = "根据条件查询行政区划机构树")
    @PostMapping(value = "/getXzqhTree")
    public AjaxResponse getXzqhTree(@RequestBody AreaDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<Object> result = commonBPO.getXzqhTree(dto);
            ajaxResponse.setAppcode("0");
            ajaxResponse.setMsg("操作成功");
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "获取字典项信息", notes = "根据条件查询消息列表1")
    @PostMapping(value = "/getJbxxDicts")
    public AjaxResponse getJbxxDicts(@RequestBody CommonDictDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, Object> result = commonBPO.getJbxxDicts(dto);
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "获取所属行业树", notes = "根据条件查询所属行业树")
    @PostMapping(value = "/getSshyTree")
    public AjaxResponse getSshyTree(@RequestBody AreaDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<Object> result = commonBPO.getSshyTree(dto);
            ajaxResponse.setAppcode("0");
            ajaxResponse.setMsg("操作成功");
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
