Subversion Repositories SmartDukaan

Rev

Rev 26771 | Rev 26809 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
24124 govind 8
import java.util.ArrayList;
25276 amit.gupta 9
import java.util.Arrays;
24349 amit.gupta 10
import java.util.HashMap;
24124 govind 11
import java.util.List;
22981 ashik.ali 12
import java.util.Map;
24986 tejbeer 13
import java.util.Set;
24159 tejbeer 14
import java.util.stream.Collectors;
22981 ashik.ali 15
 
16
import javax.servlet.http.HttpServletRequest;
25276 amit.gupta 17
import javax.transaction.Transactional;
22981 ashik.ali 18
 
24159 tejbeer 19
import org.apache.logging.log4j.LogManager;
23955 govind 20
import org.apache.logging.log4j.Logger;
24159 tejbeer 21
import org.json.JSONObject;
22981 ashik.ali 22
import org.springframework.beans.factory.annotation.Autowired;
24159 tejbeer 23
import org.springframework.beans.factory.annotation.Qualifier;
23494 ashik.ali 24
import org.springframework.core.io.InputStreamResource;
25
import org.springframework.http.HttpHeaders;
26
import org.springframework.http.HttpStatus;
23330 ashik.ali 27
import org.springframework.http.ResponseEntity;
22981 ashik.ali 28
import org.springframework.stereotype.Controller;
29
import org.springframework.ui.Model;
24124 govind 30
import org.springframework.web.bind.annotation.GetMapping;
31
import org.springframework.web.bind.annotation.PostMapping;
23026 ashik.ali 32
import org.springframework.web.bind.annotation.RequestBody;
22981 ashik.ali 33
import org.springframework.web.bind.annotation.RequestMapping;
34
import org.springframework.web.bind.annotation.RequestMethod;
35
import org.springframework.web.bind.annotation.RequestParam;
36
 
23494 ashik.ali 37
import com.spice.profitmandi.common.enumuration.ContentType;
23955 govind 38
import com.spice.profitmandi.common.enumuration.CounterSize;
22981 ashik.ali 39
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24123 tejbeer 40
import com.spice.profitmandi.common.model.AddLocationModel;
24124 govind 41
import com.spice.profitmandi.common.model.CustomRetailer;
22981 ashik.ali 42
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24159 tejbeer 43
import com.spice.profitmandi.common.model.PromoterDetailModel;
23026 ashik.ali 44
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
23330 ashik.ali 45
import com.spice.profitmandi.common.web.util.ResponseSender;
23494 ashik.ali 46
import com.spice.profitmandi.dao.entity.dtr.Document;
47
import com.spice.profitmandi.dao.entity.dtr.Retailer;
48
import com.spice.profitmandi.dao.entity.dtr.Shop;
24124 govind 49
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24159 tejbeer 50
import com.spice.profitmandi.dao.entity.user.Location;
51
import com.spice.profitmandi.dao.entity.user.Promoter;
24123 tejbeer 52
import com.spice.profitmandi.dao.entity.user.User;
23494 ashik.ali 53
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
24124 govind 54
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24159 tejbeer 55
import com.spice.profitmandi.dao.repository.dtr.Mongo;
23494 ashik.ali 56
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
57
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
24123 tejbeer 58
import com.spice.profitmandi.dao.repository.user.LocationRepository;
24159 tejbeer 59
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
24123 tejbeer 60
import com.spice.profitmandi.dao.repository.user.UserRepository;
24349 amit.gupta 61
import com.spice.profitmandi.service.PartnerInvestmentService;
24159 tejbeer 62
import com.spice.profitmandi.service.inventory.InventoryService;
22981 ashik.ali 63
import com.spice.profitmandi.service.user.RetailerService;
25276 amit.gupta 64
import com.spice.profitmandi.web.model.LoginDetails;
65
import com.spice.profitmandi.web.util.CookiesProcessor;
24123 tejbeer 66
import com.spice.profitmandi.web.util.MVCResponseSender;
22981 ashik.ali 67
 
68
@Controller
25277 amit.gupta 69
@Transactional(rollbackOn = Throwable.class)
22981 ashik.ali 70
public class RetailerController {
71
 
23568 govind 72
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
24124 govind 73
 
22981 ashik.ali 74
	@Autowired
75
	private RetailerService retailerService;
24124 govind 76
 
23330 ashik.ali 77
	@Autowired
23494 ashik.ali 78
	private RetailerRepository retailerRepository;
24124 govind 79
 
23494 ashik.ali 80
	@Autowired
81
	private ShopRepository shopRepository;
24124 govind 82
 
23494 ashik.ali 83
	@Autowired
24124 govind 84
	private FofoStoreRepository fofoStoreRepository;
85
 
86
	@Autowired
23494 ashik.ali 87
	private DocumentRepository documentRepository;
24124 govind 88
 
23494 ashik.ali 89
	@Autowired
25276 amit.gupta 90
	private CookiesProcessor cookiesProcessor;
91
 
92
	@Autowired
24159 tejbeer 93
	@Qualifier("userUserRepository")
24123 tejbeer 94
	private UserRepository userRepository;
24124 govind 95
 
24123 tejbeer 96
	@Autowired
97
	private LocationRepository locationRepository;
24124 govind 98
 
24123 tejbeer 99
	@Autowired
23330 ashik.ali 100
	private ResponseSender<?> responseSender;
24124 govind 101
 
24123 tejbeer 102
	@Autowired
103
	private MVCResponseSender mvcResponseSender;
24124 govind 104
 
24159 tejbeer 105
	@Autowired
106
	private InventoryService inventoryService;
107
 
108
	@Autowired
109
	private PromoterRepository promoterRepository;
110
 
111
	@Autowired
24349 amit.gupta 112
	private PartnerInvestmentService partnerInvestmentService;
113
 
114
	@Autowired
24159 tejbeer 115
	private Mongo mongoClient;
116
 
23784 ashik.ali 117
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
24124 govind 118
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
119
			@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
120
			Model model) throws ProfitMandiBusinessException {
121
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
122
				emailIdOrMobileNumber);
26771 amit.gupta 123
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
124
		model.addAllAttributes(map);
23955 govind 125
		model.addAttribute("counterSizes", CounterSize.values());
26209 tejbeer 126
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
127
		LOGGER.info("warehouseMap", warehouseMap);
128
		model.addAttribute("warehouses", warehouseMap);
26771 amit.gupta 129
		if (map.containsKey("retailer")) {
130
			Retailer retailer = (Retailer) map.get("retailer");
131
			User user = userRepository.selectById(retailer.getId());
132
			if (user.getLocation() != null) {
133
				Location location = locationRepository.selectById(user.getLocation());
134
				model.addAttribute("locationdetail", location);
135
				LOGGER.info("location" + location);
136
			}
137
		}
22981 ashik.ali 138
		return "retailer-details";
139
	}
24124 govind 140
 
23026 ashik.ali 141
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
24124 govind 142
	public String updateRetailerDetails(HttpServletRequest request,
143
			@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
23026 ashik.ali 144
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
145
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
146
		model.addAllAttributes(map);
23955 govind 147
		model.addAttribute("counterSizes", CounterSize.values());
26209 tejbeer 148
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
149
		LOGGER.info("warehouseMap", warehouseMap);
150
		model.addAttribute("warehouses", warehouseMap);
23026 ashik.ali 151
		return "retailer-details";
152
	}
22981 ashik.ali 153
 
154
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
24124 govind 155
	public String retailerInfo(HttpServletRequest request) throws Exception {
22981 ashik.ali 156
		return "retailer-info";
157
	}
24124 govind 158
 
23330 ashik.ali 159
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
24124 govind 160
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
23330 ashik.ali 161
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
162
	}
24124 govind 163
 
23494 ashik.ali 164
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
24124 govind 165
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
166
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
167
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
23494 ashik.ali 168
		Document document = documentRepository.selectById(documentId);
23499 ashik.ali 169
		Retailer retailer = retailerRepository.selectById(retailerId);
24124 govind 170
 
171
		if (retailer.getDocumentId() == null) {
23494 ashik.ali 172
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
173
		}
24124 govind 174
		if (retailer.getDocumentId() != documentId) {
23494 ashik.ali 175
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
176
		}
177
		return responseSender.ok(document);
178
	}
24124 govind 179
 
23494 ashik.ali 180
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
24124 govind 181
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
182
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
183
			throws ProfitMandiBusinessException {
184
 
23499 ashik.ali 185
		Retailer retailer = retailerRepository.selectById(retailerId);
24124 govind 186
 
187
		if (retailer.getDocumentId() == null) {
23494 ashik.ali 188
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
189
		}
24124 govind 190
 
23494 ashik.ali 191
		Document document = documentRepository.selectById(retailer.getDocumentId());
24124 govind 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
		}
24159 tejbeer 200
		// ByteArrayOutputStream byteArrayOutputStream = new
201
		// ByteArrayOutputStream();
24124 govind 202
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
203
 
204
		final HttpHeaders headers = new HttpHeaders();
23494 ashik.ali 205
		String contentType = "";
24124 govind 206
		if (document.getContentType() == ContentType.JPEG) {
23494 ashik.ali 207
			contentType = "image/jpeg";
24124 govind 208
		} else if (document.getContentType() == ContentType.PNG) {
23494 ashik.ali 209
			contentType = "image/png";
24124 govind 210
		} else if (document.getContentType() == ContentType.PDF) {
23494 ashik.ali 211
			contentType = "application/pdf";
212
		}
24124 govind 213
		headers.set("Content-Type", contentType);
214
		headers.set("Content-disposition", "inline; filename=" + document.getName());
215
		headers.setContentLength(document.getSize());
216
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
217
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
218
 
24159 tejbeer 219
		// return
220
		// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
23494 ashik.ali 221
	}
24124 govind 222
 
23494 ashik.ali 223
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
24124 govind 224
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
225
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
226
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
23494 ashik.ali 227
		Shop shop = shopRepository.selectById(shopId);
24124 govind 228
 
229
		if (shop.getRetailerId() != retailerId) {
23494 ashik.ali 230
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
231
		}
24124 govind 232
 
233
		if (shop.getDocumentId() == null) {
23494 ashik.ali 234
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
235
		}
24124 govind 236
 
23494 ashik.ali 237
		Document document = documentRepository.selectById(shop.getDocumentId());
238
		return responseSender.ok(document);
239
	}
24124 govind 240
 
23494 ashik.ali 241
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
24124 govind 242
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
243
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
244
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
245
			throws ProfitMandiBusinessException {
246
 
23494 ashik.ali 247
		Shop shop = shopRepository.selectById(shopId);
24124 govind 248
 
249
		if (shop.getRetailerId() != retailerId) {
23494 ashik.ali 250
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
251
		}
24124 govind 252
 
253
		if (shop.getDocumentId() == null) {
23494 ashik.ali 254
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
255
		}
24124 govind 256
 
23494 ashik.ali 257
		Document document = documentRepository.selectById(shop.getDocumentId());
24124 govind 258
 
23494 ashik.ali 259
		FileInputStream file = null;
260
		try {
261
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
262
		} catch (FileNotFoundException e) {
263
			LOGGER.error("Retailer Document file not found : ", e);
264
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
265
		}
24159 tejbeer 266
		// ByteArrayOutputStream byteArrayOutputStream = new
267
		// ByteArrayOutputStream();
24124 govind 268
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
269
 
270
		final HttpHeaders headers = new HttpHeaders();
23494 ashik.ali 271
		String contentType = "";
24124 govind 272
		if (document.getContentType() == ContentType.JPEG) {
23494 ashik.ali 273
			contentType = "image/jpeg";
24124 govind 274
		} else if (document.getContentType() == ContentType.PNG) {
23494 ashik.ali 275
			contentType = "image/png";
24124 govind 276
		} else if (document.getContentType() == ContentType.PDF) {
23494 ashik.ali 277
			contentType = "application/pdf";
278
		}
24124 govind 279
		headers.set("Content-Type", contentType);
280
		headers.set("Content-disposition", "inline; filename=" + document.getName());
281
		headers.setContentLength(document.getSize());
282
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
283
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
284
 
24159 tejbeer 285
		// return
286
		// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
23494 ashik.ali 287
	}
24124 govind 288
 
289
	@GetMapping(value = "/getAllStores")
290
	public String getAllStores(HttpServletRequest request, Model model) {
291
 
25276 amit.gupta 292
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
293
				.collect(Collectors.toList());
24349 amit.gupta 294
		Map<Integer, Boolean> investments = new HashMap<>();
24124 govind 295
 
24349 amit.gupta 296
		for (FofoStore fofoStore : fofoStores) {
297
			boolean isOk = false;
298
			if (fofoStore.getGraceDate() != null && fofoStore.getGraceDate().isAfter(LocalDate.now())) {
299
				isOk = true;
300
			} else {
301
				try {
25276 amit.gupta 302
					isOk = partnerInvestmentService.isInvestmentOk(fofoStore.getId(), 10,
303
							ProfitMandiConstants.CUTOFF_INVESTMENT);
304
					if (fofoStore.getGraceCount() > 0) {
24349 amit.gupta 305
						fofoStore.setGraceDate(null);
306
						fofoStore.setGraceCount(0);
307
						fofoStoreRepository.persist(fofoStore);
308
					}
309
				} catch (ProfitMandiBusinessException e) {
310
				}
311
			}
312
			investments.put(fofoStore.getId(), isOk);
313
		}
24124 govind 314
 
24349 amit.gupta 315
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers();
24124 govind 316
		model.addAttribute("fofoStores", fofoStores);
24349 amit.gupta 317
		model.addAttribute("investments", investments);
24124 govind 318
		model.addAttribute("customRetailers", customRetailers);
319
 
320
		return "store";
321
 
322
	}
323
 
24349 amit.gupta 324
	@GetMapping(value = "/partners")
325
	public String getStoreName(HttpServletRequest request, Model model, @RequestParam String query) throws Exception {
326
		model.addAttribute("response", mvcResponseSender
327
				.createResponseString(retailerService.getFofoRetailers().values().stream().filter(x -> {
328
					return x.getDisplayName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?");
329
				}).collect(Collectors.toList())));
330
		return "response";
331
	}
332
 
24124 govind 333
	@PostMapping(value = "/deactivateStore")
334
	public String deActivateStore(HttpServletRequest request,
335
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
336
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
25276 amit.gupta 337
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26808 amit.gupta 338
		if (!Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com","amit.gupta@smartdukaan.com")
26131 tejbeer 339
				.contains(loginDetails.getEmailId())) {
340
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
341
					"You are not authorise to deactivate retailer");
25276 amit.gupta 342
		}
24843 govind 343
		fofoStore.setActive(false);
344
		fofoStoreRepository.persist(fofoStore);
24124 govind 345
		LOGGER.info("inserted into InActiveFofoStore successfully");
346
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
347
 
348
		return "response";
349
 
350
	}
25276 amit.gupta 351
 
352
	@GetMapping(value = "/getAllInactiveStores")
353
	public String getInactiveStores(HttpServletRequest request, Model model) {
354
		List<FofoStore> inActiveFofoStores = fofoStoreRepository.selectInActiveStore();
355
		Map<Integer, CustomRetailer> customRetailers = retailerService
356
				.getFofoRetailers(inActiveFofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
24680 govind 357
		model.addAttribute("inActiveFofoStores", inActiveFofoStores);
358
		model.addAttribute("customRetailers", customRetailers);
359
		return "inactive-stores";
360
	}
25276 amit.gupta 361
 
362
	// Extend billing for 2 days
24349 amit.gupta 363
	@PostMapping(value = "/extendBilling")
364
	public String extendBilling(HttpServletRequest request,
365
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
366
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
25276 amit.gupta 367
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26601 amit.gupta 368
		if (Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "prakash.rai@smartdukaan.com", "amit.gupta@shop2020.in")
26131 tejbeer 369
				.contains(loginDetails.getEmailId())) {
25276 amit.gupta 370
			fofoStore.setGraceDate(LocalDate.now().plusDays(2));
371
			fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
372
			fofoStoreRepository.persist(fofoStore);
373
			model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
374
		} else {
26131 tejbeer 375
			throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
376
					"You are not authorise to extend billing");
25276 amit.gupta 377
		}
24349 amit.gupta 378
		return "response";
25276 amit.gupta 379
 
24124 govind 380
	}
381
 
24159 tejbeer 382
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
383
	public String getPromoterInfo(HttpServletRequest request,
384
			@RequestParam(name = "offset", defaultValue = "0") int offset,
385
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
386
		LOGGER.info("requested url : " + request.getRequestURL().toString());
387
		List<Promoter> promoterInfo = null;
388
 
389
		long size = 0;
390
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
391
				.collect(Collectors.toList());
392
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
393
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
24986 tejbeer 394
		Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
395
		brands.add("Airtel");
396
		brands.add("Vodafone");
397
		brands.add("Idea");
25276 amit.gupta 398
		LOGGER.info("brands" + brands);
24159 tejbeer 399
		model.addAttribute("customRetailers", customRetailers);
25276 amit.gupta 400
		model.addAttribute("brands", brands);
24159 tejbeer 401
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
402
 
403
		size = promoterRepository.selectAllCount();
404
 
405
		LOGGER.info("promoterInfo" + promoterInfo);
406
		if (!promoterInfo.isEmpty()) {
407
			List<Integer> partnerIds = new ArrayList<>();
408
 
409
			for (Promoter promoterdetail : promoterInfo) {
410
				partnerIds.add(promoterdetail.getRetailerId());
411
			}
412
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 413
			if (!partnerIds.equals(null)) {
24159 tejbeer 414
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 415
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 416
			}
24349 amit.gupta 417
 
24159 tejbeer 418
			LOGGER.info("partnerIds" + partnersMap);
419
			model.addAttribute("promoterInfo", promoterInfo);
420
			model.addAttribute("partnersMap", partnersMap);
421
			model.addAttribute("start", offset + 1);
422
			model.addAttribute("size", size);
423
			model.addAttribute("url", "/getPaginatedPromoterInfo");
424
 
425
			if (promoterInfo.size() < limit) {
426
				model.addAttribute("end", offset + promoterInfo.size());
427
			} else {
428
				model.addAttribute("end", offset + limit);
429
			}
430
		} else {
431
			model.addAttribute("promoterInfo", promoterInfo);
432
			model.addAttribute("size", size);
433
		}
434
		return "promoter-info";
435
 
436
	}
24349 amit.gupta 437
 
24159 tejbeer 438
	@RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
439
	public String getPaginatedPromoterInfo(HttpServletRequest request,
440
			@RequestParam(name = "offset", defaultValue = "0") int offset,
441
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
442
			throws ProfitMandiBusinessException {
443
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
444
		List<Promoter> promoterInfo = null;
445
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
446
 
447
		LOGGER.info("promoterInfo" + promoterInfo);
448
		if (!promoterInfo.isEmpty()) {
449
			List<Integer> partnerIds = new ArrayList<>();
450
 
451
			for (Promoter promoterdetail : promoterInfo) {
452
				partnerIds.add(promoterdetail.getRetailerId());
453
			}
454
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 455
			if (!partnerIds.equals(null)) {
24159 tejbeer 456
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 457
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 458
			}
24349 amit.gupta 459
 
24159 tejbeer 460
			LOGGER.info("partnerIds" + partnersMap);
461
			model.addAttribute("promoterInfo", promoterInfo);
462
			model.addAttribute("partnersMap", partnersMap);
463
			model.addAttribute("url", "/getPaginatedPromoterInfo");
464
		} else {
465
			model.addAttribute("promoterInfo", promoterInfo);
466
 
467
		}
468
 
469
		return "promoter-info-paginated";
470
	}
471
 
472
	@RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
473
	public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
474
			Model model) throws Exception {
475
		LOGGER.info("requested url : " + request.getRequestURL().toString());
476
		LOGGER.info("requested url : " + promoterdetailModel);
26131 tejbeer 477
		Promoter promoter = promoterRepository.selectById(promoterdetailModel.getId());
478
		if (promoter == null) {
479
			promoter = new Promoter();
24159 tejbeer 480
			promoter.setName(promoterdetailModel.getName());
481
			promoter.setBrand(promoterdetailModel.getBrand());
482
			promoter.setEmail(promoterdetailModel.getEmail());
483
			promoter.setMobile(promoterdetailModel.getMobile());
484
			promoter.setRetailerId(promoterdetailModel.getRetailerId());
485
			promoter.setCreatedTimestamp(LocalDateTime.now());
26131 tejbeer 486
			promoter.setStatus(promoterdetailModel.isStatus());
24429 tejbeer 487
			promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
24159 tejbeer 488
			promoterRepository.persist(promoter);
489
		} else {
26131 tejbeer 490
 
491
			promoter.setRetailerId(promoterdetailModel.getRetailerId());
492
			promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
26132 tejbeer 493
			promoter.setStatus(promoterdetailModel.isStatus());
494
			LOGGER.info("sdport" + promoterdetailModel.isStatus());
26131 tejbeer 495
			promoterRepository.persist(promoter);
25276 amit.gupta 496
 
24159 tejbeer 497
		}
498
 
499
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
500
 
501
		return "response";
502
 
503
	}
504
 
505
	@RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
506
	public String removePromoterfromPartnerStore(HttpServletRequest request,
507
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
508
 
509
		Promoter promoter = promoterRepository.selectById(id);
510
 
26131 tejbeer 511
		promoter.setStatus(false);
24159 tejbeer 512
		promoterRepository.persist(promoter);
513
 
514
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
515
 
516
		return "response";
517
	}
518
 
519
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
520
	public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
521
			throws Exception {
522
 
523
		Location location = new Location();
524
		location.setName(addLocationModel.getName());
525
		location.setLine1(addLocationModel.getLine1());
526
		location.setLine2(addLocationModel.getLine2());
527
		location.setCity(addLocationModel.getCity());
528
		location.setState(addLocationModel.getState());
529
		location.setPin(addLocationModel.getPin());
530
 
531
		LOGGER.info("PostLocation" + location);
532
		locationRepository.persist(location);
533
 
534
		User user = userRepository.selectById(addLocationModel.getUserId());
535
		user.setLocation(location.getId());
536
		userRepository.persist(user);
537
 
538
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
539
		return "response";
540
 
541
	}
542
 
543
	@RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
544
	public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
545
			Model model) throws Exception {
546
 
547
		Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
548
 
549
		userlocation.setName(addLocationModel.getName());
550
		userlocation.setCity(addLocationModel.getCity());
551
		userlocation.setLine1(addLocationModel.getLine1());
552
		userlocation.setLine2(addLocationModel.getLine2());
553
		userlocation.setPin(addLocationModel.getPin());
554
		userlocation.setState(addLocationModel.getState());
555
 
556
		locationRepository.persist(userlocation);
557
 
558
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
559
		return "response";
560
 
561
	}
562
 
24124 govind 563
}