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