Subversion Repositories SmartDukaan

Rev

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