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