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