Subversion Repositories SmartDukaan

Rev

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

Rev 34081 Rev 34082
Line 149... Line 149...
149
        AuthUser user = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
149
        AuthUser user = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
150
 
150
 
151
        Map<String, Set<Integer>> pp = csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.UPSELLING), true);
151
        Map<String, Set<Integer>> pp = csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.UPSELLING), true);
152
        Set<Integer> fofoIds = new HashSet<>(pp.get(user.getEmailId()));
152
        Set<Integer> fofoIds = new HashSet<>(pp.get(user.getEmailId()));
153
 
153
 
154
        LocalDateTime endDate = LocalDateTime.now();
-
 
155
 
-
 
156
 
-
 
157
        List<UpSaleAgentCollection> upSaleAgentCollections = upSaleAgentCollectionRepository.selectByAgentId(user.getId());
154
        List<UpSaleAgentCollection> upSaleAgentCollections = upSaleAgentCollectionRepository.selectByAgentId(user.getId());
158
        double totalProductSaleAmount = upSaleAgentCollections.stream()
155
        double totalProductSaleAmount = upSaleAgentCollections.stream()
159
                .mapToDouble(UpSaleAgentCollection::getProductSaleAmount)
156
                .mapToDouble(UpSaleAgentCollection::getProductSaleAmount)
160
                .sum();
157
                .sum();
161
 
158
 
162
        try {
159
        try {
163
            LOGGER.info("LocalDateTime {}", endDate);
-
 
164
            // Fetch all rescheduled calls and filter them in-memory
160
            // Fetch all rescheduled calls and filter them in-memory
165
            List<UpSaleCall> upSaleCalls = upSaleCallRepository.selectAllByDispostion(UpSaleCallStatus.RESCHEDULED);
161
            List<UpSaleCall> upSaleCalls = upSaleCallRepository.selectAllByDispostion(UpSaleCallStatus.RESCHEDULED);
166
            LOGGER.info("UpSaleCall {}", upSaleCalls);
162
            LOGGER.info("UpSaleCall {}", upSaleCalls);
-
 
163
 
167
            List<UpSaleCall> filteredUpSaleCalls = upSaleCalls.stream()
164
            List<UpSaleCall> filteredUpSaleCalls = upSaleCalls.stream()
168
                    .filter(call -> call.getRescheduledTimestamp() != null && call.getRescheduledTimestamp().isBefore(endDate))
165
                    .filter(call -> call.getRescheduledTimestamp() != null
-
 
166
                            && call.getRescheduledTimestamp().isBefore(LocalDateTime.now())
-
 
167
                            && call.getCreatedTimestamp() != null
-
 
168
                            && call.getCreatedTimestamp().isAfter(LocalDateTime.now().minusHours(48)))
169
                    .collect(Collectors.toList());
169
                    .collect(Collectors.toList());
170
            LOGGER.info("UpSaleCall {}", filteredUpSaleCalls);
-
 
171
 
170
 
172
            if (!filteredUpSaleCalls.isEmpty()) {
171
            if (!filteredUpSaleCalls.isEmpty()) {
173
                for (UpSaleCall upSaleCall : filteredUpSaleCalls) {
172
                for (UpSaleCall upSaleCall : filteredUpSaleCalls) {
174
                    FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(upSaleCall.getOriginalOrderId());
173
                    FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(upSaleCall.getOriginalOrderId());
175
 
174
 
Line 177... Line 176...
177
                    if (fofoIds.contains(fofoOrder.getFofoId())) {
176
                    if (fofoIds.contains(fofoOrder.getFofoId())) {
178
                        if (customer != null) {
177
                        if (customer != null) {
179
                            upSaleCall.setStatus(UpSaleCallStatus.FETCHED);
178
                            upSaleCall.setStatus(UpSaleCallStatus.FETCHED);
180
                            upSaleCall.setRescheduledTimestamp(null);
179
                            upSaleCall.setRescheduledTimestamp(null);
181
 
180
 
182
                            LOGGER.info("Processing Rescheduled UpSaleCall {}", upSaleCall);
-
 
183
 
-
 
184
                            List<Map<String, Object>> itemDetails = new ArrayList<>();
181
                            List<Map<String, Object>> itemDetails = new ArrayList<>();
185
                            List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
182
                            List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
186
 
183
 
187
                            for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
184
                            for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
188
                                Item item = itemRepository.selectById(fofoOrderItem.getItemId());
185
                                Item item = itemRepository.selectById(fofoOrderItem.getItemId());
Line 216... Line 213...
216
 
213
 
217
                            return "up-sale-call";
214
                            return "up-sale-call";
218
                        }
215
                        }
219
                    }
216
                    }
220
                }
217
                }
-
 
218
            } else {
-
 
219
                throw new RuntimeException("No filtered calls available for processing");
221
            }
220
            }
222
        } catch (Exception e) {
221
        } catch (Exception e) {
223
            // If no rescheduled calls found, fall back to original logic
222
            // If no rescheduled calls found, fall back to original logic
224
            UpSaleOrder TMinus2UpsaleOrder = this.getTMinus2UpSaleOrderByFofoIds(fofoIds);
223
            UpSaleOrder TMinus2UpsaleOrder = this.getTMinus2UpSaleOrderByFofoIds(fofoIds);
225
 
224
 
Line 289... Line 288...
289
 
288
 
290
 
289
 
291
        LOGGER.info("No valid UpSaleOrder found for up-sale call.");
290
        LOGGER.info("No valid UpSaleOrder found for up-sale call.");
292
        model.addAttribute("totalProductSaleAmount", totalProductSaleAmount);
291
        model.addAttribute("totalProductSaleAmount", totalProductSaleAmount);
293
        model.addAttribute("message", "No valid UpSaleOrder found.");
292
        model.addAttribute("message", "No valid UpSaleOrder found.");
-
 
293
 
294
        return "up-sale-call";
294
        return "up-sale-call";
295
    }
295
    }
296
 
296
 
297
    UpSaleOrder getTMinus2UpSaleOrderByFofoIds(Set<Integer> fofoIds) {
297
    UpSaleOrder getTMinus2UpSaleOrderByFofoIds(Set<Integer> fofoIds) {
298
        LocalDateTime startDateTime = LocalDateTime.now().minusDays(2); // 48 hours ago
298
        LocalDateTime startDateTime = LocalDateTime.now().minusDays(2); // 48 hours ago