package com.zjrs.ggfw.dzsbk.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.dzsbk.bpo.SignBPO;
import com.zjrs.ggfw.dzsbk.dto.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api("电子社保卡服务")
@RestController
@RequestMapping("/api/dzsbk/comm")
public class DzsbkController {
    /**
     * 日志
     */
    private static final Logger LOG = LoggerFactory.getLogger(DzsbkController.class);
    
    @Resource
    private SignBPO signBPO;
    
    @ApiOperation(value = "获取自助终端电子社保卡签名", notes = "获取自助终端电子社保卡签名")
    @PostMapping("/getZzzdSignature")
    public AjaxResponse getZzzdSignature(@RequestBody @Validated SignDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getZzzdSignature(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    
    @ApiOperation(value = "获取自助终端电子社保卡用户", notes = "获取自助终端电子社保卡用户")
    @PostMapping("/getZzzdDzsbkUser")
    public AjaxResponse getZzzdDzsbkUser(@RequestBody @Validated SecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getZzzdDzsbkUser(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取小程序用户签发信息", notes = "获取小程序用户签发信息")
    @GetMapping("/getMiniRsDzsbkQf")
    public AjaxResponse getMiniRsDzsbkQf() {
    	AjaxResponse ajaxResponse = new AjaxResponse();
    	try {
        	ajaxResponse = signBPO.getMiniRsDzsbkQf();
    	} catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;	
    }
    
    @ApiOperation(value = "获取小程序电子社保卡签名", notes = "获取小程序电子社保卡签名")
    @PostMapping("/getMiniSignature")
    public AjaxResponse getMiniSignature(@RequestBody @Validated SignDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getMiniSignature(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "保存小程序电子社保卡签发用户", notes = "保存小程序电子社保卡签发用户")
    @PostMapping("/saveMiniDzsbkUser")
    public AjaxResponse saveMiniDzsbkUser(@RequestBody @Validated MiniProgramQfUserDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.saveMiniDzsbkUser(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "小程序解析签发成功返回获取签发号", notes = "小程序解析签发成功返回获取签发号")
    @PostMapping("/saveMiniSignNo")
    public AjaxResponse saveMiniSignNo(@RequestBody @Validated SecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.saveMiniSignNo(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "获取微信公众号用户签发数据", notes = "获取微信公众号用户签发数据")
    @PostMapping("/getWeChatDzsbkQf")
    public AjaxResponse getWeChatDzsbkQf(@RequestBody @Validated WeChatQueryQfDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getWeChatDzsbkQf(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "保存微信公众号签发用户信息", notes = "保存微信公众号签发用户信息")
    @PostMapping("/saveWeChatDzsbkUser")
    public AjaxResponse saveWeChatDzsbkUser(@RequestBody @Validated SecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.saveWeChatDzsbkUser(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "微信公众号获取签名串", notes = "微信公众号获取签名串")
    @PostMapping("/getWeChatSignature")
    public AjaxResponse getWeChatSignature(@RequestBody @Validated SecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getWeChatSignature(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "微信公众号解析签发成功返回获取签发号", notes = "微信公众号解析签发成功返回获取签发号")
    @PostMapping("/saveWeChatSignNo")
    public AjaxResponse saveWeChatSignNo(@RequestBody @Validated WeChatSecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.saveWeChatSignNo(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "微信公众号解除绑定电子社保卡", notes = "微信公众号解除绑定电子社保卡")
    @PostMapping("/removeWeChatSignNo")
    public AjaxResponse removeWeChatSignNo(@RequestBody @Validated WeChatSecurityDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.removeWeChatSignNo(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "微信公众号获取微信实名认证结果", notes = "微信公众号获取微信实名认证结果")
    @PostMapping("/getWeChatRealName")
    public AjaxResponse getWeChatRealName(@RequestBody @Validated RealNameAuthDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = signBPO.getWeChatRealName(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "获取用户信息(解析电子社保卡二维码)", notes = "获取用户信息(解析电子社保卡二维码)")
    @PostMapping("/getUserByEsscNo")
    public AjaxResponse getUserByEsscNo(@RequestBody @Validated EsscnoDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse = signBPO.getUserByEsscNo(dto);
        return ajaxResponse;
    }
}    