@Override public ListedCompanyEntity syncCoordinates(StockEntity stock) { ListedCompanyEntity listedComapny = listedCompanyDao.getById(stock.getIdListedCompany()); if (listedComapny.getLatitude() == null || listedComapny.getLongitude() == null || listedComapny.getAddressCode() == null) { Map<String, String> gaodeMap = DDConstant.gaodeMap(); // 设置请求参数 Map<String, Object> args = objectMap( "key", gaodeMap.get("amap-web-key"), "address", listedComapny.getRegisteredAddress()); // 请求 Map<String, Object> data = HttpUtil.getJsonAsMap(gaodeMap.get("amap-geocode"), args); // 解析数据 @SuppressWarnings("unchecked") List<Map<String, Object>> geocodes = (List<Map<String, Object>>) data.get("geocodes"); if (geocodes.size() > 0) { Map<String, Object> m0 = geocodes.get(0); ListedCompanyEntity lc = new ListedCompanyEntity(); lc.setId(listedComapny.getId()); lc.setAddressCode(String.valueOf(m0.get("adcode"))); String[] ll = String.valueOf(m0.get("location")).split(","); lc.setLongitude(ll[0]); lc.setLatitude(ll[1]); listedCompanyDao.lazyUpdate(lc); return lc; } else { log.debug("同步经纬信息出错::{}", data); } } return listedComapny; }
@Override public ListedCompanyEntity syncCompanyInfo(StockEntity stock) { String template = TemplateConstant.getTemplateConstantMap().get("ths-company-info"); String dataUrl = DDConstant.thsMap() .get("ths-company-info") .replaceFirst("\\{[^\\{\\}]+\\}", String.valueOf(stock.getId())); String htmlData = HttpUtil.getHtmlAsString(dataUrl); Map<String, String> dataMap = TemplateParserUtil.parserHtmlTemplate2Map(htmlData, template); ListedCompanyEntity listedCompany = JSONUtil.convertMapToBean(dataMap, ListedCompanyEntity.class); Map<String, String> listedCompanyNameMap = ListedCompanyNameConstant.getListedCompanyNameConstantMap(); // 检查公司名是否已经存在 if (!listedCompanyNameMap.containsKey(listedCompany.getName())) { listedCompany.setId(StringUtil.buildUUID()); try { listedCompany.setIssuePrice( Float.valueOf(dataMap.get("other").replaceAll("元", "").split("/", 2)[0])); } catch (Exception e) { listedCompany.setIssuePrice(-1f); } listedCompanyDao.saveOrUpdate(listedCompany); // 将公司名称和ID保存到map中 listedCompanyNameMap.put(listedCompany.getId(), listedCompany.getName()); listedCompanyNameMap.put(listedCompany.getName(), listedCompany.getId()); } else { listedCompany.setId(listedCompanyNameMap.get(listedCompany.getName())); } if (stock.getIdListedCompany() == null || "".equals(stock.getIdListedCompany())) { // 更新股票的公司ID StockEntity st = new StockEntity(); st.setId(stock.getId()); st.setIdListedCompany(listedCompany.getId()); stockDao.lazyUpdate(st); } return listedCompany; }