| 21339 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.eclipsesource.json.Json;
|
|
|
4 |
import com.eclipsesource.json.JsonArray;
|
|
|
5 |
import com.eclipsesource.json.JsonObject;
|
|
|
6 |
import com.eclipsesource.json.JsonValue;
|
|
|
7 |
import com.google.gson.Gson;
|
| 21356 |
kshitij.so |
8 |
import com.google.gson.reflect.TypeToken;
|
| 25010 |
amit.gupta |
9 |
import com.mongodb.BasicDBObject;
|
| 24163 |
amit.gupta |
10 |
import com.mongodb.DBObject;
|
| 21643 |
ashik.ali |
11 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21339 |
kshitij.so |
12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33929 |
tejus.loha |
13 |
import com.spice.profitmandi.common.model.BrandAndAddToCartEligibleModel;
|
| 21339 |
kshitij.so |
14 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22289 |
amit.gupta |
15 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 27030 |
amit.gupta |
16 |
import com.spice.profitmandi.common.solr.SolrService;
|
| 21643 |
ashik.ali |
17 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 22319 |
amit.gupta |
18 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 30686 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.entity.catalog.*;
|
| 31507 |
tejbeer |
20 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
| 30595 |
tejbeer |
21 |
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
|
| 33929 |
tejus.loha |
22 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 30669 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
| 27032 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
|
| 31572 |
tejbeer |
25 |
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
|
| 31507 |
tejbeer |
26 |
import com.spice.profitmandi.dao.enumuration.dtr.WebListingType;
|
| 31954 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.model.AmountModel;
|
| 30188 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 22361 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 30686 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 32978 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 31625 |
tejbeer |
32 |
import com.spice.profitmandi.dao.repository.fofo.CatalogFavouriteRepository;
|
| 34260 |
vikas.jang |
33 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 26846 |
tejbeer |
34 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
|
| 26847 |
tejbeer |
35 |
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
|
| 30669 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
| 33929 |
tejus.loha |
37 |
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
|
| 23798 |
amit.gupta |
38 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 31507 |
tejbeer |
39 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 30686 |
amit.gupta |
40 |
import com.spice.profitmandi.service.inventory.*;
|
| 31954 |
amit.gupta |
41 |
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
|
| 30123 |
amit.gupta |
42 |
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
|
|
|
43 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
| 22287 |
amit.gupta |
44 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 26695 |
amit.gupta |
45 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 21356 |
kshitij.so |
46 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 21339 |
kshitij.so |
47 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
48 |
import com.spice.profitmandi.web.res.DealsResponse;
|
|
|
49 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
50 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
51 |
import io.swagger.annotations.ApiOperation;
|
| 30686 |
amit.gupta |
52 |
import org.apache.commons.lang3.StringUtils;
|
|
|
53 |
import org.apache.http.conn.HttpHostConnectException;
|
|
|
54 |
import org.apache.logging.log4j.LogManager;
|
|
|
55 |
import org.apache.logging.log4j.Logger;
|
|
|
56 |
import org.json.JSONArray;
|
|
|
57 |
import org.json.JSONObject;
|
|
|
58 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
59 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
60 |
import org.springframework.http.HttpStatus;
|
|
|
61 |
import org.springframework.http.MediaType;
|
|
|
62 |
import org.springframework.http.ResponseEntity;
|
|
|
63 |
import org.springframework.stereotype.Controller;
|
|
|
64 |
import org.springframework.transaction.annotation.Transactional;
|
| 33929 |
tejus.loha |
65 |
import org.springframework.web.bind.annotation.*;
|
| 21339 |
kshitij.so |
66 |
|
| 30686 |
amit.gupta |
67 |
import javax.servlet.http.HttpServletRequest;
|
| 31954 |
amit.gupta |
68 |
import java.time.LocalDate;
|
| 31625 |
tejbeer |
69 |
import java.time.LocalDateTime;
|
| 30686 |
amit.gupta |
70 |
import java.util.*;
|
| 35411 |
amit |
71 |
import java.util.concurrent.CompletableFuture;
|
| 30686 |
amit.gupta |
72 |
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
73 |
import java.util.stream.Collectors;
|
|
|
74 |
|
| 21339 |
kshitij.so |
75 |
@Controller
|
| 22319 |
amit.gupta |
76 |
@Transactional(rollbackFor = Throwable.class)
|
| 21339 |
kshitij.so |
77 |
public class DealsController {
|
|
|
78 |
|
| 32339 |
tejbeer |
79 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
|
|
80 |
private static final List<Integer> TAG_IDS = Arrays.asList(4);
|
| 21339 |
kshitij.so |
81 |
|
| 32339 |
tejbeer |
82 |
@Value("${python.api.host}")
|
|
|
83 |
private String host;
|
| 23816 |
amit.gupta |
84 |
|
| 32339 |
tejbeer |
85 |
@Value("${new.solr.url}")
|
|
|
86 |
private String solrUrl;
|
| 26889 |
amit.gupta |
87 |
|
| 32339 |
tejbeer |
88 |
@Value("${python.api.port}")
|
|
|
89 |
private int port;
|
| 23816 |
amit.gupta |
90 |
|
| 32339 |
tejbeer |
91 |
@Autowired
|
|
|
92 |
RestClient restClient;
|
| 27051 |
amit.gupta |
93 |
|
| 32339 |
tejbeer |
94 |
@Autowired
|
|
|
95 |
SolrService solrService;
|
| 26889 |
amit.gupta |
96 |
|
| 32339 |
tejbeer |
97 |
@Autowired
|
| 33873 |
ranu |
98 |
com.spice.profitmandi.web.services.SolrService webSolrService;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
| 32339 |
tejbeer |
101 |
InventoryService inventoryService;
|
| 26924 |
amit.gupta |
102 |
|
| 32339 |
tejbeer |
103 |
// This is now unused as we are not supporting multiple companies.
|
|
|
104 |
@Value("${gadgetCops.invoice.cc}")
|
|
|
105 |
private String[] ccGadgetCopInvoiceTo;
|
| 22319 |
amit.gupta |
106 |
|
| 32339 |
tejbeer |
107 |
@Autowired
|
|
|
108 |
private PricingService pricingService;
|
| 23816 |
amit.gupta |
109 |
|
| 32339 |
tejbeer |
110 |
@Autowired
|
|
|
111 |
private CategoryRepository categoryRepository;
|
| 25010 |
amit.gupta |
112 |
|
| 32339 |
tejbeer |
113 |
@Autowired
|
|
|
114 |
private SchemeService schemeService;
|
| 26695 |
amit.gupta |
115 |
|
| 32339 |
tejbeer |
116 |
@Autowired
|
|
|
117 |
private SaholicInventoryService saholicInventoryService;
|
| 26889 |
amit.gupta |
118 |
|
| 32339 |
tejbeer |
119 |
@Autowired
|
|
|
120 |
private Mongo mongoClient;
|
| 25879 |
amit.gupta |
121 |
|
| 32339 |
tejbeer |
122 |
@Autowired
|
|
|
123 |
private ItemBucketService itemBucketService;
|
| 23816 |
amit.gupta |
124 |
|
| 32339 |
tejbeer |
125 |
@Autowired
|
|
|
126 |
private UserAccountRepository userAccountRepository;
|
| 27051 |
amit.gupta |
127 |
|
| 32339 |
tejbeer |
128 |
@Autowired
|
|
|
129 |
private FofoStoreRepository fofoStoreRepository;
|
| 23816 |
amit.gupta |
130 |
|
| 32339 |
tejbeer |
131 |
@Autowired
|
|
|
132 |
private ResponseSender<?> responseSender;
|
| 23816 |
amit.gupta |
133 |
|
| 32339 |
tejbeer |
134 |
@Autowired
|
|
|
135 |
private TagListingRepository tagListingRepository;
|
| 23816 |
amit.gupta |
136 |
|
| 32339 |
tejbeer |
137 |
@Autowired
|
|
|
138 |
private ItemRepository itemRepository;
|
|
|
139 |
@Autowired
|
|
|
140 |
private PriceCircularService priceCircularService;
|
| 23816 |
amit.gupta |
141 |
|
| 32339 |
tejbeer |
142 |
@Autowired
|
|
|
143 |
private RoleManager roleManagerService;
|
| 23816 |
amit.gupta |
144 |
|
| 32339 |
tejbeer |
145 |
@Autowired
|
| 32978 |
amit.gupta |
146 |
private SuggestedPoDetailRepository suggestedPoDetailRepository;
|
| 26846 |
tejbeer |
147 |
|
| 32339 |
tejbeer |
148 |
@Autowired
|
|
|
149 |
private SuggestedPoRepository suggestedPoRepository;
|
| 26847 |
tejbeer |
150 |
|
| 32339 |
tejbeer |
151 |
@Autowired
|
|
|
152 |
private WebOfferRepository webOfferRepository;
|
| 30595 |
tejbeer |
153 |
|
| 32339 |
tejbeer |
154 |
@Autowired
|
|
|
155 |
private ComboModelRepository comboModelRepository;
|
| 30683 |
tejbeer |
156 |
|
| 32339 |
tejbeer |
157 |
@Autowired
|
|
|
158 |
private ComboMappedModelRepository comboMappedModelRepository;
|
| 30683 |
tejbeer |
159 |
|
| 32339 |
tejbeer |
160 |
@Autowired
|
|
|
161 |
private BrandsService brandsService;
|
| 31547 |
tejbeer |
162 |
|
| 32339 |
tejbeer |
163 |
@Autowired
|
|
|
164 |
private WebListingRepository webListingRepository;
|
| 31547 |
tejbeer |
165 |
|
| 32339 |
tejbeer |
166 |
@Autowired
|
|
|
167 |
private WebProductListingRepository webProductListingRepository;
|
| 31547 |
tejbeer |
168 |
|
| 32339 |
tejbeer |
169 |
@Autowired
|
|
|
170 |
private CatalogFavouriteRepository catalogFavouriteRepository;
|
| 31625 |
tejbeer |
171 |
|
| 33929 |
tejus.loha |
172 |
@Autowired
|
|
|
173 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
174 |
|
|
|
175 |
@Autowired
|
|
|
176 |
PartnerDealerRepository partnerDealerRepository;
|
|
|
177 |
|
|
|
178 |
@Autowired
|
|
|
179 |
BrandCommitRepository brandCommitRepository;
|
|
|
180 |
|
|
|
181 |
@Autowired
|
|
|
182 |
CatalogRepository catalogRepository;
|
|
|
183 |
|
| 34260 |
vikas.jang |
184 |
@Autowired
|
|
|
185 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
186 |
|
| 32339 |
tejbeer |
187 |
List<String> filterableParams = Arrays.asList("brand");
|
| 24949 |
amit.gupta |
188 |
|
| 32339 |
tejbeer |
189 |
@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
190 |
public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
191 |
logger.info("Request " + request.getParameterMap());
|
|
|
192 |
return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
|
|
|
193 |
}
|
| 25879 |
amit.gupta |
194 |
|
| 32339 |
tejbeer |
195 |
@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
196 |
public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
|
|
|
197 |
List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
|
|
|
198 |
Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
|
|
199 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
|
|
200 |
Map<String, String> params = new HashMap<>();
|
|
|
201 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
202 |
mandatoryQ.add(
|
|
|
203 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
|
|
204 |
params.put("start", "0");
|
|
|
205 |
params.put("rows", "100");
|
|
|
206 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
207 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 25879 |
amit.gupta |
208 |
|
| 32339 |
tejbeer |
209 |
params.put("wt", "json");
|
|
|
210 |
String response = null;
|
|
|
211 |
try {
|
| 35410 |
amit |
212 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32339 |
tejbeer |
213 |
} catch (HttpHostConnectException e) {
|
|
|
214 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
215 |
}
|
|
|
216 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
217 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
218 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
|
| 26051 |
amit.gupta |
219 |
|
| 32339 |
tejbeer |
220 |
Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
|
|
|
221 |
bucket.setFofoCatalogResponses(dealResponse);
|
|
|
222 |
return responseSender.ok(bucket);
|
|
|
223 |
}
|
| 25879 |
amit.gupta |
224 |
|
| 32339 |
tejbeer |
225 |
@RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
226 |
public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
|
| 34436 |
ranu |
227 |
int userId = (int) request.getAttribute("userId");
|
|
|
228 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
229 |
int fofoId = uc.getUserId();
|
|
|
230 |
SuggestedPo suggestedPo = suggestedPoRepository.selectAllOpenPoByFofoId(fofoId).get(0);
|
|
|
231 |
if(suggestedPo == null){
|
|
|
232 |
throw new ProfitMandiBusinessException("", "", "Open po is not available in list");
|
|
|
233 |
}
|
|
|
234 |
List<SuggestedPoDetail> mpd = suggestedPoDetailRepository.selectByPoId(suggestedPo.getId());
|
| 32339 |
tejbeer |
235 |
Map<Integer, Integer> itemIdsQtyMap = mpd.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 26846 |
tejbeer |
236 |
|
| 32339 |
tejbeer |
237 |
Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 35410 |
amit |
238 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
239 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
240 |
mandatoryQ.add(
|
|
|
241 |
String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
|
|
|
242 |
params.put("start", "0");
|
|
|
243 |
params.put("rows", "100");
|
|
|
244 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
245 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 26846 |
tejbeer |
246 |
|
| 32339 |
tejbeer |
247 |
params.put("wt", "json");
|
|
|
248 |
String response = null;
|
|
|
249 |
try {
|
| 35410 |
amit |
250 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32339 |
tejbeer |
251 |
} catch (HttpHostConnectException e) {
|
|
|
252 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
253 |
}
|
|
|
254 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
255 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
256 |
List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
|
| 26846 |
tejbeer |
257 |
|
| 32339 |
tejbeer |
258 |
return responseSender.ok(dealResponse);
|
|
|
259 |
}
|
| 26846 |
tejbeer |
260 |
|
| 34436 |
ranu |
261 |
@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 32339 |
tejbeer |
262 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
263 |
@ApiOperation(value = "")
|
|
|
264 |
public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
|
|
|
265 |
SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
|
|
|
266 |
suggestedPo.setStatus("closed");
|
| 33873 |
ranu |
267 |
//suggestedPo.setStatus(SuggestedPoStatus.valueOf("closed"));
|
| 26847 |
tejbeer |
268 |
|
| 32339 |
tejbeer |
269 |
return responseSender.ok(true);
|
|
|
270 |
}
|
| 26847 |
tejbeer |
271 |
|
| 32339 |
tejbeer |
272 |
@RequestMapping(value = "/fofo/fovourites", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
273 |
public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
|
| 31625 |
tejbeer |
274 |
|
| 32339 |
tejbeer |
275 |
int userId = (int) request.getAttribute("userId");
|
|
|
276 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
277 |
int fofoId = uc.getUserId();
|
|
|
278 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
279 |
Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
280 |
if (!catalogIds.isEmpty()) {
|
| 33929 |
tejus.loha |
281 |
dealResponse = webSolrService.dealResponse(catalogIds, fofoId);
|
| 32339 |
tejbeer |
282 |
}
|
|
|
283 |
return responseSender.ok(dealResponse);
|
|
|
284 |
}
|
| 31625 |
tejbeer |
285 |
|
| 32339 |
tejbeer |
286 |
@RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
287 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
288 |
@ApiOperation(value = "")
|
|
|
289 |
public ResponseEntity<?> mangeFavourites(HttpServletRequest request, @RequestParam int catalogId) throws ProfitMandiBusinessException {
|
| 31625 |
tejbeer |
290 |
|
| 32339 |
tejbeer |
291 |
int userId = (int) request.getAttribute("userId");
|
|
|
292 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
293 |
int fofoId = uc.getUserId();
|
| 31625 |
tejbeer |
294 |
|
| 32339 |
tejbeer |
295 |
CatalogFavourite catalogFavourite = catalogFavouriteRepository.selectBypartnerAndCatalogId(fofoId, catalogId);
|
| 31625 |
tejbeer |
296 |
|
| 32339 |
tejbeer |
297 |
if (catalogFavourite == null) {
|
|
|
298 |
catalogFavourite = new CatalogFavourite();
|
|
|
299 |
catalogFavourite.setCatalogId(catalogId);
|
|
|
300 |
catalogFavourite.setFofoId(fofoId);
|
|
|
301 |
catalogFavourite.setCreatedTimestamp(LocalDateTime.now());
|
|
|
302 |
catalogFavouriteRepository.persist(catalogFavourite);
|
| 31625 |
tejbeer |
303 |
|
| 32978 |
amit.gupta |
304 |
} else {
|
| 32339 |
tejbeer |
305 |
catalogFavouriteRepository.deleteByPartnerAndCatalogId(fofoId, catalogId);
|
|
|
306 |
}
|
|
|
307 |
return responseSender.ok(true);
|
|
|
308 |
}
|
| 31625 |
tejbeer |
309 |
|
| 33249 |
ranu |
310 |
private String getCommaSeparateTags(int userId) throws ProfitMandiBusinessException {
|
| 32339 |
tejbeer |
311 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
312 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
|
|
313 |
List<String> strTagIds = new ArrayList<>();
|
|
|
314 |
for (Integer tagId : tagIds) {
|
|
|
315 |
strTagIds.add(String.valueOf(tagId));
|
|
|
316 |
}
|
|
|
317 |
return String.join(",", strTagIds);
|
|
|
318 |
}
|
| 22273 |
amit.gupta |
319 |
|
| 33575 |
amit.gupta |
320 |
@RequestMapping(value = "/fofo/similar-models/{modelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
321 |
public ResponseEntity<?> similarModels(HttpServletRequest httpServletRequest, @PathVariable int modelId) throws Throwable {
|
|
|
322 |
UserInfo userInfo = (UserInfo) httpServletRequest.getAttribute("userInfo");
|
|
|
323 |
//FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
324 |
|
|
|
325 |
JSONObject jsonObject = solrService.getContentByCatalogIds(Arrays.asList(modelId)).get(modelId);
|
|
|
326 |
|
|
|
327 |
JSONArray similarModelsArray = jsonObject.getJSONArray("similarModels_ii");
|
|
|
328 |
List<Integer> similarCatalogIds = new ArrayList<>();
|
|
|
329 |
for (int j = 0; j < similarModelsArray.length(); j++) {
|
|
|
330 |
similarCatalogIds.add(similarModelsArray.getInt(j));
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
Map<String, String> params = new HashMap<>();
|
|
|
334 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
335 |
|
|
|
336 |
mandatoryQ.add(String.format(
|
|
|
337 |
"+{!parent which=\"catalogId_i:(" + StringUtils.join(similarCatalogIds, " ") + ")\"} AND active_b:true AND show_default_b:true"));
|
|
|
338 |
|
|
|
339 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
340 |
params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
|
|
|
341 |
params.put("wt", "json");
|
|
|
342 |
params.put("rows", similarCatalogIds.size() + "");
|
|
|
343 |
try {
|
|
|
344 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
|
|
345 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
346 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 33576 |
amit.gupta |
347 |
return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
|
| 33575 |
amit.gupta |
348 |
} catch (HttpHostConnectException e) {
|
|
|
349 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
|
| 32339 |
tejbeer |
353 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
354 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 33573 |
amit.gupta |
355 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
|
| 34024 |
vikas.jang |
356 |
@RequestParam(value = "limit") int limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand, @RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(value = "q", required = false) String queryTerm, @RequestParam(value = "hotDeal", required = false) boolean hotDeal, @RequestParam(value = "endPoint", required = false) String endPoint,@RequestParam(value = "group", required = false) boolean group) throws Throwable {
|
| 33543 |
amit.gupta |
357 |
List<FofoCatalogResponse> dealResponse;
|
| 32339 |
tejbeer |
358 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
359 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
360 |
sort = "w" + fs.getWarehouseId() + "_i desc";
|
| 31548 |
tejbeer |
361 |
|
| 32339 |
tejbeer |
362 |
logger.info("endPoint {}", endPoint);
|
| 34024 |
vikas.jang |
363 |
logger.info("group Column {}", group);
|
| 31552 |
tejbeer |
364 |
|
| 32339 |
tejbeer |
365 |
if (endPoint != null && !endPoint.trim().isEmpty()) {
|
|
|
366 |
WebListing webListing = webListingRepository.selectByUrl(endPoint);
|
| 35411 |
amit |
367 |
dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
|
| 31552 |
tejbeer |
368 |
|
| 32339 |
tejbeer |
369 |
} else {
|
| 31552 |
tejbeer |
370 |
|
| 32339 |
tejbeer |
371 |
dealResponse = this.getCatalogResponse(
|
| 35369 |
ranu |
372 |
solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,true), hotDeal, userInfo.getRetailerId());
|
| 32339 |
tejbeer |
373 |
}
|
| 33573 |
amit.gupta |
374 |
|
|
|
375 |
Map<Integer, List<Integer>> similarModelMap = dealResponse.stream().filter(x -> x.getSimilarModelIds() != null && x.getSimilarModelIds().size() > 0)
|
|
|
376 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
|
|
|
377 |
Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
|
|
|
378 |
logger.info("similarModelIds - {}", similarModelIds);
|
| 33575 |
amit.gupta |
379 |
if (similarModelIds.size() > 0) {
|
| 33573 |
amit.gupta |
380 |
|
| 33576 |
amit.gupta |
381 |
Map<Integer, FofoCatalogResponse> similarCatalogResponsesMap = this.getSimpleDocs(fs, similarModelIds).stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
| 33573 |
amit.gupta |
382 |
logger.info("Similar Catalog ResponseMap - {}", similarCatalogResponsesMap.keySet());
|
|
|
383 |
|
|
|
384 |
for (FofoCatalogResponse deal : dealResponse) {
|
|
|
385 |
if (similarModelMap.containsKey(deal.getCatalogId())) {
|
|
|
386 |
List<Integer> similarCatalogIds = similarModelMap.get(deal.getCatalogId());
|
|
|
387 |
logger.info("Similar Catalog Ids - {}", similarCatalogIds);
|
| 33575 |
amit.gupta |
388 |
List<FofoCatalogResponse> similarModels = similarCatalogIds.stream().filter(x -> similarCatalogResponsesMap.containsKey(x)).map(x -> similarCatalogResponsesMap.get(x)).collect(Collectors.toList());
|
| 33573 |
amit.gupta |
389 |
deal.setSimilarModels(similarModels);
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
}
|
| 32339 |
tejbeer |
393 |
return responseSender.ok(dealResponse);
|
|
|
394 |
}
|
| 25015 |
amit.gupta |
395 |
|
| 33576 |
amit.gupta |
396 |
private List<FofoCatalogResponse> getSimpleDocs(FofoStore fofoStore, Set<Integer> catalogIds) throws Exception {
|
| 33575 |
amit.gupta |
397 |
List<FofoCatalogResponse> fofoCatalogResponses = new ArrayList<>();
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
Map<String, String> params = new HashMap<>();
|
|
|
401 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
402 |
|
|
|
403 |
mandatoryQ.add(String.format(
|
|
|
404 |
"+{!parent which=\"catalogId_i:(" + StringUtils.join(catalogIds, " ") + ")\"} AND active_b:true AND show_default_b:true"));
|
|
|
405 |
|
|
|
406 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
407 |
params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
|
|
|
408 |
params.put("wt", "json");
|
|
|
409 |
params.put("rows", catalogIds.size() + "");
|
|
|
410 |
|
| 33576 |
amit.gupta |
411 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
|
|
412 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
413 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 35410 |
amit |
414 |
int warehouseId = fofoStore.getWarehouseId();
|
| 33576 |
amit.gupta |
415 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
|
| 35410 |
amit |
416 |
|
|
|
417 |
// Pre-fetch all itemIds for batch CIS query
|
|
|
418 |
List<Integer> allItemIds = new ArrayList<>();
|
| 33576 |
amit.gupta |
419 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
420 |
JSONObject doc = docs.getJSONObject(i);
|
| 35410 |
amit |
421 |
if (doc.has("_childDocuments_")) {
|
|
|
422 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
423 |
allItemIds.add(doc.getJSONArray("_childDocuments_").getJSONObject(j).getInt("itemId_i"));
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
// Batch fetch CIS data
|
|
|
428 |
Map<Integer, List<SaholicCISTable>> cisDataByItemId = saholicCISTableRepository
|
|
|
429 |
.selectByItemWarehouse(allItemIds, warehouseId).stream()
|
|
|
430 |
.collect(Collectors.groupingBy(SaholicCISTable::getItemId));
|
|
|
431 |
|
|
|
432 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
433 |
JSONObject doc = docs.getJSONObject(i);
|
| 33576 |
amit.gupta |
434 |
FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
|
|
|
435 |
if (doc.has("_childDocuments_")) {
|
|
|
436 |
String modelColorClass = "grey";
|
|
|
437 |
FofoAvailabilityInfo fdiAnyColour = null;
|
|
|
438 |
// Iterating itemIds
|
|
|
439 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
440 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
441 |
int itemId = childItem.getInt("itemId_i");
|
|
|
442 |
|
| 35410 |
amit |
443 |
List<SaholicCISTable> currentAvailability = cisDataByItemId.getOrDefault(itemId, new ArrayList<>());
|
| 33576 |
amit.gupta |
444 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
445 |
if (poItemAvailabilityMap != null) {
|
|
|
446 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
for (SaholicCISTable saholicCISTable : currentAvailability) {
|
|
|
450 |
saholicCISTable.setWarehouseName(
|
|
|
451 |
ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
String poColor = "grey";
|
|
|
456 |
boolean active = false;
|
|
|
457 |
if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
|
|
|
458 |
poColor = "green";
|
|
|
459 |
modelColorClass = "green";
|
|
|
460 |
} else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
|
|
|
461 |
if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
|
|
|
462 |
poColor = "grey";
|
|
|
463 |
} else {
|
|
|
464 |
poColor = "yellow";
|
|
|
465 |
if (!modelColorClass.equals("green")) {
|
|
|
466 |
modelColorClass = poColor;
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
}
|
|
|
472 |
fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
|
| 33575 |
amit.gupta |
473 |
}
|
| 33576 |
amit.gupta |
474 |
|
|
|
475 |
fofoCatalogResponses.add(fofoCatalogResponse);
|
| 33575 |
amit.gupta |
476 |
}
|
| 33576 |
amit.gupta |
477 |
|
| 33575 |
amit.gupta |
478 |
return fofoCatalogResponses;
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
private FofoCatalogResponse toFofoCatalogResponse(JSONObject doc) {
|
|
|
482 |
FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
|
|
|
483 |
fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
484 |
fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
485 |
fofoCatalogResponse.setTitle(doc.getString("title_s"));
|
|
|
486 |
fofoCatalogResponse.setMop(doc.getFloat("mop_f"));
|
|
|
487 |
fofoCatalogResponse.setDp(doc.getFloat("dp_f"));
|
|
|
488 |
fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
489 |
return fofoCatalogResponse;
|
|
|
490 |
}
|
|
|
491 |
|
| 32339 |
tejbeer |
492 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
493 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
494 |
@ApiOperation(value = "Get online deals")
|
| 33575 |
amit.gupta |
495 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String
|
|
|
496 |
categoryId, @RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String
|
|
|
497 |
limit, @RequestParam(value = "sort", required = false) String
|
|
|
498 |
sort, @RequestParam(value = "direction", required = false) String
|
|
|
499 |
direction, @RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
| 32339 |
tejbeer |
500 |
logger.info("Request " + request.getParameterMap());
|
|
|
501 |
String response = null;
|
|
|
502 |
int userId = (int) request.getAttribute("userId");
|
| 22289 |
amit.gupta |
503 |
|
| 32339 |
tejbeer |
504 |
String uri = "/deals/" + userId;
|
| 35410 |
amit |
505 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
506 |
params.put("offset", offset);
|
|
|
507 |
params.put("limit", limit);
|
|
|
508 |
params.put("categoryId", categoryId);
|
|
|
509 |
params.put("direction", direction);
|
|
|
510 |
params.put("sort", sort);
|
|
|
511 |
params.put("source", "online");
|
|
|
512 |
params.put("filterData", filterData);
|
|
|
513 |
/*
|
|
|
514 |
* if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
|
|
515 |
* params.put("tag_ids", getCommaSeparateTags(userId)); }
|
|
|
516 |
*/
|
|
|
517 |
List<Object> responseObject = new ArrayList<>();
|
|
|
518 |
try {
|
| 35410 |
amit |
519 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 32339 |
tejbeer |
520 |
} catch (HttpHostConnectException e) {
|
|
|
521 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
522 |
}
|
| 22931 |
ashik.ali |
523 |
|
| 32339 |
tejbeer |
524 |
JsonArray result_json = Json.parse(response).asArray();
|
|
|
525 |
for (JsonValue j : result_json) {
|
|
|
526 |
// logger.info("res " + j.asArray());
|
|
|
527 |
List<Object> innerObject = new ArrayList<>();
|
|
|
528 |
for (JsonValue jsonObject : j.asArray()) {
|
|
|
529 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
530 |
}
|
|
|
531 |
if (innerObject.size() > 0) {
|
|
|
532 |
responseObject.add(innerObject);
|
|
|
533 |
}
|
|
|
534 |
}
|
|
|
535 |
return responseSender.ok(responseObject);
|
|
|
536 |
}
|
| 22272 |
amit.gupta |
537 |
|
| 32339 |
tejbeer |
538 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
539 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
|
|
540 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
541 |
}
|
|
|
542 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
543 |
}
|
| 22319 |
amit.gupta |
544 |
|
| 32339 |
tejbeer |
545 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
546 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
547 |
@ApiOperation(value = "Get brand list and count for category")
|
| 33575 |
amit.gupta |
548 |
public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value = "category_id") String
|
|
|
549 |
category_id) throws ProfitMandiBusinessException {
|
| 32339 |
tejbeer |
550 |
logger.info("Request " + request.getParameterMap());
|
|
|
551 |
String response = null;
|
|
|
552 |
// TODO: move to properties
|
|
|
553 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 35410 |
amit |
554 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
555 |
params.put("category_id", category_id);
|
|
|
556 |
List<DealBrands> dealBrandsResponse = null;
|
|
|
557 |
try {
|
| 35410 |
amit |
558 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 32339 |
tejbeer |
559 |
} catch (HttpHostConnectException e) {
|
|
|
560 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
561 |
}
|
| 23816 |
amit.gupta |
562 |
|
| 32339 |
tejbeer |
563 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
564 |
}.getType());
|
| 23022 |
ashik.ali |
565 |
|
| 32339 |
tejbeer |
566 |
return responseSender.ok(dealBrandsResponse);
|
|
|
567 |
}
|
| 22319 |
amit.gupta |
568 |
|
| 32339 |
tejbeer |
569 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
570 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
571 |
@ApiOperation(value = "Get unit deal object")
|
| 33575 |
amit.gupta |
572 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws
|
|
|
573 |
ProfitMandiBusinessException {
|
| 32339 |
tejbeer |
574 |
String response = null;
|
|
|
575 |
// TODO: move to properties
|
|
|
576 |
String uri = "getDealById/" + id;
|
|
|
577 |
System.out.println("Unit deal " + uri);
|
| 35410 |
amit |
578 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
579 |
DealsResponse dealsResponse = null;
|
|
|
580 |
try {
|
| 35410 |
amit |
581 |
response = restClient.get(SchemeType.HTTP, host, port, uri, params);
|
| 32339 |
tejbeer |
582 |
} catch (HttpHostConnectException e) {
|
|
|
583 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
584 |
}
|
| 23816 |
amit.gupta |
585 |
|
| 32339 |
tejbeer |
586 |
JsonObject result_json = Json.parse(response).asObject();
|
|
|
587 |
if (!result_json.isEmpty()) {
|
|
|
588 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
|
|
589 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
|
|
590 |
while (iter.hasNext()) {
|
|
|
591 |
AvailabilityInfo ai = iter.next();
|
|
|
592 |
if (ai.getAvailability() <= 0)
|
|
|
593 |
iter.remove();
|
|
|
594 |
}
|
|
|
595 |
}
|
|
|
596 |
return responseSender.ok(dealsResponse);
|
|
|
597 |
}
|
| 23816 |
amit.gupta |
598 |
|
| 32339 |
tejbeer |
599 |
@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
600 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
601 |
@ApiOperation(value = "Get unit deal object")
|
| 33575 |
amit.gupta |
602 |
public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws
|
|
|
603 |
Exception {
|
| 32339 |
tejbeer |
604 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
605 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
606 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
607 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
|
|
608 |
String categoryId = "(3 OR 6)";
|
|
|
609 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 35410 |
amit |
610 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
611 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
612 |
String catalogString = "catalog" + id;
|
| 24091 |
tejbeer |
613 |
|
| 32339 |
tejbeer |
614 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
| 24149 |
amit.gupta |
615 |
|
| 32339 |
tejbeer |
616 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
617 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
618 |
params.put("sort", "rank_i asc, create_s desc");
|
|
|
619 |
params.put("wt", "json");
|
|
|
620 |
String response = null;
|
|
|
621 |
try {
|
| 35410 |
amit |
622 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32339 |
tejbeer |
623 |
} catch (HttpHostConnectException e) {
|
|
|
624 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
625 |
}
|
|
|
626 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
627 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
628 |
dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
629 |
} else {
|
|
|
630 |
return responseSender.badRequest(
|
|
|
631 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
632 |
}
|
|
|
633 |
return responseSender.ok(dealResponse.get(0));
|
|
|
634 |
}
|
| 24091 |
tejbeer |
635 |
|
| 34436 |
ranu |
636 |
|
|
|
637 |
@RequestMapping(value = "/suggestedPoDeals", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
638 |
public ResponseEntity<?> suggestedPoDeals(HttpServletRequest request,@RequestBody Set<Integer>catalogIds) throws Exception {
|
|
|
639 |
|
|
|
640 |
int userId = (int) request.getAttribute("userId");
|
|
|
641 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
642 |
int fofoId = uc.getUserId();
|
|
|
643 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
644 |
if (!catalogIds.isEmpty()) {
|
|
|
645 |
dealResponse = webSolrService.dealResponse(catalogIds, fofoId);
|
|
|
646 |
}
|
|
|
647 |
return responseSender.ok(dealResponse);
|
|
|
648 |
}
|
|
|
649 |
|
| 32339 |
tejbeer |
650 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 33575 |
amit.gupta |
651 |
public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
|
|
|
652 |
@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
|
| 32339 |
tejbeer |
653 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
654 |
logger.info("userInfo [{}]", userInfo);
|
| 32717 |
ranu |
655 |
List<BrandCatalog> brandsDisplay = brandsService.getBrandsToDisplay(categoryId);
|
|
|
656 |
//List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
|
| 32339 |
tejbeer |
657 |
return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
|
|
|
658 |
}
|
| 25879 |
amit.gupta |
659 |
|
| 32339 |
tejbeer |
660 |
@RequestMapping(value = "/fofo/brandCatalog", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 33575 |
amit.gupta |
661 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
|
|
662 |
@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
|
| 32339 |
tejbeer |
663 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
664 |
logger.info("userInfo [{}]", userInfo);
|
| 31507 |
tejbeer |
665 |
|
| 32339 |
tejbeer |
666 |
List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
|
|
|
667 |
return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
|
|
|
668 |
}
|
| 31507 |
tejbeer |
669 |
|
| 32339 |
tejbeer |
670 |
@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
671 |
public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
|
|
|
672 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
673 |
logger.info("userInfo [{}]", userInfo);
|
|
|
674 |
List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
|
|
|
675 |
return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
|
|
|
676 |
}
|
| 23816 |
amit.gupta |
677 |
|
| 32339 |
tejbeer |
678 |
private List<DBObject> getSubCategoriesToDisplay() throws Exception {
|
|
|
679 |
List<DBObject> subCategories = new ArrayList<>();
|
| 35410 |
amit |
680 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
681 |
params.put("q", "categoryId_i:6");
|
|
|
682 |
params.put("group", "true");
|
|
|
683 |
params.put("group.field", "subCategoryId_i");
|
|
|
684 |
params.put("wt", "json");
|
|
|
685 |
params.put("rows", "50");
|
|
|
686 |
params.put("fl", "subCategoryId_i");
|
|
|
687 |
String response = null;
|
|
|
688 |
try {
|
| 35410 |
amit |
689 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32339 |
tejbeer |
690 |
} catch (HttpHostConnectException e) {
|
|
|
691 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
692 |
}
|
|
|
693 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
|
|
|
694 |
JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
|
|
|
695 |
List<Integer> categoryIds = new ArrayList<>();
|
|
|
696 |
for (int i = 0; i < groups.length(); i++) {
|
|
|
697 |
JSONObject groupObject = groups.getJSONObject(i);
|
|
|
698 |
int subCategoryId = groupObject.getInt("groupValue");
|
|
|
699 |
int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
|
|
|
700 |
categoryIds.add(subCategoryId);
|
|
|
701 |
}
|
| 25015 |
amit.gupta |
702 |
|
| 32339 |
tejbeer |
703 |
List<Category> categories = categoryRepository.selectByIds(categoryIds);
|
|
|
704 |
AtomicInteger i = new AtomicInteger(0);
|
|
|
705 |
categories.forEach(x -> {
|
|
|
706 |
DBObject dbObject = new BasicDBObject();
|
|
|
707 |
dbObject.put("name", x.getLabel());
|
|
|
708 |
dbObject.put("subCategoryId", x.getId());
|
|
|
709 |
dbObject.put("rank", i.incrementAndGet());
|
|
|
710 |
dbObject.put("categoryId", 6);
|
|
|
711 |
dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
|
|
|
712 |
subCategories.add(dbObject);
|
|
|
713 |
});
|
| 25015 |
amit.gupta |
714 |
|
| 32339 |
tejbeer |
715 |
return subCategories;
|
| 25015 |
amit.gupta |
716 |
|
| 32339 |
tejbeer |
717 |
}
|
| 25010 |
amit.gupta |
718 |
|
| 32339 |
tejbeer |
719 |
@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
720 |
public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
|
|
|
721 |
return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
|
|
|
722 |
}
|
| 23816 |
amit.gupta |
723 |
|
| 32339 |
tejbeer |
724 |
@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
725 |
public ResponseEntity<?> getSubcategoriesToDisplay() {
|
|
|
726 |
return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
|
|
|
727 |
}
|
| 23816 |
amit.gupta |
728 |
|
| 32339 |
tejbeer |
729 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
730 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
731 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
|
|
732 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
|
|
733 |
String uri = sb.append(skus).toString();
|
| 35410 |
amit |
734 |
String response;
|
| 32339 |
tejbeer |
735 |
try {
|
| 35410 |
amit |
736 |
response = restClient.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
| 32339 |
tejbeer |
737 |
} catch (HttpHostConnectException e) {
|
|
|
738 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
739 |
}
|
|
|
740 |
JsonArray result_json = Json.parse(response).asArray();
|
|
|
741 |
List<Object> responseObject = new ArrayList<>();
|
|
|
742 |
for (JsonValue j : result_json) {
|
|
|
743 |
// logger.info("res " + j.asArray());
|
|
|
744 |
List<Object> innerObject = new ArrayList<>();
|
|
|
745 |
for (JsonValue jsonObject : j.asArray()) {
|
|
|
746 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
747 |
}
|
|
|
748 |
if (innerObject.size() > 0) {
|
|
|
749 |
responseObject.add(innerObject);
|
|
|
750 |
}
|
|
|
751 |
}
|
|
|
752 |
return responseSender.ok(responseObject);
|
|
|
753 |
}
|
| 21339 |
kshitij.so |
754 |
|
| 32339 |
tejbeer |
755 |
@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
756 |
public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
|
|
|
757 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
|
|
|
758 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 34786 |
aman.kumar |
759 |
|
| 35412 |
amit |
760 |
// Pre-fetch FofoStore once (instead of N times inside getDealResponses)
|
| 35411 |
amit |
761 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
762 |
|
| 35412 |
amit |
763 |
for (WebListing webListing : webListings) {
|
|
|
764 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, fs, webListing, 0, 20));
|
|
|
765 |
}
|
| 32339 |
tejbeer |
766 |
return responseSender.ok(webListings);
|
|
|
767 |
}
|
| 31547 |
tejbeer |
768 |
|
| 35411 |
amit |
769 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset,
|
| 33576 |
amit.gupta |
770 |
int limit) throws Exception {
|
| 31572 |
tejbeer |
771 |
|
| 35411 |
amit |
772 |
Map<String, String> params = new HashMap<>();
|
| 32339 |
tejbeer |
773 |
List<String> mandatoryQ = new ArrayList<>();
|
| 31670 |
tejbeer |
774 |
|
| 32339 |
tejbeer |
775 |
params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
|
| 31576 |
tejbeer |
776 |
|
| 32339 |
tejbeer |
777 |
List<Integer> webProducts = null;
|
|
|
778 |
if (webListing.getType().equals(WebListingType.solr)) {
|
|
|
779 |
logger.info("solrtype {}", webListing.getSolrQuery());
|
|
|
780 |
mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
|
|
|
781 |
} else {
|
|
|
782 |
logger.info("solrtype2 {}", webListing.getSolrQuery());
|
| 31675 |
tejbeer |
783 |
|
| 33573 |
amit.gupta |
784 |
webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId(), offset, limit).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
|
| 31572 |
tejbeer |
785 |
|
| 32339 |
tejbeer |
786 |
if (webProducts.size() == 0) {
|
|
|
787 |
return new ArrayList<>();
|
|
|
788 |
}
|
| 31572 |
tejbeer |
789 |
|
| 32339 |
tejbeer |
790 |
mandatoryQ.add(String.format(
|
| 33575 |
amit.gupta |
791 |
"+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} AND active_b:true AND show_default_b:true"));
|
| 31642 |
tejbeer |
792 |
|
| 32339 |
tejbeer |
793 |
}
|
|
|
794 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
795 |
params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
|
| 31612 |
tejbeer |
796 |
|
| 32339 |
tejbeer |
797 |
params.put("start", String.valueOf(offset));
|
|
|
798 |
params.put("rows", String.valueOf(limit));
|
|
|
799 |
params.put("wt", "json");
|
|
|
800 |
String response = null;
|
|
|
801 |
try {
|
| 35410 |
amit |
802 |
response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32339 |
tejbeer |
803 |
} catch (HttpHostConnectException e) {
|
|
|
804 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
805 |
}
|
|
|
806 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
807 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
808 |
List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
| 31671 |
tejbeer |
809 |
|
| 32339 |
tejbeer |
810 |
if (webProducts != null && webListing.getUrl().equals("new-launches")) {
|
|
|
811 |
List<Integer> webProductsFinal = webProducts;
|
|
|
812 |
dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
|
| 31671 |
tejbeer |
813 |
|
| 32339 |
tejbeer |
814 |
}
|
| 31547 |
tejbeer |
815 |
|
| 32339 |
tejbeer |
816 |
return dealResponse;
|
|
|
817 |
}
|
| 30669 |
amit.gupta |
818 |
|
| 32339 |
tejbeer |
819 |
@Autowired
|
|
|
820 |
private SaholicCISTableRepository saholicCISTableRepository;
|
| 27053 |
amit.gupta |
821 |
|
| 33575 |
amit.gupta |
822 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws
|
|
|
823 |
Exception {
|
| 32339 |
tejbeer |
824 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
825 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
826 |
List<Integer> itemIds = new ArrayList<>();
|
| 34260 |
vikas.jang |
827 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
| 32339 |
tejbeer |
828 |
if (docs.length() > 0) {
|
|
|
829 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
830 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
831 |
if (doc.has("_childDocuments_")) {
|
|
|
832 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
833 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
834 |
int itemId = childItem.getInt("itemId_i");
|
|
|
835 |
itemIds.add(itemId);
|
|
|
836 |
}
|
|
|
837 |
}
|
|
|
838 |
}
|
|
|
839 |
if (itemIds.size() == 0) {
|
|
|
840 |
return dealResponse;
|
|
|
841 |
}
|
|
|
842 |
}
|
|
|
843 |
// get warehouse Id
|
|
|
844 |
int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
|
|
|
845 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
|
|
|
846 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
847 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
848 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
849 |
catalogIds.add(doc.getInt("catalogId_i"));
|
|
|
850 |
}
|
|
|
851 |
List<CreateOfferRequest> allSchemOffers = null;
|
|
|
852 |
Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
|
|
|
853 |
if (catalogIds.size() > 0) {
|
|
|
854 |
PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
|
|
|
855 |
allSchemOffers = priceCircularModel.getOffers();
|
| 30188 |
amit.gupta |
856 |
|
| 32339 |
tejbeer |
857 |
List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
|
|
|
858 |
if (priceCircularItemModelNews != null) {
|
|
|
859 |
priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
|
|
860 |
}
|
|
|
861 |
}
|
| 31629 |
tejbeer |
862 |
|
| 33575 |
amit.gupta |
863 |
/*List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
|
| 32339 |
tejbeer |
864 |
List<Integer> catalogFavouriteIds = new ArrayList<>();
|
|
|
865 |
if (!catalogFavourites.isEmpty()) {
|
|
|
866 |
catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
|
|
867 |
}
|
| 31629 |
tejbeer |
868 |
|
| 32339 |
tejbeer |
869 |
if (!catalogFavourites.isEmpty()) {
|
|
|
870 |
catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
| 33575 |
amit.gupta |
871 |
}*/
|
| 30595 |
tejbeer |
872 |
|
| 34260 |
vikas.jang |
873 |
if (fofoId > 0) {
|
|
|
874 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
875 |
logger.info("partnerStockAvailabilityMap: {}",partnerStockAvailabilityMap);
|
|
|
876 |
}
|
| 34786 |
aman.kumar |
877 |
List<CatalogFavourite> catalogFavouriteList = catalogFavouriteRepository.selectBypartnerId(fofoId);
|
|
|
878 |
Set<Integer> favouriteCatalogIds = catalogFavouriteList.stream()
|
|
|
879 |
.map(CatalogFavourite::getCatalogId)
|
|
|
880 |
.collect(Collectors.toSet());
|
| 35410 |
amit |
881 |
|
|
|
882 |
// Pre-fetch CIS data for all items (batch query instead of N+1)
|
|
|
883 |
Map<Integer, List<SaholicCISTable>> cisDataByItemId = saholicCISTableRepository
|
|
|
884 |
.selectByItemWarehouse(itemIds, warehouseId).stream()
|
|
|
885 |
.collect(Collectors.groupingBy(SaholicCISTable::getItemId));
|
|
|
886 |
|
|
|
887 |
// Pre-fetch all Items (batch query instead of N+1)
|
|
|
888 |
Map<Integer, Item> itemMap = itemRepository.selectByIds(new HashSet<>(itemIds)).stream()
|
|
|
889 |
.collect(Collectors.toMap(Item::getId, x -> x));
|
|
|
890 |
|
|
|
891 |
// Pre-fetch cashback data for all catalogs (batch query instead of N+1)
|
|
|
892 |
Map<Integer, Float> cashbackMap = schemeService.getCatalogSchemeCashBack(fofoId, catalogIds);
|
|
|
893 |
|
|
|
894 |
// Pre-fetch web offers (call once instead of inside loop)
|
|
|
895 |
Map<Integer, List<WebOffer>> webOffersMap = webOfferRepository.selectAllActiveOffers();
|
|
|
896 |
|
|
|
897 |
// Pre-fetch combo models (call once instead of inside loop)
|
|
|
898 |
Map<Integer, List<ComboModel>> comboModelsByCatalogId = comboModelRepository.selectByWarehouseId(warehouseId)
|
|
|
899 |
.stream().collect(Collectors.groupingBy(ComboModel::getCatalogId));
|
|
|
900 |
|
| 32339 |
tejbeer |
901 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
902 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
903 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
904 |
FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
|
|
|
905 |
fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
906 |
fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
907 |
fofoCatalogResponse.setTitle(doc.getString("title_s"));
|
| 33975 |
tejus.loha |
908 |
fofoCatalogResponse.setSuperCatalogTitle(doc.getString("superCatalog_s"));
|
|
|
909 |
fofoCatalogResponse.setSuperCatalogId(doc.getInt("superCatalog_i"));
|
|
|
910 |
fofoCatalogResponse.setSuperCatalogVariants(doc.getString("superCatalogVariants_s"));
|
| 31629 |
tejbeer |
911 |
|
| 34786 |
aman.kumar |
912 |
if (favouriteCatalogIds.contains(fofoCatalogResponse.getCatalogId())) {
|
| 32339 |
tejbeer |
913 |
fofoCatalogResponse.setFavourite(true);
|
| 34786 |
aman.kumar |
914 |
} else {
|
|
|
915 |
fofoCatalogResponse.setFavourite(false); // optional, since default is false
|
|
|
916 |
}
|
| 35410 |
amit |
917 |
List<WebOffer> webOffers = webOffersMap.get(fofoCatalogResponse.getCatalogId());
|
| 31612 |
tejbeer |
918 |
|
| 33573 |
amit.gupta |
919 |
//logger.info("webOffers {}", webOffers);
|
| 32339 |
tejbeer |
920 |
if (webOffers != null && webOffers.size() > 0) {
|
|
|
921 |
fofoCatalogResponse.setWebOffers(webOffers);
|
|
|
922 |
fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
| 30683 |
tejbeer |
923 |
|
| 32339 |
tejbeer |
924 |
}
|
| 30683 |
tejbeer |
925 |
|
| 35410 |
amit |
926 |
List<ComboModel> comboModels = comboModelsByCatalogId.get(fofoCatalogResponse.getCatalogId());
|
| 30683 |
tejbeer |
927 |
|
| 33573 |
amit.gupta |
928 |
//logger.info("comboModels {}", comboModels);
|
| 32344 |
tejbeer |
929 |
|
| 32339 |
tejbeer |
930 |
if (comboModels != null && comboModels.size() > 0) {
|
|
|
931 |
fofoCatalogResponse.setComboModels(comboModels);
|
|
|
932 |
}
|
| 30683 |
tejbeer |
933 |
|
| 32339 |
tejbeer |
934 |
try {
|
|
|
935 |
fofoCatalogResponse.setFeature(doc.getString("feature_s"));
|
|
|
936 |
} catch (Exception e) {
|
|
|
937 |
fofoCatalogResponse.setFeature(null);
|
|
|
938 |
logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
|
|
|
939 |
}
|
| 30683 |
tejbeer |
940 |
|
| 32339 |
tejbeer |
941 |
fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
942 |
logger.info("labelss {}", doc.has("label_ss"));
|
| 30683 |
tejbeer |
943 |
|
| 32339 |
tejbeer |
944 |
if (doc.has("label_ss")) {
|
|
|
945 |
logger.info("label {}", doc.getJSONArray("label_ss"));
|
| 30683 |
tejbeer |
946 |
|
| 32339 |
tejbeer |
947 |
JSONArray arr = doc.getJSONArray("label_ss");
|
|
|
948 |
Set<String> labels = new HashSet<String>();
|
|
|
949 |
for (int j = 0; j < arr.length(); j++) {
|
|
|
950 |
labels.add(arr.getString(j));
|
|
|
951 |
}
|
| 31612 |
tejbeer |
952 |
|
| 32339 |
tejbeer |
953 |
fofoCatalogResponse.setLabels(new ArrayList<>(labels));
|
| 31612 |
tejbeer |
954 |
|
| 32339 |
tejbeer |
955 |
}
|
| 33573 |
amit.gupta |
956 |
if (doc.has("similarModels_ii")) {
|
|
|
957 |
JSONArray similarModelsArray = doc.getJSONArray("similarModels_ii");
|
|
|
958 |
List<Integer> similarCatalogIds = new ArrayList<>();
|
|
|
959 |
for (int j = 0; j < similarModelsArray.length(); j++) {
|
|
|
960 |
similarCatalogIds.add(similarModelsArray.getInt(j));
|
|
|
961 |
}
|
|
|
962 |
fofoCatalogResponse.setSimilarModelIds(similarCatalogIds);
|
|
|
963 |
}
|
| 31612 |
tejbeer |
964 |
|
| 32339 |
tejbeer |
965 |
if (doc.has("_childDocuments_")) {
|
|
|
966 |
String modelColorClass = "grey";
|
|
|
967 |
FofoAvailabilityInfo fdiAnyColour = null;
|
|
|
968 |
// Iterating itemIds
|
|
|
969 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
970 |
PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
|
|
|
971 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
972 |
int itemId = childItem.getInt("itemId_i");
|
|
|
973 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| 34260 |
vikas.jang |
974 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
| 32339 |
tejbeer |
975 |
if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
976 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 35410 |
amit |
977 |
List<SaholicCISTable> currentAvailability = cisDataByItemId.getOrDefault(itemId, new ArrayList<>());
|
| 32339 |
tejbeer |
978 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
979 |
if (poItemAvailabilityMap != null) {
|
|
|
980 |
poItemAvailability = poItemAvailabilityMap.get(itemId);
|
|
|
981 |
}
|
| 31612 |
tejbeer |
982 |
|
| 32339 |
tejbeer |
983 |
if (priceCircularItemModel != null) {
|
| 33410 |
ranu |
984 |
fdi.setNlc((float) priceCircularItemModel.getNetNlc());
|
| 32339 |
tejbeer |
985 |
}
|
| 31612 |
tejbeer |
986 |
|
| 32339 |
tejbeer |
987 |
for (SaholicCISTable saholicCISTable : currentAvailability) {
|
|
|
988 |
saholicCISTable.setWarehouseName(
|
|
|
989 |
ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
|
|
|
990 |
}
|
| 31612 |
tejbeer |
991 |
|
| 32339 |
tejbeer |
992 |
Map<Integer, SaholicCISTable> map = currentAvailability.stream().collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
|
|
|
993 |
if (poItemAvailability != null) {
|
|
|
994 |
for (SaholicPOItem saholicPOItem : poItemAvailability) {
|
|
|
995 |
if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
|
|
|
996 |
map.get(saholicPOItem.getWarehouseFrom()).setPopendingQty(saholicPOItem.getUnfulfilledQty());
|
|
|
997 |
} else {
|
|
|
998 |
SaholicCISTable saholicCISTable = new SaholicCISTable();
|
|
|
999 |
saholicCISTable.setAvailability(0);
|
|
|
1000 |
saholicCISTable.setReserved(0);
|
|
|
1001 |
saholicCISTable.setItemId(itemId);
|
|
|
1002 |
saholicCISTable.setWarehouseId(warehouseId);
|
|
|
1003 |
saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
|
|
|
1004 |
saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
|
|
|
1005 |
saholicCISTable.setWarehouseName(
|
|
|
1006 |
ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
|
|
|
1007 |
map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
|
|
|
1008 |
}
|
|
|
1009 |
}
|
|
|
1010 |
}
|
|
|
1011 |
fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
|
|
|
1012 |
String poColor = "grey";
|
|
|
1013 |
boolean active = false;
|
|
|
1014 |
if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
|
|
|
1015 |
poColor = "green";
|
|
|
1016 |
modelColorClass = "green";
|
| 32978 |
amit.gupta |
1017 |
} else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
|
|
|
1018 |
if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
|
|
|
1019 |
poColor = "grey";
|
|
|
1020 |
} else {
|
|
|
1021 |
poColor = "yellow";
|
| 35410 |
amit |
1022 |
if (!"green".equals(modelColorClass)) {
|
| 32978 |
amit.gupta |
1023 |
modelColorClass = poColor;
|
| 32339 |
tejbeer |
1024 |
}
|
|
|
1025 |
}
|
| 32978 |
amit.gupta |
1026 |
}
|
| 32339 |
tejbeer |
1027 |
fdi.setColorClass(poColor);
|
|
|
1028 |
fdi.setSellingPrice(sellingPrice);
|
|
|
1029 |
fdi.setActive(active);
|
|
|
1030 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
|
|
1031 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
1032 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
1033 |
if (fdi.getColor().equalsIgnoreCase("any colour")) {
|
|
|
1034 |
fdiAnyColour = fdi;
|
|
|
1035 |
}
|
| 33929 |
tejus.loha |
1036 |
fdi.setBrand((String) doc.getJSONArray("brand_ss").get(0));
|
|
|
1037 |
fdi.setCategoryId(doc.getInt("subCategoryId_i"));
|
| 32339 |
tejbeer |
1038 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
1039 |
fdi.setItem_id(itemId);
|
| 34196 |
ranu |
1040 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 35410 |
amit |
1041 |
Float cashBack = cashbackMap.get(fofoCatalogResponse.getCatalogId());
|
| 32339 |
tejbeer |
1042 |
cashBack = cashBack == null ? 0 : cashBack;
|
|
|
1043 |
fdi.setCashback(cashBack);
|
|
|
1044 |
fdi.setMinBuyQuantity(1);
|
|
|
1045 |
if (hotDeal) {
|
|
|
1046 |
if (currentAvailability != null) {
|
|
|
1047 |
fdi.setAvailability(currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
|
|
|
1048 |
} else {
|
|
|
1049 |
fdi.setAvailability(0);
|
|
|
1050 |
}
|
| 34260 |
vikas.jang |
1051 |
fdi.setPartnerAvailability(partnerAvailability);
|
| 32339 |
tejbeer |
1052 |
} else {
|
|
|
1053 |
// Lets consider that its out of stock
|
| 32591 |
amit.gupta |
1054 |
fdi.setAvailability(400);
|
| 35410 |
amit |
1055 |
Item item = itemMap.get(itemId);
|
| 32339 |
tejbeer |
1056 |
// In case its tampered glass moq should be
|
| 35410 |
amit |
1057 |
if (item != null && item.getCategoryId() == 10020) {
|
| 32339 |
tejbeer |
1058 |
fdi.setMinBuyQuantity(5);
|
|
|
1059 |
}
|
|
|
1060 |
}
|
|
|
1061 |
fdi.setQuantityStep(1);
|
| 32590 |
amit.gupta |
1062 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 400));
|
| 32339 |
tejbeer |
1063 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
1064 |
}
|
|
|
1065 |
}
|
|
|
1066 |
if (fdiAnyColour != null) {
|
|
|
1067 |
fdiAnyColour.setColorClass(modelColorClass);
|
|
|
1068 |
}
|
| 33576 |
amit.gupta |
1069 |
fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
|
| 32339 |
tejbeer |
1070 |
}
|
|
|
1071 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
1072 |
List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
|
|
|
1073 |
fofoCatalogResponse.setItems(availabilityList);
|
|
|
1074 |
if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
|
|
|
1075 |
PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
|
|
|
1076 |
if (priceCircularItemModel.getSlabPayouts() != null) {
|
|
|
1077 |
List<CreateOfferRequest> schemeOffers = new ArrayList<>();
|
|
|
1078 |
List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
|
|
|
1079 |
Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
|
|
|
1080 |
int iteratorCount = 0;
|
|
|
1081 |
while (iterator.hasNext()) {
|
|
|
1082 |
Map<Integer, AmountModel> slabPayoutMap = iterator.next();
|
|
|
1083 |
if (slabPayoutMap != null) {
|
|
|
1084 |
schemeOffers.add(allSchemOffers.get(iteratorCount));
|
|
|
1085 |
} else {
|
|
|
1086 |
iterator.remove();
|
|
|
1087 |
}
|
|
|
1088 |
iteratorCount++;
|
|
|
1089 |
}
|
|
|
1090 |
fofoCatalogResponse.setSchemeOffers(schemeOffers);
|
|
|
1091 |
}
|
|
|
1092 |
fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
|
|
|
1093 |
}
|
|
|
1094 |
dealResponse.add(fofoCatalogResponse);
|
|
|
1095 |
}
|
|
|
1096 |
}
|
|
|
1097 |
return dealResponse;
|
| 30686 |
amit.gupta |
1098 |
|
| 32339 |
tejbeer |
1099 |
}
|
| 30693 |
amit.gupta |
1100 |
|
| 33575 |
amit.gupta |
1101 |
private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray
|
|
|
1102 |
docs, Map<Integer, Integer> itemFilter, boolean hotDeal) throws ProfitMandiBusinessException {
|
| 32339 |
tejbeer |
1103 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
1104 |
List<Integer> tagIds = Arrays.asList(4);
|
| 24091 |
tejbeer |
1105 |
|
| 33873 |
ranu |
1106 |
Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 24091 |
tejbeer |
1107 |
|
| 35410 |
amit |
1108 |
// Pre-fetch all items (batch query instead of N+1)
|
|
|
1109 |
Map<Integer, Item> itemMap = itemRepository.selectByIds(itemFilter.keySet()).stream()
|
|
|
1110 |
.collect(Collectors.toMap(Item::getId, x -> x));
|
|
|
1111 |
|
| 32339 |
tejbeer |
1112 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
1113 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
1114 |
JSONObject doc = docs.getJSONObject(i);
|
| 26589 |
amit.gupta |
1115 |
|
| 32339 |
tejbeer |
1116 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
1117 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
1118 |
int itemId = childItem.getInt("itemId_i");
|
|
|
1119 |
TagListing tl = itemTagListingMap.get(itemId);
|
|
|
1120 |
if (tl == null) {
|
|
|
1121 |
continue;
|
|
|
1122 |
}
|
|
|
1123 |
if (hotDeal) {
|
|
|
1124 |
if (!tl.isHotDeals()) {
|
|
|
1125 |
continue;
|
|
|
1126 |
}
|
|
|
1127 |
}
|
|
|
1128 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
1129 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
1130 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
1131 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
1132 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
1133 |
}
|
|
|
1134 |
} else {
|
|
|
1135 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
|
|
1136 |
fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
|
|
|
1137 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
1138 |
fdi.setMop((float) tl.getMrp());
|
|
|
1139 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
1140 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
1141 |
fdi.setItem_id(itemId);
|
| 34196 |
ranu |
1142 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 35410 |
amit |
1143 |
Item item = itemMap.get(itemId);
|
| 32339 |
tejbeer |
1144 |
// In case its tampered glass moq should be 5
|
| 35410 |
amit |
1145 |
if (item != null && item.getCategoryId() == 10020) {
|
| 32339 |
tejbeer |
1146 |
fdi.setMinBuyQuantity(10);
|
|
|
1147 |
} else {
|
|
|
1148 |
fdi.setMinBuyQuantity(1);
|
|
|
1149 |
}
|
|
|
1150 |
fdi.setAvailability(itemFilter.get(itemId));
|
|
|
1151 |
fdi.setQuantityStep(1);
|
|
|
1152 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
|
|
1153 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
1154 |
}
|
|
|
1155 |
}
|
|
|
1156 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
1157 |
for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
|
|
|
1158 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
1159 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
1160 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
1161 |
ffdr.setTitle(doc.getString("title_s"));
|
|
|
1162 |
try {
|
|
|
1163 |
ffdr.setFeature(doc.getString("feature_s"));
|
|
|
1164 |
} catch (Exception e) {
|
|
|
1165 |
ffdr.setFeature(null);
|
|
|
1166 |
logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
|
|
|
1167 |
}
|
|
|
1168 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
1169 |
ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
|
|
|
1170 |
dealResponse.add(ffdr);
|
|
|
1171 |
}
|
|
|
1172 |
}
|
|
|
1173 |
}
|
|
|
1174 |
return dealResponse;
|
| 25880 |
amit.gupta |
1175 |
|
| 32339 |
tejbeer |
1176 |
}
|
| 25880 |
amit.gupta |
1177 |
|
| 32339 |
tejbeer |
1178 |
@RequestMapping(value = "/combo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1179 |
public ResponseEntity<?> getBanners(@RequestParam int catalogId, @RequestParam int warehouseId) {
|
|
|
1180 |
List<ComboModel> comboModels = comboModelRepository.selectByCatalogIdAndWarehouseId(catalogId, warehouseId);
|
|
|
1181 |
return responseSender.ok(comboModels);
|
|
|
1182 |
}
|
| 32344 |
tejbeer |
1183 |
|
|
|
1184 |
@RequestMapping(value = "/checkCombo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 33575 |
amit.gupta |
1185 |
public ResponseEntity<?> checkCombo(HttpServletRequest request, @RequestParam int catalogId,
|
|
|
1186 |
@RequestParam int warehouseId, @RequestParam int qty) throws Exception {
|
| 32344 |
tejbeer |
1187 |
boolean isCombo = false;
|
|
|
1188 |
ComboModel comboModel = comboModelRepository.selectByCatalogIdWarehouseIdAndQty(catalogId, warehouseId, qty);
|
|
|
1189 |
if (comboModel != null) {
|
|
|
1190 |
isCombo = true;
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
return responseSender.ok(isCombo);
|
|
|
1194 |
}
|
|
|
1195 |
|
| 33929 |
tejus.loha |
1196 |
@GetMapping(value = "/partner/wodCompleteBrands", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1197 |
public ResponseEntity<?> getWodcompletBrands(HttpServletRequest request) throws Exception {
|
|
|
1198 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 34630 |
tejus.loha |
1199 |
BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = brandsService.wodcompletBrands(userInfo.getRetailerId());
|
|
|
1200 |
return responseSender.ok(brandAndAddToCartEligibleModel);
|
| 33929 |
tejus.loha |
1201 |
|
|
|
1202 |
}
|
|
|
1203 |
|
| 25967 |
amit.gupta |
1204 |
}
|