Subversion Repositories SmartDukaan

Rev

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

Rev 31639 Rev 31640
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
 
-
 
67
import com.google.common.collect.Lists;
3
import com.google.common.collect.Lists;
68
import com.google.gson.Gson;
4
import com.google.gson.Gson;
69
import com.razorpay.Payment;
5
import com.razorpay.Payment;
70
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
6
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
71
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
7
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
72
import com.spice.profitmandi.common.enumuration.MessageType;
8
import com.spice.profitmandi.common.enumuration.MessageType;
73
import com.spice.profitmandi.common.enumuration.RechargeStatus;
9
import com.spice.profitmandi.common.enumuration.RechargeStatus;
74
import com.spice.profitmandi.common.enumuration.ReporticoProject;
10
import com.spice.profitmandi.common.enumuration.ReporticoProject;
75
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
11
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
76
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
77
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
-
 
78
import com.spice.profitmandi.common.model.GstRate;
12
import com.spice.profitmandi.common.model.*;
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;
-
 
83
import com.spice.profitmandi.common.services.ReporticoService;
13
import com.spice.profitmandi.common.services.ReporticoService;
84
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
14
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
85
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
15
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
86
import com.spice.profitmandi.common.services.mandii.MandiiService;
16
import com.spice.profitmandi.common.services.mandii.MandiiService;
87
import com.spice.profitmandi.common.util.FileUtil;
17
import com.spice.profitmandi.common.util.FileUtil;
Line 97... Line 27...
97
import com.spice.profitmandi.dao.entity.catalog.Item;
27
import com.spice.profitmandi.dao.entity.catalog.Item;
98
import com.spice.profitmandi.dao.entity.catalog.Scheme;
28
import com.spice.profitmandi.dao.entity.catalog.Scheme;
99
import com.spice.profitmandi.dao.entity.catalog.TagListing;
29
import com.spice.profitmandi.dao.entity.catalog.TagListing;
100
import com.spice.profitmandi.dao.entity.cs.Position;
30
import com.spice.profitmandi.dao.entity.cs.Position;
101
import com.spice.profitmandi.dao.entity.cs.Ticket;
31
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;
-
 
112
import com.spice.profitmandi.dao.entity.dtr.User;
32
import com.spice.profitmandi.dao.entity.dtr.User;
113
import com.spice.profitmandi.dao.entity.dtr.WebListing;
33
import com.spice.profitmandi.dao.entity.dtr.*;
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;
-
 
133
import com.spice.profitmandi.dao.entity.fofo.RazorPay;
34
import com.spice.profitmandi.dao.entity.fofo.*;
134
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
-
 
135
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
-
 
136
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
35
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
137
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
36
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
138
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
37
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
139
import com.spice.profitmandi.dao.entity.transaction.Loan;
38
import com.spice.profitmandi.dao.entity.transaction.*;
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;
-
 
151
import com.spice.profitmandi.dao.entity.user.Lead;
39
import com.spice.profitmandi.dao.entity.user.*;
152
import com.spice.profitmandi.dao.entity.user.Refferal;
-
 
153
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
40
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
154
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
41
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
155
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
42
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
156
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
43
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
157
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
44
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
Line 239... Line 126...
239
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
126
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
240
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
127
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
241
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
128
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
242
import com.spice.profitmandi.dao.repository.user.AddressRepository;
129
import com.spice.profitmandi.dao.repository.user.AddressRepository;
243
import com.spice.profitmandi.dao.repository.user.UserRepository;
130
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;
244
import com.spice.profitmandi.dao.service.solr.FofoSolr;
133
import com.spice.profitmandi.dao.service.solr.FofoSolr;
245
import com.spice.profitmandi.service.NotificationService;
134
import com.spice.profitmandi.service.NotificationService;
246
import com.spice.profitmandi.service.PartnerInvestmentService;
135
import com.spice.profitmandi.service.PartnerInvestmentService;
247
import com.spice.profitmandi.service.PartnerStatsService;
136
import com.spice.profitmandi.service.PartnerStatsService;
248
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
137
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
Line 267... Line 156...
267
import in.shop2020.model.v1.order.WalletReferenceType;
156
import in.shop2020.model.v1.order.WalletReferenceType;
268
import okhttp3.OkHttpClient;
157
import okhttp3.OkHttpClient;
269
import okhttp3.Request;
158
import okhttp3.Request;
270
import okhttp3.Response;
159
import okhttp3.Response;
271
 
160
 
-
 
161
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
162
import org.apache.commons.lang.StringUtils;
-
 
163
import org.apache.http.client.methods.CloseableHttpResponse;
-
 
164
import org.apache.http.client.methods.HttpPost;
-
 
165
import org.apache.http.conn.HttpHostConnectException;
-
 
166
import org.apache.http.entity.StringEntity;
-
 
167
import org.apache.http.impl.client.CloseableHttpClient;
-
 
168
import org.apache.http.impl.client.HttpClients;
-
 
169
import org.apache.logging.log4j.LogManager;
-
 
170
import org.apache.logging.log4j.Logger;
-
 
171
import org.json.JSONArray;
-
 
172
import org.json.JSONObject;
-
 
173
import org.json.XML;
-
 
174
import org.springframework.beans.factory.annotation.Autowired;
-
 
175
import org.springframework.beans.factory.annotation.Qualifier;
-
 
176
import org.springframework.beans.factory.annotation.Value;
-
 
177
import org.springframework.core.io.ByteArrayResource;
-
 
178
import org.springframework.core.io.InputStreamSource;
-
 
179
import org.springframework.mail.javamail.JavaMailSender;
-
 
180
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
181
import org.springframework.stereotype.Component;
-
 
182
import org.springframework.transaction.annotation.Transactional;
-
 
183
 
-
 
184
import javax.mail.MessagingException;
-
 
185
import javax.mail.internet.InternetAddress;
-
 
186
import javax.mail.internet.MimeMessage;
-
 
187
import java.io.*;
-
 
188
import java.math.BigDecimal;
-
 
189
import java.math.RoundingMode;
-
 
190
import java.nio.file.Files;
-
 
191
import java.nio.file.Paths;
-
 
192
import java.sql.Timestamp;
-
 
193
import java.text.DecimalFormat;
-
 
194
import java.time.*;
-
 
195
import java.time.format.DateTimeFormatter;
-
 
196
import java.time.temporal.ChronoField;
-
 
197
import java.time.temporal.ChronoUnit;
-
 
198
import java.util.*;
-
 
199
import java.util.Map.Entry;
-
 
200
import java.util.stream.Collector;
-
 
201
import java.util.stream.Collectors;
-
 
202
import java.util.stream.Stream;
-
 
203
 
272
@Component
204
@Component
273
@Transactional(rollbackFor = Throwable.class)
205
@Transactional(rollbackFor = Throwable.class)
274
public class ScheduledTasks {
206
public class ScheduledTasks {
275
 
207
 
276
	@Value("${oxigen.recharge.transaction.url}")
208
	@Value("${oxigen.recharge.transaction.url}")
Line 4703... Line 4635...
4703
			}
4635
			}
4704
 
4636
 
4705
		}
4637
		}
4706
 
4638
 
4707
	}
4639
	}
-
 
4640
	
-
 
4641
	@Autowired
-
 
4642
	WarehouseInventoryItemRepository warehouseInventoryItemRepository;
-
 
4643
	public void test() throws Exception {
-
 
4644
		this.sendMailForSamsungRebilling();
-
 
4645
	}
-
 
4646
 
-
 
4647
	public void sendMailForSamsungRebilling() throws Exception {
-
 
4648
		List<BilledImeiModel> samsungModels = warehouseInventoryItemRepository.findByBillingDateBrand(LocalDate.now(), "Samsung");
-
 
4649
		LOGGER.info("SamsungModels {}", samsungModels);
-
 
4650
		samsungModels = samsungModels.stream().sorted(Comparator.comparing(x-> x.getPcmDate()==null ? -1:1)).collect(Collectors.toList());
-
 
4651
		if(samsungModels.size() > 0) {
-
 
4652
			List<String> headers = Arrays.asList("Partner Id", "Code", "Name", "City", "Brand", "Model Name", "Model Number", "Color", "Serial Number", "Remarks");
-
 
4653
			List<List<?>> rows = new ArrayList<>();
-
 
4654
			for(BilledImeiModel billedImeiModel : samsungModels) {
-
 
4655
				List<Serializable> row = Arrays.asList(billedImeiModel.getFofoId(), billedImeiModel.getStoreCode(), billedImeiModel.getStoreName(),
-
 
4656
						billedImeiModel.getStoreCity(), billedImeiModel.getBrand(), billedImeiModel.getModelName(), billedImeiModel.getModelNumber(),
-
 
4657
						billedImeiModel.getColor(), billedImeiModel.getSerialNumber(), billedImeiModel.getPcmDate()==null ? "PCM date Missing" : "Rebill Imeis");
-
 
4658
				rows.add(row);
-
 
4659
			}
-
 
4660
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
-
 
4661
			String[] sendToArray = new String[]{"kamini.sharma@smartdukaan.com", "praveen.sharma@smartdukaan.com"};
-
 
4662
			String fileName = "Imeis need Rebilling -" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
-
 
4663
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{"tarun.verma@smartdukaan.com"}, "Samsung Rebilling IMEI Summary", "PFA",
-
 
4664
					fileName, new ByteArrayResource(baos.toByteArray()));
-
 
4665
		}
-
 
4666
	}
-
 
4667
 
-
 
4668
 
4708
 
4669
 
4709
	public void monthlyTargetForInternalTeam() throws MessagingException, ProfitMandiBusinessException, IOException {
4670
	public void monthlyTargetForInternalTeam() throws MessagingException, ProfitMandiBusinessException, IOException {
4710
 
4671
 
4711
		LocalDateTime curDate = LocalDateTime.now();
4672
		LocalDateTime curDate = LocalDateTime.now();
4712
 
4673
 
Line 4872... Line 4833...
4872
 
4833
 
4873
		Set<Integer> itemIds = tagListingRepository
4834
		Set<Integer> itemIds = tagListingRepository
4874
				.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
4835
				.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
4875
				.map(x -> x.getItemId()).collect(Collectors.toSet());
4836
				.map(x -> x.getItemId()).collect(Collectors.toSet());
4876
 
4837
 
-
 
4838
		LOGGER.info("itemIds {}", itemIds);
-
 
4839
 
4877
		Set<Integer> catalogItemIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
4840
		List<Integer> catalogItemIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
4878
				.collect(Collectors.toSet());
4841
				.distinct().collect(Collectors.toList());
4879
 
4842
 
4880
		LOGGER.info("catalogItemIds {}", catalogItemIds);
4843
		LOGGER.info("catalogItemIds {}", catalogItemIds);
4881
		if (!catalogItemIds.isEmpty()) {
4844
		if (!catalogItemIds.isEmpty()) {
4882
			webProductListingRepository.deleteByEqual(webListing.getId());
4845
			webProductListingRepository.deleteByEqual(webListing.getId());
4883
			int count = 0;
4846
			int count = 0;