@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; }
@Override public List<MerchantBean> fetchRecMerchantBeans(int userId, double longitude, double latitude) throws JSONException { List<BCCollection> collections = new ArrayList<BCCollection>(); collections = BCCollecDao.findByProperty("userId", userId); List<Integer> collectionList = new ArrayList<Integer>(); for (BCCollection c : collections) { if (c.getEntityType() == 1) { collectionList.add(c.getEntityId()); } } JSONObject root = new JSONObject(); root.put("method", RecommenderUtils.getRecPredictMethod()); JSONObject params = new JSONObject(); params.put("id", userId); params.put("items", collectionList); 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 userCFList = response.getJSONArray("userCFList"); for (int i = 0; i < userCFList.length(); i++) { Integer merchantId = Integer.valueOf(userCFList.getString(i)); MerchantBean merchantBean = fetchMerchantBean(merchantId, userId, longitude, latitude); if (merchantBean != null) merchantPredictList.add(merchantBean); } JSONArray itemCFList = response.getJSONArray("itemCFList"); for (int i = 0; i < itemCFList.length(); i++) { Integer merchantId = Integer.valueOf(itemCFList.getString(i)); MerchantBean merchantBean = fetchMerchantBean(merchantId, userId, longitude, latitude); if (merchantBean != null) merchantPredictList.add(merchantBean); } JSONArray hotList = response.getJSONArray("hotList"); for (int i = 0; i < hotList.length(); i++) { Integer merchantId = Integer.valueOf(hotList.getString(i)); MerchantBean merchantBean = fetchMerchantBean(merchantId, userId, longitude, latitude); if (merchantBean != null) merchantPredictList.add(merchantBean); } } return merchantPredictList; }