Subversion Repositories SmartDukaan

Rev

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