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