package com.zjrs.ggfw.shbzk.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.shbzk.bpo.ShbzkBPO;
import com.zjrs.ggfw.shbzk.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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("社会保障卡服务")
@RestController
@RequestMapping("/api/shbzk/comm")
public class ShbzkController {
    /**
     * 日志
     */
    private static final Logger LOG = LoggerFactory.getLogger(ShbzkController.class);
    
    @Resource
    private ShbzkBPO shbzkBPO;
    @ApiOperation(value = "查询社会保障卡号码", notes = "查询社会保障卡号码")
    @PostMapping("/getShbzkNum")
    public AjaxResponse getShbzkNum(@RequestBody @Validated FwwdQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
        }
        try {
            ajaxResponse = shbzkBPO.getShbzkNum(dto);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上社保卡列表查询", notes = "网上社保卡列表查询")
    @PostMapping("/getShbzkList")
    public AjaxResponse getShbzkList(@RequestBody @Validated ShbzkListQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getShbzkList(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }


    @ApiOperation(value = "网上社保卡查询", notes = "网上社保卡查询")
    @PostMapping("/getShbzk")
    public AjaxResponse getShbzk(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "制卡进度查询", notes = "制卡进度查询")
    @PostMapping("/getShbzkZkjd")
    public AjaxResponse getShbzkZkjd(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getShbzkZkjd(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上申请社保卡", notes = "网上申请社保卡")
    @PostMapping("/applyShbzk")
    public AjaxResponse applyShbzk(@RequestBody @Validated ShbzkDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.applyShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上补换社保卡", notes = "网上补换社保卡")
    @PostMapping("/changeShbzk")
    public AjaxResponse changeShbzk(@RequestBody @Validated ShbzkDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.changeShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "修改社保卡信息", notes = "修改社保卡信息")
    @PostMapping("/editShbzk")
    public AjaxResponse editShbzk(@RequestBody @Validated ShbzkEditDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.editShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上临时挂失", notes = "网上临时挂失")
    @PostMapping("/reportLoss")
    public AjaxResponse reportLoss(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.setShbzk("网上临时挂失",dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上正式挂失", notes = "网上正式挂失")
    @PostMapping("/formalReportLoss")
    public AjaxResponse formalReportLoss(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.setShbzk("网上正式挂失",dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上解除挂失", notes = "网上解除挂失")
    @PostMapping("/removeLoss")
    public AjaxResponse removeLoss(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.setShbzk("网上解除挂失",dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上社保卡注销", notes = "网上社保卡注销")
    @PostMapping("/cancelShbzk")
    public AjaxResponse cancelShbzk(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.setShbzk("网上社保卡注销",dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "社保卡网上领卡启用", notes = "社保卡网上领卡启用")
    @PostMapping("/startUseShbzkOnline")
    public AjaxResponse startUseShbzkOnline(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.startUseShbzkOnline(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "社保卡领卡启用", notes = "社保卡领卡启用")
    @PostMapping("/startUseShbzk")
    public AjaxResponse startUseShbzk(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.startUseShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "网上撤销申请", notes = "网上撤销申请")
    @PostMapping("/cancelApplication")
    public AjaxResponse cancelApplication(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.cancelApplication(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "转换社会保障号", notes = "转换社会保障号")
    @PostMapping("/getShbzh")
    public AjaxResponse getShbzh(@RequestBody @Validated ShbzhQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getShbzh(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "申请资格校验", notes = "申请资格校验")
    @PostMapping("/checkApplication")
    public AjaxResponse checkApplication(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.checkApplication(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "取认证相片", notes = "取认证相片")
    @PostMapping("/getPhoto")
    public AjaxResponse getPhoto(@RequestBody @Validated PhotoQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getPhoto(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "服务网点查询", notes = "服务网点查询")
    @PostMapping("/getServiceBank")
    public AjaxResponse getServiceBank(@RequestBody @Validated ServiceBankQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.getServiceBank(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "查询社保卡服务网点", notes = "查询社保卡服务网点")
    @PostMapping("/querySbkfwwd")
    public AjaxResponse querySbkfwwd(@RequestBody @Validated FwwdQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.querySbkfwwd(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "社保卡全国鉴权", notes = "社保卡全国鉴权")
    @PostMapping("/checkShbzk")
    public AjaxResponse checkShbzk(@RequestBody @Validated ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = shbzkBPO.checkShbzk(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "查询卡状态")
    @PostMapping("/queryKzt")
    public AjaxResponse queryKzt(@RequestBody @Valid ShbzkQueryDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
        }
        try {
            return shbzkBPO.queryKzt(dto);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}    