3 Commits

5 changed files with 152 additions and 86 deletions

View File

@@ -42,36 +42,81 @@ public class TransactionController {
// 一覧画面
@GetMapping("/transaction/list")
public String transactionList(@RequestParam(required = false) LocalDate startDates,
@RequestParam(required = false) LocalDate endDates, Model model,
public String transactionList(
@RequestParam(required = false, defaultValue = "0") String years,
@RequestParam(required = false, defaultValue = "0") String months,
Model model,
HttpSession session) {
LocalDate startDate = (startDates == null) ? LocalDate.now().withDayOfMonth(1) : startDates;
LocalDate endDate = (endDates == null) ? LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth())
: endDates;
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LocalDate today = LocalDate.now();
int year = years.equals("0")
? today.getYear()
: Integer.parseInt(years);
int month = months.equals("0")
? today.getMonthValue()
: Integer.parseInt(months);
YearMonth yearMonth = YearMonth.of(year, month);
YearMonth previousYearMonth = yearMonth.minusMonths(1);
int previousYear = previousYearMonth.getYear();
int previousMonth = previousYearMonth.getMonthValue();
YearMonth nextYearMonth = yearMonth.plusMonths(1);
int nextYear = nextYearMonth.getYear();
int nextMonth = nextYearMonth.getMonthValue();
LocalDate startDate = yearMonth.atDay(1);
LocalDate endDate = yearMonth.atEndOfMonth();
Map<LocalDate, List<TransactionForm>> transactionFormMap = new HashMap<>();
transactionService.findAllByDate(startDate, endDate, loginUser.getUserId()).forEach((date, list) -> {
List<TransactionForm> transactionFormList = list.stream().map(transaction -> {
System.out.println(transaction.getTransactionDate());
TransactionForm transactionForm = TransactionForm.convertFrom(
transaction,
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
.getCategoryName(),
transactionService.findTotalExpense(startDate, endDate, loginUser.getUserId()),
transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId()),
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
.getTransactionType());
System.out.println("startDate = " + startDate);
System.out.println("endDate = " + endDate);
return transactionForm;
}).collect(Collectors.toList());
transactionFormMap.put(date, transactionFormList);
});
transactionService
.findAllByDate(
startDate,
endDate,
loginUser.getUserId())
.forEach((date, list) -> {
List<TransactionForm> transactionFormList = list.stream()
.map(transaction -> {
CategoryForm categoryForm = CategoryForm.convertFrom(
categoryService.findOne(
transaction.getCategoryId()));
return TransactionForm.convertFrom(
transaction,
categoryForm.getCategoryName(),
transactionService.findTotalExpense(
startDate,
endDate,
loginUser.getUserId()),
transactionService.findTotalIncome(
startDate,
endDate,
loginUser.getUserId()),
categoryForm.getTransactionType());
})
.collect(Collectors.toList());
transactionFormMap.put(date, transactionFormList);
});
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("previousYear", previousYear);
model.addAttribute("previousMonth", previousMonth);
model.addAttribute("nextYear", nextYear);
model.addAttribute("nextMonth", nextMonth);
model.addAttribute("transactionFormMap", transactionFormMap);
@@ -134,7 +179,7 @@ public class TransactionController {
@GetMapping("/transaction/create")
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Model model) {
if (today == null) {
today = LocalDate.now();
}
@@ -189,28 +234,28 @@ public class TransactionController {
System.out.println("category: " + transactionForm.getCategoryId() + "金額: " + transactionForm.getAmount());
model.addAttribute("transactionId", transactionId);
model.addAttribute("transactionForm", transactionForm);
model.addAttribute("categoryFormList", categoryFormList);
model.addAttribute("today", today);
return "transaction_update";
}
@PostMapping("/transaction/update")
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today, Model model,
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm,
@RequestParam LocalDate today, Model model,
HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
transactionForm.setUserId(loginUser.getUserId());
transactionForm.setTransactionId(transactionId);
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
return "error";
}
@@ -228,85 +273,76 @@ public class TransactionController {
@GetMapping("/menu")
public String menu(HttpSession session, Model model,
@RequestParam(required = false, defaultValue = "0") String years,
@RequestParam(required = false, defaultValue = "0") String months) {
@RequestParam(required = false, defaultValue = "0") String years,
@RequestParam(required = false, defaultValue = "0") String months) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LocalDate today = LocalDate.now();
LocalDate today = LocalDate.now();
int year = (years.equals("0")) ? today.getYear() : Integer.parseInt(years);
int year = (years.equals("0")) ? today.getYear() : Integer.parseInt(years);
int month = (months.equals("0")) ? today.getMonthValue() : Integer.parseInt(months);
int month = (months.equals("0")) ? today.getMonthValue() : Integer.parseInt(months);
YearMonth yearMonth = YearMonth.of(year, month);
YearMonth yearMonth = YearMonth.of(year, month);
int lastDay = yearMonth.lengthOfMonth();
int lastDay = yearMonth.lengthOfMonth();
int firstDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue() % 7;
int firstDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue() % 7;
YearMonth previousYearMonth = yearMonth.minusMonths(1);
YearMonth previousYearMonth = yearMonth.minusMonths(1);
int previousYear = previousYearMonth.getYear();
int previousMonth = previousYearMonth.getMonthValue();
int previousYear = previousYearMonth.getYear();
int previousMonth = previousYearMonth.getMonthValue();
YearMonth nextYearMonth = yearMonth.plusMonths(1);
YearMonth nextYearMonth = yearMonth.plusMonths(1);
int nextYear = nextYearMonth.getYear();
int nextMonth = nextYearMonth.getMonthValue();
int nextYear = nextYearMonth.getYear();
int nextMonth = nextYearMonth.getMonthValue();
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("day", today.getDayOfMonth());
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("day", today.getDayOfMonth());
model.addAttribute("lastDay", lastDay);
model.addAttribute("firstDayOfWeek", firstDayOfWeek);
model.addAttribute("lastDay", lastDay);
model.addAttribute("firstDayOfWeek", firstDayOfWeek);
model.addAttribute("previousYear", previousYear);
model.addAttribute("previousMonth", previousMonth);
model.addAttribute("previousYear", previousYear);
model.addAttribute("previousMonth", previousMonth);
model.addAttribute("nextYear", nextYear);
model.addAttribute("nextMonth", nextMonth);
model.addAttribute("nextYear", nextYear);
model.addAttribute("nextMonth", nextMonth);
LocalDate startDate = yearMonth.atDay(1);
LocalDate endDate = yearMonth.atEndOfMonth();
LocalDate startDate = yearMonth.atDay(1);
LocalDate endDate = yearMonth.atEndOfMonth();
List<Income> incomeList = transactionService.findTotalIncomeList(startDate, endDate, loginUser.getUserId());
List<Expense> expenseList = transactionService.findTotalExpenseList(startDate, endDate, loginUser.getUserId());
List<Income> incomeList = transactionService.findTotalIncomeList(startDate, endDate, loginUser.getUserId());
model.addAttribute("incomeList", incomeList);
model.addAttribute("expenseList", expenseList);
List<Expense> expenseList = transactionService.findTotalExpenseList(startDate, endDate, loginUser.getUserId());
int totalIncome = transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId());
model.addAttribute("incomeList", incomeList);
model.addAttribute("expenseList", expenseList);
int totalExpense = transactionService.findTotalExpense(startDate, endDate, loginUser.getUserId());
model.addAttribute("totalIncome", totalIncome);
model.addAttribute("totalExpense", totalExpense);
int totalIncome = transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId());
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId()));
int totalExpense = transactionService.findTotalExpense(startDate, endDate, loginUser.getUserId());
UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId()));
model.addAttribute("achievementRate", goalForm.getAchievementRate());
model.addAttribute("totalIncome", totalIncome);
model.addAttribute("totalExpense", totalExpense);
model.addAttribute("targetAmount", goalForm.getTargetAmount());
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId()));
UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId()));
model.addAttribute("achievementRate", goalForm.getAchievementRate());
model.addAttribute("targetAmount", goalForm.getTargetAmount());
model.addAttribute("saving", userForm.getSaving());
model.addAttribute("deadline", goalForm.getDeadline());
model.addAttribute("saving", userForm.getSaving());
return "menu";
model.addAttribute("deadline", goalForm.getDeadline());
return "menu";
}
}

View File

@@ -2,6 +2,8 @@ package com.example.demo.app.presentation.form;
import java.time.LocalDate;
import org.springframework.format.annotation.DateTimeFormat;
import com.example.demo.app.domain.model.GoalModel;
import lombok.AllArgsConstructor;
@@ -20,7 +22,8 @@ public class GoalForm {
private String goalSubtitle;
private Integer targetAmount;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate deadline;
private Integer goalComplete;

View File

@@ -22,7 +22,7 @@ th {
}
td {
width: 14.28%;
width: 14%;
height: 70px;
padding: 5px;
text-align: left;

View File

@@ -129,7 +129,7 @@
<div>
<span>達成率</span>
<span th:text="${achievementRate}"></span>
<span>円</span>
<span>%</span>
</div>
<div>
<span>達成期限</span>

View File

@@ -12,7 +12,34 @@
<body class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<div class="calendar-title">
<a class="month-button" th:href="@{/transaction/list(
years=${previousYear},
months=${previousMonth}
)}">
←
</a>
<div class="calendar-date">
<span class="year" th:text="|${year}年|"></span>
<span class="month" th:text="|${month}月|"></span>
</div>
<a class="month-button" th:href="@{/transaction/list(
years=${nextYear},
months=${nextMonth}
)}">
→
</a>
</div>
<div th:each="transactionForm : ${transactionFormMap}">
<a th:href="@{/transaction/detail(todayDates=${transactionForm.key})}">