Subversion Repositories SmartDukaan

Rev

Rev 24429 | Rev 24843 | 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;
24159 tejbeer 12
import java.util.stream.Collectors;
22981 ashik.ali 13
 
14
import javax.servlet.http.HttpServletRequest;
15
 
24159 tejbeer 16
import org.apache.logging.log4j.LogManager;
23955 govind 17
import org.apache.logging.log4j.Logger;
24159 tejbeer 18
import org.json.JSONObject;
22981 ashik.ali 19
import org.springframework.beans.factory.annotation.Autowired;
24159 tejbeer 20
import org.springframework.beans.factory.annotation.Qualifier;
23494 ashik.ali 21
import org.springframework.core.io.InputStreamResource;
22
import org.springframework.http.HttpHeaders;
23
import org.springframework.http.HttpStatus;
23330 ashik.ali 24
import org.springframework.http.ResponseEntity;
22981 ashik.ali 25
import org.springframework.stereotype.Controller;
26
import org.springframework.transaction.annotation.Transactional;
27
import org.springframework.ui.Model;
24124 govind 28
import org.springframework.web.bind.annotation.GetMapping;
29
import org.springframework.web.bind.annotation.PostMapping;
23026 ashik.ali 30
import org.springframework.web.bind.annotation.RequestBody;
22981 ashik.ali 31
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestParam;
34
 
23494 ashik.ali 35
import com.spice.profitmandi.common.enumuration.ContentType;
23955 govind 36
import com.spice.profitmandi.common.enumuration.CounterSize;
22981 ashik.ali 37
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24123 tejbeer 38
import com.spice.profitmandi.common.model.AddLocationModel;
24124 govind 39
import com.spice.profitmandi.common.model.CustomRetailer;
22981 ashik.ali 40
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24159 tejbeer 41
import com.spice.profitmandi.common.model.PromoterDetailModel;
23026 ashik.ali 42
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
23330 ashik.ali 43
import com.spice.profitmandi.common.web.util.ResponseSender;
23494 ashik.ali 44
import com.spice.profitmandi.dao.entity.dtr.Document;
45
import com.spice.profitmandi.dao.entity.dtr.Retailer;
46
import com.spice.profitmandi.dao.entity.dtr.Shop;
24124 govind 47
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
48
import com.spice.profitmandi.dao.entity.fofo.InActiveFofoStore;
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
 
280
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
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
 
324
		InActiveFofoStore inActiveFofoStore = new InActiveFofoStore();
325
		inActiveFofoStore.setId(fofoStore.getId());
326
		inActiveFofoStore.setCode(fofoStore.getCode());
327
		inActiveFofoStore.setCounterSize(fofoStore.getCounterSize());
328
		inActiveFofoStore.setLatitude(fofoStore.getLatitude());
329
		inActiveFofoStore.setLongitude(fofoStore.getLongitude());
330
 
331
		inActiveFofoStore.setMinimumInvestment(fofoStore.getMinimumInvestment());
332
 
333
		inActiveFofoStore.setUserAddress(fofoStore.getUserAddress());
334
 
335
		fofoStoreRepository.saveInActiveStore(inActiveFofoStore);
336
 
337
		LOGGER.info("inserted into InActiveFofoStore successfully");
338
 
339
		fofoStoreRepository.delete(fofoStore);
340
 
341
		LOGGER.info("Deleted from fofoStore successfully");
342
 
343
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
344
 
345
		return "response";
346
 
347
	}
24680 govind 348
	@GetMapping(value="/getAllInactiveStores")
349
	public String getInactiveStores(HttpServletRequest request,Model model)
350
	{
351
		List<InActiveFofoStore> inActiveFofoStores=fofoStoreRepository.getInactiveStore();
352
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(inActiveFofoStores.stream().map(x->x.getId()).collect(Collectors.toList()));
353
		model.addAttribute("inActiveFofoStores", inActiveFofoStores);
354
		model.addAttribute("customRetailers", customRetailers);
355
		return "inactive-stores";
356
	}
24349 amit.gupta 357
 
358
	//Extend billing for 2 days
359
	@PostMapping(value = "/extendBilling")
360
	public String extendBilling(HttpServletRequest request,
361
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
362
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
363
		fofoStore.setGraceDate(LocalDate.now().plusDays(2));
364
		fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
365
		fofoStoreRepository.persist(fofoStore);
366
		model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
367
		return "response";
368
 
24124 govind 369
	}
370
 
24159 tejbeer 371
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
372
	public String getPromoterInfo(HttpServletRequest request,
373
			@RequestParam(name = "offset", defaultValue = "0") int offset,
374
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
375
		LOGGER.info("requested url : " + request.getRequestURL().toString());
376
		List<Promoter> promoterInfo = null;
377
 
378
		long size = 0;
379
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
380
				.collect(Collectors.toList());
381
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
382
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
383
		model.addAttribute("customRetailers", customRetailers);
384
		model.addAttribute("brands", inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID));
385
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
386
 
387
		size = promoterRepository.selectAllCount();
388
 
389
		LOGGER.info("promoterInfo" + promoterInfo);
390
		if (!promoterInfo.isEmpty()) {
391
			List<Integer> partnerIds = new ArrayList<>();
392
 
393
			for (Promoter promoterdetail : promoterInfo) {
394
				partnerIds.add(promoterdetail.getRetailerId());
395
			}
396
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 397
			if (!partnerIds.equals(null)) {
24159 tejbeer 398
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 399
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 400
			}
24349 amit.gupta 401
 
24159 tejbeer 402
			LOGGER.info("partnerIds" + partnersMap);
403
			model.addAttribute("promoterInfo", promoterInfo);
404
			model.addAttribute("partnersMap", partnersMap);
405
			model.addAttribute("start", offset + 1);
406
			model.addAttribute("size", size);
407
			model.addAttribute("url", "/getPaginatedPromoterInfo");
408
 
409
			if (promoterInfo.size() < limit) {
410
				model.addAttribute("end", offset + promoterInfo.size());
411
			} else {
412
				model.addAttribute("end", offset + limit);
413
			}
414
		} else {
415
			model.addAttribute("promoterInfo", promoterInfo);
416
			model.addAttribute("size", size);
417
		}
418
		return "promoter-info";
419
 
420
	}
24349 amit.gupta 421
 
24159 tejbeer 422
	@RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
423
	public String getPaginatedPromoterInfo(HttpServletRequest request,
424
			@RequestParam(name = "offset", defaultValue = "0") int offset,
425
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
426
			throws ProfitMandiBusinessException {
427
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
428
		List<Promoter> promoterInfo = null;
429
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
430
 
431
		LOGGER.info("promoterInfo" + promoterInfo);
432
		if (!promoterInfo.isEmpty()) {
433
			List<Integer> partnerIds = new ArrayList<>();
434
 
435
			for (Promoter promoterdetail : promoterInfo) {
436
				partnerIds.add(promoterdetail.getRetailerId());
437
			}
438
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 439
			if (!partnerIds.equals(null)) {
24159 tejbeer 440
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 441
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 442
			}
24349 amit.gupta 443
 
24159 tejbeer 444
			LOGGER.info("partnerIds" + partnersMap);
445
			model.addAttribute("promoterInfo", promoterInfo);
446
			model.addAttribute("partnersMap", partnersMap);
447
			model.addAttribute("url", "/getPaginatedPromoterInfo");
448
		} else {
449
			model.addAttribute("promoterInfo", promoterInfo);
450
 
451
		}
452
 
453
		return "promoter-info-paginated";
454
	}
455
 
456
	@RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
457
	public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
458
			Model model) throws Exception {
459
		LOGGER.info("requested url : " + request.getRequestURL().toString());
460
		LOGGER.info("requested url : " + promoterdetailModel);
24349 amit.gupta 461
		if (promoterdetailModel.getId() == 0) {
24159 tejbeer 462
			Promoter promoter = new Promoter();
463
			promoter.setName(promoterdetailModel.getName());
464
			promoter.setBrand(promoterdetailModel.getBrand());
465
			promoter.setEmail(promoterdetailModel.getEmail());
466
			promoter.setMobile(promoterdetailModel.getMobile());
467
			promoter.setRetailerId(promoterdetailModel.getRetailerId());
468
			promoter.setCreatedTimestamp(LocalDateTime.now());
24429 tejbeer 469
			promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
24159 tejbeer 470
			promoterRepository.persist(promoter);
471
		} else {
472
			Promoter updatePromoter = promoterRepository.selectById(promoterdetailModel.getId());
473
			updatePromoter.setRetailerId(promoterdetailModel.getRetailerId());
24429 tejbeer 474
			updatePromoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
475
			LOGGER.info("sdport"+ promoterdetailModel.isSdPortalAccess());
476
			LOGGER.info("sdport"  + updatePromoter);
24159 tejbeer 477
			promoterRepository.persist(updatePromoter);
24429 tejbeer 478
 
24159 tejbeer 479
		}
480
 
481
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
482
 
483
		return "response";
484
 
485
	}
486
 
487
	@RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
488
	public String removePromoterfromPartnerStore(HttpServletRequest request,
489
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
490
 
491
		Promoter promoter = promoterRepository.selectById(id);
492
 
493
		promoter.setRetailerId(0);
494
		promoterRepository.persist(promoter);
495
 
496
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
497
 
498
		return "response";
499
	}
500
 
501
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
502
	public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
503
			throws Exception {
504
 
505
		Location location = new Location();
506
		location.setName(addLocationModel.getName());
507
		location.setLine1(addLocationModel.getLine1());
508
		location.setLine2(addLocationModel.getLine2());
509
		location.setCity(addLocationModel.getCity());
510
		location.setState(addLocationModel.getState());
511
		location.setPin(addLocationModel.getPin());
512
 
513
		LOGGER.info("PostLocation" + location);
514
		locationRepository.persist(location);
515
 
516
		User user = userRepository.selectById(addLocationModel.getUserId());
517
		user.setLocation(location.getId());
518
		userRepository.persist(user);
519
 
520
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
521
		return "response";
522
 
523
	}
524
 
525
	@RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
526
	public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
527
			Model model) throws Exception {
528
 
529
		Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
530
 
531
		userlocation.setName(addLocationModel.getName());
532
		userlocation.setCity(addLocationModel.getCity());
533
		userlocation.setLine1(addLocationModel.getLine1());
534
		userlocation.setLine2(addLocationModel.getLine2());
535
		userlocation.setPin(addLocationModel.getPin());
536
		userlocation.setState(addLocationModel.getState());
537
 
538
		locationRepository.persist(userlocation);
539
 
540
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
541
		return "response";
542
 
543
	}
544
 
24124 govind 545
}