Subversion Repositories SmartDukaan

Rev

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

Rev 31638 Rev 31639
Line 1... Line 1...
1
package com.smartdukaan.cron.scheduled;
1
package com.smartdukaan.cron.scheduled;
2
 
2
 
-
 
3
import java.io.FileOutputStream;
-
 
4
import java.io.IOException;
-
 
5
import java.io.ObjectOutputStream;
-
 
6
import java.io.Serializable;
-
 
7
import java.io.UnsupportedEncodingException;
-
 
8
import java.math.BigDecimal;
-
 
9
import java.math.RoundingMode;
-
 
10
import java.nio.file.Files;
-
 
11
import java.nio.file.Paths;
-
 
12
import java.sql.Timestamp;
-
 
13
import java.text.DecimalFormat;
-
 
14
import java.time.Duration;
-
 
15
import java.time.LocalDate;
-
 
16
import java.time.LocalDateTime;
-
 
17
import java.time.LocalTime;
-
 
18
import java.time.Month;
-
 
19
import java.time.YearMonth;
-
 
20
import java.time.format.DateTimeFormatter;
-
 
21
import java.time.temporal.ChronoField;
-
 
22
import java.time.temporal.ChronoUnit;
-
 
23
import java.util.ArrayList;
-
 
24
import java.util.Arrays;
-
 
25
import java.util.Base64;
-
 
26
import java.util.Collections;
-
 
27
import java.util.Comparator;
-
 
28
import java.util.HashMap;
-
 
29
import java.util.HashSet;
-
 
30
import java.util.LinkedHashMap;
-
 
31
import java.util.List;
-
 
32
import java.util.Map;
-
 
33
import java.util.Map.Entry;
-
 
34
import java.util.Objects;
-
 
35
import java.util.Optional;
-
 
36
import java.util.Set;
-
 
37
import java.util.stream.Collectors;
-
 
38
import java.util.stream.Stream;
-
 
39
 
-
 
40
import javax.mail.MessagingException;
-
 
41
import javax.mail.internet.InternetAddress;
-
 
42
import javax.mail.internet.MimeMessage;
-
 
43
 
-
 
44
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
45
import org.apache.commons.lang.StringUtils;
-
 
46
import org.apache.http.client.methods.CloseableHttpResponse;
-
 
47
import org.apache.http.client.methods.HttpPost;
-
 
48
import org.apache.http.conn.HttpHostConnectException;
-
 
49
import org.apache.http.entity.StringEntity;
-
 
50
import org.apache.http.impl.client.CloseableHttpClient;
-
 
51
import org.apache.http.impl.client.HttpClients;
-
 
52
import org.apache.logging.log4j.LogManager;
-
 
53
import org.apache.logging.log4j.Logger;
-
 
54
import org.json.JSONArray;
-
 
55
import org.json.JSONObject;
-
 
56
import org.json.XML;
-
 
57
import org.springframework.beans.factory.annotation.Autowired;
-
 
58
import org.springframework.beans.factory.annotation.Qualifier;
-
 
59
import org.springframework.beans.factory.annotation.Value;
-
 
60
import org.springframework.core.io.ByteArrayResource;
-
 
61
import org.springframework.core.io.InputStreamSource;
-
 
62
import org.springframework.mail.javamail.JavaMailSender;
-
 
63
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
64
import org.springframework.stereotype.Component;
-
 
65
import org.springframework.transaction.annotation.Transactional;
-
 
66
 
3
import com.google.common.collect.Lists;
67
import com.google.common.collect.Lists;
4
import com.google.gson.Gson;
68
import com.google.gson.Gson;
5
import com.razorpay.Payment;
69
import com.razorpay.Payment;
6
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
70
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
7
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
71
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
8
import com.spice.profitmandi.common.enumuration.MessageType;
72
import com.spice.profitmandi.common.enumuration.MessageType;
9
import com.spice.profitmandi.common.enumuration.RechargeStatus;
73
import com.spice.profitmandi.common.enumuration.RechargeStatus;
10
import com.spice.profitmandi.common.enumuration.ReporticoProject;
74
import com.spice.profitmandi.common.enumuration.ReporticoProject;
11
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
75
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
76
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
77
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
12
import com.spice.profitmandi.common.model.*;
78
import com.spice.profitmandi.common.model.GstRate;
-
 
79
import com.spice.profitmandi.common.model.InvoicePdfModel;
-
 
80
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
81
import com.spice.profitmandi.common.model.RechargeCredential;
-
 
82
import com.spice.profitmandi.common.model.SendNotificationModel;
13
import com.spice.profitmandi.common.services.ReporticoService;
83
import com.spice.profitmandi.common.services.ReporticoService;
14
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
84
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
15
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
85
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
16
import com.spice.profitmandi.common.services.mandii.MandiiService;
86
import com.spice.profitmandi.common.services.mandii.MandiiService;
17
import com.spice.profitmandi.common.util.FileUtil;
87
import com.spice.profitmandi.common.util.FileUtil;
Line 27... Line 97...
27
import com.spice.profitmandi.dao.entity.catalog.Item;
97
import com.spice.profitmandi.dao.entity.catalog.Item;
28
import com.spice.profitmandi.dao.entity.catalog.Scheme;
98
import com.spice.profitmandi.dao.entity.catalog.Scheme;
29
import com.spice.profitmandi.dao.entity.catalog.TagListing;
99
import com.spice.profitmandi.dao.entity.catalog.TagListing;
30
import com.spice.profitmandi.dao.entity.cs.Position;
100
import com.spice.profitmandi.dao.entity.cs.Position;
31
import com.spice.profitmandi.dao.entity.cs.Ticket;
101
import com.spice.profitmandi.dao.entity.cs.Ticket;
-
 
102
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
-
 
103
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
-
 
104
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
-
 
105
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
-
 
106
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
-
 
107
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
-
 
108
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
-
 
109
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
-
 
110
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
-
 
111
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
32
import com.spice.profitmandi.dao.entity.dtr.User;
112
import com.spice.profitmandi.dao.entity.dtr.User;
33
import com.spice.profitmandi.dao.entity.dtr.*;
113
import com.spice.profitmandi.dao.entity.dtr.WebListing;
-
 
114
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
-
 
115
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
-
 
116
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
-
 
117
import com.spice.profitmandi.dao.entity.fofo.Customer;
-
 
118
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
-
 
119
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
-
 
120
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
-
 
121
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
-
 
122
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
-
 
123
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
124
import com.spice.profitmandi.dao.entity.fofo.HygieneData;
-
 
125
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
-
 
126
import com.spice.profitmandi.dao.entity.fofo.MonthlyTarget;
-
 
127
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
-
 
128
import com.spice.profitmandi.dao.entity.fofo.PartnerProblem;
-
 
129
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
-
 
130
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
-
 
131
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
-
 
132
import com.spice.profitmandi.dao.entity.fofo.Purchase;
34
import com.spice.profitmandi.dao.entity.fofo.*;
133
import com.spice.profitmandi.dao.entity.fofo.RazorPay;
-
 
134
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
-
 
135
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
35
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
136
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
36
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
137
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
37
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
138
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
38
import com.spice.profitmandi.dao.entity.transaction.*;
139
import com.spice.profitmandi.dao.entity.transaction.Loan;
-
 
140
import com.spice.profitmandi.dao.entity.transaction.LoanStatement;
-
 
141
import com.spice.profitmandi.dao.entity.transaction.Order;
-
 
142
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
-
 
143
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
-
 
144
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
-
 
145
import com.spice.profitmandi.dao.entity.transaction.SanctionRequest;
-
 
146
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
-
 
147
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
-
 
148
import com.spice.profitmandi.dao.entity.user.Address;
-
 
149
import com.spice.profitmandi.dao.entity.user.Device;
-
 
150
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
39
import com.spice.profitmandi.dao.entity.user.*;
151
import com.spice.profitmandi.dao.entity.user.Lead;
-
 
152
import com.spice.profitmandi.dao.entity.user.Refferal;
40
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
153
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
41
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
154
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
42
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
155
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
43
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
156
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
44
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
157
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
Line 126... Line 239...
126
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
239
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
127
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
240
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
128
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
241
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
129
import com.spice.profitmandi.dao.repository.user.AddressRepository;
242
import com.spice.profitmandi.dao.repository.user.AddressRepository;
130
import com.spice.profitmandi.dao.repository.user.UserRepository;
243
import com.spice.profitmandi.dao.repository.user.UserRepository;
131
import com.spice.profitmandi.dao.repository.warehouse.BilledImeiModel;
-
 
132
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
-
 
133
import com.spice.profitmandi.dao.service.solr.FofoSolr;
244
import com.spice.profitmandi.dao.service.solr.FofoSolr;
134
import com.spice.profitmandi.service.NotificationService;
245
import com.spice.profitmandi.service.NotificationService;
135
import com.spice.profitmandi.service.PartnerInvestmentService;
246
import com.spice.profitmandi.service.PartnerInvestmentService;
136
import com.spice.profitmandi.service.PartnerStatsService;
247
import com.spice.profitmandi.service.PartnerStatsService;
137
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
248
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
Line 489... Line 600...
489
 
600
 
490
	@Autowired
601
	@Autowired
491
	CustomerOfferItemRepository customerOfferItemRepository;
602
	CustomerOfferItemRepository customerOfferItemRepository;
492
	@Autowired
603
	@Autowired
493
	private FofoSolr fofoSolr;
604
	private FofoSolr fofoSolr;
494
 
-
 
495
 
-
 
496
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
605
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
497
 
606
 
498
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
607
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
499
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
608
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
500
 
609
 
Line 1037... Line 1146...
1037
			this.fofoId = fofoId;
1146
			this.fofoId = fofoId;
1038
		}
1147
		}
1039
 
1148
 
1040
	}
1149
	}
1041
 
1150
 
1042
	@Autowired
-
 
1043
	WarehouseInventoryItemRepository warehouseInventoryItemRepository;
-
 
1044
	public void test() throws Exception {
-
 
1045
		this.sendMailForSamsungRebilling();
-
 
1046
	}
-
 
1047
 
-
 
1048
	public void sendMailForSamsungRebilling() throws Exception {
-
 
1049
		List<BilledImeiModel> samsungModels = warehouseInventoryItemRepository.findByBillingDateBrand(LocalDate.now(), "Samsung");
-
 
1050
		LOGGER.info("SamsungModels {}", samsungModels);
-
 
1051
		samsungModels = samsungModels.stream().sorted(Comparator.comparing(x-> x.getPcmDate()==null ? -1:1)).collect(Collectors.toList());
-
 
1052
		if(samsungModels.size() > 0) {
-
 
1053
			List<String> headers = Arrays.asList("Partner Id", "Code", "Name", "City", "Brand", "Model Name", "Model Number", "Color", "Serial Number", "Remarks");
-
 
1054
			List<List<?>> rows = new ArrayList<>();
-
 
1055
			for(BilledImeiModel billedImeiModel : samsungModels) {
-
 
1056
				List<Serializable> row = Arrays.asList(billedImeiModel.getFofoId(), billedImeiModel.getStoreCode(), billedImeiModel.getStoreName(),
-
 
1057
						billedImeiModel.getStoreCity(), billedImeiModel.getBrand(), billedImeiModel.getModelName(), billedImeiModel.getModelNumber(),
-
 
1058
						billedImeiModel.getColor(), billedImeiModel.getSerialNumber(), billedImeiModel.getPcmDate()==null ? "PCM date Missing" : "Rebill Imeis");
-
 
1059
				rows.add(row);
-
 
1060
			}
-
 
1061
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
-
 
1062
			String[] sendToArray = new String[]{"kamini.sharma@smartdukaan.com", "praveen.sharma@smartdukaan.com"};
-
 
1063
			String fileName = "Imeis need Rebilling -" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
-
 
1064
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{"tarun.verma@smartdukaan.com"}, "Samsung Rebilling IMEI Summary", "PFA",
-
 
1065
					fileName, new ByteArrayResource(baos.toByteArray()));
-
 
1066
		}
-
 
1067
	}
-
 
1068
 
-
 
1069
	public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
1151
	public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
1070
		LocalDate yesterDay = LocalDate.now().minusDays(1);
1152
		LocalDate yesterDay = LocalDate.now().minusDays(1);
1071
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1153
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1072
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
1154
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
1073
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
1155
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
Line 4790... Line 4872...
4790
 
4872
 
4791
		Set<Integer> itemIds = tagListingRepository
4873
		Set<Integer> itemIds = tagListingRepository
4792
				.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
4874
				.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
4793
				.map(x -> x.getItemId()).collect(Collectors.toSet());
4875
				.map(x -> x.getItemId()).collect(Collectors.toSet());
4794
 
4876
 
4795
		LOGGER.info("itemIds {}", itemIds);
-
 
4796
 
-
 
4797
		List<Integer> catalogItemIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
4877
		Set<Integer> catalogItemIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
4798
				.distinct().collect(Collectors.toList());
4878
				.collect(Collectors.toSet());
4799
 
4879
 
4800
		LOGGER.info("catalogItemIds {}", catalogItemIds);
4880
		LOGGER.info("catalogItemIds {}", catalogItemIds);
4801
		if (!catalogItemIds.isEmpty()) {
4881
		if (!catalogItemIds.isEmpty()) {
4802
			webProductListingRepository.deleteByEqual(webListing.getId());
4882
			webProductListingRepository.deleteByEqual(webListing.getId());
4803
			int count = 0;
4883
			int count = 0;