7 Commits

19 changed files with 178 additions and 58 deletions

View File

@@ -26,6 +26,8 @@ public class GoalModel {
private Integer achievementRate; // 達成率
private Integer currentAmount; // 現在の資産
public static GoalModel convertFrom(GoalEntity goalEntity) {
return new GoalModel(
goalEntity.getGoalId(),
@@ -34,7 +36,7 @@ public class GoalModel {
goalEntity.getTargetAmount(),
goalEntity.getDeadline(),
goalEntity.getGoalComplete(),
null);
null,null);
}
public static GoalEntity convertTo(GoalModel goalModel) {
@@ -56,7 +58,7 @@ public class GoalModel {
goalForm.getTargetAmount(),
goalForm.getDeadline(),
goalForm.getGoalComplete()
,null);
,null,null);
}
}

View File

@@ -4,6 +4,9 @@ import com.example.demo.app.domain.model.AnalysisModel;
public interface AnalysisService {
AnalysisModel getAnalysis(Long userId);
AnalysisModel getAnalysis(
Long userId,
Integer year,
Integer month);
}

View File

@@ -8,4 +8,6 @@ public interface CourseService {
public List<CourseModel> findAll();
public CourseModel findById(Long courseId);
}

View File

@@ -30,7 +30,7 @@ public class AnalysisServiceImpl implements AnalysisService {
private final CategoryRepository categoryRepository;
@Override
public AnalysisModel getAnalysis(Long userId) {
public AnalysisModel getAnalysis(Long userId, Integer year, Integer month) {
// ユーザー情報取得、月別使用可能資金取得
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() ->
@@ -44,12 +44,15 @@ public class AnalysisServiceImpl implements AnalysisService {
Integer monthlyBudget =userEntity.getMonthlyBudget();
// 今月の期間取得
LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1);
LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth());
LocalDate targetDate = LocalDate.of(year, month, 1);
LocalDate currentMonthStartDate = targetDate.withDayOfMonth(1);
LocalDate currentMonthEndDate = targetDate.withDayOfMonth(targetDate.lengthOfMonth());
// 前月の期間取得
LocalDate previousMonthStartDate = LocalDate.now().minusMonths(1).withDayOfMonth(1);
LocalDate previousMonthEndDate = LocalDate.now().minusMonths(1).withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth());
LocalDate previousDate = targetDate.minusMonths(1);
LocalDate previousMonthStartDate = previousDate.withDayOfMonth(1);
LocalDate previousMonthEndDate = previousDate.withDayOfMonth(previousDate.lengthOfMonth());
// 今月の支出取得
Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId);

View File

@@ -21,4 +21,8 @@ public class CourseServiceImpl implements CourseService {
return CourseEntity.createCourseModelList(courseRepository.findAll());
}
public CourseModel findById(Long courseId) {
return CourseModel.convertFrom(courseRepository.findByCourseId(courseId));
}
}

View File

@@ -56,7 +56,8 @@ public class GoalServiceImpl implements GoalService {
goalModel.getTargetAmount(),
goalModel.getDeadline(),
goalModel.getGoalComplete(),
achievementRate);
achievementRate,
currentAmount);
}
@Override

View File

@@ -1,9 +1,14 @@
package com.example.demo.app.infra.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.example.demo.app.infra.entity.CourseEntity;
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
@Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ")
public CourseEntity findByCourseId(Long courseId);
}

View File

@@ -1,11 +1,15 @@
package com.example.demo.app.presentation.controller;
import java.time.LocalDate;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.AnalysisModel;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.AnalysisService;
@@ -20,19 +24,47 @@ public class AnalysisController {
private final AnalysisService analysisService;
@SessionCheck
@GetMapping("/analysis")
public String showAnalysis(Model model, HttpSession session) {
public String showAnalysis(
@RequestParam(required = false) Integer year,
@RequestParam(required = false) Integer month,
Model model,
HttpSession session) {
//ログインユーザーの取得(セッション)
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
//初期年月表示
LocalDate nowDate = LocalDate.now();
if (year == null) {
year = nowDate.getYear();
}
if (month == null) {
month = nowDate.getMonthValue();
}
//前月・翌月作成
LocalDate targetDate = LocalDate.of(year, month, 1);
LocalDate previousDate = targetDate.minusMonths(1);
LocalDate nextDate = targetDate.plusMonths(1);
//分析結果の取得(Service)
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId());
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId(), year, month);
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
//model格納
model.addAttribute("analysisForm", analysisForm);
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("previousYear", previousDate.getYear());
model.addAttribute("previousMonth", previousDate.getMonthValue());
model.addAttribute("nextYear", nextDate.getYear());
model.addAttribute("nextMonth", nextDate.getMonthValue());
return "analysis";
}

View File

@@ -7,6 +7,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.AuthenticationModel;
import com.example.demo.app.domain.service.AuthenticationService;
import com.example.demo.app.infra.repository.QuestionRepository;
@@ -21,6 +22,7 @@ public class AuthenticationController {
private final AuthenticationService authenticationService;
private final QuestionRepository questionRepository;
@SessionCheck
@GetMapping("/authentication")
public String showAuthentication(Model model) {
@@ -30,6 +32,7 @@ public class AuthenticationController {
return "authentication";
}
@SessionCheck
@PostMapping("/authentication")
public String authenticate(
AuthenticationForm authenticationForm,

View File

@@ -7,24 +7,25 @@ import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.model.UserModel;
import com.example.demo.app.domain.service.CourseInfoService;
import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.form.CourseForm;
import com.example.demo.app.presentation.form.CourseInfoForm;
import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequestMapping("/course")
//@RequestMapping("/course")
@RequiredArgsConstructor
public class CourseController {
@@ -38,16 +39,19 @@ public class CourseController {
private final UserService userService;
@PostMapping("/select/register")
public String showSelectCourse(@ModelAttribute UserModel userModel, Model model) {
@SessionCheck
@GetMapping("/course/select/register")
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
try {
System.out.println(userForm.getMailAddress());
model.addAttribute("mode", "select");
session.setAttribute("userForm", userForm);
model.addAttribute("mode", "regist");
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course";
} catch (Exception e) {
@@ -63,7 +67,8 @@ public class CourseController {
}
}
@PostMapping("/select/change")
@SessionCheck
@GetMapping("/select/change")
public String showChangeCourse(Model model) {
try {
@@ -87,6 +92,7 @@ public class CourseController {
}
}
@SessionCheck
@PostMapping("/change")
public String changeCourse(@RequestParam Long courseId) {

View File

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.GoalModel;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.GoalService;
@@ -23,6 +24,7 @@ public class GoalController {
private final GoalService goalService;
@SessionCheck
@GetMapping("")
public String getGoal(Model model, HttpSession session) {
@@ -37,6 +39,7 @@ public class GoalController {
return "goal_view";
}
@SessionCheck
@GetMapping("/edit")
public String editGoal(Model model, HttpSession session) {
@@ -50,6 +53,7 @@ public class GoalController {
return "goal_edit";
}
@SessionCheck
@PostMapping("/update")
public String updateGoal(@ModelAttribute GoalForm goalForm, HttpSession session) {

View File

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.model.ProfileModel;
import com.example.demo.app.domain.service.ProfileService;
@@ -21,6 +22,7 @@ import lombok.RequiredArgsConstructor;
public class ProfileController {
private final ProfileService profileService;
@SessionCheck
@GetMapping("/profile")
public String profile(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
@@ -33,6 +35,7 @@ public class ProfileController {
return "profile";
}
@SessionCheck
@GetMapping("/profile/edit")
public String showEditProfile(
Model model,
@@ -84,6 +87,7 @@ public class ProfileController {
return "redirect:/login";
}
@PostMapping("/logout")
public String logout(HttpSession session) {
session.invalidate();

View File

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CategoryService;
import com.example.demo.app.domain.service.GoalService;
@@ -41,6 +42,7 @@ public class TransactionController {
private final UserService userService;
// 一覧画面
@SessionCheck
@GetMapping("/transaction/list")
public String transactionList(
@RequestParam(required = false, defaultValue = "0") String years,
@@ -124,6 +126,7 @@ public class TransactionController {
}
// 詳細画面
@SessionCheck
@GetMapping("/transaction/detail")
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
@@ -176,6 +179,7 @@ public class TransactionController {
return "transaction_detail";
}
@SessionCheck
@GetMapping("/transaction/create")
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Model model) {
@@ -200,6 +204,7 @@ public class TransactionController {
return "transaction_create";
}
@SessionCheck
@PostMapping("/transaction/create")
public String createOnePost(@ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today,
Model model,
@@ -215,6 +220,7 @@ public class TransactionController {
}
@SessionCheck
@GetMapping("/transaction/update")
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
Model model) {
@@ -246,6 +252,7 @@ public class TransactionController {
}
@SessionCheck
@PostMapping("/transaction/update")
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm,
@RequestParam LocalDate today, Model model,
@@ -264,6 +271,7 @@ public class TransactionController {
}
@SessionCheck
@PostMapping("/transaction/delete")
public String deleteOne(@RequestParam Long transactionId, @RequestParam LocalDate today) {
@@ -271,6 +279,7 @@ public class TransactionController {
return "redirect:/transaction/detail?todayDates=" + today;
}
@SessionCheck
@GetMapping("/menu")
public String menu(HttpSession session, Model model,
@RequestParam(required = false, defaultValue = "0") String years,
@@ -336,6 +345,8 @@ public class TransactionController {
model.addAttribute("achievementRate", goalForm.getAchievementRate());
model.addAttribute("currentAmount", goalForm.getCurrentAmount());
model.addAttribute("targetAmount", goalForm.getTargetAmount());
model.addAttribute("saving", userForm.getSaving());

View File

@@ -7,24 +7,45 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class UserController {
private final CourseService courseService;
@GetMapping("/user/register")
public String showRegister(Model model, HttpSession session) {
UserForm userForm = new UserForm();
model.addAttribute("userForm", userForm);
return "user_register";
}
@PostMapping("/user/register/return")
public String showRegisterReturn(@RequestParam(required = false) Long courseId, Model model, HttpSession session) {
UserForm userForm = (UserForm) session.getAttribute("userForm");
if(userForm == null) {
userForm = new UserForm();
userForm.setCourseId(courseId);
}
if(courseId != null) {
model.addAttribute("selectedCourseName", courseService.findById(courseId).getCourseName());
}
model.addAttribute("courseId", courseId);
model.addAttribute("userForm", userForm);
return "user_register";
}

View File

@@ -30,6 +30,8 @@ public class GoalForm {
private Integer achievementRate; // 達成率
private Integer currentAmount; // 現在の資産
public static GoalForm convertFrom(GoalModel goalModel) {
return new GoalForm(
goalModel.getGoalId(),
@@ -38,7 +40,8 @@ public class GoalForm {
goalModel.getTargetAmount(),
goalModel.getDeadline(),
goalModel.getGoalComplete(),
goalModel.getAchievementRate());
goalModel.getAchievementRate(),
goalModel.getCurrentAmount());
}
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {

View File

@@ -5,6 +5,7 @@
<title>分析画面</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="pb-5 pt-5">
<div th:replace="~{header :: header}">
@@ -13,6 +14,23 @@
<div class="container mt-4">
<h2 class="text-center">支出分析</h2>
<div class="text-center">
<a class="month-button" th:href="@{/analysis(year=${previousYear}, month=${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="@{/analysis(year=${nextYear}, month=${nextMonth})}">
→
</a>
</div>
<table class="table text-center">
<thead>
<tr>

View File

@@ -14,7 +14,6 @@
<h1>目標詳細</h1>
<table>
<tr>
<th>目標名</th>
<td th:text="${goalForm.goalTitle}"></td>

View File

@@ -118,6 +118,13 @@
<span th:text="${targetAmount}"></span>
<span>円</span>
</div>
<div>
<span>現在高</span>
<span th:text="${currentAmount}"></span>
<span>円</span>
</div>
<div>
<span>貯金額</span>
<span th:text="${saving}"></span>

View File

@@ -9,42 +9,34 @@
<body>
<h1>コース選択</h1>
<form th:action="@{/user/register}" th:object="${userForm}" method="post">
<input type="hidden" th:field="*{userName}">
<input type="hidden" th:field="*{mailAddress}">
<input type="hidden" th:field="*{birthDate}">
<input type="hidden" th:field="*{password}">
<input type="hidden" th:field="*{secretQuestionId}">
<input type="hidden" th:field="*{secretAnswer}">
<input type="hidden" th:field="*{saving}">
<input type="hidden" th:field="*{annualIncome}">
<input type="hidden" th:field="*{monthlyBudget}">
<input type="hidden" th:field="*{targetAmount}">
<button type="submit">確定</button>
<div class="accordion" id="accordionExample">
<div class="accordion-item" th:each="course:${courseList}">
<h2 class="accordion-header d-flex align-items-center">
<input type="radio" name="courseId" th:value="${course.courseId}" class="form-check-input ms-3 me-2">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" th:data-bs-target="'#collapse' + ${course.courseId}" aria-expanded="false" aria-controls="'collapse' + ${course.courseId}">
<span th:text="${course.courseName}"></span>
</button>
</h2>
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<span th:text="${course.description}"></span>
<table border="1">
<tr>
<th>カテゴリ名</th><th>配分(%)</th>
</tr>
<tr th:each="courseInfo:${courseInfoList}" th:if="${course.courseId == courseInfo.courseId}">
<td th:text="${courseInfo.categoryName}"></td>
<td th:text="${courseInfo.allocationRatio}"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<form th:action="${mode == 'regist'} ? @{/user/register/return}: @{/change}" method="post">
<button type="submit">確定</button>
<div class="accordion" id="accordionExample">
<div class="accordion-item" th:each="course:${courseList}">
<h2 class="accordion-header d-flex align-items-center">
<input type="radio" name="courseId" th:value="${course.courseId}" class="form-check-input ms-3 me-2">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" th:data-bs-target="'#collapse' + ${course.courseId}" aria-expanded="false" aria-controls="'collapse' + ${course.courseId}">
<span th:text="${course.courseName}"></span>
</button>
</h2>
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<span th:text="${course.description}"></span>
<table border="1">
<tr>
<th>カテゴリ名</th><th>配分(%)</th>
</tr>
<tr th:each="courseInfo:${courseInfoList}" th:if="${course.courseId == courseInfo.courseId}">
<td th:text="${courseInfo.categoryName}"></td>
<td th:text="${courseInfo.allocationRatio}"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>