package com.zjrs.zwnw.rlzysc.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.dto.AreaDTO;
import com.zjrs.zwnw.portal.dto.common.CommonDictDTO;
import com.zjrs.zwnw.rlzysc.bpo.RlzyScCommonBPO;
import com.zjrs.zwnw.rlzysc.dto.UseridForDwDTO;
import com.zjrs.zwnw.rlzysc.dto.UseridForGrDTO;
import com.zjrs.zwnw.rlzysc.po.RsGgfwUserPO;
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/rlzysc/common")
public class RlzyScCommonController {

    private static final Logger LOG = LoggerFactory.getLogger(RlzyScCommonController.class);

    @Resource
    private RlzyScCommonBPO rlzyScCommonBPO;

    @ApiOperation(value = "获取职业机构树", notes = "获取职业机构树")
    @PostMapping(value = "/getZyTree")
    public AjaxResponse getZyTree(@RequestBody AreaDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<Object> result = rlzyScCommonBPO.getZyTree(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;
    }

    /**
     * 获取静态字典
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取字典项信息", notes = "根据条件查询消息列表1")
    @PostMapping(value = "/getDicts")
    public AjaxResponse getDicts(@RequestBody CommonDictDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            Map<String, Object> result = rlzyScCommonBPO.getDicts(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 = "根据条件查询消息列表1")
    @PostMapping(value = "/getUseridForGr")
    public AjaxResponse getUseridForGr(@RequestBody UseridForGrDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            RsGgfwUserPO result = rlzyScCommonBPO.getUseridForGr(dto.getXm(),dto.getZjlx(),dto.getZjhm());
            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 = "/getUseridForDw")
    public AjaxResponse getUseridForDw(@RequestBody UseridForDwDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            RsGgfwUserPO result = rlzyScCommonBPO.getUseridForDw(dto.getDwmc(),dto.getTyshxydm());
            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;
    }
}
