| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
| 4 |
import java.util.Arrays;
|
4 |
import java.util.Arrays;
|
| 5 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| - |
|
6 |
import java.util.HashSet;
|
| 6 |
import java.util.Iterator;
|
7 |
import java.util.Iterator;
|
| 7 |
import java.util.List;
|
8 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
9 |
import java.util.Map;
|
| - |
|
10 |
import java.util.stream.Collectors;
|
| 9 |
|
11 |
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
12 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
|
13 |
|
| 12 |
import org.apache.commons.lang3.StringUtils;
|
14 |
import org.apache.commons.lang3.StringUtils;
|
| 13 |
import org.apache.http.conn.HttpHostConnectException;
|
15 |
import org.apache.http.conn.HttpHostConnectException;
|
| Line 38... |
Line 40... |
| 38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
40 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 39 |
import com.spice.profitmandi.common.model.UserInfo;
|
41 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 40 |
import com.spice.profitmandi.common.web.client.RestClient;
|
42 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 41 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 42 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
44 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
45 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 43 |
import com.spice.profitmandi.dao.model.UserCart;
|
46 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 44 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
47 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| - |
|
48 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 46 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
50 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 47 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
51 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 48 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
52 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 49 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
53 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| Line 87... |
Line 91... |
| 87 |
|
91 |
|
| 88 |
@Autowired
|
92 |
@Autowired
|
| 89 |
private ResponseSender<?> responseSender;
|
93 |
private ResponseSender<?> responseSender;
|
| 90 |
|
94 |
|
| 91 |
@Autowired
|
95 |
@Autowired
|
| - |
|
96 |
private TagListingRepository tagListingRepository;
|
| - |
|
97 |
|
| - |
|
98 |
@Autowired
|
| 92 |
private ItemRepository itemRepository;
|
99 |
private ItemRepository itemRepository;
|
| 93 |
|
100 |
|
| 94 |
@Autowired
|
101 |
@Autowired
|
| 95 |
private RoleManager roleManagerService;
|
102 |
private RoleManager roleManagerService;
|
| 96 |
|
103 |
|
| Line 163... |
Line 170... |
| 163 |
@ApiImplicitParams({
|
170 |
@ApiImplicitParams({
|
| 164 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
171 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 165 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
172 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 166 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
173 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| 167 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
174 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| 168 |
@RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand) throws Throwable {
|
175 |
@RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand,
|
| - |
|
176 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
| 169 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
177 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 170 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
178 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 171 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
179 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
| 172 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
180 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 173 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
181 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| Line 175... |
Line 183... |
| 175 |
Map<String, String> params = new HashMap<>();
|
183 |
Map<String, String> params = new HashMap<>();
|
| 176 |
List<String> mandatoryQ = new ArrayList<>();
|
184 |
List<String> mandatoryQ = new ArrayList<>();
|
| 177 |
if(brand != null) {
|
185 |
if(brand != null) {
|
| 178 |
|
186 |
|
| 179 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
187 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
| - |
|
188 |
} else if (hotDeal) {
|
| - |
|
189 |
mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
| 180 |
} else {
|
190 |
} else {
|
| 181 |
mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
191 |
mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
| 182 |
}
|
192 |
}
|
| 183 |
params.put("q", StringUtils.join(mandatoryQ," "));
|
193 |
params.put("q", StringUtils.join(mandatoryQ," "));
|
| 184 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
194 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| Line 192... |
Line 202... |
| 192 |
} catch (HttpHostConnectException e) {
|
202 |
} catch (HttpHostConnectException e) {
|
| 193 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
203 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 194 |
}
|
204 |
}
|
| 195 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
205 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 196 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
206 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
207 |
|
| - |
|
208 |
HashSet<Integer> itemsSet = new HashSet<>();
|
| - |
|
209 |
for(int i=0; i < docs.length(); i++) {
|
| - |
|
210 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| - |
|
211 |
JSONObject doc = docs.getJSONObject(i);
|
| - |
|
212 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
| - |
|
213 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| - |
|
214 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
215 |
itemsSet.add(itemId);
|
| - |
|
216 |
}
|
| - |
|
217 |
}
|
| - |
|
218 |
Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
|
| - |
|
219 |
.collect(Collectors.toMap(x->x.getItemId(), x->x));
|
| - |
|
220 |
|
| - |
|
221 |
|
| 197 |
for(int i=0; i < docs.length(); i++) {
|
222 |
for(int i=0; i < docs.length(); i++) {
|
| 198 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
223 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 199 |
JSONObject doc = docs.getJSONObject(i);
|
224 |
JSONObject doc = docs.getJSONObject(i);
|
| 200 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
225 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
| 201 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
226 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
| 202 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
227 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
| 203 |
ffdr.setTitle(doc.getString("title_s"));
|
228 |
ffdr.setTitle(doc.getString("title_s"));
|
| 204 |
ffdr.setBrand(doc.getString("brand_s"));
|
229 |
ffdr.setBrand(doc.getString("brand_s"));
|
| 205 |
ffdr.setHotDeals(doc.getBoolean("hot_deals_b"));
|
- |
|
| - |
|
230 |
|
| 206 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
231 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 207 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
232 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 208 |
int itemId = childItem.getInt("itemId_i");
|
233 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
234 |
TagListing tl = itemTagListingMap.get(itemId);
|
| - |
|
235 |
if(!tl.isHotDeals()) {
|
| - |
|
236 |
continue;
|
| - |
|
237 |
}
|
| 209 |
float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
|
238 |
float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
|
| 210 |
if(fofoAvailabilityInfoMap.containsKey(itemId)) {
|
239 |
if(fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| 211 |
if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
240 |
if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
| 212 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
241 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
| 213 |
fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
|
242 |
fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
|