Subversion Repositories SmartDukaan

Rev

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

Rev 36000 Rev 36017
Line 256... Line 256...
256
        }
256
        }
257
    }
257
    }
258
 
258
 
259
    /**
259
    /**
260
     * Save status duration to RbmBreakLog
260
     * Save status duration to RbmBreakLog
-
 
261
     * Uses UPSERT logic: If record exists within time window, update duration; otherwise create new
261
     *
262
     *
262
     * @param statusStartTime - the time when agent ENTERED this status (start time)
263
     * @param statusStartTime - the time when agent ENTERED this status (start time)
263
     */
264
     */
264
    private void saveStatusDuration(int authId, String agentName, String srNumber, String status,
265
    private void saveStatusDuration(int authId, String agentName, String srNumber, String status,
265
                                    String durationDisplay, int durationSeconds, LocalDateTime statusStartTime) {
266
                                    String durationDisplay, int durationSeconds, LocalDateTime statusStartTime) {
Line 267... Line 268...
267
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
268
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {
268
                @Override
269
                @Override
269
                protected void doInTransactionWithoutResult(TransactionStatus txStatus) {
270
                protected void doInTransactionWithoutResult(TransactionStatus txStatus) {
270
                    LocalDate logDate = statusStartTime.toLocalDate();
271
                    LocalDate logDate = statusStartTime.toLocalDate();
271
 
272
 
-
 
273
                    // Check if existing record within 5 minute window
272
                    LOGGER.info("Saving status duration: agent={}, status={}, startTime={}, duration={}s ({})",
274
                    RbmBreakLog existing = rbmBreakLogRepository.findByAuthIdStatusAndLogTimeWindow(
273
                            agentName, status, statusStartTime, durationSeconds, durationDisplay);
275
                            authId, status, statusStartTime, 5);
274
 
276
 
-
 
277
                    if (existing != null) {
-
 
278
                        // Update existing record with latest duration
-
 
279
                        LOGGER.info("Updating existing break log id={}: agent={}, status={}, duration {}s -> {}s",
-
 
280
                                existing.getId(), agentName, status, existing.getDurationSeconds(), durationSeconds);
-
 
281
                        rbmBreakLogRepository.updateDuration(existing.getId(), durationSeconds, durationDisplay);
-
 
282
                    } else {
-
 
283
                        // Create new record
-
 
284
                        LOGGER.info("Creating new break log: agent={}, status={}, startTime={}, duration={}s ({})",
-
 
285
                                agentName, status, statusStartTime, durationSeconds, durationDisplay);
-
 
286
 
275
                    RbmBreakLog breakLog = new RbmBreakLog(
287
                        RbmBreakLog breakLog = new RbmBreakLog(
276
                            authId,
288
                                authId,
277
                            agentName,
289
                                agentName,
278
                            srNumber,
290
                                srNumber,
279
                            status,
291
                                status,
280
                            statusStartTime,  // Use START TIME when agent entered this status
292
                                statusStartTime,
281
                            durationSeconds,
293
                                durationSeconds,
282
                            durationDisplay,
294
                                durationDisplay,
283
                            logDate
295
                                logDate
284
                    );
296
                        );
285
                    rbmBreakLogRepository.persist(breakLog);
297
                        rbmBreakLogRepository.persist(breakLog);
-
 
298
                    }
286
                }
299
                }
287
            });
300
            });
288
        } catch (Exception e) {
301
        } catch (Exception e) {
289
            LOGGER.error("Error saving status duration for {}: {}", agentName, e.getMessage());
302
            LOGGER.error("Error saving status duration for {}: {}", agentName, e.getMessage());
290
        }
303
        }