package com.sooka.system.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sooka.common.core.text.Convert;
import com.sooka.common.utils.DateUtils;
import com.util.HttpUtil;
import com.util.HttpUtil2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sooka.system.mapper.TUPeoplemarryinfosingleMapper;
import com.sooka.system.domain.TUPeoplemarryinfosingle;
import com.sooka.system.service.ITUPeoplemarryinfosingleService;

import javax.annotation.Resource;


/**
 * 国家民政部-婚姻信息（单方）-数据查询接口Service业务层处理
 *
 * @author lei
 * @date 2021-07-14
 */
@Service
public class TUPeoplemarryinfosingleServiceImpl implements ITUPeoplemarryinfosingleService
{
    @Resource
    private TUPeoplemarryinfosingleMapper tUPeoplemarryinfosingleMapper;

    /**
     * 查询国家民政部-婚姻信息（单方）-数据查询接口
     *
     * @param id 国家民政部-婚姻信息（单方）-数据查询接口ID
     * @return 国家民政部-婚姻信息（单方）-数据查询接口
     */
    @Override
    public TUPeoplemarryinfosingle selectTUPeoplemarryinfosingleById(String id)
    {
        return tUPeoplemarryinfosingleMapper.selectTUPeoplemarryinfosingleById(id);
    }

    /**
     * 查询国家民政部-婚姻信息（单方）-数据查询接口列表
     *
     * @param tUPeoplemarryinfosingle 国家民政部-婚姻信息（单方）-数据查询接口
     * @return 国家民政部-婚姻信息（单方）-数据查询接口
     */
    @Override
    public List<TUPeoplemarryinfosingle> selectTUPeoplemarryinfosingleList(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        Map map = new HashMap();
        map.put("secretKey", tUPeoplemarryinfosingle.getSecretKey());
        map.put("intCode", "00002");
        map.put("Content-Type", "application/json");
//        String params = "{\"certNumberMan\":\""+tUPeoplemarryinfosingle.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfosingle.getNameman()+"\"}";
        String params = "{\"certNumMan\":\""+tUPeoplemarryinfosingle.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfosingle.getNameman()+"\"}";
//        String params ="certNumberMan="+tUPeoplemarryinfosingle.getCertnumberman()+"&nameMan="+tUPeoplemarryinfosingle.getNameman();
        map.put("Authorization-Type", "Basic");
        map.put("Authorization", "Basic NjBlODQxNzQyZTIyMDE2NjUzYmQ3NmE4N2QxY2FjMzA6ODhlOWM0NzcxMWZkMTM5YjhiMGMyODlkZjBiMWI5YmQ=");
        map.put("Service-ID", "qNpU77");
        List ls = new ArrayList();
        try {
            TUPeoplemarryinfosingle bean = new TUPeoplemarryinfosingle();
//            String result = HttpUtil2.doPost("http://localhost:88/api/test/peoplemarryInfosingle", params,map);//原始的一期旧代码
//            String result = HttpUtil2.doPost("http://172.24.5.241:6689/v1/apigw/iam/cmca/get/peoplemarryInfosingle", params,map);//IAM方式
//            String result = HttpUtil2.doPost("http://172.24.5.241:6689/v1/apigw/app/cmca/get/peoplemarryInfosingle", params,map);//AK/SK方式
            String result = HttpUtil2.doPost("http://172.24.5.241:6689/mz/querySingleVerification", params,map);//mz/querySingleVerification
            System.out.println(tUPeoplemarryinfosingle.getCertnumberman()+"===婚姻单方certNumberMan");
            System.out.println(tUPeoplemarryinfosingle.getNameman()+"===婚姻单方nameMan");
            System.out.println(result+"===婚姻单方result");

            if(result != null){
                JSONObject jsonObject = JSONObject.parseObject(result);
                String code = jsonObject.getString("code");
                String message = jsonObject.getString("message");
                String data = jsonObject.getString("data");
                JSONObject data_obj =JSON.parseObject(data);
                String r = data_obj.getString("result");
                bean.setCertnumberman(tUPeoplemarryinfosingle.getCertnumberman());
                bean.setNameman(tUPeoplemarryinfosingle.getNameman());
                bean.setCode(code);
                bean.setMessage(message);
                bean.setResult(r);
                ls.add(bean);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return ls;
    }

    /**
     * 新增国家民政部-婚姻信息（单方）-数据查询接口
     *
     * @param tUPeoplemarryinfosingle 国家民政部-婚姻信息（单方）-数据查询接口
     * @return 结果
     */
    @Override
    public int insertTUPeoplemarryinfosingle(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        tUPeoplemarryinfosingle.setCreateTime(DateUtils.getNowDate());
        return tUPeoplemarryinfosingleMapper.insertTUPeoplemarryinfosingle(tUPeoplemarryinfosingle);
    }

    /**
     * 修改国家民政部-婚姻信息（单方）-数据查询接口
     *
     * @param tUPeoplemarryinfosingle 国家民政部-婚姻信息（单方）-数据查询接口
     * @return 结果
     */
    @Override
    public int updateTUPeoplemarryinfosingle(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        tUPeoplemarryinfosingle.setUpdateTime(DateUtils.getNowDate());
        return tUPeoplemarryinfosingleMapper.updateTUPeoplemarryinfosingle(tUPeoplemarryinfosingle);
    }

    /**
     * 删除国家民政部-婚姻信息（单方）-数据查询接口对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTUPeoplemarryinfosingleByIds(String ids)
    {
        return tUPeoplemarryinfosingleMapper.deleteTUPeoplemarryinfosingleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除国家民政部-婚姻信息（单方）-数据查询接口信息
     *
     * @param id 国家民政部-婚姻信息（单方）-数据查询接口ID
     * @return 结果
     */
    @Override
    public int deleteTUPeoplemarryinfosingleById(String id)
    {
        return tUPeoplemarryinfosingleMapper.deleteTUPeoplemarryinfosingleById(id);
    }
}
