Compare commits
28 Commits
d87bdfbe91
...
830d8a672f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
830d8a672f | ||
|
|
22191e63ef | ||
|
|
bd2cad7c34 | ||
|
|
db7fc1d16d | ||
| 23232954f1 | |||
| 4e3477af77 | |||
|
|
296bcf8d70 | ||
|
|
544cbd0ac8 | ||
|
|
0eddd7889f | ||
|
|
bda791567c | ||
|
|
1e09463984 | ||
|
|
a89c54f8c0 | ||
| cbaee01d13 | |||
| 2dad64ab10 | |||
| 9b51b26b0e | |||
| a5799843d3 | |||
|
|
7a13d9cdda | ||
|
|
0c5f4a8c9b | ||
|
|
c5d1814be4 | ||
|
|
1b6193082d | ||
|
|
86e41765f5 | ||
|
|
804e4a6fdd | ||
| ca7e93908d | |||
| a735162974 | |||
|
|
2e64d623b5 | ||
|
|
170e319dca | ||
| ce0a158988 | |||
| 54b909d00d |
@@ -5,6 +5,10 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationModel {
|
||||
private Long userId;
|
||||
public class AllocationModel {
|
||||
|
||||
private Long categoryId;
|
||||
private Long courseId;
|
||||
private Integer allocationRatio;
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class CategoryAnalysisModel {
|
||||
|
||||
private Integer previousMonthAmount;
|
||||
|
||||
private Integer previousMonthDifferenceAmount;
|
||||
private Integer monthDifferenceAmount;
|
||||
|
||||
private Integer courseLimitAmount;
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CourseInfoModel {
|
||||
|
||||
private Long courseId;
|
||||
|
||||
private String courseName;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer allocationRatio;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CourseModel {
|
||||
|
||||
private Long courseId;
|
||||
private String courseName;
|
||||
private String description;
|
||||
|
||||
public static CourseModel convertFrom(CourseEntity courseEntity) {
|
||||
return new CourseModel(
|
||||
courseEntity.getCourseId(),
|
||||
courseEntity.getCourseName(),
|
||||
courseEntity.getDescription());
|
||||
}
|
||||
|
||||
public static List<CourseModel> convertFrom(List<CourseEntity> courseEntityList) {
|
||||
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UserModel {
|
||||
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private String emailAddress;
|
||||
private String password;
|
||||
private Integer secretQuestionId;
|
||||
private String secretAnswer;
|
||||
@@ -18,7 +19,7 @@ public class UserModel {
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
private Long goalId;
|
||||
private Long courseId;
|
||||
private Integer goalId;
|
||||
private Integer courseId;
|
||||
private Integer deleteFlag;
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
public interface AuthenticationService {
|
||||
|
||||
AuthenticationModel authenticate(AuthenticationForm authenticationForm);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public AuthenticationModel authenticate(AuthenticationForm authenticationForm) {
|
||||
|
||||
UserEntity userEntity = userRepository.findByMailAddress(
|
||||
authenticationForm.getMailAddress())
|
||||
.orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getQuestionEntity().getSecretQuestionId()
|
||||
.equals(authenticationForm.getSecretQuestionId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getSecretQuestionAnswer()
|
||||
.equals(authenticationForm.getSecretAnswer())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AuthenticationModel(userEntity.getUserId());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,26 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.IdClass;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import com.example.demo.app.domain.model.AllocationModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Table(name = "allocation")
|
||||
@IdClass(AllocationId.class)
|
||||
@Table(name = "allocation_m")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -33,4 +39,15 @@ public class AllocationEntity {
|
||||
@Column(name = "allocation_ratio", nullable = false)
|
||||
private Integer allocationRatio;
|
||||
|
||||
|
||||
public static List<AllocationModel> createAllocationModelList(List<AllocationEntity> allocationEntityList) {
|
||||
|
||||
return allocationEntityList
|
||||
.stream()
|
||||
.map(allocationEntity -> new AllocationModel(
|
||||
allocationEntity.getCategoryEntity().getCategoryId(),
|
||||
allocationEntity.getCourseEntity().getCourseId(),
|
||||
allocationEntity.getAllocationRatio()
|
||||
)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AllocationId implements Serializable {
|
||||
private Long categoryEntity;
|
||||
|
||||
private Long courseEntity;
|
||||
}
|
||||
@@ -6,18 +6,19 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Table(name = "course")
|
||||
@Table(name = "course_m")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -39,6 +40,18 @@ public class CourseEntity {
|
||||
private List<UserEntity> userEntity;
|
||||
|
||||
@OneToOne(mappedBy = "courseEntity")
|
||||
private List<AllocationEntity> allocationEntity;
|
||||
private AllocationEntity allocationEntity;
|
||||
|
||||
|
||||
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
|
||||
|
||||
return courseEntityList
|
||||
.stream()
|
||||
.map(courseEntity -> new CourseModel(
|
||||
courseEntity.getCourseId(),
|
||||
courseEntity.getCourseName(),
|
||||
courseEntity.getDescription()
|
||||
)).toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class QuestionEntity {
|
||||
@Column(name = "question_text", nullable = false)
|
||||
private String questionText;
|
||||
|
||||
@OneToMany(mappedBy = "QuestionEntity")
|
||||
@OneToMany(mappedBy = "questionEntity")
|
||||
private List<UserEntity> userEntity;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,30 @@ package com.example.demo.app.infra.repository;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||
import com.example.demo.app.infra.entity.AllocationId;
|
||||
|
||||
public interface AllocationRepository extends JpaRepository<AllocationEntity, Long>{
|
||||
public interface AllocationRepository extends JpaRepository<AllocationEntity, AllocationId>{
|
||||
|
||||
List<AllocationEntity> findByCourseEntity_CourseId(Long courseId);
|
||||
|
||||
@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();
|
||||
|
||||
List<AllocationEntity> findByCourseId(Long courseId);
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
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 com.example.demo.app.domain.model.AnalysisModel;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.AnalysisService;
|
||||
import com.example.demo.app.presentation.form.AnalysisForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -16,13 +21,18 @@ public class AnalysisController {
|
||||
private final AnalysisService analysisService;
|
||||
|
||||
@GetMapping("/analysis")
|
||||
public String showAnalysis(Model model) {
|
||||
public String showAnalysis(Model model, HttpSession session) {
|
||||
|
||||
//ログインユーザーの取得(セッション)
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
//分析結果の取得(Service)
|
||||
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId());
|
||||
|
||||
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
|
||||
|
||||
//model格納
|
||||
model.addAttribute("analysisForm", analysisForm);
|
||||
|
||||
return "analysis";
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
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.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationController {
|
||||
|
||||
private final AuthenticationService authenticationService;
|
||||
private final QuestionRepository questionRepository;
|
||||
|
||||
@GetMapping("/authentication")
|
||||
public String showAuthentication(Model model) {
|
||||
|
||||
model.addAttribute("authenticationForm", new AuthenticationForm());
|
||||
model.addAttribute("questionList", questionRepository.findAll());
|
||||
|
||||
return "authentication";
|
||||
}
|
||||
|
||||
@PostMapping("/authentication")
|
||||
public String authenticate(
|
||||
AuthenticationForm authenticationForm,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
AuthenticationModel authenticationModel =
|
||||
authenticationService.authenticate(authenticationForm);
|
||||
|
||||
if (authenticationModel == null) {
|
||||
model.addAttribute("errorMessage", "認証情報が正しくありません。");
|
||||
model.addAttribute("questionList", questionRepository.findAll());
|
||||
|
||||
return "authentication";
|
||||
}
|
||||
|
||||
session.setAttribute(
|
||||
"passwordResetUserId",
|
||||
authenticationModel.getUserId());
|
||||
|
||||
return "password_reset";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import com.example.demo.app.domain.service.CourseInfoService;
|
||||
import com.example.demo.app.domain.service.CourseService;
|
||||
import com.example.demo.app.presentation.form.CourseForm;
|
||||
import com.example.demo.app.presentation.form.CourseInfoForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class CourseController {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(CourseController.class.getName());
|
||||
// エラーメッセージ用の定数フィールド
|
||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||
|
||||
// private final HttpSession httpSession;
|
||||
private final CourseService courseService;
|
||||
private final CourseInfoService courseInfoService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/select-course")
|
||||
public String select(Model model) {
|
||||
|
||||
//try {
|
||||
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
||||
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
|
||||
return "select-course";
|
||||
|
||||
//} catch (Exception e) {
|
||||
// // ログイン情報の破棄
|
||||
// httpSession.invalidate();
|
||||
//
|
||||
// e.printStackTrace();
|
||||
//
|
||||
// // エラーログ出力
|
||||
// LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||
// // エラー画面遷移
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -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,32 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.AnalysisModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AnalysisForm {
|
||||
|
||||
private Integer currentMonthTotalAmount;
|
||||
private Integer previousMonthTotalAmount;
|
||||
private Integer totalDifferenceAmount;
|
||||
private List<CategoryAnalysisForm> categoryAnalysisFormList;
|
||||
|
||||
public static AnalysisForm convertFrom(
|
||||
AnalysisModel analysisModel) {
|
||||
|
||||
return new AnalysisForm(
|
||||
analysisModel.getCurrentMonthTotalAmount(),
|
||||
analysisModel.getPreviousMonthTotalAmount(),
|
||||
analysisModel.getTotalDifferenceAmount(),
|
||||
CategoryAnalysisForm.convertFrom(
|
||||
analysisModel.getCategoryAnalysisModelList()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AuthenticationForm {
|
||||
private String mailAddress;
|
||||
private Integer secretQuestionId;
|
||||
private String secretAnswer;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CategoryAnalysisModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CategoryAnalysisForm {
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer currentMonthAmount;
|
||||
|
||||
private Integer previousMonthAmount;
|
||||
|
||||
private Integer monthDifferenceAmount;
|
||||
|
||||
private Integer courseLimitAmount;
|
||||
|
||||
private Integer courseDifferenceAmount;
|
||||
|
||||
public static CategoryAnalysisForm convertFrom(
|
||||
|
||||
CategoryAnalysisModel categoryAnalysisModel) {
|
||||
return new CategoryAnalysisForm(
|
||||
categoryAnalysisModel.getCategoryName(),
|
||||
categoryAnalysisModel.getCurrentMonthAmount(),
|
||||
categoryAnalysisModel.getPreviousMonthAmount(),
|
||||
categoryAnalysisModel.getMonthDifferenceAmount(),
|
||||
categoryAnalysisModel.getCourseLimitAmount(),
|
||||
categoryAnalysisModel.getCourseDifferenceAmount());
|
||||
}
|
||||
|
||||
public static List<CategoryAnalysisForm> convertFrom(
|
||||
List<CategoryAnalysisModel> categoryAnalysisModelList) {
|
||||
|
||||
return categoryAnalysisModelList.stream()
|
||||
.map(CategoryAnalysisForm::convertFrom)
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CourseForm {
|
||||
|
||||
private Long courseId;
|
||||
private String courseName;
|
||||
private String description;
|
||||
|
||||
|
||||
public static CourseForm convertFrom(CourseModel courseModel) {
|
||||
return new CourseForm(
|
||||
courseModel.getCourseId(),
|
||||
courseModel.getCourseName(),
|
||||
courseModel.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
public static List<CourseForm> convertFrom(List<CourseModel> courseModelList){
|
||||
return courseModelList.stream().map(CourseForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CourseInfoForm {
|
||||
|
||||
private Long courseId;
|
||||
|
||||
private String courseName;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer allocationRatio;
|
||||
|
||||
|
||||
public static CourseInfoForm convertFrom(CourseInfoModel courseInfoModel ) {
|
||||
return new CourseInfoForm(courseInfoModel.getCategoryId(), courseInfoModel.getCourseName(), courseInfoModel.getCategoryId(), courseInfoModel.getCategoryName(), courseInfoModel.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<CourseInfoForm> convertFrom(List<CourseInfoModel> courseInfoModelList ) {
|
||||
return courseInfoModelList.stream().map(CourseInfoForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CourseInfoModel convertTo(CourseInfoForm courseInfoForm) {
|
||||
return new CourseInfoModel(
|
||||
courseInfoForm.getCourseId(),
|
||||
courseInfoForm.getCourseName(),
|
||||
courseInfoForm.getCategoryId(),
|
||||
courseInfoForm.getCategoryName(),
|
||||
courseInfoForm.getAllocationRatio());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>認証</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1>本人認証確認</h1>
|
||||
|
||||
<form th:action="@{/authentication}" th:object="${authenticationForm}" method="post">
|
||||
|
||||
<div>
|
||||
<label for="mailAddress">メールアドレス</label>
|
||||
<input type="email" id="mailAddress" th:field="*{mailAddress}">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="secretQuestionId">秘密の質問</label>
|
||||
<select id="secretQuestionId" th:field="*{secretQuestionId}">
|
||||
|
||||
<option value="">選択してください</option>
|
||||
|
||||
<option th:each="question : ${questionList}" th:value="${question.secretQuestionId}"
|
||||
th:text="${question.questionText}">
|
||||
</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="secretAnswer">秘密の質問の回答</label>
|
||||
<input type="text" id="secretAnswer" th:field="*{secretAnswer}">
|
||||
</div>
|
||||
|
||||
<button type="submit">確認</button>
|
||||
|
||||
</form>
|
||||
|
||||
<form th:action="@{/login}" method="get">
|
||||
<button type="submit">戻る</button>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<script th:if="${errorMessage}" th:inline="javascript">
|
||||
alert(/*[[${errorMessage}]]*/);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -12,7 +12,7 @@
|
||||
<table class="table text-center">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">カテゴリ別</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col">支出</th>
|
||||
<th scope="col">前月比</th>
|
||||
</tr>
|
||||
@@ -20,8 +20,17 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">総支出</th>
|
||||
<td>¥234,000</td>
|
||||
<td>+¥38,000</td>
|
||||
<td th:text="'¥' + ${analysisForm.currentMonthTotalAmount}">
|
||||
0
|
||||
</td>
|
||||
<td th:text="${analysisForm.totalDifferenceAmount >= 0}
|
||||
? '+' + ${analysisForm.totalDifferenceAmount}
|
||||
: '-' + ${analysisForm.totalDifferenceAmount}"
|
||||
th:class="${analysisForm.totalDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
0
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -33,24 +42,42 @@
|
||||
<tr>
|
||||
<th scope="col">カテゴリ別</th>
|
||||
<th scope="col">支出</th>
|
||||
<th scope="col">前月比<br>コース比</th>
|
||||
<th scope="col">
|
||||
前月比
|
||||
<br>
|
||||
コース比
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">食費</th>
|
||||
<td>¥34,000</td>
|
||||
<td>+¥8,000<br>+¥1,100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">交通費</th>
|
||||
<td>¥14,000</td>
|
||||
<td>+¥8,000<br>+¥1,100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">日用品</th>
|
||||
<td>¥4,000</td>
|
||||
<td>+¥8,000<br>+¥1,100</td>
|
||||
<tr th:each="category : ${analysisForm.categoryAnalysisFormList}">
|
||||
|
||||
<th scope="row"
|
||||
th:text="${category.categoryName}">
|
||||
食費
|
||||
</th>
|
||||
|
||||
<td th:text="'¥' + ${category.currentMonthAmount}">
|
||||
0
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span th:text="${category.monthDifferenceAmount >= 0}
|
||||
? '+' + ${category.monthDifferenceAmount}
|
||||
: '-' + ${category.monthDifferenceAmount}"
|
||||
th:class="${category.monthDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
</span>
|
||||
<br>
|
||||
<span th:text="${category.courseDifferenceAmount >= 0}
|
||||
? '+' + ${category.courseDifferenceAmount}
|
||||
: '-' + ${category.courseDifferenceAmount}"
|
||||
th:class="${category.courseDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
35
src/main/resources/templates/select_course.html
Normal file
35
src/main/resources/templates/select_course.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>コース選択</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="accordion" id="accordionExample">
|
||||
<div class="accordion-item" th:each="course:${courseList}">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
|
||||
<span th:text="${course.courseName}"></span>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
|
||||
<div class="accordion-body">
|
||||
<span th:text="${course.description}"></span>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>カテゴリ名</th><tr>配分(%)</tr>
|
||||
</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>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user