Subversion Repositories SmartDukaan

Rev

Rev 22503 | Rev 22553 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22503 Rev 22524
Line 369... Line 369...
369
				retailerBrand.setBrandId(brand.getId());
369
				retailerBrand.setBrandId(brand.getId());
370
				retailerBrandRepository.persist(retailerBrand);
370
				retailerBrandRepository.persist(retailerBrand);
371
			}
371
			}
372
		}
372
		}
373
	}
373
	}
-
 
374
	
-
 
375
	@ApiOperation(value = "Create Fofo Store")
-
 
376
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_FOFO_FOFO_STORE, method=RequestMethod.POST)
-
 
377
	public ResponseEntity<?> createFofoStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DISTRICT_NAME) String districtName) throws ProfitMandiBusinessException, Exception{
-
 
378
		try{
-
 
379
			UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
-
 
380
			LOGGER.info("requestAttribute [userInfo={}]", userInfo);
-
 
381
			User user = userRepository.selectById(userInfo.getUserId());
-
 
382
			// = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
383
			UserAccounts userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
384
			Retailer retailer = retailerRepository.selectById(Integer.parseInt(userAccounts.getAccount_key()));
-
 
385
			if(!retailer.isFofo()){
-
 
386
				throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
-
 
387
			}
-
 
388
			boolean foundFofoStore = false;
-
 
389
			try{
-
 
390
				fofoStoreRepository.selectByRetailerId(retailer.getId());
-
 
391
				foundFofoStore = true;
-
 
392
			}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
393
				
-
 
394
			}
-
 
395
			
-
 
396
			if(foundFofoStore){
-
 
397
				throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
-
 
398
			}			
-
 
399
			
-
 
400
			int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
-
 
401
			Address retailerAddress = addressRepository.selectById(retailerAddressId);
-
 
402
			
-
 
403
			StateInfo stateInfo = Utils.getStateInfo(retailerAddress.getState());
-
 
404
			DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
-
 
405
			FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
-
 
406
			boolean foundFofoStoreSequence = false;
-
 
407
			try{
-
 
408
				fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
-
 
409
				foundFofoStoreSequence = true;
-
 
410
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
411
				fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
-
 
412
				fofoStoreSequenceGeneration.setSequence(1);
-
 
413
				fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
-
 
414
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
415
			}
-
 
416
			
-
 
417
			FofoStore fofoStore = new FofoStore();
-
 
418
			fofoStore.setId(retailer.getId());
-
 
419
			String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
420
			if(foundFofoStoreSequence){
-
 
421
				fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
422
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
423
			}
-
 
424
			fofoStore.setCode(fofoStoreCode);
-
 
425
			fofoStoreRepository.persist(fofoStore);
-
 
426
			
-
 
427
			return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1003"));
-
 
428
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
429
			LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
-
 
430
			throw profitMandiBusinessException;
-
 
431
			//return responseSender.badRequest(profitMandiBusinessException);
-
 
432
		}
-
 
433
	}
-
 
434
	
374
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
435
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
375
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
436
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
376
		LOGGER.info("requested url : "+request.getRequestURL().toString());
437
		LOGGER.info("requested url : "+request.getRequestURL().toString());
377
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
438
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
378
	}
439
	}