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.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 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")); }}; private final static Map params = new HashMap(){{ put("apikey",apikey); put("from",Integer.toString(0)); put("size",Integer.toString(size)); }}; @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 getGroupAll() throws Exception{ Map 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 getFollowingByGroup() throws Exception { Map param = new HashMap<>(); param.put("apikey",apikey); param.put("from",Integer.toString(0)); param.put("size",Integer.toString(1000)); List groupAll = getGroupAll(); if (groupAll!=null){ List list = new ArrayList<>(); for (Group group:groupAll) { param.put("group_id",Long.toString(group.getId())); JSONArray following = httpResponseBySize(url + httpConfig.get("following"), apikey, 1000, hender, param); if (following!=null){ List strings = JSON.parseArray(following.toString(), String.class); list.addAll(strings); } } return list; } return null; } /** * 保存工商资料 * @param company_id */ @Async("taskExecutor") @Transactional(rollbackFor=Exception.class) @Override public void saveBusiness(String company_id) throws Exception{ deleteByCompanyId(company_id); Map param = new HashMap<>(); param.put("apikey", apikey); String s = httpResponse(url + company + "/" + company_id, hender, param); if (s != null) { Business business = JSON.parseObject(s, Business.class); 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); Long 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 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); } saveBusinessChange(company_id,fb_id); saveInvestor(company_id,fb_id); saveMember(company_id,fb_id); saveKtgg(company_id,fb_id); saveCpws(company_id,fb_id); saveExecutedPerson(company_id,fb_id); saveSxbzxr(company_id,fb_id); saveJyyc(company_id,fb_id); saveSswf(company_id,fb_id); saveQsjl(company_id,fb_id); saveDcdy(company_id,fb_id); saveGqcz(company_id,fb_id); saveSfxz(company_id,fb_id); saveSsgg(company_id,fb_id); saveDanbao(company_id,fb_id); } } /** * 保存工商变更 * @param company_id */ /*@Async("taskExecutor")*/ private void saveBusinessChange(String company_id,Long id) throws Exception{ JSONArray gsbg = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gsbg"), apikey, size, hender, params); if(gsbg!=null) { List businessChanges = JSON.parseArray(gsbg.toString(), BusinessChange.class); if (businessChanges != null && businessChanges.size() > 0) { int detno = 1; for (BusinessChange fbc : businessChanges) { fbc.setFbc_detno(detno); fbc.setFbc_tyshxycode(company_id); fbc.setFbc_fbid(id); detno = detno + 1; } businessChangeDao.save(businessChanges); } } } /** * 保存工商登记股东信息 * @param company_id */ private void saveInvestor(String company_id,Long id) throws Exception{ JSONArray objects = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("investor") , apikey, size, hender, params); if (objects!=null) { int det=1; for (Object obj:objects) { 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 sjDetails = JSON.parseArray(sjmx.toString(), InvestorSJDetail.class); int detno=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 rjDetails = JSON.parseArray(rjmx.toString(),InvestorRJDetail.class); int no=1; for (InvestorRJDetail investorRJDetail:rjDetails) { investorRJDetail.setFid_detno(no); investorRJDetail.setFid_fiid(fi_id); investorRJDetail.setFid_type("认缴明细"); no=no+1; } investorRJDetailDao.save(rjDetails); } } } } /** * 保存主要成员 * @param company_id */ private void saveMember(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("member") , apikey, size, hender, params); if (jsonArray!=null) { List members = JSON.parseArray(jsonArray.toString(), Member.class); for (Member member:members) { member.setFm_tyshxycode(company_id); member.setFm_fbid(id); } memberDao.save(members); } } /** * 保存开庭公告 * @param company_id */ private void saveKtgg(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ktgg") , apikey, size, hender, params); if (jsonArray!=null) { int detno=1; for (Object obj:jsonArray) { 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 ktggDetails = JSON.parseArray(dsrDetail.toString(), KtggDetail.class); int det=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_type("所属地区"); ktggDetailDao.save(ktggDetail); } } } } /** * 保存裁判文书 * @param company_id */ private void saveCpws(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("cpws"), apikey, size, hender, params); if (jsonArray!=null) { int detno=1; for (Object obj:jsonArray) { 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 cpwsDetails = JSON.parseArray(dls.toString(), CpwsDetail.class); int det=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 cpwsDetails = JSON.parseArray(dsrs.toString(),CpwsDetail.class); int det=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 cpwsDetails = JSON.parseArray(cpjes.toString(),CpwsDetail.class); int det=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); } } } } /** * 保存被执行人 * @param company_id */ private void saveExecutedPerson(String company_id,Long id) throws Exception{ JSONArray zhixing = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("zhixing"), apikey, size, hender, params); if (zhixing!=null) { List executedPersonList = JSON.parseArray(zhixing.toString(), ExecutedPerson.class); for (ExecutedPerson executedPerson:executedPersonList) { executedPerson.setFep_entities(stringArraytoString(executedPerson.getFep_entities())); executedPerson.setFep_tyshxycode(company_id); executedPerson.setFep_fbid(id); } executedPersonDao.save(executedPersonList); } } /** * 保存失信被执行人 * @param company_id */ private void saveSxbzxr(String company_id,Long id) throws Exception{ JSONArray shixin = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("shixin"), apikey, size, hender, params); if (shixin!=null) { List sxbzxrs = JSON.parseArray(shixin.toString(), Sxbzxr.class); for (Sxbzxr sxbzxr:sxbzxrs) { sxbzxr.setFsx_tyshxycode(company_id); sxbzxr.setFsx_fbid(id); } sxbzxrDao.save(sxbzxrs); } } /** * 保存经营异常 * @param company_id */ private void saveJyyc(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("jyyc"), apikey, size, hender, params); if (jsonArray!=null) { List jyycs = JSON.parseArray(jsonArray.toString(), Jyyc.class); for (Jyyc jyyc:jyycs) { jyyc.setFj_tyshxycode(company_id); jyyc.setFj_fbid(id); } jyycDao.save(jyycs); } } /** * 保存重大税收违法 * @param company_id */ private void saveSswf(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sswf"), apikey, size, hender, params); if (jsonArray!=null) { List sswfs = JSON.parseArray(jsonArray.toString(), Sswf.class); for (Sswf sswf:sswfs) { sswf.setFs_taxpayercode(company_id); sswf.setFs_fbid(id); } sswfDao.save(sswfs); } } /** * 保存催缴/欠税 * @param company_id */ private void saveQsjl(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("qsjl"), apikey, size, hender, params); if (jsonArray!=null) { List qsjls = JSON.parseArray(jsonArray.toString(), Qsjl.class); for (Qsjl qsjl:qsjls) { qsjl.setFq_tyshxycode(company_id); qsjl.setFq_fbid(id); } qsjlDao.save(qsjls); } } /** * 保存动产抵押 * @param company_id */ private void saveDcdy(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("dcdy"), apikey, size, hender, params); if (jsonArray!=null) { for (Object obj:jsonArray) { 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 dcdyDetails = JSON.parseArray(dsrs.toString(), DcdyDetail.class); for (DcdyDetail dsr:dcdyDetails) { dsr.setFdd_fdid(fd_id); dsr.setFdd_type("当事人"); } dcdyDetailDao.save(dcdyDetails); } Object dywgks = jsonObject.get("抵押物概况"); if (dywgks != null && !"[]".equals(dywgks.toString())) { List dcdyDetails = JSON.parseArray(dywgks.toString(), DcdyDetail.class); for (DcdyDetail dywgk:dcdyDetails) { dywgk.setFdd_fdid(fd_id); dywgk.setFdd_type("抵押物概况"); } dcdyDetailDao.save(dcdyDetails); } } } } /** * 保存股权出质 * @param company_id */ private void saveGqcz(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gqcz"), apikey, size, hender, params); if (jsonArray!=null) { List gqczs = JSON.parseArray(jsonArray.toString(), Gqcz.class); for (Gqcz gqcz:gqczs) { gqcz.setFg_tyshxycode(company_id); gqcz.setFg_fbid(id); } gqczDao.save(gqczs); } } /** * 保存司法协助 * @param company_id */ private void saveSfxz(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sfxz"), apikey, size, hender, params); if (jsonArray!=null) { List sfxzs = JSON.parseArray(jsonArray.toString(), Sfxz.class); for (Sfxz sfxz:sfxzs) { sfxz.setFf_tyshxycode(company_id); sfxz.setFf_fbid(id); } sfxzDao.save(sfxzs); } } /** * 保存涉诉公告 * @param company_id */ private void saveSsgg(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ssgg"), apikey, size, hender, params); if (jsonArray!=null) { List ssggs = JSON.parseArray(jsonArray.toString(), Ssgg.class); 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); } ssggDao.save(ssggs); } } /** * 保存担保 * @param company_id */ private void saveDanbao(String company_id,Long id) throws Exception{ JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("danbao"), apikey, size, hender, params); if (jsonArray!=null) { List danBaos = JSON.parseArray(jsonArray.toString(), DanBao.class); int detno=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); } } /** * 更新客户关注状态为已取消关注 */ @Override public void updateGZStatus(List 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 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 hend,Map param) throws Exception{ 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) { return response.getResponseText(); }else{ throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText()); } } /** * 接口结果分页处理 * @param url * @param hend * @param param * @return */ private JSONArray httpResponseBySize(String url,String apikey,int size,HashMap hend, Map param) throws Exception{ logger.info(url +"?apikey="+apikey+" 参数:"+param.toString()); JSONArray jsonArray=null; 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) { JSONObject jsonObject = JSON.parseObject(responseText); int total = Integer.parseInt(jsonObject.get("total").toString()); if (total>0) { Object hits = jsonObject.get("hits"); jsonArray = JSON.parseArray(hits.toString()); if (total > size) { Map map = new HashMap<>(); map.put("apikey", apikey); for (int i = size; i < total; i += size) { map.put("from", Integer.toString(i)); 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 { throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText()); } } } } } return jsonArray; } else{ logger.error("接口状态:"+statusCode+",返回内容:"+response.getResponseText()); throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText()); } } /** * 数组形式处理/分割 * @param stringArray * @return */ private String stringArraytoString(String stringArray){ if ("[]".equals(stringArray)||stringArray==null){ return null; } List 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 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(); } }