Subversion Repositories SmartDukaan

Rev

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

Rev 35440 Rev 35896
Line 217... Line 217...
217
                }
217
                }
218
                map.put("brands", brands);
218
                map.put("brands", brands);
219
                map.put("retailerBlockBrands", retailerBlockBrands);
219
                map.put("retailerBlockBrands", retailerBlockBrands);
220
 
220
 
221
                try {
221
                try {
222
                    PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
-
 
223
                    if (privateDealUser.getCounterId() != null) {
-
 
224
                        Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
222
                    FofoStore gstStore = fofoStoreRepository.selectByRetailerId(retailer.getId());
225
                        map.put("gstNumber", counter.getGstin());
223
                    map.put("gstNumber", gstStore != null ? gstStore.getGstNumber() : null);
226
                        // LOGGER.info("gstNumber" + counter.getGstin());
-
 
227
                    }
-
 
228
                } catch (ProfitMandiBusinessException profitMandiBusinessException) {
224
                } catch (ProfitMandiBusinessException e) {
229
                    LOGGER.error("PrivateDealUser not found");
225
                    LOGGER.error("FofoStore not found for GST lookup");
230
                }
226
                }
231
                try {
227
                try {
232
                    int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
228
                    int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
233
                    Address retailerAddress = addressRepository.selectById(retailerAddressId);
229
                    Address retailerAddress = addressRepository.selectById(retailerAddressId);
234
                    map.put("retailerAddress", retailerAddress);
230
                    map.put("retailerAddress", retailerAddress);
Line 841... Line 837...
841
            fofoStore.setAstId(updateRetailerRequest.getAstId());
837
            fofoStore.setAstId(updateRetailerRequest.getAstId());
842
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
838
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
843
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
839
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
844
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
840
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
845
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
841
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
-
 
842
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
846
        } else {
843
        } else {
847
            int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
844
            int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
848
            Address retailerAddress = addressRepository.selectById(retailerAddressId);
845
            Address retailerAddress = addressRepository.selectById(retailerAddressId);
849
 
846
 
850
            // StateInfo stateInfo = null;
847
            // StateInfo stateInfo = null;
Line 894... Line 891...
894
                fofoStore.setInternal(false);
891
                fofoStore.setInternal(false);
895
            }
892
            }
896
            fofoStore.setFofoType(FofoType.FRANCHISE);
893
            fofoStore.setFofoType(FofoType.FRANCHISE);
897
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
894
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
898
            fofoStore.setActivationType(ActivationType.ACTIVE);
895
            fofoStore.setActivationType(ActivationType.ACTIVE);
-
 
896
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
899
            fofoStoreRepository.persist(fofoStore);
897
            fofoStoreRepository.persist(fofoStore);
900
 
898
 
901
            // Auto fill in onboarding Panel
899
            // Auto fill in onboarding Panel
902
            PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
900
            PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
903
            if (pobp != null) {
901
            if (pobp != null) {
Line 998... Line 996...
998
        // Batch fetch all FofoStores to avoid N+1 queries
996
        // Batch fetch all FofoStores to avoid N+1 queries
999
        Set<Integer> retailerIds = addresses.stream().map(Address::getRetaierId).collect(Collectors.toSet());
997
        Set<Integer> retailerIds = addresses.stream().map(Address::getRetaierId).collect(Collectors.toSet());
1000
        Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(retailerIds))
998
        Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(retailerIds))
1001
                .stream().collect(Collectors.toMap(FofoStore::getId, fs -> fs));
999
                .stream().collect(Collectors.toMap(FofoStore::getId, fs -> fs));
1002
 
1000
 
1003
        // Batch fetch all PrivateDealUsers to avoid N+1 queries
-
 
1004
        Map<Integer, PrivateDealUser> privateDealUserMap = privateDealUserRepository.selectByIds(new ArrayList<>(retailerIds))
-
 
1005
                .stream().collect(Collectors.toMap(PrivateDealUser::getId, pdu -> pdu));
-
 
1006
 
-
 
1007
        // Batch fetch all Counters to avoid N+1 queries
-
 
1008
        Set<Integer> counterIds = privateDealUserMap.values().stream()
-
 
1009
                .filter(pdu -> pdu.getCounterId() != null)
-
 
1010
                .map(PrivateDealUser::getCounterId)
-
 
1011
                .collect(Collectors.toSet());
-
 
1012
        Map<Integer, Counter> counterMap = counterIds.isEmpty() ? Collections.emptyMap()
-
 
1013
                : counterRepository.selectByIds(new ArrayList<>(counterIds))
-
 
1014
                .stream().collect(Collectors.toMap(Counter::getId, c -> c));
-
 
1015
 
-
 
1016
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1001
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1017
        for (Address address : addresses) {
1002
        for (Address address : addresses) {
1018
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
1003
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
1019
            FofoStore fs = fofoStoreMap.get(address.getRetaierId());
1004
            FofoStore fs = fofoStoreMap.get(address.getRetaierId());
1020
            if (fs == null) {
1005
            if (fs == null) {
1021
                continue;
1006
                continue;
1022
            }
1007
            }
1023
 
1008
 
1024
            CustomRetailer customRetailer = buildCustomRetailer(user, address, fs, privateDealUserMap, counterMap);
1009
            CustomRetailer customRetailer = buildCustomRetailer(user, address, fs);
1025
            customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
1010
            customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
1026
        }
1011
        }
1027
        return customRetailersMap;
1012
        return customRetailersMap;
1028
    }
1013
    }
1029
 
1014
 
1030
    /**
1015
    /**
1031
     * Helper method to build CustomRetailer from fetched entities
1016
     * Helper method to build CustomRetailer from fetched entities
1032
     */
1017
     */
1033
    private CustomRetailer buildCustomRetailer(com.spice.profitmandi.dao.entity.user.User user, Address address,
1018
    private CustomRetailer buildCustomRetailer(com.spice.profitmandi.dao.entity.user.User user, Address address,
1034
                                               FofoStore fs, Map<Integer, PrivateDealUser> privateDealUserMap,
-
 
1035
                                               Map<Integer, Counter> counterMap) {
1019
                                               FofoStore fs) {
1036
        CustomRetailer customRetailer = new CustomRetailer();
1020
        CustomRetailer customRetailer = new CustomRetailer();
1037
        customRetailer.setEmail(user.getEmailId());
1021
        customRetailer.setEmail(user.getEmailId());
1038
        customRetailer.setBusinessName(address.getName());
1022
        customRetailer.setBusinessName(address.getName());
1039
        customRetailer.setMobileNumber(address.getPhoneNumber());
1023
        customRetailer.setMobileNumber(address.getPhoneNumber());
1040
        customRetailer.setCode(fs.getCode());
1024
        customRetailer.setCode(fs.getCode());
Line 1045... Line 1029...
1045
        customRetailer.setWarehouseId(fs.getWarehouseId());
1029
        customRetailer.setWarehouseId(fs.getWarehouseId());
1046
        customRetailer.setPartnerId(fs.getId());
1030
        customRetailer.setPartnerId(fs.getId());
1047
        customRetailer.setFofoType(fs.getFofoType());
1031
        customRetailer.setFofoType(fs.getFofoType());
1048
        customRetailer.setCartId(user.getActiveCartId());
1032
        customRetailer.setCartId(user.getActiveCartId());
1049
 
1033
 
1050
        // Get GST number from pre-fetched maps
-
 
1051
        PrivateDealUser pdu = privateDealUserMap.get(address.getRetaierId());
-
 
1052
        if (pdu != null && pdu.getCounterId() != null) {
-
 
1053
            Counter counter = counterMap.get(pdu.getCounterId());
-
 
1054
            customRetailer.setGstNumber(counter != null ? counter.getGstin() : null);
1034
        customRetailer.setGstNumber(fs.getGstNumber());
1055
        }
-
 
1056
 
1035
 
1057
        CustomAddress customAddress = buildCustomAddress(address);
1036
        CustomAddress customAddress = buildCustomAddress(address);
1058
        customRetailer.setAddress(customAddress);
1037
        customRetailer.setAddress(customAddress);
1059
        customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + customAddress.getCity());
1038
        customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + customAddress.getCity());
1060
        return customRetailer;
1039
        return customRetailer;
Line 1099... Line 1078...
1099
        customRetailer.setCode(store.getCode());
1078
        customRetailer.setCode(store.getCode());
1100
        customRetailer.setAstId(store.getAstId());
1079
        customRetailer.setAstId(store.getAstId());
1101
        customRetailer.setActivationType(store.getActivationType());
1080
        customRetailer.setActivationType(store.getActivationType());
1102
        customRetailer.setWarehouseId(store.getWarehouseId());
1081
        customRetailer.setWarehouseId(store.getWarehouseId());
1103
 
1082
 
1104
        // Get GST number
-
 
1105
        try {
-
 
1106
            PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
-
 
1107
            if (pdu != null && pdu.getCounterId() != null) {
-
 
1108
                Counter counter = counterRepository.selectById(pdu.getCounterId());
-
 
1109
                customRetailer.setGstNumber(counter != null ? counter.getGstin() : null);
-
 
1110
            }
-
 
1111
        } catch (Exception e) {
-
 
1112
            customRetailer.setGstNumber(null);
1083
        customRetailer.setGstNumber(store.getGstNumber());
1113
        }
-
 
1114
 
1084
 
1115
        // Reuse helper method for CustomAddress
1085
        // Reuse helper method for CustomAddress
1116
        CustomAddress customAddress = buildCustomAddress(address);
1086
        CustomAddress customAddress = buildCustomAddress(address);
1117
        customRetailer.setAddress(customAddress);
1087
        customRetailer.setAddress(customAddress);
1118
        customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
1088
        customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
Line 1134... Line 1104...
1134
 
1104
 
1135
        // Batch fetch all retailerIds to userIds mapping to avoid N+1
1105
        // Batch fetch all retailerIds to userIds mapping to avoid N+1
1136
        Set<Integer> retailerIds = addresses.stream().map(Address::getRetaierId).collect(Collectors.toSet());
1106
        Set<Integer> retailerIds = addresses.stream().map(Address::getRetaierId).collect(Collectors.toSet());
1137
        Map<Integer, Integer> retailerIdToUserIdMap = getUserIdRetailerIdMapReverse(retailerIds);
1107
        Map<Integer, Integer> retailerIdToUserIdMap = getUserIdRetailerIdMapReverse(retailerIds);
1138
 
1108
 
1139
        // Batch fetch all PrivateDealUsers to avoid N+1 queries
1109
        // Batch fetch FofoStores for GST numbers
1140
        Map<Integer, PrivateDealUser> privateDealUserMap = privateDealUserRepository.selectByIds(new ArrayList<>(retailerIds))
1110
        Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(retailerIds))
1141
                .stream().collect(Collectors.toMap(PrivateDealUser::getId, pdu -> pdu));
-
 
1142
 
-
 
1143
        // Batch fetch all Counters to avoid N+1 queries
-
 
1144
        Set<Integer> counterIds = privateDealUserMap.values().stream()
-
 
1145
                .filter(pdu -> pdu.getCounterId() != null)
-
 
1146
                .map(PrivateDealUser::getCounterId)
-
 
1147
                .collect(Collectors.toSet());
-
 
1148
        Map<Integer, Counter> counterMap = counterIds.isEmpty() ? Collections.emptyMap()
-
 
1149
                : counterRepository.selectByIds(new ArrayList<>(counterIds))
-
 
1150
                .stream().collect(Collectors.toMap(Counter::getId, c -> c));
1111
                .stream().collect(Collectors.toMap(FofoStore::getId, fs -> fs));
1151
 
1112
 
1152
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1113
        Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
1153
        for (Address address : addresses) {
1114
        for (Address address : addresses) {
1154
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
1115
            com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
1155
            Integer userId = retailerIdToUserIdMap.get(user.getId());
1116
            Integer userId = retailerIdToUserIdMap.get(user.getId());
Line 1162... Line 1123...
1162
            customRetailer.setBusinessName(address.getName());
1123
            customRetailer.setBusinessName(address.getName());
1163
            customRetailer.setMobileNumber(address.getPhoneNumber());
1124
            customRetailer.setMobileNumber(address.getPhoneNumber());
1164
            customRetailer.setCartId(user.getActiveCartId());
1125
            customRetailer.setCartId(user.getActiveCartId());
1165
            customRetailer.setPartnerId(address.getRetaierId());
1126
            customRetailer.setPartnerId(address.getRetaierId());
1166
 
1127
 
1167
            // Get GST number from pre-fetched maps
-
 
1168
            PrivateDealUser pdu = privateDealUserMap.get(address.getRetaierId());
1128
            FofoStore fs = fofoStoreMap.get(address.getRetaierId());
1169
            if (pdu != null && pdu.getCounterId() != null) {
-
 
1170
                Counter counter = counterMap.get(pdu.getCounterId());
-
 
1171
                customRetailer.setGstNumber(counter != null ? counter.getGstin() : null);
1129
            customRetailer.setGstNumber(fs != null ? fs.getGstNumber() : null);
1172
            }
-
 
1173
 
1130
 
1174
            CustomAddress customAddress = buildCustomAddress(address);
1131
            CustomAddress customAddress = buildCustomAddress(address);
1175
            customRetailer.setAddress(customAddress);
1132
            customRetailer.setAddress(customAddress);
1176
            customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + customAddress.getCity());
1133
            customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + customAddress.getCity());
1177
            customRetailersMap.put(userId, customRetailer);
1134
            customRetailersMap.put(userId, customRetailer);