Merge branch 'n-kawahito' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,8 +20,8 @@
|
||||
<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</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -33,24 +33,32 @@
|
||||
<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}">
|
||||
</span>
|
||||
<br>
|
||||
<span th:text="'¥' + ${category.courseDifferenceAmount}">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user