| 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;
|
| 23724 |
amit.gupta |
18 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
19 |
|
| 24121 |
govind |
20 |
import javax.mail.MessagingException;
|
|
|
21 |
import javax.mail.internet.InternetAddress;
|
|
|
22 |
import javax.mail.internet.MimeMessage;
|
|
|
23 |
|
|
|
24 |
import org.apache.commons.codec.CharEncoding;
|
|
|
25 |
import org.apache.commons.io.IOUtils;
|
| 23929 |
amit.gupta |
26 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23755 |
amit.gupta |
27 |
import org.apache.logging.log4j.LogManager;
|
|
|
28 |
import org.apache.logging.log4j.Logger;
|
| 24184 |
govind |
29 |
import org.apache.poi.EncryptedDocumentException;
|
|
|
30 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| 23723 |
amit.gupta |
31 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
32 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
33 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
34 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
35 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
36 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
37 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
38 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
39 |
|
| 23724 |
amit.gupta |
40 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24121 |
govind |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
42 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23724 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 24002 |
amit.gupta |
44 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
45 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 24533 |
govind |
47 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
|
|
48 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 23724 |
amit.gupta |
49 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
|
|
50 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
|
|
53 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 23929 |
amit.gupta |
54 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24174 |
govind |
57 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 23724 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24174 |
govind |
59 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 24242 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 24431 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 24250 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 24242 |
amit.gupta |
64 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24533 |
govind |
65 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 24249 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 24533 |
govind |
68 |
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
|
|
|
69 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23724 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
73 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
74 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
|
|
75 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
78 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 23724 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23929 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24431 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24337 |
amit.gupta |
84 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23929 |
amit.gupta |
85 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24271 |
amit.gupta |
86 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
87 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
88 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
89 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
90 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
91 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
92 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
93 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
94 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
95 |
|
| 24197 |
amit.gupta |
96 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
97 |
|
| 23723 |
amit.gupta |
98 |
@Component
|
| 23724 |
amit.gupta |
99 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
100 |
public class ScheduledTasks {
|
|
|
101 |
|
| 24533 |
govind |
102 |
private static final String Escalate_TICKET = "Dear {0},Your Ticket created by {1} is escalated and assigned to {2}. Regards \nSmartdukaan";
|
|
|
103 |
|
| 23724 |
amit.gupta |
104 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
105 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
106 |
|
| 23724 |
amit.gupta |
107 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
108 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
109 |
|
| 24431 |
amit.gupta |
110 |
@Autowired
|
|
|
111 |
private PriceDropService priceDropService;
|
| 23723 |
amit.gupta |
112 |
|
| 23724 |
amit.gupta |
113 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
114 |
private String oxigenRechargeAuthKey;
|
|
|
115 |
|
|
|
116 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
117 |
private String oxigenRechargeValidationUrl;
|
|
|
118 |
|
|
|
119 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
120 |
private String oxigenRechargeValidationAuthKey;
|
|
|
121 |
|
|
|
122 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
123 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
124 |
|
|
|
125 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
126 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
127 |
|
|
|
128 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
129 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
130 |
|
|
|
131 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
132 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
133 |
|
|
|
134 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
135 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
136 |
|
|
|
137 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
138 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
139 |
|
|
|
140 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
141 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
142 |
|
| 23723 |
amit.gupta |
143 |
@Autowired
|
| 23724 |
amit.gupta |
144 |
private PurchaseRepository purchaseRepository;
|
|
|
145 |
|
|
|
146 |
@Autowired
|
|
|
147 |
private SchemeService schemeService;
|
|
|
148 |
|
|
|
149 |
@Autowired
|
| 24271 |
amit.gupta |
150 |
private OrderService orderService;
|
|
|
151 |
|
|
|
152 |
@Autowired
|
| 24337 |
amit.gupta |
153 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
154 |
|
|
|
155 |
@Autowired
|
| 24277 |
amit.gupta |
156 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
157 |
|
|
|
158 |
@Autowired
|
| 24241 |
amit.gupta |
159 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
160 |
|
|
|
161 |
@Autowired
|
| 23724 |
amit.gupta |
162 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
163 |
|
|
|
164 |
@Autowired
|
|
|
165 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
166 |
|
|
|
167 |
@Autowired
|
|
|
168 |
private FofoOrderRepository fofoOrderRepository;
|
| 24250 |
amit.gupta |
169 |
|
| 24249 |
amit.gupta |
170 |
@Autowired
|
|
|
171 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
172 |
|
| 23739 |
amit.gupta |
173 |
@Autowired
|
|
|
174 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
175 |
|
|
|
176 |
@Autowired
|
|
|
177 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
178 |
|
|
|
179 |
@Autowired
|
|
|
180 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
181 |
|
|
|
182 |
@Autowired
|
|
|
183 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
184 |
|
|
|
185 |
@Autowired
|
| 24242 |
amit.gupta |
186 |
private ScanRecordRepository scanRecordRepository;
|
|
|
187 |
|
|
|
188 |
@Autowired
|
| 23724 |
amit.gupta |
189 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
190 |
|
| 23929 |
amit.gupta |
191 |
@Autowired
|
|
|
192 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
193 |
|
| 24121 |
govind |
194 |
@Autowired
|
|
|
195 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
196 |
|
| 23724 |
amit.gupta |
197 |
@Value("${prod}")
|
|
|
198 |
private boolean prod;
|
|
|
199 |
|
| 23929 |
amit.gupta |
200 |
@Autowired
|
|
|
201 |
private RetailerService retailerService;
|
|
|
202 |
|
|
|
203 |
@Autowired
|
|
|
204 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
205 |
|
| 24249 |
amit.gupta |
206 |
@Autowired
|
|
|
207 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
208 |
|
|
|
209 |
@Autowired
|
|
|
210 |
private OrderRepository orderRepository;
|
|
|
211 |
|
|
|
212 |
@Autowired
|
| 24241 |
amit.gupta |
213 |
private SchemeRepository schemeRepository;
|
|
|
214 |
|
|
|
215 |
@Autowired
|
| 23929 |
amit.gupta |
216 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
217 |
|
| 24174 |
govind |
218 |
@Autowired
|
| 24431 |
amit.gupta |
219 |
private PriceDropRepository priceDropRepository;
|
|
|
220 |
|
|
|
221 |
@Autowired
|
| 24174 |
govind |
222 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
223 |
|
|
|
224 |
@Autowired
|
|
|
225 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
226 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
227 |
|
|
|
228 |
@Autowired
|
|
|
229 |
private InventoryService inventoryService;
|
|
|
230 |
|
| 24533 |
govind |
231 |
@Autowired
|
|
|
232 |
private TicketRepository ticketRepository;
|
|
|
233 |
|
|
|
234 |
@Autowired
|
|
|
235 |
private TicketAssignedRepository ticketAssignedRepository;
|
|
|
236 |
|
|
|
237 |
@Autowired
|
|
|
238 |
private AuthRepository authRepository;
|
|
|
239 |
|
| 23755 |
amit.gupta |
240 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
241 |
|
|
|
242 |
public void generateDailyRecharge() {
|
|
|
243 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
244 |
.selectAll(0, 2000);
|
|
|
245 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
246 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
247 |
|
|
|
248 |
rechargeProviders.stream().forEach(x -> {
|
|
|
249 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
250 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
251 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
252 |
|
|
|
253 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
254 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
255 |
float previousDayClosing = 0;
|
|
|
256 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
257 |
while (date.isBefore(endDate)) {
|
|
|
258 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
259 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
260 |
date.plusDays(1).atStartOfDay());
|
|
|
261 |
|
|
|
262 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
263 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
264 |
|
|
|
265 |
float dailyAmount = 0;
|
|
|
266 |
float totalCommission = 0;
|
|
|
267 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
268 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
269 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
270 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
275 |
float dailyWalletRecharge = 0;
|
|
|
276 |
if (rechargeHistoryList != null) {
|
|
|
277 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
278 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
279 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
284 |
DailyRecharge dailyRecharge = null;
|
|
|
285 |
try {
|
|
|
286 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
287 |
} catch (Exception e) {
|
|
|
288 |
LOGGER.info("Could not find Recharge entry");
|
|
|
289 |
}
|
|
|
290 |
if (dailyRecharge == null) {
|
|
|
291 |
dailyRecharge = new DailyRecharge();
|
|
|
292 |
dailyRecharge.setCreateDate(date);
|
|
|
293 |
}
|
|
|
294 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
295 |
dailyRecharge.setProviderId(x.getId());
|
|
|
296 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
297 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
298 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
299 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
300 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
301 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
302 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
303 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
304 |
}
|
|
|
305 |
date = date.plusDays(1);
|
|
|
306 |
}
|
|
|
307 |
rechargeProviderRepository.persist(x);
|
|
|
308 |
});
|
| 23761 |
amit.gupta |
309 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
310 |
}
|
|
|
311 |
|
| 23738 |
amit.gupta |
312 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
313 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
314 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
315 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
316 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
317 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
318 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
319 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
320 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
321 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
322 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
323 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
324 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
325 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
326 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
327 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
328 |
try {
|
|
|
329 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
330 |
if (providerId == 1) {
|
|
|
331 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
332 |
rechargeTransaction);
|
|
|
333 |
} else if (providerId == 2) {
|
|
|
334 |
thinkWalnutDigitalRechargeProviderService
|
|
|
335 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
336 |
}
|
|
|
337 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
338 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
339 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
340 |
rechargeTransaction.getStatus());
|
|
|
341 |
}
|
|
|
342 |
} catch (Exception e) {
|
|
|
343 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
344 |
}
|
|
|
345 |
}
|
| 23738 |
amit.gupta |
346 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
347 |
}
|
| 24240 |
amit.gupta |
348 |
|
|
|
349 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
350 |
public void migrateInvoice() {
|
|
|
351 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
352 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
353 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
354 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
355 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
356 |
int sequence = 0;
|
|
|
357 |
String prefix = "";
|
| 24241 |
amit.gupta |
358 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
359 |
.collect(Collectors.toList());
|
|
|
360 |
for (FofoOrder order : sortedList) {
|
|
|
361 |
|
| 24240 |
amit.gupta |
362 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
363 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
364 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
365 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
366 |
} else {
|
|
|
367 |
sequence += 1;
|
| 24241 |
amit.gupta |
368 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
369 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
370 |
fofoOrderRepository.persist(order);
|
|
|
371 |
}
|
|
|
372 |
}
|
| 24241 |
amit.gupta |
373 |
|
| 24237 |
amit.gupta |
374 |
}
|
|
|
375 |
}
|
| 23724 |
amit.gupta |
376 |
|
| 24241 |
amit.gupta |
377 |
// Temporary Method
|
| 24252 |
amit.gupta |
378 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
379 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
380 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
381 |
|
|
|
382 |
List<List<Object>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
383 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
384 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
385 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
386 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
387 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
388 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
389 |
if (x.getActiveTimestamp() != null) {
|
|
|
390 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
391 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
392 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
393 |
}
|
| 24250 |
amit.gupta |
394 |
for (SchemeInOut sio : sioList) {
|
|
|
395 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
396 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
397 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
398 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
399 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
400 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
401 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
402 |
if (record.isPresent()) {
|
|
|
403 |
int fofoId = record.get().getFofoId();
|
|
|
404 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
405 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
406 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
407 |
userAmountMap.put(fofoId, 0f);
|
|
|
408 |
}
|
|
|
409 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
410 |
try {
|
| 24252 |
amit.gupta |
411 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
412 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
413 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
414 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
415 |
fofoOrder.getInvoiceNumber(),
|
|
|
416 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
417 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
418 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
419 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
420 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
421 |
} catch (Exception e) {
|
|
|
422 |
e.printStackTrace();
|
|
|
423 |
}
|
| 24242 |
amit.gupta |
424 |
}
|
| 24241 |
amit.gupta |
425 |
}
|
|
|
426 |
}
|
|
|
427 |
}
|
|
|
428 |
}
|
|
|
429 |
});
|
| 24246 |
amit.gupta |
430 |
userAmountMap.entrySet().stream()
|
|
|
431 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
432 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
433 |
|
| 24252 |
amit.gupta |
434 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
435 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
436 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
437 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
438 |
|
| 24241 |
amit.gupta |
439 |
}
|
| 24271 |
amit.gupta |
440 |
|
| 24256 |
amit.gupta |
441 |
public void processScheme(int offset) throws Exception {
|
| 24462 |
amit.gupta |
442 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
443 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 24258 |
amit.gupta |
444 |
processScheme(startDate, endDate);
|
| 24256 |
amit.gupta |
445 |
}
|
| 24533 |
govind |
446 |
|
| 24461 |
amit.gupta |
447 |
public void processScheme(int offset, int durationDays) throws Exception {
|
| 24462 |
amit.gupta |
448 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
449 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
|
|
450 |
processScheme(startDate, endDate);
|
|
|
451 |
}
|
| 24271 |
amit.gupta |
452 |
|
| 23738 |
amit.gupta |
453 |
public void processScheme() throws Exception {
|
| 24256 |
amit.gupta |
454 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
|
|
455 |
processScheme(fromDate, LocalDateTime.now());
|
|
|
456 |
}
|
| 24271 |
amit.gupta |
457 |
|
| 24256 |
amit.gupta |
458 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 23724 |
amit.gupta |
459 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 24256 |
amit.gupta |
460 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 23724 |
amit.gupta |
461 |
for (Purchase purchase : purchases) {
|
|
|
462 |
try {
|
|
|
463 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
464 |
} catch (Exception e) {
|
|
|
465 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
|
|
466 |
e.printStackTrace();
|
| 24271 |
amit.gupta |
467 |
|
| 23724 |
amit.gupta |
468 |
}
|
|
|
469 |
}
|
| 24256 |
amit.gupta |
470 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 23724 |
amit.gupta |
471 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
472 |
try {
|
|
|
473 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
474 |
} catch (Exception e) {
|
|
|
475 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
|
|
476 |
}
|
|
|
477 |
}
|
|
|
478 |
LOGGER.info("Schemes process successfully.");
|
|
|
479 |
}
|
| 23929 |
amit.gupta |
480 |
|
| 23739 |
amit.gupta |
481 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
482 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
483 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
484 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
485 |
.getPendingCashBackRehargeTransactions();
|
|
|
486 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
487 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
488 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
489 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
490 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
491 |
if (Math.round(amount) > 0) {
|
|
|
492 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
493 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
494 |
}
|
| 23739 |
amit.gupta |
495 |
}
|
| 23929 |
amit.gupta |
496 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
497 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
498 |
rt.setCashbackReference(referenceId);
|
|
|
499 |
rechargeTransactionRepository.persist(rt);
|
|
|
500 |
}
|
| 23739 |
amit.gupta |
501 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
502 |
}
|
| 23724 |
amit.gupta |
503 |
|
| 24271 |
amit.gupta |
504 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
505 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 23929 |
amit.gupta |
506 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
|
|
507 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
508 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
509 |
|
| 24271 |
amit.gupta |
510 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
|
|
511 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
|
|
512 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 24002 |
amit.gupta |
513 |
List<List<Object>> rows = new ArrayList<>();
|
|
|
514 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
515 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
|
|
516 |
if (retailer == null) {
|
|
|
517 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
518 |
continue;
|
|
|
519 |
}
|
| 24533 |
govind |
520 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
|
|
521 |
1);
|
| 24337 |
amit.gupta |
522 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
523 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 24533 |
govind |
524 |
|
| 24002 |
amit.gupta |
525 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| 24337 |
amit.gupta |
526 |
retailer.getMobileNumber(), partnerDailyInvestment.getWalletAmount(),
|
|
|
527 |
partnerDailyInvestment.getSalesAmount(), partnerDailyInvestment.getInStockAmount(), 0,
|
| 24415 |
amit.gupta |
528 |
partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
| 24533 |
govind |
529 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
|
|
530 |
partnerDailyInvestment.getShortInvestment());
|
| 24002 |
amit.gupta |
531 |
rows.add(row);
|
|
|
532 |
|
| 23929 |
amit.gupta |
533 |
}
|
| 24271 |
amit.gupta |
534 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 24002 |
amit.gupta |
535 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
536 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
537 |
|
|
|
538 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
|
|
539 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
540 |
|
| 23929 |
amit.gupta |
541 |
}
|
| 24177 |
govind |
542 |
|
| 24271 |
amit.gupta |
543 |
public void sendPartnerInvestmentDetails() throws Exception {
|
|
|
544 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
|
|
545 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
|
|
546 |
"neeraj.gupta@smartdukaan.com");
|
|
|
547 |
this.sendPartnerInvestmentDetails(sendTo);
|
|
|
548 |
|
|
|
549 |
}
|
|
|
550 |
|
| 24177 |
govind |
551 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 24187 |
govind |
552 |
Map<String, InputStream> inputStreams)
|
| 24177 |
govind |
553 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 24121 |
govind |
554 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24177 |
govind |
555 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
556 |
helper.setSubject(subject);
|
|
|
557 |
helper.setText(body);
|
|
|
558 |
if (ccEmails != null) {
|
|
|
559 |
helper.setCc(ccEmails);
|
|
|
560 |
}
|
| 24240 |
amit.gupta |
561 |
for (String attachment : inputStreams.keySet()) {
|
|
|
562 |
helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
|
|
|
563 |
new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
|
| 24187 |
govind |
564 |
}
|
| 24177 |
govind |
565 |
helper.setTo(email);
|
| 24195 |
govind |
566 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24177 |
govind |
567 |
helper.setFrom(senderAddress);
|
|
|
568 |
mailSender.send(message);
|
| 24135 |
govind |
569 |
}
|
| 24240 |
amit.gupta |
570 |
|
|
|
571 |
private void sendMailWithAttachmentsForPartners(String email, String body, String subject, InputStream is)
|
| 24184 |
govind |
572 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
573 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
574 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
575 |
helper.setSubject(subject);
|
|
|
576 |
helper.setText(body);
|
| 24240 |
amit.gupta |
577 |
helper.addAttachment("DailySaleTargetReports_" + LocalDate.now() + ".xls",
|
|
|
578 |
new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 24184 |
govind |
579 |
helper.setTo(email);
|
| 24195 |
govind |
580 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24184 |
govind |
581 |
helper.setFrom(senderAddress);
|
|
|
582 |
mailSender.send(message);
|
|
|
583 |
}
|
| 24177 |
govind |
584 |
|
|
|
585 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail)
|
|
|
586 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
587 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
588 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
589 |
Map<String, InputStream> inputStreams = new HashMap<>();
|
|
|
590 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
591 |
InputStream is = targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,
|
|
|
592 |
salesHeadDetail.getName());
|
| 24240 |
amit.gupta |
593 |
|
| 24177 |
govind |
594 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
|
|
595 |
|
| 24174 |
govind |
596 |
}
|
| 24240 |
amit.gupta |
597 |
// String[] ccEmails = null;
|
| 24271 |
amit.gupta |
598 |
if (partnerTargetDetails.size() > 0) {
|
| 24254 |
govind |
599 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
|
|
600 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
|
|
601 |
String subject = "Daily Sales Report ";
|
|
|
602 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
|
|
603 |
LOGGER.info("message" + message);
|
|
|
604 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
|
|
605 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
606 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 24177 |
govind |
607 |
|
| 24271 |
amit.gupta |
608 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 24177 |
govind |
609 |
|
| 24271 |
amit.gupta |
610 |
} else {
|
|
|
611 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
612 |
String[] to = { salesHeadDetail.getEmail() };
|
|
|
613 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
|
|
614 |
}
|
| 24177 |
govind |
615 |
}
|
| 24121 |
govind |
616 |
}
|
| 24177 |
govind |
617 |
|
| 24240 |
amit.gupta |
618 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
|
|
619 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
| 24177 |
govind |
620 |
List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
|
|
|
621 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
|
|
|
622 |
.getFofoRetailers(new ArrayList<>(fofoIds));
|
| 24240 |
amit.gupta |
623 |
List<InputStream> input = new ArrayList<>();
|
| 24177 |
govind |
624 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
625 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
626 |
for (Integer fofoId : fofoIds) {
|
| 24240 |
amit.gupta |
627 |
InputStream is = targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetails);
|
|
|
628 |
LOGGER.info("is" + is);
|
|
|
629 |
if (is == null) {
|
| 24192 |
govind |
630 |
continue;
|
|
|
631 |
}
|
| 24240 |
amit.gupta |
632 |
LOGGER.info("fofoId" + fofoId);
|
|
|
633 |
|
| 24177 |
govind |
634 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| 24240 |
amit.gupta |
635 |
String subject = "Daily Sales Report";
|
|
|
636 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 24177 |
govind |
637 |
LOGGER.info(message);
|
| 24240 |
amit.gupta |
638 |
this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
|
|
|
639 |
is);
|
|
|
640 |
|
| 24174 |
govind |
641 |
}
|
|
|
642 |
}
|
| 24533 |
govind |
643 |
|
|
|
644 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
645 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
646 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
647 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
648 |
}
|
|
|
649 |
}
|
| 23929 |
amit.gupta |
650 |
|
| 24533 |
govind |
651 |
public void escalateTicket() throws ProfitMandiBusinessException {
|
|
|
652 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTickets();
|
|
|
653 |
for (Ticket ticket : tickets) {
|
|
|
654 |
if ((ticket.getL2EscalationTimestamp().isBefore(LocalDateTime.now())
|
|
|
655 |
|| ticket.getL2EscalationTimestamp().isEqual(LocalDateTime.now()))
|
|
|
656 |
&& ticket.getL3EscalationTimestamp().isAfter(LocalDateTime.now())) {
|
|
|
657 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
658 |
.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
|
|
|
659 |
if (ticketAssigned == null) {
|
|
|
660 |
ticketAssigned = new TicketAssigned();
|
|
|
661 |
ticketAssigned.setAssineeId(ticket.getL2AuthUser());
|
|
|
662 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
663 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
664 |
String subject = "Escalated Ticket";
|
|
|
665 |
LOGGER.info(subject);
|
|
|
666 |
|
|
|
667 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
668 |
authRepository.selectById(ticket.getL1AuthUser()).getFirstName(),
|
|
|
669 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
670 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName());
|
|
|
671 |
LOGGER.info(message);
|
|
|
672 |
|
|
|
673 |
String[] cc = { authRepository.selectById(ticket.getL2AuthUser()).getEmailId() };
|
|
|
674 |
LOGGER.info(cc[0]);
|
|
|
675 |
|
|
|
676 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
|
|
677 |
LOGGER.info(to);
|
|
|
678 |
|
|
|
679 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
680 |
LOGGER.info(subject + " " + message + " " + to + " " + cc[0]);
|
|
|
681 |
}
|
|
|
682 |
} else if ((ticket.getL3EscalationTimestamp().isBefore(LocalDateTime.now())
|
|
|
683 |
|| ticket.getL3EscalationTimestamp().isEqual(LocalDateTime.now()))
|
|
|
684 |
&& ticket.getLastEscalationTimestamp().isAfter(LocalDateTime.now())) {
|
|
|
685 |
|
|
|
686 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
687 |
.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
|
|
|
688 |
if (ticketAssigned == null) {
|
|
|
689 |
ticketAssigned = new TicketAssigned();
|
|
|
690 |
ticketAssigned.setAssineeId(ticket.getL3AuthUser());
|
|
|
691 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
692 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
693 |
String subject = "Escalated Ticket";
|
|
|
694 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
695 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName(),
|
|
|
696 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
697 |
authRepository.selectById(ticket.getL3AuthUser()).getFirstName());
|
|
|
698 |
LOGGER.info(subject);
|
|
|
699 |
LOGGER.info(message);
|
|
|
700 |
String[] cc = { authRepository.selectById(ticket.getL3AuthUser()).getEmailId() };
|
|
|
701 |
LOGGER.info(cc[0]);
|
|
|
702 |
|
|
|
703 |
String to = authRepository.selectById(ticket.getL2AuthUser()).getEmailId();
|
|
|
704 |
LOGGER.info(to);
|
|
|
705 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
706 |
LOGGER.info(subject);
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
}
|
|
|
710 |
}
|
|
|
711 |
|
|
|
712 |
private void sendEscaltedTicketMail(String to, String subject, String message, String[] cc)
|
|
|
713 |
throws ProfitMandiBusinessException {
|
|
|
714 |
try {
|
|
|
715 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
716 |
LOGGER.info("mail send successfully");
|
|
|
717 |
} catch (Exception e) {
|
|
|
718 |
throw new ProfitMandiBusinessException("Escalated Ticket", to, "Could not send Escalated ticket mail");
|
|
|
719 |
}
|
|
|
720 |
}
|
|
|
721 |
|
| 23724 |
amit.gupta |
722 |
}
|