Subversion Repositories SmartDukaan

Rev

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

Rev 23365 Rev 23378
Line 13... Line 13...
13
import org.slf4j.LoggerFactory;
13
import org.slf4j.LoggerFactory;
14
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Qualifier;
15
import org.springframework.beans.factory.annotation.Qualifier;
16
import org.springframework.stereotype.Component;
16
import org.springframework.stereotype.Component;
17
 
17
 
-
 
18
import com.spice.profitmandi.common.ResponseCodeHolder;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.CustomAddress;
20
import com.spice.profitmandi.common.model.CustomAddress;
20
import com.spice.profitmandi.common.model.CustomShop;
21
import com.spice.profitmandi.common.model.CustomShop;
21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
23
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
Line 259... Line 260...
259
		
260
		
260
		userRoles = this.addRole(userRoles, user.getId(), RoleType.RETAILER);
261
		userRoles = this.addRole(userRoles, user.getId(), RoleType.RETAILER);
261
		
262
		
262
		if(updateRetailerRequest.isFofo()){
263
		if(updateRetailerRequest.isFofo()){
263
			userRoles = this.addRole(userRoles, user.getId(), RoleType.FOFO);
264
			userRoles = this.addRole(userRoles, user.getId(), RoleType.FOFO);
-
 
265
			map.put("fofoRole", this.containsRoleType(userRoles, RoleType.FOFO));
264
		}
266
		}
265
		
267
		
266
		if(this.containsRoleType(userRoles, RoleType.FOFO)){
268
		if(this.containsRoleType(userRoles, RoleType.FOFO)){
267
			this.createDefaultPaymentOption(retailer.getId());
269
			this.createDefaultPaymentOption(retailer.getId());
268
		}
270
		}
Line 273... Line 275...
273
		Address retailerAddress = (Address)map.get("retailerAddress");
275
		Address retailerAddress = (Address)map.get("retailerAddress");
274
		retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
276
		retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
275
		map.put("retailerAddress", retailerAddress);
277
		map.put("retailerAddress", retailerAddress);
276
		
278
		
277
		if(updateRetailerRequest.isFofo()){
279
		if(updateRetailerRequest.isFofo()){
278
			this.createFofoStoreCodeByUserId(user.getId(), updateRetailerRequest.getDistrictName(), retailerAddress.getState());
280
			FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(), updateRetailerRequest.getDistrictName(), retailerAddress.getState());
-
 
281
			map.put("fofoStore", fofoStore);
279
		}
282
		}
280
		
283
		
281
		this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
284
		this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer, retailerAddress.getId());
282
		map.put("gstNumber", updateRetailerRequest.getGstNumber());
285
		map.put("gstNumber", updateRetailerRequest.getGstNumber());
283
		this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
286
		this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
Line 641... Line 644...
641
		};
644
		};
642
		Set<String> userRoleStrings = userRoles.stream().map(userRoleToRoleNameFunction).collect(Collectors.toSet());
645
		Set<String> userRoleStrings = userRoles.stream().map(userRoleToRoleNameFunction).collect(Collectors.toSet());
643
		return String.join(", ", userRoleStrings);
646
		return String.join(", ", userRoleStrings);
644
	}
647
	}
645
	
648
	
646
	@Override
-
 
647
	public void createFofoStoreCodeByUserId(int userId, String districtName, String stateName) throws ProfitMandiBusinessException {
649
	private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName) throws ProfitMandiBusinessException{
648
		User user = userRepository.selectById(userId);
-
 
649
		// = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
650
		UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
651
		Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
-
 
652
		try{
-
 
653
			userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
-
 
654
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
655
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
-
 
656
		}
-
 
657
		
-
 
658
		boolean foundFofoStore = false;
650
		FofoStore fofoStore = null;
659
		try{
651
		try{
660
			fofoStoreRepository.selectByRetailerId(retailer.getId());
652
			fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
661
			foundFofoStore = true;
-
 
662
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
653
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
663
			
654
			
664
		}
655
		}
665
		
656
		
666
		if(foundFofoStore){
657
		if(fofoStore != null){
-
 
658
			LOGGER.error(ResponseCodeHolder.getMessage("USR_1014"));
667
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
659
			//throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
668
		}			
660
		}else {
669
		
-
 
670
		int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
661
			int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
671
		Address retailerAddress = addressRepository.selectById(retailerAddressId);
662
			Address retailerAddress = addressRepository.selectById(retailerAddressId);
672
		
663
			
673
		StateInfo stateInfo = null;
664
			StateInfo stateInfo = null;
674
		try {
665
			try {
675
			stateInfo = Utils.getStateInfo(retailerAddress.getState());
666
				stateInfo = Utils.getStateInfo(retailerAddress.getState());
676
		} catch (Exception e) {
667
			} catch (Exception e) {
677
			// TODO Auto-generated catch block
668
				// TODO Auto-generated catch block
678
			e.printStackTrace();
669
				e.printStackTrace();
679
			//throw new ProfitMandiBusinessException();
670
				//throw new ProfitMandiBusinessException();
-
 
671
			}
-
 
672
			DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
-
 
673
			
-
 
674
			FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
-
 
675
			boolean foundFofoStoreSequence = false;
-
 
676
			try{
-
 
677
				fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
-
 
678
				foundFofoStoreSequence = true;
-
 
679
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
680
				fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
-
 
681
				fofoStoreSequenceGeneration.setSequence(1);
-
 
682
				fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
-
 
683
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
684
			}
-
 
685
			
-
 
686
			fofoStore = new FofoStore();
-
 
687
			fofoStore.setId(retailerId);
-
 
688
			String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
689
			if(foundFofoStoreSequence){
-
 
690
				fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
691
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
692
			}
-
 
693
			fofoStore.setCode(fofoStoreCode);
-
 
694
			fofoStoreRepository.persist(fofoStore);
680
		}
695
		}
681
		DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
-
 
682
		
696
		
-
 
697
		return fofoStore;
-
 
698
	}
-
 
699
	
-
 
700
	@Override
-
 
701
	public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName) throws ProfitMandiBusinessException {
683
		FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
702
		User user = userRepository.selectById(userId);
684
		boolean foundFofoStoreSequence = false;
703
		// = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
704
		UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
705
		Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
685
		try{
706
		try{
686
			fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
707
			userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
687
			foundFofoStoreSequence = true;
-
 
688
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
708
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
689
			fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
-
 
690
			fofoStoreSequenceGeneration.setSequence(1);
-
 
691
			fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
-
 
692
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
709
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
693
		}
710
		}
-
 
711
		return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName);
694
		
712
		
695
		FofoStore fofoStore = new FofoStore();
-
 
696
		fofoStore.setId(retailer.getId());
-
 
697
		String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
698
		if(foundFofoStoreSequence){
-
 
699
			fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
700
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
701
		}
-
 
702
		fofoStore.setCode(fofoStoreCode);
-
 
703
		fofoStoreRepository.persist(fofoStore);
-
 
704
	}
713
	}
705
	
714
	
706
	@Override
715
	@Override
707
	public List<DistrictMaster> getAllDistrictMaster(String stateName) {
716
	public List<DistrictMaster> getAllDistrictMaster(String stateName) {
708
		StateInfo stateInfo = null;
717
		StateInfo stateInfo = null;