Subversion Repositories SmartDukaan

Rev

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

Rev 33140 Rev 33247
Line 743... Line 743...
743
 
743
 
744
        }
744
        }
745
 
745
 
746
    }
746
    }
747
 
747
 
748
    private void addAddress(List<Shop> shops) {
748
    private void addAddress(List<Shop> shops) throws ProfitMandiBusinessException {
749
        Set<Integer> shopIds = this.toShopIds(shops);
749
        Set<Integer> shopIds = this.toShopIds(shops);
750
        if (shopIds.isEmpty()) {
750
        if (shopIds.isEmpty()) {
751
            return;
751
            return;
752
        }
752
        }
753
        List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
753
        List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
Line 756... Line 756...
756
        for (Shop shop : shops) {
756
        for (Shop shop : shops) {
757
            shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
757
            shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
758
        }
758
        }
759
    }
759
    }
760
 
760
 
761
    private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) {
761
    private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) throws ProfitMandiBusinessException {
762
        Map<Integer, Address> addressIdAddressMap = new HashMap<>();
762
        Map<Integer, Address> addressIdAddressMap = new HashMap<>();
763
        List<Integer> addressIds = this.toAddressIds(shopAddresses);
763
        List<Integer> addressIds = this.toAddressIds(shopAddresses);
764
        List<Address> addresses = addressRepository.selectByIds(addressIds);
764
        List<Address> addresses = addressRepository.selectByIds(addressIds);
765
        for (Address address : addresses) {
765
        for (Address address : addresses) {
766
            addressIdAddressMap.put(address.getId(), address);
766
            addressIdAddressMap.put(address.getId(), address);
Line 786... Line 786...
786
            }
786
            }
787
        };
787
        };
788
        return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
788
        return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
789
    }
789
    }
790
 
790
 
791
    private String toString(List<UserRole> userRoles) {
791
    private String toString(List<UserRole> userRoles) throws ProfitMandiBusinessException {
792
        Set<Integer> roleIds = new HashSet<>();
792
        Set<Integer> roleIds = new HashSet<>();
793
        for (UserRole userRole : userRoles) {
793
        for (UserRole userRole : userRoles) {
794
            roleIds.add(userRole.getRoleId());
794
            roleIds.add(userRole.getRoleId());
795
        }
795
        }
796
        List<Role> roles = roleRepository.selectByIds(roleIds);
796
        List<Role> roles = roleRepository.selectByIds(roleIds);
Line 913... Line 913...
913
        }
913
        }
914
        return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
914
        return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
915
    }
915
    }
916
 
916
 
917
    @Override
917
    @Override
918
    public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
918
    public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) throws ProfitMandiBusinessException {
919
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
919
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
920
        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));
920
        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));
921
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
921
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
922
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
922
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
923
        for (Address address : addresses) {
923
        for (Address address : addresses) {
Line 1011... Line 1011...
1011
        return customRetailer;
1011
        return customRetailer;
1012
 
1012
 
1013
    }
1013
    }
1014
 
1014
 
1015
    @Override
1015
    @Override
1016
    public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) {
1016
    public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) throws ProfitMandiBusinessException {
1017
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
1017
        List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
1018
        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));
1018
        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));
1019
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
1019
        List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
1020
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1020
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1021
        for (Address address : addresses) {
1021
        for (Address address : addresses) {
Line 1052... Line 1052...
1052
        }
1052
        }
1053
        return customRetailersMap;
1053
        return customRetailersMap;
1054
    }
1054
    }
1055
 
1055
 
1056
    @Override
1056
    @Override
1057
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
1057
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() throws ProfitMandiBusinessException {
1058
        Role roleFofo = null;
1058
        Role roleFofo = null;
1059
        try {
1059
        try {
1060
            roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
1060
            roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
1061
        } catch (ProfitMandiBusinessException e) {
1061
        } catch (ProfitMandiBusinessException e) {
1062
            // TODO Auto-generated catch block
1062
            // TODO Auto-generated catch block
Line 1089... Line 1089...
1089
            userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
1089
            userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
1090
        }
1090
        }
1091
        return userIdRetailerIdMap;
1091
        return userIdRetailerIdMap;
1092
    }
1092
    }
1093
 
1093
 
1094
    private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
1094
    private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) throws ProfitMandiBusinessException {
1095
        List<User> users = userRepository.selectAllByIds(userIds);
1095
        List<User> users = userRepository.selectAllByIds(userIds);
1096
        Map<Integer, String> userIdEmailIdMap = new HashMap<>();
1096
        Map<Integer, String> userIdEmailIdMap = new HashMap<>();
1097
        for (User user : users) {
1097
        for (User user : users) {
1098
            userIdEmailIdMap.put(user.getId(), user.getEmailId());
1098
            userIdEmailIdMap.put(user.getId(), user.getEmailId());
1099
        }
1099
        }
1100
        return userIdEmailIdMap;
1100
        return userIdEmailIdMap;
1101
    }
1101
    }
1102
 
1102
 
1103
    @Override
1103
    @Override
1104
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) {
1104
    public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) throws ProfitMandiBusinessException {
1105
        List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
1105
        List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
1106
        Set<Integer> userIds = new HashSet<>();
1106
        Set<Integer> userIds = new HashSet<>();
1107
        for (UserAccount userAccount : userAccounts) {
1107
        for (UserAccount userAccount : userAccounts) {
1108
            userIds.add(userAccount.getUserId());
1108
            userIds.add(userAccount.getUserId());
1109
        }
1109
        }
Line 1114... Line 1114...
1114
        }
1114
        }
1115
        return retailerIdEmailIdMap;
1115
        return retailerIdEmailIdMap;
1116
    }
1116
    }
1117
 
1117
 
1118
    @Override
1118
    @Override
1119
    public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
1119
    public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) throws ProfitMandiBusinessException {
1120
        Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
1120
        Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
1121
        Map<Integer, String> retailerIdNameMap = new HashMap<>();
1121
        Map<Integer, String> retailerIdNameMap = new HashMap<>();
1122
        for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
1122
        for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
1123
            retailerIdNameMap.put(entry.getKey(), entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
1123
            retailerIdNameMap.put(entry.getKey(), entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
1124
        }
1124
        }
1125
        return retailerIdNameMap;
1125
        return retailerIdNameMap;
1126
    }
1126
    }
1127
 
1127
 
1128
    @Override
1128
    @Override
1129
    @Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
1129
    @Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
1130
    public Map<Integer, String> getAllFofoRetailerIdNameMap() {
1130
    public Map<Integer, String> getAllFofoRetailerIdNameMap() throws ProfitMandiBusinessException {
1131
        List<FofoStore> stores = fofoStoreRepository.selectAll();
1131
        List<FofoStore> stores = fofoStoreRepository.selectAll();
1132
        List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
1132
        List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
1133
        return this.getAllFofoRetailerIdNameMap(storeIds);
1133
        return this.getAllFofoRetailerIdNameMap(storeIds);
1134
    }
1134
    }
1135
 
1135
 
1136
    @Override
1136
    @Override
1137
    public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
1137
    public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() throws ProfitMandiBusinessException {
1138
        List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
1138
        List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
1139
        // TODO Auto-generated method stub
1139
        // TODO Auto-generated method stub
1140
        Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
1140
        Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
1141
        fofoIdNameMap.forEach((fofoId, name) -> {
1141
        fofoIdNameMap.forEach((fofoId, name) -> {
1142
            MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
1142
            MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
Line 1147... Line 1147...
1147
        return mapWrappers;
1147
        return mapWrappers;
1148
    }
1148
    }
1149
 
1149
 
1150
    @Override
1150
    @Override
1151
    @Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
1151
    @Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
1152
    public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) {
1152
    public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) throws ProfitMandiBusinessException {
1153
        // TODO Auto-generated method stub
1153
        // TODO Auto-generated method stub
1154
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
1154
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
1155
        if (activeOnly) {
1155
        if (activeOnly) {
1156
            storeStream = storeStream.filter(x -> x.isActive());
1156
            storeStream = storeStream.filter(x -> x.isActive());
1157
        }
1157
        }
Line 1159... Line 1159...
1159
        return this.getFofoRetailers(storeIds);
1159
        return this.getFofoRetailers(storeIds);
1160
    }
1160
    }
1161
 
1161
 
1162
    @Override
1162
    @Override
1163
    @Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
1163
    @Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
1164
    public Map<Integer, CustomRetailer> getAllFofoRetailers() {
1164
    public Map<Integer, CustomRetailer> getAllFofoRetailers() throws ProfitMandiBusinessException {
1165
        // TODO Auto-generated method stub
1165
        // TODO Auto-generated method stub
1166
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
1166
        Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
1167
 
1167
 
1168
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1168
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1169
        return this.getFofoRetailers(storeIds);
1169
        return this.getFofoRetailers(storeIds);
Line 1306... Line 1306...
1306
    }
1306
    }
1307
 
1307
 
1308
 
1308
 
1309
    @Override
1309
    @Override
1310
    public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset,
1310
    public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset,
1311
                                                                  int limit, FofoType fofoType) {
1311
                                                                  int limit, FofoType fofoType) throws ProfitMandiBusinessException {
1312
 
1312
 
1313
        Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
1313
        Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit).stream();
1314
 
1314
 
1315
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1315
        List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
1316
        return this.getFofoRetailers(storeIds);
1316
        return this.getFofoRetailers(storeIds);