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