package com.uas.service.Impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.uas.core.support.GetProperties;
import com.uas.dao.*;
import com.uas.entity.*;
import com.uas.service.CustomerService;
import com.uas.utils.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @author koul
 * @email koul@usoftchina.com
 * @date 2020-10-27 9:03
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    private static Map<String,String> httpConfig = GetProperties.getAllProperty();
    private static String url = httpConfig.get("URL");
    private static String apikey = httpConfig.get("APIKEY");
    private static String company = httpConfig.get("company");
    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final static int size=50;
    private final static HashMap hender = new HashMap() {{
        put(httpConfig.get("henderKey"), httpConfig.get("henderValue"));
    }};

    @Autowired
    private BaseDao baseDao;
    @Autowired
    private BusinessDao businessDao;
    @Autowired
    private BusinessDetailDao businessDetailDao;
    @Autowired
    private BusinessChangeDao businessChangeDao;
    @Autowired
    private InvestorDao investorDao;
    @Autowired
    private InvestorRJDetailDao investorRJDetailDao;
    @Autowired
    private InvestorSJDetailDao investorSJDetailDao;
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private KtggDao ktggDao;
    @Autowired
    private KtggDetailDao ktggDetailDao;
    @Autowired
    private CpwsDao cpwsDao;
    @Autowired
    private CpwsDetailDao cpwsDetailDao;
    @Autowired
    private ExecutedPersonDao executedPersonDao;
    @Autowired
    private SxbzxrDao sxbzxrDao;
    @Autowired
    private JyycDao jyycDao;
    @Autowired
    private SswfDao sswfDao;
    @Autowired
    private QsjlDao qsjlDao;
    @Autowired
    private DcdyDao dcdyDao;
    @Autowired
    private DcdyDetailDao dcdyDetailDao;
    @Autowired
    private GqczDao gqczDao;
    @Autowired
    private SfxzDao sfxzDao;
    @Autowired
    private SsggDao ssggDao;
    @Autowired
    private DanBaoDao danBaoDao;

    /**
     * 获取所有分组
     * @return
     */
    private List<Group> getGroupAll(){
        Map<String, String> param = new HashMap<>();
        param.put("apikey",apikey);
        String group = httpResponse(url + httpConfig.get("group"), hender, param);
        if (group != null && !"[]".equals(group)) {
            return JSON.parseArray(group, Group.class);
        }
        return null;
    }

    /**
     * 获取所有客户统一信用编码
     * @return
     */
    @Override
    public List<String> getFollowingByGroup(){
        Map<String, String> param = new HashMap<>();
        param.put("apikey",apikey);
        param.put("from",Integer.toString(0));
        param.put("size",Integer.toString(1000));
        List<Group> groupAll = getGroupAll();
        if (groupAll!=null){
            List<String> list = new ArrayList<>();
            for (Group group:groupAll) {
                param.put("group_id",Long.toString(group.getId()));
                Map map = httpResponseBySize(url + httpConfig.get("following"), apikey, 0,1000, hender, param);
                if (map!=null&&map.get("data")!=null){
                    List<String> strings = JSON.parseArray(map.get("data").toString(), String.class);
                    list.addAll(strings);
                }
            }
            return list;
        }
        return null;
    }


    /**
     * 保存工商资料
     * @param company_id
     */
    @Async("taskExecutor")
    @Override
    //@Transactional
    public void saveBusiness(String company_id){
        /*deleteByCompanyId(company_id);*/
        Map<String, String> param = new HashMap<>();
        param.put("apikey", apikey);
        String s = httpResponse(url + company + "/" + company_id, hender, param);
        if (s != null) {
            Long fb_id=0L;
            int count = baseDao.getCountByCondition("FBBUSINESS", "fb_tyshxycode='" + company_id + "'");
                Business business = JSON.parseObject(s, Business.class);
            if (count>0){
                fb_id = Long.parseLong(baseDao.getFieldDataByCondition("FBBUSINESS", "fb_id", "fb_tyshxycode='" + company_id + "'").toString());
                baseDao.deleteByCondition("FBBUSINESSDETAIL","fbd_fbid="+fb_id);
                baseDao.execute("update fbbusiness set fb_evaluation='"+stringArraytoString(business.getFb_evaluation())+ "', fb_organizer='"+business.getFb_organizer()+"', fb_oldcode='"+business.getFb_oldcode()+"', " +
                        "fb_issuedate='"+business.getFb_issuedate()+"', fb_issueorgan='"+business.getFb_issueorgan()+"', fb_dxreason='"+business.getFb_dxreason()+"', fb_dxdate='"+business.getFb_dxdate()+"', " +
                        "fb_name='"+business.getFb_name()+"', fb_address='"+business.getFb_address()+"', fb_dzhy='"+business.getFb_dzhy()+"', fb_paidamount='"+business.getFb_paidamount()+"', " +
                        "fb_cldate='"+business.getFb_cldate()+ "', " + "fb_zxswhhr='"+business.getFb_zxswhhr()+"', fb_zxswhhrdb='"+business.getFb_zxswhhrdb()+"', fb_investors='"+business.getFb_investors()+"', fb_oldname='"+stringArraytoString(business.getFb_oldname())+"', fb_bzhname='"+business.getFb_bzhname()+"', fb_approveddate='"+business.getFb_approveddate()+"', fb_execution='"+business.getFb_execution()+"', fb_legalrepresentative='"+business.getFb_legalrepresentative()+"', fb_code='"+business.getFb_code()+"', fb_date='"+business.getFb_date()+"', fb_currency='"+business.getFb_currency()+"', fb_amount="+business.getFb_amount()+", " +
                        "fb_zdxdate='"+business.getFb_zdxdate()+"', fb_zxreason='"+business.getFb_zxreason()+"', fb_zxdate='"+business.getFb_zxdate()+"', fb_companyname='"+business.getFb_companyname()+"', fb_email='"+business.getFb_email()+"',fb_djdate='"+business.getFb_djdate()+"', fb_djorgan='"+business.getFb_djorgan()+"', fb_djstatus='"+business.getFb_djstatus()+"', fb_province='"+business.getFb_province()+"', " +
                        "fb_type='"+business.getFb_type()+"', fb_typecode='"+business.getFb_typecode()+"', fb_formation='"+business.getFb_formation()+"', fb_economicnature='"+business.getFb_economicnature()+"', fb_place='"+business.getFb_place()+"', fb_jyqxfrom='"+business.getFb_jyqxfrom()+"', " +
                        "fb_jyqxto='"+business.getFb_jyqxto()+"', fb_operators='"+business.getFb_operators()+"', fb_businessscope='"+business.getFb_businessscope()+"', fb_contactnumber='"+business.getFb_contactnumber()+"', fb_equipmentamount='"+business.getFb_equipmentamount()+
                        "', fb_level='"+business.getFb_level()+"', fb_principal='"+business.getFb_principal()+"', " +
                        "fb_qrdgsj='"+business.getFb_qrdgsj()+"', fb_chiefrepresentative='"+business.getFb_chiefrepresentative()+"',fb_gzstatus='正在关注' where  fb_id="+fb_id);
            }else {
                business.setFb_gzstatus("正在关注");
                business.setFb_gxdate(new Date());
                business.setFb_evaluation(stringArraytoString(business.getFb_evaluation()));
                business.setFb_oldname(stringArraytoString(business.getFb_oldname()));
                Business save = businessDao.save(business);
                fb_id = save.getFb_id();
            }
            JSONObject jsonObject = JSONObject.parseObject(s);
            Object objzcd = jsonObject.get("注册地");
            if (objzcd != null) {
                BusinessDetail zcd = JSON.parseObject(objzcd.toString(), BusinessDetail.class);
                zcd.setFbd_fbid(fb_id);
                zcd.setFbd_type("注册地");
                zcd.setFbd_detno(1);
                businessDetailDao.save(zcd);
            }
            Object objjyd = jsonObject.get("经营地");
            if (objjyd != null) {
                BusinessDetail zcd = JSON.parseObject(objjyd.toString(), BusinessDetail.class);
                zcd.setFbd_fbid(fb_id);
                zcd.setFbd_type("经营地");
                zcd.setFbd_detno(1);
                businessDetailDao.save(zcd);
            }
            Object objgp = jsonObject.get("股票");
            if (objgp != null && !"[]".equals(objgp.toString())) {
                List<BusinessDetail> gps = JSON.parseArray(objgp.toString(),
                        BusinessDetail.class);
                int detno = 1;
                for (BusinessDetail gp : gps) {
                    gp.setFbd_fbid(fb_id);
                    gp.setFbd_type("股票");
                    gp.setFbd_detno(detno);
                    detno = detno + 1;
                }
                businessDetailDao.save(gps);
            }
            int fbdaycount = baseDao.getCountByCondition("FBDAYCOUNT", "fdc_fbid="+fb_id);
            int fdcgsbgcount=0;
            int fdcInvestorcount=0;
            int fdcMembercount =0;
            int fdcKtggcount = 0;
            int fdcCpwscount = 0;
            int fdcZhixingcount = 0;
            int fdcShixincount = 0;
            int fdcJyyccount = 0;
            int fdcSswfcount = 0;
            int fdcQsjlcount = 0;
            int fdcDcdycount = 0;
            int fdcGqczcount = 0;
            int fdcSfxzcount = 0;
            int fdcSsggcount = 0;
            int fdcDanbaocount = 0;
            if (fbdaycount>0) {
                String sql="select * from (select * from FBDAYCOUNT where fdc_fbid="+fb_id+" order by fdc_date desc) where rownum<2";
                List<DayCount> dayCounts = baseDao.query(sql, DayCount.class);
                DayCount dayCount = dayCounts.get(0);
                fdcgsbgcount = dayCount.getFdc_gsbgcount();
                fdcInvestorcount = dayCount.getFdc_investorcount();
                fdcMembercount = dayCount.getFdc_membercount();
                fdcKtggcount = dayCount.getFdc_ktggcount();
                fdcCpwscount = dayCount.getFdc_cpwscount();
                fdcZhixingcount = dayCount.getFdc_zhixingcount();
                fdcShixincount = dayCount.getFdc_shixincount();
                fdcJyyccount = dayCount.getFdc_jyyccount();
                fdcSswfcount = dayCount.getFdc_sswfcount();
                fdcQsjlcount = dayCount.getFdc_qsjlcount();
                fdcDcdycount = dayCount.getFdc_dcdycount();
                fdcGqczcount = dayCount.getFdc_gqczcount();
                fdcSfxzcount = dayCount.getFdc_sfxzcount();
                fdcSsggcount = dayCount.getFdc_ssggcount();
                fdcDanbaocount = dayCount.getFdc_danbaocount();
            }
            Map<String, String> params = new HashMap<String, String>();
            params.put("apikey",apikey);
            params.put("size",Integer.toString(size));
            params.put("from",Integer.toString(0));
            int gsbgcount = saveBusinessChange(company_id, fb_id,fdcgsbgcount,params);
            int gsbgaddcount = gsbgcount - fdcgsbgcount;
            int investorcount = saveInvestor(company_id, fb_id, fdcInvestorcount,params);
            int investoraddcount = investorcount - fdcInvestorcount;
            int membercount = saveMember(company_id, fb_id, fdcMembercount,params);
            int memberaddcount = membercount - fdcMembercount;
            int ktggcount = saveKtgg(company_id, fb_id, fdcKtggcount,params);
            int ktggaddcount = ktggcount - fdcKtggcount;
            int cpwscount = saveCpws(company_id,fb_id,fdcCpwscount,params);
            int cpwsaddcount = cpwscount - fdcCpwscount;
            int zhixingcount = saveExecutedPerson(company_id,fb_id,fdcZhixingcount,params);
            int zhixingaddcount = zhixingcount - fdcZhixingcount;
            int shixincount = saveSxbzxr(company_id,fb_id,fdcShixincount,params);
            int shixinaddcount = shixincount - fdcShixincount;
            int jyyccount = saveJyyc(company_id,fb_id,fdcJyyccount,params);
            int jyycaddcount = jyyccount - fdcJyyccount;
            int sswfcount = saveSswf(company_id,fb_id,fdcSswfcount,params);
            int sswfaddcount = sswfcount - fdcSswfcount;
            int qsjlcount = saveQsjl(company_id,fb_id,fdcQsjlcount,params);
            int qsjladdcount = qsjlcount - fdcQsjlcount;
            int dcdycount = saveDcdy(company_id,fb_id,fdcDcdycount,params);
            int dcdyaddcount = dcdycount - fdcDcdycount;
            int gqczcount = saveGqcz(company_id,fb_id,fdcGqczcount,params);
            int gqczaddcount = gqczcount - fdcGqczcount;
            int sfxzcount = saveSfxz(company_id,fb_id,fdcSfxzcount,params);
            int sfxzaddcount = sfxzcount - fdcSfxzcount;
            int ssggcount = saveSsgg(company_id,fb_id,fdcSsggcount,params);
            int ssggaddcount = ssggcount - fdcSsggcount;
            int danbaocount = saveDanbao(company_id,fb_id,fdcDanbaocount,params);
            int danbaoaddcount = danbaocount - fdcDanbaocount;
            if (gsbgaddcount>0||investoraddcount>0||memberaddcount>0||ktggaddcount>0||cpwsaddcount>0||zhixingaddcount>0||shixinaddcount>0||jyycaddcount>0||sswfaddcount>0||qsjladdcount>0||dcdyaddcount>0||gqczaddcount>0||sfxzaddcount>0||ssggaddcount>0||danbaoaddcount>0) {
                int zczbbgaddcount = baseDao.getCountByCondition("fbbusinesschange", "fbc_changesdetail='注册资本(金)变更' and fbc_fbid=" + fb_id + " and nvl(fbc_changesdate,' ')=to_char(sysdate-1,'yyyy-MM-dd')");
                int tzrbgaddcount = baseDao.getCountByCondition("fbbusinesschange", "fbc_changesdetail='投资人(股权)变更' and fbc_fbid=" + fb_id + " and nvl(fbc_changesdate,' ')=to_char(sysdate-1,'yyyy-MM-dd')");
                int fddbraddcount = baseDao.getCountByCondition("fbbusinesschange", "fbc_changesdetail='法定代表人变更' and fbc_fbid=" + fb_id + " and nvl(fbc_changesdate,' ')=to_char(sysdate-1,'yyyy-MM-dd')");
                int ggbdaddcount = baseDao.getCountByCondition("fbbusinesschange", "fbc_changes='高管变动' and fbc_fbid=" + fb_id + " and nvl(fbc_changesdate,' ')=to_char(sysdate-1,'yyyy-MM-dd')");
                int jyfwbgaddcount = baseDao.getCountByCondition("fbbusinesschange", "fbc_changes='经营范围变更' and fbc_fbid=" + fb_id + " and nvl(fbc_changesdate,' ')=to_char(sysdate-1,'yyyy-MM-dd')");
                baseDao.execute("insert into FBDAYCOUNT (fdc_id ,fdc_date ,fdc_fbid ,fdc_tyshxycode ,fdc_name ," +
                        "fdc_gsbgaddcount ,fdc_gsbgcount ,fdc_zczbbgaddcount,fdc_tzrbgaddcount,fdc_fddbraddcount," +
                        "fdc_ggbdaddcount,fdc_jyfwbgaddcount,fdc_investoraddcount ,fdc_investorcount ," +
                        "fdc_memberaddcount ,fdc_membercount ,fdc_ktggaddcount ,fdc_ktggcount ,fdc_cpwsaddcount ," +
                        "fdc_cpwscount ,fdc_zhixingaddcount ,fdc_zhixingcount ,fdc_shixinaddcount ,fdc_shixincount ," +
                        "fdc_jyycaddcount ,fdc_jyyccount ,fdc_sswfaddcount ,fdc_sswfcount ,fdc_qsjladdcount ," +
                        "fdc_qsjlcount ,fdc_dcdyaddcount ,fdc_dcdycount ,fdc_gqczaddcount ,fdc_gqczcount ," +
                        "fdc_sfxzaddcount ,fdc_sfxzcount ,fdc_ssggaddcount ,fdc_ssggcount ,fdc_danbaoaddcount ," +
                        "fdc_danbaocount) values (FBDAYCOUNT_SEQ.nextval,sysdate-1," + fb_id + ",'" + company_id +
                        "','" + business.getFb_name() + "'," + gsbgaddcount + "," + gsbgcount + ","+zczbbgaddcount+","+tzrbgaddcount+","+fddbraddcount+","+ggbdaddcount+
                        ","+jyfwbgaddcount+"," + investoraddcount + "," + investorcount + "," + memberaddcount + "," + membercount +
                        "," + ktggaddcount + "," + ktggcount + "," + cpwsaddcount + "," + cpwscount + "," + zhixingaddcount + "," + zhixingcount + "," + shixinaddcount + "," + shixincount + "," + jyycaddcount + "," + jyyccount + "," + sswfaddcount + "," + sswfcount + "," + qsjladdcount + "," + qsjlcount + "," + dcdyaddcount + "," + dcdycount + "," + gqczaddcount + "," + gqczcount + "," + sfxzaddcount + "," + sfxzcount + "," + ssggaddcount + "," + ssggcount + "," + danbaoaddcount + "," + danbaocount + ")");
            }
            if (count==0){
                baseDao.callProcedure("SP_FBDAYCOUNT_INSERT",new Object[]{fb_id});
            }
        }
    }

    /**
     * 保存工商变更
     * @param company_id
     */
    private int saveBusinessChange(String company_id,Long id,int count,Map<String, String> params){
        Map gsbg = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gsbg"),
                apikey, count,size, hender, params);
        int total=0;
        if(gsbg!=null){
            total=gsbg.get("total")==null?0:Integer.parseInt(gsbg.get("total").toString());
            if(gsbg.get("data")!=null) {
                List<BusinessChange> businessChanges = JSON.parseArray(gsbg.get("data").toString(), BusinessChange.class);
                if (businessChanges != null && businessChanges.size() > 0) {
                    Object fbcdetno = baseDao.getFieldDataByCondition("FBBUSINESSCHANGE", "max(fbc_detno)",
                            "fbc_fbid="+id);
                    int detno = fbcdetno==null?1:Integer.parseInt(fbcdetno.toString())+1;
                    for (BusinessChange fbc : businessChanges) {
                        fbc.setFbc_detno(detno);
                        fbc.setFbc_tyshxycode(company_id);
                        fbc.setFbc_fbid(id);
                        detno = detno + 1;
                    }
                    businessChangeDao.save(businessChanges);
                }
            }
        }
        return total;
    }

    /**
     * 保存工商登记股东信息
     * @param company_id
     */
    private int saveInvestor(String company_id,Long id,int count,Map<String, String> params){
        Map investorMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("investor")
                , apikey, count,size, hender, params);
        int total=0;
        if (investorMap!=null){
            total=investorMap.get("total")==null?0:Integer.parseInt(investorMap.get("total").toString());
            if(investorMap.get("data")!=null) {
                Object fidetno = baseDao.getFieldDataByCondition("FBINVESTOR", "max(fi_detno)",
                        "fi_fbid="+id);
                int det=fidetno==null?1:Integer.parseInt(fidetno.toString())+1;
                for (Object obj:JSON.parseArray(investorMap.get("data").toString())) {
                    JSONObject jsonObject = JSON.parseObject(obj.toString());
                    Investor investor = JSON.parseObject(obj.toString(), Investor.class);
                    investor.setFi_detno(det);
                    investor.setFi_tyshxycode(company_id);
                    investor.setFi_fbid(id);
                    Investor save = investorDao.save(investor);
                    det=det+1;
                    Long fi_id = save.getFi_id();
                    Object sjmx = jsonObject.get("实缴明细");
                    if (sjmx!=null&&!"[]".equals(sjmx.toString())) {
                        List<InvestorSJDetail> sjDetails = JSON.parseArray(sjmx.toString(),
                                InvestorSJDetail.class);
                        Object fiddetno = baseDao.getFieldDataByCondition("FBINVESTORDETAIL", "max(fid_detno)",
                                "fid_type='实缴明细' and fid_fiid="+fi_id);
                        int detno=fiddetno==null?1:Integer.parseInt(fiddetno.toString())+1;
                        for (InvestorSJDetail investorSJDetail:sjDetails) {
                            investorSJDetail.setFid_detno(detno);
                            investorSJDetail.setFid_fiid(fi_id);
                            investorSJDetail.setFid_type("实缴明细");
                            detno=detno+1;
                        }
                        investorSJDetailDao.save(sjDetails);
                    }
                    Object rjmx = jsonObject.get("认缴明细");
                    if (rjmx!=null&&!"[]".equals(rjmx.toString())) {
                        List<InvestorRJDetail> rjDetails = JSON.parseArray(rjmx.toString(),InvestorRJDetail.class);
                        Object fiddetno = baseDao.getFieldDataByCondition("FBINVESTORDETAIL", "max(fid_detno)",
                                "fid_type='认缴明细' and fid_fiid="+fi_id);
                        int no=fiddetno==null?1:Integer.parseInt(fiddetno.toString())+1;
                        for (InvestorRJDetail investorRJDetail:rjDetails) {
                            investorRJDetail.setFid_detno(no);
                            investorRJDetail.setFid_fiid(fi_id);
                            investorRJDetail.setFid_type("认缴明细");
                            no=no+1;
                        }
                        investorRJDetailDao.save(rjDetails);
                    }
                }
            }
        }
        return total;
    }

    /**
     * 保存主要成员
     * @param company_id
     */
    private int saveMember(String company_id,Long id,int count,Map<String, String> params){
        Map memberMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("member")
                , apikey, count,size, hender, params);
        int total=0;
        if (memberMap!=null){
            total=memberMap.get("total")==null?0:Integer.parseInt(memberMap.get("total").toString());
            if(memberMap.get("data")!=null) {
                List<Member> members = JSON.parseArray(memberMap.get("data").toString(), Member.class);
                Object fmdetno = baseDao.getFieldDataByCondition("FBMEMBER", "max(fm_detno)",
                        "fm_fbid="+id);
                int detno=fmdetno==null?1:Integer.parseInt(fmdetno.toString())+1;
                for (Member member:members) {
                    member.setFm_tyshxycode(company_id);
                    member.setFm_fbid(id);
                    member.setFm_detno(detno);
                    detno=detno+1;
                }
                memberDao.save(members);
            }
        }
        return total;
    }

    /**
     * 保存开庭公告
     * @param company_id
     */
    private int saveKtgg(String company_id,Long id,int count,Map<String, String> params){
        Map ktggMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ktgg")
                , apikey, count,size, hender, params);
        int total=0;
        if (ktggMap!=null){
            total=ktggMap.get("total")==null?0:Integer.parseInt(ktggMap.get("total").toString());
            if(ktggMap.get("data")!=null) {
                Object fkdetno = baseDao.getFieldDataByCondition("FBKTGG", "max(fk_detno)",
                        "fk_fbid="+id);
                int detno=fkdetno==null?1:Integer.parseInt(fkdetno.toString())+1;
                for (Object obj:JSON.parseArray(ktggMap.get("data").toString())) {
                    JSONObject jsonObject = JSON.parseObject(obj.toString());
                    Ktgg ktgg = JSON.parseObject(obj.toString(), Ktgg.class);
                    ktgg.setFk_tyshxycode(company_id);
                    ktgg.setFk_fbid(id);
                    ktgg.setFk_entities(stringArraytoString(ktgg.getFk_entities()));
                    ktgg.setFk_otherroles(stringArraytoString(ktgg.getFk_otherroles()));
                    ktgg.setFk_plaintif(stringArraytoString(ktgg.getFk_plaintif()));
                    ktgg.setFk_party(stringArraytoString(ktgg.getFk_party()));
                    ktgg.setFk_defendant(stringArraytoString(ktgg.getFk_defendant()));
                    ktgg.setFk_detno(detno);
                    Ktgg save = ktggDao.save(ktgg);
                    detno=detno+1;
                    Long fk_id = save.getFk_id();
                    Object dsrDetail = jsonObject.get("当事人详情");
                    if (dsrDetail != null && !"[]".equals(dsrDetail.toString())) {
                        List<KtggDetail> ktggDetails = JSON.parseArray(dsrDetail.toString(), KtggDetail.class);
                        Object fkddetno = baseDao.getFieldDataByCondition("FBKTGGDETAIL", "max(fkd_detno)",
                                "fkd_type='当事人详情' and fkd_fkid="+fk_id);
                        int det=fkddetno==null?1:Integer.parseInt(fkddetno.toString())+1;
                        for (KtggDetail ktggdetail:ktggDetails) {
                            ktggdetail.setFkd_fkid(fk_id);
                            ktggdetail.setFkd_detno(det);
                            ktggdetail.setFkd_type("当事人详情");
                            ktggdetail.setFkd_otherroles(stringArraytoString(ktggdetail.getFkd_otherroles()));
                            det=det+1;
                        }
                        ktggDetailDao.save(ktggDetails);
                    }
                    Object ssdq = jsonObject.get("所属地区");
                    if (ssdq!=null){
                        KtggDetail ktggDetail = JSON.parseObject(ssdq.toString(), KtggDetail.class);
                        ktggDetail.setFkd_fkid(fk_id);
                        ktggDetail.setFkd_detno(1);
                        ktggDetail.setFkd_type("所属地区");
                        ktggDetailDao.save(ktggDetail);
                    }

                }
            }
        }
        return total;
    }

    /**
     * 保存裁判文书
     * @param company_id
     */
   private int saveCpws(String company_id,Long id,int count,Map<String, String> params){
       Map cpwsMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("cpws"), apikey, count,size,
               hender, params);
       int total=0;
       if (cpwsMap!=null){
           total=cpwsMap.get("total")==null?0:Integer.parseInt(cpwsMap.get("total").toString());
           if(cpwsMap.get("data")!=null) {
               Object fcdetno = baseDao.getFieldDataByCondition("FBCPWS", "max(fc_detno)",
                       "fc_fbid="+id);
               int detno=fcdetno==null?1:Integer.parseInt(fcdetno.toString())+1;
               for (Object obj:JSON.parseArray(cpwsMap.get("data").toString())) {
                   JSONObject jsonObject = JSON.parseObject(obj.toString());
                   Cpws cpws = JSON.parseObject(obj.toString(), Cpws.class);
                   cpws.setFc_tyshxycode(company_id);
                   cpws.setFc_detno(detno);
                   cpws.setFc_fbid(id);
                   Cpws save = cpwsDao.save(cpws);
                   detno=detno+1;
                   Long fc_id = save.getFc_id();
                   Object ssdq = jsonObject.get("所属地区");
                   if (ssdq!=null){
                       CpwsDetail cpwsDetail = JSON.parseObject(ssdq.toString(), CpwsDetail.class);
                       cpwsDetail.setFcd_fcid(fc_id);
                       cpwsDetail.setFcd_type("所属地区");
                       cpwsDetail.setFcd_detno(1);
                       cpwsDetailDao.save(cpwsDetail);
                   }
                   Object dls = jsonObject.get("段落");
                   if (dls != null && !"[]".equals(dls.toString())) {
                       List<CpwsDetail> cpwsDetails = JSON.parseArray(dls.toString(), CpwsDetail.class);
                       Object fcddetno = baseDao.getFieldDataByCondition("FBCPWSDETAIL", "max(fcd_detno)",
                               "fcd_type='段落' and fcd_fcid="+fc_id);
                       int det=fcddetno==null?1:Integer.parseInt(fcddetno.toString())+1;
                       for (CpwsDetail cpwsDetail:cpwsDetails) {
                           cpwsDetail.setFcd_fcid(fc_id);
                           cpwsDetail.setFcd_type("段落");
                           cpwsDetail.setFcd_detno(det);
                           det=det+1;
                       }
                       cpwsDetailDao.save(cpwsDetails);
                   }
                   Object dsrs = jsonObject.get("当事人");
                   if (dsrs != null && !"[]".equals(dsrs.toString())) {
                       List<CpwsDetail> cpwsDetails = JSON.parseArray(dsrs.toString(),CpwsDetail.class);
                       Object fcddetno = baseDao.getFieldDataByCondition("FBCPWSDETAIL", "max(fcd_detno)",
                               "fcd_type='当事人' and fcd_fcid="+fc_id);
                       int det=fcddetno==null?1:Integer.parseInt(fcddetno.toString())+1;
                       for (CpwsDetail cpwsDetail:cpwsDetails) {
                           cpwsDetail.setFcd_fcid(fc_id);
                           cpwsDetail.setFcd_type("当事人");
                           cpwsDetail.setFcd_detno(det);
                           cpwsDetail.setFcd_otherroles(stringArraytoString(cpwsDetail.getFcd_otherroles()));
                           cpwsDetail.setFcd_oldname(stringArraytoString(cpwsDetail.getFcd_oldname()));
                           cpwsDetail.setFcd_role(stringArraytoString(cpwsDetail.getFcd_role()));
                           cpwsDetail.setFcd_legalrepresentative(stringArraytoString(cpwsDetail.getFcd_legalrepresentative()));
                           det=det+1;
                       }
                       cpwsDetailDao.save(cpwsDetails);
                   }
                   Object cpjes = jsonObject.get("判决金额");
                   if (cpjes != null && !"[]".equals(cpjes.toString())) {
                       List<CpwsDetail> cpwsDetails = JSON.parseArray(cpjes.toString(),CpwsDetail.class);
                       Object fcddetno = baseDao.getFieldDataByCondition("FBCPWSDETAIL", "max(fcd_detno)",
                               "fcd_type='判决金额' and fcd_fcid="+fc_id);
                       int det=fcddetno==null?1:Integer.parseInt(fcddetno.toString())+1;
                       for (CpwsDetail cpwsDetail:cpwsDetails) {
                           cpwsDetail.setFcd_type("判决金额");
                           cpwsDetail.setFcd_detno(det);
                           cpwsDetail.setFcd_payer(stringArraytoString(cpwsDetail.getFcd_payer()));
                           cpwsDetail.setFcd_fcid(fc_id);
                           det=det+1;
                       }
                       cpwsDetailDao.save(cpwsDetails);
                   }
               }
           }
       }
       return total;
    }

    /**
     * 保存被执行人
     * @param company_id
     */
    private int saveExecutedPerson(String company_id,Long id,int count,Map<String, String> params){
        Map zhixingMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("zhixing"), apikey,
                count,size, hender, params);
        int total=0;
        if (zhixingMap!=null){
            total = zhixingMap.get("total") == null ? 0 : Integer.parseInt(zhixingMap.get("total").toString());
            if (zhixingMap.get("data") != null) {
                List<ExecutedPerson> executedPersonList = JSON.parseArray(zhixingMap.get("data").toString(), ExecutedPerson.class);
                Object fepdetno = baseDao.getFieldDataByCondition("FBEXECUTEDPERSON", "max(fep_detno)",
                        "fep_fbid="+id);
                int detno=fepdetno==null?1:Integer.parseInt(fepdetno.toString())+1;
                for (ExecutedPerson executedPerson : executedPersonList) {
                    executedPerson.setFep_entities(stringArraytoString(executedPerson.getFep_entities()));
                    executedPerson.setFep_tyshxycode(company_id);
                    executedPerson.setFep_fbid(id);
                    executedPerson.setFep_detno(detno);
                    detno=detno+1;
                }
                executedPersonDao.save(executedPersonList);
            }
        }
        return total;
    }

    /**
     * 保存失信被执行人
     * @param company_id
     */
    private int saveSxbzxr(String company_id,Long id,int count,Map<String, String> params){
        Map shixinMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("shixin"), apikey,
                count,size, hender, params);
        int total=0;
        if (shixinMap!=null){
            total=shixinMap.get("total")==null?0:Integer.parseInt(shixinMap.get("total").toString());
            if(shixinMap.get("data")!=null) {
                List<Sxbzxr> sxbzxrs = JSON.parseArray(shixinMap.get("data").toString(), Sxbzxr.class);
                Object fsxdetno = baseDao.getFieldDataByCondition("FBSXBZXR", "max(fsx_detno)",
                        "fsx_fbid="+id);
                int detno=fsxdetno==null?1:Integer.parseInt(fsxdetno.toString())+1;
                for (Sxbzxr sxbzxr:sxbzxrs) {
                    sxbzxr.setFsx_tyshxycode(company_id);
                    sxbzxr.setFsx_fbid(id);
                    sxbzxr.setFsx_detno(detno);
                    detno=detno+1;
                }
                sxbzxrDao.save(sxbzxrs);
            }
        }
        return total;
    }

    /**
     * 保存经营异常
     * @param company_id
     */
    private int saveJyyc(String company_id,Long id,int count,Map<String, String> params){
        Map jyycMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("jyyc"),
                apikey, count,size, hender, params);
        int total=0;
        if (jyycMap!=null){
            total=jyycMap.get("total")==null?0:Integer.parseInt(jyycMap.get("total").toString());
            if(jyycMap.get("data")!=null) {
                List<Jyyc> jyycs = JSON.parseArray(jyycMap.get("data").toString(), Jyyc.class);
                Object fjdetno = baseDao.getFieldDataByCondition("FBJYYC", "max(fj_detno)",
                        "fj_fbid="+id);
                int detno=fjdetno==null?1:Integer.parseInt(fjdetno.toString())+1;
                for (Jyyc jyyc:jyycs) {
                    jyyc.setFj_tyshxycode(company_id);
                    jyyc.setFj_fbid(id);
                    jyyc.setFj_detno(detno);
                    detno=detno+1;
                }
                jyycDao.save(jyycs);
            }
        }
        return total;
    }

    /**
     * 保存重大税收违法
     * @param company_id
     */
    private int saveSswf(String company_id,Long id,int count,Map<String, String> params){
        Map sswfMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sswf"),
                apikey,count, size, hender, params);
        int total=0;
        if (sswfMap!=null){
            total=sswfMap.get("total")==null?0:Integer.parseInt(sswfMap.get("total").toString());
            if(sswfMap.get("data")!=null) {
                List<Sswf> sswfs = JSON.parseArray(sswfMap.get("data").toString(), Sswf.class);
                Object fsdetno = baseDao.getFieldDataByCondition("FBSSWF", "max(fs_detno)",
                        "fs_fbid="+id);
                int detno=fsdetno==null?1:Integer.parseInt(fsdetno.toString())+1;
                for (Sswf sswf:sswfs) {
                    sswf.setFs_taxpayercode(company_id);
                    sswf.setFs_fbid(id);
                    sswf.setFs_detno(detno);
                    detno=detno+1;

                }
                sswfDao.save(sswfs);
            }
        }
        return total;
    }

    /**
     * 保存催缴/欠税
     * @param company_id
     */
    private int saveQsjl(String company_id,Long id,int count,Map<String, String> params){
        Map qsjlMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("qsjl"),
                apikey,count, size, hender, params);
        int total=0;
        if (qsjlMap!=null){
            total=qsjlMap.get("total")==null?0:Integer.parseInt(qsjlMap.get("total").toString());
            if(qsjlMap.get("data")!=null) {
                List<Qsjl> qsjls = JSON.parseArray(qsjlMap.get("data").toString(), Qsjl.class);
                Object fqdetno = baseDao.getFieldDataByCondition("FBQSJL", "max(fq_detno)",
                        "fq_fbid="+id);
                int detno=fqdetno==null?1:Integer.parseInt(fqdetno.toString())+1;
                for (Qsjl qsjl:qsjls) {
                    qsjl.setFq_tyshxycode(company_id);
                    qsjl.setFq_fbid(id);
                    qsjl.setFq_detno(detno);
                    detno=detno+1;
                }
                qsjlDao.save(qsjls);
            }
        }
        return total;
    }

    /**
     * 保存动产抵押
     * @param company_id
     */
    private int saveDcdy(String company_id,Long id,int count,Map<String, String> params){
        Map dcdyMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("dcdy"),
                apikey,count, size, hender, params);
        int total=0;
        if (dcdyMap!=null){
            total=dcdyMap.get("total")==null?0:Integer.parseInt(dcdyMap.get("total").toString());
            if(dcdyMap.get("data")!=null) {
                Object fddetno = baseDao.getFieldDataByCondition("FBDCDY", "max(fd_detno)",
                        "fd_fbid="+id);
                int detno=fddetno==null?1:Integer.parseInt(fddetno.toString())+1;
                for (Object obj:JSON.parseArray(dcdyMap.get("data").toString())) {
                    JSONObject jsonObject = JSON.parseObject(obj.toString());
                    Dcdy dcdy = JSON.parseObject(obj.toString(), Dcdy.class);
                    dcdy.setFd_tyshxycode(company_id);
                    dcdy.setFd_fbid(id);
                    Dcdy save = dcdyDao.save(dcdy);
                    Long fd_id = save.getFd_id();
                    Object dsrs = jsonObject.get("当事人");
                    if (dsrs != null && !"[]".equals(dsrs.toString())) {
                        List<DcdyDetail> dcdyDetails = JSON.parseArray(dsrs.toString(), DcdyDetail.class);
                        Object fdddetno = baseDao.getFieldDataByCondition("FBDCDYDETAIL", "max(fdd_detno)",
                                "fdd_type='当事人' and fdd_fdid="+fd_id);
                        int det=fdddetno==null?1:Integer.parseInt(fdddetno.toString())+1;
                        for (DcdyDetail dsr:dcdyDetails) {
                            dsr.setFdd_fdid(fd_id);
                            dsr.setFdd_type("当事人");
                            dsr.setFdd_detno(det);
                            det=det+1;
                        }
                        dcdyDetailDao.save(dcdyDetails);
                    }
                    Object dywgks = jsonObject.get("抵押物概况");
                    if (dywgks != null && !"[]".equals(dywgks.toString())) {
                        List<DcdyDetail> dcdyDetails = JSON.parseArray(dywgks.toString(), DcdyDetail.class);
                        Object fdddetno = baseDao.getFieldDataByCondition("FBDCDYDETAIL", "max(fdd_detno)",
                                "fdd_type='抵押物概况' and fdd_fdid="+fd_id);
                        int det=fdddetno==null?1:Integer.parseInt(fdddetno.toString())+1;
                        for (DcdyDetail dywgk:dcdyDetails) {
                            dywgk.setFdd_fdid(fd_id);
                            dywgk.setFdd_type("抵押物概况");
                            dywgk.setFdd_detno(det);
                            det=det+1;
                        }
                        dcdyDetailDao.save(dcdyDetails);
                    }
                    detno=detno+1;
                }
            }
        }
        return total;
    }

    /**
     * 保存股权出质
     * @param company_id
     */
    private int saveGqcz(String company_id,Long id,int count,Map<String, String> params){
        Map gqczMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gqcz"),
                apikey,count, size, hender, params);
        int total=0;
        if (gqczMap!=null){
            total=gqczMap.get("total")==null?0:Integer.parseInt(gqczMap.get("total").toString());
            if(gqczMap.get("data")!=null) {
                List<Gqcz> gqczs = JSON.parseArray(gqczMap.get("data").toString(), Gqcz.class);
                Object fgdetno = baseDao.getFieldDataByCondition("FBGQCZ", "max(fg_detno)",
                        "fg_fbid="+id);
                int detno=fgdetno==null?1:Integer.parseInt(fgdetno.toString())+1;
                for (Gqcz gqcz:gqczs) {
                    gqcz.setFg_tyshxycode(company_id);
                    gqcz.setFg_fbid(id);
                    gqcz.setFg_detno(detno);
                    detno=detno+1;
                }
                gqczDao.save(gqczs);
            }
        }
        return total;
    }

    /**
     * 保存司法协助
     * @param company_id
     */
    private int saveSfxz(String company_id,Long id,int count,Map<String, String> params){
        Map sfxzMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sfxz"),
                apikey,count, size, hender, params);
        int total=0;
        if (sfxzMap!=null){
            total=sfxzMap.get("total")==null?0:Integer.parseInt(sfxzMap.get("total").toString());
            if(sfxzMap.get("data")!=null) {
                List<Sfxz> sfxzs = JSON.parseArray(sfxzMap.get("data").toString(), Sfxz.class);
                Object ffdetno = baseDao.getFieldDataByCondition("FBSFXZ", "max(ff_detno)",
                        "ff_fbid="+id);
                int detno=ffdetno==null?1:Integer.parseInt(ffdetno.toString())+1;
                for (Sfxz sfxz:sfxzs) {
                    sfxz.setFf_tyshxycode(company_id);
                    sfxz.setFf_fbid(id);
                    sfxz.setFf_detno(detno);
                    detno=detno+1;
                }
                sfxzDao.save(sfxzs);
            }
        }
        return total;
    }

    /**
     * 保存涉诉公告
     * @param company_id
     */
    private int saveSsgg(String company_id,Long id,int count,Map<String, String> params){
        Map ssggMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ssgg"),
                apikey,count, size, hender, params);
        int total=0;
        if (ssggMap!=null) {
            total=ssggMap.get("total")==null?0:Integer.parseInt(ssggMap.get("total").toString());
            if (ssggMap.get("data") != null) {
                List<Ssgg> ssggs = JSON.parseArray(ssggMap.get("data").toString(), Ssgg.class);
                Object fssdetno = baseDao.getFieldDataByCondition("FBSSGG", "max(fss_detno)",
                        "fss_fbid="+id);
                int detno=fssdetno==null?1:Integer.parseInt(fssdetno.toString())+1;
                for (Ssgg ssgg : ssggs) {
                    ssgg.setFss_party(stringArraytoString(ssgg.getFss_party()));
                    ssgg.setFss_tyshxycode(company_id);
                    ssgg.setFss_entities(stringArraytoString(ssgg.getFss_entities()));
                    ssgg.setFss_fbid(id);
                    ssgg.setFss_detno(detno);
                    detno=detno+1;
                }
                ssggDao.save(ssggs);
            }
        }
        return total;
    }

    /**
     * 保存担保
     * @param company_id
     */
    private int saveDanbao(String company_id,Long id,int count,Map<String, String> params){
        Map danbaoMap = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("danbao"),
                apikey,count, size, hender, params);
        int total=0;
        if (danbaoMap!=null) {
            total=danbaoMap.get("total")==null?0:Integer.parseInt(danbaoMap.get("total").toString());
            if (danbaoMap.get("data") != null) {
                List<DanBao> danBaos = JSON.parseArray(danbaoMap.get("data").toString(), DanBao.class);
                Object fddetno = baseDao.getFieldDataByCondition("FBDANBAO", "max(fd_detno)",
                        "fd_fbid="+id);
                int detno=fddetno==null?1:Integer.parseInt(fddetno.toString())+1;
                for (DanBao danBao : danBaos) {
                    danBao.setFd_party(stringArraytoString(danBao.getFd_party()));
                    danBao.setFd_guarantor(stringArraytoString(danBao.getFd_guarantor()));
                    danBao.setFd_dbmethod(stringArraytoString(danBao.getFd_dbmethod()));
                    danBao.setFd_bparty(stringArraytoString(danBao.getFd_bparty()));
                    danBao.setFd_tyshxycode(company_id);
                    danBao.setFd_detno(detno);
                    danBao.setFd_detail(stringArraytoString(danBao.getFd_detail()));
                    danBao.setFd_fbid(id);
                    detno = detno + 1;
                }
                danBaoDao.save(danBaos);
            }
        }
        return total;
    }

    /**
     * 更新客户关注状态为已取消关注
     */
    @Override
    public void updateGZStatus(List<String> list){
        if (list!=null&&list.size()>0) {
            baseDao.execute("update fbbusiness set fb_gzstatus='已取消关注' where fb_tyshxycode not in (" + list2String(list) + ")");
            baseDao.execute("update customer set cu_gzstatus='已取消关注' where cu_name in (select fb_name from fbbusiness where fb_tyshxycode not in (" + list2String(list) + "))");
        }
    }

    /**
     * 更新客户关注状态为正在关注
     */
    @Override
    public void updateCUGZStatus(List<String> list){
        if (list!=null&&list.size()>0) {
            baseDao.execute(
                    "update customer set cu_gzstatus='正在关注' where cu_name in (select fb_name from fbbusiness where fb_tyshxycode in (" + list2String(list) + "))");
        }
    }



    /**
     * 清除所有相关表中数据
     */
    private void deleteByCompanyId(String company_id) {
        if (baseDao.checkIf("FBBUSINESS","fb_tyshxycode='"+company_id+"'")) {
            //清除工商资料明细
            baseDao.execute("delete from FBBUSINESSDETAIL where fbd_fbid in (select fb_id from FBBUSINESS where fb_tyshxycode='" + company_id + "')");
            //清除工商资料
            baseDao.execute("delete from FBBUSINESS where fb_tyshxycode='" + company_id + "'");
            //清除工商变更
            baseDao.execute("delete from FBBUSINESSCHANGE where fbc_tyshxycode='" + company_id + "'");
            //清除工商登记股东信息明细
            baseDao.execute("delete from FBINVESTORDETAIL where fid_fiid in (select fi_id from FBINVESTOR where fi_tyshxycode='" + company_id + "')");
            //清除工商登记股东信息
            baseDao.execute("delete from FBINVESTOR where fi_tyshxycode='" + company_id + "'");
            //清除主要成员
            baseDao.execute("delete from FBMEMBER where fm_tyshxycode='" + company_id + "'");
            //清除开庭公告明细
            baseDao.execute("delete from FBKTGGDETAIL where fkd_fkid in (select fk_id from FBKTGG where fk_tyshxycode='" + company_id + "')");
            //清除开庭公告
            baseDao.execute("delete from FBKTGG where fk_tyshxycode='" + company_id + "'");
            //清除裁判文书明细
            baseDao.execute("delete from FBCPWSDETAIL where fcd_fcid in (select fc_id from FBCPWS where fc_tyshxycode='" + company_id + "')");
            //清除裁判文书
            baseDao.execute("delete from FBCPWS where fc_tyshxycode='" + company_id + "'");
            //清除被执行人
            baseDao.execute("delete from FBEXECUTEDPERSON where fep_tyshxycode='" + company_id + "'");
            //清除失信被执行人
            baseDao.execute("delete from FBSXBZXR where fsx_tyshxycode='" + company_id + "'");
            //清除经营异常
            baseDao.execute("delete from FBJYYC where fj_tyshxycode='" + company_id + "'");
            //清除重大税收违法
            baseDao.execute("delete from FBSSWF where fs_tyshxycode='" + company_id + "'");
            //清除催缴/欠税
            baseDao.execute("delete from FBQSJL where fq_tyshxycode='" + company_id + "'");
            //清除动产抵押明细
            baseDao.execute("delete from FBDCDYDETAIL where fdd_fdid in (select fd_id from FBDCDY where fd_tyshxycode='" + company_id + "')");
            //清除动产抵押
            baseDao.execute("delete from FBDCDY where fd_tyshxycode='" + company_id + "'");
            //清除股权出质
            baseDao.execute("delete from FBGQCZ where fg_tyshxycode='" + company_id + "'");
            //清除司法协助
            baseDao.execute("delete from FBSFXZ where ff_tyshxycode='" + company_id + "'");
            //清除涉诉公告
            baseDao.execute("delete from FBSSGG where fss_tyshxycode='" + company_id + "'");
            //清除担保信息
            baseDao.execute("delete from FBDANBAO where fd_tyshxycode='" + company_id + "'");
        }

    }

    /**
     * 接口结果简单处理
     * @param url
     * @param hend
     * @param param
     * @return
     */
    private String httpResponse(String url,HashMap<String,String> hend,Map<String,String> param){
        logger.info(url +"?apikey="+apikey+"  参数："+param.toString());
        try {
            HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
            int statusCode = response.getStatusCode();
            logger.info(Integer.toString(statusCode));
            if (statusCode == 200) {
                return response.getResponseText();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 接口结果分页处理
     * @param url
     * @param hend
     * @param param
     * @return
     */
    private Map<String, Object> httpResponseBySize(String url,String apikey,int from,int size,HashMap<String,String> hend, Map<String, String> param){
        Map<String, Object> hashMap =null;
        try {
            logger.info(url + "?apikey=" + apikey + "  参数：" + param.toString());
            HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
            int statusCode = response.getStatusCode();
            logger.info(Integer.toString(statusCode));
            if (statusCode == 200) {
                String responseText = response.getResponseText();
                if (responseText != null) {
                    hashMap= new HashMap<>();
                    JSONArray jsonArray = null;
                    JSONObject jsonObject = JSON.parseObject(responseText);
                    int total = Integer.parseInt(jsonObject.get("total").toString());
                    hashMap.put("total",total);
                    if (total - from>0) {
                        Map<String, String> map = new HashMap<>();
                        map.put("apikey", apikey);
                        if (total-from < size){
                            map.put("from", Integer.toString(0));
                            map.put("size", Integer.toString(total-from));
                            HttpUtil.Response response1 = HttpUtil.sendGetRequest(url, hend, map);
                            int status = response1.getStatusCode();
                            if (status == 200) {
                                String s = response1.getResponseText();
                                if (s != null) {
                                    Object hits = JSON.parseObject(s).get("hits");
                                    jsonArray = JSON.parseArray(hits.toString());
                                }
                            }
                        }else{
                            Object hits = jsonObject.get("hits");
                            jsonArray = JSON.parseArray(hits.toString());
                            for (int i = size; i < total - from; i += size) {
                                map.put("from", Integer.toString(i));
                                if (total-from-i >= size) {
                                    map.put("size", Integer.toString(size));
                                    HttpUtil.Response response1 = HttpUtil.sendGetRequest(url, hend, map);
                                    int status = response1.getStatusCode();
                                    if (status == 200) {
                                        String s = response1.getResponseText();
                                        if (s != null) {
                                            Object hits1 = JSON.parseObject(s).get("hits");
                                            JSONArray array = JSON.parseArray(hits1.toString());
                                            jsonArray.addAll(array);
                                        }
                                    }
                                }else {
                                    map.put("size", Integer.toString(total-from-i));
                                    HttpUtil.Response response1 = HttpUtil.sendGetRequest(url, hend, map);
                                    int status = response1.getStatusCode();
                                    if (status == 200) {
                                        String s = response1.getResponseText();
                                        if (s != null) {
                                            Object hits1 = JSON.parseObject(s).get("hits");
                                            JSONArray array = JSON.parseArray(hits1.toString());
                                            jsonArray.addAll(array);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    hashMap.put("data",jsonArray);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return hashMap;
    }

    /**
     * 数组形式处理/分割
     * @param stringArray
     * @return
     */
    private String stringArraytoString(String stringArray){
        if ("[]".equals(stringArray)||stringArray==null){
            return null;
        }
    List<String> strings = JSON.parseArray(stringArray, String.class);
        String str="";
    for (String string:strings) {
        str=str+string+"/";
    }
    return str.substring(0,str.length()-1);
}

private String list2String(List<String> list){
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        if (i > 0) {
            str.append(",");
        }

        str.append("'").append(list.get(i)).append("'");
    }
    return str.toString();
}

}
