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.DwxxglBPO;
import com.zjrs.zwnw.jbxxgl.dto.*;
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 jakarta.validation.Valid;


@Api("管理")
@RestController
@RequestMapping("/api/jbxxgl/dwxx")
public class DwxxglController {
    private static final Logger LOG = LoggerFactory.getLogger(DwxxglController.class);

    @Resource
    private DwxxglBPO dwxxglBPO;

    @ApiOperation(value = "单位信息查询", notes = "单位信息查询")
    @PostMapping(value = "/getDwxxList")
    public AjaxResponse getDwxxList(@RequestBody @Valid DwxxQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", dwxxglBPO.getDwxxList(dto));
            ajaxResponse.setData("pagenum", dto.getPagenum());
            ajaxResponse.setData("pagesize", dto.getPagesize());
        } 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 = "/saveDwxx")
    public AjaxResponse saveDwxx(@RequestBody @Valid DwxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("ztid", dwxxglBPO.saveDwxx(dto));
        } 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 = "/saveDwjbxx")
    public AjaxResponse saveDwjbxx(@RequestBody @Valid DwjbxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("ztid", dwxxglBPO.saveDwjbxx(dto));
        } 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 = "/getDwxx")
    public AjaxResponse getDwxx(@RequestBody @Valid JbxxglCommonDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", dwxxglBPO.getDwxx(dto));
        } 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 = "/getDwjbxxLog")
    public AjaxResponse getDwjbxxLog(@RequestBody @Valid DwLogQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", dwxxglBPO.getDwjbxxLog(dto));
            ajaxResponse.setData("pagenum", dto.getPagenum());
            ajaxResponse.setData("pagesize", dto.getPagesize());
        } 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;
    }
}
