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