| 26607 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 27028 |
tejbeer |
3 |
import java.io.StringWriter;
|
| 27025 |
tejbeer |
4 |
import java.time.LocalDateTime;
|
| 26628 |
amit.gupta |
5 |
import java.time.LocalTime;
|
| 27069 |
tejbeer |
6 |
import java.time.format.DateTimeFormatter;
|
| 26607 |
amit.gupta |
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.Arrays;
|
|
|
9 |
import java.util.HashMap;
|
|
|
10 |
import java.util.HashSet;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
| 26745 |
amit.gupta |
13 |
import java.util.Optional;
|
| 26607 |
amit.gupta |
14 |
import java.util.Set;
|
|
|
15 |
import java.util.stream.Collectors;
|
|
|
16 |
|
| 27028 |
tejbeer |
17 |
import javax.mail.internet.InternetAddress;
|
|
|
18 |
import javax.mail.internet.MimeMessage;
|
| 26607 |
amit.gupta |
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
|
|
|
21 |
import org.apache.commons.lang3.StringUtils;
|
|
|
22 |
import org.apache.http.conn.HttpHostConnectException;
|
|
|
23 |
import org.apache.logging.log4j.LogManager;
|
|
|
24 |
import org.apache.logging.log4j.Logger;
|
| 27028 |
tejbeer |
25 |
import org.apache.velocity.Template;
|
|
|
26 |
import org.apache.velocity.VelocityContext;
|
|
|
27 |
import org.apache.velocity.app.VelocityEngine;
|
| 26607 |
amit.gupta |
28 |
import org.json.JSONArray;
|
|
|
29 |
import org.json.JSONObject;
|
|
|
30 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
31 |
import org.springframework.beans.factory.annotation.Value;
|
| 26745 |
amit.gupta |
32 |
import org.springframework.cache.annotation.Cacheable;
|
| 26607 |
amit.gupta |
33 |
import org.springframework.http.MediaType;
|
|
|
34 |
import org.springframework.http.ResponseEntity;
|
| 27028 |
tejbeer |
35 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
36 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 26607 |
amit.gupta |
37 |
import org.springframework.stereotype.Controller;
|
|
|
38 |
import org.springframework.transaction.annotation.Transactional;
|
| 26923 |
amit.gupta |
39 |
import org.springframework.web.bind.annotation.GetMapping;
|
| 26662 |
amit.gupta |
40 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 26607 |
amit.gupta |
41 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
42 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
43 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
44 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
45 |
|
|
|
46 |
import com.eclipsesource.json.JsonObject;
|
| 26774 |
amit.gupta |
47 |
import com.fasterxml.jackson.annotation.JsonProperty;
|
| 26607 |
amit.gupta |
48 |
import com.google.gson.Gson;
|
|
|
49 |
import com.google.gson.reflect.TypeToken;
|
|
|
50 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
51 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 26923 |
amit.gupta |
52 |
import com.spice.profitmandi.common.model.CreatePendingOrderItem;
|
| 26648 |
amit.gupta |
53 |
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
|
| 26651 |
amit.gupta |
54 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 26607 |
amit.gupta |
55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
56 |
import com.spice.profitmandi.common.model.UserInfo;
|
|
|
57 |
import com.spice.profitmandi.common.solr.SolrService;
|
|
|
58 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
59 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
60 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
61 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 26745 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
| 26774 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
| 26857 |
amit.gupta |
64 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 28267 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 26855 |
tejbeer |
66 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
|
|
|
67 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
| 26715 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
|
| 26630 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
| 27045 |
tejbeer |
70 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 26607 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.model.AddCartRequest;
|
|
|
72 |
import com.spice.profitmandi.dao.model.CartItem;
|
|
|
73 |
import com.spice.profitmandi.dao.model.CartItemResponseModel;
|
|
|
74 |
import com.spice.profitmandi.dao.model.CartResponse;
|
| 27045 |
tejbeer |
75 |
import com.spice.profitmandi.dao.model.CustomerOrderDetail;
|
| 26607 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
77 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 28290 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 26718 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 27030 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 26745 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
|
|
82 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
| 26607 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 26788 |
amit.gupta |
84 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 26774 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 26855 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
|
|
87 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
|
| 26648 |
amit.gupta |
88 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
| 26715 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
|
| 26607 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 26784 |
amit.gupta |
91 |
import com.spice.profitmandi.service.CustomerService;
|
| 26607 |
amit.gupta |
92 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 26923 |
amit.gupta |
93 |
import com.spice.profitmandi.service.inventory.AvailabilityModel;
|
| 26607 |
amit.gupta |
94 |
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
|
|
|
95 |
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
|
| 26923 |
amit.gupta |
96 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 26909 |
amit.gupta |
97 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 26683 |
amit.gupta |
98 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26651 |
amit.gupta |
99 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 26630 |
amit.gupta |
100 |
import com.spice.profitmandi.web.processor.OtpProcessor;
|
| 26607 |
amit.gupta |
101 |
import com.spice.profitmandi.web.res.DealBrands;
|
|
|
102 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
103 |
import com.spice.profitmandi.web.res.DealsResponse;
|
|
|
104 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
|
|
105 |
|
|
|
106 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
107 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
108 |
import io.swagger.annotations.ApiOperation;
|
|
|
109 |
|
|
|
110 |
@Controller
|
|
|
111 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
112 |
public class StoreController {
|
|
|
113 |
|
|
|
114 |
private static final Logger logger = LogManager.getLogger(StoreController.class);
|
| 26630 |
amit.gupta |
115 |
|
| 26628 |
amit.gupta |
116 |
private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
|
| 26745 |
amit.gupta |
117 |
|
|
|
118 |
private static final List<Integer> TAG_IDS = Arrays.asList(4);
|
|
|
119 |
|
| 26717 |
amit.gupta |
120 |
private static final int DEFAULT_STORE = 171912487;
|
| 26833 |
amit.gupta |
121 |
|
| 26788 |
amit.gupta |
122 |
@Autowired
|
|
|
123 |
CustomerAddressRepository customerAddressRepository;
|
| 26607 |
amit.gupta |
124 |
|
| 26923 |
amit.gupta |
125 |
@Autowired
|
| 27030 |
amit.gupta |
126 |
SolrService solrService;
|
| 27045 |
tejbeer |
127 |
|
| 27030 |
amit.gupta |
128 |
@Autowired
|
| 26923 |
amit.gupta |
129 |
InventoryService inventoryService;
|
| 27045 |
tejbeer |
130 |
|
| 27030 |
amit.gupta |
131 |
@Autowired
|
|
|
132 |
UserAccountRepository userAccountRepository;
|
| 26923 |
amit.gupta |
133 |
|
| 26607 |
amit.gupta |
134 |
@Value("${python.api.host}")
|
|
|
135 |
private String host;
|
| 26833 |
amit.gupta |
136 |
|
| 26784 |
amit.gupta |
137 |
@Autowired
|
|
|
138 |
CustomerService customerService;
|
| 26607 |
amit.gupta |
139 |
|
|
|
140 |
@Value("${python.api.port}")
|
|
|
141 |
private int port;
|
| 26923 |
amit.gupta |
142 |
|
| 26909 |
amit.gupta |
143 |
@Autowired
|
|
|
144 |
private SaholicInventoryService saholicInventoryService;
|
| 26607 |
amit.gupta |
145 |
|
|
|
146 |
// This is now unused as we are not supporting multiple companies.
|
|
|
147 |
@Value("${gadgetCops.invoice.cc}")
|
|
|
148 |
private String[] ccGadgetCopInvoiceTo;
|
|
|
149 |
|
|
|
150 |
@Autowired
|
| 26715 |
amit.gupta |
151 |
private PincodePartnerRepository pincodePartnerRepository;
|
|
|
152 |
|
|
|
153 |
@Autowired
|
| 26718 |
amit.gupta |
154 |
private FofoStoreRepository fofoStoreRepository;
|
| 26745 |
amit.gupta |
155 |
|
| 26718 |
amit.gupta |
156 |
@Autowired
|
| 26651 |
amit.gupta |
157 |
private RetailerService retailerService;
|
| 26861 |
tejbeer |
158 |
|
| 26857 |
amit.gupta |
159 |
@Autowired
|
|
|
160 |
private PendingOrderRepository pendingOrderRepository;
|
| 26861 |
tejbeer |
161 |
|
| 26857 |
amit.gupta |
162 |
@Autowired
|
|
|
163 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
| 26652 |
amit.gupta |
164 |
|
| 26651 |
amit.gupta |
165 |
@Autowired
|
| 26652 |
amit.gupta |
166 |
private PendingOrderService pendingOrderService;
|
| 26648 |
amit.gupta |
167 |
|
|
|
168 |
@Autowired
|
| 26774 |
amit.gupta |
169 |
private CustomerRepository customerRepository;
|
|
|
170 |
|
|
|
171 |
@Autowired
|
| 26607 |
amit.gupta |
172 |
private SolrService commonSolrService;
|
|
|
173 |
|
|
|
174 |
@Autowired
|
| 26630 |
amit.gupta |
175 |
private OtpProcessor otpProcessor;
|
|
|
176 |
|
|
|
177 |
@Autowired
|
| 26607 |
amit.gupta |
178 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
179 |
|
| 26609 |
amit.gupta |
180 |
@Autowired
|
| 26607 |
amit.gupta |
181 |
private ResponseSender<?> responseSender;
|
|
|
182 |
|
|
|
183 |
@Autowired
|
|
|
184 |
private TagListingRepository tagListingRepository;
|
|
|
185 |
|
|
|
186 |
@Autowired
|
|
|
187 |
private ItemRepository itemRepository;
|
| 26701 |
amit.gupta |
188 |
|
| 26683 |
amit.gupta |
189 |
@Autowired
|
|
|
190 |
private SchemeService schemeService;
|
| 26607 |
amit.gupta |
191 |
|
|
|
192 |
@Autowired
|
|
|
193 |
private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
|
|
|
194 |
|
|
|
195 |
@Autowired
|
| 26745 |
amit.gupta |
196 |
private WebListingRepository webListingRepository;
|
|
|
197 |
|
|
|
198 |
@Autowired
|
|
|
199 |
private WebProductListingRepository webProductListingRepository;
|
|
|
200 |
|
|
|
201 |
@Autowired
|
| 26607 |
amit.gupta |
202 |
private RoleManager roleManagerService;
|
|
|
203 |
|
| 27028 |
tejbeer |
204 |
@Autowired
|
|
|
205 |
private VelocityEngine velocityEngine;
|
|
|
206 |
|
|
|
207 |
@Autowired
|
|
|
208 |
JavaMailSender mailSender;
|
|
|
209 |
|
| 28290 |
tejbeer |
210 |
@Autowired
|
|
|
211 |
CsService csService;
|
| 26607 |
amit.gupta |
212 |
List<String> filterableParams = Arrays.asList("brand");
|
|
|
213 |
|
| 26668 |
amit.gupta |
214 |
@RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
215 |
@ApiImplicitParams({
|
|
|
216 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
217 |
@ApiOperation(value = "Get unit deal object")
|
|
|
218 |
public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
|
|
219 |
throws ProfitMandiBusinessException {
|
|
|
220 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
221 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
222 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
223 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
|
|
224 |
String categoryId = "(3 OR 6)";
|
| 26745 |
amit.gupta |
225 |
|
| 26668 |
amit.gupta |
226 |
RestClient rc = new RestClient();
|
|
|
227 |
Map<String, String> params = new HashMap<>();
|
|
|
228 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
229 |
String catalogString = "catalog" + id;
|
| 26607 |
amit.gupta |
230 |
|
| 26668 |
amit.gupta |
231 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
|
|
|
232 |
categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
|
|
233 |
|
|
|
234 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
235 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
236 |
params.put("sort", "rank_i asc, create_s desc");
|
|
|
237 |
params.put("wt", "json");
|
|
|
238 |
String response = null;
|
|
|
239 |
try {
|
|
|
240 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
|
|
241 |
} catch (HttpHostConnectException e) {
|
|
|
242 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
243 |
}
|
|
|
244 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
245 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 26909 |
amit.gupta |
246 |
dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
| 26668 |
amit.gupta |
247 |
} else {
|
|
|
248 |
return responseSender.badRequest(
|
|
|
249 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
250 |
}
|
|
|
251 |
return responseSender.ok(dealResponse.get(0));
|
|
|
252 |
}
|
|
|
253 |
|
| 26607 |
amit.gupta |
254 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
255 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
|
|
256 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
257 |
}
|
|
|
258 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
@RequestMapping(value = "/store/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
262 |
@ApiImplicitParams({
|
|
|
263 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
264 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
265 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
|
|
266 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
|
|
|
267 |
logger.info("Request " + request.getParameterMap());
|
|
|
268 |
String response = null;
|
|
|
269 |
// TODO: move to properties
|
|
|
270 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
|
|
271 |
RestClient rc = new RestClient();
|
|
|
272 |
Map<String, String> params = new HashMap<>();
|
|
|
273 |
params.put("category_id", category_id);
|
|
|
274 |
List<DealBrands> dealBrandsResponse = null;
|
|
|
275 |
try {
|
|
|
276 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
277 |
} catch (HttpHostConnectException e) {
|
|
|
278 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
282 |
}.getType());
|
|
|
283 |
|
|
|
284 |
return responseSender.ok(dealBrandsResponse);
|
|
|
285 |
}
|
|
|
286 |
|
| 26745 |
amit.gupta |
287 |
@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
288 |
public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
|
| 26909 |
amit.gupta |
289 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 28287 |
amit.gupta |
290 |
WebListing webListing = webListingRepository.selectByUrl(listingUrl);
|
|
|
291 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
| 26745 |
amit.gupta |
292 |
return responseSender.ok(webListing);
|
| 26654 |
amit.gupta |
293 |
}
|
|
|
294 |
|
| 26632 |
amit.gupta |
295 |
@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26783 |
amit.gupta |
296 |
public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String mobile) throws Exception {
|
| 26630 |
amit.gupta |
297 |
|
| 26857 |
amit.gupta |
298 |
return responseSender.ok(otpProcessor.generateOtp(mobile, OtpType.REGISTRATION));
|
| 26630 |
amit.gupta |
299 |
|
|
|
300 |
}
|
| 26652 |
amit.gupta |
301 |
|
| 26784 |
amit.gupta |
302 |
@RequestMapping(value = "/store/checkmobile/{mobile}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26833 |
amit.gupta |
303 |
public ResponseEntity<?> checkRegistrationUsingMobile(HttpServletRequest request, @PathVariable String mobile)
|
|
|
304 |
throws Exception {
|
| 26774 |
amit.gupta |
305 |
try {
|
|
|
306 |
Customer customer = customerRepository.selectByMobileNumber(mobile);
|
| 26777 |
amit.gupta |
307 |
customer.setPasswordExist(StringUtils.isNotEmpty(customer.getPassword()));
|
| 26774 |
amit.gupta |
308 |
return responseSender.ok(new CustomerModel(true, customer));
|
|
|
309 |
} catch (Exception e) {
|
|
|
310 |
return responseSender.ok(new CustomerModel(false, null));
|
|
|
311 |
}
|
|
|
312 |
}
|
| 26833 |
amit.gupta |
313 |
|
| 26784 |
amit.gupta |
314 |
@RequestMapping(value = "/store/signin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
315 |
public ResponseEntity<?> signIn(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
| 26833 |
amit.gupta |
316 |
if (customerService.authenticate(userModel.getMobile(), userModel.getPassword())) {
|
| 26784 |
amit.gupta |
317 |
return responseSender.ok(true);
|
|
|
318 |
} else {
|
|
|
319 |
return responseSender.ok(false);
|
|
|
320 |
}
|
|
|
321 |
}
|
| 26923 |
amit.gupta |
322 |
|
| 26841 |
amit.gupta |
323 |
@RequestMapping(value = "/store/resetPassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26923 |
amit.gupta |
324 |
public ResponseEntity<?> resetPassword(HttpServletRequest request, @RequestBody UserModel userModel)
|
|
|
325 |
throws Exception {
|
| 26843 |
amit.gupta |
326 |
customerService.changePassword(userModel.getMobile(), userModel.getPassword());
|
| 26841 |
amit.gupta |
327 |
return responseSender.ok(true);
|
|
|
328 |
}
|
| 26774 |
amit.gupta |
329 |
|
| 26857 |
amit.gupta |
330 |
@RequestMapping(value = "/store/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
331 |
public ResponseEntity<?> register(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
|
|
332 |
Customer customer = new Customer();
|
|
|
333 |
customer.setPassword(userModel.getPassword());
|
|
|
334 |
customer.setEmailId(userModel.getEmail());
|
|
|
335 |
customer.setFirstName(userModel.getFirstName());
|
|
|
336 |
customer.setLastName(userModel.getLastName());
|
|
|
337 |
customer.setMobileNumber(userModel.getMobile());
|
|
|
338 |
return responseSender.ok(customerService.addCustomer(customer));
|
|
|
339 |
}
|
|
|
340 |
|
| 26648 |
amit.gupta |
341 |
@RequestMapping(value = "/store/confirmOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26857 |
amit.gupta |
342 |
public ResponseEntity<?> confirmOrder(HttpServletRequest request,
|
| 26652 |
amit.gupta |
343 |
@RequestBody CreatePendingOrderRequest createPendingOrderRequest) throws Exception {
|
| 26648 |
amit.gupta |
344 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
345 |
Integer storeId = userInfo.getRetailerId();
|
|
|
346 |
createPendingOrderRequest.setFofoId(storeId);
|
| 26923 |
amit.gupta |
347 |
List<CreatePendingOrderItem> pendingOrderItems = createPendingOrderRequest.getCreatePendingOrderItem();
|
|
|
348 |
List<CartItem> cartItems = new ArrayList<>();
|
|
|
349 |
pendingOrderItems.stream().forEach(x -> {
|
|
|
350 |
CartItem ci = new CartItem();
|
|
|
351 |
ci.setItemId(x.getItemId());
|
|
|
352 |
ci.setQuantity(x.getQuantity());
|
|
|
353 |
ci.setSellingPrice(x.getSellingPrice());
|
|
|
354 |
cartItems.add(ci);
|
|
|
355 |
});
|
|
|
356 |
CartResponse cr = this.validateCart(storeId, cartItems);
|
|
|
357 |
if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
|
|
|
358 |
return responseSender.badRequest("Invalid request");
|
|
|
359 |
}
|
| 26652 |
amit.gupta |
360 |
|
| 27028 |
tejbeer |
361 |
Map<String, String> returnMap = this.pendingOrderService.createPendingOrder(createPendingOrderRequest, cr);
|
|
|
362 |
|
|
|
363 |
return responseSender.ok(returnMap);
|
|
|
364 |
|
| 26648 |
amit.gupta |
365 |
}
|
| 26630 |
amit.gupta |
366 |
|
| 26857 |
amit.gupta |
367 |
@RequestMapping(value = "/store/address", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
368 |
@ApiImplicitParams({
|
|
|
369 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
370 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
371 |
public ResponseEntity<?> getAddress(HttpServletRequest request) throws Exception {
|
|
|
372 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
373 |
Integer storeId = userInfo.getRetailerId();
|
|
|
374 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
|
|
|
375 |
|
|
|
376 |
return responseSender.ok(customRetailer.getAddress());
|
|
|
377 |
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
@RequestMapping(value = "/store/address/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
381 |
@ApiImplicitParams({
|
|
|
382 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
383 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
384 |
public ResponseEntity<?> getStoresByPincode(HttpServletRequest request, @PathVariable String pincode)
|
|
|
385 |
throws Exception {
|
|
|
386 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
387 |
int fofoId = DEFAULT_STORE;
|
|
|
388 |
if (pincodePartners.size() > 0) {
|
| 28287 |
amit.gupta |
389 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 28267 |
amit.gupta |
390 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActivePartnersByRetailerIds(fofoIds);
|
| 28287 |
amit.gupta |
391 |
if (fofoStores.size() > 0) {
|
| 28267 |
amit.gupta |
392 |
fofoId = fofoStores.get(0).getId();
|
|
|
393 |
}
|
| 28287 |
amit.gupta |
394 |
|
| 26857 |
amit.gupta |
395 |
}
|
|
|
396 |
return responseSender.ok(fofoStoreRepository.selectByRetailerId(fofoId).getCode());
|
|
|
397 |
}
|
| 26923 |
amit.gupta |
398 |
|
| 28298 |
tejbeer |
399 |
@RequestMapping(value = "/store/address/detail/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
400 |
@ApiImplicitParams({
|
|
|
401 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
402 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
403 |
public ResponseEntity<?> getStoresDetailsByPincode(HttpServletRequest request, @PathVariable String pincode)
|
|
|
404 |
throws Exception {
|
|
|
405 |
List<CustomRetailer> customerRetailers = new ArrayList<>();
|
|
|
406 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
407 |
|
|
|
408 |
if (!pincodePartners.isEmpty()) {
|
|
|
409 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
410 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
|
|
411 |
.filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
|
|
412 |
Map<Integer, CustomRetailer> customerRetailerMap = retailerService.getFofoRetailers(activefofoIds);
|
|
|
413 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
logger.info("customerRetailers" + customerRetailers);
|
|
|
417 |
return responseSender.ok(customerRetailers);
|
|
|
418 |
}
|
|
|
419 |
|
| 26855 |
tejbeer |
420 |
@RequestMapping(value = "/store/order", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
421 |
public ResponseEntity<?> getOrderDetail(HttpServletRequest request, @RequestParam(value = "id") int id,
|
| 27049 |
tejbeer |
422 |
@RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
|
| 26855 |
tejbeer |
423 |
List<CustomerOrderDetail> customerOrderDetails = new ArrayList<>();
|
| 27049 |
tejbeer |
424 |
List<Integer> catalogIds = new ArrayList<>();
|
| 26855 |
tejbeer |
425 |
List<PendingOrder> pendingOrders = pendingOrderRepository.selectByCustomerId(id, offset, limit);
|
|
|
426 |
if (!pendingOrders.isEmpty()) {
|
|
|
427 |
for (PendingOrder po : pendingOrders) {
|
|
|
428 |
List<PendingOrderItem> pois = pendingOrderItemRepository.selectByOrderId(po.getId());
|
| 27049 |
tejbeer |
429 |
for (PendingOrderItem pendingOrderItem : pois) {
|
|
|
430 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
431 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
432 |
catalogIds.add(item.getCatalogItemId());
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
436 |
|
| 26855 |
tejbeer |
437 |
for (PendingOrderItem poi : pois) {
|
|
|
438 |
|
|
|
439 |
CustomerOrderDetail customerOrderDetail = new CustomerOrderDetail();
|
|
|
440 |
|
|
|
441 |
Item item = itemRepository.selectById(poi.getItemId());
|
| 27049 |
tejbeer |
442 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
443 |
customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
|
| 26855 |
tejbeer |
444 |
customerOrderDetail.setBrand(item.getBrand());
|
|
|
445 |
customerOrderDetail.setColor(item.getColor());
|
| 27056 |
tejbeer |
446 |
customerOrderDetail.setPendingOrderItemId(poi.getId());
|
| 26855 |
tejbeer |
447 |
customerOrderDetail.setId(poi.getOrderId());
|
|
|
448 |
customerOrderDetail.setItemId(poi.getItemId());
|
|
|
449 |
customerOrderDetail.setModelName(item.getModelName());
|
|
|
450 |
customerOrderDetail.setModelNumber(item.getModelNumber());
|
|
|
451 |
customerOrderDetail.setQuantity(poi.getQuantity());
|
| 27045 |
tejbeer |
452 |
customerOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
|
|
|
453 |
customerOrderDetail.setStatus(poi.getStatus());
|
| 26855 |
tejbeer |
454 |
customerOrderDetail.setTotalPrice(poi.getSellingPrice());
|
|
|
455 |
customerOrderDetail.setPayMethod(po.getPayMethod());
|
| 26861 |
tejbeer |
456 |
customerOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
|
| 26855 |
tejbeer |
457 |
customerOrderDetails.add(customerOrderDetail);
|
|
|
458 |
}
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
return responseSender.ok(customerOrderDetails);
|
|
|
463 |
}
|
|
|
464 |
|
| 26745 |
amit.gupta |
465 |
@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
466 |
@Cacheable(value = "storelisting.all", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 26774 |
amit.gupta |
467 |
public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
|
| 26745 |
amit.gupta |
468 |
List<WebListing> webListings = webListingRepository.selectAllWebListing(Optional.of(true));
|
| 28287 |
amit.gupta |
469 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 26745 |
amit.gupta |
470 |
for (WebListing webListing : webListings) {
|
| 28287 |
amit.gupta |
471 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
| 26745 |
amit.gupta |
472 |
}
|
|
|
473 |
return responseSender.ok(webListings);
|
|
|
474 |
}
|
|
|
475 |
|
| 28287 |
amit.gupta |
476 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing)
|
|
|
477 |
throws ProfitMandiBusinessException {
|
|
|
478 |
List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
|
|
|
479 |
.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
|
|
|
480 |
if (webProducts.size() == 0) {
|
|
|
481 |
return new ArrayList<>();
|
|
|
482 |
}
|
|
|
483 |
RestClient rc = new RestClient();
|
|
|
484 |
Map<String, String> params = new HashMap<>();
|
|
|
485 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
486 |
mandatoryQ.add(String.format(
|
|
|
487 |
"+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} tagId_i:(%s)",
|
|
|
488 |
StringUtils.join(TAG_IDS, " ")));
|
|
|
489 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
490 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
491 |
// params.put("sort", "create_s desc");
|
|
|
492 |
params.put("start", String.valueOf(0));
|
|
|
493 |
params.put("rows", String.valueOf(100));
|
|
|
494 |
params.put("wt", "json");
|
|
|
495 |
String response = null;
|
|
|
496 |
try {
|
|
|
497 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
|
|
498 |
} catch (HttpHostConnectException e) {
|
|
|
499 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
500 |
}
|
|
|
501 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
502 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
503 |
List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
504 |
return dealResponse;
|
|
|
505 |
}
|
|
|
506 |
|
| 26652 |
amit.gupta |
507 |
@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
508 |
@ApiImplicitParams({
|
| 26651 |
amit.gupta |
509 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 26652 |
amit.gupta |
510 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
511 |
public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest)
|
|
|
512 |
throws Exception {
|
| 26923 |
amit.gupta |
513 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
514 |
Integer storeId = userInfo.getRetailerId();
|
|
|
515 |
ValidateCartResponse vc = new ValidateCartResponse(this.validateCart(storeId, cartRequest.getCartItems()),
|
|
|
516 |
"Success", "Items added to cart successfully");
|
|
|
517 |
return responseSender.ok(vc);
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
// Validate Cart for B2C Customers
|
|
|
521 |
private CartResponse validateCart(int storeId, List<CartItem> cartItems) throws Exception {
|
|
|
522 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
|
|
523 |
List<Integer> itemIds = cartItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
|
|
524 |
Map<Integer, AvailabilityModel> inventoryItemAvailabilityMap = inventoryService.getStoreAndOurStock(storeId,
|
|
|
525 |
itemIds);
|
| 26607 |
amit.gupta |
526 |
CartResponse cartResponse = new CartResponse();
|
| 26612 |
amit.gupta |
527 |
List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
|
|
|
528 |
cartResponse.setCartItems(cartItemResponseModels);
|
| 26607 |
amit.gupta |
529 |
Set<Integer> itemsIdsSet = new HashSet<>(itemIds);
|
| 26668 |
amit.gupta |
530 |
logger.info("Store Id {}, Item Ids {}", storeId, itemsIdsSet);
|
| 26607 |
amit.gupta |
531 |
|
|
|
532 |
Map<Integer, Item> itemsMap = itemRepository.selectByIds(itemsIdsSet).stream()
|
|
|
533 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
534 |
|
| 26923 |
amit.gupta |
535 |
Map<Integer, TagListing> tagListingMap = tagListingRepository
|
| 26607 |
amit.gupta |
536 |
.selectByItemIdsAndTagIds(new HashSet<>(itemIds), new HashSet<>(Arrays.asList(4))).stream()
|
|
|
537 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
538 |
|
|
|
539 |
List<Integer> catalogIds = itemsMap.values().stream().map(x -> x.getCatalogItemId())
|
|
|
540 |
.collect(Collectors.toList());
|
|
|
541 |
|
|
|
542 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
543 |
|
|
|
544 |
// cartResponse.getCartItems()
|
| 26923 |
amit.gupta |
545 |
int cartMessageChanged = 0;
|
|
|
546 |
int cartMessageOOS = 0;
|
|
|
547 |
int totalAmount = 0;
|
|
|
548 |
int totalQty = 0;
|
|
|
549 |
for (CartItem cartItem : cartItems) {
|
| 26607 |
amit.gupta |
550 |
Item item = itemsMap.get(cartItem.getItemId());
|
| 26923 |
amit.gupta |
551 |
TagListing tagListing = tagListingMap.get(cartItem.getItemId());
|
|
|
552 |
Float cashback = schemeService.getItemSchemeCashBack().get(cartItem.getItemId());
|
|
|
553 |
cashback = cashback == null ? 0 : cashback;
|
|
|
554 |
float itemSellingPrice = tagListing.getMop() - cashback;
|
| 26607 |
amit.gupta |
555 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
| 26923 |
amit.gupta |
556 |
cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
|
|
|
557 |
if (itemSellingPrice != cartItem.getSellingPrice()) {
|
|
|
558 |
cartItemResponseModel.setSellingPrice(itemSellingPrice);
|
|
|
559 |
cartMessageChanged++;
|
|
|
560 |
}
|
| 26628 |
amit.gupta |
561 |
int estimate = -2;
|
| 27025 |
tejbeer |
562 |
LocalDateTime promiseDeliveryTime = LocalDateTime.now();
|
| 26923 |
amit.gupta |
563 |
int qtyRequired = (int) cartItem.getQuantity();
|
|
|
564 |
AvailabilityModel availabilityModel = inventoryItemAvailabilityMap.get(cartItem.getItemId());
|
|
|
565 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
|
|
566 |
if (availabilityModel.getStoreAvailability() >= qtyRequired) {
|
|
|
567 |
estimate = 0;
|
|
|
568 |
} else if (availabilityModel.getWarehouseAvailability() >= qtyRequired) {
|
| 26628 |
amit.gupta |
569 |
estimate = 2;
|
| 26923 |
amit.gupta |
570 |
} else if (availabilityModel.getStoreAvailability() > 0) {
|
|
|
571 |
estimate = 0;
|
|
|
572 |
qtyRequired = availabilityModel.getStoreAvailability();
|
|
|
573 |
cartMessageChanged++;
|
|
|
574 |
} else if (availabilityModel.getWarehouseAvailability() > 0) {
|
|
|
575 |
qtyRequired = availabilityModel.getWarehouseAvailability();
|
|
|
576 |
estimate = 2;
|
|
|
577 |
cartMessageChanged++;
|
| 26620 |
amit.gupta |
578 |
} else {
|
| 26923 |
amit.gupta |
579 |
qtyRequired = 0;
|
| 26926 |
amit.gupta |
580 |
cartMessageChanged++;
|
| 26607 |
amit.gupta |
581 |
}
|
| 26923 |
amit.gupta |
582 |
cartItemResponseModel.setQuantity(qtyRequired);
|
| 26630 |
amit.gupta |
583 |
if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
|
| 26628 |
amit.gupta |
584 |
estimate = estimate + 1;
|
| 27025 |
tejbeer |
585 |
promiseDeliveryTime = promiseDeliveryTime.plusDays(3);
|
| 26628 |
amit.gupta |
586 |
}
|
| 26923 |
amit.gupta |
587 |
totalQty += qtyRequired;
|
|
|
588 |
totalAmount += qtyRequired * itemSellingPrice;
|
| 26628 |
amit.gupta |
589 |
cartItemResponseModel.setEstimate(estimate);
|
| 26616 |
amit.gupta |
590 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
| 26614 |
amit.gupta |
591 |
cartItemResponseModel.setItemId(cartItem.getItemId());
|
| 26615 |
amit.gupta |
592 |
cartItemResponseModel.setMinBuyQuantity(1);
|
| 26923 |
amit.gupta |
593 |
cartItemResponseModel.setQuantity(qtyRequired);
|
| 26621 |
amit.gupta |
594 |
cartItemResponseModel.setQuantityStep(1);
|
| 27025 |
tejbeer |
595 |
cartItemResponseModel.setPromiseDelivery(promiseDeliveryTime);
|
| 26923 |
amit.gupta |
596 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
| 26607 |
amit.gupta |
597 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
|
|
598 |
cartItemResponseModel.setImageUrl(contentMap.get(item.getCatalogItemId()).getString("imageUrl_s"));
|
|
|
599 |
cartItemResponseModel.setColor(item.getColor());
|
| 26620 |
amit.gupta |
600 |
cartItemResponseModels.add(cartItemResponseModel);
|
| 26607 |
amit.gupta |
601 |
}
|
| 26923 |
amit.gupta |
602 |
cartResponse.setCartItems(cartItemResponseModels);
|
|
|
603 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
|
|
604 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
|
|
605 |
int maxEstimate = cartItemResponseModels.stream().mapToInt(x -> x.getEstimate()).max().getAsInt();
|
|
|
606 |
cartResponse.setMaxEstimate(maxEstimate);
|
|
|
607 |
cartResponse.setTotalAmount(totalAmount);
|
|
|
608 |
cartResponse.setTotalQty(totalQty);
|
| 26652 |
amit.gupta |
609 |
|
| 26923 |
amit.gupta |
610 |
return cartResponse;
|
|
|
611 |
|
| 26648 |
amit.gupta |
612 |
}
|
| 26607 |
amit.gupta |
613 |
|
| 27030 |
amit.gupta |
614 |
@RequestMapping(value = "/store/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
615 |
public ResponseEntity<?> partnerStock(HttpServletRequest request,
|
|
|
616 |
@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
|
|
|
617 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
|
|
618 |
@RequestParam(value = "sort", required = false) String sort,
|
|
|
619 |
@RequestParam(value = "brand", required = false) String brand,
|
|
|
620 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
|
|
621 |
@RequestParam(value = "q", required = false) String queryTerm,
|
| 28287 |
amit.gupta |
622 |
@RequestParam(required = false) String listing,
|
|
|
623 |
@RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
|
| 27030 |
amit.gupta |
624 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
625 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 28269 |
amit.gupta |
626 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
627 |
sort = "w" + fs.getWarehouseId() + "_i desc";
|
| 27045 |
tejbeer |
628 |
dealResponse = this.getCatalogResponse(
|
|
|
629 |
solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, false), false,
|
|
|
630 |
userInfo.getRetailerId());
|
| 27030 |
amit.gupta |
631 |
return responseSender.ok(dealResponse);
|
|
|
632 |
}
|
|
|
633 |
|
| 26909 |
amit.gupta |
634 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
|
| 26607 |
amit.gupta |
635 |
throws ProfitMandiBusinessException {
|
| 26909 |
amit.gupta |
636 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
|
|
637 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
| 26607 |
amit.gupta |
638 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
639 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
640 |
if (docs.length() > 0) {
|
|
|
641 |
HashSet<Integer> itemsSet = new HashSet<>();
|
|
|
642 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
643 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
644 |
if (doc.has("_childDocuments_")) {
|
|
|
645 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
646 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
647 |
int itemId = childItem.getInt("itemId_i");
|
|
|
648 |
itemsSet.add(itemId);
|
|
|
649 |
}
|
|
|
650 |
}
|
|
|
651 |
}
|
|
|
652 |
if (itemsSet.size() == 0) {
|
|
|
653 |
return dealResponse;
|
|
|
654 |
}
|
| 28269 |
amit.gupta |
655 |
if (fofoId > 0) {
|
| 26909 |
amit.gupta |
656 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
|
|
|
657 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
658 |
}
|
| 28287 |
amit.gupta |
659 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
| 26607 |
amit.gupta |
660 |
}
|
|
|
661 |
|
|
|
662 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
663 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
664 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
665 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
666 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
667 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
668 |
ffdr.setTitle(doc.getString("title_s"));
|
|
|
669 |
try {
|
|
|
670 |
ffdr.setFeature(doc.getString("feature_s"));
|
|
|
671 |
} catch (Exception e) {
|
|
|
672 |
ffdr.setFeature(null);
|
|
|
673 |
logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
|
|
|
674 |
}
|
|
|
675 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
676 |
if (doc.has("_childDocuments_")) {
|
|
|
677 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
678 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
679 |
int itemId = childItem.getInt("itemId_i");
|
|
|
680 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
681 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
682 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
683 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
684 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
685 |
}
|
|
|
686 |
} else {
|
|
|
687 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 26909 |
amit.gupta |
688 |
fdi.setSellingPrice(sellingPrice);
|
|
|
689 |
fdi.setActive(childItem.getBoolean("active_b"));
|
|
|
690 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
| 26607 |
amit.gupta |
691 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
692 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
693 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
694 |
fdi.setItem_id(itemId);
|
| 26909 |
amit.gupta |
695 |
Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
|
|
|
696 |
cashBack = cashBack == null ? 0 : cashBack;
|
|
|
697 |
fdi.setCashback(cashBack);
|
| 26673 |
amit.gupta |
698 |
fdi.setMinBuyQuantity(1);
|
| 28287 |
amit.gupta |
699 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0
|
|
|
700 |
: Math.max(0, ourItemAvailabilityMap.get(itemId));
|
| 28269 |
amit.gupta |
701 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0
|
|
|
702 |
: partnerStockAvailabilityMap.get(itemId);
|
| 28287 |
amit.gupta |
703 |
fdi.setAvailability(Math.min(5, ourStockAvailability + partnerAvailability));
|
| 26607 |
amit.gupta |
704 |
fdi.setQuantityStep(1);
|
| 28269 |
amit.gupta |
705 |
fdi.setMaxQuantity(fdi.getAvailability());
|
| 26607 |
amit.gupta |
706 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
}
|
|
|
710 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| 26909 |
amit.gupta |
711 |
ffdr.setItems(fofoAvailabilityInfoMap.values().stream()
|
| 26923 |
amit.gupta |
712 |
.sorted((x, y) -> y.getAvailability() - x.getAvailability()).collect(Collectors.toList()));
|
| 26607 |
amit.gupta |
713 |
dealResponse.add(ffdr);
|
|
|
714 |
}
|
|
|
715 |
}
|
| 28287 |
amit.gupta |
716 |
return dealResponse.stream().sorted((x, y) -> {
|
|
|
717 |
return Math.min(y.getItems().get(0).getAvailability(), 1)
|
|
|
718 |
- Math.min(x.getItems().get(0).getAvailability(), 1);
|
| 28237 |
amit.gupta |
719 |
}).collect(Collectors.toList());
|
| 26909 |
amit.gupta |
720 |
|
| 26607 |
amit.gupta |
721 |
}
|
| 26923 |
amit.gupta |
722 |
|
|
|
723 |
@GetMapping(value = "store/order-status/{pendingOrderId}")
|
| 27028 |
tejbeer |
724 |
public ResponseEntity<?> orderStatus(HttpServletRequest request, @PathVariable int pendingOrderId)
|
|
|
725 |
throws Exception {
|
| 26923 |
amit.gupta |
726 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderId);
|
|
|
727 |
List<PendingOrderItem> pendingOrderItems = pendingOrderItemRepository.selectByOrderId(pendingOrder.getId());
|
|
|
728 |
List<Integer> catalogIds = new ArrayList<>();
|
| 27028 |
tejbeer |
729 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
| 26923 |
amit.gupta |
730 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
731 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
732 |
catalogIds.add(item.getCatalogItemId());
|
|
|
733 |
}
|
|
|
734 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
| 27028 |
tejbeer |
735 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
| 26923 |
amit.gupta |
736 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
737 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
738 |
pendingOrderItem.setImgUrl(jsonObj.getString("imageUrl_s"));
|
|
|
739 |
}
|
|
|
740 |
pendingOrder.setPendingOrderItems(pendingOrderItems);
|
| 27069 |
tejbeer |
741 |
|
|
|
742 |
CustomerAddress customerAddress = customerAddressRepository.selectById(pendingOrder.getCustomerAddressId());
|
|
|
743 |
|
|
|
744 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy H:m");
|
|
|
745 |
Template t = velocityEngine.getTemplate("sms.vm");
|
|
|
746 |
VelocityContext context = new VelocityContext();
|
|
|
747 |
|
|
|
748 |
context.put("customer", customerAddress);
|
|
|
749 |
context.put("pendingOrder", pendingOrder);
|
|
|
750 |
context.put("date", dateTimeFormatter);
|
|
|
751 |
StringWriter writer = new StringWriter();
|
|
|
752 |
t.merge(context, writer);
|
|
|
753 |
|
| 28290 |
tejbeer |
754 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(pendingOrder.getFofoId());
|
|
|
755 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
| 28294 |
tejbeer |
756 |
|
| 28291 |
tejbeer |
757 |
if (!customer.getEmailId().equals(null)) {
|
|
|
758 |
String[] customerEmail = { customer.getEmailId() };
|
| 28290 |
tejbeer |
759 |
|
| 28291 |
tejbeer |
760 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(), customerEmail);
|
|
|
761 |
|
|
|
762 |
}
|
|
|
763 |
|
| 28290 |
tejbeer |
764 |
String[] retailerEmail = { customRetailer.getEmail() };
|
|
|
765 |
|
| 28296 |
tejbeer |
766 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
|
|
767 |
"hemant.kaura@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
|
|
768 |
"tejbeer.kaur@shop2020.in");
|
|
|
769 |
|
| 28290 |
tejbeer |
770 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
| 28294 |
tejbeer |
771 |
logger.info("authUserEmails" + authUserEmails);
|
| 28290 |
tejbeer |
772 |
|
|
|
773 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(), retailerEmail);
|
| 28296 |
tejbeer |
774 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(),
|
|
|
775 |
sendTo.toArray(new String[sendTo.size()]));
|
| 28290 |
tejbeer |
776 |
|
| 28293 |
tejbeer |
777 |
if (!authUserEmails.isEmpty()) {
|
|
|
778 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(),
|
| 28294 |
tejbeer |
779 |
authUserEmails.toArray(new String[authUserEmails.size()]));
|
| 28293 |
tejbeer |
780 |
}
|
| 26923 |
amit.gupta |
781 |
return responseSender.ok(pendingOrder);
|
|
|
782 |
}
|
|
|
783 |
|
| 28290 |
tejbeer |
784 |
private void sendMailWithAttachments(String subject, String messageText, String[] email) throws Exception {
|
| 27069 |
tejbeer |
785 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
786 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 28290 |
tejbeer |
787 |
helper.setTo(email);
|
| 27069 |
tejbeer |
788 |
helper.setSubject(subject);
|
|
|
789 |
helper.setText(messageText, true);
|
|
|
790 |
|
|
|
791 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
|
|
792 |
helper.setFrom(senderAddress);
|
|
|
793 |
mailSender.send(message);
|
|
|
794 |
|
|
|
795 |
}
|
|
|
796 |
|
| 26833 |
amit.gupta |
797 |
@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
|
|
|
798 |
public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
|
| 27045 |
tejbeer |
799 |
return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
|
| 26788 |
amit.gupta |
800 |
}
|
| 26833 |
amit.gupta |
801 |
|
| 26857 |
amit.gupta |
802 |
@RequestMapping(value = "/store/address", method = RequestMethod.POST)
|
|
|
803 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress)
|
|
|
804 |
throws Throwable {
|
|
|
805 |
customerAddressRepository.persist(customerAddress);
|
|
|
806 |
return responseSender.ok(customerAddress);
|
|
|
807 |
}
|
|
|
808 |
|
| 27045 |
tejbeer |
809 |
@RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
|
|
|
810 |
public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
|
|
|
811 |
CustomerAddress cust = customerAddressRepository.selectById(id);
|
|
|
812 |
cust.setActive(false);
|
|
|
813 |
return responseSender.ok(cust);
|
|
|
814 |
}
|
|
|
815 |
|
| 26861 |
tejbeer |
816 |
@RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
|
|
|
817 |
public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer)
|
|
|
818 |
throws Throwable {
|
|
|
819 |
Customer cust = customerRepository.selectById(customer.getId());
|
|
|
820 |
cust.setGender(customer.getGender());
|
| 26867 |
tejbeer |
821 |
cust.setProfileImageId(customer.getProfileImageId());
|
| 26861 |
tejbeer |
822 |
cust.setDob(customer.getDob());
|
|
|
823 |
return responseSender.ok(cust);
|
|
|
824 |
}
|
|
|
825 |
|
| 27048 |
tejbeer |
826 |
@RequestMapping(value = "/cancelPendingOrderItem", method = RequestMethod.POST)
|
|
|
827 |
public ResponseEntity<?> cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id,
|
| 27045 |
tejbeer |
828 |
|
| 27048 |
tejbeer |
829 |
@RequestParam String statusDescription) throws Exception {
|
|
|
830 |
|
|
|
831 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
|
|
832 |
|
| 27057 |
tejbeer |
833 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
| 27048 |
tejbeer |
834 |
if (pendingOrderItem.getBilledTimestamp() == null) {
|
|
|
835 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
|
|
836 |
pendingOrderItem.setStatusDescription(statusDescription);
|
|
|
837 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId())
|
|
|
838 |
.stream().map(x -> x.getStatus()).collect(Collectors.toList());
|
|
|
839 |
|
|
|
840 |
if (!status.contains(OrderStatus.PENDING)) {
|
|
|
841 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
|
|
842 |
}
|
|
|
843 |
|
|
|
844 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
|
|
845 |
}
|
|
|
846 |
|
|
|
847 |
return responseSender.ok(true);
|
|
|
848 |
|
|
|
849 |
}
|
|
|
850 |
|
| 26774 |
amit.gupta |
851 |
}
|
|
|
852 |
|
| 26784 |
amit.gupta |
853 |
class UserModel {
|
| 26857 |
amit.gupta |
854 |
@JsonProperty(required = true)
|
| 26784 |
amit.gupta |
855 |
private String mobile;
|
| 26857 |
amit.gupta |
856 |
@JsonProperty(required = true)
|
| 26784 |
amit.gupta |
857 |
private String password;
|
| 26857 |
amit.gupta |
858 |
@JsonProperty(required = false)
|
|
|
859 |
private String firstName;
|
|
|
860 |
@JsonProperty(required = false)
|
|
|
861 |
private String lastName;
|
|
|
862 |
@JsonProperty(required = false)
|
|
|
863 |
private String email;
|
| 26833 |
amit.gupta |
864 |
|
| 26784 |
amit.gupta |
865 |
@Override
|
|
|
866 |
public String toString() {
|
|
|
867 |
return "UserModel [mobile=" + mobile + ", password=" + password + "]";
|
|
|
868 |
}
|
| 26833 |
amit.gupta |
869 |
|
| 26784 |
amit.gupta |
870 |
public String getMobile() {
|
|
|
871 |
return mobile;
|
|
|
872 |
}
|
| 26833 |
amit.gupta |
873 |
|
| 26784 |
amit.gupta |
874 |
public void setMobile(String mobile) {
|
|
|
875 |
this.mobile = mobile;
|
|
|
876 |
}
|
| 26833 |
amit.gupta |
877 |
|
| 26784 |
amit.gupta |
878 |
public String getPassword() {
|
|
|
879 |
return password;
|
|
|
880 |
}
|
| 26833 |
amit.gupta |
881 |
|
| 26784 |
amit.gupta |
882 |
public void setPassword(String password) {
|
|
|
883 |
this.password = password;
|
|
|
884 |
}
|
| 26857 |
amit.gupta |
885 |
|
|
|
886 |
public String getFirstName() {
|
|
|
887 |
return firstName;
|
|
|
888 |
}
|
|
|
889 |
|
|
|
890 |
public void setFirstName(String firstName) {
|
|
|
891 |
this.firstName = firstName;
|
|
|
892 |
}
|
|
|
893 |
|
|
|
894 |
public String getLastName() {
|
|
|
895 |
return lastName;
|
|
|
896 |
}
|
|
|
897 |
|
|
|
898 |
public void setLastName(String lastName) {
|
|
|
899 |
this.lastName = lastName;
|
|
|
900 |
}
|
|
|
901 |
|
|
|
902 |
public String getEmail() {
|
|
|
903 |
return email;
|
|
|
904 |
}
|
|
|
905 |
|
|
|
906 |
public void setEmail(String email) {
|
|
|
907 |
this.email = email;
|
|
|
908 |
}
|
|
|
909 |
|
| 26784 |
amit.gupta |
910 |
}
|
|
|
911 |
|
| 26774 |
amit.gupta |
912 |
class CustomerModel {
|
| 26783 |
amit.gupta |
913 |
|
| 26774 |
amit.gupta |
914 |
@JsonProperty(required = false)
|
|
|
915 |
private Customer customer;
|
|
|
916 |
@JsonProperty(required = true)
|
|
|
917 |
private boolean exists;
|
|
|
918 |
|
|
|
919 |
public CustomerModel(boolean exists, Customer customer) {
|
|
|
920 |
super();
|
|
|
921 |
this.customer = customer;
|
|
|
922 |
this.exists = exists;
|
|
|
923 |
}
|
|
|
924 |
|
|
|
925 |
@Override
|
|
|
926 |
public String toString() {
|
|
|
927 |
return "CustomerModel [customer=" + customer + ", exists=" + exists + "]";
|
|
|
928 |
}
|
|
|
929 |
|
|
|
930 |
public Customer getCustomer() {
|
|
|
931 |
return customer;
|
|
|
932 |
}
|
|
|
933 |
|
|
|
934 |
public void setCustomer(Customer customer) {
|
|
|
935 |
this.customer = customer;
|
|
|
936 |
}
|
|
|
937 |
|
|
|
938 |
public boolean isExists() {
|
|
|
939 |
return exists;
|
|
|
940 |
}
|
|
|
941 |
|
|
|
942 |
public void setExists(boolean exists) {
|
|
|
943 |
this.exists = exists;
|
|
|
944 |
}
|
| 26607 |
amit.gupta |
945 |
}
|