Subversion Repositories SmartDukaan

Rev

Rev 24349 | Rev 24680 | 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
	}
24349 amit.gupta 348
 
349
	//Extend billing for 2 days
350
	@PostMapping(value = "/extendBilling")
351
	public String extendBilling(HttpServletRequest request,
352
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
353
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
354
		fofoStore.setGraceDate(LocalDate.now().plusDays(2));
355
		fofoStore.setGraceCount(fofoStore.getGraceCount() + 1);
356
		fofoStoreRepository.persist(fofoStore);
357
		model.addAttribute("response", mvcResponseSender.createResponseString(fofoStore.getGraceCount()));
358
		return "response";
359
 
24124 govind 360
	}
361
 
24159 tejbeer 362
	@RequestMapping(value = "/getPromoterInfo", method = RequestMethod.GET)
363
	public String getPromoterInfo(HttpServletRequest request,
364
			@RequestParam(name = "offset", defaultValue = "0") int offset,
365
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
366
		LOGGER.info("requested url : " + request.getRequestURL().toString());
367
		List<Promoter> promoterInfo = null;
368
 
369
		long size = 0;
370
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
371
				.collect(Collectors.toList());
372
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
373
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
374
		model.addAttribute("customRetailers", customRetailers);
375
		model.addAttribute("brands", inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID));
376
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
377
 
378
		size = promoterRepository.selectAllCount();
379
 
380
		LOGGER.info("promoterInfo" + promoterInfo);
381
		if (!promoterInfo.isEmpty()) {
382
			List<Integer> partnerIds = new ArrayList<>();
383
 
384
			for (Promoter promoterdetail : promoterInfo) {
385
				partnerIds.add(promoterdetail.getRetailerId());
386
			}
387
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 388
			if (!partnerIds.equals(null)) {
24159 tejbeer 389
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 390
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 391
			}
24349 amit.gupta 392
 
24159 tejbeer 393
			LOGGER.info("partnerIds" + partnersMap);
394
			model.addAttribute("promoterInfo", promoterInfo);
395
			model.addAttribute("partnersMap", partnersMap);
396
			model.addAttribute("start", offset + 1);
397
			model.addAttribute("size", size);
398
			model.addAttribute("url", "/getPaginatedPromoterInfo");
399
 
400
			if (promoterInfo.size() < limit) {
401
				model.addAttribute("end", offset + promoterInfo.size());
402
			} else {
403
				model.addAttribute("end", offset + limit);
404
			}
405
		} else {
406
			model.addAttribute("promoterInfo", promoterInfo);
407
			model.addAttribute("size", size);
408
		}
409
		return "promoter-info";
410
 
411
	}
24349 amit.gupta 412
 
24159 tejbeer 413
	@RequestMapping(value = "/getPaginatedPromoterInfo", method = RequestMethod.GET)
414
	public String getPaginatedPromoterInfo(HttpServletRequest request,
415
			@RequestParam(name = "offset", defaultValue = "0") int offset,
416
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
417
			throws ProfitMandiBusinessException {
418
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
419
		List<Promoter> promoterInfo = null;
420
		promoterInfo = promoterRepository.selectAllPromoter(offset, limit);
421
 
422
		LOGGER.info("promoterInfo" + promoterInfo);
423
		if (!promoterInfo.isEmpty()) {
424
			List<Integer> partnerIds = new ArrayList<>();
425
 
426
			for (Promoter promoterdetail : promoterInfo) {
427
				partnerIds.add(promoterdetail.getRetailerId());
428
			}
429
			Map<Integer, CustomRetailer> partnersMap = null;
24349 amit.gupta 430
			if (!partnerIds.equals(null)) {
24159 tejbeer 431
				LOGGER.info("partnerIds" + partnerIds);
24349 amit.gupta 432
				partnersMap = retailerService.getFofoRetailers(partnerIds);
24159 tejbeer 433
			}
24349 amit.gupta 434
 
24159 tejbeer 435
			LOGGER.info("partnerIds" + partnersMap);
436
			model.addAttribute("promoterInfo", promoterInfo);
437
			model.addAttribute("partnersMap", partnersMap);
438
			model.addAttribute("url", "/getPaginatedPromoterInfo");
439
		} else {
440
			model.addAttribute("promoterInfo", promoterInfo);
441
 
442
		}
443
 
444
		return "promoter-info-paginated";
445
	}
446
 
447
	@RequestMapping(value = "/createPromoter", method = RequestMethod.POST)
448
	public String createPromoter(HttpServletRequest request, @RequestBody PromoterDetailModel promoterdetailModel,
449
			Model model) throws Exception {
450
		LOGGER.info("requested url : " + request.getRequestURL().toString());
451
		LOGGER.info("requested url : " + promoterdetailModel);
24349 amit.gupta 452
		if (promoterdetailModel.getId() == 0) {
24159 tejbeer 453
			Promoter promoter = new Promoter();
454
			promoter.setName(promoterdetailModel.getName());
455
			promoter.setBrand(promoterdetailModel.getBrand());
456
			promoter.setEmail(promoterdetailModel.getEmail());
457
			promoter.setMobile(promoterdetailModel.getMobile());
458
			promoter.setRetailerId(promoterdetailModel.getRetailerId());
459
			promoter.setCreatedTimestamp(LocalDateTime.now());
24429 tejbeer 460
			promoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
24159 tejbeer 461
			promoterRepository.persist(promoter);
462
		} else {
463
			Promoter updatePromoter = promoterRepository.selectById(promoterdetailModel.getId());
464
			updatePromoter.setRetailerId(promoterdetailModel.getRetailerId());
24429 tejbeer 465
			updatePromoter.setSdPortalAccess(promoterdetailModel.isSdPortalAccess());
466
			LOGGER.info("sdport"+ promoterdetailModel.isSdPortalAccess());
467
			LOGGER.info("sdport"  + updatePromoter);
24159 tejbeer 468
			promoterRepository.persist(updatePromoter);
24429 tejbeer 469
 
24159 tejbeer 470
		}
471
 
472
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
473
 
474
		return "response";
475
 
476
	}
477
 
478
	@RequestMapping(value = "/removePromoterfromPartnerStore", method = RequestMethod.POST)
479
	public String removePromoterfromPartnerStore(HttpServletRequest request,
480
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
481
 
482
		Promoter promoter = promoterRepository.selectById(id);
483
 
484
		promoter.setRetailerId(0);
485
		promoterRepository.persist(promoter);
486
 
487
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
488
 
489
		return "response";
490
	}
491
 
492
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
493
	public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
494
			throws Exception {
495
 
496
		Location location = new Location();
497
		location.setName(addLocationModel.getName());
498
		location.setLine1(addLocationModel.getLine1());
499
		location.setLine2(addLocationModel.getLine2());
500
		location.setCity(addLocationModel.getCity());
501
		location.setState(addLocationModel.getState());
502
		location.setPin(addLocationModel.getPin());
503
 
504
		LOGGER.info("PostLocation" + location);
505
		locationRepository.persist(location);
506
 
507
		User user = userRepository.selectById(addLocationModel.getUserId());
508
		user.setLocation(location.getId());
509
		userRepository.persist(user);
510
 
511
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
512
		return "response";
513
 
514
	}
515
 
516
	@RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
517
	public String updateLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel,
518
			Model model) throws Exception {
519
 
520
		Location userlocation = locationRepository.selectById(addLocationModel.getUserId());
521
 
522
		userlocation.setName(addLocationModel.getName());
523
		userlocation.setCity(addLocationModel.getCity());
524
		userlocation.setLine1(addLocationModel.getLine1());
525
		userlocation.setLine2(addLocationModel.getLine2());
526
		userlocation.setPin(addLocationModel.getPin());
527
		userlocation.setState(addLocationModel.getState());
528
 
529
		locationRepository.persist(userlocation);
530
 
531
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
532
		return "response";
533
 
534
	}
535
 
24124 govind 536
}