Subversion Repositories SmartDukaan

Rev

Rev 31732 | Rev 31756 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31732 amit.gupta 1
package com.smartdukaan.cron.scheduled.b2b;
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.dao.entity.catalog.Item;
5
import com.spice.profitmandi.dao.entity.dtr.WebListing;
6
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
7
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
8
import com.spice.profitmandi.dao.repository.catalog.*;
9
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
10
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
11
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
12
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
13
import com.spice.profitmandi.dao.service.solr.FofoSolr;
14
import in.shop2020.model.v1.order.OrderStatus;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.scheduling.annotation.Scheduled;
19
import org.springframework.stereotype.Component;
31754 tejbeer 20
import org.springframework.transaction.annotation.Transactional;
31732 amit.gupta 21
 
22
import java.time.LocalDate;
23
import java.time.LocalDateTime;
24
import java.util.*;
25
import java.util.stream.Collectors;
26
 
27
@Component
31754 tejbeer 28
@Transactional(rollbackFor = Throwable.class)
31732 amit.gupta 29
public class Listing {
30
    @Autowired
31
    private WebListingRepository webListingRepository;
32
 
33
    @Autowired
34
    private FofoSolr fofoSolr;
35
 
36
    @Autowired
37
    OrderRepository orderRepository;
38
 
39
    @Autowired
40
    ItemRepository itemRepository;
41
 
42
    @Autowired
43
    PriceDropRepository priceDropRepository;
44
 
45
    @Autowired
46
    CustomerOfferRepository customerOfferRepository;
47
 
48
    @Autowired
49
    CustomerOfferItemRepository customerOfferItemRepository;
50
 
51
    @Autowired
52
    SchemeRepository schemeRepository;
53
 
54
    @Autowired
55
    TagListingRepository tagListingRepository;
56
 
57
 
58
    private static final Logger LOGGER = LogManager.getLogger(Listing.class);
59
 
60
    @Autowired
61
    private WebProductListingRepository webProductListingRepository;
62
 
63
 
64
    public void pushDataToSolr() throws Exception {
65
        fofoSolr.pushData();
66
    }
67
 
68
    public void getBestSeller() throws ProfitMandiBusinessException {
69
        WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");
70
 
31754 tejbeer 71
        List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());
31732 amit.gupta 72
 
31754 tejbeer 73
        List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30), LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
31732 amit.gupta 74
 
75
        LOGGER.info("catalogItemIds {}", catalogItemIds);
76
        if (!catalogItemIds.isEmpty()) {
77
            webProductListingRepository.deleteByEqual(webListing.getId());
78
            int count = 0;
79
            for (Integer catalogItemId : catalogItemIds) {
80
 
81
                WebProductListing webProductListing = new WebProductListing();
82
                webProductListing.setEntityId(catalogItemId);
83
                webProductListing.setWebListingId(webListing.getId());
84
                count = count + 1;
85
 
86
                webProductListing.setRank(count + 1);
87
                webProductListingRepository.persist(webProductListing);
88
 
89
            }
90
 
91
        }
92
    }
93
 
94
    public void getPriceDrop() throws ProfitMandiBusinessException {
95
        WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
96
 
31754 tejbeer 97
        List<WebProductListing> webProductListings = webProductListingRepository.selectAllByWebListingId(webListing.getId());
31732 amit.gupta 98
 
31754 tejbeer 99
        Set<Integer> catalogItemIds = priceDropRepository.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream().filter(x -> x.getAmount() > 0).map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
31732 amit.gupta 100
 
101
        LOGGER.info("catalogItemIds {}", catalogItemIds);
102
        if (!catalogItemIds.isEmpty()) {
103
            webProductListingRepository.deleteByEqual(webListing.getId());
104
            int count = 0;
105
            for (Integer catalogItemId : catalogItemIds) {
106
 
107
                WebProductListing webProductListing = new WebProductListing();
108
                webProductListing.setEntityId(catalogItemId);
109
                webProductListing.setWebListingId(webListing.getId());
110
                count = count + 1;
111
                webProductListing.setRank(count);
112
                webProductListingRepository.persist(webProductListing);
113
 
114
            }
115
 
116
        }
117
    }
118
 
119
    public void getNewLaunches() throws ProfitMandiBusinessException {
120
        WebListing webListing = webListingRepository.selectByUrl("new-launches");
121
 
31754 tejbeer 122
        List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));
31732 amit.gupta 123
 
124
        if (!catalogItemIds.isEmpty()) {
125
            webProductListingRepository.deleteByEqual(webListing.getId());
126
            int count = 0;
127
            for (Integer catalogItemId : catalogItemIds) {
128
 
129
                WebProductListing webProductListing = new WebProductListing();
130
                webProductListing.setEntityId(catalogItemId);
131
                webProductListing.setWebListingId(webListing.getId());
132
                count = count + 1;
133
                webProductListing.setRank(count);
134
                webProductListingRepository.persist(webProductListing);
135
 
136
            }
137
 
138
        }
139
    }
140
 
141
    public void getSpecialSupport() throws ProfitMandiBusinessException {
142
        WebListing webListing = webListingRepository.selectByUrl("special-support");
143
 
31754 tejbeer 144
        List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));
31732 amit.gupta 145
 
146
        LOGGER.info("catalogItemIds {}", catalogItemIds);
147
        if (!catalogItemIds.isEmpty()) {
148
            webProductListingRepository.deleteByEqual(webListing.getId());
149
            int count = 0;
150
            for (Integer catalogItemId : catalogItemIds) {
151
 
152
                WebProductListing webProductListing = new WebProductListing();
153
                webProductListing.setEntityId(catalogItemId);
154
                webProductListing.setWebListingId(webListing.getId());
155
                count = count + 1;
156
                webProductListing.setRank(count);
157
                webProductListingRepository.persist(webProductListing);
158
 
159
            }
160
 
161
        }
162
    }
163
 
164
    public void getUpgradeOffer() throws ProfitMandiBusinessException {
165
        WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
166
        webProductListingRepository.deleteByEqual(webListing.getId());
167
 
31754 tejbeer 168
        List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream().map(x -> x.getId()).collect(Collectors.toList());
31732 amit.gupta 169
 
31754 tejbeer 170
        List<Integer> catalogItemIds = customerOfferItemRepository.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct().collect(Collectors.toList());
31732 amit.gupta 171
 
172
        LOGGER.info("catalogItemIds {}", catalogItemIds);
173
        if (!catalogItemIds.isEmpty()) {
174
            int count = 0;
175
            for (Integer catalogItemId : catalogItemIds) {
176
 
177
                WebProductListing webProductListing = new WebProductListing();
178
                webProductListing.setEntityId(catalogItemId);
179
                webProductListing.setWebListingId(webListing.getId());
180
                count = count + 1;
181
                webProductListing.setRank(count);
182
                webProductListingRepository.persist(webProductListing);
183
 
184
            }
185
 
186
        }
187
    }
188
 
189
    @Scheduled(cron = "0 */30 * * * *")
190
    public void scheduledPushDataToSolr() throws Throwable {
191
        this.pushDataToSolr();
192
    }
193
 
194
    @Scheduled(cron = "0 0 8 * * *")
195
    public void scheduledGetBestSeller() throws Throwable {
196
        this.getBestSeller();
197
    }
198
 
199
    @Scheduled(cron = "0 0 8 * * *")
200
    public void scheduledGetPriceDrop() throws Throwable {
201
        this.getPriceDrop();
202
    }
203
 
204
    @Scheduled(cron = "0 0 8 * * *")
205
    public void scheduledGetNewLaunches() throws Throwable {
206
        this.getNewLaunches();
207
    }
208
 
209
    @Scheduled(cron = "0 0 8 * * *")
210
    public void scheduledGetSpecialSupport() throws Throwable {
211
        this.getSpecialSupport();
212
    }
213
 
214
    @Scheduled(cron = "0 0 8 * * *")
215
    public void scheduledGetUpgradeOffer() throws Throwable {
216
        this.getUpgradeOffer();
217
    }
218
}
219