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.GrxxglBPO;
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/grxx")
public class GrxxglController {
    private static final Logger LOG = LoggerFactory.getLogger(GrxxglController.class);

    @Resource
    private GrxxglBPO grxxglBPO;

    @ApiOperation(value = "个人信息查询", notes = "个人信息查询")
    @PostMapping(value = "/getGrxxList")
    public AjaxResponse getGrxxList(@RequestBody @Valid GrxxQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", grxxglBPO.getGrxxList(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 = "/saveGrxx")
    public AjaxResponse saveGrxx(@RequestBody @Valid GrxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("ztid", grxxglBPO.saveGrxx(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 = "/saveGrjbxx")
    public AjaxResponse saveGrjbxx(@RequestBody @Valid GrjbxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("ztid", grxxglBPO.saveGrjbxx(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 = "/getGrxx")
    public AjaxResponse getGrxx(@RequestBody @Valid JbxxglCommonDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", grxxglBPO.getGrxx(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 = "/getGrjbxxLog")
    public AjaxResponse getGrjbxxLog(@RequestBody @Valid GrLogQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", grxxglBPO.getGrjbxxLog(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;
    }
}
