Subversion Repositories SmartDukaan

Rev

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

Rev 24705 Rev 25295
Line 112... Line 112...
112
	@Autowired
112
	@Autowired
113
	private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
113
	private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
114
 
114
 
115
	@Autowired
115
	@Autowired
116
	private CounterRepository counterRepository;
116
	private CounterRepository counterRepository;
117
	
117
 
118
	@Autowired
118
	@Autowired
119
	private StateRepository stateRepository;
119
	private StateRepository stateRepository;
120
 
120
 
121
	@Autowired
121
	@Autowired
122
	@Qualifier("userUserRepository")
122
	@Qualifier("userUserRepository")
Line 152... Line 152...
152
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
152
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
153
 
153
 
154
			}
154
			}
155
		}
155
		}
156
		Map<String, Object> map = new HashMap<>();
156
		Map<String, Object> map = new HashMap<>();
157
		map.put("stateNames", stateRepository.selectAll().stream().map(x->x.getName()).collect(Collectors.toList()));
157
		map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
158
 
158
 
159
		if (user != null) {
159
		if (user != null) {
160
 
160
 
161
			List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
161
			List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
162
 
162
 
Line 247... Line 247...
247
		}
247
		}
248
		return userRoles;
248
		return userRoles;
249
 
249
 
250
	}
250
	}
251
 
251
 
-
 
252
	private List<UserRole> removeRole(List<UserRole> userRoles, int userId, int roleId) {
-
 
253
		if (userRoles == null) {
-
 
254
			userRoles = new ArrayList<>();
-
 
255
			return userRoles;
-
 
256
		}
-
 
257
		try {
-
 
258
			userRoles.remove(userRoleRepository.deleteByRoleUserId(userId, roleId));
-
 
259
		} catch (Exception e) {
-
 
260
 
-
 
261
		}
-
 
262
		return userRoles;
-
 
263
 
-
 
264
	}
-
 
265
 
252
	@SuppressWarnings("unchecked")
266
	@SuppressWarnings("unchecked")
253
	@Override
267
	@Override
254
	public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
268
	public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
255
			throws ProfitMandiBusinessException {
269
			throws ProfitMandiBusinessException {
256
		Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
270
		Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
Line 271... Line 285...
271
		Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
285
		Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
272
 
286
 
273
		if (updateRetailerRequest.isFofo()) {
287
		if (updateRetailerRequest.isFofo()) {
274
 
288
 
275
			userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
289
			userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
-
 
290
		} else {
276
			map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
291
			userRoles = this.removeRole(userRoles, user.getId(), roleFofo.getId());
277
		}
292
		}
-
 
293
		map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
278
 
294
 
279
		if (this.containsRoleType(userRoles, roleFofo.getId())) {
295
		if (this.containsRoleType(userRoles, roleFofo.getId())) {
280
			this.createDefaultPaymentOption(retailer.getId());
296
			this.createDefaultPaymentOption(retailer.getId());
281
		}
297
		}
282
 
298
 
Line 409... Line 425...
409
		}
425
		}
410
		if (updateRetailerRequest.getDocumentId() > 0) {
426
		if (updateRetailerRequest.getDocumentId() > 0) {
411
			if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
427
			if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
412
				try {
428
				try {
413
					documentRepository.deleteById(retailer.getDocumentId());
429
					documentRepository.deleteById(retailer.getDocumentId());
414
				} catch(Exception e) {
430
				} catch (Exception e) {
415
					e.printStackTrace();
431
					e.printStackTrace();
416
				}
432
				}
417
			}
433
			}
418
			retailer.setDocumentId(updateRetailerRequest.getDocumentId());
434
			retailer.setDocumentId(updateRetailerRequest.getDocumentId());
419
			documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
435
			documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
Line 574... Line 590...
574
		shop.setName(customShop.getName());
590
		shop.setName(customShop.getName());
575
		if (customShop.getDocumentId() > 0) {
591
		if (customShop.getDocumentId() > 0) {
576
			if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
592
			if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
577
				try {
593
				try {
578
					documentRepository.deleteById(shop.getDocumentId());
594
					documentRepository.deleteById(shop.getDocumentId());
579
				} catch(Exception e) {
595
				} catch (Exception e) {
580
					e.printStackTrace();
596
					e.printStackTrace();
581
				}
597
				}
582
			}
598
			}
583
			shop.setDocumentId(customShop.getDocumentId());
599
			shop.setDocumentId(customShop.getDocumentId());
584
			documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
600
			documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
Line 622... Line 638...
622
					shopAddress.setAddressId(address.getId());
638
					shopAddress.setAddressId(address.getId());
623
					shopAddressRepository.persist(shopAddress);
639
					shopAddressRepository.persist(shopAddress);
624
					shop.setAddress(address);
640
					shop.setAddress(address);
625
					shopRepository.persist(shop);
641
					shopRepository.persist(shop);
626
				}
642
				}
627
			} catch(Exception e) {
643
			} catch (Exception e) {
628
				if (customShop.isSameAsRetailerAddress()) {
644
				if (customShop.isSameAsRetailerAddress()) {
629
					address = sameAsRetailerAddressValue;
645
					address = sameAsRetailerAddressValue;
630
				} else {
646
				} else {
631
					// shop.setDocumentId(customShop.getDocumentId());
647
					// shop.setDocumentId(customShop.getDocumentId());
632
					address = new Address();
648
					address = new Address();
Line 642... Line 658...
642
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
658
				} catch (ProfitMandiBusinessException profitMandiBusinessException) {
643
					shopAddress = new ShopAddress();
659
					shopAddress = new ShopAddress();
644
					shopAddress.setAddressId(address.getId());
660
					shopAddress.setAddressId(address.getId());
645
					shopAddress.setShopId(shop.getId());
661
					shopAddress.setShopId(shop.getId());
646
				}
662
				}
647
				shopAddressRepository.persist(shopAddress);			}
663
				shopAddressRepository.persist(shopAddress);
-
 
664
			}
648
 
665
 
649
		}
666
		}
650
 
667
 
651
	}
668
	}
652
 
669
 
Line 766... Line 783...
766
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
783
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
767
		}
784
		}
768
		return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
785
		return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
769
 
786
 
770
	}
787
	}
771
	
-
 
772
 
788
 
773
	@Override
789
	@Override
774
	public List<DistrictMaster> getAllDistrictMaster(String stateName) {
790
	public List<DistrictMaster> getAllDistrictMaster(String stateName) {
775
		StateInfo stateInfo = null;
791
		StateInfo stateInfo = null;
776
		try {
792
		try {
Line 783... Line 799...
783
	}
799
	}
784
 
800
 
785
	@Override
801
	@Override
786
	public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
802
	public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
787
		List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
803
		List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
788
		Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream().filter(x->x.getAddressId()!=null).collect(Collectors.toMap(x->x.getAddressId(), x->x));
804
		Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
-
 
805
				.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
789
		List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
806
		List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
790
		Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
807
		Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
791
		for(Address address: addresses) {
808
		for (Address address : addresses) {
792
			com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
809
			com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
793
			CustomRetailer customRetailer = new CustomRetailer();
810
			CustomRetailer customRetailer = new CustomRetailer();
794
			customRetailer.setEmail(user.getEmailId());
811
			customRetailer.setEmail(user.getEmailId());
795
			customRetailer.setBusinessName(address.getName());
812
			customRetailer.setBusinessName(address.getName());
796
			customRetailer.setMobileNumber(address.getPhoneNumber());
813
			customRetailer.setMobileNumber(address.getPhoneNumber());
Line 814... Line 831...
814
			customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
831
			customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
815
			customRetailersMap.put(address.getRetaierId(), customRetailer);
832
			customRetailersMap.put(address.getRetaierId(), customRetailer);
816
		}
833
		}
817
		return customRetailersMap;
834
		return customRetailersMap;
818
	}
835
	}
819
	
836
 
820
	@Override
837
	@Override
821
	public  CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
838
	public CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
822
		com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
839
		com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
823
		Address address = null;
840
		Address address = null;
824
		try {
841
		try {
825
			address = addressRepository.selectById(saholicUser.getAddressId());
842
			address = addressRepository.selectById(saholicUser.getAddressId());
826
		} catch (ProfitMandiBusinessException e1) {
843
		} catch (ProfitMandiBusinessException e1) {
827
			// TODO Auto-generated catch block
844
			// TODO Auto-generated catch block
828
			e1.printStackTrace();
845
			e1.printStackTrace();
829
		}
846
		}
830
		Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
847
		Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
831
			CustomRetailer customRetailer = new CustomRetailer();
848
		CustomRetailer customRetailer = new CustomRetailer();
832
			customRetailer.setEmail(saholicUser.getEmailId());
849
		customRetailer.setEmail(saholicUser.getEmailId());
833
			customRetailer.setBusinessName(address.getName());
850
		customRetailer.setBusinessName(address.getName());
834
			customRetailer.setMobileNumber(address.getPhoneNumber());
851
		customRetailer.setMobileNumber(address.getPhoneNumber());
835
			try {
852
		try {
836
				customRetailer.setCartId(saholicUser.getActiveCartId());
853
			customRetailer.setCartId(saholicUser.getActiveCartId());
837
				PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
854
			PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
838
				Counter counter = counterRepository.selectById(pdu.getCounterId());
855
			Counter counter = counterRepository.selectById(pdu.getCounterId());
839
				customRetailer.setGstNumber(counter.getGstin());
856
			customRetailer.setGstNumber(counter.getGstin());
840
			} catch(Exception e) {
857
		} catch (Exception e) {
841
				customRetailer.setGstNumber(null);
858
			customRetailer.setGstNumber(null);
842
			}
859
		}
843
			CustomAddress address1 = new CustomAddress();
860
		CustomAddress address1 = new CustomAddress();
844
			address1.setCity(address.getCity());
861
		address1.setCity(address.getCity());
845
			address1.setState(address.getState());
862
		address1.setState(address.getState());
846
			address1.setLine1(address.getLine1());
863
		address1.setLine1(address.getLine1());
847
			address1.setLine2(address.getLine2());
864
		address1.setLine2(address.getLine2());
848
			address1.setPinCode(address.getPinCode());
865
		address1.setPinCode(address.getPinCode());
849
			address1.setName(address.getName());
866
		address1.setName(address.getName());
850
			customRetailer.setAddress(address1);
867
		customRetailer.setAddress(address1);
851
			customRetailer.setPartnerId(address.getRetaierId());
868
		customRetailer.setPartnerId(address.getRetaierId());
852
			customRetailersMap.put(address.getRetaierId(), customRetailer);
869
		customRetailersMap.put(address.getRetaierId(), customRetailer);
853
		return customRetailer;
870
		return customRetailer;
854
		
871
 
855
	}
872
	}
856
	
873
 
857
	@Override
874
	@Override
858
	public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
875
	public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
859
		Role roleFofo = null;
876
		Role roleFofo = null;
860
		try {
877
		try {
861
			roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
878
			roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
Line 889... Line 906...
889
		for (UserAccount userAccount : userAccounts) {
906
		for (UserAccount userAccount : userAccounts) {
890
			userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
907
			userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
891
		}
908
		}
892
		return userIdRetailerIdMap;
909
		return userIdRetailerIdMap;
893
	}
910
	}
894
	
911
 
895
	private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds){
912
	private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
896
		List<User> users = userRepository.selectAllByIds(userIds);
913
		List<User> users = userRepository.selectAllByIds(userIds);
897
		Map<Integer, String> userIdEmailIdMap = new HashMap<>();
914
		Map<Integer, String> userIdEmailIdMap = new HashMap<>();
898
		for (User user : users) {
915
		for (User user : users) {
899
			userIdEmailIdMap.put(user.getId(), user.getEmailId());
916
			userIdEmailIdMap.put(user.getId(), user.getEmailId());
900
		}
917
		}
Line 913... Line 930...
913
		for (UserAccount userAccount : userAccounts) {
930
		for (UserAccount userAccount : userAccounts) {
914
			retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
931
			retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
915
		}
932
		}
916
		return retailerIdEmailIdMap;
933
		return retailerIdEmailIdMap;
917
	}
934
	}
-
 
935
 
918
	@Override
936
	@Override
919
	public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
937
	public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
920
		Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
938
		Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
921
		Map<Integer, String> retailerIdNameMap = new HashMap<>();
939
		Map<Integer, String> retailerIdNameMap = new HashMap<>();
922
		for (Map.Entry<Integer, CustomRetailer> entry: retailersMap.entrySet()) {
940
		for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
-
 
941
			retailerIdNameMap.put(entry.getKey(),
923
			retailerIdNameMap.put(entry.getKey(), entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
942
					entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
924
		}
943
		}
925
		return retailerIdNameMap;
944
		return retailerIdNameMap;
926
	}
945
	}
927
 
946
 
928
	@Override
947
	@Override
929
	public Map<Integer, String> getAllFofoRetailerIdNameMap() {
948
	public Map<Integer, String> getAllFofoRetailerIdNameMap() {
930
		List<FofoStore> stores = fofoStoreRepository.selectAll();
949
		List<FofoStore> stores = fofoStoreRepository.selectAll();
931
		List<Integer> storeIds = stores.stream().map(x->x.getId()).collect(Collectors.toList());
950
		List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
932
		return this.getAllFofoRetailerIdNameMap(storeIds);
951
		return this.getAllFofoRetailerIdNameMap(storeIds);
933
	}
952
	}
934
 
953
 
935
	@Override
954
	@Override
936
	public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
955
	public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
937
		List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
956
		List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
938
		// TODO Auto-generated method stub
957
		// TODO Auto-generated method stub
939
		Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
958
		Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
940
		fofoIdNameMap .forEach((fofoId,name)->{
959
		fofoIdNameMap.forEach((fofoId, name) -> {
941
			MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
960
			MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
942
			idWrapper.setKey(fofoId);
961
			idWrapper.setKey(fofoId);
943
			idWrapper.setValue(name);
962
			idWrapper.setValue(name);
944
			mapWrappers.add(idWrapper);
963
			mapWrappers.add(idWrapper);
945
		});
964
		});
946
		return mapWrappers;
965
		return mapWrappers;
947
	}
966
	}
948
 
967
 
949
	
-
 
950
	@Override
968
	@Override
951
	@Cacheable(value="retailerNames", cacheManager="cacheManager")
969
	@Cacheable(value = "retailerNames", cacheManager = "cacheManager")
952
	public Map<Integer, CustomRetailer> getFofoRetailers() {
970
	public Map<Integer, CustomRetailer> getFofoRetailers() {
953
		// TODO Auto-generated method stub
971
		// TODO Auto-generated method stub
954
		List<FofoStore> stores = fofoStoreRepository.selectAll();
972
		List<FofoStore> stores = fofoStoreRepository.selectAll();
955
		List<Integer> storeIds = stores.stream().map(x->x.getId()).collect(Collectors.toList());
973
		List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
956
		return this.getFofoRetailers(storeIds);
974
		return this.getFofoRetailers(storeIds);
957
	}
975
	}
958
	
976
 
959
}
977
}