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.sooka.system.domain.TUPeoplemarryinfosingle;
import com.util.HttpUtil2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sooka.system.mapper.TUPeoplemarryinfodoubleMapper;
import com.sooka.system.domain.TUPeoplemarryinfodouble;
import com.sooka.system.service.ITUPeoplemarryinfodoubleService;

import javax.annotation.Resource;

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

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

    /**
     * 查询国家民政部-婚姻信息（双方）-数据查询接口列表
     *
     * @param tUPeoplemarryinfodouble 国家民政部-婚姻信息（双方）-数据查询接口
     * @return 国家民政部-婚姻信息（双方）-数据查询接口
     */
    @Override
    public List<TUPeoplemarryinfodouble> selectTUPeoplemarryinfodoubleList(TUPeoplemarryinfodouble tUPeoplemarryinfodouble)
    {

        Map map = new HashMap();
        map.put("secretKey", tUPeoplemarryinfodouble.getSecretKey());
        map.put("intCode", "00003");
        map.put("Content-Type", "application/json");
//        String params = "{\"certNumberMan\":\""+tUPeoplemarryinfodouble.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfodouble.getNameman()+"\",\"certNumberWoman\":\""+tUPeoplemarryinfodouble.getCertnumberwoman()+"\",\"nameWoman\":\""+tUPeoplemarryinfodouble.getNamewoman()+"\"}";
        String params = "{\"certNumMan\":\""+tUPeoplemarryinfodouble.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfodouble.getNameman()+"\",\"certNumWoman\":\""+tUPeoplemarryinfodouble.getCertnumberwoman()+"\",\"nameWoman\":\""+tUPeoplemarryinfodouble.getNamewoman()+"\"}";
//        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 {
            TUPeoplemarryinfodouble bean = new TUPeoplemarryinfodouble();
//            String result = HttpUtil2.doPost("http://localhost:88/api/test/peoplemarryInfodouble", params,map);
            String result = HttpUtil2.doPost("http://172.24.5.241:6689/mz/queryMutualVerification", params,map);
            System.out.println(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(tUPeoplemarryinfodouble.getCertnumberman());
                bean.setNameman(tUPeoplemarryinfodouble.getNameman());
                bean.setCertnumberwoman(tUPeoplemarryinfodouble.getCertnumberwoman());
                bean.setNamewoman(tUPeoplemarryinfodouble.getNamewoman());
                bean.setCode(code);
                bean.setMessage(message);
                bean.setResult(r);
                ls.add(bean);
            }

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







//        return tUPeoplemarryinfodoubleMapper.selectTUPeoplemarryinfodoubleList(tUPeoplemarryinfodouble);
    }

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

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

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

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