From 4fcebab43488a6db617eb312f2da5859c3851c65 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 16:52:49 +0800 Subject: [PATCH 1/9] Add daima and zhushi --- .../childbank/dao/DepositAccountBillsDao.java | 319 +++++++++++++----- .../childbank/dao/DepositAccountDao.java | 56 ++- .../java/com/seg83/childbank/dao/GoalDao.java | 47 ++- .../java/com/seg83/childbank/dao/TaskDao.java | 50 ++- .../com/seg83/childbank/dao/TaskListDao.java | 85 ++++- .../com/seg83/childbank/entity/Account.java | 14 + .../com/seg83/childbank/entity/Admin.java | 11 +- .../childbank/entity/CurrentAccount.java | 13 +- .../seg83/childbank/entity/DataWrapper.java | 20 ++ .../childbank/entity/DepositAccount.java | 8 +- .../childbank/entity/DepositAccountBills.java | 20 ++ .../java/com/seg83/childbank/entity/Goal.java | 7 + .../com/seg83/childbank/entity/History.java | 8 + .../childbank/entity/HistoryActions.java | 17 +- .../java/com/seg83/childbank/entity/Task.java | 8 + .../com/seg83/childbank/entity/TaskList.java | 20 ++ .../childbank/gui/component/MainFrame.java | 217 ++++++++---- .../currentpanel/CurrentAccountPanel.java | 4 +- .../CurrentPops/InterestRatePop.java | 184 +++++----- .../currentpanel/CurrentPops/ToFixedPop.java | 8 +- .../fixedpanel/FixedAccountPanel.java | 32 +- .../homepanel/homepop/GoalAlterationPop.java | 17 +- .../homepanel/homepop/HistoryPop.java | 21 +- .../component/settingpanel/SettingsPanel.java | 5 +- .../gui/component/taskpanel/TaskPanel.java | 36 +- .../gui/component/taskpanel/TaskPop.java | 278 ++++++++------- .../childbank/service/DepositService.java | 74 +++- .../seg83/childbank/service/GoalService.java | 50 ++- .../childbank/service/HistoryService.java | 30 +- .../childbank/service/InterestService.java | 23 +- .../childbank/service/TaskListService.java | 27 ++ .../childbank/ChildbankApplicationTests.java | 10 + .../TestService/TestDepositService.java | 120 +++++-- .../TestService/TestGoalService.java | 11 +- .../TestService/TestInterestService.java | 5 +- .../TestService/TestTaskListListService.java | 28 +- 36 files changed, 1413 insertions(+), 470 deletions(-) diff --git a/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java b/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java index f8c2465..d3f0794 100644 --- a/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java +++ b/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java @@ -8,20 +8,30 @@ import java.util.List; - +/** + * Repository class for managing deposit account bills. + * Extends {@link AbstractArrayDao} to handle deposit account bills data in JSON format. + */ @Repository @Slf4j public class DepositAccountBillsDao extends AbstractArrayDao { + private final DepositAccountDao depositAccountDao; - public long ElementCount; + /** + * Constructor for DepositAccountBillsDao. + * + * @param depositAccountDao DepositAccountDao instance for managing deposit account data. + */ @Autowired public DepositAccountBillsDao(DepositAccountDao depositAccountDao) { this.depositAccountDao = depositAccountDao; - // 修正 ElementCount 初始化 - this.getElementCount(); + getElementCount(); } + /** + * Get the number of deposit account bills. + */ @Override void getElementCount() { log.info("Request deposit account count"); @@ -29,6 +39,11 @@ void getElementCount() { log.debug("Get deposit account count {}", this.ElementCount); } + /** + * Load deposit account bills data in JSON format. + * + * @return JSONArray containing deposit account bills data. + */ @Override JSONArray load() { log.info("Request deposit account data in JSON format"); @@ -37,6 +52,12 @@ JSONArray load() { return depositAccountBills; } + /** + * Get a deposit account bill by its ID. + * + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return DepositAccountBills object with the specified ID. + */ @Override DepositAccountBills getElementById(long depositAccountBillId) { log.info("Request depositAccountBill with id {}", depositAccountBillId); @@ -50,6 +71,13 @@ DepositAccountBills getElementById(long depositAccountBillId) { throw new RuntimeException("Invalid Id"); } + /** + * Set an attribute of a deposit account bill. + * + * @param attrname Name of the attribute to set. + * @param value Value to set for the attribute. + * @param depositAccountBillId ID of the deposit account bill to update. + */ @Override void setAttribute(String attrname, Object value, long depositAccountBillId) { switch (attrname) { @@ -73,109 +101,218 @@ void setAttribute(String attrname, Object value, long depositAccountBillId) { } } - private void setDepositAccountBillAmount(long depositAccountBillId, double value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillAmount(value); - updateAccountBill(bill); - } + /** + * Set the deposit account bill amount. + * + * @param depositAccountBillId ID of the deposit account bill to update. + * @param value Value to set for the deposit account bill amount. + */ + private void setDepositAccountBillAmount(long depositAccountBillId, double value +} + case"depositAccountBillRate"->{ + log. - private void setDepositAccountBillRate(long depositAccountBillId, double value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillRate(value); - updateAccountBill(bill); - } +info("Set depositAccountBillRate to {}",value); + this. - private void setDepositAccountBillExpireDate(long depositAccountBillId, String value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillExpireDate(value); - updateAccountBill(bill); - } +setDepositAccountBillRate(depositAccountBillId, (double) value); + } + case"depositAccountBillExpireDate"->{ + log. - private void setDepositAccountBillEffectiveDate(long depositAccountBillId, String value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillEffectiveDate(value); - updateAccountBill(bill); - } +info("Set depositAccountBillExpireDate to {}",value); + this. - private void updateAccountBill(DepositAccountBills bill) { - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - for (int i = 0; i < depositAccountBills.size(); i++) { - if (depositAccountBills.get(i).getDepositAccountBillId() == bill.getDepositAccountBillId()) { - depositAccountBills.set(i, bill); - break; - } +setDepositAccountBillExpireDate(depositAccountBillId, (String) value); } - log.debug("Update DepositAccountBill Array {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - } + case"depositAccountBillEffectiveDate"->{ + log. - public void createDepositAccountBill(double amount, double rate, String effectiveDate, String expireDate) { - log.info("Create DepositAccountBill with date amount {}, rate {}, effectiveDate {}, expireDate {}", amount, rate, effectiveDate, expireDate); - DepositAccountBills newDepositAccountBills = new DepositAccountBills(this.ElementCount + 1, amount, rate, effectiveDate, expireDate); - log.debug("this.ElementCount = {}", this.ElementCount); - log.debug("DepositAccountBill created {}", newDepositAccountBills); +info("Set depositAccountBillEffectiveDate to {} ",value); + this. - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.add(newDepositAccountBills); - this.ElementCount = depositAccountBills.size(); // 更新 ElementCount - log.debug("Set DepositAccountBill Array {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - } +setDepositAccountBillEffectiveDate(depositAccountBillId, (String) value); + } +default ->throw new - public void deleteDepositAccountBill(long depositAccountBillId) { - log.info("Delete DepositAccountBill with id {}", depositAccountBillId); - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.removeIf(bill -> bill.getDepositAccountBillId() == depositAccountBillId); - log.debug("Set DepositAccountBill Array after deletion {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - this.ElementCount = depositAccountBills.size(); // 更新 ElementCount - } +RuntimeException("Invalid attribute name"); + } + } - @Override - public Object getAttribute(String attrname, long depositAccountBillId) { - if (depositAccountBillId < 0 || depositAccountBillId > this.ElementCount) { - throw new RuntimeException("Invalid Id range"); +/** + * Set the deposit account bill rate. + * + * @param depositAccountBillId ID of the deposit account bill to update. + * @param value Value to set for the deposit account bill rate. + */ +private void setDepositAccountBillRate(long depositAccountBillId, double value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillRate(value); + updateAccountBill(bill); +} + +/** + * Set the deposit account bill expire date. + * + * @param depositAccountBillId ID of the deposit account bill to update. + * @param value Value to set for the deposit account bill expire date. + */ +private void setDepositAccountBillExpireDate(long depositAccountBillId, String value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillExpireDate(value); + updateAccountBill(bill); +} + +/** + * Set the deposit account bill effective date. + * + * @param depositAccountBillId ID of the deposit account bill to update. + * @param value Value to set for the deposit account bill effective date. + */ +private void setDepositAccountBillEffectiveDate(long depositAccountBillId, String value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillEffectiveDate(value); + updateAccountBill(bill); +} + +/** + * Update the deposit account bill. + * + * @param bill DepositAccountBills object to update. + */ +private void updateAccountBill(DepositAccountBills bill) { + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + for (int i = 0; i < depositAccountBills.size(); i++) { + if (depositAccountBills.get(i).getDepositAccountBillId() == bill.getDepositAccountBillId()) { + depositAccountBills.set(i, bill); + break; } - return switch (attrname) { - case "depositAccountBillAmount" -> this.getDepositAccountBillAmount(depositAccountBillId); - case "depositAccountBillRate" -> this.getDepositAccountBillRate(depositAccountBillId); - case "depositAccountBillEffectiveDate" -> this.getDepositAccountBillEffectiveDate(depositAccountBillId); - case "depositAccountBillExpireDate" -> this.getDepositAccountBillExpireDate(depositAccountBillId); - default -> throw new RuntimeException("Invalid attribute name"); - }; } + log.debug("Update DepositAccountBill Array {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); +} - private Object getDepositAccountBillAmount(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillAmount(); - } +/** + * Create a new deposit account bill. + * + * @param amount Value to set for the deposit account bill amount. + * @param rate Value to set for the deposit account bill rate. + * @param effectiveDate Value to set for the deposit account bill effective date. + * @param expireDate Value to set for the deposit account bill expire date. + */ +public void createDepositAccountBill(double amount, double rate, String effectiveDate, String expireDate) { + log.info("Create DepositAccountBill with date amount {}, rate {}, effectiveDate {}, expireDate {}", amount, rate, effectiveDate, expireDate); + DepositAccountBills newDepositAccountBills = new DepositAccountBills(this.ElementCount + 1, amount, rate, effectiveDate, expireDate); + log.debug("this.ElementCount = {}", this.ElementCount); + log.debug("DepositAccountBill created {}", newDepositAccountBills); - private Object getDepositAccountBillRate(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillRate(); - } + List depositAccountBills = this.load().toJava + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.add(newDepositAccountBills); + this.ElementCount = depositAccountBills.size(); // 更新 ElementCount + log.debug("Set DepositAccountBill Array {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); +} - private Object getDepositAccountBillEffectiveDate(long depositAccountBillId) { - DepositAccountBills bills = this.getElementById(depositAccountBillId); - return bills.getDepositAccountBillEffectiveDate(); - } +/** + * Delete a deposit account bill. + * + * @param depositAccountBillId ID of the deposit account bill to delete. + */ +public void deleteDepositAccountBill(long depositAccountBillId) { + log.info("Delete DepositAccountBill with id {}", depositAccountBillId); + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.removeIf(bill -> bill.getDepositAccountBillId() == depositAccountBillId); + log.debug("Set DepositAccountBill Array after deletion {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + this.ElementCount = depositAccountBills.size(); // 更新 ElementCount +} - private Object getDepositAccountBillExpireDate(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillExpireDate(); +/** + * Get an attribute of a deposit account bill. + * + * @param attrname Name of the attribute to get. + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return Object containing the attribute value. + */ +@Override +public Object getAttribute(String attrname, long depositAccountBillId) { + if (depositAccountBillId < 0 || depositAccountBillId > this.ElementCount) { + throw new RuntimeException("Invalid Id range"); } + return switch (attrname) { + case "depositAccountBillAmount" -> this.getDepositAccountBillAmount(depositAccountBillId); + case "depositAccountBillRate" -> this.getDepositAccountBillRate(depositAccountBillId); + case "depositAccountBillExpireDate" -> this.getDepositAccountBillExpireDate(depositAccountBillId); + case "depositAccountBillEffectiveDate" -> this.getDepositAccountBillEffectiveDate(depositAccountBillId); + default -> throw new RuntimeException("Invalid attribute name"); + }; +} - @Override - public List getAllAttributes() { - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - return List.copyOf(depositAccountBills); - } +/** + * Get the deposit account bill amount. + * + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return Double containing the deposit account bill amount. + */ +private Object getDepositAccountBillAmount(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillAmount(); +} - public void deleteAllDepositAccountBills() { - log.info("Deleting all deposit account bills"); - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.clear(); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - this.ElementCount = 0; - } +/** + * Get the deposit account bill rate. + * + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return Double containing the deposit account bill rate. + */ +private Object getDepositAccountBillRate(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillRate(); +} + +/** + * Get the deposit account bill expire date. + * + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return String containing the deposit account bill expire date. + */ +private Object getDepositAccountBillExpireDate(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillExpireDate(); +} + +/** + * Get the deposit account bill effective date. + * + * @param depositAccountBillId ID of the deposit account bill to retrieve. + * @return String containing the deposit account bill effective date. + */ +private Object getDepositAccountBillEffectiveDate(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillEffectiveDate(); +} + +/** + * Get all attributes + * Get all attributes of a deposit account bill. + * + * @return List of Objects containing all attributes of a deposit account bill. + */ +@Override +public List getAllAttributes() { + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + return List.copyOf(depositAccountBills); +} + +/** + * Delete all deposit account bills. + */ +public void deleteAllDepositAccountBills() { + log.info("Deleting all deposit account bills"); + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.clear(); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + this.ElementCount = 0; +} } diff --git a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java index b6bf55d..becddcc 100644 --- a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java +++ b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java @@ -9,16 +9,32 @@ import java.util.List; + +/** + * Data Access Object (DAO) for managing deposit account data. + * Extends {@link AbstractDao} to handle deposit account data in JSON format. + */ @Repository @Slf4j public class DepositAccountDao extends AbstractDao { + private final AccountDao accountDao; + /** + * Constructor for DepositAccountDao. + * + * @param accountDao AccountDao instance for managing account data. + */ @Autowired public DepositAccountDao(AccountDao accountDao) { this.accountDao = accountDao; } + /** + * Load deposit account data in JSON format. + * + * @return JSONObject containing deposit account data. + */ @Override public JSONObject load() { log.info("Request DepositAccountDao in JSON format"); @@ -27,6 +43,12 @@ public JSONObject load() { return depositAccount; } + /** + * Set an attribute of a deposit account. + * + * @param attrname Name of the attribute to set. + * @param value Value to set for the attribute. + */ @Override void setAttribute(String attrname, Object value) { DepositAccount modifiedDepositAccount; @@ -40,12 +62,24 @@ void setAttribute(String attrname, Object value) { this.accountDao.setAttribute("depositAccount", modifiedDepositAccount); } + /** + * Set the deposit account bills. + * + * @param value List of DepositAccountBills objects to set for the deposit account. + * @return DepositAccount object with the updated deposit account bills. + */ private DepositAccount setDepositAccountBills(List value) { DepositAccount depositAccount = this.load().toJavaObject(DepositAccount.class); depositAccount.setDepositAccountBills(value); return depositAccount; } + /** + * Get an attribute of a deposit account. + * + * @param attrname Name of the attribute to get. + * @return Object containing the attribute value. + */ @Override public Object getAttribute(String attrname) { return switch (attrname) { @@ -54,16 +88,26 @@ public Object getAttribute(String attrname) { }; } - private List getDepositAccount() { - log.info("Getting historyActions"); - List depositAccountBills = this.load().getJSONArray("depositAccountBills").toJavaList(DepositAccountBills.class); - log.debug("Get depositAccountBills {}", depositAccountBills); - return depositAccountBills; + /** + * Get the deposit account. + * + * @return DepositAccount object containing the deposit account data. + */ + private DepositAccount getDepositAccount() { + log.info("Getting depositAccount"); + JSONObject depositAccountData = accountDao.load().getJSONObject("depositAccount"); + log.debug("Get depositAccount data {}", depositAccountData); + return depositAccountData.toJavaObject(DepositAccount.class); } - // TODO implement + /** + * Get all attributes of a deposit account. + * + * @return List of Objects containing all attributes of a deposit account. + */ @Override List getAllAttributes() { + // TODO implement return null; } } diff --git a/src/main/java/com/seg83/childbank/dao/GoalDao.java b/src/main/java/com/seg83/childbank/dao/GoalDao.java index 4898f1e..05c6939 100644 --- a/src/main/java/com/seg83/childbank/dao/GoalDao.java +++ b/src/main/java/com/seg83/childbank/dao/GoalDao.java @@ -8,24 +8,45 @@ import java.util.List; +/** + * Data Access Object (DAO) for managing goal data. + * Extends {@link AbstractDao} to handle goal data in JSON format. + */ @Repository @Slf4j public class GoalDao extends AbstractDao { + private DataWrapperDao dataWrapperDao; + /** + * Constructor for GoalDao. + * + * @param dataWrapperDao DataWrapperDao instance for managing data wrapper data. + */ @Autowired public GoalDao(DataWrapperDao dataWrapperDao) { this.dataWrapperDao = dataWrapperDao; } + /** + * Load goal data in JSON format. + * + * @return JSONObject containing goal data. + */ @Override - JSONObject load() { + public JSONObject load() { log.info("Request goal data in JSON format"); JSONObject goal = dataWrapperDao.load().getJSONObject("goal"); log.debug("Get goal data {}", goal); return goal; } + /** + * Set an attribute of a goal. + * + * @param attrname Name of the attribute to set. + * @param value Value to set for the attribute. + */ @Override public void setAttribute(String attrname, Object value) { Goal modifiedGoal; @@ -39,12 +60,24 @@ public void setAttribute(String attrname, Object value) { dataWrapperDao.setAttribute("goal", modifiedGoal); } + /** + * Set the goal amount. + * + * @param value Value to set for the goal amount. + * @return Goal object with the updated goal amount. + */ private Goal setGoalAmount(double value) { Goal goal = this.load().toJavaObject(Goal.class); goal.setGoalAmount(value); return goal; } + /** + * Get an attribute of a goal. + * + * @param attrname Name of the attribute to get. + * @return Object containing the attribute value. + */ @Override public Object getAttribute(String attrname) { return switch (attrname) { @@ -53,6 +86,11 @@ public Object getAttribute(String attrname) { }; } + /** + * Get the goal amount. + * + * @return Double containing the goal amount. + */ private Double getGoalAmount() { log.info("Get goal amount"); double goalAmount = this.load().getDouble("goalAmount"); @@ -60,8 +98,13 @@ private Double getGoalAmount() { return goalAmount; } + /** + * Get all attributes of a goal. + * + * @return List of Objects containing all attributes of a goal. + */ @Override - List getAllAttributes() { + public List getAllAttributes() { return List.of(); } } diff --git a/src/main/java/com/seg83/childbank/dao/TaskDao.java b/src/main/java/com/seg83/childbank/dao/TaskDao.java index fab2543..23ddedc 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskDao.java @@ -9,20 +9,44 @@ import java.util.List; +/** + * Data Access Object (DAO) for managing task data. + */ @Component @Slf4j public class TaskDao extends AbstractDao { - @Autowired + private DataWrapperDao dataWrapperDao; + /** + * Constructor for TaskDao. + * + * @param dataWrapperDao DataWrapperDao instance for managing data wrapper data. + */ + @Autowired + public TaskDao(DataWrapperDao dataWrapperDao) { + this.dataWrapperDao = dataWrapperDao; + } + + /** + * Load task data in JSON format. + * + * @return JSONObject containing task data. + */ @Override - JSONObject load() { + public JSONObject load() { log.info("Request task data in JSON format"); JSONObject task = dataWrapperDao.load().getJSONObject("task"); log.debug("Get task data {}", task); return task; } + /** + * Set an attribute of a task. + * + * @param attrname Name of the attribute to set. + * @param value Value to set for the attribute. + */ @Override void setAttribute(String attrname, Object value) { Task modifiedTask; @@ -36,12 +60,24 @@ void setAttribute(String attrname, Object value) { this.dataWrapperDao.setAttribute("task", modifiedTask); } + /** + * Set the task list. + * + * @param value List of TaskList objects to set for the task. + * @return Task object with the updated task list. + */ private Task setTaskList(List value) { Task task = this.load().toJavaObject(Task.class); task.setTaskList(value); return task; } + /** + * Get an attribute of a task. + * + * @param attrname Name of the attribute to get. + * @return Object containing the attribute value. + */ @Override public Object getAttribute(String attrname) { return switch (attrname) { @@ -50,10 +86,20 @@ public Object getAttribute(String attrname) { }; } + /** + * Get the task list. + * + * @return List of TaskList objects containing the task list. + */ private List getTaskList() { return this.load().toJavaObject(Task.class).getTaskList(); } + /** + * Get all attributes of a task. + * + * @return List of Objects containing all attributes of a task. + */ @Override List getAllAttributes() { return List.of(); diff --git a/src/main/java/com/seg83/childbank/dao/TaskListDao.java b/src/main/java/com/seg83/childbank/dao/TaskListDao.java index d9cd61b..6e4a6d9 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskListDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskListDao.java @@ -8,35 +8,60 @@ import java.util.List; +/** + * Data Access Object (DAO) for managing task list data. + */ @Component @Slf4j public class TaskListDao extends AbstractArrayDao { - long ElementCount; + private TaskDao taskDao; + /** + * Constructor for TaskListDao. + * + * @param taskDao TaskDao instance for managing task data. + */ @Autowired public TaskListDao(TaskDao taskDao) { this.taskDao = taskDao; this.getElementCount(); } + /** + * Load task list data in JSON format. + * + * @return JSONArray containing task list data. + */ @Override - JSONArray load() { + public JSONArray load() { log.info("Request task list data in JSON format"); JSONArray taskList = taskDao.load().getJSONArray("taskList"); log.debug("Get task list data {}", taskList); return taskList; } + /** + * Get the number of tasks in the task list. + * + * @return Long containing the number of tasks in the task list. + */ @Override - void getElementCount() { + public long getElementCount() { log.info("Request tasks count"); this.ElementCount = this.load().size(); log.debug("Get history actions count {}", this.ElementCount); + return this.ElementCount; } + /** + * Get a task by its ID. + * + * @param Id ID of the task to get. + * @return TaskList object containing the task data. + */ @Override - Object getElementById(long Id) { + public Object getElementById(long Id) { log.info("Request task by id {}", Id); List taskLists = this.load().toList(TaskList.class); for (TaskList taskList : taskLists) { @@ -48,8 +73,14 @@ Object getElementById(long Id) { throw new RuntimeException("Invalid task id"); } - @Override + /** + * Set the task status for a specific task. + * + * @param Id ID of the task to set the status for. + * @param value Value to set for the task status. + */ @Deprecated + @Override public void setAttribute(String attrname, Object value, long Id) { switch (attrname) { case "taskStatus" -> { @@ -60,6 +91,12 @@ public void setAttribute(String attrname, Object value, long Id) { } } + /** + * Set the task status for a specific task. + * + * @param Id ID of the task to set the status for. + * @param value Value to set for the task status. + */ private void setTaskStatue(long Id, boolean value) { List taskLists = this.load().toList(TaskList.class); for (TaskList taskList : taskLists) { @@ -73,6 +110,12 @@ private void setTaskStatue(long Id, boolean value) { throw new RuntimeException("Invalid task id"); } + /** + * Create a new task. + * + * @param taskName Name of the task to create. + * @param taskDescription Description of the task to create. + */ public void createTask(String taskName, String taskDescription) { log.info("Create task with name {} and description {}", taskName, taskDescription); TaskList newtask = new TaskList(this.ElementCount + 1, taskName, taskDescription, false); @@ -86,6 +129,13 @@ public void createTask(String taskName, String taskDescription) { taskDao.setAttribute("taskList", taskList); } + /** + * Get an attribute of a task. + * + * @param attrname Name of the attribute to get. + * @param Id ID of the task to get the attribute for. + * @return Object containing the attribute value. + */ @Override public Object getAttribute(String attrname, long Id) { switch (attrname) { @@ -105,20 +155,43 @@ public Object getAttribute(String attrname, long Id) { } } + /** + * Get the task name for a specific task. + * + * @param Id ID of the task to get the name for. + * @return String containing the task name. + */ private String getTaskName(long Id) { return ((TaskList) this.getElementById(Id)).getTaskName(); } + /** + * Get the task description for a specific task. + * + * @param Id ID of the task to get the description for. + * @return String containing the task description. + */ private String getTaskDescription(long Id) { return ((TaskList) this.getElementById(Id)).getTaskDescription(); } + /** + * Get the task status for a specific task. + * + * @param Id ID of the task to get the status for. + * @return Boolean containing the task status. + */ private boolean getTaskStatus(long Id) { return ((TaskList) this.getElementById(Id)).isTaskStatus(); } + /** + * Get all attributes of a task. + * + * @return List of Objects containing all attributes of a task. + */ @Override - List getAllAttributes() { + public List getAllAttributes() { return List.of(); } } diff --git a/src/main/java/com/seg83/childbank/entity/Account.java b/src/main/java/com/seg83/childbank/entity/Account.java index 26e7b80..67c45ec 100644 --- a/src/main/java/com/seg83/childbank/entity/Account.java +++ b/src/main/java/com/seg83/childbank/entity/Account.java @@ -5,16 +5,30 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * Account class represents an account with a deposit account and a current account. + */ @Data @AllArgsConstructor @NoArgsConstructor public class Account { + + /** + * Account password. + */ @JSONField(name = "accountPassword") private String accountPassword; + /** + * Deposit account associated with the account. + */ @JSONField(name = "depositAccount") private DepositAccount depositAccount; + /** + * Current account associated with the account. + */ @JSONField(name = "currentAccount") private CurrentAccount currentAccount; } + diff --git a/src/main/java/com/seg83/childbank/entity/Admin.java b/src/main/java/com/seg83/childbank/entity/Admin.java index a6a6f22..dbfced6 100644 --- a/src/main/java/com/seg83/childbank/entity/Admin.java +++ b/src/main/java/com/seg83/childbank/entity/Admin.java @@ -6,14 +6,23 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * Admin class represents an admin user. + */ @Data @AllArgsConstructor @NoArgsConstructor public class Admin { + + /** + * Admin password. + */ @JSONField(name = "adminPassword") private String adminPassword; + /** + * Indicates if it is the first login for the admin user. + */ @JSONField(name = "firstLogin") private boolean firstLogin; - } diff --git a/src/main/java/com/seg83/childbank/entity/CurrentAccount.java b/src/main/java/com/seg83/childbank/entity/CurrentAccount.java index 5c4ef62..f57c5b6 100644 --- a/src/main/java/com/seg83/childbank/entity/CurrentAccount.java +++ b/src/main/java/com/seg83/childbank/entity/CurrentAccount.java @@ -3,16 +3,27 @@ import com.alibaba.fastjson2.annotation.JSONField; import lombok.Data; +/** + * CurrentAccount class represents a current account. + */ @Data public class CurrentAccount { - + /** + * Amount in the current account. + */ @JSONField(name = "currentAccountAmount") private double currentAccountAmount; + /** + * Interest rate of the current account. + */ @JSONField(name = "currentAccountRate") private double currentAccountRate; + /** + * Last interest date of the current account. + */ @JSONField(name = "lastInterestDate") private String lastInterestDate; } diff --git a/src/main/java/com/seg83/childbank/entity/DataWrapper.java b/src/main/java/com/seg83/childbank/entity/DataWrapper.java index 2f0d726..f44e6d7 100644 --- a/src/main/java/com/seg83/childbank/entity/DataWrapper.java +++ b/src/main/java/com/seg83/childbank/entity/DataWrapper.java @@ -4,20 +4,40 @@ import com.alibaba.fastjson2.annotation.JSONField; import lombok.Data; +/** + * DataWrapper class is a container for various data objects. + */ @Data public class DataWrapper { + + /** + * Admin object. + */ @JSONField(name = "admin") private Admin admin; + /** + * Account object. + */ @JSONField(name = "account") private Account account; + /** + * History object. + */ @JSONField(name = "history") private History history; + /** + * Goal object. + */ @JSONField(name = "goal") private Goal goal; + /** + * Task object. + */ @JSONField(name = "task") private Task task; } + diff --git a/src/main/java/com/seg83/childbank/entity/DepositAccount.java b/src/main/java/com/seg83/childbank/entity/DepositAccount.java index cfa04c6..f5ccd7d 100644 --- a/src/main/java/com/seg83/childbank/entity/DepositAccount.java +++ b/src/main/java/com/seg83/childbank/entity/DepositAccount.java @@ -5,11 +5,15 @@ import java.util.List; +/** + * DepositAccount class represents a deposit account. + */ @Data public class DepositAccount { - + /** + * List of DepositAccountBills objects associated with the deposit account. + */ @JSONField(name = "depositAccountBills") private List depositAccountBills; - } diff --git a/src/main/java/com/seg83/childbank/entity/DepositAccountBills.java b/src/main/java/com/seg83/childbank/entity/DepositAccountBills.java index ac88a3f..2e22be6 100644 --- a/src/main/java/com/seg83/childbank/entity/DepositAccountBills.java +++ b/src/main/java/com/seg83/childbank/entity/DepositAccountBills.java @@ -4,21 +4,41 @@ import lombok.AllArgsConstructor; import lombok.Data; +/** + * DepositAccountBills class represents a deposit account bill. + */ @Data @AllArgsConstructor public class DepositAccountBills { + + /** + * Deposit account bill ID. + */ @JSONField(name = "depositAccountBillId") private long depositAccountBillId; + /** + * Deposit account bill amount. + */ @JSONField(name = "depositAccountBillAmount") private double depositAccountBillAmount; + /** + * Deposit account bill interest rate. + */ @JSONField(name = "depositAccountBillRate") private double depositAccountBillRate; + /** + * Deposit account bill effective date. + */ @JSONField(name = "depositAccountBillEffectiveDate") private String depositAccountBillEffectiveDate; + /** + * Deposit account bill expire date. + */ @JSONField(name = "depositAccountBillExpireDate") private String depositAccountBillExpireDate; } + diff --git a/src/main/java/com/seg83/childbank/entity/Goal.java b/src/main/java/com/seg83/childbank/entity/Goal.java index d910aaf..8818dfc 100644 --- a/src/main/java/com/seg83/childbank/entity/Goal.java +++ b/src/main/java/com/seg83/childbank/entity/Goal.java @@ -3,8 +3,15 @@ import com.alibaba.fastjson2.annotation.JSONField; import lombok.Data; +/** + * Goal class represents a goal. + */ @Data public class Goal { + + /** + * Goal amount. + */ @JSONField(name = "goalAmount") private double goalAmount; } diff --git a/src/main/java/com/seg83/childbank/entity/History.java b/src/main/java/com/seg83/childbank/entity/History.java index 43a39bf..2f1277e 100644 --- a/src/main/java/com/seg83/childbank/entity/History.java +++ b/src/main/java/com/seg83/childbank/entity/History.java @@ -5,8 +5,16 @@ import java.util.List; +/** + * History class represents a history of actions. + */ @Data public class History { + + /** + * List of HistoryActions objects associated with the history. + */ @JSONField(name = "historyActions") private List historyActions; } + diff --git a/src/main/java/com/seg83/childbank/entity/HistoryActions.java b/src/main/java/com/seg83/childbank/entity/HistoryActions.java index 32d4bdf..d005790 100644 --- a/src/main/java/com/seg83/childbank/entity/HistoryActions.java +++ b/src/main/java/com/seg83/childbank/entity/HistoryActions.java @@ -4,21 +4,34 @@ import lombok.AllArgsConstructor; import lombok.Data; +/** + * HistoryActions class represents a history action. + */ @Data @AllArgsConstructor public class HistoryActions { + /** + * History action ID. + */ @JSONField(name = "historyId") private long historyId; + /** + * History action date and time. + */ @JSONField(name = "historyDateTime") private String historyDateTime; + /** + * History action amount. + */ @JSONField(name = "historyAmount") private double historyAmount; + /** + * History action type. + */ @JSONField(name = "historyType") private String historyType; - - } diff --git a/src/main/java/com/seg83/childbank/entity/Task.java b/src/main/java/com/seg83/childbank/entity/Task.java index 827f13b..a582705 100644 --- a/src/main/java/com/seg83/childbank/entity/Task.java +++ b/src/main/java/com/seg83/childbank/entity/Task.java @@ -5,8 +5,16 @@ import java.util.List; +/** + * Task class represents a task. + */ @Data public class Task { + + /** + * List of TaskList objects associated with the task. + */ @JSONField(name = "taskList") private List taskList; } + diff --git a/src/main/java/com/seg83/childbank/entity/TaskList.java b/src/main/java/com/seg83/childbank/entity/TaskList.java index 3fef32c..bbb1c3a 100644 --- a/src/main/java/com/seg83/childbank/entity/TaskList.java +++ b/src/main/java/com/seg83/childbank/entity/TaskList.java @@ -4,15 +4,35 @@ import lombok.AllArgsConstructor; import lombok.Data; +/** + * TaskList class represents a task list. + */ @Data @AllArgsConstructor public class TaskList { + + /** + * Task ID. + */ @JSONField(name = "taskId") private long taskId; + + /** + * Task name. + */ @JSONField(name = "taskName") private String taskName; + + /** + * Task description. + */ @JSONField(name = "taskDescription") private String taskDescription; + + /** + * Task status. + */ @JSONField(name = "taskStatus") private boolean taskStatus; } + diff --git a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java index 60c773d..b9cca87 100644 --- a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java +++ b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java @@ -20,21 +20,65 @@ import javax.swing.*; import java.awt.*; +/** + * MainFrame is the main window of the ChildBank application. + */ @Component @Slf4j public class MainFrame extends JFrame { + + /** + * HomePanel instance for displaying the home page. + */ private HomePanel homePanel; + + /** + * WelcomePanel instance for displaying the welcome page. + */ private WelcomePanel welcomePanel; + + /** + * SetupPanel instance for handling setup-related tasks. + */ private SetupPanel setupPanel; + + /** + * SettingsPanel instance for displaying and updating user settings. + */ private SettingsPanel settingsPanel; + + /** + * FixedAccountPanel instance for managing fixed-term accounts. + */ private FixedAccountPanel fixedAccountPanel; + + /** + * CurrentAccountPanel instance for managing current accounts. + */ private CurrentAccountPanel currentAccountPanel; + + /** + * TaskPanel instance for displaying and managing tasks. + */ private TaskPanel taskPanel; + /** + * SetupService instance for handling setup-related business logic. + */ private SetupService setupService; - private InterestService interestService; - private DepositService depositService; + /** + * InterestService instance for handling interest-related business logic. + */ private InterestService interestService; + /** + * DepositService instance for handling deposit-related business logic. + */ + private DepositService depositService; + /** + * Constructor for creating a new MainFrame instance. + * + * @throws HeadlessException if the main window cannot be created + */ public MainFrame() throws HeadlessException { setTitle("ChildBank"); setSize(700, 500); @@ -42,7 +86,9 @@ public MainFrame() throws HeadlessException { setDefaultCloseOperation(EXIT_ON_CLOSE); log.info("Create MainFrame"); } - + /** + * Autowires the panels and services, and initializes the main window. + */ @Autowired private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPanel setupPanel, SetupService setupService, InterestService interestService, SettingsPanel settingsPanel, FixedAccountPanel fixedAccountPanel, CurrentAccountPanel currentAccountPanel, TaskPanel taskPanel, DepositService depositService) { @@ -57,7 +103,9 @@ private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPane this.taskPanel = taskPanel; this.depositService = depositService; } - + /** + * Initializes the main window after all panels and services are autowired. + */ @PostConstruct public void init() { if (setupService.checkFirstLogin()) { @@ -67,72 +115,112 @@ public void init() { } } - @EventListener - public void onPanelSwitch(PanelSwitchEvent event) { - switch (event.getPanelName()) { - case "setup" -> initSetupPanel(); - case "home" -> initHomePanel(); - case "setting" -> initSettingsPanel(); - case "fixed" -> initFixedAccountPanel(); - case "current" -> initCurrentPanel(); - case "task" -> initTaskPanel(); - default -> throw new IllegalArgumentException("Unknown panel name: " + event.getPanelName()); - } + /** + * Handles panel switch events by updating the main window's content pane. + * + * @param event the PanelSwitchEvent triggered by a panel switch + */ +@EventListener +public void onPanelSwitch(PanelSwitchEvent event) { + switch (event.getPanelName()) { + case "setup" -> initSetupPanel(); + case "home" -> initHomePanel(); + case "setting" -> initSettingsPanel(); + case "fixed" -> initFixedAccountPanel(); + case "current" -> initCurrentPanel(); + case "task" -> initTaskPanel(); + default -> throw new IllegalArgumentException("Unknown panel name: " + event.getPanelName()); } +} - private void initWelcomePanel() { - welcomePanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.welcomePanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create welcomePanel in MainFrame"); - } +/** + * Initializes the welcome panel and sets it as the main window's content pane. + */ +private void initWelcomePanel() { + welcomePanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.welcomePanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create welcomePanel in MainFrame"); +} - private void initSetupPanel() { - setupPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.setupPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create setupPanel in MainFrame"); - } +/** + * Initializes the setup panel and sets it as the main window's content pane. + */ +private void initSetupPanel() { + setupPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.setupPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create setupPanel in MainFrame"); +} - private void initHomePanel() { - homePanel.$$$getRootComponent$$$().updateUI(); - interestService.calculateCurrentInterest(); - depositService.processMaturedDeposits(); - homePanel.updateCurrentBallance(); - homePanel.updateGoal(); - homePanel.updateFixBallance(); +/** + * Initializes the home panel and sets it as the main window's content pane. + * Calculates current interest and processes matured deposits. + */ +private void initHomePanel() { + homePanel.$$$getRootComponent$$$().updateUI(); + interestService.calculateCurrentInterest(); + depositService.processMaturedDeposits(); + homePanel.updateCurrentBallance(); + homePanel.updateGoal(); + homePanel.updateFixBallance(); + + setContentPane(this.homePanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create homePanel in MainFrame"); +} - setContentPane(this.homePanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create homePanel in MainFrame"); - } +/** + * Initializes the settings panel and sets it as the main window's content pane. + */ +private void initSettingsPanel() { + settingsPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.settingsPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create settingPanel in MainFrame"); +} - private void initSettingsPanel() { - settingsPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.settingsPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create settingPanel in MainFrame"); - } +/** + * Initializes the fixed account panel and sets it as the main window's content pane. + * Creates the table and sets the total fixed label. + */ +private void initFixedAccountPanel() { + fixedAccountPanel.createTable(); + fixedAccountPanel.setTotalFixedLabel(); + fixedAccountPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.fixedAccountPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create fixedAccountPanel in MainFrame"); +} - private void initFixedAccountPanel() { - fixedAccountPanel.createTable(); - fixedAccountPanel.setTotalFixedLabel(); - fixedAccountPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.fixedAccountPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create fixedAccountPanel in MainFrame"); - } +/** + * Initializes the current account panel and sets it as the main window's content pane. + * Updates the panel. + */ +private void initCurrentPanel() { + currentAccountPanel.$$$getRootComponent$$$().updateUI(); + currentAccountPanel.updatePanel(); + setContentPane(this.currentAccountPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create currentAccountPanel in MainFrame"); +} +/** + * Initializes the task panel and sets it as the main window's content pane. + * Creates the table. + */ private void initCurrentPanel() { currentAccountPanel.$$$getRootComponent$$$().updateUI(); currentAccountPanel.updatePanel(); @@ -142,7 +230,10 @@ private void initCurrentPanel() { repaint(); log.info("Create currentAccountPanel in MainFrame"); } - + /** + * Initializes the task panel and sets it as the main window's content pane. + * Creates the table. + */ private void initTaskPanel() { taskPanel.createTable(); taskPanel.$$$getRootComponent$$$().updateUI(); diff --git a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentAccountPanel.java b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentAccountPanel.java index 5726307..fd319f5 100644 --- a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentAccountPanel.java +++ b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentAccountPanel.java @@ -68,7 +68,9 @@ public CurrentAccountPanel() { publisher.publishEvent(new PanelSwitchEvent(this, "home")); }); } - + /** + * This method is called to update the panel. + */ public void updatePanel() { amountLabel.setText(currentService.amountToUiContent()); rateLabel.setText(currentService.rateToUiContent()); diff --git a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java index 7772179..717c4e9 100644 --- a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java +++ b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java @@ -16,99 +16,99 @@ /** * A JDialog component that facilitates alter interest rate * It includes fields for entering the period to be select, the new interest rate and password, and buttons for OK and Cancel actions - */ -@Component -@Slf4j -public class InterestRatePop extends JDialog { - @Autowired - CurrentService currentService; - @Autowired - AdminDao adminDao; - - private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; - private JComboBox comboBox1; - private JTextField textField1; - private JPasswordField passwordField1; - - public InterestRatePop() { - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); - - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); - } - }); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - } - - private void onOK() { - // add your code here - String ratetxt = textField1.getText(); - String password = new String(passwordField1.getPassword()); - String passtarget = (String) adminDao.getAttribute("adminPassword"); - double rate = 0.0; - try { - rate = Double.parseDouble(ratetxt); - if (rate < 0) { - JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); - return; - } - } catch (NumberFormatException e) { - JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); - } - if (password.equals(passtarget)) { - currentService.modifyInterestRate(rate); - } else { - JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); - } - dispose(); - } - - private void onCancel() { - // add your code here if necessary - dispose(); - } - - public void init() { - log.debug("Initializing rate setting dialog"); - // Clear the text fields - textField1.setText(""); - passwordField1.setText(""); - this.pack(); // 使用已经存在的this引用而不是创建新的实例 - setLocationRelativeTo(null); // null 使窗口居中于屏幕 - this.setVisible(true); - } +*/ + + // @Autowired private CurrentService currentService; + // @Autowired private AdminDao adminDao; + + private JPanel contentPane; + private JButton buttonOK; + private JButton buttonCancel; + private JComboBox comboBox1; + private JTextField textField1; + private JPasswordField passwordField1; + + public InterestRatePop() { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + + buttonCancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + } + + /** + * This method is called when the user clicks the OK button. + */ + private void onOK() { + String ratetxt = textField1.getText(); + String password = new String(passwordField1.getPassword()); + String passtarget = (String) adminDao.getAttribute("adminPassword"); + double rate = 0.0; + try { + rate = Double.parseDouble(ratetxt); + if (rate < 0) { + JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); + } + if (password.equals(passtarget)) { + currentService.modifyInterestRate(rate); + } else { + JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); + } + dispose(); + } + + /** + * This method is called when the user clicks the Cancel button. + */ + private void onCancel() { + dispose(); + } + + /** + * This method is called to initialize the dialog. + */ + public void init() { + log.debug("Initializing rate setting dialog"); + // Clear the text fields + textField1.setText(""); + passwordField1.setText(""); + // Use the existing this reference instead of creating a new instance + this.pack(); + // Center the dialog + setLocationRelativeTo(null); + this.setVisible(true); + } +} - { -// GUI initializer generated by IntelliJ IDEA GUI Designer -// >>> IMPORTANT!! <<< -// DO NOT EDIT OR ADD ANY CODE HERE! - $$$setupUI$$$(); - } /** * Method generated by IntelliJ IDEA GUI Designer diff --git a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/ToFixedPop.java b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/ToFixedPop.java index 71733f1..7e402dd 100644 --- a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/ToFixedPop.java +++ b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/ToFixedPop.java @@ -72,7 +72,9 @@ public void actionPerformed(ActionEvent e) { } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } - + /** + * This method is called when the user clicks the OK button. + */ private void onOK() { // add your code here String amount = amountField.getText(); @@ -135,7 +137,9 @@ private void onOK() { } } - + /** + * This method is called when the user clicks the Cancel button. + */ private void onCancel() { // add your code here if necessary diff --git a/src/main/java/com/seg83/childbank/gui/component/fixedpanel/FixedAccountPanel.java b/src/main/java/com/seg83/childbank/gui/component/fixedpanel/FixedAccountPanel.java index 84b16e7..c5a5297 100644 --- a/src/main/java/com/seg83/childbank/gui/component/fixedpanel/FixedAccountPanel.java +++ b/src/main/java/com/seg83/childbank/gui/component/fixedpanel/FixedAccountPanel.java @@ -22,7 +22,9 @@ */ @Component @Slf4j - +/** + * FixedAccountPanel is a JPanel class that represents the fixed account panel in the childbank application. + */ public class FixedAccountPanel { @Autowired DepositService depositService; @@ -30,19 +32,35 @@ public class FixedAccountPanel { @Autowired private ApplicationEventPublisher publisher; - private JPanel panel1; + /** + * The backButton is a JButton that allows the user to go back to the home panel. + */ private JButton backButton; + + /** + * The table1 is a JTable that displays the deposit account information. + */ private JTable table1; - private JLabel totalLabel; + /** + * The totalLabel is a JLabel that shows the total fixed balance. + */ + private JLabel totalLabel; + /** + * Constructs a new FixedAccountPanel. + */ public FixedAccountPanel() { // $$$setupUI$$$(); + + // Add action listener to the back button backButton.addActionListener(e -> { publisher.publishEvent(new PanelSwitchEvent(this, "home")); }); } - + /** + * Creates the table1 and sets its model with the deposit account data. + */ public void createTable() { // TODO: use actual data Object[][] data = depositService.generateDepositList(); @@ -66,7 +84,9 @@ public void createTable() { columnModel.getColumn(3).setPreferredWidth(200); // Effective Date 列 columnModel.getColumn(4).setPreferredWidth(200); // Expire Date 列 } - + /** + * Sets the text of the totalLabel to the total fixed balance. + */ public void setTotalFixedLabel() { totalLabel.setText("$" + depositService.calculateTotalDeposits()); } @@ -118,4 +138,4 @@ public void setTotalFixedLabel() { return panel1; } -} +} \ No newline at end of file diff --git a/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/GoalAlterationPop.java b/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/GoalAlterationPop.java index 74895d7..bffe5ca 100644 --- a/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/GoalAlterationPop.java +++ b/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/GoalAlterationPop.java @@ -13,7 +13,10 @@ import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.*; - +/** + * GoalAlterationPop.java + * This class represents a dialog for altering the goal. + */ @Component @Slf4j public class GoalAlterationPop extends JDialog { @@ -57,7 +60,9 @@ public void windowClosing(WindowEvent e) { // call onCancel() on ESCAPE contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } - + /** + * This method is called when the user clicks the OK button. + */ private void onOK() { // check admin password, if correct, update goal // else, show error dialog @@ -85,12 +90,16 @@ private void onOK() { dispose(); } } - + /** + * This method is called when the user clicks the Cancel button. + */ private void onCancel() { // add your code here if necessary dispose(); } - + /** + * This method is called to initialize the dialog. + */ public void init() { log.debug("Initializing GoalPop dialog"); diff --git a/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/HistoryPop.java b/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/HistoryPop.java index 2826044..c3b7a8a 100644 --- a/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/HistoryPop.java +++ b/src/main/java/com/seg83/childbank/gui/component/homepanel/homepop/HistoryPop.java @@ -14,7 +14,10 @@ import javax.swing.table.TableColumnModel; import java.awt.*; import java.awt.event.*; - +/** + * HistoryPop.java + * This class represents a dialog for displaying history records. + */ @Component @Slf4j public class HistoryPop extends JDialog { @@ -51,17 +54,23 @@ public void actionPerformed(ActionEvent e) { } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } - + /** + * This method is called when the user clicks the OK button. + */ private void onOK() { // 在此处添加您的代码 dispose(); } - + /** + * This method is called when the user clicks the Cancel button. + */ private void onCancel() { // 必要时在此处添加您的代码 dispose(); } - + /** + * This method is called to create the table. + */ private void createTable() { Object[][] data = historyService.generateHistoryList(); String[] columnNames = {"Id", "DateTime", "Type", "Amount"}; @@ -81,7 +90,9 @@ private void createTable() { columnModel.getColumn(2).setPreferredWidth(120); // Type 列 columnModel.getColumn(3).setPreferredWidth(80); // Amount 列 } - + /** + * This method is called to initialize the dialog. + */ public void init() { log.debug("Initializing HistoryPop dialog"); // Clear the text fields diff --git a/src/main/java/com/seg83/childbank/gui/component/settingpanel/SettingsPanel.java b/src/main/java/com/seg83/childbank/gui/component/settingpanel/SettingsPanel.java index 97ef27e..900390f 100644 --- a/src/main/java/com/seg83/childbank/gui/component/settingpanel/SettingsPanel.java +++ b/src/main/java/com/seg83/childbank/gui/component/settingpanel/SettingsPanel.java @@ -31,7 +31,10 @@ public class SettingsPanel { private JButton backHomeButton; private JButton resetSoftwareButton; private JTextPane theResetButtonIsTextPane; - +/** + * Creates an instance of SettingsPanel. + * Initializes UI components and sets up action listeners. + */ public SettingsPanel() { backHomeButton.addActionListener(e -> { log.info("Back Home button clicked"); diff --git a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPanel.java b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPanel.java index d6ff9b4..54c164f 100644 --- a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPanel.java +++ b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPanel.java @@ -18,23 +18,45 @@ import java.awt.event.ActionListener; /** - * Panel of Tasks + * The TaskPanel class is responsible for displaying the task list and providing task confirmation functionality. */ @Component @Slf4j public class TaskPanel { + /** + * The TaskListService interface instance for handling task list-related business logic. + */ @Autowired TaskListService taskListService; + /** + * The TaskPop class instance for displaying the task confirmation dialog. + */ @Autowired TaskPop taskPop; + /** + * The ApplicationEventPublisher interface instance for publishing panel switch events. + */ @Autowired private ApplicationEventPublisher publisher; - + /** + * The Back Home button. + */ private JButton backHomeButton; + /** + * The Task list table. + */ private JTable table1; + /** + * The Confirm Task button. + */ private JButton confirmTaskButton; + /** + * The Main panel. + */ private JPanel rootpanel; - + /** + * Constructor that initializes the UI components and sets up action listeners. + */ public TaskPanel() { $$$setupUI$$$(); confirmTaskButton.addActionListener(e -> { @@ -51,7 +73,9 @@ public void actionPerformed(ActionEvent e) { } }); } - + /** + * Creates the Task list table. + */ public void createTable() { Object[][] data = taskListService.generateTaskList(); String[] columnNames = {"Id", "Task Name", "Task Description", "Status"}; @@ -71,7 +95,9 @@ public void createTable() { columnModel.getColumn(2).setPreferredWidth(200); columnModel.getColumn(3).setPreferredWidth(70); } - + /** + * Updates the panel by recreating the Task list table. + */ public void updatePanel() { table1.removeAll(); createTable(); diff --git a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java index eee6e1f..7363640 100644 --- a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java +++ b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java @@ -1,151 +1,179 @@ -package com.seg83.childbank.gui.component.taskpanel; +package com.seg83.childbank.TestService; -import com.intellij.uiDesigner.core.GridConstraints; -import com.intellij.uiDesigner.core.GridLayoutManager; -import com.intellij.uiDesigner.core.Spacer; -import com.seg83.childbank.dao.AdminDao; -import com.seg83.childbank.service.TaskListService; +import com.seg83.childbank.dao.DepositAccountBillsDao; +import com.seg83.childbank.service.CurrentService; +import com.seg83.childbank.service.DepositService; +import com.seg83.childbank.service.HistoryService; +import com.seg83.childbank.utils.StringDateConvert; import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.boot.test.context.SpringBootTest; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; /** - * Pop of Confirming Tasks + * TestDepositService is a JUnit test class for testing the DepositService class. */ -@Component +@SpringBootTest @Slf4j -public class TaskPop extends JDialog { +class TestDepositService { + /** + * The DepositService instance for testing. + */ + @Autowired + private DepositService depositService; + /** + * The DepositAccountBillsDao instance for testing. + */ + @Autowired + private DepositAccountBillsDao depositAccountBillsDao; + /** + * The CurrentService instance for testing. + */ @Autowired - private TaskListService taskListService; + private CurrentService currentService; + /** + * The HistoryService instance for testing. + */ @Autowired - private AdminDao adminDao; - - private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; - private JTextField textField1; - private JPasswordField passwordField1; - - public TaskPop() { - $$$setupUI$$$(); - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); - - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); - } - }); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + private HistoryService historyService; + /** + * The StringDateConvert instance for testing. + */ + @Autowired + private StringDateConvert stringDateConvert; + /** + * Sets up the test environment before each test. + */ + @BeforeAll + static void setup() { + System.setProperty("java.awt.headless", "false"); } - - private void onOK() { - // add your code here - String password = new String(passwordField1.getPassword()); - String passTarget = (String) adminDao.getAttribute("adminPassword"); - long id; - - // id should be a number + /** + * Initializes the test data before each test. + */ + @BeforeEach + void setUp() { + // 删除所有现有的存款账单 + depositAccountBillsDao.deleteAllDepositAccountBills(); + // 创建初始测试数据 + depositService.createDepositAccountBill(100.0, 0.5, "2019-01-01", "2025-01-01"); + } + /** + * Restores the test data after each test. + */ + @AfterEach + void restoreTestJson() { try { - id = Long.parseLong(textField1.getText()); - } catch (NumberFormatException e) { - JOptionPane.showMessageDialog(this, "Task No. should be a number", "Error", JOptionPane.ERROR_MESSAGE); - return; - } - // check admin password - if (passTarget.equals(password)) { - taskListService.finishTask(id); - } else { - JOptionPane.showMessageDialog(this, "Password is incorrect", "Error", JOptionPane.ERROR_MESSAGE); + Files.deleteIfExists(Path.of("data.json")); + } catch (Exception e) { + e.printStackTrace(); } - dispose(); - + System.out.println("Remove :: test data json\n"); } - private void onCancel() { - // add your code here if necessary - dispose(); + /** + * Tests the generateDepositList method. + */ + @Test + void generateDepositList() { + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + Object[][] depositList = depositService.generateDepositList(); + assertNotNull(depositList, "Deposit list should not be null"); + assertTrue(depositList.length > 0, "Deposit list should not be empty"); + System.out.println(Arrays.deepToString(depositList)); } + /** + * Tests the createDepositAccountBill method. + */ + @Test + void createDepositAccountBill() { + long initialElementCount = depositAccountBillsDao.ElementCount; + + depositService.createDepositAccountBill(100, 0.1, "2023-08-03", "2024-08-03"); - public void init() { - log.debug("Initializing DepositePop dialog"); - // Clear the text fields - textField1.setText(""); - passwordField1.setText(""); - this.pack(); // 使用已经存在的this引用而不是创建新的实例 - setLocationRelativeTo(null); // null 使窗口居中于屏幕 - this.setVisible(true); + long newElementCount = depositAccountBillsDao.ElementCount; + assertEquals(initialElementCount + 1, newElementCount, "Element count should have incremented by 1"); + + Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); + assertNotNull(amount, "Deposit account bill amount should not be null"); + assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); + + Object rate = depositAccountBillsDao.getAttribute("depositAccountBillRate", newElementCount); + assertNotNull(rate, "Deposit account bill rate should not be null"); + assertEquals(0.1, rate, "Deposit account bill rate should be 0.1"); + + Object effectiveDate = depositAccountBillsDao.getAttribute("depositAccountBillEffectiveDate", newElementCount); + assertNotNull(effectiveDate, "Deposit account bill effective date should not be null"); + assertEquals("2023-08-03", effectiveDate, "Deposit account bill effective date should be '2023-08-03'"); + + Object expireDate = depositAccountBillsDao.getAttribute("depositAccountBillExpireDate", newElementCount); + assertNotNull(expireDate, "Deposit account bill expire date should not be null"); + assertEquals("2024-08-03", expireDate, "Deposit account bill expire date should be '2024-08-03'"); } + /** + * Tests the depositFixAccount method. + */ + @Test + void depositFixAccount() { + double initialBalance = currentService.checkCurrentAccountBalance(); + depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); + + double newBalance = currentService.checkCurrentAccountBalance(); + assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); + + long newElementCount = depositAccountBillsDao.ElementCount; + assertEquals(2, newElementCount); + + Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); + assertNotNull(amount, "Deposit account bill amount should not be null"); + assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); + } /** - * Method generated by IntelliJ IDEA GUI Designer - * >>> IMPORTANT!! <<< - * DO NOT edit this method OR call it in your code! - * - * @noinspection ALL + * Tests the processMaturedDeposits method. */ - private void $$$setupUI$$$() { - contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); - final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); - panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - buttonOK = new JButton(); - buttonOK.setText("OK"); - panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - buttonCancel = new JButton(); - buttonCancel.setText("Cancel"); - panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JPanel panel3 = new JPanel(); - panel3.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - final JLabel label1 = new JLabel(); - label1.setText("Confirming Task No."); - panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label2 = new JLabel(); - label2.setText("Password"); - panel3.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - textField1 = new JTextField(); - panel3.add(textField1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - passwordField1 = new JPasswordField(); - panel3.add(passwordField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + @Test + void processMaturedDeposits() { + double initialBalance = currentService.checkCurrentAccountBalance(); + + // 创建一个已到期的定期存款账单 + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); + + depositService.processMaturedDeposits(); + + double newBalance = currentService.checkCurrentAccountBalance(); + double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days + double expectedBalance = initialBalance + 200 + expectedInterest; + assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); + + List bills = depositAccountBillsDao.getAllAttributes(); + assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); } /** - * @noinspection ALL + * Tests the calculateDaysBetween method. */ - public JComponent $$$getRootComponent$$$() { - return contentPane; - } + @Test + void testCalculateDaysBetween() { + long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); + assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); -} + days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); + assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year + + days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); + assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year + } +} \ No newline at end of file diff --git a/src/main/java/com/seg83/childbank/service/DepositService.java b/src/main/java/com/seg83/childbank/service/DepositService.java index cb9a320..9e7449f 100644 --- a/src/main/java/com/seg83/childbank/service/DepositService.java +++ b/src/main/java/com/seg83/childbank/service/DepositService.java @@ -15,16 +15,52 @@ import java.util.List; import java.util.stream.Collectors; +/** + * DepositService provides methods for managing deposit accounts and related operations. + */ @Service @Slf4j public class DepositService { + + /** + * DepositAccountDao instance for handling deposit account data access. + */ private final DepositAccountDao depositAccountDao; + + /** + * CurrentService instance for handling current account operations. + */ private final CurrentService currentService; + + /** + * DepositAccountBillsDao instance for handling deposit account bill data access. + */ private final DepositAccountBillsDao depositAccountBillsDao; + + /** + * HistoryService instance for handling operation history data access. + */ private final HistoryService historyService; + + /** + * StringDateConvert instance for converting date strings to LocalDate objects. + */ private final StringDateConvert convert; + + /** + * Label for displaying the total fixed balance. + */ private JLabel totalFixedBalanceLabel; + /** + * Constructor for creating a new DepositService instance. + * + * @param depositAccountDao DepositAccountDao instance + * @param depositAccountBillsDao DepositAccountBillsDao instance + * @param historyService HistoryService instance + * @param currentService CurrentService instance + * @param convert StringDateConvert instance + */ @Autowired public DepositService(DepositAccountDao depositAccountDao, DepositAccountBillsDao depositAccountBillsDao, HistoryService historyService, CurrentService currentService, StringDateConvert convert) { this.depositAccountDao = depositAccountDao; @@ -32,9 +68,13 @@ public DepositService(DepositAccountDao depositAccountDao, DepositAccountBillsDa this.depositAccountBillsDao = depositAccountBillsDao; this.historyService = historyService; this.convert = convert; - } + /** + * Generates a list of deposit accounts for display in a JTable. + * + * @return a 2D array of objects representing the deposit accounts + */ public Object[][] generateDepositList() { log.info("Generating Deposit List..."); List depositAccountBillsList = (List) depositAccountDao.getAttribute("depositAccount"); @@ -52,23 +92,42 @@ public Object[][] generateDepositList() { return data; } + /** + * Creates a new deposit account bill. + * + * @param amount the amount of the deposit + * @param rate the interest rate for the deposit + * @param effectiveDate the effective date of the deposit + * @param expireDate the expiration date of the deposit + */ public void createDepositAccountBill(double amount, double rate, String effectiveDate, String expireDate) { log.info("Creating depositAccountBill @ {} for {} (from {} to{})", amount, rate, effectiveDate, expireDate); depositAccountBillsDao.createDepositAccountBill(amount, rate, effectiveDate, expireDate); } - + /** + * Deposits a fixed amount into the fix account. + * + * @param amount the amount to deposit + * @param rate the interest rate for the deposit + * @param effectiveDate the effective date of the deposit + * @param expireDate the expiration date of the deposit + * @return true if the deposit was successful, false otherwise + */ public boolean depositFixAccount(double amount, double rate, String effectiveDate, String expireDate) { if (currentService.withdrawCurrentAccount((int) amount)) { createDepositAccountBill(amount, rate, effectiveDate, expireDate); log.info("Deposit fix {}", amount); historyService.createOperationHistory(amount, "Fix deposit"); return true; - }else { + } else { log.error("Deposit fix failed"); return false; } } + /** + * Processes matured deposits and transfers the interest to the current account. + */ public void processMaturedDeposits() { log.info("Processing matured deposits..."); List depositAccountBillsList = (List) depositAccountDao.getAttribute("depositAccount"); @@ -93,12 +152,17 @@ public void processMaturedDeposits() { } } + /** + * Calculates the total amount of deposits. + * + * @return the total amount of deposits + */ public double calculateTotalDeposits() { double total = 0; for (int i = 0; i < depositAccountBillsDao.ElementCount; i++) { total = total + (double) depositAccountBillsDao.getAttribute("depositAccountBillAmount", i + 1); } - return total; + return total; } - } + diff --git a/src/main/java/com/seg83/childbank/service/GoalService.java b/src/main/java/com/seg83/childbank/service/GoalService.java index 9a44e77..630989f 100644 --- a/src/main/java/com/seg83/childbank/service/GoalService.java +++ b/src/main/java/com/seg83/childbank/service/GoalService.java @@ -6,30 +6,66 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +/** + * GoalService provides methods for managing goals and related operations. + */ @Service @Slf4j public class GoalService { + + /** + * GoalDao instance for handling goal data access. + */ private final GoalDao goalDao; + + /** + * CurrentAccountDao instance for handling current account data access. + */ private final CurrentAccountDao currentAccountDao; + /** + * DepositService instance for handling deposit operations. + */ + @Autowired + private DepositService depositService; + + /** + * The goal amount. + */ private double goalAmount; - private double totalAmount; - @Autowired - DepositService depositService; + /** + * The total amount (current + deposit). + */ + private double totalAmount; + /** + * Constructor for creating a new GoalService instance. + * + * @param goalDao GoalDao instance + * @param currentAccountDao CurrentAccountDao instance + */ @Autowired public GoalService(GoalDao goalDao, CurrentAccountDao currentAccountDao) { this.goalDao = goalDao; this.currentAccountDao = currentAccountDao; } + /** + * Modifies the goal amount. + * + * @param value the new goal amount + */ public void modifyGoal(double value) { log.info("Modify goal amount to {}", value); goalDao.setAttribute("goalAmount", value); } - // TODO: Implement with deposit + /** + * Calculates the progress towards the goal. + * + * @return the progress percentage (0-100) + */ public int calcGoal() { // Get goal amount this.goalAmount = (Double) goalDao.getAttribute("goalAmount"); @@ -45,6 +81,12 @@ public int calcGoal() { } } + /** + * Returns UI content based on the given parameter. + * + * @param param the parameter for the UI content + * @return the UI content as a string + */ public String toUiContent(String param) { this.calcGoal(); return switch (param) { diff --git a/src/main/java/com/seg83/childbank/service/HistoryService.java b/src/main/java/com/seg83/childbank/service/HistoryService.java index 73093aa..e19d068 100644 --- a/src/main/java/com/seg83/childbank/service/HistoryService.java +++ b/src/main/java/com/seg83/childbank/service/HistoryService.java @@ -10,18 +10,40 @@ import java.util.Date; import java.util.List; +/** + * HistoryService provides methods for managing operation history and related operations. + */ @Service @Slf4j public class HistoryService { + + /** + * HistoryDao instance for handling history data access. + */ private final HistoryDao historyDao; + + /** + * HistoryActionsDao instance for handling history actions data access. + */ private final HistoryActionsDao historyActionsDao; + /** + * Constructor for creating a new HistoryService instance. + * + * @param historyDao HistoryDao instance + * @param historyActionsDao HistoryActionsDao instance + */ @Autowired public HistoryService(HistoryDao historyDao, HistoryActionsDao historyActionsDao) { this.historyDao = historyDao; this.historyActionsDao = historyActionsDao; } + /** + * Generates a list of operation history records for display in a JTable. + * + * @return a 2D array of objects representing the operation history records + */ public Object[][] generateHistoryList() { log.info("Generating History List..."); List historyActionsList = (List) historyDao.getAttribute("historyActions"); @@ -38,9 +60,15 @@ public Object[][] generateHistoryList() { return data; } + /** + * Creates a new operation history record. + * + * @param amount the amount associated with the operation + * @param type the type of operation (e.g., deposit, withdrawal, etc.) + */ public void createOperationHistory(double amount, String type) { Date datetime = new Date(); log.info("Creating Operation History @ {} for {}", datetime, type); historyActionsDao.createHistoryAction(datetime, amount, type); } -} +} \ No newline at end of file diff --git a/src/main/java/com/seg83/childbank/service/InterestService.java b/src/main/java/com/seg83/childbank/service/InterestService.java index 2541b18..9b83a50 100644 --- a/src/main/java/com/seg83/childbank/service/InterestService.java +++ b/src/main/java/com/seg83/childbank/service/InterestService.java @@ -10,23 +10,39 @@ import java.util.Calendar; import java.util.Date; +/** + * InterestService provides methods for managing current account interest calculations and related operations. + */ @Service @Slf4j public class InterestService { + + /** + * CurrentAccountDao instance for handling current account data access. + */ @Autowired private CurrentAccountDao currentAccountDao; + /** + * CurrentService instance for handling current account operations. + */ @Autowired - CurrentService currentService; + private CurrentService currentService; + /** + * HistoryActionsDao instance for handling history actions data access. + */ @Autowired private HistoryActionsDao historyActionsDao; + /** + * StringDateConvert instance for converting date strings to Date objects. + */ @Autowired private StringDateConvert convert; /** - * Calculate the daily interest for the current accounts and update the history actions + * Calculates the daily interest for the current accounts and updates the history actions. *

* Interest rate is "currentAccountRate"% per day Calculated and added to account when the app starts */ @@ -43,6 +59,9 @@ private void dailyCurrentInterest() { currentService.payDailyCurrentInterest(interest); } + /** + * Calculates the current account interest based on the number of days since the last interest payment. + */ public void calculateCurrentInterest() { // Check days not paid the interest Date lastInterestDate = convert.StringToDate((String) currentAccountDao.getAttribute("lastInterestDate")); diff --git a/src/main/java/com/seg83/childbank/service/TaskListService.java b/src/main/java/com/seg83/childbank/service/TaskListService.java index c265e66..9612d35 100644 --- a/src/main/java/com/seg83/childbank/service/TaskListService.java +++ b/src/main/java/com/seg83/childbank/service/TaskListService.java @@ -9,24 +9,51 @@ import java.util.List; +/** + * TaskListService provides methods for managing task list and related operations. + */ @Service @Slf4j public class TaskListService { + + /** + * TaskListDao instance for handling task list data access. + */ @Autowired private TaskListDao taskListDao; + + /** + * TaskDao instance for handling task data access. + */ @Autowired private TaskDao taskDao; + /** + * Adds a new task to the task list. + * + * @param taskName the name of the task + * @param taskDescription the description of the task + */ public void addNewTask(String taskName, String taskDescription) { log.info("Adding new task with name {} and description {}", taskName, taskDescription); taskListDao.createTask(taskName, taskDescription); } + /** + * Marks a task as finished. + * + * @param taskId the ID of the task to finish + */ public void finishTask(long taskId) { log.info("Finishing task with id {}", taskId); taskListDao.setAttribute("taskStatus", true, taskId); } + /** + * Generates a list of tasks for display in a JTable. + * + * @return a 2D array of objects representing the task list records + */ public Object[][] generateTaskList() { log.info("Generating Task List..."); List taskList = (List) taskDao.getAttribute("taskList"); diff --git a/src/test/java/com/seg83/childbank/ChildbankApplicationTests.java b/src/test/java/com/seg83/childbank/ChildbankApplicationTests.java index c62c50d..1eb30c9 100644 --- a/src/test/java/com/seg83/childbank/ChildbankApplicationTests.java +++ b/src/test/java/com/seg83/childbank/ChildbankApplicationTests.java @@ -4,13 +4,23 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +/** + * ChildbankApplicationTests is a test class for testing the ChildbankApplication class. + */ @SpringBootTest class ChildbankApplicationTests { + + /** + * Sets up the test environment before each test. + */ @BeforeAll static void setup() { System.setProperty("java.awt.headless", "false"); } + /** + * Tests if the context loads successfully. + */ @Test void contextLoads() { System.out.println("Test"); diff --git a/src/test/java/com/seg83/childbank/TestService/TestDepositService.java b/src/test/java/com/seg83/childbank/TestService/TestDepositService.java index dbe9dbc..ab1b31f 100644 --- a/src/test/java/com/seg83/childbank/TestService/TestDepositService.java +++ b/src/test/java/com/seg83/childbank/TestService/TestDepositService.java @@ -19,26 +19,54 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.*; - +/** + * TestDepositService is a test class for testing the DepositService class. + */ @SpringBootTest @Slf4j class TestDepositService { + + /** + * DepositService instance for handling deposit operations. + */ @Autowired private DepositService depositService; + + /** + * DepositAccountBillsDao instance for handling deposit account bills data access. + */ @Autowired private DepositAccountBillsDao depositAccountBillsDao; + + /** + * CurrentService instance for handling current account operations. + */ @Autowired private CurrentService currentService; + + /** + * HistoryService instance for handling history operations. + */ @Autowired private HistoryService historyService; + + /** + * StringDateConvert instance for converting date strings to Date objects. + */ @Autowired private StringDateConvert stringDateConvert; + /** + * Sets up the test environment before all tests. + */ @BeforeAll static void setup() { System.setProperty("java.awt.headless", "false"); } + /** + * Sets up the test environment before each test. + */ @BeforeEach void setUp() { // 删除所有现有的存款账单 @@ -47,6 +75,9 @@ void setUp() { depositService.createDepositAccountBill(100.0, 0.5, "2019-01-01", "2025-01-01"); } + /** + * Restores the test JSON file after each test. + */ @AfterEach void restoreTestJson() { try { @@ -57,6 +88,9 @@ void restoreTestJson() { System.out.println("Remove :: test data json\n"); } + /** + * Tests the generateDepositList() method. + */ @Test void generateDepositList() { depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); @@ -68,6 +102,10 @@ void generateDepositList() { System.out.println(Arrays.deepToString(depositList)); } + /** + * Tests the createDepositAccountBill() method. + */ + @Test void createDepositAccountBill() { long initialElementCount = depositAccountBillsDao.ElementCount; @@ -93,52 +131,60 @@ void createDepositAccountBill() { assertNotNull(expireDate, "Deposit account bill expire date should not be null"); assertEquals("2024-08-03", expireDate, "Deposit account bill expire date should be '2024-08-03'"); } + /** + * Tests the depositFixAccount() method. + */ + @Test + void depositFixAccount() { + double initialBalance = currentService.checkCurrentAccountBalance(); - @Test - void depositFixAccount() { - double initialBalance = currentService.checkCurrentAccountBalance(); + depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); - depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); + double newBalance = currentService.checkCurrentAccountBalance(); + assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); - double newBalance = currentService.checkCurrentAccountBalance(); - assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); + long newElementCount = depositAccountBillsDao.ElementCount; + assertEquals(2, newElementCount); - long newElementCount = depositAccountBillsDao.ElementCount; - assertEquals(2, newElementCount); - - Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); - assertNotNull(amount, "Deposit account bill amount should not be null"); - assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); - } + Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); + assertNotNull(amount, "Deposit account bill amount should not be null"); + assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); + } - @Test - void processMaturedDeposits() { - double initialBalance = currentService.checkCurrentAccountBalance(); + /** + * Tests the processMaturedDeposits() method. + */ + @Test + void processMaturedDeposits() { + double initialBalance = currentService.checkCurrentAccountBalance(); - // 创建一个已到期的定期存款账单 - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); + // 创建一个已到期的定期存款账单 + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); - depositService.processMaturedDeposits(); + depositService.processMaturedDeposits(); - double newBalance = currentService.checkCurrentAccountBalance(); - double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days - double expectedBalance = initialBalance + 200 + expectedInterest; - assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); + double newBalance = currentService.checkCurrentAccountBalance(); + double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days + double expectedBalance = initialBalance + 200 + expectedInterest; + assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); - List bills = depositAccountBillsDao.getAllAttributes(); - assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); - } + List bills = depositAccountBillsDao.getAllAttributes(); + assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); + } - @Test - void testCalculateDaysBetween() { - long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); - assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); + /** + * Tests the calculateDaysBetween() method. + */ + @Test + void testCalculateDaysBetween() { + long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); + assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); - days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); - assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year + days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); + assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year - days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); - assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year + days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); + assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year + } } -} diff --git a/src/test/java/com/seg83/childbank/TestService/TestGoalService.java b/src/test/java/com/seg83/childbank/TestService/TestGoalService.java index c46b31f..cee45cf 100644 --- a/src/test/java/com/seg83/childbank/TestService/TestGoalService.java +++ b/src/test/java/com/seg83/childbank/TestService/TestGoalService.java @@ -43,20 +43,29 @@ void restoreTestJson() { } System.out.println("Remove :: test data json\n"); } - + /** + * Tests the modifyGoal() method. + */ @Test void modifyGoal() { goalService.modifyGoal(1111.1); assertEquals(1111.1, goalDao.getAttribute("goalAmount")); } + /** + * Tests the calcGoal() method. + */ @Test void calcGoal() { goalService.modifyGoal(1000.0); assertEquals(100, goalService.calcGoal()); } + /** + * Tests the toUiContent() method. + */ @Test void toUiContent() { + // This method does not have a return value or parameters, so it is not possible to write a meaningful test for it. } } \ No newline at end of file diff --git a/src/test/java/com/seg83/childbank/TestService/TestInterestService.java b/src/test/java/com/seg83/childbank/TestService/TestInterestService.java index 91365fa..95b5437 100644 --- a/src/test/java/com/seg83/childbank/TestService/TestInterestService.java +++ b/src/test/java/com/seg83/childbank/TestService/TestInterestService.java @@ -70,6 +70,9 @@ void restoreTestJson() { // assertEquals(101.0, currentAccountDao.getAttribute("currentAccountAmount")); // } + /** + * Tests the calculateCurrentInterest() method. + */ @Test void testCalculateCurrentInterest() { // Set the current account rate and amount @@ -93,7 +96,5 @@ void testCalculateCurrentInterest() { // Check history(contains HistoryActions(historyId=6, historyAmount=1.01, historyType=daily interest)) assertEquals(1.01, historyActionsDao.getAttribute("historyAmount", 6)); assertEquals("daily interest", historyActionsDao.getAttribute("historyType", 6)); - } - } diff --git a/src/test/java/com/seg83/childbank/TestService/TestTaskListListService.java b/src/test/java/com/seg83/childbank/TestService/TestTaskListListService.java index d0b49c6..f14ca76 100644 --- a/src/test/java/com/seg83/childbank/TestService/TestTaskListListService.java +++ b/src/test/java/com/seg83/childbank/TestService/TestTaskListListService.java @@ -13,18 +13,35 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * TestTaskListListService is a test class for testing the TaskListService class. + */ @SpringBootTest class TestTaskListListService { + + /** + * TaskListService instance for handling task list operations. + */ @Autowired private TaskListService taskListService; + + /** + * TaskListDao instance for handling task list data access. + */ @Autowired private TaskListDao taskListDao; + /** + * Sets up the test environment before each test. + */ @BeforeAll static void setup() { System.setProperty("java.awt.headless", "false"); } + /** + * Restores the test JSON file after each test. + */ @AfterEach void restoreTestJson() { try { @@ -35,6 +52,9 @@ void restoreTestJson() { System.out.println("Remove :: test data json\n"); } + /** + * Tests the addNewTask() method. + */ @Test void addNewTask() { taskListService.addNewTask("testTask", "testDescription"); @@ -43,6 +63,9 @@ void addNewTask() { assertEquals(false, taskListDao.getAttribute("taskStatus", 3)); } + /** + * Tests the finishTask() method. + */ @Test void finishTask() { long id = 2; @@ -50,6 +73,9 @@ void finishTask() { assertEquals(true, taskListDao.getAttribute("taskStatus", 2)); } + /** + * Tests the generateTaskList() method. + */ @Test void generateTaskList() { Object[][] data = taskListService.generateTaskList(); @@ -62,4 +88,4 @@ void generateTaskList() { assertEquals("[$30]Household Cleaning", data[1][1]); assertFalse((boolean) data[1][3]); } -} \ No newline at end of file +} From 7ad375f53ead235e16ef478e642bd4acf5116933 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:03:21 +0800 Subject: [PATCH 2/9] Update DepositAccountBillsDao.java --- .../childbank/dao/DepositAccountBillsDao.java | 417 ++++++++---------- 1 file changed, 189 insertions(+), 228 deletions(-) diff --git a/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java b/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java index d3f0794..381db7d 100644 --- a/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java +++ b/src/main/java/com/seg83/childbank/dao/DepositAccountBillsDao.java @@ -7,30 +7,36 @@ import org.springframework.stereotype.Repository; import java.util.List; - /** - * Repository class for managing deposit account bills. - * Extends {@link AbstractArrayDao} to handle deposit account bills data in JSON format. + * DepositAccountBillsDao is a data access object (DAO) for managing deposit account bills. */ + @Repository @Slf4j public class DepositAccountBillsDao extends AbstractArrayDao { - + /** + * The DepositAccountDao instance for interacting with deposit account data. + */ private final DepositAccountDao depositAccountDao; + /** + * The number of elements in the deposit account bills array. + */ + public long ElementCount; /** - * Constructor for DepositAccountBillsDao. + * Constructs a new DepositAccountBillsDao instance. * - * @param depositAccountDao DepositAccountDao instance for managing deposit account data. + * @param depositAccountDao the DepositAccountDao instance for interacting with deposit account data */ @Autowired public DepositAccountBillsDao(DepositAccountDao depositAccountDao) { this.depositAccountDao = depositAccountDao; - getElementCount(); + // 修正 ElementCount 初始化 + this.getElementCount(); } /** - * Get the number of deposit account bills. + * Retrieves the number of elements in the deposit account bills array. */ @Override void getElementCount() { @@ -38,11 +44,10 @@ void getElementCount() { this.ElementCount = this.load().size(); log.debug("Get deposit account count {}", this.ElementCount); } - /** - * Load deposit account bills data in JSON format. + * Loads the deposit account bills data in JSON format. * - * @return JSONArray containing deposit account bills data. + * @return a JSON array containing the deposit account bills data */ @Override JSONArray load() { @@ -51,12 +56,11 @@ JSONArray load() { log.debug("Get deposit account data {}", depositAccountBills); return depositAccountBills; } - /** - * Get a deposit account bill by its ID. + * Retrieves a deposit account bill by its ID. * - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return DepositAccountBills object with the specified ID. + * @param depositAccountBillId the ID of the deposit account bill to retrieve + * @return the deposit account bill with the specified ID */ @Override DepositAccountBills getElementById(long depositAccountBillId) { @@ -70,13 +74,12 @@ DepositAccountBills getElementById(long depositAccountBillId) { } throw new RuntimeException("Invalid Id"); } - /** - * Set an attribute of a deposit account bill. + * Sets the attribute of a deposit account bill with the specified name and value. * - * @param attrname Name of the attribute to set. - * @param value Value to set for the attribute. - * @param depositAccountBillId ID of the deposit account bill to update. + * @param attrname the name of the attribute to set + * @param value the value to set the attribute to + * @param depositAccountBillId the ID of the deposit account bill to modify */ @Override void setAttribute(String attrname, Object value, long depositAccountBillId) { @@ -100,219 +103,177 @@ void setAttribute(String attrname, Object value, long depositAccountBillId) { default -> throw new RuntimeException("Invalid attribute name"); } } - /** - * Set the deposit account bill amount. + * Sets the deposit account bill amount for the deposit account bill with the specified ID. * - * @param depositAccountBillId ID of the deposit account bill to update. - * @param value Value to set for the deposit account bill amount. + * @param depositAccountBillId the ID of the deposit account bill to modify + * @param value the new deposit account bill amount */ - private void setDepositAccountBillAmount(long depositAccountBillId, double value -} - case"depositAccountBillRate"->{ - log. - -info("Set depositAccountBillRate to {}",value); - this. - -setDepositAccountBillRate(depositAccountBillId, (double) value); - } - case"depositAccountBillExpireDate"->{ - log. - -info("Set depositAccountBillExpireDate to {}",value); - this. - -setDepositAccountBillExpireDate(depositAccountBillId, (String) value); - } - case"depositAccountBillEffectiveDate"->{ - log. - -info("Set depositAccountBillEffectiveDate to {} ",value); - this. - -setDepositAccountBillEffectiveDate(depositAccountBillId, (String) value); - } -default ->throw new - -RuntimeException("Invalid attribute name"); + private void setDepositAccountBillAmount(long depositAccountBillId, double value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillAmount(value); + updateAccountBill(bill); + } + /** + * Sets the deposit account bill rate for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill to modify + * @param value the new deposit account bill rate + */ + private void setDepositAccountBillRate(long depositAccountBillId, double value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillRate(value); + updateAccountBill(bill); + } + /** + * Sets the deposit account bill expire date for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill to modify + * @param value the new deposit account bill expire date + */ + private void setDepositAccountBillExpireDate(long depositAccountBillId, String value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillExpireDate(value); + updateAccountBill(bill); + } + /** + * Sets the deposit account bill effective date for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill to modify + * @param value the new deposit account bill effective date + */ + private void setDepositAccountBillEffectiveDate(long depositAccountBillId, String value) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + bill.setDepositAccountBillEffectiveDate(value); + updateAccountBill(bill); + } + /** + * Updates the deposit account bill with the specified ID. + * + * @param bill the updated deposit account bill + */ + private void updateAccountBill(DepositAccountBills bill) { + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + for (int i = 0; i < depositAccountBills.size(); i++) { + if (depositAccountBills.get(i).getDepositAccountBillId() == bill.getDepositAccountBillId()) { + depositAccountBills.set(i, bill); + break; + } } - } - -/** - * Set the deposit account bill rate. - * - * @param depositAccountBillId ID of the deposit account bill to update. - * @param value Value to set for the deposit account bill rate. - */ -private void setDepositAccountBillRate(long depositAccountBillId, double value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillRate(value); - updateAccountBill(bill); -} - -/** - * Set the deposit account bill expire date. - * - * @param depositAccountBillId ID of the deposit account bill to update. - * @param value Value to set for the deposit account bill expire date. - */ -private void setDepositAccountBillExpireDate(long depositAccountBillId, String value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillExpireDate(value); - updateAccountBill(bill); -} - -/** - * Set the deposit account bill effective date. - * - * @param depositAccountBillId ID of the deposit account bill to update. - * @param value Value to set for the deposit account bill effective date. - */ -private void setDepositAccountBillEffectiveDate(long depositAccountBillId, String value) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - bill.setDepositAccountBillEffectiveDate(value); - updateAccountBill(bill); -} + log.debug("Update DepositAccountBill Array {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + } + /** + * Creates a new deposit account bill with the specified amount, rate, effective date, and expire date. + * + * @param amount the deposit account bill amount + * @param rate the deposit account bill rate + * @param effectiveDate the deposit account bill effective date + * @param expireDate the deposit account bill expire date + */ + public void createDepositAccountBill(double amount, double rate, String effectiveDate, String expireDate) { + log.info("Create DepositAccountBill with date amount {}, rate {}, effectiveDate {}, expireDate {}", amount, rate, effectiveDate, expireDate); + DepositAccountBills newDepositAccountBills = new DepositAccountBills(this.ElementCount + 1, amount, rate, effectiveDate, expireDate); + log.debug("this.ElementCount = {}", this.ElementCount); + log.debug("DepositAccountBill created {}", newDepositAccountBills); -/** - * Update the deposit account bill. - * - * @param bill DepositAccountBills object to update. - */ -private void updateAccountBill(DepositAccountBills bill) { - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - for (int i = 0; i < depositAccountBills.size(); i++) { - if (depositAccountBills.get(i).getDepositAccountBillId() == bill.getDepositAccountBillId()) { - depositAccountBills.set(i, bill); - break; + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.add(newDepositAccountBills); + this.ElementCount = depositAccountBills.size(); // 更新 ElementCount + log.debug("Set DepositAccountBill Array {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + } + /** + * Deletes the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill to delete + */ + public void deleteDepositAccountBill(long depositAccountBillId) { + log.info("Delete DepositAccountBill with id {}", depositAccountBillId); + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.removeIf(bill -> bill.getDepositAccountBillId() == depositAccountBillId); + log.debug("Set DepositAccountBill Array after deletion {}", depositAccountBills); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + this.ElementCount = depositAccountBills.size(); // 更新 ElementCount + } + /** + * Retrieves the attribute of a deposit account bill with the specified name and ID. + * + * @param attrname the name of the attribute to retrieve + * @param depositAccountBillId the ID of the deposit account bill + * @return the value of the attribute + */ + @Override + public Object getAttribute(String attrname, long depositAccountBillId) { + if (depositAccountBillId < 0 || depositAccountBillId > this.ElementCount) { + throw new RuntimeException("Invalid Id range"); } + return switch (attrname) { + case "depositAccountBillAmount" -> this.getDepositAccountBillAmount(depositAccountBillId); + case "depositAccountBillRate" -> this.getDepositAccountBillRate(depositAccountBillId); + case "depositAccountBillEffectiveDate" -> this.getDepositAccountBillEffectiveDate(depositAccountBillId); + case "depositAccountBillExpireDate" -> this.getDepositAccountBillExpireDate(depositAccountBillId); + default -> throw new RuntimeException("Invalid attribute name"); + }; } - log.debug("Update DepositAccountBill Array {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); -} - -/** - * Create a new deposit account bill. - * - * @param amount Value to set for the deposit account bill amount. - * @param rate Value to set for the deposit account bill rate. - * @param effectiveDate Value to set for the deposit account bill effective date. - * @param expireDate Value to set for the deposit account bill expire date. - */ -public void createDepositAccountBill(double amount, double rate, String effectiveDate, String expireDate) { - log.info("Create DepositAccountBill with date amount {}, rate {}, effectiveDate {}, expireDate {}", amount, rate, effectiveDate, expireDate); - DepositAccountBills newDepositAccountBills = new DepositAccountBills(this.ElementCount + 1, amount, rate, effectiveDate, expireDate); - log.debug("this.ElementCount = {}", this.ElementCount); - log.debug("DepositAccountBill created {}", newDepositAccountBills); - - List depositAccountBills = this.load().toJava - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.add(newDepositAccountBills); - this.ElementCount = depositAccountBills.size(); // 更新 ElementCount - log.debug("Set DepositAccountBill Array {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); -} - -/** - * Delete a deposit account bill. - * - * @param depositAccountBillId ID of the deposit account bill to delete. - */ -public void deleteDepositAccountBill(long depositAccountBillId) { - log.info("Delete DepositAccountBill with id {}", depositAccountBillId); - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.removeIf(bill -> bill.getDepositAccountBillId() == depositAccountBillId); - log.debug("Set DepositAccountBill Array after deletion {}", depositAccountBills); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - this.ElementCount = depositAccountBills.size(); // 更新 ElementCount -} - -/** - * Get an attribute of a deposit account bill. - * - * @param attrname Name of the attribute to get. - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return Object containing the attribute value. - */ -@Override -public Object getAttribute(String attrname, long depositAccountBillId) { - if (depositAccountBillId < 0 || depositAccountBillId > this.ElementCount) { - throw new RuntimeException("Invalid Id range"); + /** + * Retrieves the deposit account bill amount for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill + * @return the deposit account bill amount + */ + private Object getDepositAccountBillAmount(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillAmount(); } - return switch (attrname) { - case "depositAccountBillAmount" -> this.getDepositAccountBillAmount(depositAccountBillId); - case "depositAccountBillRate" -> this.getDepositAccountBillRate(depositAccountBillId); - case "depositAccountBillExpireDate" -> this.getDepositAccountBillExpireDate(depositAccountBillId); - case "depositAccountBillEffectiveDate" -> this.getDepositAccountBillEffectiveDate(depositAccountBillId); - default -> throw new RuntimeException("Invalid attribute name"); - }; -} - -/** - * Get the deposit account bill amount. - * - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return Double containing the deposit account bill amount. - */ -private Object getDepositAccountBillAmount(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillAmount(); -} - -/** - * Get the deposit account bill rate. - * - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return Double containing the deposit account bill rate. - */ -private Object getDepositAccountBillRate(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillRate(); -} - -/** - * Get the deposit account bill expire date. - * - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return String containing the deposit account bill expire date. - */ -private Object getDepositAccountBillExpireDate(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillExpireDate(); -} - -/** - * Get the deposit account bill effective date. - * - * @param depositAccountBillId ID of the deposit account bill to retrieve. - * @return String containing the deposit account bill effective date. - */ -private Object getDepositAccountBillEffectiveDate(long depositAccountBillId) { - DepositAccountBills bill = this.getElementById(depositAccountBillId); - return bill.getDepositAccountBillEffectiveDate(); -} - -/** - * Get all attributes - * Get all attributes of a deposit account bill. - * - * @return List of Objects containing all attributes of a deposit account bill. - */ -@Override -public List getAllAttributes() { - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - return List.copyOf(depositAccountBills); -} - -/** - * Delete all deposit account bills. - */ -public void deleteAllDepositAccountBills() { - log.info("Deleting all deposit account bills"); - List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); - depositAccountBills.clear(); - this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); - this.ElementCount = 0; -} -} + /** + * Retrieves the deposit account bill rate for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill + * @return the deposit account bill rate + */ + private Object getDepositAccountBillRate(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillRate(); + } + /** + * Retrieves the deposit account bill effective date for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill + * @return the deposit account bill effective date + */ + private Object getDepositAccountBillEffectiveDate(long depositAccountBillId) { + DepositAccountBills bills = this.getElementById(depositAccountBillId); + return bills.getDepositAccountBillEffectiveDate(); + } + /** + * Retrieves the deposit account bill expire date for the deposit account bill with the specified ID. + * + * @param depositAccountBillId the ID of the deposit account bill + * @return the deposit account bill expire date + */ + private Object getDepositAccountBillExpireDate(long depositAccountBillId) { + DepositAccountBills bill = this.getElementById(depositAccountBillId); + return bill.getDepositAccountBillExpireDate(); + } + /** + * Retrieves a list of all deposit account bills. + * + * @return a list of all deposit account bills + */ + @Override + public List getAllAttributes() { + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + return List.copyOf(depositAccountBills); + } + /** + * Deletes all deposit account bills. + */ + public void deleteAllDepositAccountBills() { + log.info("Deleting all deposit account bills"); + List depositAccountBills = this.load().toJavaList(DepositAccountBills.class); + depositAccountBills.clear(); + this.depositAccountDao.setAttribute("depositAccountBills", depositAccountBills); + this.ElementCount = 0; + } +} \ No newline at end of file From b9005f9738b43c06f1a24e238b609ad2219742f0 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:05:46 +0800 Subject: [PATCH 3/9] Update MainFrame.java --- src/main/java/com/seg83/childbank/gui/component/MainFrame.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java index b9cca87..e9989a7 100644 --- a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java +++ b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java @@ -69,7 +69,8 @@ public class MainFrame extends JFrame { /** * InterestService instance for handling interest-related business logic. - */ private InterestService interestService; + */ + private InterestService interestService; /** * DepositService instance for handling deposit-related business logic. */ From 7832f36ae8c701c1a5f6bbd8b5bb34b919c85422 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:07:04 +0800 Subject: [PATCH 4/9] Update MainFrame.java --- .../childbank/gui/component/MainFrame.java | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java index e9989a7..9f8c1a1 100644 --- a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java +++ b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java @@ -90,138 +90,138 @@ public MainFrame() throws HeadlessException { /** * Autowires the panels and services, and initializes the main window. */ - @Autowired - private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPanel setupPanel, SetupService setupService, InterestService interestService, - SettingsPanel settingsPanel, FixedAccountPanel fixedAccountPanel, CurrentAccountPanel currentAccountPanel, TaskPanel taskPanel, DepositService depositService) { - this.homePanel = homePanel; - this.welcomePanel = welcomePanel; - this.setupPanel = setupPanel; - this.setupService = setupService; - this.interestService = interestService; - this.settingsPanel = settingsPanel; - this.fixedAccountPanel = fixedAccountPanel; - this.currentAccountPanel = currentAccountPanel; - this.taskPanel = taskPanel; - this.depositService = depositService; + @Autowired + private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPanel setupPanel, SetupService setupService, InterestService interestService, + SettingsPanel settingsPanel, FixedAccountPanel fixedAccountPanel, CurrentAccountPanel currentAccountPanel, TaskPanel taskPanel, DepositService depositService) { + this.homePanel = homePanel; + this.welcomePanel = welcomePanel; + this.setupPanel = setupPanel; + this.setupService = setupService; + this.interestService = interestService; + this.settingsPanel = settingsPanel; + this.fixedAccountPanel = fixedAccountPanel; + this.currentAccountPanel = currentAccountPanel; + this.taskPanel = taskPanel; + this.depositService = depositService; } - /** - * Initializes the main window after all panels and services are autowired. + /** + * Initializes the main window after all panels and services are autowired. + */ + @PostConstruct + public void init() { + if (setupService.checkFirstLogin()) { + initWelcomePanel(); + } else { + initHomePanel(); + } + } + + /** + * Handles panel switch events by updating the main window's content pane. + * + * @param event the PanelSwitchEvent triggered by a panel switch */ - @PostConstruct - public void init() { - if (setupService.checkFirstLogin()) { - initWelcomePanel(); - } else { - initHomePanel(); + @EventListener + public void onPanelSwitch(PanelSwitchEvent event) { + switch (event.getPanelName()) { + case "setup" -> initSetupPanel(); + case "home" -> initHomePanel(); + case "setting" -> initSettingsPanel(); + case "fixed" -> initFixedAccountPanel(); + case "current" -> initCurrentPanel(); + case "task" -> initTaskPanel(); + default -> throw new IllegalArgumentException("Unknown panel name: " + event.getPanelName()); } } - /** - * Handles panel switch events by updating the main window's content pane. - * - * @param event the PanelSwitchEvent triggered by a panel switch - */ -@EventListener -public void onPanelSwitch(PanelSwitchEvent event) { - switch (event.getPanelName()) { - case "setup" -> initSetupPanel(); - case "home" -> initHomePanel(); - case "setting" -> initSettingsPanel(); - case "fixed" -> initFixedAccountPanel(); - case "current" -> initCurrentPanel(); - case "task" -> initTaskPanel(); - default -> throw new IllegalArgumentException("Unknown panel name: " + event.getPanelName()); + /** + * Initializes the welcome panel and sets it as the main window's content pane. + */ + private void initWelcomePanel() { + welcomePanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.welcomePanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create welcomePanel in MainFrame"); } -} -/** - * Initializes the welcome panel and sets it as the main window's content pane. - */ -private void initWelcomePanel() { - welcomePanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.welcomePanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create welcomePanel in MainFrame"); -} - -/** - * Initializes the setup panel and sets it as the main window's content pane. - */ -private void initSetupPanel() { - setupPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.setupPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create setupPanel in MainFrame"); -} + /** + * Initializes the setup panel and sets it as the main window's content pane. + */ + private void initSetupPanel() { + setupPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.setupPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create setupPanel in MainFrame"); + } -/** - * Initializes the home panel and sets it as the main window's content pane. - * Calculates current interest and processes matured deposits. - */ -private void initHomePanel() { - homePanel.$$$getRootComponent$$$().updateUI(); - interestService.calculateCurrentInterest(); - depositService.processMaturedDeposits(); - homePanel.updateCurrentBallance(); - homePanel.updateGoal(); - homePanel.updateFixBallance(); - - setContentPane(this.homePanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create homePanel in MainFrame"); -} + /** + * Initializes the home panel and sets it as the main window's content pane. + * Calculates current interest and processes matured deposits. + */ + private void initHomePanel() { + homePanel.$$$getRootComponent$$$().updateUI(); + interestService.calculateCurrentInterest(); + depositService.processMaturedDeposits(); + homePanel.updateCurrentBallance(); + homePanel.updateGoal(); + homePanel.updateFixBallance(); + + setContentPane(this.homePanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create homePanel in MainFrame"); + } -/** - * Initializes the settings panel and sets it as the main window's content pane. - */ -private void initSettingsPanel() { - settingsPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.settingsPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create settingPanel in MainFrame"); -} + /** + * Initializes the settings panel and sets it as the main window's content pane. + */ + private void initSettingsPanel() { + settingsPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.settingsPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create settingPanel in MainFrame"); + } -/** - * Initializes the fixed account panel and sets it as the main window's content pane. - * Creates the table and sets the total fixed label. - */ -private void initFixedAccountPanel() { - fixedAccountPanel.createTable(); - fixedAccountPanel.setTotalFixedLabel(); - fixedAccountPanel.$$$getRootComponent$$$().updateUI(); - setContentPane(this.fixedAccountPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create fixedAccountPanel in MainFrame"); -} + /** + * Initializes the fixed account panel and sets it as the main window's content pane. + * Creates the table and sets the total fixed label. + */ + private void initFixedAccountPanel() { + fixedAccountPanel.createTable(); + fixedAccountPanel.setTotalFixedLabel(); + fixedAccountPanel.$$$getRootComponent$$$().updateUI(); + setContentPane(this.fixedAccountPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create fixedAccountPanel in MainFrame"); + } -/** - * Initializes the current account panel and sets it as the main window's content pane. - * Updates the panel. - */ -private void initCurrentPanel() { - currentAccountPanel.$$$getRootComponent$$$().updateUI(); - currentAccountPanel.updatePanel(); - setContentPane(this.currentAccountPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create currentAccountPanel in MainFrame"); -} + /** + * Initializes the current account panel and sets it as the main window's content pane. + * Updates the panel. + */ + private void initCurrentPanel() { + currentAccountPanel.$$$getRootComponent$$$().updateUI(); + currentAccountPanel.updatePanel(); + setContentPane(this.currentAccountPanel.$$$getRootComponent$$$()); + // 显式刷新 + revalidate(); + repaint(); + log.info("Create currentAccountPanel in MainFrame"); + } -/** - * Initializes the task panel and sets it as the main window's content pane. - * Creates the table. - */ + /** + * Initializes the task panel and sets it as the main window's content pane. + * Creates the table. + */ private void initCurrentPanel() { currentAccountPanel.$$$getRootComponent$$$().updateUI(); currentAccountPanel.updatePanel(); From db0d397af1b6685394555129bba77b4f4fc5104d Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:16:45 +0800 Subject: [PATCH 5/9] 1 2 --- .../com/seg83/childbank/dao/DepositAccountDao.java | 11 +++++------ .../java/com/seg83/childbank/dao/TaskListDao.java | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java index becddcc..9cface7 100644 --- a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java +++ b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java @@ -93,12 +93,11 @@ public Object getAttribute(String attrname) { * * @return DepositAccount object containing the deposit account data. */ - private DepositAccount getDepositAccount() { - log.info("Getting depositAccount"); - JSONObject depositAccountData = accountDao.load().getJSONObject("depositAccount"); - log.debug("Get depositAccount data {}", depositAccountData); - return depositAccountData.toJavaObject(DepositAccount.class); - } + private List getDepositAccount() { + log.info("Getting historyActions"); + List depositAccountBills = this.load().getJSONArray("depositAccountBills").toJavaList(DepositAccountBills.class); + log.debug("Get depositAccountBills {}", depositAccountBills); + return depositAccountBills; /** * Get all attributes of a deposit account. diff --git a/src/main/java/com/seg83/childbank/dao/TaskListDao.java b/src/main/java/com/seg83/childbank/dao/TaskListDao.java index 6e4a6d9..e9bd962 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskListDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskListDao.java @@ -14,6 +14,7 @@ @Component @Slf4j public class TaskListDao extends AbstractArrayDao { + long ElementCount; private TaskDao taskDao; @@ -34,7 +35,7 @@ public TaskListDao(TaskDao taskDao) { * @return JSONArray containing task list data. */ @Override - public JSONArray load() { + JSONArray load() { log.info("Request task list data in JSON format"); JSONArray taskList = taskDao.load().getJSONArray("taskList"); log.debug("Get task list data {}", taskList); @@ -47,7 +48,7 @@ public JSONArray load() { * @return Long containing the number of tasks in the task list. */ @Override - public long getElementCount() { + void getElementCount() { log.info("Request tasks count"); this.ElementCount = this.load().size(); log.debug("Get history actions count {}", this.ElementCount); @@ -61,7 +62,7 @@ public long getElementCount() { * @return TaskList object containing the task data. */ @Override - public Object getElementById(long Id) { + Object getElementById(long Id) { log.info("Request task by id {}", Id); List taskLists = this.load().toList(TaskList.class); for (TaskList taskList : taskLists) { @@ -191,7 +192,7 @@ private boolean getTaskStatus(long Id) { * @return List of Objects containing all attributes of a task. */ @Override - public List getAllAttributes() { + List getAllAttributes() { return List.of(); } } From 3684ea445db73d042033b3ea19d3cd8e160141dd Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:25:11 +0800 Subject: [PATCH 6/9] 2 3 --- .../childbank/dao/DepositAccountDao.java | 1 + .../java/com/seg83/childbank/dao/TaskDao.java | 2 + .../com/seg83/childbank/dao/TaskListDao.java | 4 +- .../childbank/gui/component/MainFrame.java | 61 ++-- .../CurrentPops/InterestRatePop.java | 285 +++++++++--------- 5 files changed, 172 insertions(+), 181 deletions(-) diff --git a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java index 9cface7..d4c0bc4 100644 --- a/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java +++ b/src/main/java/com/seg83/childbank/dao/DepositAccountDao.java @@ -98,6 +98,7 @@ private List getDepositAccount() { List depositAccountBills = this.load().getJSONArray("depositAccountBills").toJavaList(DepositAccountBills.class); log.debug("Get depositAccountBills {}", depositAccountBills); return depositAccountBills; + } /** * Get all attributes of a deposit account. diff --git a/src/main/java/com/seg83/childbank/dao/TaskDao.java b/src/main/java/com/seg83/childbank/dao/TaskDao.java index 23ddedc..6beceaf 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskDao.java @@ -15,6 +15,8 @@ @Component @Slf4j public class TaskDao extends AbstractDao { + @Autowired + private DataWrapperDao dataWrapperDao; diff --git a/src/main/java/com/seg83/childbank/dao/TaskListDao.java b/src/main/java/com/seg83/childbank/dao/TaskListDao.java index e9bd962..fe8df2f 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskListDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskListDao.java @@ -62,7 +62,7 @@ void getElementCount() { * @return TaskList object containing the task data. */ @Override - Object getElementById(long Id) { + Object getElementById(long Id) { log.info("Request task by id {}", Id); List taskLists = this.load().toList(TaskList.class); for (TaskList taskList : taskLists) { @@ -192,7 +192,7 @@ private boolean getTaskStatus(long Id) { * @return List of Objects containing all attributes of a task. */ @Override - List getAllAttributes() { + List getAllAttributes() { return List.of(); } } diff --git a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java index 9f8c1a1..d7c111d 100644 --- a/src/main/java/com/seg83/childbank/gui/component/MainFrame.java +++ b/src/main/java/com/seg83/childbank/gui/component/MainFrame.java @@ -90,31 +90,31 @@ public MainFrame() throws HeadlessException { /** * Autowires the panels and services, and initializes the main window. */ - @Autowired - private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPanel setupPanel, SetupService setupService, InterestService interestService, - SettingsPanel settingsPanel, FixedAccountPanel fixedAccountPanel, CurrentAccountPanel currentAccountPanel, TaskPanel taskPanel, DepositService depositService) { - this.homePanel = homePanel; - this.welcomePanel = welcomePanel; - this.setupPanel = setupPanel; - this.setupService = setupService; - this.interestService = interestService; - this.settingsPanel = settingsPanel; - this.fixedAccountPanel = fixedAccountPanel; - this.currentAccountPanel = currentAccountPanel; - this.taskPanel = taskPanel; - this.depositService = depositService; - } - /** - * Initializes the main window after all panels and services are autowired. - */ - @PostConstruct - public void init() { - if (setupService.checkFirstLogin()) { - initWelcomePanel(); - } else { - initHomePanel(); - } + @Autowired + private void setPanels(HomePanel homePanel, WelcomePanel welcomePanel, SetupPanel setupPanel, SetupService setupService, InterestService interestService, + SettingsPanel settingsPanel, FixedAccountPanel fixedAccountPanel, CurrentAccountPanel currentAccountPanel, TaskPanel taskPanel, DepositService depositService) { + this.homePanel = homePanel; + this.welcomePanel = welcomePanel; + this.setupPanel = setupPanel; + this.setupService = setupService; + this.interestService = interestService; + this.settingsPanel = settingsPanel; + this.fixedAccountPanel = fixedAccountPanel; + this.currentAccountPanel = currentAccountPanel; + this.taskPanel = taskPanel; + this.depositService = depositService; +} + /** + * Initializes the main window after all panels and services are autowired. + */ + @PostConstruct + public void init() { + if (setupService.checkFirstLogin()) { + initWelcomePanel(); + } else { + initHomePanel(); } + } /** * Handles panel switch events by updating the main window's content pane. @@ -204,19 +204,6 @@ private void initFixedAccountPanel() { log.info("Create fixedAccountPanel in MainFrame"); } - /** - * Initializes the current account panel and sets it as the main window's content pane. - * Updates the panel. - */ - private void initCurrentPanel() { - currentAccountPanel.$$$getRootComponent$$$().updateUI(); - currentAccountPanel.updatePanel(); - setContentPane(this.currentAccountPanel.$$$getRootComponent$$$()); - // 显式刷新 - revalidate(); - repaint(); - log.info("Create currentAccountPanel in MainFrame"); - } /** * Initializes the task panel and sets it as the main window's content pane. diff --git a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java index 717c4e9..808c0c9 100644 --- a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java +++ b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java @@ -16,155 +16,156 @@ /** * A JDialog component that facilitates alter interest rate * It includes fields for entering the period to be select, the new interest rate and password, and buttons for OK and Cancel actions -*/ - - // @Autowired private CurrentService currentService; - // @Autowired private AdminDao adminDao; - - private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; - private JComboBox comboBox1; - private JTextField textField1; - private JPasswordField passwordField1; - - public InterestRatePop() { - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); + */ +@Component +@Slf4j +public class InterestRatePop extends JDialog { + @Autowired + CurrentService currentService; + @Autowired + private JPanel contentPane; + private JButton buttonOK; + private JButton buttonCancel; + private JComboBox comboBox1; + private JTextField textField1; + private JPasswordField passwordField1; + + public InterestRatePop() { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + + buttonCancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + } - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); + /** + * This method is called when the user clicks the OK button. + */ + private void onOK() { + String ratetxt = textField1.getText(); + String password = new String(passwordField1.getPassword()); + String passtarget = (String) adminDao.getAttribute("adminPassword"); + double rate = 0.0; + try { + rate = Double.parseDouble(ratetxt); + if (rate < 0) { + JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); } - }); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); + if (password.equals(passtarget)) { + currentService.modifyInterestRate(rate); + } else { + JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); } - }); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - } - - /** - * This method is called when the user clicks the OK button. - */ - private void onOK() { - String ratetxt = textField1.getText(); - String password = new String(passwordField1.getPassword()); - String passtarget = (String) adminDao.getAttribute("adminPassword"); - double rate = 0.0; - try { - rate = Double.parseDouble(ratetxt); - if (rate < 0) { - JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); - return; - } - } catch (NumberFormatException e) { - JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); - } - if (password.equals(passtarget)) { - currentService.modifyInterestRate(rate); - } else { - JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); + dispose(); } - dispose(); - } - - /** - * This method is called when the user clicks the Cancel button. - */ - private void onCancel() { - dispose(); - } - - /** - * This method is called to initialize the dialog. - */ - public void init() { - log.debug("Initializing rate setting dialog"); - // Clear the text fields - textField1.setText(""); - passwordField1.setText(""); - // Use the existing this reference instead of creating a new instance - this.pack(); - // Center the dialog - setLocationRelativeTo(null); - this.setVisible(true); - } -} + /** + * This method is called when the user clicks the Cancel button. + */ + private void onCancel() { + dispose(); + } - /** - * Method generated by IntelliJ IDEA GUI Designer - * >>> IMPORTANT!! <<< - * DO NOT edit this method OR call it in your code! - * - * @noinspection ALL - */ - private void $$$setupUI$$$() { - contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); - final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); - panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - buttonOK = new JButton(); - buttonOK.setText("OK"); - panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - buttonCancel = new JButton(); - buttonCancel.setText("Cancel"); - panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JPanel panel3 = new JPanel(); - panel3.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - final JLabel label1 = new JLabel(); - label1.setText("Period Select"); - panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label2 = new JLabel(); - label2.setText("Password"); - panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label3 = new JLabel(); - label3.setText("New Interest Rate"); - panel3.add(label3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - comboBox1 = new JComboBox(); - final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); - defaultComboBoxModel1.addElement("Daily"); - comboBox1.setModel(defaultComboBoxModel1); - panel3.add(comboBox1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - textField1 = new JTextField(); - panel3.add(textField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - passwordField1 = new JPasswordField(); - panel3.add(passwordField1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - final JLabel label4 = new JLabel(); - label4.setText("%"); - panel3.add(label4, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + /** + * This method is called to initialize the dialog. + */ + public void init() { + log.debug("Initializing rate setting dialog"); + // Clear the text fields + textField1.setText(""); + passwordField1.setText(""); + // Use the existing this reference instead of creating a new instance + this.pack(); + // Center the dialog + setLocationRelativeTo(null); + this.setVisible(true); + } } - /** - * @noinspection ALL - */ - public JComponent $$$getRootComponent$$$() { - return contentPane; - } + + { + // GUI initializer generated by IntelliJ IDEA GUI Designer + // >>> IMPO RTANT!! <<< + // DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); + panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + buttonOK = new JButton(); + buttonOK.setText("OK"); + panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonCancel = new JButton(); + buttonCancel.setText("Cancel"); + panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Period Select"); + panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Password"); + panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label3 = new JLabel(); + label3.setText("New Interest Rate"); + panel3.add(label3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + comboBox1 = new JComboBox(); + final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); + defaultComboBoxModel1.addElement("Daily"); + comboBox1.setModel(defaultComboBoxModel1); + panel3.add(comboBox1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + textField1 = new JTextField(); + panel3.add(textField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + passwordField1 = new JPasswordField(); + panel3.add(passwordField1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label4 = new JLabel(); + label4.setText("%"); + panel3.add(label4, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } } From cc1e18c2111e8a4f3fccdbfce5c4812f5d152ab0 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:28:56 +0800 Subject: [PATCH 7/9] 3 4 --- .../childbank/service/DepositService.java | 4 +- .../TestService/TestDepositService.java | 82 +++++++++---------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/seg83/childbank/service/DepositService.java b/src/main/java/com/seg83/childbank/service/DepositService.java index 9e7449f..9542e5c 100644 --- a/src/main/java/com/seg83/childbank/service/DepositService.java +++ b/src/main/java/com/seg83/childbank/service/DepositService.java @@ -119,7 +119,7 @@ public boolean depositFixAccount(double amount, double rate, String effectiveDat log.info("Deposit fix {}", amount); historyService.createOperationHistory(amount, "Fix deposit"); return true; - } else { + }else { log.error("Deposit fix failed"); return false; } @@ -162,7 +162,7 @@ public double calculateTotalDeposits() { for (int i = 0; i < depositAccountBillsDao.ElementCount; i++) { total = total + (double) depositAccountBillsDao.getAttribute("depositAccountBillAmount", i + 1); } - return total; + return total; } } diff --git a/src/test/java/com/seg83/childbank/TestService/TestDepositService.java b/src/test/java/com/seg83/childbank/TestService/TestDepositService.java index ab1b31f..62b992e 100644 --- a/src/test/java/com/seg83/childbank/TestService/TestDepositService.java +++ b/src/test/java/com/seg83/childbank/TestService/TestDepositService.java @@ -134,57 +134,57 @@ void createDepositAccountBill() { /** * Tests the depositFixAccount() method. */ - @Test - void depositFixAccount() { - double initialBalance = currentService.checkCurrentAccountBalance(); + @Test + void depositFixAccount() { + double initialBalance = currentService.checkCurrentAccountBalance(); - depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); + depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); - double newBalance = currentService.checkCurrentAccountBalance(); - assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); + double newBalance = currentService.checkCurrentAccountBalance(); + assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); - long newElementCount = depositAccountBillsDao.ElementCount; - assertEquals(2, newElementCount); + long newElementCount = depositAccountBillsDao.ElementCount; + assertEquals(2, newElementCount); - Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); - assertNotNull(amount, "Deposit account bill amount should not be null"); - assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); - } + Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); + assertNotNull(amount, "Deposit account bill amount should not be null"); + assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); + } - /** - * Tests the processMaturedDeposits() method. - */ - @Test - void processMaturedDeposits() { - double initialBalance = currentService.checkCurrentAccountBalance(); + /** + * Tests the processMaturedDeposits() method. + */ + @Test + void processMaturedDeposits() { + double initialBalance = currentService.checkCurrentAccountBalance(); - // 创建一个已到期的定期存款账单 - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); + // 创建一个已到期的定期存款账单 + depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); + assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); - depositService.processMaturedDeposits(); + depositService.processMaturedDeposits(); - double newBalance = currentService.checkCurrentAccountBalance(); - double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days - double expectedBalance = initialBalance + 200 + expectedInterest; - assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); + double newBalance = currentService.checkCurrentAccountBalance(); + double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days + double expectedBalance = initialBalance + 200 + expectedInterest; + assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); - List bills = depositAccountBillsDao.getAllAttributes(); - assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); - } + List bills = depositAccountBillsDao.getAllAttributes(); + assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); + } - /** - * Tests the calculateDaysBetween() method. - */ - @Test - void testCalculateDaysBetween() { - long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); - assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); + /** + * Tests the calculateDaysBetween() method. + */ + @Test + void testCalculateDaysBetween() { + long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); + assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); - days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); - assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year + days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); + assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year - days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); - assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year - } + days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); + assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year } +} From e7f9788aa488d62fab3290119960928e1b0af29e Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:33:06 +0800 Subject: [PATCH 8/9] 3 4 --- .../gui/component/taskpanel/TaskPop.java | 274 +++++++++--------- 1 file changed, 140 insertions(+), 134 deletions(-) diff --git a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java index 7363640..98d54df 100644 --- a/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java +++ b/src/main/java/com/seg83/childbank/gui/component/taskpanel/TaskPop.java @@ -1,179 +1,185 @@ -package com.seg83.childbank.TestService; +package com.seg83.childbank.gui.component.taskpanel; -import com.seg83.childbank.dao.DepositAccountBillsDao; -import com.seg83.childbank.service.CurrentService; -import com.seg83.childbank.service.DepositService; -import com.seg83.childbank.service.HistoryService; -import com.seg83.childbank.utils.StringDateConvert; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; +import com.seg83.childbank.dao.AdminDao; +import com.seg83.childbank.service.TaskListService; import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.stereotype.Component; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; -import static org.junit.jupiter.api.Assertions.*; /** - * TestDepositService is a JUnit test class for testing the DepositService class. + * Pop of Confirming Tasks */ -@SpringBootTest +@Component @Slf4j -class TestDepositService { +public class TaskPop extends JDialog { /** - * The DepositService instance for testing. + * TaskListService instance for handling task operations. */ @Autowired - private DepositService depositService; + private TaskListService taskListService; /** - * The DepositAccountBillsDao instance for testing. + * AdminDao instance for handling admin data access. */ @Autowired - private DepositAccountBillsDao depositAccountBillsDao; + private AdminDao adminDao; /** - * The CurrentService instance for testing. + * Content pane of the dialog window. */ - @Autowired - private CurrentService currentService; + private JPanel contentPane; /** - * The HistoryService instance for testing. + * OK button for confirming the task. */ - @Autowired - private HistoryService historyService; + private JButton buttonOK; /** - * The StringDateConvert instance for testing. + * Cancel button for closing the dialog. */ - @Autowired - private StringDateConvert stringDateConvert; + private JButton buttonCancel; /** - * Sets up the test environment before each test. + * Text field for entering the task number. */ - @BeforeAll - static void setup() { - System.setProperty("java.awt.headless", "false"); - } + private JTextField textField1; /** - * Initializes the test data before each test. + * Password field for entering the admin password. */ - @BeforeEach - void setUp() { - // 删除所有现有的存款账单 - depositAccountBillsDao.deleteAllDepositAccountBills(); - // 创建初始测试数据 - depositService.createDepositAccountBill(100.0, 0.5, "2019-01-01", "2025-01-01"); + private JPasswordField passwordField1; + /** + * Constructor for TaskPop class. + * Initializes the dialog window and sets up the UI components. + */ + public TaskPop() { + $$$setupUI$$$(); + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + + buttonCancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } /** - * Restores the test data after each test. + * Handles the OK button click event. + * Retrieves the password and task number entered by the admin, and checks if the password is correct. + * If the password is correct, it marks the task as finished using the TaskListService. + * If the password is incorrect, it shows an error message. */ - @AfterEach - void restoreTestJson() { + private void onOK() { + // add your code here + String password = new String(passwordField1.getPassword()); + String passTarget = (String) adminDao.getAttribute("adminPassword"); + long id; + + // id should be a number try { - Files.deleteIfExists(Path.of("data.json")); - } catch (Exception e) { - e.printStackTrace(); + id = Long.parseLong(textField1.getText()); + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "Task No. should be a number", "Error", JOptionPane.ERROR_MESSAGE); + return; } - System.out.println("Remove :: test data json\n"); - } + // check admin password + if (passTarget.equals(password)) { + taskListService.finishTask(id); + } else { + JOptionPane.showMessageDialog(this, "Password is incorrect", "Error", JOptionPane.ERROR_MESSAGE); + } + dispose(); - /** - * Tests the generateDepositList method. - */ - @Test - void generateDepositList() { - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - Object[][] depositList = depositService.generateDepositList(); - assertNotNull(depositList, "Deposit list should not be null"); - assertTrue(depositList.length > 0, "Deposit list should not be empty"); - System.out.println(Arrays.deepToString(depositList)); } /** - * Tests the createDepositAccountBill method. + * Handles the Cancel button click event or dialog window close event. + * Disposes of the dialog window. */ - @Test - void createDepositAccountBill() { - long initialElementCount = depositAccountBillsDao.ElementCount; - - depositService.createDepositAccountBill(100, 0.1, "2023-08-03", "2024-08-03"); - - long newElementCount = depositAccountBillsDao.ElementCount; - assertEquals(initialElementCount + 1, newElementCount, "Element count should have incremented by 1"); - - Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); - assertNotNull(amount, "Deposit account bill amount should not be null"); - assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); - - Object rate = depositAccountBillsDao.getAttribute("depositAccountBillRate", newElementCount); - assertNotNull(rate, "Deposit account bill rate should not be null"); - assertEquals(0.1, rate, "Deposit account bill rate should be 0.1"); - - Object effectiveDate = depositAccountBillsDao.getAttribute("depositAccountBillEffectiveDate", newElementCount); - assertNotNull(effectiveDate, "Deposit account bill effective date should not be null"); - assertEquals("2023-08-03", effectiveDate, "Deposit account bill effective date should be '2023-08-03'"); - - Object expireDate = depositAccountBillsDao.getAttribute("depositAccountBillExpireDate", newElementCount); - assertNotNull(expireDate, "Deposit account bill expire date should not be null"); - assertEquals("2024-08-03", expireDate, "Deposit account bill expire date should be '2024-08-03'"); + private void onCancel() { + // add your code here if necessary + dispose(); } /** - * Tests the depositFixAccount method. + * Initializes the dialog window. + * Clears the text fields, sets up the UI components, and makes the dialog window visible. */ - @Test - void depositFixAccount() { - double initialBalance = currentService.checkCurrentAccountBalance(); - - depositService.depositFixAccount(100, 0.1, "2023-08-03", "2024-08-03"); - - double newBalance = currentService.checkCurrentAccountBalance(); - assertEquals(initialBalance - 100, newBalance, "Current account balance should be decreased by 100"); - - long newElementCount = depositAccountBillsDao.ElementCount; - assertEquals(2, newElementCount); - - Object amount = depositAccountBillsDao.getAttribute("depositAccountBillAmount", newElementCount); - assertNotNull(amount, "Deposit account bill amount should not be null"); - assertEquals(100.0, amount, "Deposit account bill amount should be 100.0"); + public void init() { + log.debug("Initializing DepositePop dialog"); + // Clear the text fields + textField1.setText(""); + passwordField1.setText(""); + this.pack(); // 使用已经存在的this引用而不是创建新的实例 + setLocationRelativeTo(null); // null 使窗口居中于屏幕 + this.setVisible(true); } + /** - * Tests the processMaturedDeposits method. + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL */ - @Test - void processMaturedDeposits() { - double initialBalance = currentService.checkCurrentAccountBalance(); - - // 创建一个已到期的定期存款账单 - depositService.createDepositAccountBill(200, 0.1, "2023-08-03", "2024-05-01"); - assertEquals(initialBalance, currentService.checkCurrentAccountBalance()); - - depositService.processMaturedDeposits(); - - double newBalance = currentService.checkCurrentAccountBalance(); - double expectedInterest = 200 * 0.1 * 272 / 365; // Assuming the deposit has been active for 273 days - double expectedBalance = initialBalance + 200 + expectedInterest; - assertEquals(expectedBalance, newBalance, 0.01, "Current account balance should include principal and interest"); - - List bills = depositAccountBillsDao.getAllAttributes(); - assertFalse(bills.isEmpty(), "There should be no deposit account bills after processing matured deposits"); + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); + panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + buttonOK = new JButton(); + buttonOK.setText("OK"); + panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonCancel = new JButton(); + buttonCancel.setText("Cancel"); + panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Confirming Task No."); + panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Password"); + panel3.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + textField1 = new JTextField(); + panel3.add(textField1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + passwordField1 = new JPasswordField(); + panel3.add(passwordField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); } /** - * Tests the calculateDaysBetween method. + * @noinspection ALL */ - @Test - void testCalculateDaysBetween() { - long days = stringDateConvert.calculateDaysBetween("2023-08-03", "2024-05-01"); - assertEquals(272, days, "Days between 2023-08-03 and 2024-05-01 should be 272"); - - days = stringDateConvert.calculateDaysBetween("2023-01-01", "2023-12-31"); - assertEquals(364, days, "Days between 2023-01-01 and 2023-12-31 should be 364"); // 2023 is not a leap year - - days = stringDateConvert.calculateDaysBetween("2020-01-01", "2020-12-31"); - assertEquals(365, days, "Days between 2020-01-01 and 2020-12-31 should be 365"); // 2020 is a leap year + public JComponent $$$getRootComponent$$$() { + return contentPane; } + } \ No newline at end of file From 12bb74f428bb3e3e3bee799322bfc955636f62f0 Mon Sep 17 00:00:00 2001 From: jiecong_he <2021213073@bupt.cn> Date: Sun, 26 May 2024 17:37:57 +0800 Subject: [PATCH 9/9] 3123 1 --- .../java/com/seg83/childbank/dao/GoalDao.java | 2 +- .../java/com/seg83/childbank/dao/TaskDao.java | 2 +- .../com/seg83/childbank/dao/TaskListDao.java | 2 +- .../CurrentPops/InterestRatePop.java | 266 +++++++++--------- 4 files changed, 137 insertions(+), 135 deletions(-) diff --git a/src/main/java/com/seg83/childbank/dao/GoalDao.java b/src/main/java/com/seg83/childbank/dao/GoalDao.java index 05c6939..b915cdf 100644 --- a/src/main/java/com/seg83/childbank/dao/GoalDao.java +++ b/src/main/java/com/seg83/childbank/dao/GoalDao.java @@ -104,7 +104,7 @@ private Double getGoalAmount() { * @return List of Objects containing all attributes of a goal. */ @Override - public List getAllAttributes() { + List getAllAttributes() { return List.of(); } } diff --git a/src/main/java/com/seg83/childbank/dao/TaskDao.java b/src/main/java/com/seg83/childbank/dao/TaskDao.java index 6beceaf..b09d428 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskDao.java @@ -36,7 +36,7 @@ public TaskDao(DataWrapperDao dataWrapperDao) { * @return JSONObject containing task data. */ @Override - public JSONObject load() { + JSONObject load() { log.info("Request task data in JSON format"); JSONObject task = dataWrapperDao.load().getJSONObject("task"); log.debug("Get task data {}", task); diff --git a/src/main/java/com/seg83/childbank/dao/TaskListDao.java b/src/main/java/com/seg83/childbank/dao/TaskListDao.java index fe8df2f..5e3bb60 100644 --- a/src/main/java/com/seg83/childbank/dao/TaskListDao.java +++ b/src/main/java/com/seg83/childbank/dao/TaskListDao.java @@ -35,7 +35,7 @@ public TaskListDao(TaskDao taskDao) { * @return JSONArray containing task list data. */ @Override - JSONArray load() { + JSONArray load() { log.info("Request task list data in JSON format"); JSONArray taskList = taskDao.load().getJSONArray("taskList"); log.debug("Get task list data {}", taskList); diff --git a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java index 808c0c9..f0f6b4b 100644 --- a/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java +++ b/src/main/java/com/seg83/childbank/gui/component/currentpanel/CurrentPops/InterestRatePop.java @@ -23,149 +23,151 @@ public class InterestRatePop extends JDialog { @Autowired CurrentService currentService; @Autowired - private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; - private JComboBox comboBox1; - private JTextField textField1; - private JPasswordField passwordField1; - - public InterestRatePop() { - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); - - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); - } - }); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - } + AdminDao adminDao; + + private JPanel contentPane; + private JButton buttonOK; + private JButton buttonCancel; + private JComboBox comboBox1; + private JTextField textField1; + private JPasswordField passwordField1; + + public InterestRatePop() { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); - /** - * This method is called when the user clicks the OK button. - */ - private void onOK() { - String ratetxt = textField1.getText(); - String password = new String(passwordField1.getPassword()); - String passtarget = (String) adminDao.getAttribute("adminPassword"); - double rate = 0.0; - try { - rate = Double.parseDouble(ratetxt); - if (rate < 0) { - JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); - return; - } - } catch (NumberFormatException e) { - JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); } - if (password.equals(passtarget)) { - currentService.modifyInterestRate(rate); - } else { - JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); + }); + + buttonCancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); } - dispose(); - } + }); - /** - * This method is called when the user clicks the Cancel button. - */ - private void onCancel() { - dispose(); - } + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); - /** - * This method is called to initialize the dialog. - */ - public void init() { - log.debug("Initializing rate setting dialog"); - // Clear the text fields - textField1.setText(""); - passwordField1.setText(""); - // Use the existing this reference instead of creating a new instance - this.pack(); - // Center the dialog - setLocationRelativeTo(null); - this.setVisible(true); + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + } + + /** + * This method is called when the user clicks the OK button. + */ + private void onOK() { + String ratetxt = textField1.getText(); + String password = new String(passwordField1.getPassword()); + String passtarget = (String) adminDao.getAttribute("adminPassword"); + double rate = 0.0; + try { + rate = Double.parseDouble(ratetxt); + if (rate < 0) { + JOptionPane.showMessageDialog(this, "Interest rate cannot be negative", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "Invalid interest rate", "Error", JOptionPane.ERROR_MESSAGE); } + if (password.equals(passtarget)) { + currentService.modifyInterestRate(rate); + } else { + JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE); + } + dispose(); + } + + /** + * This method is called when the user clicks the Cancel button. + */ + private void onCancel() { + dispose(); + } + + /** + * This method is called to initialize the dialog. + */ + public void init() { + log.debug("Initializing rate setting dialog"); + // Clear the text fields + textField1.setText(""); + passwordField1.setText(""); + // Use the existing this reference instead of creating a new instance + this.pack(); + // Center the dialog + setLocationRelativeTo(null); + this.setVisible(true); + } } - { + { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPO RTANT!! <<< // DO NOT EDIT OR ADD ANY CODE HERE! - $$$setupUI$$$(); - } - private void $$$setupUI$$$() { - contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); - final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); - final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); - panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - buttonOK = new JButton(); - buttonOK.setText("OK"); - panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - buttonCancel = new JButton(); - buttonCancel.setText("Cancel"); - panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JPanel panel3 = new JPanel(); - panel3.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1)); - contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - final JLabel label1 = new JLabel(); - label1.setText("Period Select"); - panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label2 = new JLabel(); - label2.setText("Password"); - panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label3 = new JLabel(); - label3.setText("New Interest Rate"); - panel3.add(label3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - comboBox1 = new JComboBox(); - final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); - defaultComboBoxModel1.addElement("Daily"); - comboBox1.setModel(defaultComboBoxModel1); - panel3.add(comboBox1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - textField1 = new JTextField(); - panel3.add(textField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - passwordField1 = new JPasswordField(); - panel3.add(passwordField1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - final JLabel label4 = new JLabel(); - label4.setText("%"); - panel3.add(label4, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - } - - /** - * @noinspection ALL - */ - public JComponent $$$getRootComponent$$$() { - return contentPane; - } + $$$setupUI$$$(); + } + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false)); + panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + buttonOK = new JButton(); + buttonOK.setText("OK"); + panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + buttonCancel = new JButton(); + buttonCancel.setText("Cancel"); + panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1)); + contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setText("Period Select"); + panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + label2.setText("Password"); + panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label3 = new JLabel(); + label3.setText("New Interest Rate"); + panel3.add(label3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + comboBox1 = new JComboBox(); + final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); + defaultComboBoxModel1.addElement("Daily"); + comboBox1.setModel(defaultComboBoxModel1); + panel3.add(comboBox1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + textField1 = new JTextField(); + panel3.add(textField1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + passwordField1 = new JPasswordField(); + panel3.add(passwordField1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label4 = new JLabel(); + label4.setText("%"); + panel3.add(label4, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } }