@Override public List<MerchantBean> fetchHotMerchantBeans(int userId, double longitude, double latitude) throws JSONException { // TODO Auto-generated method stub JSONObject root = new JSONObject(); root.put("method", RecommenderUtils.getHotPredictMethod()); JSONObject params = new JSONObject(); params.put("longitude", longitude); params.put("latitude", latitude); root.put("params", params); BaseHttpClient httpClient = new BaseHttpClient(RecommenderUtils.getRecommenderUrl()); JSONObject response = httpClient.post(root); List<MerchantBean> merchantPredictList = new ArrayList<MerchantBean>(); if (response.has("result") && response.getString("result").equals("success")) { JSONArray hotList = response.getJSONArray("hotList"); for (int i = 0; i < hotList.length(); i++) { JSONArray hotItem = hotList.getJSONArray(i); Integer merchantId = Integer.valueOf(hotItem.getString(0)); MerchantBean merchantBean = fetchMerchantBean(merchantId, userId, longitude, latitude); if (merchantBean != null) { merchantBean.setCollectionCount(hotItem.getInt(1)); merchantPredictList.add(merchantBean); } } } return merchantPredictList; }
private MerchantBean fetchMerchantBean( Integer merchantId, Integer userId, double longitude, double latitude) { List<Merchant> merchantList = merchantDao.findByProperty("merchantId", merchantId); if (merchantList == null || merchantList.size() <= 0) { return null; } Merchant merchant = merchantList.get(0); MerchantBean merchantBean = new MerchantBean(merchant); List<String> tags = new ArrayList<String>(); List<TagEntity> tagEntity = tagEntityDao.getMerchantTags(merchantId); for (int i = 0; i < tagEntity.size(); i++) { String t = tagEntity.get(i).getTagName(); tags.add(t); } merchantBean.setDistance( Distances.computeDistance( merchant.getLongitude(), merchant.getLatitude(), longitude, latitude)); if (userId == null) merchantBean.setType(0); else if (subscriptionMerchantDao.getSubscriptionMerchant(userId, merchantId).size() > 0) merchantBean.setType( subscriptionMerchantDao.getSubscriptionMerchant(userId, merchantId).get(0).getType()); else { merchantBean.setType(2); } merchantBean.setTagName(tags); return merchantBean; }