21 Commits

Author SHA1 Message Date
kkazuya
a89c54f8c0 [ADD] Course, CoureseInfoのサービスとそれを実装したクラスを作成しました。 2026-09-17 15:49:11 +09:00
kkazuya
7a13d9cdda Merge branch 'n-kawahito' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 15:31:40 +09:00
kkazuya
0c5f4a8c9b Merge branch 'k-oshita' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi
# Conflicts:
#	src/main/java/com/example/demo/app/infra/repository/GoalRepository.java
2026-09-17 15:31:20 +09:00
kkazuya
c5d1814be4 Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi 2026-09-17 15:25:03 +09:00
s-choi
1b6193082d 「FIX] 収支処理のURLを指定しました。 2026-09-17 14:52:46 +09:00
s-choi
86e41765f5 [FIX] JPQLの変数を修正しました。 2026-09-17 14:52:24 +09:00
s-choi
804e4a6fdd [FIX] JQPLの変数名とテーブル名を修正しました。 2026-09-17 14:51:11 +09:00
ca7e93908d [FIX]HOTFIXに合わせて、変数名を変更しました。 2026-09-17 14:43:44 +09:00
a735162974 [EDIT]支出分析のためのサービス実装部分を記述しました。 2026-09-17 14:43:11 +09:00
s-choi
2e64d623b5 [FIX] 主キーの型を修正しました。 2026-09-17 14:32:48 +09:00
ce0a158988 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 14:23:41 +09:00
3d3177bbfa [ADD]新規会員登録機能の作成 2026-09-17 14:23:30 +09:00
54b909d00d [ADD] 目標のためのModelを作成しました。 2026-09-17 14:22:06 +09:00
0b336dcf5a [EDIT] 改行・コード位置を調整しました。 2026-09-17 14:16:29 +09:00
68fbe40385 [EDIT] 改行・コードを調整しました。 2026-09-17 14:03:44 +09:00
9ae0669739 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 14:01:56 +09:00
f03638b347 Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 14:01:32 +09:00
867926391f [ADD] 目標のためのRepositoryを作成しました。 2026-09-17 13:56:58 +09:00
b0e675d32e Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 13:52:56 +09:00
86c6910c4a Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 13:29:15 +09:00
cef08f1663 Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-17 12:51:54 +09:00
15 changed files with 345 additions and 38 deletions

View File

@@ -13,7 +13,7 @@ public class CategoryAnalysisModel {
private Integer previousMonthAmount;
private Integer previousMonthDifferenceAmount;
private Integer monthDifferenceAmount;
private Integer courseLimitAmount;

View File

@@ -0,0 +1,10 @@
package com.example.demo.app.domain.service;
import java.util.List;
import com.example.demo.app.domain.model.CourseInfoModel;
public interface CourseInfoService {
public List<CourseInfoModel> findAll();
}

View File

@@ -0,0 +1,11 @@
package com.example.demo.app.domain.service;
import java.util.List;
import com.example.demo.app.domain.model.CourseModel;
public interface CourseService {
public List<CourseModel> findAll();
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.app.domain.service;
import com.example.demo.app.presentation.form.UserForm;
public interface UserService {
void register(UserForm userForm);
}

View File

@@ -1,9 +1,21 @@
package com.example.demo.app.domain.service.impl;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.AnalysisModel;
import com.example.demo.app.domain.model.CategoryAnalysisModel;
import com.example.demo.app.domain.service.AnalysisService;
import com.example.demo.app.infra.entity.AllocationEntity;
import com.example.demo.app.infra.entity.CategoryEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.AllocationRepository;
import com.example.demo.app.infra.repository.CategoryRepository;
import com.example.demo.app.infra.repository.TransactionRepository;
import com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor;
@@ -12,29 +24,119 @@ import lombok.RequiredArgsConstructor;
public class AnalysisServiceImpl implements AnalysisService {
//Repositoryの呼び出し
// private final TransactionRepository transactionRepository;
// private final AllocationRepository allocationRepository;
// private final UserRepository userRepository;
// private final CategoryRepository categoryRepository;
private final TransactionRepository transactionRepository;
private final AllocationRepository allocationRepository;
private final UserRepository userRepository;
private final CategoryRepository categoryRepository;
@Override
public AnalysisModel getAnalysis(Long userId) {
// ユーザー情報取得、月別使用可能資金取得
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
// コースID取得
Long courseId = userEntity.getCourseEntity().getCourseId();
// 月別使用可能資金取得
Integer monthlyBudget =userEntity.getMonthlyBudget();
// 今月の期間取得
LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1);
LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth());
// 前月の期間取得
LocalDate previousMonthStartDate = LocalDate.now().minusMonths(1).withDayOfMonth(1);
LocalDate previousMonthEndDate = LocalDate.now().minusMonths(1).withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth());
// 今月の支出取得
Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId);
if (currentMonthTotalAmount == null) {
currentMonthTotalAmount = 0;
}
// 前月の支出取得
Integer previousMonthTotalAmount = transactionRepository.findTotalExpense(previousMonthStartDate, previousMonthEndDate, userId);
if (previousMonthTotalAmount == null) {
previousMonthTotalAmount = 0;
}
//総支出差額算出
Integer totalDifferenceAmount = currentMonthTotalAmount - previousMonthTotalAmount;
//カテゴリ一覧取得
List<CategoryAnalysisModel> categoryAnalysisModelList = new ArrayList<>();
List<CategoryEntity> categoryEntityList = categoryRepository.findAll();
List<AllocationEntity> allocationEntityList = allocationRepository.findByCourseEntity_CourseId(courseId);
//取得ループ
for (CategoryEntity categoryEntity : categoryEntityList) {
if (categoryEntity.getTransactionType() != 0) {
continue;
}
// カテゴリ別今月金額取得
Integer currentMonthAmount =
transactionRepository.findCategoryExpense(currentMonthStartDate,
currentMonthEndDate,
userId,
categoryEntity.getCategoryId());
// カテゴリ別前月金額取得
Integer previousMonthAmount =
transactionRepository.findCategoryExpense(previousMonthStartDate,
previousMonthEndDate,
userId,
categoryEntity.getCategoryId());
if (currentMonthAmount == null) {
currentMonthAmount = 0;
}
if (previousMonthAmount == null) {
previousMonthAmount = 0;
}
// カテゴリ別前月差額算出
Integer monthDifferenceAmount = currentMonthAmount - previousMonthAmount;
// コース配分取得
// カテゴリ別集計
// 前月との差額集計
//総支出算出
// コース限度額算出、コース別差額算出
AllocationEntity allocationEntity = allocationEntityList.stream().filter(allocation ->
allocation.getCategoryEntity()
.getCategoryId()
.equals(categoryEntity.getCategoryId()))
.findFirst()
.orElse(null);
Integer allocationRatio = 0;
if (allocationEntity != null) {
allocationRatio =
allocationEntity.getAllocationRatio();
}
// コース限度額算出
Integer courseLimitAmount = monthlyBudget * allocationRatio / 100;
// コース差額算出
Integer courseDifferenceAmount = currentMonthAmount - courseLimitAmount;
// CategoryAnalysisModel生成
CategoryAnalysisModel categoryAnalysisModel = new CategoryAnalysisModel(
categoryEntity.getCategoryName(),
currentMonthAmount,
previousMonthAmount,
monthDifferenceAmount,
courseLimitAmount,
courseDifferenceAmount);
categoryAnalysisModelList.add(categoryAnalysisModel);
}
// AnalysisModelの生成
return null;
return new AnalysisModel(currentMonthTotalAmount, previousMonthTotalAmount, totalDifferenceAmount, categoryAnalysisModelList);
}
}

View File

@@ -0,0 +1,23 @@
package com.example.demo.app.domain.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.CourseInfoModel;
import com.example.demo.app.domain.service.CourseInfoService;
import com.example.demo.app.infra.repository.AllocationRepository;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class CourseInfoServiceImpl implements CourseInfoService {
private final AllocationRepository allocationRepository;
@Override
public List<CourseInfoModel> findAll() {
return allocationRepository.findAllJoinedAllocation();
}
}

View File

@@ -0,0 +1,24 @@
package com.example.demo.app.domain.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.CourseModel;
import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.repository.CourseRepository;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class CourseServiceImpl implements CourseService {
private final CourseRepository courseRepository;
public List<CourseModel> findAll(){
return CourseEntity.createCourseModelList(courseRepository.findAll());
}
}

View File

@@ -0,0 +1,58 @@
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.entity.GoalEntity;
import com.example.demo.app.infra.entity.QuestionEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.CourseRepository;
import com.example.demo.app.infra.repository.GoalRepository;
import com.example.demo.app.infra.repository.QuestionRepository;
import com.example.demo.app.infra.repository.UserRepository;
import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final QuestionRepository questionRepository;
private final GoalRepository goalRepository;
private final CourseRepository courseRepository;
@Override
public void register(UserForm userForm) {
UserEntity userEntity = new UserEntity();
userEntity.setUserName(userForm.getUserName());
userEntity.setMailAddress(userForm.getMailAddress());
userEntity.setPassword(userForm.getPassword());
userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer());
userEntity.setBirthDate(userForm.getBirthDate());
userEntity.setSaving(userForm.getSaving());
userEntity.setAnnualIncome(userForm.getAnnualIncome());
userEntity.setMonthlyBudget(userForm.getMonthlyBudget());
QuestionEntity questionEntity =
questionRepository.findById(userForm.getSecretQuestionId()).orElse(null);
GoalEntity goalEntity =
goalRepository.findById(userForm.getGoalId()).orElse(null);
CourseEntity courseEntity =
courseRepository.findById(userForm.getCourseId()).orElse(null);
userEntity.setQuestionEntity(questionEntity);
userEntity.setGoalEntity(goalEntity);
userEntity.setCourseEntity(courseEntity);
userEntity.setDeleteFlag(0);
userRepository.save(userEntity);
}
}

View File

@@ -24,7 +24,7 @@ public class GoalEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "goal_id")
private Integer goalId;
private Long goalId;
@Column(name = "goal_title", nullable = true)
private String goalTitle;

View File

@@ -13,19 +13,20 @@ public interface AllocationRepository extends JpaRepository<AllocationEntity, Al
List<AllocationEntity> findByCourseEntity_CourseId(Long courseId);
@Query(" SELECT co.course_id, "
+ " co.course_name, "
+ " ca.category_id, "
+ " ca.categpry_name, "
+ " a.allocation_ratio "
+ " FROM allocation_m a "
+ " INNER JOIN course_m co "
+ " ON a.course_id = co.course_id "
+ " INNER JOIN category_t ca "
+ " on a.category_id = ca.category_id "
+ " WHERE ca.transaction_type = 0 "
+ " ORDER BY a.course_id ASC, "
+ " a.category_id ASC ")
@Query(" SELECT new com.example.demo.app.domain.model.CourseInfoModel("
+ "co.courseId, "
+ " co.courseName, "
+ " ca.categoryId, "
+ " ca.categoryName, "
+ " a.allocationRatio )"
+ " FROM AllocationEntity a"
+ " INNER JOIN CourseEntity co "
+ " ON a.courseEntity.courseId = co.courseId "
+ " INNER JOIN CategoryEntity ca "
+ " on a.categoryEntity.categoryId = ca.categoryId "
+ " WHERE ca.transactionType = 0 "
+ " ORDER BY a.courseEntity.courseId ASC, "
+ " a.categoryEntity.categoryId ASC ")
List<CourseInfoModel> findAllJoinedAllocation();
}

View File

@@ -0,0 +1,11 @@
package com.example.demo.app.infra.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.app.infra.entity.GoalEntity;
@Repository
public interface GoalRepository extends JpaRepository<GoalEntity, Long> {
}

View File

@@ -13,13 +13,13 @@ public interface TransactionRepository extends JpaRepository<TransactionEntity,
@Query("select t from TransactionEntity t where t.userEntity.userId = :userId and t.transactionDate = :transactionDate")
public List<TransactionEntity> findByUserIdAndDate(LocalDate todayDate, Long userId);
@Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc")
@Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userEntity.userId = :userId) order by t.transactionDate asc")
public List<TransactionEntity> findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId);
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId);
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId);
@Query("select sum(t.amount) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate")

View File

@@ -66,7 +66,7 @@ public class TransactionController {
}
// 詳細画面
@GetMapping()
@GetMapping("/transaction/detail")
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
LocalDate todayDate = (todayDates == null) ? LocalDate.now() : todayDates;
@@ -93,13 +93,13 @@ public class TransactionController {
return "";
}
@GetMapping("")
@GetMapping("/transaction/create")
public String createOneGet(@ModelAttribute TransactionForm transactionForm) {
return "";
}
@PostMapping()
@PostMapping("/transaction/create")
public String createOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
if (transactionService.createTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
@@ -110,13 +110,13 @@ public class TransactionController {
}
@GetMapping("")
@GetMapping("/transaction/update")
public String updateOneGet(@ModelAttribute TransactionForm transactionForm) {
return "";
}
@PostMapping()
@PostMapping("/transaction/update")
public String updateOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {

View File

@@ -0,0 +1,35 @@
package com.example.demo.app.presentation.controller;
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 com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class UserController {
@GetMapping("/user/register")
public String showRegister(Model model) {
model.addAttribute("userForm", new UserForm());
return "user_register";
}
@PostMapping("/user/register/confirm")
public String confirmRegister(
@ModelAttribute UserForm userForm,
HttpSession session) {
session.setAttribute("userForm", userForm);
return "user_register_confirm";
}
}

View File

@@ -0,0 +1,24 @@
package com.example.demo.app.presentation.form;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserForm {
private String userName;
private String mailAddress;
private String password;
private Long secretQuestionId;
private String SecretAnswer;
private LocalDate birthDate;
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;
private Long goalId;
private Long courseId;
}