| 21339 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
| 22336 |
amit.gupta |
4 |
import java.util.Arrays;
|
| 21339 |
kshitij.so |
5 |
import java.util.HashMap;
|
| 23814 |
amit.gupta |
6 |
import java.util.HashSet;
|
| 22952 |
amit.gupta |
7 |
import java.util.Iterator;
|
| 21339 |
kshitij.so |
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
| 25875 |
amit.gupta |
10 |
import java.util.Optional;
|
| 25959 |
amit.gupta |
11 |
import java.util.Set;
|
| 25010 |
amit.gupta |
12 |
import java.util.concurrent.atomic.AtomicInteger;
|
| 23814 |
amit.gupta |
13 |
import java.util.stream.Collectors;
|
| 21339 |
kshitij.so |
14 |
|
|
|
15 |
import javax.servlet.http.HttpServletRequest;
|
|
|
16 |
|
| 22319 |
amit.gupta |
17 |
import org.apache.commons.lang3.StringUtils;
|
| 23532 |
amit.gupta |
18 |
import org.apache.http.conn.HttpHostConnectException;
|
| 23786 |
amit.gupta |
19 |
import org.apache.logging.log4j.LogManager;
|
|
|
20 |
import org.apache.logging.log4j.Logger;
|
| 22319 |
amit.gupta |
21 |
import org.json.JSONArray;
|
|
|
22 |
import org.json.JSONObject;
|
| 22273 |
amit.gupta |
23 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21339 |
kshitij.so |
24 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
25 |
import org.springframework.http.HttpStatus;
|
|
|
26 |
import org.springframework.http.MediaType;
|
|
|
27 |
import org.springframework.http.ResponseEntity;
|
|
|
28 |
import org.springframework.stereotype.Controller;
|
| 22286 |
amit.gupta |
29 |
import org.springframework.transaction.annotation.Transactional;
|
| 21339 |
kshitij.so |
30 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
34 |
|
|
|
35 |
import com.eclipsesource.json.Json;
|
|
|
36 |
import com.eclipsesource.json.JsonArray;
|
|
|
37 |
import com.eclipsesource.json.JsonObject;
|
|
|
38 |
import com.eclipsesource.json.JsonValue;
|
|
|
39 |
import com.google.gson.Gson;
|
| 21356 |
kshitij.so |
40 |
import com.google.gson.reflect.TypeToken;
|
| 25010 |
amit.gupta |
41 |
import com.mongodb.BasicDBObject;
|
| 24163 |
amit.gupta |
42 |
import com.mongodb.DBObject;
|
| 21643 |
ashik.ali |
43 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21339 |
kshitij.so |
44 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
45 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22289 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21643 |
ashik.ali |
47 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 22319 |
amit.gupta |
48 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25010 |
amit.gupta |
49 |
import com.spice.profitmandi.dao.entity.catalog.Category;
|
| 23426 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 23814 |
amit.gupta |
51 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 26847 |
tejbeer |
52 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
|
| 26846 |
tejbeer |
53 |
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
|
| 22361 |
amit.gupta |
54 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 25010 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
|
| 23426 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23814 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 22333 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 22361 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 26889 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 26846 |
tejbeer |
61 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
|
| 26847 |
tejbeer |
62 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
|
| 22989 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 23798 |
amit.gupta |
64 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25880 |
amit.gupta |
65 |
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
|
| 25882 |
amit.gupta |
66 |
import com.spice.profitmandi.service.inventory.Bucket;
|
| 25880 |
amit.gupta |
67 |
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
|
|
|
68 |
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
|
| 25875 |
amit.gupta |
69 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
| 25879 |
amit.gupta |
70 |
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
|
| 26889 |
amit.gupta |
71 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 22287 |
amit.gupta |
72 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 26695 |
amit.gupta |
73 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 21356 |
kshitij.so |
74 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 21339 |
kshitij.so |
75 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
76 |
import com.spice.profitmandi.web.res.DealsResponse;
|
|
|
77 |
|
|
|
78 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
79 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
80 |
import io.swagger.annotations.ApiOperation;
|
|
|
81 |
|
|
|
82 |
@Controller
|
| 22319 |
amit.gupta |
83 |
@Transactional(rollbackFor = Throwable.class)
|
| 21339 |
kshitij.so |
84 |
public class DealsController {
|
|
|
85 |
|
| 23568 |
govind |
86 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
| 21339 |
kshitij.so |
87 |
|
|
|
88 |
@Value("${python.api.host}")
|
|
|
89 |
private String host;
|
| 23816 |
amit.gupta |
90 |
|
| 26889 |
amit.gupta |
91 |
@Value("${new.solr.url}")
|
|
|
92 |
private String solrUrl;
|
|
|
93 |
|
| 21339 |
kshitij.so |
94 |
@Value("${python.api.port}")
|
|
|
95 |
private int port;
|
| 23816 |
amit.gupta |
96 |
|
| 26889 |
amit.gupta |
97 |
@Autowired
|
|
|
98 |
RestClient restClient;
|
|
|
99 |
|
| 23816 |
amit.gupta |
100 |
// This is now unused as we are not supporting multiple companies.
|
| 23300 |
amit.gupta |
101 |
@Value("${gadgetCops.invoice.cc}")
|
| 23816 |
amit.gupta |
102 |
private String[] ccGadgetCopInvoiceTo;
|
| 22319 |
amit.gupta |
103 |
|
|
|
104 |
@Autowired
|
|
|
105 |
private PricingService pricingService;
|
| 23816 |
amit.gupta |
106 |
|
| 22273 |
amit.gupta |
107 |
@Autowired
|
| 26889 |
amit.gupta |
108 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
109 |
|
|
|
110 |
@Autowired
|
| 25010 |
amit.gupta |
111 |
private CategoryRepository categoryRepository;
|
|
|
112 |
|
|
|
113 |
@Autowired
|
| 26695 |
amit.gupta |
114 |
private SchemeService schemeService;
|
|
|
115 |
|
|
|
116 |
@Autowired
|
| 26889 |
amit.gupta |
117 |
private SaholicInventoryService saholicInventoryService;
|
|
|
118 |
|
|
|
119 |
@Autowired
|
| 22333 |
amit.gupta |
120 |
private Mongo mongoClient;
|
| 25879 |
amit.gupta |
121 |
|
| 25875 |
amit.gupta |
122 |
@Autowired
|
|
|
123 |
private ItemBucketService itemBucketService;
|
| 23816 |
amit.gupta |
124 |
|
| 22333 |
amit.gupta |
125 |
@Autowired
|
| 22361 |
amit.gupta |
126 |
private UserAccountRepository userAccountRepository;
|
| 23816 |
amit.gupta |
127 |
|
| 22989 |
amit.gupta |
128 |
@Autowired
|
| 22931 |
ashik.ali |
129 |
private ResponseSender<?> responseSender;
|
| 23816 |
amit.gupta |
130 |
|
| 22554 |
amit.gupta |
131 |
@Autowired
|
| 25010 |
amit.gupta |
132 |
private CategoryRepository repository;
|
|
|
133 |
|
|
|
134 |
@Autowired
|
| 23814 |
amit.gupta |
135 |
private TagListingRepository tagListingRepository;
|
| 23816 |
amit.gupta |
136 |
|
| 23814 |
amit.gupta |
137 |
@Autowired
|
| 23426 |
amit.gupta |
138 |
private ItemRepository itemRepository;
|
| 23816 |
amit.gupta |
139 |
|
| 23786 |
amit.gupta |
140 |
@Autowired
|
| 23861 |
amit.gupta |
141 |
private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
|
|
|
142 |
|
|
|
143 |
@Autowired
|
| 23798 |
amit.gupta |
144 |
private RoleManager roleManagerService;
|
| 23816 |
amit.gupta |
145 |
|
| 26846 |
tejbeer |
146 |
@Autowired
|
|
|
147 |
private SuggestedPoDetailRepository monthlyPoDetailRepository;
|
|
|
148 |
|
| 26847 |
tejbeer |
149 |
@Autowired
|
|
|
150 |
private SuggestedPoRepository suggestedPoRepository;
|
|
|
151 |
|
| 22336 |
amit.gupta |
152 |
List<String> filterableParams = Arrays.asList("brand");
|
| 24949 |
amit.gupta |
153 |
|
| 25876 |
amit.gupta |
154 |
@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 25879 |
amit.gupta |
155 |
public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 25875 |
amit.gupta |
156 |
logger.info("Request " + request.getParameterMap());
|
|
|
157 |
return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
|
|
|
158 |
}
|
| 25879 |
amit.gupta |
159 |
|
|
|
160 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 25880 |
amit.gupta |
161 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
|
| 25879 |
amit.gupta |
162 |
throws ProfitMandiBusinessException {
|
| 25880 |
amit.gupta |
163 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
| 25968 |
amit.gupta |
164 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream()
|
|
|
165 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
|
|
166 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
|
|
|
167 |
.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 25879 |
amit.gupta |
168 |
RestClient rc = new RestClient();
|
|
|
169 |
Map<String, String> params = new HashMap<>();
|
|
|
170 |
List<String> mandatoryQ = new ArrayList<>();
|
| 25968 |
amit.gupta |
171 |
mandatoryQ.add(
|
|
|
172 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
| 25959 |
amit.gupta |
173 |
params.put("start", "0");
|
|
|
174 |
params.put("rows", "100");
|
| 25879 |
amit.gupta |
175 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
176 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
177 |
|
|
|
178 |
params.put("wt", "json");
|
|
|
179 |
String response = null;
|
|
|
180 |
try {
|
| 26889 |
amit.gupta |
181 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 25879 |
amit.gupta |
182 |
} catch (HttpHostConnectException e) {
|
|
|
183 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
184 |
}
|
|
|
185 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
186 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 25968 |
amit.gupta |
187 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
|
| 26051 |
amit.gupta |
188 |
|
| 26589 |
amit.gupta |
189 |
Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id)
|
|
|
190 |
.collect(Collectors.toList()).get(0);
|
| 25882 |
amit.gupta |
191 |
bucket.setFofoCatalogResponses(dealResponse);
|
|
|
192 |
return responseSender.ok(bucket);
|
| 25879 |
amit.gupta |
193 |
}
|
|
|
194 |
|
| 26846 |
tejbeer |
195 |
@RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
196 |
public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id)
|
|
|
197 |
throws ProfitMandiBusinessException {
|
|
|
198 |
|
|
|
199 |
List<SuggestedPoDetail> mpd = monthlyPoDetailRepository.selectByPoId(id);
|
|
|
200 |
Map<Integer, Integer> itemIdsQtyMap = mpd.stream()
|
|
|
201 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
|
|
202 |
|
|
|
203 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
|
|
|
204 |
.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
|
|
205 |
RestClient rc = new RestClient();
|
|
|
206 |
Map<String, String> params = new HashMap<>();
|
|
|
207 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
208 |
mandatoryQ.add(
|
|
|
209 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
|
|
210 |
params.put("start", "0");
|
|
|
211 |
params.put("rows", "100");
|
|
|
212 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
213 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
214 |
|
|
|
215 |
params.put("wt", "json");
|
|
|
216 |
String response = null;
|
|
|
217 |
try {
|
| 26889 |
amit.gupta |
218 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 26846 |
tejbeer |
219 |
} catch (HttpHostConnectException e) {
|
|
|
220 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
221 |
}
|
|
|
222 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
223 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
224 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
|
|
|
225 |
|
|
|
226 |
return responseSender.ok(dealResponse);
|
|
|
227 |
}
|
|
|
228 |
|
| 26847 |
tejbeer |
229 |
@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26848 |
tejbeer |
230 |
@ApiImplicitParams({
|
|
|
231 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
232 |
@ApiOperation(value = "")
|
| 26847 |
tejbeer |
233 |
public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id)
|
|
|
234 |
throws ProfitMandiBusinessException {
|
|
|
235 |
SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
|
|
|
236 |
suggestedPo.setStatus("closed");
|
|
|
237 |
|
|
|
238 |
return responseSender.ok(true);
|
|
|
239 |
}
|
|
|
240 |
|
| 23816 |
amit.gupta |
241 |
private String getCommaSeparateTags(int userId) {
|
| 22361 |
amit.gupta |
242 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
243 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 22287 |
amit.gupta |
244 |
List<String> strTagIds = new ArrayList<>();
|
|
|
245 |
for (Integer tagId : tagIds) {
|
|
|
246 |
strTagIds.add(String.valueOf(tagId));
|
| 22273 |
amit.gupta |
247 |
}
|
| 22287 |
amit.gupta |
248 |
return String.join(",", strTagIds);
|
| 22273 |
amit.gupta |
249 |
}
|
|
|
250 |
|
| 22319 |
amit.gupta |
251 |
@ApiImplicitParams({
|
|
|
252 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
253 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 24091 |
tejbeer |
254 |
public ResponseEntity<?> getFofo(HttpServletRequest request,
|
| 26758 |
amit.gupta |
255 |
@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
|
| 22319 |
amit.gupta |
256 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| 23816 |
amit.gupta |
257 |
@RequestParam(value = "sort", required = false) String sort,
|
|
|
258 |
@RequestParam(value = "brand", required = false) String brand,
|
| 25011 |
amit.gupta |
259 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
| 24946 |
amit.gupta |
260 |
@RequestParam(value = "q", required = false) String queryTerm,
|
| 24091 |
tejbeer |
261 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
| 22328 |
amit.gupta |
262 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 22319 |
amit.gupta |
263 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 26889 |
amit.gupta |
264 |
dealResponse = this.getCatalogResponse(this.getSolrDocs(userInfo.getRetailerId(), queryTerm, categoryId, offset,
|
|
|
265 |
limit, sort, brand, subCategoryId, hotDeal), hotDeal, 0);
|
|
|
266 |
return responseSender.ok(dealResponse);
|
|
|
267 |
}
|
| 25015 |
amit.gupta |
268 |
|
| 26889 |
amit.gupta |
269 |
private JSONArray getSolrDocs(int fofoId, String queryTerm, String categoryId, String offset, String limit,
|
|
|
270 |
String sort, String brand, int subCategoryId, boolean hotDeal) throws Throwable {
|
|
|
271 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(fofoId);
|
|
|
272 |
List<String> parentFilter = new ArrayList<>();
|
|
|
273 |
parentFilter.add("categoryId_i:" + categoryId);
|
| 25015 |
amit.gupta |
274 |
|
| 26889 |
amit.gupta |
275 |
List<String> childFilter = new ArrayList<>();
|
|
|
276 |
childFilter.add("itemId_i:*");
|
|
|
277 |
|
|
|
278 |
Map<String, String> params = new HashMap<>();
|
|
|
279 |
if (queryTerm == null || queryTerm.equals("null")) {
|
|
|
280 |
queryTerm = "";
|
| 26589 |
amit.gupta |
281 |
} else {
|
| 26889 |
amit.gupta |
282 |
queryTerm = "(" + queryTerm + ")";
|
| 26589 |
amit.gupta |
283 |
}
|
| 26889 |
amit.gupta |
284 |
if (hotDeal) {
|
|
|
285 |
childFilter.add("hot_deal_b:true");
|
|
|
286 |
} else {
|
|
|
287 |
childFilter.add("active_b:true");
|
|
|
288 |
}
|
|
|
289 |
if (subCategoryId != 0) {
|
|
|
290 |
parentFilter.add("subCategoryId_i:" + subCategoryId);
|
|
|
291 |
}
|
|
|
292 |
if (StringUtils.isNotBlank(brand)) {
|
|
|
293 |
parentFilter.add("brand_ss:" + brand);
|
|
|
294 |
}
|
|
|
295 |
String parentFilterString = "\"" + String.join(" AND ", parentFilter) + "\"";
|
|
|
296 |
String childFilterString = String.join(" AND ", childFilter);
|
|
|
297 |
logger.info(parentFilterString);
|
|
|
298 |
params.put("q", String.format("%s{!parent which=%s}%s", queryTerm, parentFilterString, childFilterString));
|
| 26894 |
amit.gupta |
299 |
params.put("fl", String.format("*, [child parentFilter=id:catalog* childFilter=%s]",
|
| 26889 |
amit.gupta |
300 |
"\"" + childFilterString + "\""));
|
|
|
301 |
if (queryTerm == "") {
|
|
|
302 |
params.put("sort", "create_s desc");
|
|
|
303 |
}
|
|
|
304 |
params.put("start", String.valueOf(offset));
|
|
|
305 |
params.put("rows", String.valueOf(limit));
|
|
|
306 |
params.put("wt", "json");
|
|
|
307 |
String response = null;
|
|
|
308 |
try {
|
|
|
309 |
response = restClient.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
|
|
310 |
} catch (HttpHostConnectException e) {
|
|
|
311 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
312 |
}
|
|
|
313 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
314 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
315 |
return docs;
|
| 26589 |
amit.gupta |
316 |
}
|
|
|
317 |
|
|
|
318 |
@ApiImplicitParams({
|
|
|
319 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
320 |
@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
321 |
public ResponseEntity<?> partnerStock(HttpServletRequest request,
|
| 26758 |
amit.gupta |
322 |
@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
|
| 26589 |
amit.gupta |
323 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
|
|
324 |
@RequestParam(value = "sort", required = false) String sort,
|
|
|
325 |
@RequestParam(value = "brand", required = false) String brand,
|
|
|
326 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
|
|
327 |
@RequestParam(value = "q", required = false) String queryTerm,
|
|
|
328 |
@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
|
|
|
329 |
throws Throwable {
|
|
|
330 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
331 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
332 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 26889 |
amit.gupta |
333 |
dealResponse = this.getCatalogResponse(this.getSolrDocs(uc.getUserId(), queryTerm, categoryId, offset, limit,
|
|
|
334 |
sort, brand, subCategoryId, false), false, userInfo.getRetailerId());
|
| 22319 |
amit.gupta |
335 |
return responseSender.ok(dealResponse);
|
|
|
336 |
}
|
| 22273 |
amit.gupta |
337 |
|
| 22319 |
amit.gupta |
338 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22272 |
amit.gupta |
339 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
340 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 22272 |
amit.gupta |
341 |
@ApiOperation(value = "Get online deals")
|
| 22319 |
amit.gupta |
342 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
|
|
|
343 |
@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
|
|
|
344 |
@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
|
|
|
345 |
@RequestParam(value = "direction", required = false) String direction,
|
|
|
346 |
@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
|
|
347 |
logger.info("Request " + request.getParameterMap());
|
| 22272 |
amit.gupta |
348 |
String response = null;
|
| 22319 |
amit.gupta |
349 |
int userId = (int) request.getAttribute("userId");
|
| 22289 |
amit.gupta |
350 |
|
| 22319 |
amit.gupta |
351 |
String uri = "/deals/" + userId;
|
| 23532 |
amit.gupta |
352 |
RestClient rc = new RestClient();
|
| 22272 |
amit.gupta |
353 |
Map<String, String> params = new HashMap<>();
|
|
|
354 |
params.put("offset", offset);
|
|
|
355 |
params.put("limit", limit);
|
|
|
356 |
params.put("categoryId", categoryId);
|
|
|
357 |
params.put("direction", direction);
|
|
|
358 |
params.put("sort", sort);
|
|
|
359 |
params.put("source", "online");
|
|
|
360 |
params.put("filterData", filterData);
|
| 23816 |
amit.gupta |
361 |
/*
|
|
|
362 |
* if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
|
|
363 |
* params.put("tag_ids", getCommaSeparateTags(userId)); }
|
|
|
364 |
*/
|
| 22272 |
amit.gupta |
365 |
List<Object> responseObject = new ArrayList<>();
|
| 23532 |
amit.gupta |
366 |
try {
|
|
|
367 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
368 |
} catch (HttpHostConnectException e) {
|
|
|
369 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
370 |
}
|
| 22931 |
ashik.ali |
371 |
|
| 22272 |
amit.gupta |
372 |
JsonArray result_json = Json.parse(response).asArray();
|
| 22319 |
amit.gupta |
373 |
for (JsonValue j : result_json) {
|
| 23816 |
amit.gupta |
374 |
// logger.info("res " + j.asArray());
|
| 22272 |
amit.gupta |
375 |
List<Object> innerObject = new ArrayList<>();
|
| 22319 |
amit.gupta |
376 |
for (JsonValue jsonObject : j.asArray()) {
|
| 22272 |
amit.gupta |
377 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
378 |
}
|
| 22319 |
amit.gupta |
379 |
if (innerObject.size() > 0) {
|
| 22272 |
amit.gupta |
380 |
responseObject.add(innerObject);
|
|
|
381 |
}
|
|
|
382 |
}
|
| 23022 |
ashik.ali |
383 |
return responseSender.ok(responseObject);
|
| 22272 |
amit.gupta |
384 |
}
|
|
|
385 |
|
| 22319 |
amit.gupta |
386 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
387 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
| 21339 |
kshitij.so |
388 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
389 |
}
|
|
|
390 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
391 |
}
|
| 22319 |
amit.gupta |
392 |
|
|
|
393 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21356 |
kshitij.so |
394 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
395 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21356 |
kshitij.so |
396 |
@ApiOperation(value = "Get brand list and count for category")
|
| 22319 |
amit.gupta |
397 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
| 23816 |
amit.gupta |
398 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
|
| 22319 |
amit.gupta |
399 |
logger.info("Request " + request.getParameterMap());
|
| 21356 |
kshitij.so |
400 |
String response = null;
|
| 22319 |
amit.gupta |
401 |
// TODO: move to properties
|
| 21356 |
kshitij.so |
402 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 23532 |
amit.gupta |
403 |
RestClient rc = new RestClient();
|
| 21356 |
kshitij.so |
404 |
Map<String, String> params = new HashMap<>();
|
|
|
405 |
params.put("category_id", category_id);
|
| 21358 |
kshitij.so |
406 |
List<DealBrands> dealBrandsResponse = null;
|
| 23532 |
amit.gupta |
407 |
try {
|
|
|
408 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
409 |
} catch (HttpHostConnectException e) {
|
|
|
410 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
411 |
}
|
| 23816 |
amit.gupta |
412 |
|
| 22319 |
amit.gupta |
413 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
414 |
}.getType());
|
| 23022 |
ashik.ali |
415 |
|
|
|
416 |
return responseSender.ok(dealBrandsResponse);
|
| 21356 |
kshitij.so |
417 |
}
|
| 22319 |
amit.gupta |
418 |
|
|
|
419 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21445 |
kshitij.so |
420 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
421 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21445 |
kshitij.so |
422 |
@ApiOperation(value = "Get unit deal object")
|
| 23816 |
amit.gupta |
423 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
|
|
424 |
throws ProfitMandiBusinessException {
|
| 21445 |
kshitij.so |
425 |
String response = null;
|
| 22319 |
amit.gupta |
426 |
// TODO: move to properties
|
|
|
427 |
String uri = "getDealById/" + id;
|
|
|
428 |
System.out.println("Unit deal " + uri);
|
| 23532 |
amit.gupta |
429 |
RestClient rc = new RestClient();
|
| 21445 |
kshitij.so |
430 |
Map<String, String> params = new HashMap<>();
|
|
|
431 |
DealsResponse dealsResponse = null;
|
| 23532 |
amit.gupta |
432 |
try {
|
|
|
433 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
434 |
} catch (HttpHostConnectException e) {
|
|
|
435 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
436 |
}
|
| 23816 |
amit.gupta |
437 |
|
| 21445 |
kshitij.so |
438 |
JsonObject result_json = Json.parse(response).asObject();
|
| 22319 |
amit.gupta |
439 |
if (!result_json.isEmpty()) {
|
| 21445 |
kshitij.so |
440 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 22952 |
amit.gupta |
441 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
| 23816 |
amit.gupta |
442 |
while (iter.hasNext()) {
|
| 22952 |
amit.gupta |
443 |
AvailabilityInfo ai = iter.next();
|
| 23816 |
amit.gupta |
444 |
if (ai.getAvailability() <= 0)
|
| 22952 |
amit.gupta |
445 |
iter.remove();
|
|
|
446 |
}
|
| 21445 |
kshitij.so |
447 |
}
|
| 22952 |
amit.gupta |
448 |
return responseSender.ok(dealsResponse);
|
| 21445 |
kshitij.so |
449 |
}
|
| 23816 |
amit.gupta |
450 |
|
| 24091 |
tejbeer |
451 |
@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
452 |
@ApiImplicitParams({
|
|
|
453 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
454 |
@ApiOperation(value = "Get unit deal object")
|
|
|
455 |
public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
|
|
456 |
throws ProfitMandiBusinessException {
|
|
|
457 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
458 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
459 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
460 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
|
|
461 |
String categoryId = "(3 OR 6)";
|
|
|
462 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
463 |
RestClient rc = new RestClient();
|
|
|
464 |
Map<String, String> params = new HashMap<>();
|
|
|
465 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
466 |
String catalogString = "catalog" + id;
|
|
|
467 |
|
| 24149 |
amit.gupta |
468 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
|
|
|
469 |
categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
|
|
470 |
|
| 24091 |
tejbeer |
471 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
472 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
473 |
params.put("sort", "rank_i asc, create_s desc");
|
|
|
474 |
params.put("wt", "json");
|
|
|
475 |
String response = null;
|
|
|
476 |
try {
|
| 26575 |
amit.gupta |
477 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
| 24091 |
tejbeer |
478 |
} catch (HttpHostConnectException e) {
|
|
|
479 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
480 |
}
|
|
|
481 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
482 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 26889 |
amit.gupta |
483 |
dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
| 24091 |
tejbeer |
484 |
} else {
|
|
|
485 |
return responseSender.badRequest(
|
|
|
486 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
487 |
}
|
|
|
488 |
return responseSender.ok(dealResponse.get(0));
|
|
|
489 |
}
|
|
|
490 |
|
| 22333 |
amit.gupta |
491 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 24949 |
amit.gupta |
492 |
public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
|
| 25010 |
amit.gupta |
493 |
@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
|
| 24163 |
amit.gupta |
494 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 25543 |
amit.gupta |
495 |
logger.info("userInfo [{}]", userInfo);
|
| 25879 |
amit.gupta |
496 |
List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
|
|
|
497 |
categoryId);
|
| 24163 |
amit.gupta |
498 |
return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
|
| 22333 |
amit.gupta |
499 |
}
|
| 25879 |
amit.gupta |
500 |
|
| 25813 |
amit.gupta |
501 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
502 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
|
|
503 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
504 |
logger.info("userInfo [{}]", userInfo);
|
| 26889 |
amit.gupta |
505 |
List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
|
|
|
506 |
return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
|
| 25813 |
amit.gupta |
507 |
}
|
| 23816 |
amit.gupta |
508 |
|
| 25011 |
amit.gupta |
509 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
| 25010 |
amit.gupta |
510 |
List<DBObject> subCategories = new ArrayList<>();
|
|
|
511 |
RestClient rc = new RestClient();
|
|
|
512 |
Map<String, String> params = new HashMap<>();
|
|
|
513 |
params.put("q", "categoryId_i:6");
|
|
|
514 |
params.put("group", "true");
|
|
|
515 |
params.put("group.field", "subCategoryId_i");
|
|
|
516 |
params.put("wt", "json");
|
| 25126 |
amit.gupta |
517 |
params.put("rows", "50");
|
| 25014 |
amit.gupta |
518 |
params.put("fl", "subCategoryId_i");
|
| 25010 |
amit.gupta |
519 |
String response = null;
|
|
|
520 |
try {
|
| 26575 |
amit.gupta |
521 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
| 25010 |
amit.gupta |
522 |
} catch (HttpHostConnectException e) {
|
|
|
523 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
524 |
}
|
|
|
525 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
|
|
|
526 |
JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
|
|
|
527 |
List<Integer> categoryIds = new ArrayList<>();
|
| 25015 |
amit.gupta |
528 |
for (int i = 0; i < groups.length(); i++) {
|
|
|
529 |
JSONObject groupObject = groups.getJSONObject(i);
|
|
|
530 |
int subCategoryId = groupObject.getInt("groupValue");
|
| 25010 |
amit.gupta |
531 |
int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
|
| 25013 |
amit.gupta |
532 |
categoryIds.add(subCategoryId);
|
| 25010 |
amit.gupta |
533 |
}
|
| 25015 |
amit.gupta |
534 |
|
| 25010 |
amit.gupta |
535 |
List<Category> categories = categoryRepository.selectByIds(categoryIds);
|
| 25015 |
amit.gupta |
536 |
AtomicInteger i = new AtomicInteger(0);
|
|
|
537 |
categories.forEach(x -> {
|
| 25011 |
amit.gupta |
538 |
DBObject dbObject = new BasicDBObject();
|
|
|
539 |
dbObject.put("name", x.getLabel());
|
|
|
540 |
dbObject.put("subCategoryId", x.getId());
|
|
|
541 |
dbObject.put("rank", i.incrementAndGet());
|
|
|
542 |
dbObject.put("categoryId", 6);
|
| 26441 |
tejbeer |
543 |
dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
|
| 25011 |
amit.gupta |
544 |
subCategories.add(dbObject);
|
| 25010 |
amit.gupta |
545 |
});
|
| 25015 |
amit.gupta |
546 |
|
| 25011 |
amit.gupta |
547 |
return subCategories;
|
| 25015 |
amit.gupta |
548 |
|
| 25010 |
amit.gupta |
549 |
}
|
|
|
550 |
|
| 22446 |
amit.gupta |
551 |
@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22448 |
amit.gupta |
552 |
public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
|
| 22447 |
amit.gupta |
553 |
return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
|
| 22446 |
amit.gupta |
554 |
}
|
| 23816 |
amit.gupta |
555 |
|
| 23793 |
tejbeer |
556 |
@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
557 |
public ResponseEntity<?> getSubcategoriesToDisplay() {
|
|
|
558 |
return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
|
|
|
559 |
}
|
| 23816 |
amit.gupta |
560 |
|
| 22406 |
amit.gupta |
561 |
@ApiImplicitParams({
|
| 23816 |
amit.gupta |
562 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 22401 |
amit.gupta |
563 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22931 |
ashik.ali |
564 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 22401 |
amit.gupta |
565 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
|
|
566 |
String uri = sb.append(skus).toString();
|
| 23532 |
amit.gupta |
567 |
RestClient rc = new RestClient();
|
|
|
568 |
String response;
|
|
|
569 |
try {
|
|
|
570 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
| 23816 |
amit.gupta |
571 |
} catch (HttpHostConnectException e) {
|
| 23532 |
amit.gupta |
572 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
573 |
}
|
| 22406 |
amit.gupta |
574 |
JsonArray result_json = Json.parse(response).asArray();
|
| 22407 |
amit.gupta |
575 |
List<Object> responseObject = new ArrayList<>();
|
|
|
576 |
for (JsonValue j : result_json) {
|
| 23816 |
amit.gupta |
577 |
// logger.info("res " + j.asArray());
|
| 22407 |
amit.gupta |
578 |
List<Object> innerObject = new ArrayList<>();
|
|
|
579 |
for (JsonValue jsonObject : j.asArray()) {
|
|
|
580 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
581 |
}
|
|
|
582 |
if (innerObject.size() > 0) {
|
|
|
583 |
responseObject.add(innerObject);
|
|
|
584 |
}
|
|
|
585 |
}
|
| 22408 |
amit.gupta |
586 |
return responseSender.ok(responseObject);
|
| 22401 |
amit.gupta |
587 |
}
|
| 21339 |
kshitij.so |
588 |
|
| 26889 |
amit.gupta |
589 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
|
| 24149 |
amit.gupta |
590 |
throws ProfitMandiBusinessException {
|
| 26889 |
amit.gupta |
591 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
|
|
592 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
| 24091 |
tejbeer |
593 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
594 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
595 |
if (docs.length() > 0) {
|
|
|
596 |
HashSet<Integer> itemsSet = new HashSet<>();
|
|
|
597 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
598 |
JSONObject doc = docs.getJSONObject(i);
|
| 26589 |
amit.gupta |
599 |
if (doc.has("_childDocuments_")) {
|
| 26515 |
amit.gupta |
600 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
601 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
602 |
int itemId = childItem.getInt("itemId_i");
|
|
|
603 |
itemsSet.add(itemId);
|
|
|
604 |
}
|
| 24091 |
tejbeer |
605 |
}
|
|
|
606 |
}
|
| 26589 |
amit.gupta |
607 |
if (itemsSet.size() == 0) {
|
| 26573 |
amit.gupta |
608 |
return dealResponse;
|
|
|
609 |
}
|
| 26889 |
amit.gupta |
610 |
if (hotDeal) {
|
|
|
611 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
|
|
612 |
} else if (fofoId > 0) {
|
|
|
613 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock().stream()
|
|
|
614 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
615 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
|
|
616 |
}
|
| 24091 |
tejbeer |
617 |
}
|
|
|
618 |
|
| 26889 |
amit.gupta |
619 |
List<FofoAvailabilityInfo> fdis = new ArrayList<>();
|
|
|
620 |
|
| 24091 |
tejbeer |
621 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
622 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
623 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
624 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
625 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
626 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
627 |
ffdr.setTitle(doc.getString("title_s"));
|
| 24117 |
amit.gupta |
628 |
try {
|
|
|
629 |
ffdr.setFeature(doc.getString("feature_s"));
|
| 24149 |
amit.gupta |
630 |
} catch (Exception e) {
|
| 24117 |
amit.gupta |
631 |
ffdr.setFeature(null);
|
| 24149 |
amit.gupta |
632 |
logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
|
| 24117 |
amit.gupta |
633 |
}
|
| 24091 |
tejbeer |
634 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
| 26589 |
amit.gupta |
635 |
if (doc.has("_childDocuments_")) {
|
| 26515 |
amit.gupta |
636 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
637 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
638 |
int itemId = childItem.getInt("itemId_i");
|
|
|
639 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
640 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
641 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
642 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
643 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
644 |
}
|
| 24091 |
tejbeer |
645 |
} else {
|
| 26515 |
amit.gupta |
646 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 26889 |
amit.gupta |
647 |
fdi.setSellingPrice(sellingPrice);
|
|
|
648 |
fdi.setActive(childItem.getBoolean("active_b"));
|
|
|
649 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
| 26515 |
amit.gupta |
650 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
651 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
652 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
653 |
fdi.setItem_id(itemId);
|
| 26696 |
amit.gupta |
654 |
Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
|
| 26846 |
tejbeer |
655 |
cashBack = cashBack == null ? 0 : cashBack;
|
| 26696 |
amit.gupta |
656 |
fdi.setCashback(cashBack);
|
| 26889 |
amit.gupta |
657 |
|
|
|
658 |
if (hotDeal) {
|
| 26515 |
amit.gupta |
659 |
try {
|
| 26889 |
amit.gupta |
660 |
int totalAvailability = ourItemAvailabilityMap.get(itemId);
|
|
|
661 |
if (totalAvailability <= 0) {
|
|
|
662 |
continue;
|
|
|
663 |
}
|
|
|
664 |
fdi.setAvailability(ourItemAvailabilityMap.get(itemId));
|
| 26515 |
amit.gupta |
665 |
} catch (Exception e) {
|
|
|
666 |
continue;
|
|
|
667 |
}
|
| 26889 |
amit.gupta |
668 |
} else if (fofoId == 0) {
|
|
|
669 |
// For accessories item availability should at be ordered for Rs.1000
|
|
|
670 |
fdi.setAvailability(100);
|
|
|
671 |
Item item = itemRepository.selectById(itemId);
|
|
|
672 |
// In case its tampered glass moq should be 5
|
|
|
673 |
if (item.getCategoryId() == 10020) {
|
|
|
674 |
fdi.setMinBuyQuantity(5);
|
|
|
675 |
} else {
|
|
|
676 |
fdi.setMinBuyQuantity(1);
|
| 26515 |
amit.gupta |
677 |
}
|
|
|
678 |
} else {
|
| 26889 |
amit.gupta |
679 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0 : ourItemAvailabilityMap.get(itemId);
|
|
|
680 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
|
|
681 |
fdi.setAvailability(ourStockAvailability + partnerAvailability);
|
| 24091 |
tejbeer |
682 |
}
|
| 26515 |
amit.gupta |
683 |
fdi.setQuantityStep(1);
|
|
|
684 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
|
|
685 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| 24091 |
tejbeer |
686 |
}
|
|
|
687 |
}
|
|
|
688 |
}
|
|
|
689 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
690 |
ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
|
|
|
691 |
dealResponse.add(ffdr);
|
|
|
692 |
}
|
|
|
693 |
}
|
|
|
694 |
return dealResponse;
|
|
|
695 |
|
|
|
696 |
}
|
|
|
697 |
|
| 25968 |
amit.gupta |
698 |
private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
|
|
|
699 |
boolean hotDeal) throws ProfitMandiBusinessException {
|
| 25879 |
amit.gupta |
700 |
Map<Integer, TagListing> itemTagListingMap = null;
|
|
|
701 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
702 |
List<Integer> tagIds = Arrays.asList(4);
|
| 26589 |
amit.gupta |
703 |
|
| 25968 |
amit.gupta |
704 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
|
|
|
705 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 25880 |
amit.gupta |
706 |
|
| 25879 |
amit.gupta |
707 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
708 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
709 |
JSONObject doc = docs.getJSONObject(i);
|
| 25880 |
amit.gupta |
710 |
|
| 25879 |
amit.gupta |
711 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
712 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
713 |
int itemId = childItem.getInt("itemId_i");
|
|
|
714 |
TagListing tl = itemTagListingMap.get(itemId);
|
| 26589 |
amit.gupta |
715 |
if (tl == null) {
|
| 25968 |
amit.gupta |
716 |
continue;
|
|
|
717 |
}
|
| 25879 |
amit.gupta |
718 |
if (hotDeal) {
|
|
|
719 |
if (!tl.isHotDeals()) {
|
|
|
720 |
continue;
|
|
|
721 |
}
|
|
|
722 |
}
|
|
|
723 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
724 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
725 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
726 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
727 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
728 |
}
|
|
|
729 |
} else {
|
|
|
730 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
|
|
731 |
fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
|
|
|
732 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
| 26665 |
amit.gupta |
733 |
fdi.setMop((float) tl.getMrp());
|
| 25879 |
amit.gupta |
734 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
735 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
736 |
fdi.setItem_id(itemId);
|
|
|
737 |
Item item = itemRepository.selectById(itemId);
|
|
|
738 |
// In case its tampered glass moq should be 5
|
|
|
739 |
if (item.getCategoryId() == 10020) {
|
|
|
740 |
fdi.setMinBuyQuantity(10);
|
|
|
741 |
} else {
|
|
|
742 |
fdi.setMinBuyQuantity(1);
|
|
|
743 |
}
|
| 26050 |
amit.gupta |
744 |
fdi.setAvailability(itemFilter.get(itemId));
|
| 25879 |
amit.gupta |
745 |
fdi.setQuantityStep(1);
|
|
|
746 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
|
|
747 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| 25880 |
amit.gupta |
751 |
for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
|
| 25879 |
amit.gupta |
752 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
753 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
754 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
755 |
ffdr.setTitle(doc.getString("title_s"));
|
|
|
756 |
try {
|
|
|
757 |
ffdr.setFeature(doc.getString("feature_s"));
|
|
|
758 |
} catch (Exception e) {
|
|
|
759 |
ffdr.setFeature(null);
|
|
|
760 |
logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
|
|
|
761 |
}
|
|
|
762 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
763 |
ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
|
|
|
764 |
dealResponse.add(ffdr);
|
|
|
765 |
}
|
|
|
766 |
}
|
|
|
767 |
}
|
|
|
768 |
return dealResponse;
|
| 25880 |
amit.gupta |
769 |
|
| 25879 |
amit.gupta |
770 |
}
|
| 25967 |
amit.gupta |
771 |
}
|