| 26607 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.eclipsesource.json.JsonObject;
|
|
|
4 |
import com.google.gson.Gson;
|
|
|
5 |
import com.google.gson.reflect.TypeToken;
|
| 28377 |
tejbeer |
6 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 26607 |
amit.gupta |
7 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
8 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30123 |
amit.gupta |
9 |
import com.spice.profitmandi.common.model.*;
|
| 26607 |
amit.gupta |
10 |
import com.spice.profitmandi.common.solr.SolrService;
|
| 28304 |
amit.gupta |
11 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 28566 |
tejbeer |
12 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 28405 |
amit.gupta |
13 |
import com.spice.profitmandi.common.util.Utils;
|
| 26607 |
amit.gupta |
14 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
15 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
16 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
17 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 29515 |
tejbeer |
18 |
import com.spice.profitmandi.dao.entity.dtr.ScratchOffer;
|
| 28377 |
tejbeer |
19 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 26745 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
| 28374 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
|
| 30123 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 31203 |
tejbeer |
23 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 26630 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
| 31573 |
tejbeer |
25 |
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
|
| 29515 |
tejbeer |
26 |
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
|
| 27045 |
tejbeer |
27 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 30123 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.model.*;
|
| 26607 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
30 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 28290 |
tejbeer |
31 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 30123 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
33 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 26607 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 28582 |
amit.gupta |
35 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 26784 |
amit.gupta |
36 |
import com.spice.profitmandi.service.CustomerService;
|
| 28377 |
tejbeer |
37 |
import com.spice.profitmandi.service.EmailService;
|
|
|
38 |
import com.spice.profitmandi.service.NotificationService;
|
| 26607 |
amit.gupta |
39 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 30123 |
amit.gupta |
40 |
import com.spice.profitmandi.service.inventory.*;
|
| 28566 |
tejbeer |
41 |
import com.spice.profitmandi.service.order.OrderService;
|
| 26683 |
amit.gupta |
42 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26651 |
amit.gupta |
43 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 26630 |
amit.gupta |
44 |
import com.spice.profitmandi.web.processor.OtpProcessor;
|
| 26607 |
amit.gupta |
45 |
import com.spice.profitmandi.web.res.DealBrands;
|
|
|
46 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
47 |
import com.spice.profitmandi.web.res.DealsResponse;
|
|
|
48 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
| 28322 |
amit.gupta |
49 |
import com.spice.profitmandi.web.services.PartnerIndexService;
|
| 26607 |
amit.gupta |
50 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
51 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
52 |
import io.swagger.annotations.ApiOperation;
|
| 30123 |
amit.gupta |
53 |
import org.apache.commons.lang3.StringUtils;
|
|
|
54 |
import org.apache.http.conn.HttpHostConnectException;
|
|
|
55 |
import org.apache.logging.log4j.LogManager;
|
|
|
56 |
import org.apache.logging.log4j.Logger;
|
|
|
57 |
import org.json.JSONArray;
|
|
|
58 |
import org.json.JSONObject;
|
|
|
59 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
60 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
61 |
import org.springframework.core.io.InputStreamResource;
|
|
|
62 |
import org.springframework.http.HttpHeaders;
|
|
|
63 |
import org.springframework.http.HttpStatus;
|
|
|
64 |
import org.springframework.http.MediaType;
|
|
|
65 |
import org.springframework.http.ResponseEntity;
|
|
|
66 |
import org.springframework.stereotype.Controller;
|
|
|
67 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
68 |
import org.springframework.web.bind.annotation.*;
|
| 26607 |
amit.gupta |
69 |
|
| 30123 |
amit.gupta |
70 |
import javax.servlet.http.HttpServletRequest;
|
|
|
71 |
import javax.servlet.http.HttpServletResponse;
|
|
|
72 |
import java.io.ByteArrayInputStream;
|
|
|
73 |
import java.io.ByteArrayOutputStream;
|
|
|
74 |
import java.io.IOException;
|
|
|
75 |
import java.io.InputStream;
|
| 31445 |
tejbeer |
76 |
import java.time.LocalDate;
|
| 30123 |
amit.gupta |
77 |
import java.time.LocalDateTime;
|
|
|
78 |
import java.time.LocalTime;
|
|
|
79 |
import java.time.format.DateTimeFormatter;
|
|
|
80 |
import java.util.*;
|
|
|
81 |
import java.util.stream.Collectors;
|
|
|
82 |
|
| 26607 |
amit.gupta |
83 |
@Controller
|
|
|
84 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
85 |
public class StoreController {
|
|
|
86 |
|
|
|
87 |
private static final Logger logger = LogManager.getLogger(StoreController.class);
|
| 26630 |
amit.gupta |
88 |
|
| 26628 |
amit.gupta |
89 |
private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
|
| 26745 |
amit.gupta |
90 |
|
|
|
91 |
private static final List<Integer> TAG_IDS = Arrays.asList(4);
|
|
|
92 |
|
| 26788 |
amit.gupta |
93 |
@Autowired
|
|
|
94 |
CustomerAddressRepository customerAddressRepository;
|
| 28392 |
tejbeer |
95 |
|
| 28374 |
amit.gupta |
96 |
@Autowired
|
|
|
97 |
WebOfferRepository webOfferRepository;
|
| 26607 |
amit.gupta |
98 |
|
| 28315 |
amit.gupta |
99 |
@Value("${new.solr.url}")
|
| 28314 |
amit.gupta |
100 |
private String solrUrl;
|
| 28345 |
tejbeer |
101 |
|
| 26923 |
amit.gupta |
102 |
@Autowired
|
| 28322 |
amit.gupta |
103 |
private PartnerIndexService partnerIndexService;
|
| 28345 |
tejbeer |
104 |
|
| 28322 |
amit.gupta |
105 |
@Autowired
|
| 26923 |
amit.gupta |
106 |
InventoryService inventoryService;
|
| 27045 |
tejbeer |
107 |
|
| 27030 |
amit.gupta |
108 |
@Autowired
|
|
|
109 |
UserAccountRepository userAccountRepository;
|
| 26923 |
amit.gupta |
110 |
|
| 26607 |
amit.gupta |
111 |
@Value("${python.api.host}")
|
|
|
112 |
private String host;
|
| 26833 |
amit.gupta |
113 |
|
| 26784 |
amit.gupta |
114 |
@Autowired
|
|
|
115 |
CustomerService customerService;
|
| 26607 |
amit.gupta |
116 |
|
|
|
117 |
@Value("${python.api.port}")
|
|
|
118 |
private int port;
|
| 26923 |
amit.gupta |
119 |
|
| 26909 |
amit.gupta |
120 |
@Autowired
|
|
|
121 |
private SaholicInventoryService saholicInventoryService;
|
| 26607 |
amit.gupta |
122 |
|
|
|
123 |
@Autowired
|
| 26715 |
amit.gupta |
124 |
private PincodePartnerRepository pincodePartnerRepository;
|
|
|
125 |
|
|
|
126 |
@Autowired
|
| 26718 |
amit.gupta |
127 |
private FofoStoreRepository fofoStoreRepository;
|
| 26745 |
amit.gupta |
128 |
|
| 26718 |
amit.gupta |
129 |
@Autowired
|
| 26651 |
amit.gupta |
130 |
private RetailerService retailerService;
|
| 26861 |
tejbeer |
131 |
|
| 26857 |
amit.gupta |
132 |
@Autowired
|
|
|
133 |
private PendingOrderRepository pendingOrderRepository;
|
| 26861 |
tejbeer |
134 |
|
| 26857 |
amit.gupta |
135 |
@Autowired
|
|
|
136 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
| 26652 |
amit.gupta |
137 |
|
| 26651 |
amit.gupta |
138 |
@Autowired
|
| 26652 |
amit.gupta |
139 |
private PendingOrderService pendingOrderService;
|
| 26648 |
amit.gupta |
140 |
|
|
|
141 |
@Autowired
|
| 26774 |
amit.gupta |
142 |
private CustomerRepository customerRepository;
|
|
|
143 |
|
|
|
144 |
@Autowired
|
| 26607 |
amit.gupta |
145 |
private SolrService commonSolrService;
|
|
|
146 |
|
|
|
147 |
@Autowired
|
| 26630 |
amit.gupta |
148 |
private OtpProcessor otpProcessor;
|
|
|
149 |
|
|
|
150 |
@Autowired
|
| 26607 |
amit.gupta |
151 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
152 |
|
| 26609 |
amit.gupta |
153 |
@Autowired
|
| 26607 |
amit.gupta |
154 |
private ResponseSender<?> responseSender;
|
|
|
155 |
|
|
|
156 |
@Autowired
|
|
|
157 |
private TagListingRepository tagListingRepository;
|
|
|
158 |
|
|
|
159 |
@Autowired
|
|
|
160 |
private ItemRepository itemRepository;
|
| 26701 |
amit.gupta |
161 |
|
| 26683 |
amit.gupta |
162 |
@Autowired
|
|
|
163 |
private SchemeService schemeService;
|
| 26607 |
amit.gupta |
164 |
|
|
|
165 |
@Autowired
|
| 28566 |
tejbeer |
166 |
private UserRepository userRepository;
|
|
|
167 |
|
|
|
168 |
@Autowired
|
| 26607 |
amit.gupta |
169 |
private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
|
|
|
170 |
|
|
|
171 |
@Autowired
|
| 26745 |
amit.gupta |
172 |
private WebListingRepository webListingRepository;
|
|
|
173 |
|
|
|
174 |
@Autowired
|
|
|
175 |
private WebProductListingRepository webProductListingRepository;
|
|
|
176 |
|
|
|
177 |
@Autowired
|
| 26607 |
amit.gupta |
178 |
private RoleManager roleManagerService;
|
|
|
179 |
|
| 27028 |
tejbeer |
180 |
@Autowired
|
| 28304 |
amit.gupta |
181 |
EmailService emailService;
|
| 27028 |
tejbeer |
182 |
|
|
|
183 |
@Autowired
|
| 28290 |
tejbeer |
184 |
CsService csService;
|
| 28339 |
tejbeer |
185 |
|
| 28377 |
tejbeer |
186 |
@Autowired
|
|
|
187 |
private NotificationService notificationService;
|
|
|
188 |
|
|
|
189 |
@Autowired
|
|
|
190 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
|
|
191 |
|
| 28566 |
tejbeer |
192 |
@Autowired
|
|
|
193 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
194 |
|
|
|
195 |
@Autowired
|
|
|
196 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
197 |
|
|
|
198 |
@Autowired
|
|
|
199 |
private OrderService orderService;
|
| 29515 |
tejbeer |
200 |
|
|
|
201 |
@Autowired
|
|
|
202 |
private ScratchOfferRepository scratchOfferRepository;
|
| 28339 |
tejbeer |
203 |
private static final List<String> offlineOrders = Arrays.asList("EMIOD", "POD");
|
|
|
204 |
|
| 26607 |
amit.gupta |
205 |
List<String> filterableParams = Arrays.asList("brand");
|
|
|
206 |
|
| 26668 |
amit.gupta |
207 |
@RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
208 |
@ApiImplicitParams({
|
|
|
209 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
210 |
@ApiOperation(value = "Get unit deal object")
|
|
|
211 |
public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
|
|
212 |
throws ProfitMandiBusinessException {
|
| 28423 |
amit.gupta |
213 |
List<FofoCatalogResponse> dealResponses = new ArrayList<>();
|
| 26668 |
amit.gupta |
214 |
List<Integer> tagIds = Arrays.asList(4);
|
| 28423 |
amit.gupta |
215 |
FofoCatalogResponse fofoCatalogResponse = null;
|
| 26668 |
amit.gupta |
216 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
217 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
|
|
218 |
String categoryId = "(3 OR 6)";
|
| 26745 |
amit.gupta |
219 |
|
| 26668 |
amit.gupta |
220 |
RestClient rc = new RestClient();
|
|
|
221 |
Map<String, String> params = new HashMap<>();
|
|
|
222 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
223 |
String catalogString = "catalog" + id;
|
| 26607 |
amit.gupta |
224 |
|
| 26668 |
amit.gupta |
225 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
|
|
|
226 |
categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
|
|
227 |
|
|
|
228 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
229 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
230 |
params.put("sort", "rank_i asc, create_s desc");
|
|
|
231 |
params.put("wt", "json");
|
|
|
232 |
String response = null;
|
|
|
233 |
try {
|
| 28316 |
amit.gupta |
234 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 26668 |
amit.gupta |
235 |
} catch (HttpHostConnectException e) {
|
|
|
236 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
237 |
}
|
|
|
238 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
239 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 28423 |
amit.gupta |
240 |
dealResponses = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
241 |
fofoCatalogResponse = dealResponses.get(0);
|
| 28467 |
tejbeer |
242 |
fofoCatalogResponse
|
|
|
243 |
.setWebOffers(webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId()));
|
|
|
244 |
|
| 26668 |
amit.gupta |
245 |
} else {
|
|
|
246 |
return responseSender.badRequest(
|
|
|
247 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
248 |
}
|
| 28423 |
amit.gupta |
249 |
return responseSender.ok(dealResponses.get(0));
|
| 26668 |
amit.gupta |
250 |
}
|
|
|
251 |
|
| 26607 |
amit.gupta |
252 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
253 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
|
|
254 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
255 |
}
|
|
|
256 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
@RequestMapping(value = "/store/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
260 |
@ApiImplicitParams({
|
|
|
261 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
262 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
263 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
|
|
264 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
|
|
|
265 |
logger.info("Request " + request.getParameterMap());
|
|
|
266 |
String response = null;
|
|
|
267 |
// TODO: move to properties
|
|
|
268 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
|
|
269 |
RestClient rc = new RestClient();
|
|
|
270 |
Map<String, String> params = new HashMap<>();
|
|
|
271 |
params.put("category_id", category_id);
|
|
|
272 |
List<DealBrands> dealBrandsResponse = null;
|
|
|
273 |
try {
|
|
|
274 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
275 |
} catch (HttpHostConnectException e) {
|
|
|
276 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
280 |
}.getType());
|
|
|
281 |
|
|
|
282 |
return responseSender.ok(dealBrandsResponse);
|
|
|
283 |
}
|
|
|
284 |
|
| 26745 |
amit.gupta |
285 |
@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
286 |
public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
|
| 26909 |
amit.gupta |
287 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 28287 |
amit.gupta |
288 |
WebListing webListing = webListingRepository.selectByUrl(listingUrl);
|
|
|
289 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
| 26745 |
amit.gupta |
290 |
return responseSender.ok(webListing);
|
| 26654 |
amit.gupta |
291 |
}
|
|
|
292 |
|
| 26632 |
amit.gupta |
293 |
@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26783 |
amit.gupta |
294 |
public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String mobile) throws Exception {
|
| 26630 |
amit.gupta |
295 |
|
| 26857 |
amit.gupta |
296 |
return responseSender.ok(otpProcessor.generateOtp(mobile, OtpType.REGISTRATION));
|
| 26630 |
amit.gupta |
297 |
|
|
|
298 |
}
|
| 26652 |
amit.gupta |
299 |
|
| 26784 |
amit.gupta |
300 |
@RequestMapping(value = "/store/checkmobile/{mobile}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26833 |
amit.gupta |
301 |
public ResponseEntity<?> checkRegistrationUsingMobile(HttpServletRequest request, @PathVariable String mobile)
|
|
|
302 |
throws Exception {
|
| 26774 |
amit.gupta |
303 |
try {
|
|
|
304 |
Customer customer = customerRepository.selectByMobileNumber(mobile);
|
| 26777 |
amit.gupta |
305 |
customer.setPasswordExist(StringUtils.isNotEmpty(customer.getPassword()));
|
| 26774 |
amit.gupta |
306 |
return responseSender.ok(new CustomerModel(true, customer));
|
|
|
307 |
} catch (Exception e) {
|
|
|
308 |
return responseSender.ok(new CustomerModel(false, null));
|
|
|
309 |
}
|
|
|
310 |
}
|
| 26833 |
amit.gupta |
311 |
|
| 26784 |
amit.gupta |
312 |
@RequestMapping(value = "/store/signin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
313 |
public ResponseEntity<?> signIn(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
| 26833 |
amit.gupta |
314 |
if (customerService.authenticate(userModel.getMobile(), userModel.getPassword())) {
|
| 26784 |
amit.gupta |
315 |
return responseSender.ok(true);
|
|
|
316 |
} else {
|
|
|
317 |
return responseSender.ok(false);
|
|
|
318 |
}
|
|
|
319 |
}
|
| 26923 |
amit.gupta |
320 |
|
| 26841 |
amit.gupta |
321 |
@RequestMapping(value = "/store/resetPassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26923 |
amit.gupta |
322 |
public ResponseEntity<?> resetPassword(HttpServletRequest request, @RequestBody UserModel userModel)
|
|
|
323 |
throws Exception {
|
| 26843 |
amit.gupta |
324 |
customerService.changePassword(userModel.getMobile(), userModel.getPassword());
|
| 26841 |
amit.gupta |
325 |
return responseSender.ok(true);
|
|
|
326 |
}
|
| 26774 |
amit.gupta |
327 |
|
| 26857 |
amit.gupta |
328 |
@RequestMapping(value = "/store/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
329 |
public ResponseEntity<?> register(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
|
|
330 |
Customer customer = new Customer();
|
|
|
331 |
customer.setPassword(userModel.getPassword());
|
|
|
332 |
customer.setEmailId(userModel.getEmail());
|
|
|
333 |
customer.setFirstName(userModel.getFirstName());
|
|
|
334 |
customer.setLastName(userModel.getLastName());
|
|
|
335 |
customer.setMobileNumber(userModel.getMobile());
|
|
|
336 |
return responseSender.ok(customerService.addCustomer(customer));
|
|
|
337 |
}
|
|
|
338 |
|
| 26648 |
amit.gupta |
339 |
@RequestMapping(value = "/store/confirmOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26857 |
amit.gupta |
340 |
public ResponseEntity<?> confirmOrder(HttpServletRequest request,
|
| 26652 |
amit.gupta |
341 |
@RequestBody CreatePendingOrderRequest createPendingOrderRequest) throws Exception {
|
| 26648 |
amit.gupta |
342 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
343 |
Integer storeId = userInfo.getRetailerId();
|
|
|
344 |
createPendingOrderRequest.setFofoId(storeId);
|
| 26923 |
amit.gupta |
345 |
List<CreatePendingOrderItem> pendingOrderItems = createPendingOrderRequest.getCreatePendingOrderItem();
|
|
|
346 |
List<CartItem> cartItems = new ArrayList<>();
|
|
|
347 |
pendingOrderItems.stream().forEach(x -> {
|
|
|
348 |
CartItem ci = new CartItem();
|
|
|
349 |
ci.setItemId(x.getItemId());
|
|
|
350 |
ci.setQuantity(x.getQuantity());
|
|
|
351 |
ci.setSellingPrice(x.getSellingPrice());
|
|
|
352 |
cartItems.add(ci);
|
|
|
353 |
});
|
|
|
354 |
CartResponse cr = this.validateCart(storeId, cartItems);
|
|
|
355 |
if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
|
|
|
356 |
return responseSender.badRequest("Invalid request");
|
|
|
357 |
}
|
| 26652 |
amit.gupta |
358 |
|
| 27028 |
tejbeer |
359 |
Map<String, String> returnMap = this.pendingOrderService.createPendingOrder(createPendingOrderRequest, cr);
|
|
|
360 |
|
| 28339 |
tejbeer |
361 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(Integer.parseInt(returnMap.get("poId")));
|
|
|
362 |
if (offlineOrders.contains(pendingOrder.getPayMethod())) {
|
|
|
363 |
|
|
|
364 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(pendingOrder);
|
|
|
365 |
|
|
|
366 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(pendingOrder.getFofoId());
|
|
|
367 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
|
|
368 |
String[] customerEmail = null;
|
| 28405 |
amit.gupta |
369 |
if (Utils.validateEmail(customer.getEmailId())) {
|
| 28339 |
tejbeer |
370 |
customerEmail = new String[] { customer.getEmailId() };
|
|
|
371 |
}
|
| 28377 |
tejbeer |
372 |
|
| 28339 |
tejbeer |
373 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 28467 |
tejbeer |
374 |
"niranjan.kala@smartdukaan.com", "sm@smartdukaan.com", "tejbeer.kaur@shop2020.in",
|
|
|
375 |
"devkinandan.lal@smartdukaan.com", customRetailer.getEmail());
|
| 28377 |
tejbeer |
376 |
|
| 28339 |
tejbeer |
377 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
|
|
378 |
if (authUserEmails != null) {
|
|
|
379 |
authUserEmails = new ArrayList<>();
|
|
|
380 |
}
|
|
|
381 |
logger.info("authUserEmails {}", authUserEmails);
|
|
|
382 |
authUserEmails.addAll(bccTo);
|
| 28374 |
amit.gupta |
383 |
StringBuffer itemBuffer = new StringBuffer();
|
|
|
384 |
List<PendingOrderItem> orderItems = pendingOrderItemRepository.selectByOrderId(pendingOrder.getId());
|
|
|
385 |
int totalItems = 0;
|
|
|
386 |
String itemNoColor = null;
|
|
|
387 |
float maxValue = 0;
|
| 28391 |
tejbeer |
388 |
for (PendingOrderItem orderItem : orderItems) {
|
|
|
389 |
if (maxValue < orderItem.getSellingPrice()) {
|
| 28374 |
amit.gupta |
390 |
maxValue = orderItem.getSellingPrice();
|
|
|
391 |
itemNoColor = itemRepository.selectById(orderItem.getItemId()).getItemDescriptionNoColor();
|
|
|
392 |
}
|
|
|
393 |
totalItems += orderItem.getQuantity();
|
|
|
394 |
}
|
| 28391 |
tejbeer |
395 |
if (totalItems > 1) {
|
| 28374 |
amit.gupta |
396 |
itemBuffer.append(StringUtils.abbreviate(itemNoColor, 22));
|
| 28391 |
tejbeer |
397 |
itemBuffer.append(" +").append(totalItems - 1).append(" items");
|
| 28374 |
amit.gupta |
398 |
} else {
|
|
|
399 |
itemBuffer.append(StringUtils.abbreviate(itemNoColor, 30));
|
|
|
400 |
}
|
| 28400 |
tejbeer |
401 |
String message = String.format(OtpProcessor.TEMPLATE_ORDER_CREATED, pendingOrder.getId(),
|
|
|
402 |
itemBuffer.toString(), pendingOrder.getTotalAmount());
|
|
|
403 |
otpProcessor.sendSms(OtpProcessor.TEMPLATE_ORDER_CREATED_ID, message, customer.getMobileNumber());
|
| 28391 |
tejbeer |
404 |
|
| 28400 |
tejbeer |
405 |
emailService.sendMailWithAttachments("Order Created with SmartDukaan", "order-confirm.vm", emailModel,
|
|
|
406 |
customerEmail, null, bccTo.toArray(new String[0]));
|
|
|
407 |
|
| 28402 |
tejbeer |
408 |
List<String> emailIds = csService.getAuthUserIdByPartnerId(customRetailer.getPartnerId()).stream()
|
|
|
409 |
.map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 31203 |
tejbeer |
410 |
|
|
|
411 |
emailIds.addAll(
|
|
|
412 |
csService
|
|
|
413 |
.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_MARKETING,
|
|
|
414 |
Arrays.asList(EscalationType.L1, EscalationType.L2, EscalationType.L3,
|
|
|
415 |
EscalationType.L4))
|
|
|
416 |
.stream().map(x -> x.getEmailId()).collect(Collectors.toList()));
|
| 28402 |
tejbeer |
417 |
emailIds.add("tarun.verma@smartdukaan.com");
|
| 28436 |
tejbeer |
418 |
emailIds.add("devkinandan.lal@smartdukaan.com");
|
| 28402 |
tejbeer |
419 |
emailIds.add("tejbeer.kaur@shop2020.in");
|
|
|
420 |
List<User> user = dtrUserRepository.selectAllByEmailIds(emailIds);
|
| 28377 |
tejbeer |
421 |
List<Integer> userIds = user.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 28394 |
tejbeer |
422 |
|
|
|
423 |
logger.info("userIds" + userIds);
|
| 28397 |
tejbeer |
424 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 28377 |
tejbeer |
425 |
sendNotificationModel.setCampaignName("Online Order Alert");
|
|
|
426 |
sendNotificationModel.setTitle("Online Order Update");
|
| 28391 |
tejbeer |
427 |
sendNotificationModel.setMessage(String.format(
|
|
|
428 |
"You have new Online Order. Please check your Dashboard. In case of an activation scheme pls ensure the handset is activated, payout will be processed as per brand's activation report."));
|
| 28377 |
tejbeer |
429 |
sendNotificationModel.setType("url");
|
|
|
430 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
431 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
432 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
433 |
int userId = userAccountRepository.selectUserIdByRetailerId(pendingOrder.getFofoId());
|
|
|
434 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 28397 |
tejbeer |
435 |
notificationService.sendNotification(sendNotificationModel);
|
| 28377 |
tejbeer |
436 |
|
| 28394 |
tejbeer |
437 |
SendNotificationModel snm = new SendNotificationModel();
|
|
|
438 |
snm.setCampaignName("Online Order Alert");
|
|
|
439 |
snm.setTitle("Online Order Update");
|
|
|
440 |
snm.setMessage(String.format("Your Partner " + customRetailer.getBusinessName()
|
| 28393 |
tejbeer |
441 |
+ " have new Online Order. Please inform your partner. In case of an activation scheme pls ensure the handset is activated, payout will be processed as per brand's activation report."));
|
| 28394 |
tejbeer |
442 |
snm.setType("url");
|
|
|
443 |
snm.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
444 |
snm.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
445 |
snm.setMessageType(MessageType.notification);
|
|
|
446 |
snm.setUserIds(userIds);
|
|
|
447 |
notificationService.sendNotification(snm);
|
| 28377 |
tejbeer |
448 |
|
| 28339 |
tejbeer |
449 |
}
|
| 27028 |
tejbeer |
450 |
return responseSender.ok(returnMap);
|
|
|
451 |
|
| 26648 |
amit.gupta |
452 |
}
|
| 26630 |
amit.gupta |
453 |
|
| 26857 |
amit.gupta |
454 |
@RequestMapping(value = "/store/address", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
455 |
@ApiImplicitParams({
|
|
|
456 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
457 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
458 |
public ResponseEntity<?> getAddress(HttpServletRequest request) throws Exception {
|
|
|
459 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
460 |
Integer storeId = userInfo.getRetailerId();
|
|
|
461 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
|
|
|
462 |
|
|
|
463 |
return responseSender.ok(customRetailer.getAddress());
|
|
|
464 |
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
@RequestMapping(value = "/store/address/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
468 |
@ApiImplicitParams({
|
|
|
469 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
470 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
471 |
public ResponseEntity<?> getStoresByPincode(HttpServletRequest request, @PathVariable String pincode)
|
|
|
472 |
throws Exception {
|
|
|
473 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
| 28321 |
amit.gupta |
474 |
int fofoId = ProfitMandiConstants.DEFAULT_STORE;
|
| 26857 |
amit.gupta |
475 |
if (pincodePartners.size() > 0) {
|
| 28287 |
amit.gupta |
476 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 28267 |
amit.gupta |
477 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActivePartnersByRetailerIds(fofoIds);
|
| 28287 |
amit.gupta |
478 |
if (fofoStores.size() > 0) {
|
| 28267 |
amit.gupta |
479 |
fofoId = fofoStores.get(0).getId();
|
|
|
480 |
}
|
| 28287 |
amit.gupta |
481 |
|
| 26857 |
amit.gupta |
482 |
}
|
|
|
483 |
return responseSender.ok(fofoStoreRepository.selectByRetailerId(fofoId).getCode());
|
|
|
484 |
}
|
| 26923 |
amit.gupta |
485 |
|
| 28566 |
tejbeer |
486 |
@RequestMapping(value = "/store/addresses", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
487 |
@ApiImplicitParams({
|
|
|
488 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
489 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
490 |
public ResponseEntity<?> getStoresByPincod(HttpServletRequest request, @RequestParam String pincode,
|
|
|
491 |
@RequestParam(name = "fofoCode", defaultValue = "", required = false) String fofoCode) throws Exception {
|
|
|
492 |
|
|
|
493 |
List<CustomRetailer> customerRetailers = new ArrayList<>();
|
|
|
494 |
|
|
|
495 |
logger.info("fofoCode" + fofoCode);
|
|
|
496 |
|
|
|
497 |
if (fofoCode != null) {
|
|
|
498 |
FofoStore fs = fofoStoreRepository.selectByStoreCode(fofoCode.toUpperCase());
|
|
|
499 |
PincodePartner pp = pincodePartnerRepository.selectPartnerByPincode(pincode, fs.getId());
|
|
|
500 |
if (pp != null) {
|
|
|
501 |
return responseSender.ok(customerRetailers.add(retailerService.getFofoRetailer(pp.getFofoId())));
|
|
|
502 |
} else {
|
|
|
503 |
|
|
|
504 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
505 |
if (pincodePartners.size() > 0) {
|
|
|
506 |
|
|
|
507 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId())
|
|
|
508 |
.collect(Collectors.toList());
|
|
|
509 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
|
|
510 |
.filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
|
|
511 |
|
| 30426 |
tejbeer |
512 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
513 |
|
|
|
514 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream()
|
|
|
515 |
.map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList())
|
|
|
516 |
.stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
517 |
|
| 28566 |
tejbeer |
518 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
519 |
|
|
|
520 |
}
|
|
|
521 |
return responseSender.ok(customerRetailers);
|
|
|
522 |
|
|
|
523 |
}
|
|
|
524 |
} else {
|
|
|
525 |
|
|
|
526 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
527 |
if (pincodePartners.size() > 0) {
|
|
|
528 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
529 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
|
|
530 |
.filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
|
|
531 |
|
| 30426 |
tejbeer |
532 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
533 |
|
|
|
534 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream()
|
|
|
535 |
.map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
536 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
537 |
|
| 28566 |
tejbeer |
538 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
return responseSender.ok(customerRetailers);
|
|
|
542 |
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
}
|
|
|
546 |
|
| 28298 |
tejbeer |
547 |
@RequestMapping(value = "/store/address/detail/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
548 |
@ApiImplicitParams({
|
|
|
549 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
550 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
551 |
public ResponseEntity<?> getStoresDetailsByPincode(HttpServletRequest request, @PathVariable String pincode)
|
|
|
552 |
throws Exception {
|
|
|
553 |
List<CustomRetailer> customerRetailers = new ArrayList<>();
|
|
|
554 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
555 |
|
|
|
556 |
if (!pincodePartners.isEmpty()) {
|
|
|
557 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
558 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
|
|
559 |
.filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
| 30426 |
tejbeer |
560 |
|
|
|
561 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
562 |
|
|
|
563 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
564 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
565 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
566 |
|
| 28298 |
tejbeer |
567 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
logger.info("customerRetailers" + customerRetailers);
|
|
|
571 |
return responseSender.ok(customerRetailers);
|
|
|
572 |
}
|
|
|
573 |
|
| 26855 |
tejbeer |
574 |
@RequestMapping(value = "/store/order", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
575 |
public ResponseEntity<?> getOrderDetail(HttpServletRequest request, @RequestParam(value = "id") int id,
|
| 27049 |
tejbeer |
576 |
@RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
|
| 26855 |
tejbeer |
577 |
List<CustomerOrderDetail> customerOrderDetails = new ArrayList<>();
|
| 27049 |
tejbeer |
578 |
List<Integer> catalogIds = new ArrayList<>();
|
| 26855 |
tejbeer |
579 |
List<PendingOrder> pendingOrders = pendingOrderRepository.selectByCustomerId(id, offset, limit);
|
| 28566 |
tejbeer |
580 |
|
| 26855 |
tejbeer |
581 |
if (!pendingOrders.isEmpty()) {
|
|
|
582 |
for (PendingOrder po : pendingOrders) {
|
|
|
583 |
List<PendingOrderItem> pois = pendingOrderItemRepository.selectByOrderId(po.getId());
|
| 27049 |
tejbeer |
584 |
for (PendingOrderItem pendingOrderItem : pois) {
|
|
|
585 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
586 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
587 |
catalogIds.add(item.getCatalogItemId());
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
591 |
|
| 26855 |
tejbeer |
592 |
for (PendingOrderItem poi : pois) {
|
|
|
593 |
|
|
|
594 |
CustomerOrderDetail customerOrderDetail = new CustomerOrderDetail();
|
|
|
595 |
|
|
|
596 |
Item item = itemRepository.selectById(poi.getItemId());
|
| 27049 |
tejbeer |
597 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
598 |
customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
|
| 26855 |
tejbeer |
599 |
customerOrderDetail.setBrand(item.getBrand());
|
|
|
600 |
customerOrderDetail.setColor(item.getColor());
|
| 27056 |
tejbeer |
601 |
customerOrderDetail.setPendingOrderItemId(poi.getId());
|
| 26855 |
tejbeer |
602 |
customerOrderDetail.setId(poi.getOrderId());
|
|
|
603 |
customerOrderDetail.setItemId(poi.getItemId());
|
|
|
604 |
customerOrderDetail.setModelName(item.getModelName());
|
|
|
605 |
customerOrderDetail.setModelNumber(item.getModelNumber());
|
|
|
606 |
customerOrderDetail.setQuantity(poi.getQuantity());
|
| 27045 |
tejbeer |
607 |
customerOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
|
|
|
608 |
customerOrderDetail.setStatus(poi.getStatus());
|
| 26855 |
tejbeer |
609 |
customerOrderDetail.setTotalPrice(poi.getSellingPrice());
|
|
|
610 |
customerOrderDetail.setPayMethod(po.getPayMethod());
|
| 26861 |
tejbeer |
611 |
customerOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
|
| 26855 |
tejbeer |
612 |
customerOrderDetails.add(customerOrderDetail);
|
|
|
613 |
}
|
|
|
614 |
}
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
return responseSender.ok(customerOrderDetails);
|
|
|
618 |
}
|
|
|
619 |
|
| 28566 |
tejbeer |
620 |
@RequestMapping(value = "/store/invoiceOrder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
621 |
public ResponseEntity<?> getOrderInvoiceDetail(HttpServletRequest request, @RequestParam(value = "id") int id,
|
|
|
622 |
@RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
|
|
|
623 |
List<CustomerOrderDetail> customerOrderDetails = new ArrayList<>();
|
|
|
624 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
625 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectOrderByCustomerId(id, offset, limit);
|
|
|
626 |
|
|
|
627 |
if (!fofoOrders.isEmpty()) {
|
|
|
628 |
for (FofoOrder fo : fofoOrders) {
|
|
|
629 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fo.getId());
|
|
|
630 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
|
|
631 |
Item item = itemRepository.selectById(fofoOrderItem.getItemId());
|
|
|
632 |
fofoOrderItem.setItemName(item.getItemDescription());
|
|
|
633 |
catalogIds.add(item.getCatalogItemId());
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
637 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
638 |
|
|
|
639 |
CustomerOrderDetail customerOrderDetail = new CustomerOrderDetail();
|
|
|
640 |
|
|
|
641 |
Item item = itemRepository.selectById(foi.getItemId());
|
|
|
642 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
643 |
customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
|
|
|
644 |
customerOrderDetail.setBrand(item.getBrand());
|
|
|
645 |
customerOrderDetail.setColor(item.getColor());
|
|
|
646 |
customerOrderDetail.setFofoOrderItemId(foi.getId());
|
|
|
647 |
customerOrderDetail.setFofoOrderId(foi.getOrderId());
|
|
|
648 |
customerOrderDetail.setItemId(foi.getItemId());
|
|
|
649 |
customerOrderDetail.setModelName(item.getModelName());
|
|
|
650 |
customerOrderDetail.setModelNumber(item.getModelNumber());
|
|
|
651 |
customerOrderDetail.setQuantity(foi.getQuantity());
|
|
|
652 |
customerOrderDetail.setTotalPrice(foi.getSellingPrice());
|
|
|
653 |
customerOrderDetail.setCreatedTimeStamp(foi.getCreateTimestamp());
|
|
|
654 |
customerOrderDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
|
|
655 |
customerOrderDetail.setCancelledTimestamp(fo.getCancelledTimestamp());
|
|
|
656 |
customerOrderDetails.add(customerOrderDetail);
|
|
|
657 |
}
|
|
|
658 |
}
|
|
|
659 |
|
|
|
660 |
}
|
|
|
661 |
return responseSender.ok(customerOrderDetails);
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
@RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET)
|
|
|
665 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request,
|
|
|
666 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
| 30330 |
tejbeer |
667 |
InvoicePdfModel pdfModel = null;
|
| 28566 |
tejbeer |
668 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
669 |
pdfModel = orderService.getInvoicePdfModel(fo.getFofoId(), orderId);
|
|
|
670 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
671 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
|
|
672 |
try {
|
|
|
673 |
byteArrayOutputStream.close();
|
|
|
674 |
} catch (IOException e) {
|
|
|
675 |
// TODO Auto-generated catch block
|
|
|
676 |
e.printStackTrace();
|
|
|
677 |
}
|
|
|
678 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
679 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
680 |
// headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
|
|
681 |
|
|
|
682 |
headers.setContentType(MediaType.parseMediaType("application/pdf"));
|
|
|
683 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
684 |
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
|
685 |
headers.add("Pragma", "no-cache");
|
|
|
686 |
headers.add("Expires", "0");
|
|
|
687 |
|
|
|
688 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
689 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
690 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
691 |
return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
692 |
// return responseSender.ok(new
|
|
|
693 |
// ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(),
|
|
|
694 |
// headers,HttpStatus.OK));
|
|
|
695 |
/*
|
|
|
696 |
* ResponseEntity<byte[]> response = new
|
|
|
697 |
* ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
|
|
|
698 |
* HttpStatus.OK); return response;
|
|
|
699 |
*/
|
|
|
700 |
|
|
|
701 |
}
|
|
|
702 |
|
| 26745 |
amit.gupta |
703 |
@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 26774 |
amit.gupta |
704 |
public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
|
| 31447 |
tejbeer |
705 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true),
|
| 31573 |
tejbeer |
706 |
WebListingSource.store);
|
| 28287 |
amit.gupta |
707 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 26745 |
amit.gupta |
708 |
for (WebListing webListing : webListings) {
|
| 28287 |
amit.gupta |
709 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
| 26745 |
amit.gupta |
710 |
}
|
|
|
711 |
return responseSender.ok(webListings);
|
|
|
712 |
}
|
|
|
713 |
|
| 28287 |
amit.gupta |
714 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing)
|
|
|
715 |
throws ProfitMandiBusinessException {
|
|
|
716 |
List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream()
|
|
|
717 |
.filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
|
|
|
718 |
if (webProducts.size() == 0) {
|
|
|
719 |
return new ArrayList<>();
|
|
|
720 |
}
|
|
|
721 |
RestClient rc = new RestClient();
|
|
|
722 |
Map<String, String> params = new HashMap<>();
|
|
|
723 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
724 |
mandatoryQ.add(String.format(
|
|
|
725 |
"+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} tagId_i:(%s)",
|
|
|
726 |
StringUtils.join(TAG_IDS, " ")));
|
|
|
727 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
728 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
729 |
// params.put("sort", "create_s desc");
|
|
|
730 |
params.put("start", String.valueOf(0));
|
|
|
731 |
params.put("rows", String.valueOf(100));
|
|
|
732 |
params.put("wt", "json");
|
|
|
733 |
String response = null;
|
|
|
734 |
try {
|
|
|
735 |
response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
|
|
|
736 |
} catch (HttpHostConnectException e) {
|
|
|
737 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
738 |
}
|
|
|
739 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
740 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
741 |
List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
742 |
return dealResponse;
|
|
|
743 |
}
|
|
|
744 |
|
| 26652 |
amit.gupta |
745 |
@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
746 |
@ApiImplicitParams({
|
| 26651 |
amit.gupta |
747 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 26652 |
amit.gupta |
748 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
749 |
public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest)
|
|
|
750 |
throws Exception {
|
| 26923 |
amit.gupta |
751 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
752 |
Integer storeId = userInfo.getRetailerId();
|
|
|
753 |
ValidateCartResponse vc = new ValidateCartResponse(this.validateCart(storeId, cartRequest.getCartItems()),
|
|
|
754 |
"Success", "Items added to cart successfully");
|
|
|
755 |
return responseSender.ok(vc);
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
// Validate Cart for B2C Customers
|
|
|
759 |
private CartResponse validateCart(int storeId, List<CartItem> cartItems) throws Exception {
|
|
|
760 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
|
|
761 |
List<Integer> itemIds = cartItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
|
|
762 |
Map<Integer, AvailabilityModel> inventoryItemAvailabilityMap = inventoryService.getStoreAndOurStock(storeId,
|
|
|
763 |
itemIds);
|
| 26607 |
amit.gupta |
764 |
CartResponse cartResponse = new CartResponse();
|
| 26612 |
amit.gupta |
765 |
List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
|
|
|
766 |
cartResponse.setCartItems(cartItemResponseModels);
|
| 26607 |
amit.gupta |
767 |
Set<Integer> itemsIdsSet = new HashSet<>(itemIds);
|
| 26668 |
amit.gupta |
768 |
logger.info("Store Id {}, Item Ids {}", storeId, itemsIdsSet);
|
| 26607 |
amit.gupta |
769 |
|
|
|
770 |
Map<Integer, Item> itemsMap = itemRepository.selectByIds(itemsIdsSet).stream()
|
|
|
771 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
772 |
|
| 26923 |
amit.gupta |
773 |
Map<Integer, TagListing> tagListingMap = tagListingRepository
|
| 26607 |
amit.gupta |
774 |
.selectByItemIdsAndTagIds(new HashSet<>(itemIds), new HashSet<>(Arrays.asList(4))).stream()
|
|
|
775 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
776 |
|
|
|
777 |
List<Integer> catalogIds = itemsMap.values().stream().map(x -> x.getCatalogItemId())
|
|
|
778 |
.collect(Collectors.toList());
|
|
|
779 |
|
|
|
780 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
781 |
|
|
|
782 |
// cartResponse.getCartItems()
|
| 26923 |
amit.gupta |
783 |
int cartMessageChanged = 0;
|
|
|
784 |
int cartMessageOOS = 0;
|
|
|
785 |
int totalAmount = 0;
|
|
|
786 |
int totalQty = 0;
|
|
|
787 |
for (CartItem cartItem : cartItems) {
|
| 26607 |
amit.gupta |
788 |
Item item = itemsMap.get(cartItem.getItemId());
|
| 26923 |
amit.gupta |
789 |
TagListing tagListing = tagListingMap.get(cartItem.getItemId());
|
| 30330 |
tejbeer |
790 |
Float cashback = schemeService.getCatalogSchemeCashBack()
|
|
|
791 |
.get(itemsMap.get(cartItem.getItemId()).getCatalogItemId());
|
| 26923 |
amit.gupta |
792 |
cashback = cashback == null ? 0 : cashback;
|
|
|
793 |
float itemSellingPrice = tagListing.getMop() - cashback;
|
| 26607 |
amit.gupta |
794 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
| 26923 |
amit.gupta |
795 |
cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
|
|
|
796 |
if (itemSellingPrice != cartItem.getSellingPrice()) {
|
|
|
797 |
cartItemResponseModel.setSellingPrice(itemSellingPrice);
|
|
|
798 |
cartMessageChanged++;
|
|
|
799 |
}
|
| 26628 |
amit.gupta |
800 |
int estimate = -2;
|
| 27025 |
tejbeer |
801 |
LocalDateTime promiseDeliveryTime = LocalDateTime.now();
|
| 26923 |
amit.gupta |
802 |
int qtyRequired = (int) cartItem.getQuantity();
|
|
|
803 |
AvailabilityModel availabilityModel = inventoryItemAvailabilityMap.get(cartItem.getItemId());
|
|
|
804 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
|
|
805 |
if (availabilityModel.getStoreAvailability() >= qtyRequired) {
|
|
|
806 |
estimate = 0;
|
|
|
807 |
} else if (availabilityModel.getWarehouseAvailability() >= qtyRequired) {
|
| 26628 |
amit.gupta |
808 |
estimate = 2;
|
| 26923 |
amit.gupta |
809 |
} else if (availabilityModel.getStoreAvailability() > 0) {
|
|
|
810 |
estimate = 0;
|
|
|
811 |
qtyRequired = availabilityModel.getStoreAvailability();
|
|
|
812 |
cartMessageChanged++;
|
|
|
813 |
} else if (availabilityModel.getWarehouseAvailability() > 0) {
|
|
|
814 |
qtyRequired = availabilityModel.getWarehouseAvailability();
|
|
|
815 |
estimate = 2;
|
|
|
816 |
cartMessageChanged++;
|
| 26620 |
amit.gupta |
817 |
} else {
|
| 26923 |
amit.gupta |
818 |
qtyRequired = 0;
|
| 26926 |
amit.gupta |
819 |
cartMessageChanged++;
|
| 26607 |
amit.gupta |
820 |
}
|
| 26923 |
amit.gupta |
821 |
cartItemResponseModel.setQuantity(qtyRequired);
|
| 26630 |
amit.gupta |
822 |
if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
|
| 26628 |
amit.gupta |
823 |
estimate = estimate + 1;
|
| 27025 |
tejbeer |
824 |
promiseDeliveryTime = promiseDeliveryTime.plusDays(3);
|
| 26628 |
amit.gupta |
825 |
}
|
| 26923 |
amit.gupta |
826 |
totalQty += qtyRequired;
|
|
|
827 |
totalAmount += qtyRequired * itemSellingPrice;
|
| 26628 |
amit.gupta |
828 |
cartItemResponseModel.setEstimate(estimate);
|
| 26616 |
amit.gupta |
829 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
| 26614 |
amit.gupta |
830 |
cartItemResponseModel.setItemId(cartItem.getItemId());
|
| 26615 |
amit.gupta |
831 |
cartItemResponseModel.setMinBuyQuantity(1);
|
| 26923 |
amit.gupta |
832 |
cartItemResponseModel.setQuantity(qtyRequired);
|
| 26621 |
amit.gupta |
833 |
cartItemResponseModel.setQuantityStep(1);
|
| 27025 |
tejbeer |
834 |
cartItemResponseModel.setPromiseDelivery(promiseDeliveryTime);
|
| 26923 |
amit.gupta |
835 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
| 26607 |
amit.gupta |
836 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
|
|
837 |
cartItemResponseModel.setImageUrl(contentMap.get(item.getCatalogItemId()).getString("imageUrl_s"));
|
|
|
838 |
cartItemResponseModel.setColor(item.getColor());
|
| 26620 |
amit.gupta |
839 |
cartItemResponseModels.add(cartItemResponseModel);
|
| 26607 |
amit.gupta |
840 |
}
|
| 26923 |
amit.gupta |
841 |
cartResponse.setCartItems(cartItemResponseModels);
|
|
|
842 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
|
|
843 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
|
|
844 |
int maxEstimate = cartItemResponseModels.stream().mapToInt(x -> x.getEstimate()).max().getAsInt();
|
|
|
845 |
cartResponse.setMaxEstimate(maxEstimate);
|
|
|
846 |
cartResponse.setTotalAmount(totalAmount);
|
|
|
847 |
cartResponse.setTotalQty(totalQty);
|
| 26652 |
amit.gupta |
848 |
|
| 26923 |
amit.gupta |
849 |
return cartResponse;
|
|
|
850 |
|
| 26648 |
amit.gupta |
851 |
}
|
| 26607 |
amit.gupta |
852 |
|
| 27030 |
amit.gupta |
853 |
@RequestMapping(value = "/store/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
854 |
public ResponseEntity<?> partnerStock(HttpServletRequest request,
|
|
|
855 |
@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
|
|
|
856 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
|
|
857 |
@RequestParam(value = "sort", required = false) String sort,
|
|
|
858 |
@RequestParam(value = "brand", required = false) String brand,
|
|
|
859 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
|
|
|
860 |
@RequestParam(value = "q", required = false) String queryTerm,
|
| 28287 |
amit.gupta |
861 |
@RequestParam(required = false) String listing,
|
|
|
862 |
@RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
|
| 27030 |
amit.gupta |
863 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
864 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 28269 |
amit.gupta |
865 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
866 |
sort = "w" + fs.getWarehouseId() + "_i desc";
|
| 27045 |
tejbeer |
867 |
dealResponse = this.getCatalogResponse(
|
| 28314 |
amit.gupta |
868 |
commonSolrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, false),
|
|
|
869 |
false, userInfo.getRetailerId());
|
| 27030 |
amit.gupta |
870 |
return responseSender.ok(dealResponse);
|
|
|
871 |
}
|
|
|
872 |
|
| 26909 |
amit.gupta |
873 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
|
| 26607 |
amit.gupta |
874 |
throws ProfitMandiBusinessException {
|
| 26909 |
amit.gupta |
875 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
|
|
876 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
| 26607 |
amit.gupta |
877 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
878 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
879 |
if (docs.length() > 0) {
|
|
|
880 |
HashSet<Integer> itemsSet = new HashSet<>();
|
|
|
881 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
882 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
883 |
if (doc.has("_childDocuments_")) {
|
|
|
884 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
885 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
886 |
int itemId = childItem.getInt("itemId_i");
|
|
|
887 |
itemsSet.add(itemId);
|
|
|
888 |
}
|
|
|
889 |
}
|
|
|
890 |
}
|
|
|
891 |
if (itemsSet.size() == 0) {
|
|
|
892 |
return dealResponse;
|
|
|
893 |
}
|
| 28269 |
amit.gupta |
894 |
if (fofoId > 0) {
|
| 26909 |
amit.gupta |
895 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
|
|
|
896 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
897 |
}
|
| 28287 |
amit.gupta |
898 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
| 26607 |
amit.gupta |
899 |
}
|
|
|
900 |
|
|
|
901 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
902 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
903 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
904 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
905 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
906 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
907 |
ffdr.setTitle(doc.getString("title_s"));
|
| 28374 |
amit.gupta |
908 |
List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(ffdr.getCatalogId());
|
| 28391 |
tejbeer |
909 |
if (webOffers != null && webOffers.size() > 0) {
|
| 28428 |
amit.gupta |
910 |
ffdr.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
| 28374 |
amit.gupta |
911 |
}
|
| 26607 |
amit.gupta |
912 |
try {
|
|
|
913 |
ffdr.setFeature(doc.getString("feature_s"));
|
|
|
914 |
} catch (Exception e) {
|
|
|
915 |
ffdr.setFeature(null);
|
|
|
916 |
}
|
|
|
917 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
|
|
918 |
if (doc.has("_childDocuments_")) {
|
|
|
919 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
920 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
921 |
int itemId = childItem.getInt("itemId_i");
|
|
|
922 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
923 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
924 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
925 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
926 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
927 |
}
|
|
|
928 |
} else {
|
|
|
929 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 26909 |
amit.gupta |
930 |
fdi.setSellingPrice(sellingPrice);
|
|
|
931 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
| 26607 |
amit.gupta |
932 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
933 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
934 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
935 |
fdi.setItem_id(itemId);
|
| 30123 |
amit.gupta |
936 |
Float cashBack = schemeService.getCatalogSchemeCashBack().get(ffdr.getCatalogId());
|
| 26909 |
amit.gupta |
937 |
cashBack = cashBack == null ? 0 : cashBack;
|
| 28391 |
tejbeer |
938 |
// TODO:Dont commit
|
|
|
939 |
// fdi.setCashback(Math.min(100, fdi.getMop()));
|
| 28405 |
amit.gupta |
940 |
fdi.setCashback(cashBack);
|
| 26673 |
amit.gupta |
941 |
fdi.setMinBuyQuantity(1);
|
| 28313 |
amit.gupta |
942 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0
|
|
|
943 |
: partnerStockAvailabilityMap.get(itemId);
|
| 28287 |
amit.gupta |
944 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0
|
|
|
945 |
: Math.max(0, ourItemAvailabilityMap.get(itemId));
|
| 28313 |
amit.gupta |
946 |
fdi.setActive(partnerAvailability > 0);
|
| 28467 |
tejbeer |
947 |
// fdi.setActive(true);
|
| 28287 |
amit.gupta |
948 |
fdi.setAvailability(Math.min(5, ourStockAvailability + partnerAvailability));
|
| 26607 |
amit.gupta |
949 |
fdi.setQuantityStep(1);
|
| 28269 |
amit.gupta |
950 |
fdi.setMaxQuantity(fdi.getAvailability());
|
| 26607 |
amit.gupta |
951 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
952 |
}
|
|
|
953 |
}
|
|
|
954 |
}
|
|
|
955 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| 28313 |
amit.gupta |
956 |
ffdr.setItems(fofoAvailabilityInfoMap.values().stream()
|
|
|
957 |
.sorted(Comparator.comparing(FofoAvailabilityInfo::isActive, Comparator.reverseOrder())
|
|
|
958 |
.thenComparingInt(y -> -y.getAvailability()))
|
|
|
959 |
.collect(Collectors.toList()));
|
| 26607 |
amit.gupta |
960 |
dealResponse.add(ffdr);
|
|
|
961 |
}
|
|
|
962 |
}
|
| 28314 |
amit.gupta |
963 |
return dealResponse.stream()
|
|
|
964 |
.sorted(Comparator
|
|
|
965 |
.comparing(FofoCatalogResponse::getItems,
|
|
|
966 |
(s1, s2) -> (s2.get(0).isActive() ? 1 : 0) - (s1.get(0).isActive() ? 1 : 0))
|
|
|
967 |
.thenComparing(FofoCatalogResponse::getItems,
|
|
|
968 |
(x, y) -> y.get(0).getAvailability() - x.get(0).getAvailability()))
|
|
|
969 |
.collect(Collectors.toList());
|
| 26607 |
amit.gupta |
970 |
}
|
| 26923 |
amit.gupta |
971 |
|
|
|
972 |
@GetMapping(value = "store/order-status/{pendingOrderId}")
|
| 27028 |
tejbeer |
973 |
public ResponseEntity<?> orderStatus(HttpServletRequest request, @PathVariable int pendingOrderId)
|
|
|
974 |
throws Exception {
|
| 26923 |
amit.gupta |
975 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderId);
|
|
|
976 |
List<PendingOrderItem> pendingOrderItems = pendingOrderItemRepository.selectByOrderId(pendingOrder.getId());
|
|
|
977 |
List<Integer> catalogIds = new ArrayList<>();
|
| 27028 |
tejbeer |
978 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
| 26923 |
amit.gupta |
979 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
980 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
981 |
catalogIds.add(item.getCatalogItemId());
|
|
|
982 |
}
|
|
|
983 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
| 27028 |
tejbeer |
984 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
| 26923 |
amit.gupta |
985 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
986 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
987 |
pendingOrderItem.setImgUrl(jsonObj.getString("imageUrl_s"));
|
|
|
988 |
}
|
|
|
989 |
pendingOrder.setPendingOrderItems(pendingOrderItems);
|
| 27069 |
tejbeer |
990 |
|
| 26923 |
amit.gupta |
991 |
return responseSender.ok(pendingOrder);
|
|
|
992 |
}
|
|
|
993 |
|
| 26833 |
amit.gupta |
994 |
@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
|
|
|
995 |
public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
|
| 27045 |
tejbeer |
996 |
return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
|
| 26788 |
amit.gupta |
997 |
}
|
| 26833 |
amit.gupta |
998 |
|
| 26857 |
amit.gupta |
999 |
@RequestMapping(value = "/store/address", method = RequestMethod.POST)
|
|
|
1000 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress)
|
|
|
1001 |
throws Throwable {
|
|
|
1002 |
customerAddressRepository.persist(customerAddress);
|
|
|
1003 |
return responseSender.ok(customerAddress);
|
|
|
1004 |
}
|
|
|
1005 |
|
| 27045 |
tejbeer |
1006 |
@RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
|
|
|
1007 |
public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
|
|
|
1008 |
CustomerAddress cust = customerAddressRepository.selectById(id);
|
|
|
1009 |
cust.setActive(false);
|
|
|
1010 |
return responseSender.ok(cust);
|
|
|
1011 |
}
|
|
|
1012 |
|
| 26861 |
tejbeer |
1013 |
@RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
|
|
|
1014 |
public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer)
|
|
|
1015 |
throws Throwable {
|
|
|
1016 |
Customer cust = customerRepository.selectById(customer.getId());
|
|
|
1017 |
cust.setGender(customer.getGender());
|
| 26867 |
tejbeer |
1018 |
cust.setProfileImageId(customer.getProfileImageId());
|
| 26861 |
tejbeer |
1019 |
cust.setDob(customer.getDob());
|
|
|
1020 |
return responseSender.ok(cust);
|
|
|
1021 |
}
|
| 28345 |
tejbeer |
1022 |
|
| 28322 |
amit.gupta |
1023 |
@RequestMapping(value = "/stores/{state}/{city}/{storeCode}", method = RequestMethod.GET)
|
| 28345 |
tejbeer |
1024 |
public void getStoreIndex(HttpServletResponse response, HttpServletRequest request, @PathVariable String state,
|
|
|
1025 |
@PathVariable String city, @PathVariable String storeCode) throws Throwable {
|
| 28325 |
amit.gupta |
1026 |
logger.info("Store code {}", storeCode);
|
| 28345 |
tejbeer |
1027 |
Map<String, Integer> map = retailerService.getStoreCodeRetailerMap();
|
|
|
1028 |
logger.info("retailer id {}", map.get(storeCode));
|
| 28336 |
amit.gupta |
1029 |
String retailerName = retailerService.getAllFofoRetailers().get(map.get(storeCode)).getBusinessName();
|
| 28322 |
amit.gupta |
1030 |
String html = partnerIndexService.getPartnerIndexHtml();
|
| 28332 |
amit.gupta |
1031 |
logger.info("html {}", html);
|
| 28327 |
amit.gupta |
1032 |
html = html.replace("Buy Mobiles and Accessories at exciting prices - SmartDukaan",
|
| 28338 |
amit.gupta |
1033 |
String.format("%s is now ONLINE. Buy Mobiles, Accessories & more | SmartDukaan", retailerName));
|
| 28334 |
amit.gupta |
1034 |
response.getWriter().write(html);
|
| 28322 |
amit.gupta |
1035 |
}
|
| 26861 |
tejbeer |
1036 |
|
| 27048 |
tejbeer |
1037 |
@RequestMapping(value = "/cancelPendingOrderItem", method = RequestMethod.POST)
|
|
|
1038 |
public ResponseEntity<?> cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id,
|
| 27045 |
tejbeer |
1039 |
|
| 28354 |
tejbeer |
1040 |
@RequestParam String statusDescription, @RequestParam String reason) throws Exception {
|
| 27048 |
tejbeer |
1041 |
|
|
|
1042 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
| 27057 |
tejbeer |
1043 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
| 28304 |
amit.gupta |
1044 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
| 27048 |
tejbeer |
1045 |
if (pendingOrderItem.getBilledTimestamp() == null) {
|
|
|
1046 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
| 28354 |
tejbeer |
1047 |
pendingOrderItem.setRemark(reason);
|
|
|
1048 |
pendingOrderItem.setStatusDescription("cancel by self");
|
| 28304 |
amit.gupta |
1049 |
pendingOrderItem.setCancelledTimestamp(LocalDateTime.now());
|
| 27048 |
tejbeer |
1050 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId())
|
|
|
1051 |
.stream().map(x -> x.getStatus()).collect(Collectors.toList());
|
|
|
1052 |
|
| 28345 |
tejbeer |
1053 |
if (!status.contains(OrderStatus.PENDING) && !status.contains(OrderStatus.PROCESSING)
|
|
|
1054 |
&& !status.contains(OrderStatus.BILLED) && !status.contains(OrderStatus.UNSETTLED)
|
|
|
1055 |
&& !status.contains(OrderStatus.CLAIMED)) {
|
| 27048 |
tejbeer |
1056 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
|
|
1057 |
}
|
|
|
1058 |
|
|
|
1059 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
| 28304 |
amit.gupta |
1060 |
String itemDescription = itemRepository.selectById(pendingOrderItem.getItemId()).getItemDescription();
|
| 28313 |
amit.gupta |
1061 |
otpProcessor.sendSms(OtpProcessor.SELF_CANCELLED_TEMPLATE_ID,
|
|
|
1062 |
String.format(OtpProcessor.SELF_CANCELLED_TEMPLATE, pendingOrder.getId(),
|
| 28304 |
amit.gupta |
1063 |
StringUtils.abbreviate(itemDescription, 30),
|
| 28313 |
amit.gupta |
1064 |
FormattingUtils.format(pendingOrderItem.getCancelledTimestamp())),
|
| 28304 |
amit.gupta |
1065 |
customer.getMobileNumber());
|
| 28339 |
tejbeer |
1066 |
|
|
|
1067 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
1068 |
|
|
|
1069 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
1070 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
1071 |
catalogIds.add(item.getCatalogItemId());
|
|
|
1072 |
|
|
|
1073 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
1074 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
1075 |
pendingOrderItem.setImgUrl(jsonObj.getString("imageUrl_s"));
|
|
|
1076 |
pendingOrder.setPendingOrderItems(Arrays.asList(pendingOrderItem));
|
|
|
1077 |
CustomerAddress customerAddress = customerAddressRepository.selectById(pendingOrder.getCustomerAddressId());
|
|
|
1078 |
|
|
|
1079 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy h:mm a");
|
|
|
1080 |
|
|
|
1081 |
Map<String, Object> emailModel = new HashMap<>();
|
|
|
1082 |
emailModel.put("customer", customerAddress);
|
|
|
1083 |
emailModel.put("pendingOrder", pendingOrder);
|
|
|
1084 |
emailModel.put("date", dateTimeFormatter);
|
|
|
1085 |
|
|
|
1086 |
String[] customerEmail = null;
|
|
|
1087 |
if (customer.getEmailId() != null) {
|
| 28355 |
tejbeer |
1088 |
customerEmail = new String[] { customer.getEmailId() };
|
| 28339 |
tejbeer |
1089 |
|
| 28355 |
tejbeer |
1090 |
List<String> bccTo = Arrays.asList("tejbeer.kaur@smartdukaan.com");
|
|
|
1091 |
|
| 28339 |
tejbeer |
1092 |
emailService.sendMailWithAttachments("Order Cancellation", "order-cancellation.vm", emailModel,
|
| 28355 |
tejbeer |
1093 |
customerEmail, null, bccTo.toArray(new String[0]));
|
| 28339 |
tejbeer |
1094 |
|
|
|
1095 |
}
|
| 27048 |
tejbeer |
1096 |
}
|
|
|
1097 |
|
|
|
1098 |
return responseSender.ok(true);
|
|
|
1099 |
|
|
|
1100 |
}
|
| 29515 |
tejbeer |
1101 |
|
|
|
1102 |
@RequestMapping(value = "/store/checkEligibilityStoreOffers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1103 |
public ResponseEntity<?> checkEligibilityStoreOffers(HttpServletRequest request, @RequestParam(value = "id") int id)
|
|
|
1104 |
throws Exception {
|
|
|
1105 |
|
|
|
1106 |
boolean eligibility = false;
|
|
|
1107 |
|
| 31444 |
tejbeer |
1108 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), 14, 0, 0);
|
| 29515 |
tejbeer |
1109 |
|
| 31444 |
tejbeer |
1110 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(id,
|
|
|
1111 |
startDate.toLocalDate());
|
|
|
1112 |
|
| 29515 |
tejbeer |
1113 |
if (!scratchOffers.isEmpty()) {
|
|
|
1114 |
eligibility = true;
|
|
|
1115 |
|
|
|
1116 |
} else {
|
|
|
1117 |
eligibility = false;
|
|
|
1118 |
}
|
|
|
1119 |
|
|
|
1120 |
return responseSender.ok(eligibility);
|
|
|
1121 |
}
|
|
|
1122 |
|
|
|
1123 |
@RequestMapping(value = "/store/ScratchOffers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1124 |
public ResponseEntity<?> scratchOffers(HttpServletRequest request, @RequestParam(value = "id") int id)
|
|
|
1125 |
throws Exception {
|
|
|
1126 |
|
| 31457 |
tejbeer |
1127 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), 14, 0, 0);
|
|
|
1128 |
|
|
|
1129 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(id,
|
|
|
1130 |
startDate.toLocalDate());
|
|
|
1131 |
|
|
|
1132 |
// List<ScratchOffer> scratchOffers =
|
|
|
1133 |
// scratchOfferRepository.selectBycCustomerId(id);
|
| 29515 |
tejbeer |
1134 |
for (ScratchOffer so : scratchOffers) {
|
| 31444 |
tejbeer |
1135 |
LocalDateTime endDate = LocalDateTime.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), 27, 21, 00);
|
| 29515 |
tejbeer |
1136 |
|
|
|
1137 |
if (so.getOfferName() != null) {
|
| 31444 |
tejbeer |
1138 |
so.setExpiredTimestamp(endDate);
|
| 29515 |
tejbeer |
1139 |
}
|
|
|
1140 |
if (LocalDateTime.now().isAfter(so.getUnlockedAt())) {
|
|
|
1141 |
so.setUnlocked(true);
|
|
|
1142 |
} else {
|
|
|
1143 |
so.setUnlocked(false);
|
|
|
1144 |
}
|
|
|
1145 |
}
|
|
|
1146 |
|
|
|
1147 |
return responseSender.ok(scratchOffers);
|
|
|
1148 |
}
|
|
|
1149 |
|
|
|
1150 |
@RequestMapping(value = "/store/ScratchedOffer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1151 |
public ResponseEntity<?> scratchedOffer(HttpServletRequest request, @RequestParam(value = "id") int id)
|
|
|
1152 |
throws Exception {
|
|
|
1153 |
|
|
|
1154 |
ScratchOffer scratchOffer = scratchOfferRepository.selectById(id);
|
|
|
1155 |
scratchOffer.setScratched(true);
|
|
|
1156 |
scratchOffer.setScracthedAt(LocalDateTime.now());
|
|
|
1157 |
|
|
|
1158 |
return responseSender.ok(true);
|
|
|
1159 |
}
|
|
|
1160 |
|
| 26607 |
amit.gupta |
1161 |
}
|