/*
 * @Author: Kane
 * @Date: 2023-05-25 12:09:27
 * @LastEditors: Kane
 * @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/controllers/NewCitizen/QueryResultController.java
 * @Description: 
 * 
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 */

package com.cpic.xim.web.controllers.NewCitizen;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestBody;

import com.cpic.xim.utils.newcitizen.*;

// 9ILpXKFSHckH1g7h

@Controller
public class QueryResultController
{
    @RequestMapping("/save_score.do")
    public void saveQueryResult(HttpServletResponse response, @RequestBody QueryResultRequest result )
    {
        response.setStatus(HttpServletResponse.SC_OK);
    }

    @RequestMapping("/identify.do")
    @ResponseBody
    public IdentifyNewCitizenResponse identifyNewCitizen(@RequestBody IdentifyNewCitizenRequest request )
    {
        String idCardNo = request.getIdCardNo();
        String name = request.getName();
        IdentifyResult result = null;
        IdentifyNewCitizenResponse response = new IdentifyNewCitizenResponse();
        
        try
        {
            result = NewCitizenUitls.identifyNewCitizen(idCardNo, name);

            response.setSuccess(true);
            response.setMessage("调用成功");
            response.setCitizenType(result.getCitizenType());
            response.setScore(result.getScore());
            response.setExpireDate(result.getExpireDate());
        }
        catch ( Exception error )
        {
            System.out.println( error.getMessage() );

            response.setSuccess(false);
            response.setMessage(error.getMessage());
        }

        return response;
    }
}