2026-04-06 14:51:00 +07:00
|
|
|
package ru.soune.nocopy.service.complaint;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import ru.soune.nocopy.entity.complaint.LawCase;
|
|
|
|
|
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
|
|
|
|
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
2026-04-07 18:09:14 +07:00
|
|
|
import ru.soune.nocopy.entity.user.User;
|
2026-04-06 14:51:00 +07:00
|
|
|
import ru.soune.nocopy.repository.LawCaseRepository;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class LawCaseService {
|
|
|
|
|
|
|
|
|
|
private final LawCaseRepository lawCaseRepository;
|
|
|
|
|
|
|
|
|
|
public LawCase addLawCase(BigDecimal amount, String description, String name,
|
2026-04-07 18:09:14 +07:00
|
|
|
LawCasePriority priority, Long violationId, User user) {
|
2026-04-06 14:51:00 +07:00
|
|
|
LawCase lawCase = new LawCase();
|
|
|
|
|
|
|
|
|
|
BigDecimal damage = amount == null ? BigDecimal.ZERO : amount;
|
|
|
|
|
|
|
|
|
|
lawCase.setAmount(damage);
|
|
|
|
|
lawCase.setName(name);
|
|
|
|
|
lawCase.setDescription(description);
|
|
|
|
|
lawCase.setPriority(priority);
|
2026-04-07 15:35:32 +07:00
|
|
|
lawCase.setViolationId(violationId);
|
2026-04-07 18:09:14 +07:00
|
|
|
lawCase.setUser(user);
|
2026-04-06 14:51:00 +07:00
|
|
|
|
|
|
|
|
return lawCaseRepository.save(lawCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LawCase getById(Long id) {
|
|
|
|
|
return lawCaseRepository.findById(id).orElse(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LawCase changeStatus(Long id, LawCaseType type) {
|
|
|
|
|
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
|
|
|
|
if (lawCase == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lawCase.setType(type);
|
|
|
|
|
return lawCaseRepository.save(lawCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LawCase changePriority(Long id, LawCasePriority priority) {
|
|
|
|
|
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
|
|
|
|
if (lawCase == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lawCase.setPriority(priority);
|
|
|
|
|
return lawCaseRepository.save(lawCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LawCase changeDamage(Long id, BigDecimal damage) {
|
|
|
|
|
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
|
|
|
|
if (lawCase == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
lawCase.setAmount(damage);
|
|
|
|
|
return lawCaseRepository.save(lawCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<LawCase> getAllUserLawCases(Long userId, int pageSize, int pageNumber,
|
|
|
|
|
LawCaseType lawCaseType, String lawyer,
|
|
|
|
|
LawCasePriority lawCasePriority,
|
2026-04-07 15:35:32 +07:00
|
|
|
Long violationId,
|
2026-04-06 14:51:00 +07:00
|
|
|
String propertySort, String ascDesc) {
|
|
|
|
|
Sort.Direction direction = ascDesc.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC;
|
|
|
|
|
Sort sort = Sort.by(direction, propertySort);
|
|
|
|
|
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
|
|
|
|
|
2026-04-07 15:35:32 +07:00
|
|
|
return lawCaseRepository.getUserLawCases(userId, lawCaseType, lawyer, lawCasePriority, violationId, pageable);
|
2026-04-06 14:51:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteById(Long id) {
|
|
|
|
|
lawCaseRepository.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|