Compare commits
21 Commits
170e319dca
...
a89c54f8c0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a89c54f8c0 | ||
|
|
7a13d9cdda | ||
|
|
0c5f4a8c9b | ||
|
|
c5d1814be4 | ||
|
|
1b6193082d | ||
|
|
86e41765f5 | ||
|
|
804e4a6fdd | ||
| ca7e93908d | |||
| a735162974 | |||
|
|
2e64d623b5 | ||
| ce0a158988 | |||
| 3d3177bbfa | |||
| 54b909d00d | |||
| 0b336dcf5a | |||
| 68fbe40385 | |||
| 9ae0669739 | |||
| f03638b347 | |||
| 867926391f | |||
| b0e675d32e | |||
| 86c6910c4a | |||
| cef08f1663 |
@@ -13,7 +13,7 @@ public class CategoryAnalysisModel {
|
||||
|
||||
private Integer previousMonthAmount;
|
||||
|
||||
private Integer previousMonthDifferenceAmount;
|
||||
private Integer monthDifferenceAmount;
|
||||
|
||||
private Integer courseLimitAmount;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
// 今月の期間取得
|
||||
// 前月の期間取得
|
||||
// 今月の支出取得
|
||||
// 前月の支出取得
|
||||
// コース配分取得
|
||||
// カテゴリ別集計
|
||||
// 前月との差額集計
|
||||
//総支出算出
|
||||
// コース限度額算出、コース別差額算出
|
||||
// CategoryAnalysisModel生成
|
||||
// AnalysisModelの生成
|
||||
LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1);
|
||||
LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth());
|
||||
|
||||
return null;
|
||||
// 前月の期間取得
|
||||
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 new AnalysisModel(currentMonthTotalAmount, previousMonthTotalAmount, totalDifferenceAmount, categoryAnalysisModelList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user