Subversion Repositories SmartDukaan

Rev

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