Subversion Repositories SmartDukaan

Rev

Rev 35458 | Rev 35505 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35458 Rev 35501
Line 6... Line 6...
6
import com.spice.profitmandi.common.model.CustomRetailer;
6
import com.spice.profitmandi.common.model.CustomRetailer;
7
import com.spice.profitmandi.common.model.ProfitMandiConstants;
7
import com.spice.profitmandi.common.model.ProfitMandiConstants;
8
import com.spice.profitmandi.common.model.SendNotificationModel;
8
import com.spice.profitmandi.common.model.SendNotificationModel;
9
import com.spice.profitmandi.common.util.FormattingUtils;
9
import com.spice.profitmandi.common.util.FormattingUtils;
10
import com.spice.profitmandi.common.web.util.ResponseSender;
10
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
11
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
11
import com.spice.profitmandi.dao.entity.catalog.Offer;
12
import com.spice.profitmandi.dao.entity.catalog.Offer;
-
 
13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
12
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
14
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
13
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
15
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
14
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
16
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
15
import com.spice.profitmandi.dao.model.CreateOfferRequest;
17
import com.spice.profitmandi.dao.model.CreateOfferRequest;
16
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
18
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
-
 
19
import com.spice.profitmandi.dao.model.TodayOfferModel;
17
import com.spice.profitmandi.dao.repository.catalog.*;
20
import com.spice.profitmandi.dao.repository.catalog.*;
18
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
21
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
19
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
22
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
20
import com.spice.profitmandi.service.NotificationService;
23
import com.spice.profitmandi.service.NotificationService;
21
import com.spice.profitmandi.service.authentication.RoleManager;
24
import com.spice.profitmandi.service.authentication.RoleManager;
22
import com.spice.profitmandi.service.catalog.BrandsService;
25
import com.spice.profitmandi.service.catalog.BrandsService;
23
import com.spice.profitmandi.service.offers.ItemCriteria;
26
import com.spice.profitmandi.service.offers.ItemCriteria;
24
import com.spice.profitmandi.service.offers.OfferService;
27
import com.spice.profitmandi.service.offers.OfferService;
-
 
28
import com.spice.profitmandi.service.offers.TodayOfferService;
25
import com.spice.profitmandi.service.user.RetailerService;
29
import com.spice.profitmandi.service.user.RetailerService;
26
import com.spice.profitmandi.web.model.LoginDetails;
30
import com.spice.profitmandi.web.model.LoginDetails;
27
import com.spice.profitmandi.web.util.CookiesProcessor;
31
import com.spice.profitmandi.web.util.CookiesProcessor;
28
import com.spice.profitmandi.web.util.MVCResponseSender;
32
import com.spice.profitmandi.web.util.MVCResponseSender;
29
import org.apache.commons.io.FileUtils;
33
import org.apache.commons.io.FileUtils;
Line 38... Line 42...
38
import org.springframework.http.HttpStatus;
42
import org.springframework.http.HttpStatus;
39
import org.springframework.http.ResponseEntity;
43
import org.springframework.http.ResponseEntity;
40
import org.springframework.mock.web.MockHttpServletRequest;
44
import org.springframework.mock.web.MockHttpServletRequest;
41
import org.springframework.mock.web.MockHttpServletResponse;
45
import org.springframework.mock.web.MockHttpServletResponse;
42
import org.springframework.stereotype.Controller;
46
import org.springframework.stereotype.Controller;
-
 
47
import org.springframework.transaction.annotation.Transactional;
43
import org.springframework.ui.Model;
48
import org.springframework.ui.Model;
44
import org.springframework.web.bind.annotation.*;
49
import org.springframework.web.bind.annotation.*;
45
import org.springframework.web.multipart.MultipartFile;
50
import org.springframework.web.multipart.MultipartFile;
46
import org.springframework.web.servlet.View;
51
import org.springframework.web.servlet.View;
47
import org.springframework.web.servlet.ViewResolver;
52
import org.springframework.web.servlet.ViewResolver;
48
import org.xhtmlrenderer.swing.Java2DRenderer;
53
import org.xhtmlrenderer.swing.Java2DRenderer;
49
 
54
 
50
import javax.imageio.ImageIO;
55
import javax.imageio.ImageIO;
51
import javax.servlet.http.HttpServletRequest;
56
import javax.servlet.http.HttpServletRequest;
52
import org.springframework.transaction.annotation.Transactional;
-
 
53
import java.awt.*;
57
import java.awt.*;
54
import java.awt.image.BufferedImage;
58
import java.awt.image.BufferedImage;
55
import java.io.ByteArrayInputStream;
59
import java.io.ByteArrayInputStream;
56
import java.io.File;
60
import java.io.File;
57
import java.io.FileNotFoundException;
61
import java.io.FileNotFoundException;
58
import java.io.InputStream;
62
import java.io.InputStream;
59
import java.time.Instant;
63
import java.time.Instant;
60
import java.time.LocalDate;
64
import java.time.LocalDate;
61
import java.time.LocalDateTime;
65
import java.time.LocalDateTime;
62
import java.time.YearMonth;
66
import java.time.YearMonth;
63
import java.util.*;
-
 
64
import java.util.List;
67
import java.util.List;
-
 
68
import java.util.*;
65
import java.util.stream.Collectors;
69
import java.util.stream.Collectors;
66
 
70
 
67
@Controller
71
@Controller
68
@Transactional(rollbackFor = Throwable.class)
72
@Transactional(rollbackFor = Throwable.class)
69
public class OfferController {
73
public class OfferController {
Line 105... Line 109...
105
    BrandsService brandsService;
109
    BrandsService brandsService;
106
 
110
 
107
    @Autowired
111
    @Autowired
108
    private CatalogRepository catalogRepository;
112
    private CatalogRepository catalogRepository;
109
 
113
 
-
 
114
    @Autowired
-
 
115
    TodayOfferService todayOfferService;
-
 
116
 
110
    @RequestMapping(value = "/getCreateOffer", method = RequestMethod.GET)
117
    @RequestMapping(value = "/getCreateOffer", method = RequestMethod.GET)
111
    public String getCreateOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
118
    public String getCreateOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
112
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
119
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
113
        List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
120
        List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
114
                .collect(Collectors.toList());
121
                .collect(Collectors.toList());
Line 455... Line 462...
455
 
462
 
456
        return "offer_margin_detail_partner";
463
        return "offer_margin_detail_partner";
457
 
464
 
458
    }
465
    }
459
 
466
 
-
 
467
    @RequestMapping(value = "/todayOffer")
-
 
468
    public String todayOffer(HttpServletRequest request, Model model, @RequestParam(name = "fofoId", defaultValue = "0") int fofoId) throws ProfitMandiBusinessException {
-
 
469
 
-
 
470
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
471
        if (fofoId == 0) {
-
 
472
            fofoId = loginDetails.getFofoId();
-
 
473
        }
-
 
474
        List<BrandCatalog> allBrands = brandsService.getBrandsToDisplay(3);
-
 
475
 
-
 
476
        // 1. IDs to exclude entirely
-
 
477
        List<Integer> excludedIds = Arrays.asList(132, 133, 28, 17, 125);
-
 
478
 
-
 
479
        // 2. Brands that must come first (in this specific order)
-
 
480
        List<String> priorityOrder = Arrays.asList("Samsung", "Oppo", "Vivo", "Xiaomi", "Realme");
-
 
481
 
-
 
482
        List<BrandCatalog> sortedBrands = allBrands.stream()
-
 
483
                .filter(brand -> !excludedIds.contains(brand.getId())) // Remove excluded
-
 
484
                .sorted((b1, b2) -> {
-
 
485
                    // Get the index of the brand name in our priority list
-
 
486
                    int index1 = priorityOrder.indexOf(b1.getName());
-
 
487
                    int index2 = priorityOrder.indexOf(b2.getName());
-
 
488
 
-
 
489
                    // If brand is NOT in priority list, give it a high index (move to bottom)
-
 
490
                    int p1 = (index1 != -1) ? index1 : Integer.MAX_VALUE;
-
 
491
                    int p2 = (index2 != -1) ? index2 : Integer.MAX_VALUE;
-
 
492
 
-
 
493
                    if (p1 != p2) {
-
 
494
                        return Integer.compare(p1, p2); // Sort by priority first
-
 
495
                    }
-
 
496
 
-
 
497
                    // If both are "Others", sort them alphabetically
-
 
498
                    return b1.getName().compareToIgnoreCase(b2.getName());
-
 
499
                })
-
 
500
                .collect(Collectors.toList());
-
 
501
 
-
 
502
        model.addAttribute("brands", sortedBrands);
-
 
503
        model.addAttribute("fofoId", fofoId);
-
 
504
        model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
-
 
505
 
-
 
506
        return "today-offer";
-
 
507
    }
-
 
508
 
-
 
509
    @RequestMapping(value = "/todayOfferList")
-
 
510
    public String todayOfferList(HttpServletRequest request, Model model, @RequestParam String brand, @RequestParam(defaultValue = "0", required = false) int fofoId) throws ProfitMandiBusinessException {
-
 
511
 
-
 
512
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
513
        if (fofoId == 0) {
-
 
514
            fofoId = loginDetails.getFofoId();
-
 
515
        }
-
 
516
        FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
517
 
-
 
518
        List<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toList());
-
 
519
 
-
 
520
        List<TodayOfferModel> todayOfferModels = todayOfferService.findAllTodayOffer(brand, fofoId);
-
 
521
 
-
 
522
        List<TodayOfferModel> groupedOffers = todayOfferService.groupSameOffers(todayOfferModels);
-
 
523
        model.addAttribute("brands", brands);
-
 
524
        model.addAttribute("todayOfferModels", todayOfferModels);
-
 
525
        model.addAttribute("groupedOffers", groupedOffers);
-
 
526
 
-
 
527
 
-
 
528
        return "today-offer-list";
-
 
529
    }
-
 
530
 
-
 
531
 
-
 
532
    @RequestMapping(value = "/todayFofoOffer")
-
 
533
    public String todayFofoOffer(HttpServletRequest request, Model model, @RequestParam(name = "fofoId", defaultValue = "0") int fofoId) throws ProfitMandiBusinessException {
-
 
534
 
-
 
535
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
536
        if (fofoId == 0) {
-
 
537
            fofoId = loginDetails.getFofoId();
-
 
538
        }
-
 
539
        List<BrandCatalog> allBrands = brandsService.getBrandsToDisplay(3);
-
 
540
 
-
 
541
        // 1. IDs to exclude entirely
-
 
542
        List<Integer> excludedIds = Arrays.asList(132, 133, 28, 17, 125);
-
 
543
 
-
 
544
        // 2. Brands that must come first (in this specific order)
-
 
545
        List<String> priorityOrder = Arrays.asList("Samsung", "Oppo", "Vivo", "Xiaomi", "Realme");
-
 
546
 
-
 
547
        List<BrandCatalog> sortedBrands = allBrands.stream()
-
 
548
                .filter(brand -> !excludedIds.contains(brand.getId())) // Remove excluded
-
 
549
                .sorted((b1, b2) -> {
-
 
550
                    // Get the index of the brand name in our priority list
-
 
551
                    int index1 = priorityOrder.indexOf(b1.getName());
-
 
552
                    int index2 = priorityOrder.indexOf(b2.getName());
-
 
553
 
-
 
554
                    // If brand is NOT in priority list, give it a high index (move to bottom)
-
 
555
                    int p1 = (index1 != -1) ? index1 : Integer.MAX_VALUE;
-
 
556
                    int p2 = (index2 != -1) ? index2 : Integer.MAX_VALUE;
-
 
557
 
-
 
558
                    if (p1 != p2) {
-
 
559
                        return Integer.compare(p1, p2); // Sort by priority first
-
 
560
                    }
-
 
561
 
-
 
562
                    // If both are "Others", sort them alphabetically
-
 
563
                    return b1.getName().compareToIgnoreCase(b2.getName());
-
 
564
                })
-
 
565
                .collect(Collectors.toList());
-
 
566
 
-
 
567
        model.addAttribute("brands", sortedBrands);
-
 
568
        model.addAttribute("fofoId", fofoId);
-
 
569
        model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
-
 
570
 
-
 
571
        return "today-fofo-offer";
-
 
572
    }
-
 
573
 
460
}
574
}
461
575