package com.zjrs.ggfw.sggfw.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.sggfw.bpo.ZgrzBPO;
import com.zjrs.ggfw.sggfw.dto.ZgrzDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
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 java.net.SocketTimeoutException;

@Api(tags = "省公共服务接口:资格认证")
@RestController
@RequestMapping("/api/sggfw/zgrz")
public class ZgrzController {
    private static final Logger LOG = LoggerFactory.getLogger(ZgrzController.class);
    @Resource
    private ZgrzBPO zgrzBPO;

    @ApiOperation(value = "养老资格认证")
    @PostMapping("/authenticateTerminal")
    public AjaxResponse authenticateTerminal(@RequestBody @Valid ZgrzDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
        }
        try {
            return zgrzBPO.authenticateTerminal(dto);
        } catch (SocketTimeoutException e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("请求超时，请稍后重试");
        }catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
