| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
| 26298 |
tejbeer |
4 |
import java.util.ArrayList;
|
| 26164 |
amit.gupta |
5 |
import java.util.HashMap;
|
| 26298 |
tejbeer |
6 |
import java.util.List;
|
| 26063 |
amit.gupta |
7 |
import java.util.Map;
|
| 28106 |
amit.gupta |
8 |
import java.util.Scanner;
|
|
|
9 |
import java.util.stream.Collectors;
|
| 23612 |
amit.gupta |
10 |
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
|
|
12 |
|
|
|
13 |
import org.apache.http.HttpResponse;
|
| 23654 |
amit.gupta |
14 |
import org.apache.logging.log4j.LogManager;
|
|
|
15 |
import org.apache.logging.log4j.Logger;
|
| 23637 |
amit.gupta |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23612 |
amit.gupta |
17 |
import org.springframework.core.io.InputStreamResource;
|
|
|
18 |
import org.springframework.http.HttpHeaders;
|
|
|
19 |
import org.springframework.http.HttpStatus;
|
|
|
20 |
import org.springframework.http.ResponseEntity;
|
|
|
21 |
import org.springframework.stereotype.Controller;
|
| 23637 |
amit.gupta |
22 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
23 |
import org.springframework.ui.Model;
|
| 23612 |
amit.gupta |
24 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 26063 |
amit.gupta |
25 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23612 |
amit.gupta |
26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
28 |
|
|
|
29 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28106 |
amit.gupta |
31 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
| 23612 |
amit.gupta |
32 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 26298 |
tejbeer |
33 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
34 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
35 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 28106 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23784 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23798 |
amit.gupta |
38 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23612 |
amit.gupta |
39 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
40 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
41 |
|
|
|
42 |
@Controller
|
| 26298 |
tejbeer |
43 |
@Transactional(rollbackFor = Throwable.class)
|
| 23612 |
amit.gupta |
44 |
public class ReportsController {
|
| 26298 |
tejbeer |
45 |
|
| 23637 |
amit.gupta |
46 |
@Autowired
|
| 23784 |
ashik.ali |
47 |
private RoleRepository roleRepository;
|
| 26298 |
tejbeer |
48 |
|
| 23764 |
amit.gupta |
49 |
@Autowired
|
| 26298 |
tejbeer |
50 |
private CookiesProcessor cookiesProcessor;
|
| 28106 |
amit.gupta |
51 |
|
|
|
52 |
@Autowired
|
|
|
53 |
private FofoStoreRepository fofoStoreRepository;
|
| 26298 |
tejbeer |
54 |
|
| 23784 |
ashik.ali |
55 |
@Autowired
|
| 23652 |
amit.gupta |
56 |
private ReporticoService reporticoService;
|
| 23764 |
amit.gupta |
57 |
|
| 23798 |
amit.gupta |
58 |
@Autowired
|
|
|
59 |
private RoleManager roleManager;
|
| 26298 |
tejbeer |
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
private CsService csService;
|
|
|
63 |
|
|
|
64 |
@Autowired
|
|
|
65 |
private AuthRepository authRepository;
|
|
|
66 |
|
| 23654 |
amit.gupta |
67 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
| 23612 |
amit.gupta |
68 |
|
| 26063 |
amit.gupta |
69 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 23764 |
amit.gupta |
70 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 26298 |
tejbeer |
71 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 23764 |
amit.gupta |
72 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23612 |
amit.gupta |
73 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
74 |
HttpResponse response;
|
| 26298 |
tejbeer |
75 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
76 |
|
|
|
77 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
|
|
78 |
if (paramsMap == null) {
|
|
|
79 |
paramsMap = new HashMap<String, String>();
|
|
|
80 |
}
|
| 26460 |
amit.gupta |
81 |
Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
|
| 26298 |
tejbeer |
82 |
|
|
|
83 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
84 |
|
|
|
85 |
List<Integer> authIds = mapping.get(authUser.getId());
|
|
|
86 |
if (authIds == null) {
|
|
|
87 |
authIds = new ArrayList<>();
|
|
|
88 |
}
|
|
|
89 |
authIds.add(authUser.getId());
|
|
|
90 |
|
|
|
91 |
paramsMap.put("authId", authIds + "");
|
|
|
92 |
}
|
| 23612 |
amit.gupta |
93 |
} else {
|
| 26298 |
tejbeer |
94 |
if (paramsMap == null) {
|
| 26164 |
amit.gupta |
95 |
paramsMap = new HashMap<String, String>();
|
|
|
96 |
}
|
| 26298 |
tejbeer |
97 |
|
| 26158 |
amit.gupta |
98 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| 26298 |
tejbeer |
99 |
|
| 23612 |
amit.gupta |
100 |
}
|
| 26298 |
tejbeer |
101 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 23612 |
amit.gupta |
102 |
HttpHeaders headers = new HttpHeaders();
|
| 23764 |
amit.gupta |
103 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 23765 |
amit.gupta |
104 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
| 26298 |
tejbeer |
105 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
| 23766 |
amit.gupta |
106 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 23764 |
amit.gupta |
107 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 23612 |
amit.gupta |
108 |
}
|
| 23637 |
amit.gupta |
109 |
|
| 26298 |
tejbeer |
110 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
|
|
111 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 26063 |
amit.gupta |
112 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
113 |
}
|
|
|
114 |
|
| 23822 |
amit.gupta |
115 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 28106 |
amit.gupta |
116 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
|
|
117 |
|
| 28137 |
amit.gupta |
118 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|
| 28106 |
amit.gupta |
119 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
|
| 28137 |
amit.gupta |
120 |
/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
|
| 28106 |
amit.gupta |
121 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
|
|
|
122 |
returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
|
|
|
123 |
returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
|
| 28107 |
amit.gupta |
124 |
returnMap = returnMap1;
|
| 28137 |
amit.gupta |
125 |
}*/
|
| 28107 |
amit.gupta |
126 |
model.addAttribute("reporticoProjectMap", returnMap);
|
| 28106 |
amit.gupta |
127 |
|
| 23637 |
amit.gupta |
128 |
return "reports";
|
|
|
129 |
}
|
| 23612 |
amit.gupta |
130 |
}
|