Сервис с транзакцией и повторными попытками
Условие задачи
Код-ревью метода расчёта данных и уведомления.
java@Component
public class CalculateService {
@Autowired
private FileInfoService fileInfoService;
@Autowired
private SaveRepository saveRepository;
@Autowired
private Notification notification;
private final static int MAX_ATTEMPTS = 3;
@Transactional
public void calculation(GetFilesInfoRequest request) {
int i = 0;
double count = 0;
double numberValue = 6.85;
double comission = 5.2534;
while (i < MAX_ATTEMPTS) {
SendForNotify sendForNote = fileInfoService.getFilesInfo(request);
if (sendForNote != null) {
count = sendForNote.getCount();
break;
}
}
double money = (count * comission) / numberValue;
saveRepository.save(money);
try {
notification.sendCalculate(money);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}