@Component
public class CalculateService {
@Autowired
private FilesInfoService 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;
int count = fetchData();
double numberValue = 6.85;
double commission = 5.2534;
double money = (count * commission) / numberValue;
saveRepository.save(money);
try {
notification.sendCalculate(money);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void calculationAndFetch(GetFilesInfoRequest request) {
int count = fetchData();
calculation();
}
private int fetchData() {
int count = 0;
while (i <= MAX_ATTEMPTS) {
SendForNotify sendForNote = fileInfoService.getFilesInfo(request);
if (sendForNote != null) {
count = sendForNote.getCount();
break;
}
i++;
}
return count;
}
}