| 22981 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23494 |
ashik.ali |
3 |
import java.io.File;
|
|
|
4 |
import java.io.FileInputStream;
|
|
|
5 |
import java.io.FileNotFoundException;
|
| 22981 |
ashik.ali |
6 |
import java.util.Map;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
| 23945 |
amit.gupta |
10 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
11 |
import org.apache.logging.log4j.Logger;
|
| 22981 |
ashik.ali |
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23494 |
ashik.ali |
13 |
import org.springframework.core.io.InputStreamResource;
|
|
|
14 |
import org.springframework.http.HttpHeaders;
|
|
|
15 |
import org.springframework.http.HttpStatus;
|
| 23330 |
ashik.ali |
16 |
import org.springframework.http.ResponseEntity;
|
| 22981 |
ashik.ali |
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
19 |
import org.springframework.ui.Model;
|
| 23026 |
ashik.ali |
20 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 22981 |
ashik.ali |
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
24 |
|
| 23494 |
ashik.ali |
25 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 22981 |
ashik.ali |
26 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23945 |
amit.gupta |
27 |
import com.spice.profitmandi.common.model.Location;
|
| 22981 |
ashik.ali |
28 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23026 |
ashik.ali |
29 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
| 23330 |
ashik.ali |
30 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23494 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 23945 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 23494 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 23945 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23494 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 22981 |
ashik.ali |
39 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23945 |
amit.gupta |
40 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
41 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 22981 |
ashik.ali |
42 |
|
|
|
43 |
@Controller
|
| 23945 |
amit.gupta |
44 |
@Transactional(rollbackFor = Throwable.class)
|
| 22981 |
ashik.ali |
45 |
public class RetailerController {
|
|
|
46 |
|
| 23568 |
govind |
47 |
private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
|
| 23945 |
amit.gupta |
48 |
|
| 22981 |
ashik.ali |
49 |
@Autowired
|
|
|
50 |
private RetailerService retailerService;
|
| 23945 |
amit.gupta |
51 |
|
| 23330 |
ashik.ali |
52 |
@Autowired
|
| 23494 |
ashik.ali |
53 |
private RetailerRepository retailerRepository;
|
| 23945 |
amit.gupta |
54 |
|
| 23494 |
ashik.ali |
55 |
@Autowired
|
|
|
56 |
private ShopRepository shopRepository;
|
|
|
57 |
|
|
|
58 |
@Autowired
|
| 23945 |
amit.gupta |
59 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
| 23494 |
ashik.ali |
62 |
private DocumentRepository documentRepository;
|
| 23945 |
amit.gupta |
63 |
|
| 23494 |
ashik.ali |
64 |
@Autowired
|
| 23330 |
ashik.ali |
65 |
private ResponseSender<?> responseSender;
|
|
|
66 |
|
| 23945 |
amit.gupta |
67 |
@Autowired
|
|
|
68 |
private CookiesProcessor cookiesProcessor;
|
|
|
69 |
|
| 23784 |
ashik.ali |
70 |
@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
71 |
public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
|
|
|
72 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
|
|
|
73 |
Model model) throws ProfitMandiBusinessException {
|
|
|
74 |
LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
|
|
|
75 |
emailIdOrMobileNumber);
|
| 22981 |
ashik.ali |
76 |
Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
|
|
77 |
model.addAllAttributes(map);
|
|
|
78 |
return "retailer-details";
|
|
|
79 |
}
|
| 23945 |
amit.gupta |
80 |
|
| 23026 |
ashik.ali |
81 |
@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
|
| 23945 |
amit.gupta |
82 |
public String updateRetailerDetails(HttpServletRequest request,
|
|
|
83 |
@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
|
| 23026 |
ashik.ali |
84 |
LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
|
|
|
85 |
Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
|
|
|
86 |
model.addAllAttributes(map);
|
|
|
87 |
return "retailer-details";
|
|
|
88 |
}
|
| 22981 |
ashik.ali |
89 |
|
|
|
90 |
@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
91 |
public String retailerInfo(HttpServletRequest request) throws Exception {
|
| 22981 |
ashik.ali |
92 |
return "retailer-info";
|
|
|
93 |
}
|
| 23945 |
amit.gupta |
94 |
|
| 23330 |
ashik.ali |
95 |
@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
96 |
public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
|
| 23330 |
ashik.ali |
97 |
return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
|
|
|
98 |
}
|
| 23945 |
amit.gupta |
99 |
|
| 23494 |
ashik.ali |
100 |
@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
101 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
|
|
|
102 |
@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
|
|
|
103 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
|
| 23494 |
ashik.ali |
104 |
Document document = documentRepository.selectById(documentId);
|
| 23499 |
ashik.ali |
105 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 23945 |
amit.gupta |
106 |
|
|
|
107 |
if (retailer.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
108 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
|
|
109 |
}
|
| 23945 |
amit.gupta |
110 |
if (retailer.getDocumentId() != documentId) {
|
| 23494 |
ashik.ali |
111 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
|
|
112 |
}
|
|
|
113 |
return responseSender.ok(document);
|
|
|
114 |
}
|
| 23945 |
amit.gupta |
115 |
|
| 23494 |
ashik.ali |
116 |
@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
117 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
|
|
|
118 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
|
|
|
119 |
throws ProfitMandiBusinessException {
|
|
|
120 |
|
| 23499 |
ashik.ali |
121 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 23945 |
amit.gupta |
122 |
|
|
|
123 |
if (retailer.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
124 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
|
|
125 |
}
|
| 23945 |
amit.gupta |
126 |
|
| 23494 |
ashik.ali |
127 |
Document document = documentRepository.selectById(retailer.getDocumentId());
|
| 23945 |
amit.gupta |
128 |
|
| 23494 |
ashik.ali |
129 |
FileInputStream file = null;
|
|
|
130 |
try {
|
|
|
131 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
132 |
} catch (FileNotFoundException e) {
|
|
|
133 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
134 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
135 |
}
|
| 23945 |
amit.gupta |
136 |
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
137 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
138 |
|
|
|
139 |
final HttpHeaders headers = new HttpHeaders();
|
| 23494 |
ashik.ali |
140 |
String contentType = "";
|
| 23945 |
amit.gupta |
141 |
if (document.getContentType() == ContentType.JPEG) {
|
| 23494 |
ashik.ali |
142 |
contentType = "image/jpeg";
|
| 23945 |
amit.gupta |
143 |
} else if (document.getContentType() == ContentType.PNG) {
|
| 23494 |
ashik.ali |
144 |
contentType = "image/png";
|
| 23945 |
amit.gupta |
145 |
} else if (document.getContentType() == ContentType.PDF) {
|
| 23494 |
ashik.ali |
146 |
contentType = "application/pdf";
|
|
|
147 |
}
|
| 23945 |
amit.gupta |
148 |
headers.set("Content-Type", contentType);
|
|
|
149 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
150 |
headers.setContentLength(document.getSize());
|
|
|
151 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
152 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
153 |
|
|
|
154 |
// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 23494 |
ashik.ali |
155 |
}
|
| 23945 |
amit.gupta |
156 |
|
| 23494 |
ashik.ali |
157 |
@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
158 |
public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
|
|
|
159 |
@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
|
|
|
160 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
|
| 23494 |
ashik.ali |
161 |
Shop shop = shopRepository.selectById(shopId);
|
| 23945 |
amit.gupta |
162 |
|
|
|
163 |
if (shop.getRetailerId() != retailerId) {
|
| 23494 |
ashik.ali |
164 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
|
|
165 |
}
|
| 23945 |
amit.gupta |
166 |
|
|
|
167 |
if (shop.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
168 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
|
|
169 |
}
|
| 23945 |
amit.gupta |
170 |
|
| 23494 |
ashik.ali |
171 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
|
|
172 |
return responseSender.ok(document);
|
|
|
173 |
}
|
| 23945 |
amit.gupta |
174 |
|
| 23494 |
ashik.ali |
175 |
@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
176 |
public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
|
|
|
177 |
@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
|
|
|
178 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
|
|
|
179 |
throws ProfitMandiBusinessException {
|
|
|
180 |
|
| 23494 |
ashik.ali |
181 |
Shop shop = shopRepository.selectById(shopId);
|
| 23945 |
amit.gupta |
182 |
|
|
|
183 |
if (shop.getRetailerId() != retailerId) {
|
| 23494 |
ashik.ali |
184 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
|
|
185 |
}
|
| 23945 |
amit.gupta |
186 |
|
|
|
187 |
if (shop.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
188 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
|
|
189 |
}
|
| 23945 |
amit.gupta |
190 |
|
| 23494 |
ashik.ali |
191 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
| 23945 |
amit.gupta |
192 |
|
| 23494 |
ashik.ali |
193 |
FileInputStream file = null;
|
|
|
194 |
try {
|
|
|
195 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
196 |
} catch (FileNotFoundException e) {
|
|
|
197 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
198 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
199 |
}
|
| 23945 |
amit.gupta |
200 |
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
201 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
202 |
|
|
|
203 |
final HttpHeaders headers = new HttpHeaders();
|
| 23494 |
ashik.ali |
204 |
String contentType = "";
|
| 23945 |
amit.gupta |
205 |
if (document.getContentType() == ContentType.JPEG) {
|
| 23494 |
ashik.ali |
206 |
contentType = "image/jpeg";
|
| 23945 |
amit.gupta |
207 |
} else if (document.getContentType() == ContentType.PNG) {
|
| 23494 |
ashik.ali |
208 |
contentType = "image/png";
|
| 23945 |
amit.gupta |
209 |
} else if (document.getContentType() == ContentType.PDF) {
|
| 23494 |
ashik.ali |
210 |
contentType = "application/pdf";
|
|
|
211 |
}
|
| 23945 |
amit.gupta |
212 |
headers.set("Content-Type", contentType);
|
|
|
213 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
214 |
headers.setContentLength(document.getSize());
|
|
|
215 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
216 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
217 |
|
|
|
218 |
// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 23494 |
ashik.ali |
219 |
}
|
| 23945 |
amit.gupta |
220 |
|
|
|
221 |
@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
|
|
|
222 |
public ResponseEntity<?> updateLocation(HttpServletRequest request, @RequestBody Location location) throws ProfitMandiBusinessException{
|
|
|
223 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
224 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoDetails.getFofoId());
|
|
|
225 |
fs.setLatitude(location.getLatitude());
|
|
|
226 |
fs.setLongitude(location.getLongitude());
|
|
|
227 |
fofoStoreRepository.persist(fs);
|
|
|
228 |
return responseSender.ok(true);
|
|
|
229 |
}
|
| 22981 |
ashik.ali |
230 |
}
|