| 23724 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
| 23723 |
amit.gupta |
2 |
|
| 24121 |
govind |
3 |
import java.io.IOException;
|
|
|
4 |
import java.io.InputStream;
|
| 23739 |
amit.gupta |
5 |
import java.sql.Timestamp;
|
| 24174 |
govind |
6 |
import java.text.MessageFormat;
|
| 23724 |
amit.gupta |
7 |
import java.time.LocalDate;
|
|
|
8 |
import java.time.LocalDateTime;
|
| 24256 |
amit.gupta |
9 |
import java.time.LocalTime;
|
| 23724 |
amit.gupta |
10 |
import java.time.temporal.ChronoUnit;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
| 23723 |
amit.gupta |
13 |
import java.util.HashMap;
|
| 24241 |
amit.gupta |
14 |
import java.util.HashSet;
|
| 23724 |
amit.gupta |
15 |
import java.util.List;
|
| 23723 |
amit.gupta |
16 |
import java.util.Map;
|
| 24242 |
amit.gupta |
17 |
import java.util.Optional;
|
| 24542 |
amit.gupta |
18 |
import java.util.Set;
|
| 23724 |
amit.gupta |
19 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
20 |
|
| 24121 |
govind |
21 |
import javax.mail.MessagingException;
|
|
|
22 |
import javax.mail.internet.InternetAddress;
|
|
|
23 |
import javax.mail.internet.MimeMessage;
|
|
|
24 |
|
|
|
25 |
import org.apache.commons.codec.CharEncoding;
|
|
|
26 |
import org.apache.commons.io.IOUtils;
|
| 23929 |
amit.gupta |
27 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23755 |
amit.gupta |
28 |
import org.apache.logging.log4j.LogManager;
|
|
|
29 |
import org.apache.logging.log4j.Logger;
|
| 24184 |
govind |
30 |
import org.apache.poi.EncryptedDocumentException;
|
|
|
31 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| 23723 |
amit.gupta |
32 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
33 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
34 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
35 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
36 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
37 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
38 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
39 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
40 |
|
| 24542 |
amit.gupta |
41 |
import com.google.common.collect.Lists;
|
| 23724 |
amit.gupta |
42 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24121 |
govind |
43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
44 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24542 |
amit.gupta |
45 |
import com.spice.profitmandi.common.model.GstRate;
|
| 23724 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 24002 |
amit.gupta |
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
48 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
49 |
import com.spice.profitmandi.common.util.Utils;
|
| 24590 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 24533 |
govind |
51 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 23724 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
56 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 24542 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 24590 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 23724 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24542 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23929 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24174 |
govind |
64 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 23724 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24174 |
govind |
66 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 24242 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 24431 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 24587 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 24580 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 24542 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 24250 |
amit.gupta |
73 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 24242 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24533 |
govind |
75 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 24249 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 24533 |
govind |
78 |
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
|
|
|
79 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23724 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
83 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
84 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24542 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
|
|
86 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 24590 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 24542 |
amit.gupta |
88 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 23724 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
91 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
92 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 23724 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
95 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23929 |
amit.gupta |
96 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24431 |
amit.gupta |
97 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24580 |
amit.gupta |
98 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 24587 |
amit.gupta |
99 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 24542 |
amit.gupta |
100 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 24337 |
amit.gupta |
101 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23929 |
amit.gupta |
102 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24271 |
amit.gupta |
103 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
104 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
105 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
106 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
107 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
108 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
109 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
110 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
111 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
112 |
|
| 24197 |
amit.gupta |
113 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
114 |
|
| 23723 |
amit.gupta |
115 |
@Component
|
| 23724 |
amit.gupta |
116 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
117 |
public class ScheduledTasks {
|
|
|
118 |
|
| 24533 |
govind |
119 |
private static final String Escalate_TICKET = "Dear {0},Your Ticket created by {1} is escalated and assigned to {2}. Regards \nSmartdukaan";
|
|
|
120 |
|
| 23724 |
amit.gupta |
121 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
122 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
123 |
|
| 23724 |
amit.gupta |
124 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
125 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
126 |
|
| 24431 |
amit.gupta |
127 |
@Autowired
|
|
|
128 |
private PriceDropService priceDropService;
|
| 23723 |
amit.gupta |
129 |
|
| 23724 |
amit.gupta |
130 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
131 |
private String oxigenRechargeAuthKey;
|
|
|
132 |
|
|
|
133 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
134 |
private String oxigenRechargeValidationUrl;
|
|
|
135 |
|
|
|
136 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
137 |
private String oxigenRechargeValidationAuthKey;
|
|
|
138 |
|
|
|
139 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
140 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
141 |
|
|
|
142 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
143 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
144 |
|
|
|
145 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
146 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
147 |
|
|
|
148 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
149 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
150 |
|
|
|
151 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
152 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
153 |
|
|
|
154 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
155 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
156 |
|
|
|
157 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
158 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
159 |
|
| 23723 |
amit.gupta |
160 |
@Autowired
|
| 23724 |
amit.gupta |
161 |
private PurchaseRepository purchaseRepository;
|
|
|
162 |
|
|
|
163 |
@Autowired
|
|
|
164 |
private SchemeService schemeService;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
| 24271 |
amit.gupta |
167 |
private OrderService orderService;
|
|
|
168 |
|
|
|
169 |
@Autowired
|
| 24337 |
amit.gupta |
170 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
171 |
|
|
|
172 |
@Autowired
|
| 24542 |
amit.gupta |
173 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
174 |
|
|
|
175 |
@Autowired
|
| 24277 |
amit.gupta |
176 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
177 |
|
|
|
178 |
@Autowired
|
| 24241 |
amit.gupta |
179 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
180 |
|
|
|
181 |
@Autowired
|
| 23724 |
amit.gupta |
182 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
183 |
|
|
|
184 |
@Autowired
|
| 24542 |
amit.gupta |
185 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
186 |
|
|
|
187 |
@Autowired
|
| 23724 |
amit.gupta |
188 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
189 |
|
|
|
190 |
@Autowired
|
| 24590 |
amit.gupta |
191 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
192 |
|
|
|
193 |
@Autowired
|
| 23724 |
amit.gupta |
194 |
private FofoOrderRepository fofoOrderRepository;
|
| 24587 |
amit.gupta |
195 |
|
| 24580 |
amit.gupta |
196 |
@Autowired
|
|
|
197 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
198 |
|
| 24249 |
amit.gupta |
199 |
@Autowired
|
| 24587 |
amit.gupta |
200 |
private UserWalletRepository userWalletRepository;
|
|
|
201 |
|
|
|
202 |
@Autowired
|
| 24249 |
amit.gupta |
203 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
204 |
|
| 23739 |
amit.gupta |
205 |
@Autowired
|
|
|
206 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
207 |
|
|
|
208 |
@Autowired
|
|
|
209 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
210 |
|
|
|
211 |
@Autowired
|
|
|
212 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
213 |
|
|
|
214 |
@Autowired
|
|
|
215 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
216 |
|
|
|
217 |
@Autowired
|
| 24242 |
amit.gupta |
218 |
private ScanRecordRepository scanRecordRepository;
|
|
|
219 |
|
|
|
220 |
@Autowired
|
| 23724 |
amit.gupta |
221 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
222 |
|
| 23929 |
amit.gupta |
223 |
@Autowired
|
|
|
224 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
225 |
|
| 24121 |
govind |
226 |
@Autowired
|
|
|
227 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
228 |
|
| 23724 |
amit.gupta |
229 |
@Value("${prod}")
|
|
|
230 |
private boolean prod;
|
|
|
231 |
|
| 23929 |
amit.gupta |
232 |
@Autowired
|
|
|
233 |
private RetailerService retailerService;
|
|
|
234 |
|
|
|
235 |
@Autowired
|
|
|
236 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
237 |
|
| 24249 |
amit.gupta |
238 |
@Autowired
|
|
|
239 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
240 |
|
|
|
241 |
@Autowired
|
|
|
242 |
private OrderRepository orderRepository;
|
|
|
243 |
|
|
|
244 |
@Autowired
|
| 24241 |
amit.gupta |
245 |
private SchemeRepository schemeRepository;
|
|
|
246 |
|
|
|
247 |
@Autowired
|
| 23929 |
amit.gupta |
248 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
249 |
|
| 24174 |
govind |
250 |
@Autowired
|
| 24431 |
amit.gupta |
251 |
private PriceDropRepository priceDropRepository;
|
|
|
252 |
|
|
|
253 |
@Autowired
|
| 24174 |
govind |
254 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
255 |
|
|
|
256 |
@Autowired
|
|
|
257 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
258 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
259 |
|
|
|
260 |
@Autowired
|
|
|
261 |
private InventoryService inventoryService;
|
|
|
262 |
|
| 24533 |
govind |
263 |
@Autowired
|
|
|
264 |
private TicketRepository ticketRepository;
|
|
|
265 |
|
|
|
266 |
@Autowired
|
|
|
267 |
private TicketAssignedRepository ticketAssignedRepository;
|
|
|
268 |
|
|
|
269 |
@Autowired
|
|
|
270 |
private AuthRepository authRepository;
|
|
|
271 |
|
| 24542 |
amit.gupta |
272 |
@Autowired
|
|
|
273 |
private AddressRepository addressRepository;
|
|
|
274 |
|
|
|
275 |
@Autowired
|
|
|
276 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
277 |
|
| 23755 |
amit.gupta |
278 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
279 |
|
|
|
280 |
public void generateDailyRecharge() {
|
|
|
281 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
282 |
.selectAll(0, 2000);
|
|
|
283 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
284 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
285 |
|
|
|
286 |
rechargeProviders.stream().forEach(x -> {
|
|
|
287 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
288 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
289 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
290 |
|
|
|
291 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
292 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
293 |
float previousDayClosing = 0;
|
|
|
294 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
295 |
while (date.isBefore(endDate)) {
|
|
|
296 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
297 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
298 |
date.plusDays(1).atStartOfDay());
|
|
|
299 |
|
|
|
300 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
301 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
302 |
|
|
|
303 |
float dailyAmount = 0;
|
|
|
304 |
float totalCommission = 0;
|
|
|
305 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
306 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
307 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
308 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
309 |
}
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
313 |
float dailyWalletRecharge = 0;
|
|
|
314 |
if (rechargeHistoryList != null) {
|
|
|
315 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
316 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
317 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
322 |
DailyRecharge dailyRecharge = null;
|
|
|
323 |
try {
|
|
|
324 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
325 |
} catch (Exception e) {
|
|
|
326 |
LOGGER.info("Could not find Recharge entry");
|
|
|
327 |
}
|
|
|
328 |
if (dailyRecharge == null) {
|
|
|
329 |
dailyRecharge = new DailyRecharge();
|
|
|
330 |
dailyRecharge.setCreateDate(date);
|
|
|
331 |
}
|
|
|
332 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
333 |
dailyRecharge.setProviderId(x.getId());
|
|
|
334 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
335 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
336 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
337 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
338 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
339 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
340 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
341 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
342 |
}
|
|
|
343 |
date = date.plusDays(1);
|
|
|
344 |
}
|
|
|
345 |
rechargeProviderRepository.persist(x);
|
|
|
346 |
});
|
| 23761 |
amit.gupta |
347 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
348 |
}
|
|
|
349 |
|
| 23738 |
amit.gupta |
350 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
351 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
352 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
353 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
354 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
355 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
356 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
357 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
358 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
359 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
360 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
361 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
362 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
363 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
364 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
365 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
366 |
try {
|
|
|
367 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
368 |
if (providerId == 1) {
|
|
|
369 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
370 |
rechargeTransaction);
|
|
|
371 |
} else if (providerId == 2) {
|
|
|
372 |
thinkWalnutDigitalRechargeProviderService
|
|
|
373 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
374 |
}
|
|
|
375 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
376 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
377 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
378 |
rechargeTransaction.getStatus());
|
|
|
379 |
}
|
|
|
380 |
} catch (Exception e) {
|
|
|
381 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
382 |
}
|
|
|
383 |
}
|
| 23738 |
amit.gupta |
384 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
385 |
}
|
| 24240 |
amit.gupta |
386 |
|
|
|
387 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
388 |
public void migrateInvoice() {
|
|
|
389 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
390 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
391 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
392 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
393 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
394 |
int sequence = 0;
|
|
|
395 |
String prefix = "";
|
| 24241 |
amit.gupta |
396 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
397 |
.collect(Collectors.toList());
|
|
|
398 |
for (FofoOrder order : sortedList) {
|
|
|
399 |
|
| 24240 |
amit.gupta |
400 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
401 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
402 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
403 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
404 |
} else {
|
|
|
405 |
sequence += 1;
|
| 24241 |
amit.gupta |
406 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
407 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
408 |
fofoOrderRepository.persist(order);
|
|
|
409 |
}
|
|
|
410 |
}
|
| 24241 |
amit.gupta |
411 |
|
| 24237 |
amit.gupta |
412 |
}
|
|
|
413 |
}
|
| 23724 |
amit.gupta |
414 |
|
| 24241 |
amit.gupta |
415 |
// Temporary Method
|
| 24252 |
amit.gupta |
416 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
417 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
418 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
419 |
|
|
|
420 |
List<List<Object>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
421 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
422 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
423 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
424 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
425 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
426 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
427 |
if (x.getActiveTimestamp() != null) {
|
|
|
428 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
429 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
430 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
431 |
}
|
| 24250 |
amit.gupta |
432 |
for (SchemeInOut sio : sioList) {
|
|
|
433 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
434 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
435 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
436 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
437 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
438 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
439 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
440 |
if (record.isPresent()) {
|
|
|
441 |
int fofoId = record.get().getFofoId();
|
|
|
442 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
443 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
444 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
445 |
userAmountMap.put(fofoId, 0f);
|
|
|
446 |
}
|
|
|
447 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
448 |
try {
|
| 24252 |
amit.gupta |
449 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
450 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
451 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
452 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
453 |
fofoOrder.getInvoiceNumber(),
|
|
|
454 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
455 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
456 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
457 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
458 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
459 |
} catch (Exception e) {
|
|
|
460 |
e.printStackTrace();
|
|
|
461 |
}
|
| 24242 |
amit.gupta |
462 |
}
|
| 24241 |
amit.gupta |
463 |
}
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
}
|
|
|
467 |
});
|
| 24246 |
amit.gupta |
468 |
userAmountMap.entrySet().stream()
|
|
|
469 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
470 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
471 |
|
| 24252 |
amit.gupta |
472 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
473 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
474 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
475 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
476 |
|
| 24241 |
amit.gupta |
477 |
}
|
| 24271 |
amit.gupta |
478 |
|
| 24256 |
amit.gupta |
479 |
public void processScheme(int offset) throws Exception {
|
| 24462 |
amit.gupta |
480 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
481 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 24258 |
amit.gupta |
482 |
processScheme(startDate, endDate);
|
| 24256 |
amit.gupta |
483 |
}
|
| 24533 |
govind |
484 |
|
| 24461 |
amit.gupta |
485 |
public void processScheme(int offset, int durationDays) throws Exception {
|
| 24462 |
amit.gupta |
486 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
487 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
|
|
488 |
processScheme(startDate, endDate);
|
|
|
489 |
}
|
| 24271 |
amit.gupta |
490 |
|
| 23738 |
amit.gupta |
491 |
public void processScheme() throws Exception {
|
| 24256 |
amit.gupta |
492 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
|
|
493 |
processScheme(fromDate, LocalDateTime.now());
|
|
|
494 |
}
|
| 24271 |
amit.gupta |
495 |
|
| 24256 |
amit.gupta |
496 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 23724 |
amit.gupta |
497 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 24561 |
amit.gupta |
498 |
try {
|
| 24587 |
amit.gupta |
499 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
500 |
for (Purchase purchase : purchases) {
|
|
|
501 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
502 |
}
|
| 24271 |
amit.gupta |
503 |
|
| 24587 |
amit.gupta |
504 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
505 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
506 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
507 |
}
|
|
|
508 |
} catch (Exception e) {
|
| 24561 |
amit.gupta |
509 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
510 |
throw e;
|
| 24561 |
amit.gupta |
511 |
}
|
| 23724 |
amit.gupta |
512 |
LOGGER.info("Schemes process successfully.");
|
|
|
513 |
}
|
| 23929 |
amit.gupta |
514 |
|
| 23739 |
amit.gupta |
515 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
516 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
517 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
518 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
519 |
.getPendingCashBackRehargeTransactions();
|
|
|
520 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
521 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
522 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
523 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
524 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
525 |
if (Math.round(amount) > 0) {
|
|
|
526 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
527 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
528 |
}
|
| 23739 |
amit.gupta |
529 |
}
|
| 23929 |
amit.gupta |
530 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
531 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
532 |
rt.setCashbackReference(referenceId);
|
|
|
533 |
rechargeTransactionRepository.persist(rt);
|
|
|
534 |
}
|
| 23739 |
amit.gupta |
535 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
536 |
}
|
| 23724 |
amit.gupta |
537 |
|
| 24271 |
amit.gupta |
538 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
539 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 23929 |
amit.gupta |
540 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
|
|
541 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
542 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
543 |
|
| 24271 |
amit.gupta |
544 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
|
|
545 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
|
|
546 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 24002 |
amit.gupta |
547 |
List<List<Object>> rows = new ArrayList<>();
|
|
|
548 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
549 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
|
|
550 |
if (retailer == null) {
|
|
|
551 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
552 |
continue;
|
|
|
553 |
}
|
| 24533 |
govind |
554 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
|
|
555 |
1);
|
| 24337 |
amit.gupta |
556 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
557 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 24533 |
govind |
558 |
|
| 24002 |
amit.gupta |
559 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| 24337 |
amit.gupta |
560 |
retailer.getMobileNumber(), partnerDailyInvestment.getWalletAmount(),
|
|
|
561 |
partnerDailyInvestment.getSalesAmount(), partnerDailyInvestment.getInStockAmount(), 0,
|
| 24415 |
amit.gupta |
562 |
partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
| 24533 |
govind |
563 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
|
|
564 |
partnerDailyInvestment.getShortInvestment());
|
| 24002 |
amit.gupta |
565 |
rows.add(row);
|
|
|
566 |
|
| 23929 |
amit.gupta |
567 |
}
|
| 24271 |
amit.gupta |
568 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 24002 |
amit.gupta |
569 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
570 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
571 |
|
|
|
572 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
|
|
573 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
574 |
|
| 23929 |
amit.gupta |
575 |
}
|
| 24177 |
govind |
576 |
|
| 24271 |
amit.gupta |
577 |
public void sendPartnerInvestmentDetails() throws Exception {
|
|
|
578 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
|
|
579 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
|
|
580 |
"neeraj.gupta@smartdukaan.com");
|
|
|
581 |
this.sendPartnerInvestmentDetails(sendTo);
|
|
|
582 |
|
|
|
583 |
}
|
|
|
584 |
|
| 24177 |
govind |
585 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 24187 |
govind |
586 |
Map<String, InputStream> inputStreams)
|
| 24177 |
govind |
587 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 24121 |
govind |
588 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24177 |
govind |
589 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
590 |
helper.setSubject(subject);
|
|
|
591 |
helper.setText(body);
|
|
|
592 |
if (ccEmails != null) {
|
|
|
593 |
helper.setCc(ccEmails);
|
|
|
594 |
}
|
| 24240 |
amit.gupta |
595 |
for (String attachment : inputStreams.keySet()) {
|
|
|
596 |
helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
|
|
|
597 |
new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
|
| 24187 |
govind |
598 |
}
|
| 24177 |
govind |
599 |
helper.setTo(email);
|
| 24195 |
govind |
600 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24177 |
govind |
601 |
helper.setFrom(senderAddress);
|
|
|
602 |
mailSender.send(message);
|
| 24135 |
govind |
603 |
}
|
| 24240 |
amit.gupta |
604 |
|
|
|
605 |
private void sendMailWithAttachmentsForPartners(String email, String body, String subject, InputStream is)
|
| 24184 |
govind |
606 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
607 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
608 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
609 |
helper.setSubject(subject);
|
|
|
610 |
helper.setText(body);
|
| 24240 |
amit.gupta |
611 |
helper.addAttachment("DailySaleTargetReports_" + LocalDate.now() + ".xls",
|
|
|
612 |
new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 24184 |
govind |
613 |
helper.setTo(email);
|
| 24195 |
govind |
614 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24184 |
govind |
615 |
helper.setFrom(senderAddress);
|
|
|
616 |
mailSender.send(message);
|
|
|
617 |
}
|
| 24177 |
govind |
618 |
|
|
|
619 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail)
|
|
|
620 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
621 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
622 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
623 |
Map<String, InputStream> inputStreams = new HashMap<>();
|
|
|
624 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
625 |
InputStream is = targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,
|
|
|
626 |
salesHeadDetail.getName());
|
| 24240 |
amit.gupta |
627 |
|
| 24177 |
govind |
628 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
|
|
629 |
|
| 24174 |
govind |
630 |
}
|
| 24240 |
amit.gupta |
631 |
// String[] ccEmails = null;
|
| 24271 |
amit.gupta |
632 |
if (partnerTargetDetails.size() > 0) {
|
| 24254 |
govind |
633 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
|
|
634 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
|
|
635 |
String subject = "Daily Sales Report ";
|
|
|
636 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
|
|
637 |
LOGGER.info("message" + message);
|
|
|
638 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
|
|
639 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
640 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 24177 |
govind |
641 |
|
| 24271 |
amit.gupta |
642 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 24177 |
govind |
643 |
|
| 24271 |
amit.gupta |
644 |
} else {
|
|
|
645 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
646 |
String[] to = { salesHeadDetail.getEmail() };
|
|
|
647 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
|
|
648 |
}
|
| 24177 |
govind |
649 |
}
|
| 24121 |
govind |
650 |
}
|
| 24177 |
govind |
651 |
|
| 24240 |
amit.gupta |
652 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
|
|
653 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
| 24177 |
govind |
654 |
List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
|
|
|
655 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
|
|
|
656 |
.getFofoRetailers(new ArrayList<>(fofoIds));
|
| 24240 |
amit.gupta |
657 |
List<InputStream> input = new ArrayList<>();
|
| 24177 |
govind |
658 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
659 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
660 |
for (Integer fofoId : fofoIds) {
|
| 24240 |
amit.gupta |
661 |
InputStream is = targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetails);
|
|
|
662 |
LOGGER.info("is" + is);
|
|
|
663 |
if (is == null) {
|
| 24192 |
govind |
664 |
continue;
|
|
|
665 |
}
|
| 24240 |
amit.gupta |
666 |
LOGGER.info("fofoId" + fofoId);
|
|
|
667 |
|
| 24177 |
govind |
668 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| 24240 |
amit.gupta |
669 |
String subject = "Daily Sales Report";
|
|
|
670 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 24177 |
govind |
671 |
LOGGER.info(message);
|
| 24240 |
amit.gupta |
672 |
this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
|
|
|
673 |
is);
|
|
|
674 |
|
| 24174 |
govind |
675 |
}
|
|
|
676 |
}
|
| 24533 |
govind |
677 |
|
|
|
678 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
679 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
680 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
681 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
682 |
}
|
|
|
683 |
}
|
| 23929 |
amit.gupta |
684 |
|
| 24542 |
amit.gupta |
685 |
public void walletmismatch() throws Exception {
|
|
|
686 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
687 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
688 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
689 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
690 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
691 |
for (PartnerDailyInvestment investment : Lists
|
|
|
692 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
693 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
694 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
695 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24561 |
amit.gupta |
696 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), investment.getDate().toString(),
|
|
|
697 |
investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
698 |
|
| 24542 |
amit.gupta |
699 |
}
|
| 24549 |
amit.gupta |
700 |
}
|
| 24542 |
amit.gupta |
701 |
|
|
|
702 |
}
|
|
|
703 |
|
| 24533 |
govind |
704 |
public void escalateTicket() throws ProfitMandiBusinessException {
|
|
|
705 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTickets();
|
| 24571 |
amit.gupta |
706 |
LocalDateTime now = LocalDateTime.now();
|
| 24533 |
govind |
707 |
for (Ticket ticket : tickets) {
|
| 24571 |
amit.gupta |
708 |
if (ticket.getL2EscalationTimestamp().isBefore(now) && ticket.getL3EscalationTimestamp().isAfter(now)) {
|
| 24533 |
govind |
709 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
710 |
.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
|
|
|
711 |
if (ticketAssigned == null) {
|
|
|
712 |
ticketAssigned = new TicketAssigned();
|
|
|
713 |
ticketAssigned.setAssineeId(ticket.getL2AuthUser());
|
|
|
714 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
715 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
716 |
String subject = "Escalated Ticket";
|
|
|
717 |
LOGGER.info(subject);
|
|
|
718 |
|
|
|
719 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
720 |
authRepository.selectById(ticket.getL1AuthUser()).getFirstName(),
|
|
|
721 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
722 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName());
|
|
|
723 |
LOGGER.info(message);
|
|
|
724 |
|
|
|
725 |
String[] cc = { authRepository.selectById(ticket.getL2AuthUser()).getEmailId() };
|
|
|
726 |
LOGGER.info(cc[0]);
|
|
|
727 |
|
|
|
728 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
|
|
729 |
LOGGER.info(to);
|
|
|
730 |
|
|
|
731 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
732 |
LOGGER.info(subject + " " + message + " " + to + " " + cc[0]);
|
|
|
733 |
}
|
| 24571 |
amit.gupta |
734 |
} else if (ticket.getL3EscalationTimestamp().isBefore(now)
|
|
|
735 |
&& ticket.getLastEscalationTimestamp().isAfter(now)) {
|
| 24533 |
govind |
736 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
737 |
.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
|
|
|
738 |
if (ticketAssigned == null) {
|
|
|
739 |
ticketAssigned = new TicketAssigned();
|
|
|
740 |
ticketAssigned.setAssineeId(ticket.getL3AuthUser());
|
|
|
741 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
742 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
743 |
String subject = "Escalated Ticket";
|
|
|
744 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
745 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName(),
|
|
|
746 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
747 |
authRepository.selectById(ticket.getL3AuthUser()).getFirstName());
|
|
|
748 |
LOGGER.info(subject);
|
|
|
749 |
LOGGER.info(message);
|
|
|
750 |
String[] cc = { authRepository.selectById(ticket.getL3AuthUser()).getEmailId() };
|
|
|
751 |
LOGGER.info(cc[0]);
|
|
|
752 |
|
|
|
753 |
String to = authRepository.selectById(ticket.getL2AuthUser()).getEmailId();
|
|
|
754 |
LOGGER.info(to);
|
|
|
755 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
756 |
LOGGER.info(subject);
|
|
|
757 |
}
|
|
|
758 |
}
|
|
|
759 |
}
|
|
|
760 |
}
|
|
|
761 |
|
|
|
762 |
private void sendEscaltedTicketMail(String to, String subject, String message, String[] cc)
|
|
|
763 |
throws ProfitMandiBusinessException {
|
|
|
764 |
try {
|
|
|
765 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
766 |
LOGGER.info("mail send successfully");
|
|
|
767 |
} catch (Exception e) {
|
|
|
768 |
throw new ProfitMandiBusinessException("Escalated Ticket", to, "Could not send Escalated ticket mail");
|
|
|
769 |
}
|
|
|
770 |
}
|
|
|
771 |
|
| 24542 |
amit.gupta |
772 |
public void gst() throws Exception {
|
| 24548 |
amit.gupta |
773 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
|
|
|
774 |
LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
|
|
|
775 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
776 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
777 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
778 |
|
|
|
779 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
780 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
781 |
Integer stateId = null;
|
|
|
782 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
783 |
try {
|
|
|
784 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
785 |
} catch (Exception e) {
|
|
|
786 |
LOGGER.error("Unable to get state rates");
|
|
|
787 |
}
|
|
|
788 |
}
|
|
|
789 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
790 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
791 |
|
|
|
792 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
793 |
Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 24542 |
amit.gupta |
794 |
if (stateId != null) {
|
|
|
795 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
|
|
|
796 |
} else {
|
|
|
797 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
|
|
|
798 |
}
|
|
|
799 |
|
| 24548 |
amit.gupta |
800 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 24542 |
amit.gupta |
801 |
if (stateId == null) {
|
|
|
802 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
803 |
} else {
|
|
|
804 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
805 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
806 |
}
|
|
|
807 |
fofoOrderItemRepository.persist(foi);
|
|
|
808 |
}
|
|
|
809 |
}
|
| 24548 |
amit.gupta |
810 |
|
| 24542 |
amit.gupta |
811 |
}
|
|
|
812 |
|
| 24580 |
amit.gupta |
813 |
public void schemewalletmismatch() {
|
|
|
814 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
815 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
816 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
817 |
// reconcileOrders(dateTime);
|
|
|
818 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
819 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
820 |
}
|
|
|
821 |
}
|
|
|
822 |
|
|
|
823 |
private void reconcileSchemes(LocalDate date) {
|
|
|
824 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
825 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
826 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
827 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
828 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
829 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
830 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
831 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
832 |
WalletReferenceType.SCHEME_OUT);
|
|
|
833 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
834 |
walletReferenceTypes);
|
|
|
835 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
836 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
837 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
838 |
|
|
|
839 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
840 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
841 |
|
|
|
842 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
843 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
844 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
845 |
|
|
|
846 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
847 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
848 |
|
|
|
849 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
850 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
851 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
852 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
853 |
|
|
|
854 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
|
|
855 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeMap.entrySet()) {
|
|
|
856 |
}
|
|
|
857 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
858 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
859 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
860 |
} else {
|
|
|
861 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
862 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
863 |
}
|
|
|
864 |
}
|
| 24590 |
amit.gupta |
865 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
866 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
867 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
868 |
|
| 24587 |
amit.gupta |
869 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
870 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
871 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
872 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
873 |
if (diff > 5) {
|
|
|
874 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
875 |
}
|
|
|
876 |
}
|
| 24580 |
amit.gupta |
877 |
}
|
| 24587 |
amit.gupta |
878 |
|
| 24580 |
amit.gupta |
879 |
}
|
| 24590 |
amit.gupta |
880 |
|
|
|
881 |
public void dryRunSchemeReco() {
|
|
|
882 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
883 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
884 |
LocalDateTime startDate = LocalDate.of(2018, 9, 4).atStartOfDay();
|
|
|
885 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
886 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
887 |
allOrders.stream().forEach(fofoOrder -> {
|
|
|
888 |
List<Integer> inventoryItemIds = new ArrayList<>();
|
|
|
889 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
890 |
orderItems.forEach(x -> {
|
|
|
891 |
inventoryItemIds.addAll(x.getFofoLineItems().stream().map(FofoLineItem::getInventoryItemId)
|
|
|
892 |
.collect(Collectors.toSet()));
|
|
|
893 |
});
|
|
|
894 |
List<SchemeType> sios = schemeInOutRepository.selectAllDuplicate(inventoryItemIds).stream()
|
|
|
895 |
.map(x -> schemeTypeMap.get(x.getSchemeId()))
|
|
|
896 |
.filter(schemeType -> schemeType.equals(SchemeType.OUT)).collect(Collectors.toList());
|
|
|
897 |
if (sios.size() > 0) {
|
|
|
898 |
LOGGER.info("Found {} duplicate scheme outs for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
899 |
}
|
|
|
900 |
});
|
|
|
901 |
}
|
| 24587 |
amit.gupta |
902 |
}
|
| 24580 |
amit.gupta |
903 |
|
| 24587 |
amit.gupta |
904 |
/*
|
|
|
905 |
* public void processSchemeForModel(String string) { pricingService
|
|
|
906 |
*
|
|
|
907 |
* }
|
|
|
908 |
*/
|