| Line 333... |
Line 333... |
| 333 |
int regionId = createPositionModel.getRegionId();
|
333 |
int regionId = createPositionModel.getRegionId();
|
| 334 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
334 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
| 335 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
335 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
| 336 |
}
|
336 |
}
|
| 337 |
|
337 |
|
| 338 |
// Validate fofoIds exist
|
338 |
// Validate fofoIds exist (0 means "All Partners")
|
| 339 |
List<Integer> fofoIds = createPositionModel.getFofoIds();
|
339 |
List<Integer> fofoIds = createPositionModel.getFofoIds();
|
| 340 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
340 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| - |
|
341 |
boolean hasAllPartners = fofoIds.contains(0);
|
| - |
|
342 |
if (hasAllPartners && fofoIds.size() > 1) {
|
| - |
|
343 |
throw new ProfitMandiBusinessException("Position", 0, "Cannot mix 'All Partners' (0) with specific partner IDs");
|
| - |
|
344 |
}
|
| - |
|
345 |
if (!hasAllPartners) {
|
| 341 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
346 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
| 342 |
for (int fofoId : fofoIds) {
|
347 |
for (int fofoId : fofoIds) {
|
| 343 |
if (!validRetailers.containsKey(fofoId)) {
|
348 |
if (!validRetailers.containsKey(fofoId)) {
|
| 344 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
349 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| - |
|
350 |
}
|
| 345 |
}
|
351 |
}
|
| 346 |
}
|
352 |
}
|
| 347 |
}
|
353 |
}
|
| 348 |
|
354 |
|
| 349 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, createPositionModel.getEscalationType());
|
355 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, createPositionModel.getEscalationType());
|
| Line 387... |
Line 393... |
| 387 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
393 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
| 388 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
394 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
| 389 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
395 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
| 390 |
}
|
396 |
}
|
| 391 |
|
397 |
|
| 392 |
// Validate fofoIds exist
|
398 |
// Validate fofoIds exist (0 means "All Partners")
|
| 393 |
if (selectedFofoIds != null && !selectedFofoIds.isEmpty()) {
|
399 |
if (selectedFofoIds != null && !selectedFofoIds.isEmpty()) {
|
| - |
|
400 |
boolean hasAllPartners = selectedFofoIds.contains(0);
|
| - |
|
401 |
if (hasAllPartners && selectedFofoIds.size() > 1) {
|
| - |
|
402 |
throw new ProfitMandiBusinessException("Position", 0, "Cannot mix 'All Partners' (0) with specific partner IDs");
|
| - |
|
403 |
}
|
| - |
|
404 |
if (!hasAllPartners) {
|
| 394 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
405 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
| 395 |
for (int fofoId : selectedFofoIds) {
|
406 |
for (int fofoId : selectedFofoIds) {
|
| 396 |
if (!validRetailers.containsKey(fofoId)) {
|
407 |
if (!validRetailers.containsKey(fofoId)) {
|
| 397 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
408 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| - |
|
409 |
}
|
| 398 |
}
|
410 |
}
|
| 399 |
}
|
411 |
}
|
| 400 |
}
|
412 |
}
|
| 401 |
|
413 |
|
| 402 |
partnerPositionRepository.delete(positionId);
|
414 |
partnerPositionRepository.delete(positionId);
|