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