Merge remote-tracking branch 'origin/n-kawahito' into s-choi
# Conflicts: # src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java
This commit is contained in:
@@ -5,6 +5,10 @@ import lombok.Getter;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class AuthenticationModel {
|
public class AllocationModel {
|
||||||
private Long userId;
|
|
||||||
|
private Long categoryId;
|
||||||
|
private Long courseId;
|
||||||
|
private Integer allocationRatio;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ public class CategoryAnalysisModel {
|
|||||||
|
|
||||||
private Integer previousMonthAmount;
|
private Integer previousMonthAmount;
|
||||||
|
|
||||||
private Integer previousMonthDifferenceAmount;
|
private Integer monthDifferenceAmount;
|
||||||
|
|
||||||
private Integer courseLimitAmount;
|
private Integer courseLimitAmount;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class UserModel {
|
public class UserModel {
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
private String userName;
|
private String userName;
|
||||||
private String mailAddress;
|
private String emailAddress;
|
||||||
private String password;
|
private String password;
|
||||||
private Integer secretQuestionId;
|
private Integer secretQuestionId;
|
||||||
private String secretAnswer;
|
private String secretAnswer;
|
||||||
@@ -18,7 +19,7 @@ public class UserModel {
|
|||||||
private Integer saving;
|
private Integer saving;
|
||||||
private Integer annualIncome;
|
private Integer annualIncome;
|
||||||
private Integer monthlyBudget;
|
private Integer monthlyBudget;
|
||||||
private Long goalId;
|
private Integer goalId;
|
||||||
private Long courseId;
|
private Integer courseId;
|
||||||
private Integer deleteFlag;
|
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;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.AnalysisModel;
|
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.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;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -12,29 +24,119 @@ import lombok.RequiredArgsConstructor;
|
|||||||
public class AnalysisServiceImpl implements AnalysisService {
|
public class AnalysisServiceImpl implements AnalysisService {
|
||||||
|
|
||||||
//Repositoryの呼び出し
|
//Repositoryの呼び出し
|
||||||
// private final TransactionRepository transactionRepository;
|
private final TransactionRepository transactionRepository;
|
||||||
// private final AllocationRepository allocationRepository;
|
private final AllocationRepository allocationRepository;
|
||||||
// private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
// private final CategoryRepository categoryRepository;
|
private final CategoryRepository categoryRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnalysisModel getAnalysis(Long userId) {
|
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());
|
||||||
// 前月の支出取得
|
|
||||||
// コース配分取得
|
|
||||||
// カテゴリ別集計
|
|
||||||
// 前月との差額集計
|
|
||||||
//総支出算出
|
|
||||||
// コース限度額算出、コース別差額算出
|
|
||||||
// CategoryAnalysisModel生成
|
|
||||||
// AnalysisModelの生成
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.example.demo.app.infra.entity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.IdClass;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.AllocationModel;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "allocation")
|
@IdClass(AllocationId.class)
|
||||||
|
@Table(name = "allocation_m")
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -33,4 +39,15 @@ public class AllocationEntity {
|
|||||||
@Column(name = "allocation_ratio", nullable = false)
|
@Column(name = "allocation_ratio", nullable = false)
|
||||||
private Integer allocationRatio;
|
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.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import com.example.demo.app.domain.model.CourseModel;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "course")
|
@Table(name = "course_m")
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -39,6 +40,18 @@ public class CourseEntity {
|
|||||||
private List<UserEntity> userEntity;
|
private List<UserEntity> userEntity;
|
||||||
|
|
||||||
@OneToOne(mappedBy = "courseEntity")
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class QuestionEntity {
|
|||||||
@Column(name = "question_text", nullable = false)
|
@Column(name = "question_text", nullable = false)
|
||||||
private String questionText;
|
private String questionText;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "QuestionEntity")
|
@OneToMany(mappedBy = "questionEntity")
|
||||||
private List<UserEntity> userEntity;
|
private List<UserEntity> userEntity;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
|
|
||||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||||
|
import com.example.demo.app.infra.entity.AllocationId;
|
||||||
|
|
||||||
public interface AllocationRepository extends JpaRepository<AllocationEntity, AllocationId>{
|
public interface AllocationRepository extends JpaRepository<AllocationEntity, AllocationId>{
|
||||||
|
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.example.demo.app.presentation.controller;
|
package com.example.demo.app.presentation.controller;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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.domain.service.AnalysisService;
|
||||||
|
import com.example.demo.app.presentation.form.AnalysisForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -16,13 +21,18 @@ public class AnalysisController {
|
|||||||
private final AnalysisService analysisService;
|
private final AnalysisService analysisService;
|
||||||
|
|
||||||
@GetMapping("/analysis")
|
@GetMapping("/analysis")
|
||||||
public String showAnalysis(Model model) {
|
public String showAnalysis(Model model, HttpSession session) {
|
||||||
|
|
||||||
//ログインユーザーの取得(セッション)
|
//ログインユーザーの取得(セッション)
|
||||||
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
//分析結果の取得(Service)
|
//分析結果の取得(Service)
|
||||||
|
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId());
|
||||||
|
|
||||||
|
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
|
||||||
|
|
||||||
//model格納
|
//model格納
|
||||||
|
model.addAttribute("analysisForm", analysisForm);
|
||||||
|
|
||||||
return "analysis";
|
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;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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">
|
<table class="table text-center">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">カテゴリ別</th>
|
<th scope="col"></th>
|
||||||
<th scope="col">支出</th>
|
<th scope="col">支出</th>
|
||||||
<th scope="col">前月比</th>
|
<th scope="col">前月比</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -20,8 +20,17 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">総支出</th>
|
<th scope="row">総支出</th>
|
||||||
<td>¥234,000</td>
|
<td th:text="'¥' + ${analysisForm.currentMonthTotalAmount}">
|
||||||
<td>+¥38,000</td>
|
0
|
||||||
|
</td>
|
||||||
|
<td th:text="${analysisForm.totalDifferenceAmount >= 0}
|
||||||
|
? '+' + ${analysisForm.totalDifferenceAmount}
|
||||||
|
: '-' + ${analysisForm.totalDifferenceAmount}"
|
||||||
|
th:class="${analysisForm.totalDifferenceAmount >= 0}
|
||||||
|
? 'color-danger;'
|
||||||
|
: 'color-primary;'">
|
||||||
|
0
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -33,24 +42,42 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="col">カテゴリ別</th>
|
<th scope="col">カテゴリ別</th>
|
||||||
<th scope="col">支出</th>
|
<th scope="col">支出</th>
|
||||||
<th scope="col">前月比<br>コース比</th>
|
<th scope="col">
|
||||||
|
前月比
|
||||||
|
<br>
|
||||||
|
コース比
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr th:each="category : ${analysisForm.categoryAnalysisFormList}">
|
||||||
<th scope="row">食費</th>
|
|
||||||
<td>¥34,000</td>
|
<th scope="row"
|
||||||
<td>+¥8,000<br>+¥1,100</td>
|
th:text="${category.categoryName}">
|
||||||
</tr>
|
食費
|
||||||
<tr>
|
</th>
|
||||||
<th scope="row">交通費</th>
|
|
||||||
<td>¥14,000</td>
|
<td th:text="'¥' + ${category.currentMonthAmount}">
|
||||||
<td>+¥8,000<br>+¥1,100</td>
|
0
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
|
||||||
<th scope="row">日用品</th>
|
<td>
|
||||||
<td>¥4,000</td>
|
<span th:text="${category.monthDifferenceAmount >= 0}
|
||||||
<td>+¥8,000<br>+¥1,100</td>
|
? '+' + ${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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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