Subversion Repositories SmartDukaan

Rev

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

Rev 34492 Rev 34545
Line 1... Line 1...
1
package com.spice.profitmandi.dao.service;
1
package com.spice.profitmandi.dao.service;
2
 
2
 
3
import com.spice.profitmandi.common.model.BulkOrderModel;
3
import com.spice.profitmandi.common.model.BulkOrderModel;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
5
import com.spice.profitmandi.common.util.StringUtils;
5
import com.spice.profitmandi.dao.entity.catalog.Bid;
6
import com.spice.profitmandi.dao.entity.catalog.Bid;
6
import com.spice.profitmandi.dao.entity.catalog.Item;
7
import com.spice.profitmandi.dao.entity.catalog.Item;
7
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
8
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
-
 
9
import com.spice.profitmandi.dao.entity.catalog.TagListing;
8
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
10
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
9
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
11
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
10
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
12
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
11
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
13
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
-
 
14
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
12
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
15
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
-
 
16
import com.spice.profitmandi.service.NotificationService;
13
import com.spice.profitmandi.service.order.BulkOrderService;
17
import com.spice.profitmandi.service.order.BulkOrderService;
-
 
18
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
14
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
20
import org.apache.logging.log4j.Logger;
16
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Component;
22
import org.springframework.stereotype.Component;
18
 
23
 
19
import java.time.LocalDateTime;
24
import java.time.LocalDateTime;
20
import java.time.format.DateTimeFormatter;
-
 
21
import java.util.ArrayList;
-
 
22
import java.util.Arrays;
-
 
23
import java.util.List;
25
import java.util.*;
24
 
26
 
25
@Component
27
@Component
26
public class LiquidationService {
28
public class LiquidationService {
27
    private static final Logger LOGGER = LogManager.getLogger(LiquidationService.class);
29
    private static final Logger LOGGER = LogManager.getLogger(LiquidationService.class);
28
 
30
 
Line 42... Line 44...
42
    SaholicCISTableRepository saholicCISTableRepository;
44
    SaholicCISTableRepository saholicCISTableRepository;
43
 
45
 
44
    @Autowired
46
    @Autowired
45
    private BulkOrderService bulkOrderService;
47
    private BulkOrderService bulkOrderService;
46
 
48
 
-
 
49
    @Autowired
-
 
50
    private TagListingRepository tagListingRepository;
-
 
51
 
-
 
52
    @Autowired
-
 
53
    private NotificationService notificationService;
-
 
54
 
47
    public void processBids(ProfitMandiConstants.BID_CRON_ENUM type) throws Exception {
55
    public void processBids(ProfitMandiConstants.BID_CRON_ENUM type) throws Exception {
48
        List<Liquidation> liquidations;
56
        List<Liquidation> liquidations;
49
        if (type.equals(ProfitMandiConstants.BID_CRON_ENUM.YESTERDAY)){
57
        if (type.equals(ProfitMandiConstants.BID_CRON_ENUM.YESTERDAY)){
50
            liquidations = liquidationRepository.selectAllByEndDate(LocalDateTime.now().minusDays(1));
58
            liquidations = liquidationRepository.selectAllByEndDate(LocalDateTime.now().minusDays(1));
51
        } else {
59
        } else {
Line 88... Line 96...
88
                    liquidation.setStatus(ProfitMandiConstants.LIQUIDATION_ENUM.CLOSED);
96
                    liquidation.setStatus(ProfitMandiConstants.LIQUIDATION_ENUM.CLOSED);
89
                }
97
                }
90
            }
98
            }
91
        }
99
        }
92
    }
100
    }
-
 
101
 
-
 
102
    public void consolidatedBiddingMessage() throws Exception {
-
 
103
        List<Liquidation> liquidations = liquidationRepository.selectAllByStatus(ProfitMandiConstants.LIQUIDATION_ENUM.PUBLISHED);
-
 
104
        LOGGER.info("consolidatedBiddingMessage liquidations: {}",liquidations);
-
 
105
 
-
 
106
        if (liquidations.size() > 0) {
-
 
107
            StringBuilder message = new StringBuilder("*Bidding Live Now!*\n" +
-
 
108
                    "Place your best bids and unlock unbeatable deals on top smartphone models!\n");
-
 
109
            //StringBuilder templateMessage = new StringBuilder("bidd_live");
-
 
110
            for (Liquidation liquidation : liquidations) {
-
 
111
                List<Item> items = itemRepository.selectAllByCatalogItemId(liquidation.getCatalogId());
-
 
112
                if (items.size() > 0) {
-
 
113
                    long remainingQty = 0;
-
 
114
                    for (Item item : items) {
-
 
115
                        List<SaholicCISTable> saholicCISTable = saholicCISTableRepository.selectAllByItemId(item.getId());
-
 
116
                        remainingQty += saholicCISTable.stream().mapToInt(SaholicCISTable::getAvailability).sum();
-
 
117
                    }
-
 
118
                    TagListing tagListing = tagListingRepository.selectByItemId(items.get(0).getId());
-
 
119
                    liquidation.setQuantity((int) remainingQty);
-
 
120
                    if (liquidation.getQuantity() > 0){
-
 
121
                        double mrp = tagListing.getMrp();
-
 
122
                        double discountPercentage = ((mrp - liquidation.getPrice()) / mrp) * 100;
-
 
123
                        message.append("\n")
-
 
124
                            .append("*").append(items.get(0).getItemDescription())
-
 
125
                            .append(" at ").append(Math.round(discountPercentage)).append("% Off*\n")
-
 
126
                            .append("Starting price: *").append(liquidation.getPrice()).append("*\n")
-
 
127
                            .append("Ending on: *")
-
 
128
                            .append(StringUtils.toLocalDateTime(liquidation.getEndDate().toString())).append("*\n");
-
 
129
                        //templateMessage.append("|").append(items.get(0).getItemDescription()).append("|").append(liquidation.getPrice()).append("|").append(StringUtils.toLocalDateTime(liquidation.getEndDate().toString()));
-
 
130
                    }
-
 
131
                }
-
 
132
            }
-
 
133
 
-
 
134
            message.append("\nDon't miss out. Submit your bid now and grab the deal before it's gone!");
-
 
135
 
-
 
136
            LOGGER.info("templateMessage : {}",message.toString());
-
 
137
 
-
 
138
            bidService.biddingLiveNotification(message.toString(), "https://images.smartdukaan.com/uploads/whatsapp.jpeg");
-
 
139
            //notificationService.sendWhatsappMessage(message, "Bidding Live Now!", "8529003611");
-
 
140
            //notificationService.sendWhatsappMediaMessage(message.toString(), "8529003611", "https://images.smartdukaan.com/uploads/whatsapp.jpeg","whatsapp.jpeg", WhatsappMessageType.IMAGE);
-
 
141
        }
-
 
142
    }
93
}
143
}