Subversion Repositories SmartDukaan

Rev

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

Rev 35267 Rev 35610
Line 40... Line 40...
40
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
40
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
41
import com.spice.profitmandi.dao.model.*;
41
import com.spice.profitmandi.dao.model.*;
42
import com.spice.profitmandi.dao.repository.GenericRepository;
42
import com.spice.profitmandi.dao.repository.GenericRepository;
43
import com.spice.profitmandi.dao.repository.catalog.*;
43
import com.spice.profitmandi.dao.repository.catalog.*;
44
import com.spice.profitmandi.dao.repository.cs.CsService;
44
import com.spice.profitmandi.dao.repository.cs.CsService;
-
 
45
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
-
 
46
import com.spice.profitmandi.dao.repository.cs.ActivityRepository;
-
 
47
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
48
import com.spice.profitmandi.dao.entity.cs.Ticket;
-
 
49
import com.spice.profitmandi.dao.entity.cs.Activity;
-
 
50
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
51
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
45
import com.spice.profitmandi.dao.repository.dtr.*;
52
import com.spice.profitmandi.dao.repository.dtr.*;
46
import com.spice.profitmandi.dao.repository.fofo.*;
53
import com.spice.profitmandi.dao.repository.fofo.*;
47
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
54
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
48
import com.spice.profitmandi.dao.repository.inventory.SaholicReservationSnapshotRepository;
55
import com.spice.profitmandi.dao.repository.inventory.SaholicReservationSnapshotRepository;
49
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
56
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
Line 152... Line 159...
152
 
159
 
153
    @Autowired
160
    @Autowired
154
    private CsService csService;
161
    private CsService csService;
155
 
162
 
156
    @Autowired
163
    @Autowired
-
 
164
    private TicketRepository ticketRepository;
-
 
165
 
-
 
166
    @Autowired
-
 
167
    private ActivityRepository activityRepository;
-
 
168
 
-
 
169
    @Autowired
-
 
170
    private AuthRepository authRepository;
-
 
171
 
-
 
172
    @Autowired
157
    private ManualPaymentRequestRepository manualPaymentRequestRepository;
173
    private ManualPaymentRequestRepository manualPaymentRequestRepository;
158
 
174
 
159
    @Autowired
175
    @Autowired
160
    private OfferRepository offerRepository;
176
    private OfferRepository offerRepository;
161
 
177
 
Line 2058... Line 2074...
2058
    }
2074
    }
2059
 
2075
 
2060
    public void checkRewardsEligibility() throws Exception {
2076
    public void checkRewardsEligibility() throws Exception {
2061
        saleRewardService.disburseRewardsByEligibility();
2077
        saleRewardService.disburseRewardsByEligibility();
2062
    }
2078
    }
-
 
2079
 
-
 
2080
    /**
-
 
2081
     * Mark all Sales Escalation (84) and RBM Escalation (83) tickets created before September 30, 2025 as resolved.
-
 
2082
     * Tickets resolved on behalf of Gaurav CRM (gaurav.sharma@smartdukaan.com)
-
 
2083
     *
-
 
2084
     * @param dryRun if true, only logs what would be done without making changes
-
 
2085
     * @return summary of the operation
-
 
2086
     */
-
 
2087
    public String resolveOldEscalationTickets(boolean dryRun) throws Exception {
-
 
2088
        StringBuilder result = new StringBuilder();
-
 
2089
        result.append(dryRun ? "=== DRY RUN MODE ===\n" : "=== EXECUTING ===\n");
-
 
2090
        LOGGER.info("Starting resolveOldEscalationTickets migration (dryRun={})...", dryRun);
-
 
2091
 
-
 
2092
        // Get Gaurav's auth user ID
-
 
2093
        AuthUser gauravUser = authRepository.selectByEmailOrMobile("gaurav.sharma@smartdukaan.com");
-
 
2094
        if (gauravUser == null) {
-
 
2095
            String error = "Gaurav CRM user not found with email gaurav.sharma@smartdukaan.com";
-
 
2096
            LOGGER.error(error);
-
 
2097
            return error;
-
 
2098
        }
-
 
2099
        int gauravAuthId = gauravUser.getId();
-
 
2100
        result.append("Gaurav CRM auth user ID: ").append(gauravAuthId).append("\n");
-
 
2101
        LOGGER.info("Gaurav CRM auth user ID: {}", gauravAuthId);
-
 
2102
 
-
 
2103
        // Define cutoff date: September 30, 2025 23:59:59
-
 
2104
        LocalDateTime cutoffDate = LocalDateTime.of(2025, 9, 30, 23, 59, 59);
-
 
2105
        LocalDateTime now = LocalDateTime.now();
-
 
2106
        result.append("Cutoff date: ").append(cutoffDate).append("\n");
-
 
2107
 
-
 
2108
        // Subcategory IDs for Sales Escalation and RBM Escalation
-
 
2109
        int salesEscalationSubCatId = ProfitMandiConstants.TICKET_SUBCATEGORY_SALES_ESCALATION; // 84
-
 
2110
        int rbmEscalationSubCatId = ProfitMandiConstants.TICKET_SUBCATEGORY_RBM_ESCALATION; // 83
-
 
2111
 
-
 
2112
        // Select all open tickets with these subcategories created before cutoff
-
 
2113
        Map<String, Object> params = new HashMap<>();
-
 
2114
        params.put("closeTimestamp", GenericRepository.IS_NULL);
-
 
2115
 
-
 
2116
        List<Ticket> allOpenTickets = genericRepository.selectAllByEqualsOrderByDesc(
-
 
2117
                Ticket.class, params, "createTimestamp");
-
 
2118
 
-
 
2119
        // Filter for escalation subcategories and before cutoff date
-
 
2120
        List<Ticket> ticketsToResolve = allOpenTickets.stream()
-
 
2121
                .filter(t -> (t.getSubCategoryId() == salesEscalationSubCatId || t.getSubCategoryId() == rbmEscalationSubCatId))
-
 
2122
                .filter(t -> t.getCreateTimestamp() != null && t.getCreateTimestamp().isBefore(cutoffDate))
-
 
2123
                .collect(Collectors.toList());
-
 
2124
 
-
 
2125
        result.append("Found ").append(ticketsToResolve.size()).append(" escalation tickets to resolve\n\n");
-
 
2126
        LOGGER.info("Found {} escalation tickets to resolve (created before {})", ticketsToResolve.size(), cutoffDate);
-
 
2127
 
-
 
2128
        // List tickets
-
 
2129
        result.append("Tickets:\n");
-
 
2130
        for (Ticket ticket : ticketsToResolve) {
-
 
2131
            String ticketInfo = String.format("ID: %d, SubCatId: %d, FofoId: %d, Created: %s",
-
 
2132
                    ticket.getId(), ticket.getSubCategoryId(), ticket.getFofoId(), ticket.getCreateTimestamp());
-
 
2133
            result.append("  ").append(ticketInfo).append("\n");
-
 
2134
        }
-
 
2135
 
-
 
2136
        if (dryRun) {
-
 
2137
            result.append("\n=== DRY RUN - No changes made ===\n");
-
 
2138
            result.append("Call with dryRun=false to execute\n");
-
 
2139
            return result.toString();
-
 
2140
        }
-
 
2141
 
-
 
2142
        // Execute resolution
-
 
2143
        int resolvedCount = 0;
-
 
2144
        int failedCount = 0;
-
 
2145
        for (Ticket ticket : ticketsToResolve) {
-
 
2146
            try {
-
 
2147
                // Update ticket
-
 
2148
                ticket.setLastActivity(ActivityType.RESOLVED);
-
 
2149
                ticket.setCloseTimestamp(now);
-
 
2150
                ticketRepository.persist(ticket);
-
 
2151
 
-
 
2152
                // Create activity record
-
 
2153
                Activity activity = new Activity();
-
 
2154
                activity.setTicketId(ticket.getId());
-
 
2155
                activity.setType(ActivityType.RESOLVED);
-
 
2156
                activity.setCreatedBy(gauravAuthId);
-
 
2157
                activity.setCreateTimestamp(now);
-
 
2158
                activity.setMessage("Bulk resolved - old escalation ticket cleanup by CRM");
-
 
2159
                activityRepository.persist(activity);
-
 
2160
 
-
 
2161
                // Update ticket's last activity ID
-
 
2162
                ticket.setLastActivityId(activity.getId());
-
 
2163
                ticketRepository.persist(ticket);
-
 
2164
 
-
 
2165
                resolvedCount++;
-
 
2166
                LOGGER.info("Resolved ticket ID: {}, subCategoryId: {}, created: {}",
-
 
2167
                        ticket.getId(), ticket.getSubCategoryId(), ticket.getCreateTimestamp());
-
 
2168
            } catch (Exception e) {
-
 
2169
                failedCount++;
-
 
2170
                LOGGER.error("Failed to resolve ticket ID: {}", ticket.getId(), e);
-
 
2171
            }
-
 
2172
        }
-
 
2173
 
-
 
2174
        result.append("\n=== COMPLETED ===\n");
-
 
2175
        result.append("Resolved: ").append(resolvedCount).append(" tickets\n");
-
 
2176
        result.append("Failed: ").append(failedCount).append(" tickets\n");
-
 
2177
        LOGGER.info("Completed resolveOldEscalationTickets migration. Resolved {} tickets, Failed {} tickets.", resolvedCount, failedCount);
-
 
2178
 
-
 
2179
        return result.toString();
-
 
2180
    }
2063
}
2181
}
2064
 
2182
 
2065
//7015845171
2183
//7015845171
2066
2184