|
1 | 1 | import accounts.BankAccount; |
2 | | -import accounts.InterestPoint; |
3 | 2 | import accounts.StudentAccount; |
4 | 3 | import accounts.serialization.BankAccountGsonSerializer; |
5 | 4 | import accounts.serialization.BankAccountXmlSerializer; |
| 5 | +import accounts.services.BankAccountService; |
6 | 6 | import accounts.services.IBankAccountService; |
| 7 | +import com.coreoz.wisp.Scheduler; |
| 8 | +import com.coreoz.wisp.schedule.Schedules; |
7 | 9 | import com.google.inject.Inject; |
8 | 10 | import com.google.inject.name.Named; |
9 | 11 | import currency.Currency; |
|
14 | 16 | import transfer.DepositTransferService; |
15 | 17 | import transfer.TransferTransferService; |
16 | 18 | import transfer.WithdrawTransferService; |
| 19 | +import transfer.services.IntrestsService; |
17 | 20 | import transfer.services.TransferLoggerService; |
18 | 21 |
|
19 | | -public class App { |
| 22 | +import java.time.Duration; |
20 | 23 |
|
| 24 | +public class App { |
| 25 | + @Inject |
| 26 | + private IntrestsService intrestsService; |
21 | 27 | @Inject |
22 | 28 | private AccountOwnerService accountOwnerService; |
23 | 29 |
|
@@ -94,12 +100,6 @@ public void run() { |
94 | 100 | System.out.println(bankAccountJsonAll); |
95 | 101 |
|
96 | 102 |
|
97 | | - for (BankAccount account: bankAccountService.getBankAccounts()){ |
98 | | - if (account instanceof InterestPoint) { |
99 | | - ((InterestPoint)account).calculateInterest(); |
100 | | - } |
101 | | - } |
102 | | - |
103 | 103 | for (BankAccount account: bankAccountService.getBankAccounts()){ |
104 | 104 |
|
105 | 105 | if (account instanceof StudentAccount) { |
@@ -160,6 +160,32 @@ public void run() { |
160 | 160 |
|
161 | 161 | System.out.println("TRANSACTIONS"); |
162 | 162 | System.out.println(transferLoggerService.getAllTransactions()); |
| 163 | + /*while(true){ |
| 164 | + intrestsService.addIntrest(); |
| 165 | + printBalance(savingAccount); |
| 166 | + try { |
| 167 | + Thread.sleep(60_000); |
| 168 | + } catch (InterruptedException e) { |
| 169 | + Thread.currentThread().interrupt(); |
| 170 | + return; |
| 171 | + } |
| 172 | + }*/ |
| 173 | + Scheduler scheduler = new Scheduler(); |
| 174 | + |
| 175 | + scheduler.schedule( |
| 176 | + "Saving account interest", |
| 177 | + () -> { |
| 178 | + intrestsService.addInterest(); |
| 179 | + |
| 180 | + notifierService.notify("Úrok byl připsán na účet."); |
| 181 | + |
| 182 | + printBalance(savingAccount); |
| 183 | + }, |
| 184 | + Schedules.afterInitialDelay( |
| 185 | + Schedules.fixedDelaySchedule(Duration.ofSeconds(60)), |
| 186 | + Duration.ZERO |
| 187 | + ) |
| 188 | + ); |
163 | 189 | } |
164 | 190 |
|
165 | 191 | private void printBalance(BankAccount bankAccount) { |
|
0 commit comments