Subversion Repositories SmartDukaan

Rev

Rev 34554 | 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
        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 98
 
99
        LOGGER.info("catalogItemIds {}", catalogItemIds);
100
        if (!catalogItemIds.isEmpty()) {
101
            webProductListingRepository.deleteByEqual(webListing.getId());
102
            int count = 0;
103
            for (Integer catalogItemId : catalogItemIds) {
104
 
105
                WebProductListing webProductListing = new WebProductListing();
106
                webProductListing.setEntityId(catalogItemId);
107
                webProductListing.setWebListingId(webListing.getId());
108
                count = count + 1;
109
                webProductListing.setRank(count);
110
                webProductListingRepository.persist(webProductListing);
111
 
112
            }
113
 
114
        }
115
    }
116
 
117
    public void getNewLaunches() throws ProfitMandiBusinessException {
118
        WebListing webListing = webListingRepository.selectByUrl("new-launches");
119
 
31754 tejbeer 120
        List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30), LocalDate.now().plusDays(1));
31732 amit.gupta 121
 
122
        if (!catalogItemIds.isEmpty()) {
123
            webProductListingRepository.deleteByEqual(webListing.getId());
124
            int count = 0;
125
            for (Integer catalogItemId : catalogItemIds) {
126
 
127
                WebProductListing webProductListing = new WebProductListing();
128
                webProductListing.setEntityId(catalogItemId);
129
                webProductListing.setWebListingId(webListing.getId());
130
                count = count + 1;
131
                webProductListing.setRank(count);
132
                webProductListingRepository.persist(webProductListing);
133
 
134
            }
135
 
136
        }
137
    }
138
 
139
    public void getSpecialSupport() throws ProfitMandiBusinessException {
140
        WebListing webListing = webListingRepository.selectByUrl("special-support");
141
 
31754 tejbeer 142
        List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT, LocalDate.now().plusDays(1));
31732 amit.gupta 143
 
144
        LOGGER.info("catalogItemIds {}", catalogItemIds);
145
        if (!catalogItemIds.isEmpty()) {
146
            webProductListingRepository.deleteByEqual(webListing.getId());
147
            int count = 0;
148
            for (Integer catalogItemId : catalogItemIds) {
149
 
150
                WebProductListing webProductListing = new WebProductListing();
151
                webProductListing.setEntityId(catalogItemId);
152
                webProductListing.setWebListingId(webListing.getId());
153
                count = count + 1;
154
                webProductListing.setRank(count);
155
                webProductListingRepository.persist(webProductListing);
156
 
157
            }
158
 
159
        }
160
    }
161
 
162
    public void getUpgradeOffer() throws ProfitMandiBusinessException {
163
        WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
164
        webProductListingRepository.deleteByEqual(webListing.getId());
165
 
31754 tejbeer 166
        List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream().map(x -> x.getId()).collect(Collectors.toList());
31732 amit.gupta 167
 
31754 tejbeer 168
        List<Integer> catalogItemIds = customerOfferItemRepository.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct().collect(Collectors.toList());
31732 amit.gupta 169
 
170
        LOGGER.info("catalogItemIds {}", catalogItemIds);
171
        if (!catalogItemIds.isEmpty()) {
172
            int count = 0;
173
            for (Integer catalogItemId : catalogItemIds) {
174
 
175
                WebProductListing webProductListing = new WebProductListing();
176
                webProductListing.setEntityId(catalogItemId);
177
                webProductListing.setWebListingId(webListing.getId());
178
                count = count + 1;
179
                webProductListing.setRank(count);
180
                webProductListingRepository.persist(webProductListing);
181
 
182
            }
183
 
184
        }
185
    }
186
 
34555 tejus.loha 187
    @Scheduled(cron = "0 */30 * * * *")
188
    public void scheduledPushDataToSolr() throws Throwable {
189
        this.pushDataToSolr();
190
    }
191
 
192
    @Scheduled(cron = "0 0 8 * * *")
193
    public void scheduledGetBestSeller() throws Throwable {
194
        this.getBestSeller();
195
    }
196
 
197
    @Scheduled(cron = "0 0 8 * * *")
198
    public void scheduledGetPriceDrop() throws Throwable {
199
        this.getPriceDrop();
200
    }
201
 
202
    @Scheduled(cron = "0 0 8 * * *")
203
    public void scheduledGetNewLaunches() throws Throwable {
204
        this.getNewLaunches();
205
    }
206
 
207
    @Scheduled(cron = "0 0 8 * * *")
208
    public void scheduledGetSpecialSupport() throws Throwable {
209
        this.getSpecialSupport();
210
    }
211
 
212
    @Scheduled(cron = "0 0 8 * * *")
213
    public void scheduledGetUpgradeOffer() throws Throwable {
214
        this.getUpgradeOffer();
215
    }
31732 amit.gupta 216
}
217