| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.scheduled;
|
1 |
package com.smartdukaan.cron.scheduled;
|
| 2 |
|
2 |
|
| 3 |
import java.io.PrintStream;
|
- |
|
| 4 |
import java.sql.Timestamp;
|
3 |
import java.sql.Timestamp;
|
| 5 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 6 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 7 |
import java.time.temporal.ChronoUnit;
|
6 |
import java.time.temporal.ChronoUnit;
|
| 8 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| Line 10... |
Line 9... |
| 10 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 11 |
import java.util.List;
|
10 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 13 |
import java.util.stream.Collectors;
|
12 |
import java.util.stream.Collectors;
|
| 14 |
|
13 |
|
| 15 |
import org.apache.commons.csv.CSVFormat;
|
- |
|
| 16 |
import org.apache.commons.csv.CSVPrinter;
|
- |
|
| 17 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
14 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 18 |
import org.apache.logging.log4j.LogManager;
|
15 |
import org.apache.logging.log4j.LogManager;
|
| 19 |
import org.apache.logging.log4j.Logger;
|
16 |
import org.apache.logging.log4j.Logger;
|
| 20 |
import org.springframework.beans.factory.annotation.Autowired;
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21 |
import org.springframework.beans.factory.annotation.Qualifier;
|
18 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| Line 26... |
Line 23... |
| 26 |
import org.springframework.transaction.annotation.Transactional;
|
23 |
import org.springframework.transaction.annotation.Transactional;
|
| 27 |
|
24 |
|
| 28 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
25 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 29 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
26 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 30 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
27 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| - |
|
28 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 31 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
29 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 32 |
import com.spice.profitmandi.common.util.Utils;
|
30 |
import com.spice.profitmandi.common.util.Utils;
|
| 33 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
31 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 34 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
32 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
| 35 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
33 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
| 36 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
34 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 37 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
35 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 38 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
36 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
37 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| - |
|
38 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 40 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
39 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| - |
|
40 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 41 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
41 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
42 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
43 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
44 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
45 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 46 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
46 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 47 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
47 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| - |
|
48 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 48 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
49 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| - |
|
50 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 49 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
51 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 50 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
52 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
| 51 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
53 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| 52 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
54 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 53 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
55 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| Line 96... |
Line 98... |
| 96 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
98 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
| 97 |
private String thinkWalnutDigitalRechargeAuthKey;
|
99 |
private String thinkWalnutDigitalRechargeAuthKey;
|
| 98 |
|
100 |
|
| 99 |
@Autowired
|
101 |
@Autowired
|
| 100 |
private PurchaseRepository purchaseRepository;
|
102 |
private PurchaseRepository purchaseRepository;
|
| - |
|
103 |
|
| - |
|
104 |
@Autowired
|
| - |
|
105 |
private SchemeInOutRepository schemeInOutRepository;
|
| 101 |
|
106 |
|
| 102 |
@Autowired
|
107 |
@Autowired
|
| 103 |
private SchemeService schemeService;
|
108 |
private SchemeService schemeService;
|
| 104 |
|
109 |
|
| 105 |
@Autowired
|
110 |
@Autowired
|
| Line 143... |
Line 148... |
| 143 |
|
148 |
|
| 144 |
@Autowired
|
149 |
@Autowired
|
| 145 |
private JavaMailSender mailSender;
|
150 |
private JavaMailSender mailSender;
|
| 146 |
|
151 |
|
| 147 |
@Autowired
|
152 |
@Autowired
|
| - |
|
153 |
private PriceDropRepository priceDropRepository;
|
| - |
|
154 |
|
| - |
|
155 |
@Autowired
|
| 148 |
@Qualifier(value="googleMailSender")
|
156 |
@Qualifier(value = "googleMailSender")
|
| 149 |
private JavaMailSender googleMailSender;
|
157 |
private JavaMailSender googleMailSender;
|
| 150 |
|
158 |
|
| 151 |
@Autowired
|
159 |
@Autowired
|
| 152 |
private InventoryService inventoryService;
|
160 |
private InventoryService inventoryService;
|
| 153 |
|
161 |
|
| Line 311... |
Line 319... |
| 311 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
319 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 312 |
|
320 |
|
| 313 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
321 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
| 314 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
322 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
| 315 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
323 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 316 |
try (
|
- |
|
| 317 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
- |
|
| 318 |
PrintStream writer = new PrintStream(baos);
|
- |
|
| 319 |
CSVPrinter csvPrinter = new CSVPrinter(writer,
|
- |
|
| 320 |
CSVFormat.EXCEL.withTrim().withHeader("Code", "StoreName", "Email", "Mobile", "WalletAmount",
|
- |
|
| 321 |
"InStockAmount", "UnbilledStockAmount", "GrnPendingStockAmount", "MinimumInvestment",
|
- |
|
| 322 |
"TotalInvested", "ShortAmount"));) {
|
- |
|
| 323 |
for (FofoStore fofoStore : fofoStores) {
|
- |
|
| 324 |
|
- |
|
| 325 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
- |
|
| 326 |
if(retailer==null) {
|
- |
|
| 327 |
LOGGER.info("Could not find retailer with retailer Id {}",fofoStore.getId() );
|
- |
|
| 328 |
continue;
|
- |
|
| 329 |
}
|
- |
|
| 330 |
float walletAmount = walletService.getUserWallet(fofoStore.getId()).getAmount();
|
- |
|
| 331 |
float inStockAmount = inventoryService.getTotalAmountInStock(fofoStore.getId());
|
- |
|
| 332 |
|
324 |
|
| - |
|
325 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "WalletAmount", "InStockAmount",
|
| - |
|
326 |
"UnbilledStockAmount", "GrnPendingStockAmount", "MinimumInvestment", "TotalInvested", "ShortAmount");
|
| - |
|
327 |
List<List<Object>> rows = new ArrayList<>();
|
| 333 |
float unbilledStockAmount = 0;
|
328 |
for (FofoStore fofoStore : fofoStores) {
|
| 334 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoStore.getId());
|
329 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 335 |
for (Order unBilledOrder : unbilledOrders) {
|
330 |
if (retailer == null) {
|
| 336 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
331 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
| - |
|
332 |
continue;
|
| 337 |
}
|
333 |
}
|
| - |
|
334 |
float walletAmount = walletService.getUserWallet(fofoStore.getId()).getAmount();
|
| - |
|
335 |
float inStockAmount = inventoryService.getTotalAmountInStock(fofoStore.getId());
|
| 338 |
|
336 |
|
| 339 |
float grnPendingStockAmount = 0;
|
337 |
float unbilledStockAmount = 0;
|
| 340 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoStore.getId());
|
338 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoStore.getId());
|
| 341 |
for (Order grnPendingOrder : grnPendingOrders) {
|
339 |
for (Order unBilledOrder : unbilledOrders) {
|
| 342 |
LOGGER.info("Grn pending for Order {} and partner {}", grnPendingOrder.getId(),
|
- |
|
| 343 |
grnPendingOrder.getRetailerEmailId());
|
- |
|
| 344 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
340 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
| 345 |
}
|
341 |
}
|
| - |
|
342 |
|
| 346 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
343 |
float grnPendingStockAmount = 0;
|
| 347 |
try {
|
- |
|
| 348 |
csvPrinter.printRecord(fofoStore.getCode(), retailer.getBusinessName(),
|
344 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoStore.getId());
|
| 349 |
retailer.getEmail(), retailer.getMobileNumber(), walletAmount,
|
345 |
for (Order grnPendingOrder : grnPendingOrders) {
|
| 350 |
inStockAmount, unbilledStockAmount, grnPendingStockAmount, fofoStore.getMinimumInvestment(), totalInvestedAmount,
|
346 |
LOGGER.info("Grn pending for Order {} and partner {}", grnPendingOrder.getId(),
|
| 351 |
fofoStore.getMinimumInvestment() - totalInvestedAmount);
|
347 |
grnPendingOrder.getRetailerEmailId());
|
| 352 |
} catch (Exception e) {
|
- |
|
| 353 |
LOGGER.info("Could not get investment details for partner {}, re", retailer.getEmail());
|
348 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
| 354 |
e.printStackTrace();
|
- |
|
| 355 |
}
|
- |
|
| 356 |
}
|
349 |
}
|
| - |
|
350 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
| 357 |
Utils.sendMailWithAttachment(googleMailSender, "kamini.sharma@smartdukaan.com",
|
351 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| - |
|
352 |
retailer.getMobileNumber(), walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount,
|
| 358 |
new String[] { "amandeep.singh@smartdukaan.com", "tarun.verma@smartdukaan.com"},
|
353 |
fofoStore.getMinimumInvestment(), totalInvestedAmount,
|
| 359 |
"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
354 |
fofoStore.getMinimumInvestment() - totalInvestedAmount);
|
| - |
|
355 |
rows.add(row);
|
| 360 |
|
356 |
|
| 361 |
}
|
357 |
}
|
| - |
|
358 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| - |
|
359 |
Utils.sendMailWithAttachment(googleMailSender, "adeel.yazdani@smartdukaan.com",
|
| - |
|
360 |
new String[] { "amandeep.singh@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| - |
|
361 |
"kamini.sharma@smartdukaan.com" },
|
| - |
|
362 |
"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
| 362 |
}
|
363 |
}
|
| 363 |
|
364 |
|
| 364 |
}
|
365 |
}
|