| Line 27... |
Line 27... |
| 27 |
import com.spice.profitmandi.dao.repository.auth.*;
|
27 |
import com.spice.profitmandi.dao.repository.auth.*;
|
| 28 |
import com.spice.profitmandi.dao.repository.cs.*;
|
28 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 29 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
29 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 30 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
30 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
31 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| - |
|
32 |
import com.spice.profitmandi.dao.repository.fofo.RatingReminderRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
|
33 |
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.fofo.SalesRatingRepository;
|
34 |
import com.spice.profitmandi.dao.repository.fofo.SalesRatingRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
35 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
36 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
37 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| Line 2257... |
Line 2258... |
| 2257 |
salesRatingRepository.persist(salesRating);
|
2258 |
salesRatingRepository.persist(salesRating);
|
| 2258 |
|
2259 |
|
| 2259 |
return responseSender.ok("Rating submitted successfully.");
|
2260 |
return responseSender.ok("Rating submitted successfully.");
|
| 2260 |
}
|
2261 |
}
|
| 2261 |
|
2262 |
|
| - |
|
2263 |
@RequestMapping(value = "/rbmRating/weekly-status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
2264 |
public ResponseEntity<?> rbmRatingWeeklyStatus(HttpServletRequest request) throws Exception {
|
| - |
|
2265 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| - |
|
2266 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| - |
|
2267 |
int fofoId = uc.getUserId();
|
| - |
|
2268 |
|
| - |
|
2269 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
| - |
|
2270 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
| - |
|
2271 |
|
| - |
|
2272 |
// Calculate current week boundaries (Monday to Sunday)
|
| - |
|
2273 |
LocalDate today = LocalDate.now();
|
| - |
|
2274 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
| - |
|
2275 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
| - |
|
2276 |
LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
| - |
|
2277 |
LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
| - |
|
2278 |
|
| - |
|
2279 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfWeekDateTime, endOfWeekDateTime);
|
| - |
|
2280 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfWeekDateTime, endOfWeekDateTime);
|
| - |
|
2281 |
|
| - |
|
2282 |
boolean pending = existingRbmRatings.isEmpty() || existingSalesRatings.isEmpty();
|
| - |
|
2283 |
|
| - |
|
2284 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
2285 |
response.put("pending", pending);
|
| - |
|
2286 |
response.put("weekStart", startOfWeek.toString());
|
| - |
|
2287 |
response.put("weekEnd", endOfWeek.toString());
|
| - |
|
2288 |
|
| - |
|
2289 |
if (rbmL1 > 0) {
|
| - |
|
2290 |
AuthUser rbmUser = authRepository.selectById(rbmL1);
|
| - |
|
2291 |
if (rbmUser != null) {
|
| - |
|
2292 |
response.put("rbmName", rbmUser.getFullName());
|
| - |
|
2293 |
}
|
| - |
|
2294 |
}
|
| - |
|
2295 |
if (salesL1Id > 0) {
|
| - |
|
2296 |
AuthUser salesUser = authRepository.selectById(salesL1Id);
|
| - |
|
2297 |
if (salesUser != null) {
|
| - |
|
2298 |
response.put("salesPersonName", salesUser.getFullName());
|
| - |
|
2299 |
}
|
| - |
|
2300 |
}
|
| - |
|
2301 |
|
| - |
|
2302 |
return responseSender.ok(response);
|
| - |
|
2303 |
}
|
| - |
|
2304 |
|
| - |
|
2305 |
@Autowired
|
| - |
|
2306 |
private RatingReminderRepository ratingReminderRepository;
|
| - |
|
2307 |
|
| - |
|
2308 |
@RequestMapping(value = "/rbmRating/reminder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
2309 |
public ResponseEntity<?> rbmRatingReminder(HttpServletRequest request) throws Exception {
|
| - |
|
2310 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| - |
|
2311 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| - |
|
2312 |
int fofoId = uc.getUserId();
|
| - |
|
2313 |
|
| - |
|
2314 |
LocalDate today = LocalDate.now();
|
| - |
|
2315 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
| - |
|
2316 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
| - |
|
2317 |
|
| - |
|
2318 |
RatingReminder reminder = ratingReminderRepository.findByFofoIdAndWeek(fofoId, startOfWeek);
|
| - |
|
2319 |
|
| - |
|
2320 |
int attemptsRemaining;
|
| - |
|
2321 |
if (reminder == null) {
|
| - |
|
2322 |
// First hit this week: create entry initialised to MAX, no decrement
|
| - |
|
2323 |
reminder = new RatingReminder();
|
| - |
|
2324 |
reminder.setFofoId(fofoId);
|
| - |
|
2325 |
reminder.setWeekStart(startOfWeek);
|
| - |
|
2326 |
reminder.setWeekEnd(endOfWeek);
|
| - |
|
2327 |
reminder.setAttemptsRemaining(RatingReminder.MAX_ATTEMPTS_PER_WEEK);
|
| - |
|
2328 |
reminder.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
2329 |
ratingReminderRepository.persist(reminder);
|
| - |
|
2330 |
attemptsRemaining = RatingReminder.MAX_ATTEMPTS_PER_WEEK;
|
| - |
|
2331 |
} else {
|
| - |
|
2332 |
// Subsequent hit: atomically decrement (floor 0) and re-read
|
| - |
|
2333 |
ratingReminderRepository.decrementRemaining(reminder.getId());
|
| - |
|
2334 |
reminder = ratingReminderRepository.findByFofoIdAndWeek(fofoId, startOfWeek);
|
| - |
|
2335 |
attemptsRemaining = reminder.getAttemptsRemaining();
|
| - |
|
2336 |
}
|
| - |
|
2337 |
|
| - |
|
2338 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
2339 |
response.put("partnerId", fofoId);
|
| - |
|
2340 |
response.put("attemptsRemaining", attemptsRemaining);
|
| - |
|
2341 |
|
| - |
|
2342 |
return responseSender.ok(response);
|
| - |
|
2343 |
}
|
| - |
|
2344 |
|
| 2262 |
|
2345 |
|
| 2263 |
}
|
2346 |
}
|
| 2264 |
|
2347 |
|