| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.File;
|
| - |
|
4 |
import java.io.FileInputStream;
|
| - |
|
5 |
import java.io.FileNotFoundException;
|
| 3 |
import java.text.DecimalFormat;
|
6 |
import java.text.DecimalFormat;
|
| 4 |
import java.time.LocalDate;
|
7 |
import java.time.LocalDate;
|
| 5 |
import java.time.LocalDateTime;
|
8 |
import java.time.LocalDateTime;
|
| 6 |
import java.time.LocalTime;
|
9 |
import java.time.LocalTime;
|
| 7 |
import java.time.ZoneOffset;
|
10 |
import java.time.ZoneOffset;
|
| Line 16... |
Line 19... |
| 16 |
|
19 |
|
| 17 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 18 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 19 |
import org.springframework.beans.factory.annotation.Autowired;
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 20 |
import org.springframework.beans.factory.annotation.Value;
|
23 |
import org.springframework.beans.factory.annotation.Value;
|
| - |
|
24 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
25 |
import org.springframework.http.HttpHeaders;
|
| - |
|
26 |
import org.springframework.http.HttpStatus;
|
| 21 |
import org.springframework.http.MediaType;
|
27 |
import org.springframework.http.MediaType;
|
| 22 |
import org.springframework.http.ResponseEntity;
|
28 |
import org.springframework.http.ResponseEntity;
|
| 23 |
import org.springframework.stereotype.Controller;
|
29 |
import org.springframework.stereotype.Controller;
|
| 24 |
import org.springframework.ui.Model;
|
30 |
import org.springframework.ui.Model;
|
| 25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 27 |
import org.springframework.web.bind.annotation.RequestParam;
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 28 |
|
34 |
|
| 29 |
import com.google.gson.Gson;
|
35 |
import com.google.gson.Gson;
|
| 30 |
import com.mongodb.DBObject;
|
36 |
import com.mongodb.DBObject;
|
| - |
|
37 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 32 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
39 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 33 |
import com.spice.profitmandi.common.model.Notification;
|
40 |
import com.spice.profitmandi.common.model.Notification;
|
| 34 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
41 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
42 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| - |
|
43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 36 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
44 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| - |
|
45 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 37 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
46 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| - |
|
47 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 38 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
48 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
49 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 40 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
50 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 41 |
import com.spice.profitmandi.dao.entity.fofo.HygieneData;
|
51 |
import com.spice.profitmandi.dao.entity.fofo.HygieneData;
|
| 42 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
52 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| Line 44... |
Line 54... |
| 44 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
54 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 45 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
55 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 46 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
56 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| 47 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
57 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 48 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
58 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| - |
|
59 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 49 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
60 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
61 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 51 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
62 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
63 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 53 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
64 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
| Line 90... |
Line 101... |
| 90 |
|
101 |
|
| 91 |
@Autowired
|
102 |
@Autowired
|
| 92 |
private CookiesProcessor cookiesProcessor;
|
103 |
private CookiesProcessor cookiesProcessor;
|
| 93 |
|
104 |
|
| 94 |
@Autowired
|
105 |
@Autowired
|
| - |
|
106 |
private ResponseSender<?> responseSender;
|
| - |
|
107 |
|
| - |
|
108 |
@Autowired
|
| 95 |
private ItemRepository itemRepository;
|
109 |
private ItemRepository itemRepository;
|
| 96 |
|
110 |
|
| 97 |
@Autowired
|
111 |
@Autowired
|
| 98 |
private TargetSlabService targetSlabService;
|
112 |
private TargetSlabService targetSlabService;
|
| 99 |
|
113 |
|
| Line 157... |
Line 171... |
| 157 |
|
171 |
|
| 158 |
@Autowired
|
172 |
@Autowired
|
| 159 |
private NotificationCampaignRepository notificationCampaignRepository;
|
173 |
private NotificationCampaignRepository notificationCampaignRepository;
|
| 160 |
|
174 |
|
| 161 |
@Autowired
|
175 |
@Autowired
|
| - |
|
176 |
private DocumentRepository documentRepository;
|
| - |
|
177 |
|
| - |
|
178 |
@Autowired
|
| 162 |
private Mongo mongoClient;
|
179 |
private Mongo mongoClient;
|
| 163 |
|
180 |
|
| 164 |
@Autowired
|
181 |
@Autowired
|
| 165 |
private Gson gson;
|
182 |
private Gson gson;
|
| 166 |
|
183 |
|
| Line 322... |
Line 339... |
| 322 |
LOGGER.info("hygieneData" + hygieneData);
|
339 |
LOGGER.info("hygieneData" + hygieneData);
|
| 323 |
int successHygieneData = hygieneData.stream().filter(x -> x.getHygieneRating() == true)
|
340 |
int successHygieneData = hygieneData.stream().filter(x -> x.getHygieneRating() == true)
|
| 324 |
.collect(Collectors.toList()).size();
|
341 |
.collect(Collectors.toList()).size();
|
| 325 |
int unsuccessfullHygieneData = hygieneData.stream().filter(x -> x.getHygieneRating() == false)
|
342 |
int unsuccessfullHygieneData = hygieneData.stream().filter(x -> x.getHygieneRating() == false)
|
| 326 |
.collect(Collectors.toList()).size();
|
343 |
.collect(Collectors.toList()).size();
|
| 327 |
|
344 |
|
| 328 |
model.addAttribute("successHygieneData", successHygieneData);
|
345 |
model.addAttribute("successHygieneData", successHygieneData);
|
| 329 |
model.addAttribute("fullHygieneData", successHygieneData + unsuccessfullHygieneData);
|
346 |
model.addAttribute("fullHygieneData", successHygieneData + unsuccessfullHygieneData);
|
| 330 |
|
347 |
|
| 331 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
348 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
| 332 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
349 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
| 333 |
return "dashboard1";
|
350 |
return "dashboard1";
|
| 334 |
}
|
351 |
}
|
| 335 |
|
352 |
|
| Line 355... |
Line 372... |
| 355 |
@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
|
372 |
@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
|
| 356 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
373 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 357 |
int userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
|
374 |
int userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
|
| 358 |
List<UserCampaign> userCampaigns = userCampaignRepository.selectByUserId(userId);
|
375 |
List<UserCampaign> userCampaigns = userCampaignRepository.selectByUserId(userId);
|
| 359 |
List<Notification> notifications = new ArrayList<>();
|
376 |
List<Notification> notifications = new ArrayList<>();
|
| - |
|
377 |
Document document = null;
|
| 360 |
if (!userCampaigns.isEmpty()) {
|
378 |
if (!userCampaigns.isEmpty()) {
|
| 361 |
List<Integer> campaignIds = new ArrayList<>();
|
379 |
List<Integer> campaignIds = new ArrayList<>();
|
| 362 |
for (UserCampaign userCampaign : userCampaigns) {
|
380 |
for (UserCampaign userCampaign : userCampaigns) {
|
| 363 |
campaignIds.add(userCampaign.getCampaignId());
|
381 |
campaignIds.add(userCampaign.getCampaignId());
|
| 364 |
}
|
382 |
}
|
| Line 373... |
Line 391... |
| 373 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
391 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
| 374 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
392 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
| 375 |
ns.setType(campaign.getType());
|
393 |
ns.setType(campaign.getType());
|
| 376 |
ns.setMessage(campaign.getMessage());
|
394 |
ns.setMessage(campaign.getMessage());
|
| 377 |
ns.setTitle(campaign.getTitle());
|
395 |
ns.setTitle(campaign.getTitle());
|
| - |
|
396 |
if (notificationCampaign.getDocumentId() != null) {
|
| - |
|
397 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
| - |
|
398 |
ns.setDocumentName(document.getDisplayName());
|
| - |
|
399 |
}
|
| 378 |
ns.setUrl(campaign.getUrl());
|
400 |
ns.setUrl(campaign.getUrl());
|
| 379 |
ns.setShowImage(campaign.getShowImage());
|
401 |
ns.setShowImage(campaign.getShowImage());
|
| 380 |
ns.setImageUrl(campaign.getImageUrl());
|
402 |
ns.setImageUrl(campaign.getImageUrl());
|
| - |
|
403 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
| 381 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
404 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
| 382 |
ns.setCreated(notificationCampaign.getCreatedTimestamp()
|
405 |
ns.setCreated(notificationCampaign.getCreatedTimestamp()
|
| 383 |
.toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
|
406 |
.toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
|
| 384 |
if (LocalDateTime.now().isAfter(expire)) {
|
407 |
if (LocalDateTime.now().isAfter(expire)) {
|
| 385 |
ns.setExpired(true);
|
408 |
ns.setExpired(true);
|
| Line 400... |
Line 423... |
| 400 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
423 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
| 401 |
ns.setType(campaign.getType());
|
424 |
ns.setType(campaign.getType());
|
| 402 |
ns.setMessage(campaign.getMessage());
|
425 |
ns.setMessage(campaign.getMessage());
|
| 403 |
ns.setTitle(campaign.getTitle());
|
426 |
ns.setTitle(campaign.getTitle());
|
| 404 |
ns.setUrl(campaign.getUrl());
|
427 |
ns.setUrl(campaign.getUrl());
|
| - |
|
428 |
if (notificationCampaign.getDocumentId() != null) {
|
| - |
|
429 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
| - |
|
430 |
ns.setDocumentName(document.getDisplayName());
|
| - |
|
431 |
}
|
| 405 |
ns.setShowImage(campaign.getShowImage());
|
432 |
ns.setShowImage(campaign.getShowImage());
|
| 406 |
ns.setImageUrl(campaign.getImageUrl());
|
433 |
ns.setImageUrl(campaign.getImageUrl());
|
| - |
|
434 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
| 407 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
435 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
| 408 |
ns.setCreated(notificationCampaign.getCreatedTimestamp()
|
436 |
ns.setCreated(notificationCampaign.getCreatedTimestamp()
|
| 409 |
.toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
|
437 |
.toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30)) * 1000);
|
| 410 |
if (LocalDateTime.now().isAfter(expire)) {
|
438 |
if (LocalDateTime.now().isAfter(expire)) {
|
| 411 |
ns.setExpired(true);
|
439 |
ns.setExpired(true);
|
| Line 425... |
Line 453... |
| 425 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
453 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
| 426 |
ns.setType(campaign.getType());
|
454 |
ns.setType(campaign.getType());
|
| 427 |
ns.setMessage(campaign.getMessage());
|
455 |
ns.setMessage(campaign.getMessage());
|
| 428 |
ns.setTitle(campaign.getTitle());
|
456 |
ns.setTitle(campaign.getTitle());
|
| 429 |
ns.setUrl(campaign.getUrl());
|
457 |
ns.setUrl(campaign.getUrl());
|
| - |
|
458 |
if (notificationCampaign.getDocumentId() != null) {
|
| - |
|
459 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
| - |
|
460 |
ns.setDocumentName(document.getDisplayName());
|
| - |
|
461 |
}
|
| - |
|
462 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
| 430 |
ns.setShowImage(campaign.getShowImage());
|
463 |
ns.setShowImage(campaign.getShowImage());
|
| 431 |
ns.setImageUrl(campaign.getImageUrl());
|
464 |
ns.setImageUrl(campaign.getImageUrl());
|
| 432 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
465 |
ns.setAnnoucement(notificationCampaign.isAnnoucement());
|
| 433 |
ns.setCreated(
|
466 |
ns.setCreated(
|
| 434 |
notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
467 |
notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
| Line 440... |
Line 473... |
| 440 |
}
|
473 |
}
|
| 441 |
notifications.add(ns);
|
474 |
notifications.add(ns);
|
| 442 |
}
|
475 |
}
|
| 443 |
}
|
476 |
}
|
| 444 |
}
|
477 |
}
|
| 445 |
|
478 |
|
| 446 |
model.addAttribute("notifications", notifications);
|
479 |
model.addAttribute("notifications", notifications);
|
| - |
|
480 |
return "notification-template";
|
| - |
|
481 |
}
|
| - |
|
482 |
|
| - |
|
483 |
@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
|
| - |
|
484 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
|
| - |
|
485 |
@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
|
| - |
|
486 |
throws ProfitMandiBusinessException {
|
| - |
|
487 |
Document document = documentRepository.selectById(documentId);
|
| - |
|
488 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
| - |
|
489 |
if (nc.getDocumentId() == null) {
|
| - |
|
490 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
| - |
|
491 |
}
|
| - |
|
492 |
if (nc.getDocumentId() != documentId) {
|
| - |
|
493 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
| - |
|
494 |
}
|
| - |
|
495 |
return responseSender.ok(document);
|
| - |
|
496 |
}
|
| - |
|
497 |
|
| - |
|
498 |
@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
|
| - |
|
499 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
|
| - |
|
500 |
throws ProfitMandiBusinessException {
|
| - |
|
501 |
|
| - |
|
502 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
| - |
|
503 |
|
| - |
|
504 |
if (nc.getDocumentId() == null) {
|
| - |
|
505 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
| - |
|
506 |
}
|
| - |
|
507 |
|
| - |
|
508 |
Document document = documentRepository.selectById(nc.getDocumentId());
|
| - |
|
509 |
|
| - |
|
510 |
FileInputStream file = null;
|
| - |
|
511 |
try {
|
| - |
|
512 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
| - |
|
513 |
} catch (FileNotFoundException e) {
|
| - |
|
514 |
LOGGER.error("Retailer Document file not found : ", e);
|
| - |
|
515 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
| - |
|
516 |
}
|
| - |
|
517 |
// ByteArrayOutputStream byteArrayOutputStream = new
|
| - |
|
518 |
// ByteArrayOutputStream();
|
| - |
|
519 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| - |
|
520 |
|
| - |
|
521 |
final HttpHeaders headers = new HttpHeaders();
|
| - |
|
522 |
String contentType = "";
|
| - |
|
523 |
if (document.getContentType() == ContentType.JPEG) {
|
| - |
|
524 |
contentType = "image/jpeg";
|
| - |
|
525 |
} else if (document.getContentType() == ContentType.PNG) {
|
| - |
|
526 |
contentType = "image/png";
|
| - |
|
527 |
} else if (document.getContentType() == ContentType.PDF) {
|
| - |
|
528 |
contentType = "application/pdf";
|
| - |
|
529 |
}
|
| - |
|
530 |
headers.set("Content-Type", contentType);
|
| - |
|
531 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
| - |
|
532 |
headers.setContentLength(document.getSize());
|
| - |
|
533 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
| - |
|
534 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 447 |
|
535 |
|
| 448 |
LOGGER.info("notifications"+notifications);
|
536 |
// return
|
| 449 |
return "notification-template" ;
|
537 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 450 |
}
|
538 |
}
|
| 451 |
|
539 |
|
| 452 |
}
|
540 |
}
|