| Line 6... |
Line 6... |
| 6 |
import java.time.LocalDateTime;
|
6 |
import java.time.LocalDateTime;
|
| 7 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 8 |
import java.util.Arrays;
|
8 |
import java.util.Arrays;
|
| 9 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 10 |
import java.util.HashSet;
|
10 |
import java.util.HashSet;
|
| - |
|
11 |
import java.util.LinkedHashMap;
|
| 11 |
import java.util.List;
|
12 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
13 |
import java.util.Map;
|
| 13 |
import java.util.Map.Entry;
|
14 |
import java.util.Map.Entry;
|
| 14 |
import java.util.Set;
|
15 |
import java.util.Set;
|
| 15 |
import java.util.stream.Collectors;
|
16 |
import java.util.stream.Collectors;
|
| Line 18... |
Line 19... |
| 18 |
import javax.transaction.Transactional;
|
19 |
import javax.transaction.Transactional;
|
| 19 |
|
20 |
|
| 20 |
import org.apache.logging.log4j.LogManager;
|
21 |
import org.apache.logging.log4j.LogManager;
|
| 21 |
import org.apache.logging.log4j.Logger;
|
22 |
import org.apache.logging.log4j.Logger;
|
| 22 |
import org.springframework.beans.factory.annotation.Autowired;
|
23 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
24 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 23 |
import org.springframework.stereotype.Controller;
|
25 |
import org.springframework.stereotype.Controller;
|
| 24 |
import org.springframework.ui.Model;
|
26 |
import org.springframework.ui.Model;
|
| 25 |
import org.springframework.web.bind.annotation.RequestBody;
|
27 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
28 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
29 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| Line 29... |
Line 31... |
| 29 |
|
31 |
|
| 30 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
32 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
33 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 32 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
34 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 33 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
35 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| - |
|
36 |
import com.spice.profitmandi.common.util.Utils;
|
| 34 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
37 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 35 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
38 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
| 36 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
39 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
| 37 |
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
|
40 |
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
|
| 38 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
41 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
42 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 40 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
43 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
| - |
|
44 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 41 |
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
|
45 |
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
|
| 42 |
import com.spice.profitmandi.dao.entity.transaction.SanctionRequest;
|
46 |
import com.spice.profitmandi.dao.entity.transaction.SanctionRequest;
|
| 43 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
47 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 44 |
import com.spice.profitmandi.dao.entity.user.Address;
|
48 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 45 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
49 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| Line 53... |
Line 57... |
| 53 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
57 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
58 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
59 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
60 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 57 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
61 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
| - |
|
62 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
| - |
|
63 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
64 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.transaction.SanctionRequestRepository;
|
65 |
import com.spice.profitmandi.dao.repository.transaction.SanctionRequestRepository;
|
| 60 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
66 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 61 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
67 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 62 |
import com.spice.profitmandi.service.NotificationService;
|
68 |
import com.spice.profitmandi.service.NotificationService;
|
| 63 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
69 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 64 |
import com.spice.profitmandi.service.user.RetailerService;
|
70 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 65 |
import com.spice.profitmandi.web.model.LoginDetails;
|
71 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 66 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
72 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| - |
|
73 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 67 |
|
74 |
|
| 68 |
@Controller
|
75 |
@Controller
|
| 69 |
@Transactional(rollbackOn = Throwable.class)
|
76 |
@Transactional(rollbackOn = Throwable.class)
|
| 70 |
public class SDCreditController {
|
77 |
public class SDCreditController {
|
| 71 |
|
78 |
|
| Line 116... |
Line 123... |
| 116 |
|
123 |
|
| 117 |
@Autowired
|
124 |
@Autowired
|
| 118 |
AddressRepository addressRepository;
|
125 |
AddressRepository addressRepository;
|
| 119 |
|
126 |
|
| 120 |
@Autowired
|
127 |
@Autowired
|
| - |
|
128 |
OrderRepository orderRepository;
|
| - |
|
129 |
|
| - |
|
130 |
@Autowired
|
| - |
|
131 |
private LoanStatementRepository loanStatementRepository;
|
| - |
|
132 |
|
| - |
|
133 |
@Autowired
|
| 121 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
134 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 122 |
|
135 |
|
| - |
|
136 |
@Autowired
|
| - |
|
137 |
private JavaMailSender mailSender;
|
| - |
|
138 |
|
| - |
|
139 |
@Autowired
|
| - |
|
140 |
private MVCResponseSender mvcResponseSender;
|
| - |
|
141 |
|
| 123 |
private static final Logger LOGGER = LogManager.getLogger(SDCreditController.class);
|
142 |
private static final Logger LOGGER = LogManager.getLogger(SDCreditController.class);
|
| 124 |
|
143 |
|
| 125 |
@RequestMapping(value = "/getSDCreditReq", method = RequestMethod.GET)
|
144 |
@RequestMapping(value = "/getSDCreditReq", method = RequestMethod.GET)
|
| 126 |
public String getSDCreditReq(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
145 |
public String getSDCreditReq(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 127 |
|
146 |
|
| Line 231... |
Line 250... |
| 231 |
@RequestMapping(value = "/getSanctionRequest", method = RequestMethod.GET)
|
250 |
@RequestMapping(value = "/getSanctionRequest", method = RequestMethod.GET)
|
| 232 |
public String getSanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
251 |
public String getSanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 233 |
|
252 |
|
| 234 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectByDate(LocalDate.now());
|
253 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectByDate(LocalDate.now());
|
| 235 |
|
254 |
|
| 236 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
255 |
if (!sanctionRequests.isEmpty()) {
|
| 237 |
|
256 |
|
| 238 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
257 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 239 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
- |
|
| 240 |
|
258 |
|
| 241 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds))
|
259 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll()
|
| 242 |
.stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
260 |
.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 243 |
|
261 |
|
| - |
|
262 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds))
|
| 244 |
if (!sanctionRequests.isEmpty()) {
|
263 |
.stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| 245 |
|
264 |
|
| 246 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
265 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
| 247 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository
|
266 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository
|
| 248 |
.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream()
|
267 |
.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream()
|
| 249 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
268 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 250 |
|
269 |
|
| 251 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
270 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| 252 |
|
271 |
|
| 253 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
272 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
| - |
|
273 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
| - |
|
274 |
|
| - |
|
275 |
model.addAttribute("userWalletMap", userWalletMap);
|
| 254 |
|
276 |
|
| 255 |
}
|
277 |
}
|
| 256 |
|
278 |
|
| 257 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
279 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| 258 |
|
280 |
|
| 259 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
- |
|
| 260 |
|
- |
|
| 261 |
model.addAttribute("userWalletMap", userWalletMap);
|
- |
|
| 262 |
|
- |
|
| 263 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
281 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
| 264 |
return "sanction-request";
|
282 |
return "sanction-request";
|
| 265 |
|
283 |
|
| 266 |
}
|
284 |
}
|
| 267 |
|
285 |
|
| Line 331... |
Line 349... |
| 331 |
+ sdCreditRequirementMap.get(sanctionRequest.getFofoId()).getFreeDays() + " days ");
|
349 |
+ sdCreditRequirementMap.get(sanctionRequest.getFofoId()).getFreeDays() + " days ");
|
| 332 |
}
|
350 |
}
|
| 333 |
|
351 |
|
| 334 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
352 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
| 335 |
sanctionRequest.setStatus(sanctionRequestModel.getStatus());
|
353 |
sanctionRequest.setStatus(sanctionRequestModel.getStatus());
|
| - |
|
354 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
| 336 |
|
355 |
|
| 337 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository
|
356 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository
|
| 338 |
.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream()
|
357 |
.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream()
|
| 339 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
358 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 340 |
|
359 |
|
| Line 417... |
Line 436... |
| 417 |
|
436 |
|
| 418 |
return "loan-summary-detail";
|
437 |
return "loan-summary-detail";
|
| 419 |
|
438 |
|
| 420 |
}
|
439 |
}
|
| 421 |
|
440 |
|
| - |
|
441 |
@RequestMapping(value = "/getSanctionHoldOrder", method = RequestMethod.GET)
|
| - |
|
442 |
public String getSanctionHoldOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
443 |
|
| - |
|
444 |
List<Order> allOrders = orderRepository.selectHoldOrder();
|
| - |
|
445 |
|
| - |
|
446 |
LOGGER.info("allOrders {}", allOrders);
|
| - |
|
447 |
|
| - |
|
448 |
if (!allOrders.isEmpty()) {
|
| - |
|
449 |
Map<Integer, Double> transactionAmountMap = allOrders.stream().collect(
|
| - |
|
450 |
Collectors.groupingBy(Order::getTransactionId, Collectors.summingDouble(x -> x.getTotalAmount())));
|
| - |
|
451 |
|
| - |
|
452 |
Map<Integer, List<Order>> transactionOrdersMap = allOrders.stream()
|
| - |
|
453 |
.collect(Collectors.groupingBy(Order::getTransactionId, Collectors.toList()));
|
| - |
|
454 |
|
| - |
|
455 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository
|
| - |
|
456 |
.selectByTransactionId(new ArrayList<>(transactionAmountMap.keySet()));
|
| - |
|
457 |
|
| - |
|
458 |
model.addAttribute("transactionAmountMap", transactionAmountMap);
|
| - |
|
459 |
|
| - |
|
460 |
model.addAttribute("transactionOrdersMap", transactionOrdersMap);
|
| - |
|
461 |
|
| - |
|
462 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| - |
|
463 |
|
| - |
|
464 |
Map<Integer, Double> transactionCreditMap = new HashMap<>();
|
| - |
|
465 |
for (Entry<Integer, List<Order>> transactionOrderEntry : transactionOrdersMap.entrySet()) {
|
| - |
|
466 |
|
| - |
|
467 |
List<Order> orders = transactionOrderEntry.getValue();
|
| - |
|
468 |
|
| - |
|
469 |
LocalDateTime createDate = orders.get(0).getCreateTimestamp();
|
| - |
|
470 |
|
| - |
|
471 |
int fofoId = orders.get(0).getRetailerId();
|
| - |
|
472 |
|
| - |
|
473 |
double loanSettleAmount = loanStatementRepository.selectByDateAndFofoId(createDate, fofoId).stream()
|
| - |
|
474 |
.filter(x -> x.getAmount().doubleValue() > 0)
|
| - |
|
475 |
.collect(Collectors.summingDouble(x -> x.getAmount().doubleValue()));
|
| - |
|
476 |
|
| - |
|
477 |
transactionCreditMap.put(transactionOrderEntry.getKey(), loanSettleAmount);
|
| - |
|
478 |
|
| - |
|
479 |
}
|
| - |
|
480 |
|
| - |
|
481 |
model.addAttribute("transactionCreditMap", transactionCreditMap);
|
| - |
|
482 |
|
| - |
|
483 |
}
|
| - |
|
484 |
|
| - |
|
485 |
return "sanction-order-hold";
|
| - |
|
486 |
|
| - |
|
487 |
}
|
| - |
|
488 |
|
| - |
|
489 |
@RequestMapping(value = "/unholdOrder", method = RequestMethod.POST)
|
| - |
|
490 |
public String unholdOrder(HttpServletRequest request, @RequestParam int transactionId, Model model)
|
| - |
|
491 |
throws Exception {
|
| - |
|
492 |
|
| - |
|
493 |
List<Order> orders = orderRepository.selectAllByTransactionId(transactionId);
|
| - |
|
494 |
|
| - |
|
495 |
LOGGER.info("orders" + orders);
|
| - |
|
496 |
|
| - |
|
497 |
if (!orders.isEmpty()) {
|
| - |
|
498 |
orders.forEach(x -> x.setShipmentHold(false));
|
| - |
|
499 |
}
|
| - |
|
500 |
|
| - |
|
501 |
double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
|
| - |
|
502 |
|
| - |
|
503 |
try {
|
| - |
|
504 |
|
| - |
|
505 |
List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId()).stream()
|
| - |
|
506 |
.map(x -> x.getEmailId()).collect(Collectors.toList());
|
| - |
|
507 |
|
| - |
|
508 |
authUserEmail.add("vinay.p@smartdukaan.com");
|
| - |
|
509 |
authUserEmail.add("shivam.gupta@smartdukaan.com");
|
| - |
|
510 |
|
| - |
|
511 |
String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
|
| - |
|
512 |
|
| - |
|
513 |
String[] ccTo = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com" };
|
| - |
|
514 |
|
| - |
|
515 |
String subject = "Dispatched " + (orders.get(0).getRetailerName());
|
| - |
|
516 |
String message = String.format("Dear Team, \n" + "Kindly note the meterial for the "
|
| - |
|
517 |
+ orders.get(0).getRetailerName() + "of Rs." + totalAmount + " is dispatched.");
|
| - |
|
518 |
|
| - |
|
519 |
LOGGER.info("message" + message);
|
| - |
|
520 |
|
| - |
|
521 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
| - |
|
522 |
} catch (Exception e) {
|
| - |
|
523 |
|
| - |
|
524 |
e.printStackTrace();
|
| - |
|
525 |
|
| - |
|
526 |
}
|
| - |
|
527 |
|
| - |
|
528 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
529 |
|
| - |
|
530 |
return "response";
|
| - |
|
531 |
|
| - |
|
532 |
}
|
| - |
|
533 |
|
| 422 |
}
|
534 |
}
|
| 423 |
|
535 |
|