package com.zjrs.ggfw.sggfw.bpo.impl;

import com.alibaba.fastjson.JSONObject;
import com.yinhai.bcpcs.exceptions.ClientException;
import org.mohrss.leaf.core.framework.domain.bpo.impl.BPOImpl;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.sggfw.bpo.ZgrzBPO;
import com.zjrs.ggfw.sggfw.dto.ZgrzDTO;
import com.zjrs.ggfw.sggfw.util.SggfwConfig;
import com.zjrs.ggfw.sggfw.util.SggfwInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class ZgrzBPOImpl  extends BPOImpl implements ZgrzBPO {

    @Autowired
    SggfwConfig config;
    @Override
    public AjaxResponse authenticateTerminal(ZgrzDTO dto) throws ClientException, IOException {
        AjaxResponse ajaxResponse = new AjaxResponse();
        Map<String, Object> p = new HashMap<String, Object>();
        p.put("SBID00", config.getSbid00());//地市
        p.put("AAC147", dto.getAac002());//身份证
        p.put("AAC003", dto.getAac003());//姓名
        p.put("AAC058","01");
        p.put("CJSBZ0",config.getKey());
        p.put("imgBase64",dto.getBase64Str());
        Map<Object,Object> m= SggfwInterface.qqjk(p,config,"ylz_authenticateTerminal");
        JSONObject jsonObject = JSONObject.parseObject(m.get("data").toString());
        String recordcount=jsonObject.get("errorCode").toString();
        if(!recordcount.equals("00")){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(jsonObject.get("message").toString());
        }else{
            ajaxResponse.setMsg(jsonObject.get("message").toString());
        }
        return ajaxResponse;
    }
}
