| 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;
|
| 24349 |
amit.gupta |
6 |
import java.time.LocalDate;
|
| 24159 |
tejbeer |
7 |
import java.time.LocalDateTime;
|
| 28272 |
tejbeer |
8 |
import java.util.AbstractMap;
|
| 24124 |
govind |
9 |
import java.util.ArrayList;
|
| 25276 |
amit.gupta |
10 |
import java.util.Arrays;
|
| 24349 |
amit.gupta |
11 |
import java.util.HashMap;
|
| 24124 |
govind |
12 |
import java.util.List;
|
| 22981 |
ashik.ali |
13 |
import java.util.Map;
|
| 28272 |
tejbeer |
14 |
import java.util.Map.Entry;
|
| 24986 |
tejbeer |
15 |
import java.util.Set;
|
| 24159 |
tejbeer |
16 |
import java.util.stream.Collectors;
|
| 22981 |
ashik.ali |
17 |
|
|
|
18 |
import javax.servlet.http.HttpServletRequest;
|
| 25276 |
amit.gupta |
19 |
import javax.transaction.Transactional;
|
| 22981 |
ashik.ali |
20 |
|
| 24159 |
tejbeer |
21 |
import org.apache.logging.log4j.LogManager;
|
| 23955 |
govind |
22 |
import org.apache.logging.log4j.Logger;
|
| 24159 |
tejbeer |
23 |
import org.json.JSONObject;
|
| 22981 |
ashik.ali |
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24159 |
tejbeer |
25 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23494 |
ashik.ali |
26 |
import org.springframework.core.io.InputStreamResource;
|
|
|
27 |
import org.springframework.http.HttpHeaders;
|
|
|
28 |
import org.springframework.http.HttpStatus;
|
| 23330 |
ashik.ali |
29 |
import org.springframework.http.ResponseEntity;
|
| 22981 |
ashik.ali |
30 |
import org.springframework.stereotype.Controller;
|
|
|
31 |
import org.springframework.ui.Model;
|
| 24124 |
govind |
32 |
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
33 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 23026 |
ashik.ali |
34 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 22981 |
ashik.ali |
35 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
36 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
37 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
38 |
|
| 23494 |
ashik.ali |
39 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 23955 |
govind |
40 |
import com.spice.profitmandi.common.enumuration.CounterSize;
|
| 22981 |
ashik.ali |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24123 |
tejbeer |
42 |
import com.spice.profitmandi.common.model.AddLocationModel;
|
| 24124 |
govind |
43 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22981 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24159 |
tejbeer |
45 |
import com.spice.profitmandi.common.model.PromoterDetailModel;
|
| 23026 |
ashik.ali |
46 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
| 28024 |
tejbeer |
47 |
import com.spice.profitmandi.common.util.Utils;
|
| 23330 |
ashik.ali |
48 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 27231 |
tejbeer |
49 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 27797 |
tejbeer |
50 |
import com.spice.profitmandi.dao.entity.cs.PartnerPosition;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 28272 |
tejbeer |
52 |
import com.spice.profitmandi.dao.entity.dtr.BrandLimit;
|
| 23494 |
ashik.ali |
53 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 28024 |
tejbeer |
55 |
import com.spice.profitmandi.dao.entity.dtr.RetailerBlockBrands;
|
| 28272 |
tejbeer |
56 |
import com.spice.profitmandi.dao.entity.dtr.RetailerBrandsLimit;
|
| 23494 |
ashik.ali |
57 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 24124 |
govind |
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 27797 |
tejbeer |
59 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
|
|
60 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
|
| 24159 |
tejbeer |
61 |
import com.spice.profitmandi.dao.entity.user.Location;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
| 24123 |
tejbeer |
63 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 28272 |
tejbeer |
64 |
import com.spice.profitmandi.dao.entity.warehouse.WarehouseInventoryItem;
|
| 27231 |
tejbeer |
65 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
66 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 28272 |
tejbeer |
67 |
import com.spice.profitmandi.dao.repository.cs.RetailerBrandsLimitService;
|
|
|
68 |
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
|
| 23494 |
ashik.ali |
69 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 24124 |
govind |
70 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24159 |
tejbeer |
71 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 28024 |
tejbeer |
72 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
|
| 28272 |
tejbeer |
73 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBrandsLimitRepository;
|
| 23494 |
ashik.ali |
74 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
75 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 27797 |
tejbeer |
76 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
|
|
|
77 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 24123 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.user.LocationRepository;
|
| 24159 |
tejbeer |
79 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| 24123 |
tejbeer |
80 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 24349 |
amit.gupta |
81 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 24159 |
tejbeer |
82 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22981 |
ashik.ali |
83 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 25276 |
amit.gupta |
84 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
85 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24123 |
tejbeer |
86 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22981 |
ashik.ali |
87 |
|
|
|
88 |
@Controller
|
| 25277 |
amit.gupta |
89 |
@Transactional(rollbackOn = Throwable.class)
|
| 22981 |
ashik.ali |
90 |
public class RetailerController {
|
|
|
91 |
|
| 23568 |
govind |
92 |
private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
|
| 24124 |
govind |
93 |
|
| 22981 |
ashik.ali |
94 |
@Autowired
|
|
|
95 |
private RetailerService retailerService;
|
| 24124 |
govind |
96 |
|
| 23330 |
ashik.ali |
97 |
@Autowired
|
| 23494 |
ashik.ali |
98 |
private RetailerRepository retailerRepository;
|
| 24124 |
govind |
99 |
|
| 23494 |
ashik.ali |
100 |
@Autowired
|
| 28272 |
tejbeer |
101 |
private BrandLimitRepository brandLimitRepository;
|
|
|
102 |
|
|
|
103 |
@Autowired
|
|
|
104 |
private RetailerBrandsLimitService retailerBrandsLimitService;
|
|
|
105 |
|
|
|
106 |
@Autowired
|
|
|
107 |
private RetailerBrandsLimitRepository retailerBrandsLimitRepository;
|
|
|
108 |
|
|
|
109 |
@Autowired
|
| 23494 |
ashik.ali |
110 |
private ShopRepository shopRepository;
|
| 24124 |
govind |
111 |
|
| 23494 |
ashik.ali |
112 |
@Autowired
|
| 28024 |
tejbeer |
113 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
|
|
114 |
|
|
|
115 |
@Autowired
|
| 24124 |
govind |
116 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
117 |
|
|
|
118 |
@Autowired
|
| 23494 |
ashik.ali |
119 |
private DocumentRepository documentRepository;
|
| 24124 |
govind |
120 |
|
| 23494 |
ashik.ali |
121 |
@Autowired
|
| 25276 |
amit.gupta |
122 |
private CookiesProcessor cookiesProcessor;
|
|
|
123 |
|
|
|
124 |
@Autowired
|
| 24159 |
tejbeer |
125 |
@Qualifier("userUserRepository")
|
| 24123 |
tejbeer |
126 |
private UserRepository userRepository;
|
| 24124 |
govind |
127 |
|
| 24123 |
tejbeer |
128 |
@Autowired
|
| 27231 |
tejbeer |
129 |
private AuthRepository authRepository;
|
|
|
130 |
|
|
|
131 |
@Autowired
|
|
|
132 |
private CsService csService;
|
|
|
133 |
|
|
|
134 |
@Autowired
|
| 24123 |
tejbeer |
135 |
private LocationRepository locationRepository;
|
| 24124 |
govind |
136 |
|
| 24123 |
tejbeer |
137 |
@Autowired
|
| 23330 |
ashik.ali |
138 |
private ResponseSender<?> responseSender;
|
| 24124 |
govind |
139 |
|
| 24123 |
tejbeer |
140 |
@Autowired
|
|
|
141 |
private MVCResponseSender mvcResponseSender;
|
| 24124 |
govind |
142 |
|
| 24159 |
tejbeer |
143 |
@Autowired
|
|
|
144 |
private InventoryService inventoryService;
|
|
|
145 |
|
|
|
146 |
@Autowired
|
|
|
147 |
private PromoterRepository promoterRepository;
|
|
|
148 |
|
|
|
149 |
@Autowired
|
| 24349 |
amit.gupta |
150 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
151 |
|
|
|
152 |
@Autowired
|
| 24159 |
tejbeer |
153 |
private Mongo mongoClient;
|
|
|
154 |
|
| 27797 |
tejbeer |
155 |
@Autowired
|
|
|
156 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
157 |
|
|
|
158 |
@Autowired
|
|
|
159 |
private PartnerTypeChangeRepository partnerTypeChangeRepository;
|
|
|
160 |
|
| 23784 |
ashik.ali |
161 |
@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
|
| 24124 |
govind |
162 |
public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
|
|
|
163 |
@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
|
|
|
164 |
Model model) throws ProfitMandiBusinessException {
|
|
|
165 |
LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
|
|
|
166 |
emailIdOrMobileNumber);
|
| 28071 |
tejbeer |
167 |
|
|
|
168 |
Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
|
|
169 |
|
| 26771 |
amit.gupta |
170 |
model.addAllAttributes(map);
|
| 28071 |
tejbeer |
171 |
|
| 23955 |
govind |
172 |
model.addAttribute("counterSizes", CounterSize.values());
|
| 26209 |
tejbeer |
173 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
|
|
174 |
LOGGER.info("warehouseMap", warehouseMap);
|
|
|
175 |
model.addAttribute("warehouses", warehouseMap);
|
| 26771 |
amit.gupta |
176 |
if (map.containsKey("retailer")) {
|
|
|
177 |
Retailer retailer = (Retailer) map.get("retailer");
|
|
|
178 |
User user = userRepository.selectById(retailer.getId());
|
|
|
179 |
if (user.getLocation() != null) {
|
|
|
180 |
Location location = locationRepository.selectById(user.getLocation());
|
|
|
181 |
model.addAttribute("locationdetail", location);
|
|
|
182 |
LOGGER.info("location" + location);
|
|
|
183 |
}
|
|
|
184 |
}
|
| 22981 |
ashik.ali |
185 |
return "retailer-details";
|
|
|
186 |
}
|
| 24124 |
govind |
187 |
|
| 23026 |
ashik.ali |
188 |
@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
|
| 24124 |
govind |
189 |
public String updateRetailerDetails(HttpServletRequest request,
|
|
|
190 |
@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
|
| 23026 |
ashik.ali |
191 |
LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
|
|
|
192 |
Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
|
| 28071 |
tejbeer |
193 |
|
| 23026 |
ashik.ali |
194 |
model.addAllAttributes(map);
|
| 23955 |
govind |
195 |
model.addAttribute("counterSizes", CounterSize.values());
|
| 26209 |
tejbeer |
196 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
|
|
197 |
LOGGER.info("warehouseMap", warehouseMap);
|
|
|
198 |
model.addAttribute("warehouses", warehouseMap);
|
| 23026 |
ashik.ali |
199 |
return "retailer-details";
|
|
|
200 |
}
|
| 22981 |
ashik.ali |
201 |
|
|
|
202 |
@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
|
| 24124 |
govind |
203 |
public String retailerInfo(HttpServletRequest request) throws Exception {
|
| 22981 |
ashik.ali |
204 |
return "retailer-info";
|
|
|
205 |
}
|
| 24124 |
govind |
206 |
|
| 23330 |
ashik.ali |
207 |
@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
|
| 24124 |
govind |
208 |
public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
|
| 23330 |
ashik.ali |
209 |
return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
|
|
|
210 |
}
|
| 24124 |
govind |
211 |
|
| 23494 |
ashik.ali |
212 |
@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
|
| 24124 |
govind |
213 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
|
|
|
214 |
@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
|
|
|
215 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
|
| 23494 |
ashik.ali |
216 |
Document document = documentRepository.selectById(documentId);
|
| 23499 |
ashik.ali |
217 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 24124 |
govind |
218 |
|
|
|
219 |
if (retailer.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
220 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
|
|
221 |
}
|
| 24124 |
govind |
222 |
if (retailer.getDocumentId() != documentId) {
|
| 23494 |
ashik.ali |
223 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
|
|
224 |
}
|
|
|
225 |
return responseSender.ok(document);
|
|
|
226 |
}
|
| 24124 |
govind |
227 |
|
| 23494 |
ashik.ali |
228 |
@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
|
| 24124 |
govind |
229 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
|
|
|
230 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
|
|
|
231 |
throws ProfitMandiBusinessException {
|
|
|
232 |
|
| 23499 |
ashik.ali |
233 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 24124 |
govind |
234 |
|
|
|
235 |
if (retailer.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
236 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
|
|
237 |
}
|
| 24124 |
govind |
238 |
|
| 23494 |
ashik.ali |
239 |
Document document = documentRepository.selectById(retailer.getDocumentId());
|
| 24124 |
govind |
240 |
|
| 23494 |
ashik.ali |
241 |
FileInputStream file = null;
|
|
|
242 |
try {
|
|
|
243 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
244 |
} catch (FileNotFoundException e) {
|
|
|
245 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
246 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
247 |
}
|
| 24159 |
tejbeer |
248 |
// ByteArrayOutputStream byteArrayOutputStream = new
|
|
|
249 |
// ByteArrayOutputStream();
|
| 24124 |
govind |
250 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
251 |
|
|
|
252 |
final HttpHeaders headers = new HttpHeaders();
|
| 23494 |
ashik.ali |
253 |
String contentType = "";
|
| 24124 |
govind |
254 |
if (document.getContentType() == ContentType.JPEG) {
|
| 23494 |
ashik.ali |
255 |
contentType = "image/jpeg";
|
| 24124 |
govind |
256 |
} else if (document.getContentType() == ContentType.PNG) {
|
| 23494 |
ashik.ali |
257 |
contentType = "image/png";
|
| 24124 |
govind |
258 |
} else if (document.getContentType() == ContentType.PDF) {
|
| 23494 |
ashik.ali |
259 |
contentType = "application/pdf";
|
|
|
260 |
}
|
| 24124 |
govind |
261 |
headers.set("Content-Type", contentType);
|
|
|
262 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
263 |
headers.setContentLength(document.getSize());
|
|
|
264 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
265 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
266 |
|
| 24159 |
tejbeer |
267 |
// return
|
|
|
268 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 23494 |
ashik.ali |
269 |
}
|
| 24124 |
govind |
270 |
|
| 23494 |
ashik.ali |
271 |
@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
|
| 24124 |
govind |
272 |
public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
|
|
|
273 |
@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
|
|
|
274 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
|
| 23494 |
ashik.ali |
275 |
Shop shop = shopRepository.selectById(shopId);
|
| 24124 |
govind |
276 |
|
|
|
277 |
if (shop.getRetailerId() != retailerId) {
|
| 23494 |
ashik.ali |
278 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
|
|
279 |
}
|
| 24124 |
govind |
280 |
|
|
|
281 |
if (shop.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
282 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
|
|
283 |
}
|
| 24124 |
govind |
284 |
|
| 23494 |
ashik.ali |
285 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
|
|
286 |
return responseSender.ok(document);
|
|
|
287 |
}
|
| 24124 |
govind |
288 |
|
| 23494 |
ashik.ali |
289 |
@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
|
| 24124 |
govind |
290 |
public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
|
|
|
291 |
@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
|
|
|
292 |
@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
|
|
|
293 |
throws ProfitMandiBusinessException {
|
|
|
294 |
|
| 23494 |
ashik.ali |
295 |
Shop shop = shopRepository.selectById(shopId);
|
| 24124 |
govind |
296 |
|
|
|
297 |
if (shop.getRetailerId() != retailerId) {
|
| 23494 |
ashik.ali |
298 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
|
|
299 |
}
|
| 24124 |
govind |
300 |
|
|
|
301 |
if (shop.getDocumentId() == null) {
|
| 23494 |
ashik.ali |
302 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
|
|
303 |
}
|
| 24124 |
govind |
304 |
|
| 23494 |
ashik.ali |
305 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
| 24124 |
govind |
306 |
|
| 23494 |
ashik.ali |
307 |
FileInputStream file = null;
|
|
|
308 |
try {
|
|
|
309 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
310 |
} catch (FileNotFoundException e) {
|
|
|
311 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
312 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
313 |
}
|
| 24159 |
tejbeer |
314 |
// ByteArrayOutputStream byteArrayOutputStream = new
|
|
|
315 |
// ByteArrayOutputStream();
|
| 24124 |
govind |
316 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
317 |
|
|
|
318 |
final HttpHeaders headers = new HttpHeaders();
|
| 23494 |
ashik.ali |
319 |
String contentType = "";
|
| 24124 |
govind |
320 |
if (document.getContentType() == ContentType.JPEG) {
|
| 23494 |
ashik.ali |
321 |
contentType = "image/jpeg";
|
| 24124 |
govind |
322 |
} else if (document.getContentType() == ContentType.PNG) {
|
| 23494 |
ashik.ali |
323 |
contentType = "image/png";
|
| 24124 |
govind |
324 |
} else if (document.getContentType() == ContentType.PDF) {
|
| 23494 |
ashik.ali |
325 |
contentType = "application/pdf";
|
|
|
326 |
}
|
| 24124 |
govind |
327 |
headers.set("Content-Type", contentType);
|
|
|
328 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
329 |
headers.setContentLength(document.getSize());
|
|
|
330 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
331 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
332 |
|
| 24159 |
tejbeer |
333 |
// return
|
|
|
334 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 23494 |
ashik.ali |
335 |
}
|
| 24124 |
govind |
336 |
|
|
|
337 |
@GetMapping(value = "/getAllStores")
|
|
|
338 |
public String getAllStores(HttpServletRequest request, Model model) {
|
|
|
339 |
|
| 25276 |
amit.gupta |
340 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
|
|
|
341 |
.collect(Collectors.toList());
|
| 24349 |
amit.gupta |
342 |
Map<Integer, Boolean> investments = new HashMap<>();
|
| 24124 |
govind |
343 |
|
| 24349 |
amit.gupta |
344 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
345 |
boolean isOk = false;
|
|
|
346 |
if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
|
|
|
347 |
isOk = true;
|
|
|
348 |
} else {
|
|
|
349 |
try {
|
| 25276 |
amit.gupta |
350 |
isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), 10,
|
|
|
351 |
ProfitMandiConstants.CUTOFF_INVESTMENT);
|
|
|
352 |
if (fofoStore.getGraceCount() > 0) {
|
| 24349 |
amit.gupta |
353 |
fofoStore.setGraceDate(null);
|
|
|
354 |
fofoStore.setGraceCount(0);
|
|
|
355 |
fofoStoreRepository.persist(fofoStore);
|
|
|
356 |
}
|
|
|
357 |
} catch (ProfitMandiBusinessException e) {
|
|
|
358 |
}
|
|
|
359 |
}
|
|
|
360 |
investments.put(fofoStore.getId(), isOk);
|
|
|
361 |
}
|
| 24124 |
govind |
362 |
|
| 26963 |
amit.gupta |
363 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(false);
|
| 24124 |
govind |
364 |
model.addAttribute("fofoStores", fofoStores);
|
| 24349 |
amit.gupta |
365 |
model.addAttribute("investments", investments);
|
| 24124 |
govind |
366 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
367 |
|
|
|
368 |
return "store";
|
|
|
369 |
|
|
|
370 |
}
|
|
|
371 |
|
| 27797 |
tejbeer |
372 |
@GetMapping(value = "/getPartnerCategory")
|
|
|
373 |
public String getPartnerCategory(HttpServletRequest request, @RequestParam int fofoId, Model model) {
|
|
|
374 |
|
|
|
375 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
|
|
376 |
List<PartnerType> partnerTypes = partnerType.nextPartnerTypes();
|
|
|
377 |
LOGGER.info("partnerType" + partnerTypes);
|
|
|
378 |
model.addAttribute("partnerTypes", partnerTypes);
|
|
|
379 |
model.addAttribute("fofoId", fofoId);
|
|
|
380 |
return "partner-category";
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
@PostMapping(value = "/updatePartnerCategory")
|
|
|
384 |
public String updatePartnerCategory(HttpServletRequest request, @RequestParam(name = "fofoId") int fofoId,
|
|
|
385 |
@RequestParam(name = "partnerType") PartnerType partnerType, Model model) throws Exception {
|
|
|
386 |
|
|
|
387 |
PartnerTypeChange ptc = new PartnerTypeChange();
|
|
|
388 |
ptc.setFofoId(fofoId);
|
|
|
389 |
ptc.setPartnerType(partnerType);
|
|
|
390 |
ptc.setCreateTimestamp(LocalDate.now().atStartOfDay().plusDays(1));
|
|
|
391 |
partnerTypeChangeRepository.persist(ptc);
|
|
|
392 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
393 |
|
|
|
394 |
return "response";
|
|
|
395 |
}
|
|
|
396 |
|
| 24349 |
amit.gupta |
397 |
@GetMapping(value = "/partners")
|
|
|
398 |
public String getStoreName(HttpServletRequest request, Model model, @RequestParam String query) throws Exception {
|
|
|
399 |
model.addAttribute("response", mvcResponseSender
|
| 26963 |
amit.gupta |
400 |
.createResponseString(retailerService.getFofoRetailers(false).values().stream().filter(x -> {
|
| 24349 |
amit.gupta |
401 |
return x.getDisplayName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?");
|
|
|
402 |
}).collect(Collectors.toList())));
|
|
|
403 |
return "response";
|
|
|
404 |
}
|
|
|
405 |
|
| 24124 |
govind |
406 |
@PostMapping(value = "/deactivateStore")
|
|
|
407 |
public String deActivateStore(HttpServletRequest request,
|
|
|
408 |
@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
|
|
|
409 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 25276 |
amit.gupta |
410 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 27231 |
tejbeer |
411 |
if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com")
|
| 26131 |
tejbeer |
412 |
.contains(loginDetails.getEmailId())) {
|
|
|
413 |
throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
|
|
|
414 |
"You are not authorise to deactivate retailer");
|
| 25276 |
amit.gupta |
415 |
}
|
| 24843 |
govind |
416 |
fofoStore.setActive(false);
|
|
|
417 |
fofoStoreRepository.persist(fofoStore);
|
| 24124 |
govind |
418 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
|
|
419 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
420 |
|
|
|
421 |
return "response";
|
|
|
422 |
|
|
|
423 |
}
|
| 25276 |
amit.gupta |
424 |
|
|
|
425 |
@GetMapping(value = "/getAllInactiveStores")
|
|
|
426 |
public String getInactiveStores(HttpServletRequest request, Model model) {
|
|
|
427 |
List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
|
|
|
428 |
Map<Integer, CustomRetailer> customRetailers = retailerService
|
|
|
429 |
.getFofoRetailers(inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 24680 |
govind |
430 |
model.addAttribute("inActiveFofoStores", inActiveFofoStores);
|
|
|
431 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
432 |
return "inactive-stores";
|
|
|
433 |
}
|
| 25276 |
amit.gupta |
434 |
|
|
|
435 |
// Extend billing for 2 days
|
| 24349 |
amit.gupta |
436 |
@PostMapping(value = "/extendBilling")
|
|
|
437 |
public String extendBilling(HttpServletRequest request,
|
|
|
438 |
@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
|
|
|
439 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 25276 |
amit.gupta |
440 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 27231 |
tejbeer |
441 |
if (Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "prakash.rai@smartdukaan.com",
|
|
|
442 |
"amit.gupta@smartdukaan.com").contains(loginDetails.getEmailId())) {
|
| 25276 |
amit.gupta |
443 |
fofoStore.setGraceDate(LocalDate.now().plusDays(2));
|
|
|
444 |
fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
|
|
|
445 |
fofoStoreRepository.persist(fofoStore);
|
|
|
446 |
model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
|
|
|
447 |
} else {
|
| 26131 |
tejbeer |
448 |
throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
|
|
|
449 |
"You are not authorise to extend billing");
|
| 25276 |
amit.gupta |
450 |
}
|
| 24349 |
amit.gupta |
451 |
return "response";
|
| 25276 |
amit.gupta |
452 |
|
| 24124 |
govind |
453 |
}
|
|
|
454 |
|
| 24159 |
tejbeer |
455 |
@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
|
|
|
456 |
public String getPromoterInfo(HttpServletRequest request,
|
|
|
457 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 27489 |
tejbeer |
458 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
459 |
@RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
|
|
|
460 |
throws Exception {
|
| 24159 |
tejbeer |
461 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
462 |
List<Promoter> promoterInfo = null;
|
|
|
463 |
|
|
|
464 |
long size = 0;
|
| 27489 |
tejbeer |
465 |
|
| 24159 |
tejbeer |
466 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
467 |
.collect(Collectors.toList());
|
|
|
468 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
469 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
| 24986 |
tejbeer |
470 |
Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
|
|
|
471 |
brands.add("Airtel");
|
|
|
472 |
brands.add("Vodafone");
|
|
|
473 |
brands.add("Idea");
|
| 25276 |
amit.gupta |
474 |
LOGGER.info("brands" + brands);
|
| 24159 |
tejbeer |
475 |
model.addAttribute("customRetailers", customRetailers);
|
| 25276 |
amit.gupta |
476 |
model.addAttribute("brands", brands);
|
| 24159 |
tejbeer |
477 |
|
| 27489 |
tejbeer |
478 |
if (fofoId != 0) {
|
|
|
479 |
promoterInfo = promoterRepository.selectAllPromoterByFofoId(fofoId, offset, limit);
|
| 24159 |
tejbeer |
480 |
|
| 27489 |
tejbeer |
481 |
size = promoterRepository.selectPromoterCount(fofoId);
|
|
|
482 |
|
|
|
483 |
} else {
|
|
|
484 |
promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
|
|
|
485 |
|
|
|
486 |
size = promoterRepository.selectAllCount();
|
|
|
487 |
|
|
|
488 |
}
|
| 24159 |
tejbeer |
489 |
if (!promoterInfo.isEmpty()) {
|
|
|
490 |
List<Integer> partnerIds = new ArrayList<>();
|
|
|
491 |
|
|
|
492 |
for (Promoter promoterdetail : promoterInfo) {
|
|
|
493 |
partnerIds.add(promoterdetail.getRetailerId());
|
|
|
494 |
}
|
|
|
495 |
Map<Integer, CustomRetailer> partnersMap = null;
|
| 24349 |
amit.gupta |
496 |
if (!partnerIds.equals(null)) {
|
| 24159 |
tejbeer |
497 |
LOGGER.info("partnerIds" + partnerIds);
|
| 24349 |
amit.gupta |
498 |
partnersMap = retailerService.getFofoRetailers(partnerIds);
|
| 24159 |
tejbeer |
499 |
}
|
| 24349 |
amit.gupta |
500 |
|
| 24159 |
tejbeer |
501 |
LOGGER.info("partnerIds" + partnersMap);
|
|
|
502 |
model.addAttribute("promoterInfo", promoterInfo);
|
|
|
503 |
model.addAttribute("partnersMap", partnersMap);
|
|
|
504 |
model.addAttribute("start", offset + 1);
|
|
|
505 |
model.addAttribute("size", size);
|
|
|
506 |
model.addAttribute("url", "/getPaginatedPromoterInfo");
|
|
|
507 |
|
|
|
508 |
if (promoterInfo.size() < limit) {
|
|
|
509 |
model.addAttribute("end", offset + promoterInfo.size());
|
|
|
510 |
} else {
|
|
|
511 |
model.addAttribute("end", offset + limit);
|
|
|
512 |
}
|
|
|
513 |
} else {
|
|
|
514 |
model.addAttribute("promoterInfo", promoterInfo);
|
|
|
515 |
model.addAttribute("size", size);
|
|
|
516 |
}
|
|
|
517 |
return "promoter-info";
|
|
|
518 |
|
|
|
519 |
}
|
| 24349 |
amit.gupta |
520 |
|
| 24159 |
tejbeer |
521 |
@RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
|
|
|
522 |
public String getPaginatedPromoterInfo(HttpServletRequest request,
|
|
|
523 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 27489 |
tejbeer |
524 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
525 |
@RequestParam(name = "fofoId", required = false, defaultValue = "0") int fofoId, Model model)
|
| 24159 |
tejbeer |
526 |
throws ProfitMandiBusinessException {
|
|
|
527 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
|
|
528 |
List<Promoter> promoterInfo = null;
|
| 27489 |
tejbeer |
529 |
if (fofoId != 0) {
|
|
|
530 |
promoterInfo = promoterRepository.selectAllPromoterByFofoId(fofoId, offset, limit);
|
|
|
531 |
} else {
|
|
|
532 |
promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
|
|
|
533 |
}
|
| 24159 |
tejbeer |
534 |
LOGGER.info("promoterInfo" + promoterInfo);
|
|
|
535 |
if (!promoterInfo.isEmpty()) {
|
|
|
536 |
List<Integer> partnerIds = new ArrayList<>();
|
|
|
537 |
|
|
|
538 |
for (Promoter promoterdetail : promoterInfo) {
|
|
|
539 |
partnerIds.add(promoterdetail.getRetailerId());
|
|
|
540 |
}
|
|
|
541 |
Map<Integer, CustomRetailer> partnersMap = null;
|
| 24349 |
amit.gupta |
542 |
if (!partnerIds.equals(null)) {
|
| 24159 |
tejbeer |
543 |
LOGGER.info("partnerIds" + partnerIds);
|
| 24349 |
amit.gupta |
544 |
partnersMap = retailerService.getFofoRetailers(partnerIds);
|
| 24159 |
tejbeer |
545 |
}
|
| 24349 |
amit.gupta |
546 |
|
| 24159 |
tejbeer |
547 |
LOGGER.info("partnerIds" + partnersMap);
|
|
|
548 |
model.addAttribute("promoterInfo", promoterInfo);
|
|
|
549 |
model.addAttribute("partnersMap", partnersMap);
|
|
|
550 |
model.addAttribute("url", "/getPaginatedPromoterInfo");
|
|
|
551 |
} else {
|
|
|
552 |
model.addAttribute("promoterInfo", promoterInfo);
|
|
|
553 |
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
return "promoter-info-paginated";
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
@RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
|
|
|
560 |
public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
|
|
|
561 |
Model model) throws Exception {
|
|
|
562 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
563 |
LOGGER.info("requested url : " + promoterdetailModel);
|
| 26131 |
tejbeer |
564 |
Promoter promoter = promoterRepository.selectById(promoterdetailModel.getId());
|
|
|
565 |
if (promoter == null) {
|
|
|
566 |
promoter = new Promoter();
|
| 24159 |
tejbeer |
567 |
promoter.setBrand(promoterdetailModel.getBrand());
|
|
|
568 |
promoter.setRetailerId(promoterdetailModel.getRetailerId());
|
|
|
569 |
promoter.setCreatedTimestamp(LocalDateTime.now());
|
| 26131 |
tejbeer |
570 |
|
| 24159 |
tejbeer |
571 |
}
|
| 27489 |
tejbeer |
572 |
promoter.setName(promoterdetailModel.getName());
|
|
|
573 |
promoter.setEmail(promoterdetailModel.getEmail());
|
|
|
574 |
promoter.setMobile(promoterdetailModel.getMobile());
|
|
|
575 |
promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
|
|
|
576 |
promoter.setStatus(promoterdetailModel.isStatus());
|
|
|
577 |
LOGGER.info("sdport" + promoterdetailModel.isStatus());
|
|
|
578 |
promoterRepository.persist(promoter);
|
| 24159 |
tejbeer |
579 |
|
|
|
580 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
581 |
|
|
|
582 |
return "response";
|
|
|
583 |
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
@RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
|
|
|
587 |
public String removePromoterfromPartnerStore(HttpServletRequest request,
|
|
|
588 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
|
|
589 |
|
|
|
590 |
Promoter promoter = promoterRepository.selectById(id);
|
|
|
591 |
|
| 26131 |
tejbeer |
592 |
promoter.setStatus(false);
|
| 24159 |
tejbeer |
593 |
promoterRepository.persist(promoter);
|
|
|
594 |
|
|
|
595 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
596 |
|
|
|
597 |
return "response";
|
|
|
598 |
}
|
|
|
599 |
|
|
|
600 |
@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
|
|
|
601 |
public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
|
|
|
602 |
throws Exception {
|
|
|
603 |
|
|
|
604 |
Location location = new Location();
|
|
|
605 |
location.setName(addLocationModel.getName());
|
|
|
606 |
location.setLine1(addLocationModel.getLine1());
|
|
|
607 |
location.setLine2(addLocationModel.getLine2());
|
|
|
608 |
location.setCity(addLocationModel.getCity());
|
|
|
609 |
location.setState(addLocationModel.getState());
|
|
|
610 |
location.setPin(addLocationModel.getPin());
|
|
|
611 |
|
|
|
612 |
LOGGER.info("PostLocation" + location);
|
|
|
613 |
locationRepository.persist(location);
|
|
|
614 |
|
|
|
615 |
User user = userRepository.selectById(addLocationModel.getUserId());
|
|
|
616 |
user.setLocation(location.getId());
|
|
|
617 |
userRepository.persist(user);
|
|
|
618 |
|
|
|
619 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
620 |
return "response";
|
|
|
621 |
|
|
|
622 |
}
|
|
|
623 |
|
|
|
624 |
@RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
|
|
|
625 |
public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
|
|
|
626 |
Model model) throws Exception {
|
|
|
627 |
|
|
|
628 |
Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
|
|
|
629 |
|
|
|
630 |
userlocation.setName(addLocationModel.getName());
|
|
|
631 |
userlocation.setCity(addLocationModel.getCity());
|
|
|
632 |
userlocation.setLine1(addLocationModel.getLine1());
|
|
|
633 |
userlocation.setLine2(addLocationModel.getLine2());
|
|
|
634 |
userlocation.setPin(addLocationModel.getPin());
|
|
|
635 |
userlocation.setState(addLocationModel.getState());
|
|
|
636 |
|
|
|
637 |
locationRepository.persist(userlocation);
|
|
|
638 |
|
|
|
639 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
640 |
return "response";
|
|
|
641 |
|
|
|
642 |
}
|
|
|
643 |
|
| 27231 |
tejbeer |
644 |
@RequestMapping(value = "/getPartnerReadonlyInfo")
|
|
|
645 |
public String getPartnerReadonlyInfo(HttpServletRequest request, Model model) throws Exception {
|
|
|
646 |
|
|
|
647 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
648 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
649 |
|
|
|
650 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
651 |
|
|
|
652 |
List<Integer> fofoIds = pp.get(authUser.getId());
|
|
|
653 |
|
|
|
654 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
655 |
|
|
|
656 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| 27243 |
tejbeer |
657 |
|
| 27231 |
tejbeer |
658 |
return "partner-readonly-info";
|
|
|
659 |
|
|
|
660 |
}
|
|
|
661 |
|
| 28071 |
tejbeer |
662 |
@RequestMapping(value = "/getBlockBrandMapping")
|
|
|
663 |
public String getBlockBrandMapping(HttpServletRequest request, Model model) throws Exception {
|
|
|
664 |
|
|
|
665 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
|
|
666 |
Set<String> brands = null;
|
|
|
667 |
|
|
|
668 |
brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
669 |
.collect(Collectors.toSet());
|
|
|
670 |
|
|
|
671 |
LOGGER.info("brands" + brands);
|
|
|
672 |
model.addAttribute("brands", brands);
|
|
|
673 |
|
|
|
674 |
return "block-brand-mapping";
|
|
|
675 |
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
@RequestMapping(value = "/getBlockBrand")
|
|
|
679 |
public String getBlockBrand(HttpServletRequest request,
|
|
|
680 |
@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
|
|
|
681 |
throws Exception {
|
|
|
682 |
|
|
|
683 |
List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
|
|
|
684 |
|
|
|
685 |
List<Integer> blockBrandPartners = retailerBlockBrands.stream().map(x -> x.getFofoId())
|
|
|
686 |
.collect(Collectors.toList());
|
|
|
687 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
|
| 28272 |
tejbeer |
688 |
|
| 28071 |
tejbeer |
689 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
|
|
690 |
model.addAttribute("blockBrandPartners", blockBrandPartners);
|
|
|
691 |
model.addAttribute("retailerBlockBrands", retailerBlockBrands);
|
|
|
692 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
693 |
|
|
|
694 |
return "retailer-block-brand";
|
|
|
695 |
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
@RequestMapping(value = "/getRetailerBlockBrandMappping", method = RequestMethod.POST)
|
|
|
699 |
public String getBlockBrandMappping(HttpServletRequest request,
|
|
|
700 |
@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
|
|
|
701 |
@RequestParam(name = "fofoIds", required = true, defaultValue = "0") List<Integer> fofoIds, Model model)
|
|
|
702 |
throws Exception {
|
|
|
703 |
List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
|
|
|
704 |
if (!retailerBlockBrands.isEmpty()) {
|
|
|
705 |
retailerBlockBrandsRepository.deleteAllbyBrands(brand);
|
|
|
706 |
}
|
|
|
707 |
|
|
|
708 |
for (int id : fofoIds) {
|
|
|
709 |
RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
|
|
|
710 |
retailerBlockBrand.setFofoId(id);
|
|
|
711 |
retailerBlockBrand.setBlockBrands(brand);
|
|
|
712 |
retailerBlockBrandsRepository.persist(retailerBlockBrand);
|
|
|
713 |
|
|
|
714 |
}
|
|
|
715 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
716 |
|
|
|
717 |
return "response";
|
|
|
718 |
}
|
|
|
719 |
|
| 28272 |
tejbeer |
720 |
@RequestMapping(value = "/getBrandslimit", method = RequestMethod.GET)
|
|
|
721 |
public String getBrandslimit(HttpServletRequest request, Model model) throws Exception {
|
|
|
722 |
|
|
|
723 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
|
|
724 |
Set<String> brands = null;
|
|
|
725 |
|
|
|
726 |
brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
727 |
.collect(Collectors.toSet());
|
|
|
728 |
|
|
|
729 |
model.addAttribute("brands", brands);
|
|
|
730 |
|
|
|
731 |
return "brands-limit";
|
|
|
732 |
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
@RequestMapping(value = "/setUpdateLimit", method = RequestMethod.POST)
|
|
|
736 |
public String getUpdateLimit(HttpServletRequest request,
|
|
|
737 |
@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
|
|
|
738 |
@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
|
|
|
739 |
@RequestParam(name = "limit", required = true, defaultValue = "0") float limit, Model model)
|
|
|
740 |
throws Exception {
|
|
|
741 |
|
|
|
742 |
CustomRetailer cr = retailerService.getFofoRetailer(fofoId);
|
| 28277 |
tejbeer |
743 |
|
|
|
744 |
Map.Entry<Integer, CustomRetailer> customRetailers = new AbstractMap.SimpleEntry(cr.getPartnerId(), cr);
|
|
|
745 |
|
|
|
746 |
// Map<Integer, CustomRetailer> customRetailers =
|
|
|
747 |
// retailerService.getFofoRetailers(true);
|
|
|
748 |
LOGGER.info("customRetailers" + customRetailers);
|
| 28272 |
tejbeer |
749 |
RetailerBrandsLimit retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
|
| 28277 |
tejbeer |
750 |
|
| 28272 |
tejbeer |
751 |
if (retailerBrands == null) {
|
|
|
752 |
retailerBrands = new RetailerBrandsLimit();
|
|
|
753 |
retailerBrands.setBrandLimit(limit);
|
|
|
754 |
retailerBrands.setIsUpdate(1);
|
|
|
755 |
retailerBrands.setCreatedTimestamp(LocalDateTime.now());
|
|
|
756 |
retailerBrands.setPartnerId(fofoId);
|
|
|
757 |
retailerBrands.setBrandName(brand);
|
|
|
758 |
retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
759 |
retailerBrandsLimitRepository.persist(retailerBrands);
|
|
|
760 |
|
|
|
761 |
}
|
|
|
762 |
|
|
|
763 |
else {
|
|
|
764 |
retailerBrands.setBrandLimit(limit);
|
|
|
765 |
retailerBrands.setIsUpdate(1);
|
|
|
766 |
retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
767 |
retailerBrandsLimitRepository.persist(retailerBrands);
|
|
|
768 |
|
|
|
769 |
}
|
|
|
770 |
retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
|
|
|
771 |
|
|
|
772 |
Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = new HashMap<>();
|
|
|
773 |
|
|
|
774 |
retailerBrandsLimitMap.put(retailerBrands.getPartnerId(), retailerBrands);
|
|
|
775 |
|
|
|
776 |
BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
|
|
|
777 |
|
|
|
778 |
model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
|
|
|
779 |
model.addAttribute("brandLimit", brandLimit);
|
|
|
780 |
model.addAttribute("customRetailers", customRetailers);
|
| 28277 |
tejbeer |
781 |
|
|
|
782 |
model.addAttribute("brand", brand);
|
| 28272 |
tejbeer |
783 |
return "brands-limit-row-mapping";
|
|
|
784 |
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
@RequestMapping(value = "/getRetailerBrandslimitMapping", method = RequestMethod.GET)
|
|
|
788 |
public String getRetailerBrandslimit(HttpServletRequest request,
|
|
|
789 |
@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
|
|
|
790 |
throws Exception {
|
|
|
791 |
|
|
|
792 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
|
| 28283 |
tejbeer |
793 |
List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrands(brand);
|
|
|
794 |
Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
|
|
|
795 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 28272 |
tejbeer |
796 |
|
|
|
797 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
798 |
model.addAttribute("brand", brand);
|
| 28283 |
tejbeer |
799 |
model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
|
| 28272 |
tejbeer |
800 |
|
|
|
801 |
BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
|
|
|
802 |
|
|
|
803 |
model.addAttribute("brandLimit", brandLimit);
|
|
|
804 |
|
|
|
805 |
return "brands-limit-mapping";
|
|
|
806 |
|
|
|
807 |
}
|
|
|
808 |
|
|
|
809 |
@RequestMapping(value = "/setBrandWiseLimit", method = RequestMethod.POST)
|
|
|
810 |
public String brandwiseLimit(HttpServletRequest request,
|
|
|
811 |
@RequestParam(name = "brands", required = true, defaultValue = "") String brands,
|
|
|
812 |
@RequestParam(name = "limit", required = true, defaultValue = "") float limit, Model model)
|
|
|
813 |
throws Exception {
|
|
|
814 |
|
|
|
815 |
LOGGER.info("limit" + limit);
|
|
|
816 |
|
|
|
817 |
BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brands);
|
|
|
818 |
|
|
|
819 |
List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrands(brands);
|
|
|
820 |
|
|
|
821 |
Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
|
|
|
822 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
823 |
|
|
|
824 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
|
|
|
825 |
|
|
|
826 |
if (brandLimit == null) {
|
|
|
827 |
|
|
|
828 |
brandLimit = new BrandLimit();
|
|
|
829 |
brandLimit.setBrandLimit(limit);
|
|
|
830 |
brandLimit.setBrandName(brands);
|
|
|
831 |
brandLimit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
832 |
brandLimit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
833 |
brandLimitRepository.persist(brandLimit);
|
|
|
834 |
|
|
|
835 |
}
|
|
|
836 |
|
|
|
837 |
else {
|
|
|
838 |
brandLimit.setBrandLimit(limit);
|
|
|
839 |
|
|
|
840 |
brandLimit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
841 |
brandLimitRepository.persist(brandLimit);
|
|
|
842 |
|
|
|
843 |
}
|
|
|
844 |
brandLimit = brandLimitRepository.setLimitByBrands(brands);
|
|
|
845 |
|
|
|
846 |
LOGGER.info("brandLimit" + brandLimit);
|
| 28277 |
tejbeer |
847 |
model.addAttribute("brand", brands);
|
| 28272 |
tejbeer |
848 |
model.addAttribute("brandLimit", brandLimit);
|
|
|
849 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
850 |
model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
|
|
|
851 |
return "brands-limit-mapping";
|
|
|
852 |
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
}
|