| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
| 30162 |
manish |
4 |
import java.time.LocalDate;
|
|
|
5 |
import java.time.LocalDateTime;
|
| 26298 |
tejbeer |
6 |
import java.util.ArrayList;
|
| 30162 |
manish |
7 |
import java.util.Arrays;
|
| 26164 |
amit.gupta |
8 |
import java.util.HashMap;
|
| 26298 |
tejbeer |
9 |
import java.util.List;
|
| 26063 |
amit.gupta |
10 |
import java.util.Map;
|
| 23612 |
amit.gupta |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
|
|
|
14 |
import org.apache.http.HttpResponse;
|
| 23654 |
amit.gupta |
15 |
import org.apache.logging.log4j.LogManager;
|
|
|
16 |
import org.apache.logging.log4j.Logger;
|
| 23637 |
amit.gupta |
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23612 |
amit.gupta |
18 |
import org.springframework.core.io.InputStreamResource;
|
|
|
19 |
import org.springframework.http.HttpHeaders;
|
|
|
20 |
import org.springframework.http.HttpStatus;
|
|
|
21 |
import org.springframework.http.ResponseEntity;
|
|
|
22 |
import org.springframework.stereotype.Controller;
|
| 23637 |
amit.gupta |
23 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
24 |
import org.springframework.ui.Model;
|
| 23612 |
amit.gupta |
25 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 26063 |
amit.gupta |
26 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23612 |
amit.gupta |
27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 30162 |
manish |
29 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23612 |
amit.gupta |
30 |
|
|
|
31 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28106 |
amit.gupta |
33 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
| 23612 |
amit.gupta |
34 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 30162 |
manish |
35 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 26298 |
tejbeer |
36 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30162 |
manish |
37 |
import com.spice.profitmandi.dao.model.CollectionSummary;
|
| 26298 |
tejbeer |
38 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 28106 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23784 |
ashik.ali |
41 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 30162 |
manish |
42 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 23798 |
amit.gupta |
43 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 30162 |
manish |
44 |
import com.spice.profitmandi.service.order.OrderService;
|
| 23612 |
amit.gupta |
45 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
46 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
47 |
|
|
|
48 |
@Controller
|
| 26298 |
tejbeer |
49 |
@Transactional(rollbackFor = Throwable.class)
|
| 23612 |
amit.gupta |
50 |
public class ReportsController {
|
| 26298 |
tejbeer |
51 |
|
| 23637 |
amit.gupta |
52 |
@Autowired
|
| 23784 |
ashik.ali |
53 |
private RoleRepository roleRepository;
|
| 26298 |
tejbeer |
54 |
|
| 23764 |
amit.gupta |
55 |
@Autowired
|
| 26298 |
tejbeer |
56 |
private CookiesProcessor cookiesProcessor;
|
| 28106 |
amit.gupta |
57 |
|
|
|
58 |
@Autowired
|
|
|
59 |
private FofoStoreRepository fofoStoreRepository;
|
| 26298 |
tejbeer |
60 |
|
| 23784 |
ashik.ali |
61 |
@Autowired
|
| 23652 |
amit.gupta |
62 |
private ReporticoService reporticoService;
|
| 23764 |
amit.gupta |
63 |
|
| 23798 |
amit.gupta |
64 |
@Autowired
|
| 30162 |
manish |
65 |
private OrderRepository orderRepository;
|
|
|
66 |
@Autowired
|
| 23798 |
amit.gupta |
67 |
private RoleManager roleManager;
|
| 30162 |
manish |
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
private OrderService orderService;
|
| 26298 |
tejbeer |
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private CsService csService;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private AuthRepository authRepository;
|
|
|
77 |
|
| 30162 |
manish |
78 |
private static final Logger Logger = LogManager.getLogger(OrderController.class);
|
| 23612 |
amit.gupta |
79 |
|
| 26063 |
amit.gupta |
80 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 23764 |
amit.gupta |
81 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 26298 |
tejbeer |
82 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 23764 |
amit.gupta |
83 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23612 |
amit.gupta |
84 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
85 |
HttpResponse response;
|
| 26298 |
tejbeer |
86 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
87 |
|
|
|
88 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
|
|
89 |
if (paramsMap == null) {
|
|
|
90 |
paramsMap = new HashMap<String, String>();
|
|
|
91 |
}
|
| 26460 |
amit.gupta |
92 |
Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
|
| 26298 |
tejbeer |
93 |
|
|
|
94 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
95 |
|
|
|
96 |
List<Integer> authIds = mapping.get(authUser.getId());
|
|
|
97 |
if (authIds == null) {
|
|
|
98 |
authIds = new ArrayList<>();
|
|
|
99 |
}
|
|
|
100 |
authIds.add(authUser.getId());
|
|
|
101 |
|
|
|
102 |
paramsMap.put("authId", authIds + "");
|
|
|
103 |
}
|
| 23612 |
amit.gupta |
104 |
} else {
|
| 26298 |
tejbeer |
105 |
if (paramsMap == null) {
|
| 26164 |
amit.gupta |
106 |
paramsMap = new HashMap<String, String>();
|
|
|
107 |
}
|
| 26298 |
tejbeer |
108 |
|
| 26158 |
amit.gupta |
109 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| 26298 |
tejbeer |
110 |
|
| 23612 |
amit.gupta |
111 |
}
|
| 26298 |
tejbeer |
112 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 23612 |
amit.gupta |
113 |
HttpHeaders headers = new HttpHeaders();
|
| 23764 |
amit.gupta |
114 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 23765 |
amit.gupta |
115 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
| 26298 |
tejbeer |
116 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
| 23766 |
amit.gupta |
117 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 23764 |
amit.gupta |
118 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 23612 |
amit.gupta |
119 |
}
|
| 23637 |
amit.gupta |
120 |
|
| 26298 |
tejbeer |
121 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
|
|
122 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 26063 |
amit.gupta |
123 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
124 |
}
|
| 30162 |
manish |
125 |
|
|
|
126 |
@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
|
|
|
127 |
public String getCollectionSummary(HttpServletRequest request,
|
|
|
128 |
Model model) throws ProfitMandiBusinessException {
|
|
|
129 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
130 |
|
|
|
131 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
132 |
LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
|
|
|
133 |
|
|
|
134 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),currentStartMonth, currentDate);
|
|
|
135 |
|
|
|
136 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
|
|
137 |
|
|
|
138 |
model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
|
|
|
139 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
140 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
141 |
return "partner-collection-summary";
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
|
|
|
145 |
public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
|
|
|
146 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
147 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,Model model) throws Exception {
|
|
|
148 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
149 |
List<List<?>> rows = new ArrayList<>();
|
| 26063 |
amit.gupta |
150 |
|
| 30162 |
manish |
151 |
|
|
|
152 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),startDate.atStartOfDay(), endDate.atStartOfDay());
|
|
|
153 |
|
|
|
154 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
|
|
155 |
|
|
|
156 |
for( CollectionSummary cs : collectionSummaryList) {
|
|
|
157 |
|
|
|
158 |
rows.add(Arrays.asList(cs.getDate(), cs.getReferenceType(),cs.getCash(),cs.getPinelabs(),cs.getBajajFinserv(),cs.getHomeCredit(),cs.getPaytm(),
|
|
|
159 |
cs.getCapitalFirst(),cs.getZestMoney(),cs.getSamsungSure(),cs.getTotalAmount()));
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
165 |
.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash","Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
|
|
|
166 |
"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
|
|
|
167 |
|
|
|
168 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,"Collection Summary Report");
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
return responseEntity;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
| 23822 |
amit.gupta |
178 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 28106 |
amit.gupta |
179 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
|
|
180 |
|
| 28137 |
amit.gupta |
181 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|
| 28106 |
amit.gupta |
182 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
|
| 28137 |
amit.gupta |
183 |
/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
|
| 28106 |
amit.gupta |
184 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
|
|
|
185 |
returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
|
|
|
186 |
returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
|
| 28107 |
amit.gupta |
187 |
returnMap = returnMap1;
|
| 28137 |
amit.gupta |
188 |
}*/
|
| 28107 |
amit.gupta |
189 |
model.addAttribute("reporticoProjectMap", returnMap);
|
| 28106 |
amit.gupta |
190 |
|
| 23637 |
amit.gupta |
191 |
return "reports";
|
|
|
192 |
}
|
| 23612 |
amit.gupta |
193 |
}
|