@k2works/claude-code-booster 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assets/docs/article/index.md +4 -1
- package/lib/assets/docs/article/practical-database-design/index.md +121 -0
- package/lib/assets/docs/article/practical-database-design/part1/chapter01.md +288 -0
- package/lib/assets/docs/article/practical-database-design/part1/chapter02.md +518 -0
- package/lib/assets/docs/article/practical-database-design/part1/chapter03.md +557 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter04.md +924 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter05.md +1627 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter06.md +2716 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter07.md +2082 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter08.md +2105 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter09.md +2031 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter10.md +1387 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter11.md +1677 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter12.md +1417 -0
- package/lib/assets/docs/article/practical-database-design/part2/chapter13.md +1434 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter14.md +667 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter15.md +1625 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter16.md +1915 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter17.md +1708 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter18.md +2095 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter19.md +1123 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter20.md +1031 -0
- package/lib/assets/docs/article/practical-database-design/part3/chapter21.md +1382 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter14-orm.md +991 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter15-orm.md +1300 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter16-orm.md +1166 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter17-orm.md +1584 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter18-orm.md +1183 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter19-orm.md +1016 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter20-orm.md +1753 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter21-orm.md +1447 -0
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter22-orm.md +1878 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter22.md +965 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter23.md +2069 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter24.md +2439 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter25.md +3661 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter26.md +2916 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter27.md +3105 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter28.md +2697 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter29.md +2544 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter30.md +2180 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter31.md +1192 -0
- package/lib/assets/docs/article/practical-database-design/part4/chapter32.md +2101 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter33.md +1032 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter34.md +1609 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter35.md +1453 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter36.md +1292 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter37.md +1470 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter38.md +1698 -0
- package/lib/assets/docs/article/practical-database-design/part5/chapter39.md +2334 -0
- package/lib/assets/docs/article/practical-database-design/study/study2-1.md +1693 -0
- package/lib/assets/docs/article/practical-database-design/study/study2-2.md +1347 -0
- package/lib/assets/docs/article/practical-database-design/study/study2-3.md +2044 -0
- package/lib/assets/docs/article/practical-database-design/study/study2-4.md +2229 -0
- package/lib/assets/docs/article/practical-database-design/study/study2-5.md +2418 -0
- package/lib/assets/docs/article/practical-database-design/study/study3-1.md +2205 -0
- package/lib/assets/docs/article/practical-database-design/study/study3-2.md +2221 -0
- package/lib/assets/docs/article/practical-database-design/study/study3-3.md +2253 -0
- package/lib/assets/docs/article/practical-database-design/study/study3-4.md +2106 -0
- package/lib/assets/docs/article/practical-database-design/study/study3-5.md +2507 -0
- package/lib/assets/docs/article/practical-database-design/study/study4-1.md +2587 -0
- package/lib/assets/docs/article/practical-database-design/study/study4-2.md +2075 -0
- package/lib/assets/docs/article/practical-database-design/study/study4-3.md +1805 -0
- package/lib/assets/docs/article/practical-database-design/study/study4-4.md +1895 -0
- package/lib/assets/docs/article/practical-database-design/study/study4-5.md +2878 -0
- package/lib/assets/docs/reference//351/201/213/345/226/266/347/256/241/347/220/206.md +131 -39
- package/package.json +1 -1
|
@@ -0,0 +1,2205 @@
|
|
|
1
|
+
# 実践データベース設計:財務会計システム 研究 1 - モノリスサービスの実装
|
|
2
|
+
|
|
3
|
+
## はじめに
|
|
4
|
+
|
|
5
|
+
本研究では、API サーバー構成(第21章)とは異なるアプローチとして、**モノリスアーキテクチャ**による財務会計システムを実装します。UI(テンプレートエンジン)、ビジネスロジック、データベースアクセスがすべて同一サーバー内で動作する、伝統的かつ堅実なアーキテクチャです。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 第22章:モノリスアーキテクチャの基礎
|
|
10
|
+
|
|
11
|
+
### 22.1 モノリスアーキテクチャとは
|
|
12
|
+
|
|
13
|
+
**モノリス(Monolith / Monolithic Architecture)**とは、「API」と「UI」と「ビジネスロジック」が **1つの実行ユニット**(1つのプロジェクトやバイナリ)にまとまっているアーキテクチャを指します。
|
|
14
|
+
|
|
15
|
+
```plantuml
|
|
16
|
+
@startuml monolith_architecture
|
|
17
|
+
|
|
18
|
+
title モノリスアーキテクチャ(財務会計システム)
|
|
19
|
+
|
|
20
|
+
package "モノリスサーバー (単一の実行ユニット)" {
|
|
21
|
+
|
|
22
|
+
package "プレゼンテーション層" {
|
|
23
|
+
[Controller]
|
|
24
|
+
[Thymeleaf テンプレート]
|
|
25
|
+
[静的リソース (CSS/JS)]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
package "ビジネスロジック層" {
|
|
29
|
+
[Application Service]
|
|
30
|
+
[Domain Model]
|
|
31
|
+
[Domain Service]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
package "データアクセス層" {
|
|
35
|
+
[Repository]
|
|
36
|
+
[MyBatis Mapper]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
database "PostgreSQL" as DB
|
|
41
|
+
|
|
42
|
+
actor "ブラウザ" as Browser
|
|
43
|
+
|
|
44
|
+
Browser --> [Controller] : HTTP リクエスト
|
|
45
|
+
[Controller] --> [Thymeleaf テンプレート] : モデル渡し
|
|
46
|
+
[Thymeleaf テンプレート] --> Browser : HTML レスポンス
|
|
47
|
+
[Controller] --> [Application Service]
|
|
48
|
+
[Application Service] --> [Domain Model]
|
|
49
|
+
[Application Service] --> [Repository]
|
|
50
|
+
[Repository] --> [MyBatis Mapper]
|
|
51
|
+
[MyBatis Mapper] --> DB
|
|
52
|
+
|
|
53
|
+
note right of "モノリスサーバー (単一の実行ユニット)"
|
|
54
|
+
すべてが1つのプロセスで動作
|
|
55
|
+
- 同一JVMで実行
|
|
56
|
+
- 同一デプロイユニット
|
|
57
|
+
- 密結合だが開発・運用がシンプル
|
|
58
|
+
end note
|
|
59
|
+
|
|
60
|
+
@enduml
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**モノリスの主な特徴:**
|
|
64
|
+
|
|
65
|
+
| 特徴 | 説明 |
|
|
66
|
+
|------|------|
|
|
67
|
+
| **単一デプロイ** | アプリケーション全体が1つのアーティファクト(JAR/WAR)としてデプロイ |
|
|
68
|
+
| **同一プロセス** | UI、ビジネスロジック、データアクセスが同じ JVM で動作 |
|
|
69
|
+
| **テンプレートエンジン** | サーバーサイドで HTML を生成してブラウザに返却 |
|
|
70
|
+
| **セッション管理** | サーバーサイドでユーザーセッションを管理 |
|
|
71
|
+
| **トランザクション境界** | 単一プロセス内でのローカルトランザクション |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### 22.2 API サーバー vs モノリス
|
|
76
|
+
|
|
77
|
+
```plantuml
|
|
78
|
+
@startuml api_vs_monolith
|
|
79
|
+
|
|
80
|
+
left to right direction
|
|
81
|
+
|
|
82
|
+
package "API サーバー構成(疎結合)" {
|
|
83
|
+
package "フロントエンド" as FE {
|
|
84
|
+
[React/Vue/Angular]
|
|
85
|
+
[SPA]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
package "バックエンド" as BE {
|
|
89
|
+
[REST API]
|
|
90
|
+
[JSON レスポンス]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
database "DB1" as DB_API
|
|
94
|
+
|
|
95
|
+
FE --> BE : HTTP/JSON
|
|
96
|
+
BE --> DB_API
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
package "モノリス構成(密結合)" {
|
|
100
|
+
package "モノリスサーバー" as Mono {
|
|
101
|
+
[Controller + View]
|
|
102
|
+
[テンプレートエンジン]
|
|
103
|
+
[ビジネスロジック]
|
|
104
|
+
[データアクセス]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
database "DB2" as DB_Mono
|
|
108
|
+
|
|
109
|
+
Mono --> DB_Mono
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
actor "ブラウザ (API)" as Browser1
|
|
113
|
+
actor "ブラウザ (Mono)" as Browser2
|
|
114
|
+
|
|
115
|
+
Browser1 --> FE
|
|
116
|
+
Browser2 --> Mono : HTTP (HTML)
|
|
117
|
+
|
|
118
|
+
@enduml
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| 観点 | API サーバー構成 | モノリス構成 |
|
|
122
|
+
|------|-----------------|-------------|
|
|
123
|
+
| **結合度** | 疎結合(フロントエンドとバックエンドが分離) | 密結合(すべてが同一サーバー) |
|
|
124
|
+
| **フロントエンド** | SPA(React/Vue/Angular) | テンプレートエンジン(Thymeleaf) |
|
|
125
|
+
| **通信方式** | REST API(JSON) | サーバーサイドレンダリング(HTML) |
|
|
126
|
+
| **開発チーム** | フロント/バックエンドで分業可能 | フルスタックで開発 |
|
|
127
|
+
| **デプロイ** | 別々にデプロイ可能 | 単一アーティファクトをデプロイ |
|
|
128
|
+
| **スケーリング** | 個別にスケール可能 | 全体をスケール |
|
|
129
|
+
| **複雑さ** | API 設計・認証・CORS などが必要 | シンプル、設定が少ない |
|
|
130
|
+
| **初期開発速度** | 環境構築に時間がかかる | 素早く開発開始できる |
|
|
131
|
+
| **SEO** | SSR/SSG が必要な場合あり | サーバーサイドレンダリングで SEO フレンドリー |
|
|
132
|
+
|
|
133
|
+
### 22.3 モノリスを選択すべき場面
|
|
134
|
+
|
|
135
|
+
**モノリスが適している状況:**
|
|
136
|
+
|
|
137
|
+
1. **小〜中規模のチーム**:専門のフロントエンドチームがいない場合
|
|
138
|
+
2. **社内システム**:SEO 不要、限られたユーザー数
|
|
139
|
+
3. **業務アプリケーション**:複雑な業務フローをサーバーサイドで処理
|
|
140
|
+
4. **迅速な開発**:MVP やプロトタイプの素早い構築
|
|
141
|
+
5. **運用コスト重視**:インフラ構成をシンプルに保ちたい場合
|
|
142
|
+
|
|
143
|
+
**財務会計システムにおけるモノリスのメリット:**
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
財務会計システムの特性
|
|
147
|
+
├── 社内利用が中心 → SEO 不要、SPA 不要
|
|
148
|
+
├── 複雑な業務フロー → サーバーサイドで制御が容易
|
|
149
|
+
├── 帳票出力 → サーバーサイドで PDF/Excel 生成
|
|
150
|
+
├── 月次締め・決算処理 → バッチ処理との親和性
|
|
151
|
+
├── 監査証跡 → サーバーサイドでのログ管理
|
|
152
|
+
└── 運用担当者のスキル → シンプルな構成が望ましい
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
### 22.4 モノリスにおけるヘキサゴナルアーキテクチャ
|
|
158
|
+
|
|
159
|
+
モノリスであっても、ヘキサゴナルアーキテクチャ(Ports and Adapters)を採用することで、保守性の高い設計を実現できます。
|
|
160
|
+
|
|
161
|
+
```plantuml
|
|
162
|
+
@startuml hexagonal_monolith
|
|
163
|
+
|
|
164
|
+
' 左右のレイアウトを強制
|
|
165
|
+
left to right direction
|
|
166
|
+
|
|
167
|
+
package "Hexagonal Architecture (財務会計モノリス版)" {
|
|
168
|
+
|
|
169
|
+
rectangle "Application Core\n(Domain + Use Cases)" as core {
|
|
170
|
+
note as core_list
|
|
171
|
+
- Account (勘定科目)
|
|
172
|
+
- Journal (仕訳)
|
|
173
|
+
- Balance (残高)
|
|
174
|
+
- JournalDomainService
|
|
175
|
+
- AccountUseCase
|
|
176
|
+
- JournalUseCase
|
|
177
|
+
- BalanceUseCase
|
|
178
|
+
end note
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
rectangle "Input Adapters\n(Driving Side)" as input {
|
|
182
|
+
note as input_list
|
|
183
|
+
- Thymeleaf Controller
|
|
184
|
+
- フォーム処理
|
|
185
|
+
- セッション管理
|
|
186
|
+
- リクエスト検証
|
|
187
|
+
end note
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
rectangle "Output Adapters\n(Driven Side)" as output {
|
|
191
|
+
note as output_list
|
|
192
|
+
- MyBatis Repository
|
|
193
|
+
- Database Access
|
|
194
|
+
- Entity Mapping
|
|
195
|
+
- 帳票出力 (PDF/Excel)
|
|
196
|
+
end note
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
' 接続線をパッケージ内に配置し、方向を指定
|
|
200
|
+
input --> core : "Input Ports\n(Use Cases)"
|
|
201
|
+
core --> output : "Output Ports\n(Repository Interfaces)"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
' 注釈の配置
|
|
205
|
+
note top of core
|
|
206
|
+
純粋なビジネスロジック
|
|
207
|
+
UI 技術(Thymeleaf)に依存しない
|
|
208
|
+
テスト可能な状態を維持
|
|
209
|
+
end note
|
|
210
|
+
|
|
211
|
+
note bottom of input
|
|
212
|
+
HTML フォームからの入力
|
|
213
|
+
サーバーサイドレンダリング
|
|
214
|
+
セッションベースの認証
|
|
215
|
+
end note
|
|
216
|
+
|
|
217
|
+
note bottom of output
|
|
218
|
+
PostgreSQL + MyBatis
|
|
219
|
+
帳票生成(PDF/Excel)
|
|
220
|
+
ファイル出力
|
|
221
|
+
end note
|
|
222
|
+
|
|
223
|
+
@enduml
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**モノリスでもヘキサゴナルアーキテクチャを適用する理由:**
|
|
227
|
+
|
|
228
|
+
1. **テスト容易性**:ドメインロジックを UI から分離してテスト可能
|
|
229
|
+
2. **将来の移行**:必要に応じて API 層を追加可能
|
|
230
|
+
3. **保守性**:関心の分離により変更影響を局所化
|
|
231
|
+
4. **再利用性**:ドメインロジックを複数の UI で共有可能
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### 22.5 ディレクトリ構成
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
src/main/java/com/example/accounting/
|
|
239
|
+
├── domain/ # ドメイン層(API版と共通)
|
|
240
|
+
│ ├── model/
|
|
241
|
+
│ │ ├── account/ # 勘定科目
|
|
242
|
+
│ │ ├── journal/ # 仕訳
|
|
243
|
+
│ │ ├── balance/ # 残高
|
|
244
|
+
│ │ └── department/ # 部門
|
|
245
|
+
│ └── exception/
|
|
246
|
+
│
|
|
247
|
+
├── application/ # アプリケーション層(API版と共通)
|
|
248
|
+
│ ├── port/
|
|
249
|
+
│ │ ├── in/ # Input Port(ユースケース)
|
|
250
|
+
│ │ └── out/ # Output Port(リポジトリ)
|
|
251
|
+
│ └── service/
|
|
252
|
+
│
|
|
253
|
+
├── infrastructure/
|
|
254
|
+
│ ├── persistence/ # Output Adapter(DB実装)
|
|
255
|
+
│ │ ├── mapper/
|
|
256
|
+
│ │ └── repository/
|
|
257
|
+
│ └── web/ # Input Adapter(Web実装)
|
|
258
|
+
│ ├── controller/ # Thymeleaf Controller
|
|
259
|
+
│ ├── form/ # フォームオブジェクト
|
|
260
|
+
│ └── helper/ # ビューヘルパー
|
|
261
|
+
│
|
|
262
|
+
├── config/
|
|
263
|
+
│
|
|
264
|
+
└── resources/
|
|
265
|
+
├── templates/ # Thymeleaf テンプレート
|
|
266
|
+
│ ├── layout/ # 共通レイアウト
|
|
267
|
+
│ ├── accounts/ # 勘定科目マスタ画面
|
|
268
|
+
│ ├── journals/ # 仕訳入力画面
|
|
269
|
+
│ ├── balances/ # 残高照会画面
|
|
270
|
+
│ └── reports/ # 帳票出力画面
|
|
271
|
+
├── static/ # 静的リソース
|
|
272
|
+
│ ├── css/
|
|
273
|
+
│ ├── js/
|
|
274
|
+
│ └── images/
|
|
275
|
+
└── messages.properties # メッセージリソース
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
### 22.6 技術スタックの導入
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary>build.gradle.kts</summary>
|
|
284
|
+
|
|
285
|
+
```kotlin
|
|
286
|
+
plugins {
|
|
287
|
+
id("java")
|
|
288
|
+
id("org.springframework.boot") version "3.2.0"
|
|
289
|
+
id("io.spring.dependency-management") version "1.1.4"
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
java {
|
|
293
|
+
toolchain {
|
|
294
|
+
languageVersion = JavaLanguageVersion.of(21)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
dependencies {
|
|
299
|
+
// Spring Boot Web(REST APIではなくMVCとして使用)
|
|
300
|
+
implementation("org.springframework.boot:spring-boot-starter-web")
|
|
301
|
+
implementation("org.springframework.boot:spring-boot-starter-validation")
|
|
302
|
+
|
|
303
|
+
// Thymeleaf(テンプレートエンジン)
|
|
304
|
+
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
|
305
|
+
implementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0")
|
|
306
|
+
|
|
307
|
+
// Thymeleaf + Spring Security(認証機能を使う場合)
|
|
308
|
+
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6")
|
|
309
|
+
|
|
310
|
+
// htmx(モダンなインタラクティブUI)
|
|
311
|
+
// CDN から読み込むため依存関係は不要
|
|
312
|
+
|
|
313
|
+
// MyBatis
|
|
314
|
+
implementation("org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3")
|
|
315
|
+
|
|
316
|
+
// PostgreSQL
|
|
317
|
+
runtimeOnly("org.postgresql:postgresql")
|
|
318
|
+
|
|
319
|
+
// Flyway
|
|
320
|
+
implementation("org.flywaydb:flyway-core")
|
|
321
|
+
implementation("org.flywaydb:flyway-database-postgresql")
|
|
322
|
+
|
|
323
|
+
// Webjars(Bootstrap等のフロントエンドライブラリ)
|
|
324
|
+
implementation("org.webjars:bootstrap:5.3.2")
|
|
325
|
+
implementation("org.webjars:webjars-locator-core:0.55")
|
|
326
|
+
|
|
327
|
+
// 帳票出力
|
|
328
|
+
implementation("org.apache.poi:poi-ooxml:5.2.5") // Excel
|
|
329
|
+
implementation("com.itextpdf:itext7-core:8.0.2") // PDF
|
|
330
|
+
|
|
331
|
+
// Test
|
|
332
|
+
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
333
|
+
testImplementation("org.testcontainers:postgresql:1.19.3")
|
|
334
|
+
testImplementation("org.testcontainers:junit-jupiter:1.19.3")
|
|
335
|
+
|
|
336
|
+
// Lombok
|
|
337
|
+
compileOnly("org.projectlombok:lombok")
|
|
338
|
+
annotationProcessor("org.projectlombok:lombok")
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
</details>
|
|
343
|
+
|
|
344
|
+
**パッケージの説明:**
|
|
345
|
+
|
|
346
|
+
| パッケージ | 用途 |
|
|
347
|
+
|-----------|------|
|
|
348
|
+
| spring-boot-starter-thymeleaf | サーバーサイドテンプレートエンジン |
|
|
349
|
+
| thymeleaf-layout-dialect | レイアウト継承(共通ヘッダー・フッター) |
|
|
350
|
+
| webjars:bootstrap | CSS フレームワーク(サーバーから配信) |
|
|
351
|
+
| poi-ooxml | Excel ファイル出力(帳票) |
|
|
352
|
+
| itext7-core | PDF ファイル出力(帳票) |
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
### 22.7 基本的な Spring Boot + Thymeleaf アプリケーション
|
|
357
|
+
|
|
358
|
+
<details>
|
|
359
|
+
<summary>アプリケーションクラス</summary>
|
|
360
|
+
|
|
361
|
+
```java
|
|
362
|
+
package com.example.accounting;
|
|
363
|
+
|
|
364
|
+
import org.springframework.boot.SpringApplication;
|
|
365
|
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
366
|
+
|
|
367
|
+
@SpringBootApplication
|
|
368
|
+
public class AccountingApplication {
|
|
369
|
+
|
|
370
|
+
public static void main(String[] args) {
|
|
371
|
+
SpringApplication.run(AccountingApplication.class, args);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
</details>
|
|
377
|
+
|
|
378
|
+
<details>
|
|
379
|
+
<summary>application.yml</summary>
|
|
380
|
+
|
|
381
|
+
```yaml
|
|
382
|
+
spring:
|
|
383
|
+
datasource:
|
|
384
|
+
url: jdbc:postgresql://localhost:5432/accounting
|
|
385
|
+
username: postgres
|
|
386
|
+
password: postgres
|
|
387
|
+
|
|
388
|
+
thymeleaf:
|
|
389
|
+
cache: false # 開発時はキャッシュ無効
|
|
390
|
+
prefix: classpath:/templates/
|
|
391
|
+
suffix: .html
|
|
392
|
+
encoding: UTF-8
|
|
393
|
+
mode: HTML
|
|
394
|
+
|
|
395
|
+
messages:
|
|
396
|
+
basename: messages
|
|
397
|
+
encoding: UTF-8
|
|
398
|
+
|
|
399
|
+
mybatis:
|
|
400
|
+
mapper-locations: classpath:mapper/*.xml
|
|
401
|
+
configuration:
|
|
402
|
+
map-underscore-to-camel-case: true
|
|
403
|
+
|
|
404
|
+
server:
|
|
405
|
+
servlet:
|
|
406
|
+
session:
|
|
407
|
+
timeout: 30m # セッションタイムアウト
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
</details>
|
|
411
|
+
|
|
412
|
+
<details>
|
|
413
|
+
<summary>共通レイアウト(layout/default.html)</summary>
|
|
414
|
+
|
|
415
|
+
```html
|
|
416
|
+
<!DOCTYPE html>
|
|
417
|
+
<html xmlns:th="http://www.thymeleaf.org"
|
|
418
|
+
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
419
|
+
lang="ja">
|
|
420
|
+
<head>
|
|
421
|
+
<meta charset="UTF-8">
|
|
422
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
423
|
+
<title layout:title-pattern="$CONTENT_TITLE - $LAYOUT_TITLE">財務会計システム</title>
|
|
424
|
+
|
|
425
|
+
<!-- Bootstrap CSS -->
|
|
426
|
+
<link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}">
|
|
427
|
+
|
|
428
|
+
<!-- カスタム CSS -->
|
|
429
|
+
<link rel="stylesheet" th:href="@{/css/style.css}">
|
|
430
|
+
|
|
431
|
+
<!-- htmx(部分更新用) -->
|
|
432
|
+
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
|
433
|
+
</head>
|
|
434
|
+
<body>
|
|
435
|
+
<!-- ナビゲーションバー -->
|
|
436
|
+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
437
|
+
<div class="container-fluid">
|
|
438
|
+
<a class="navbar-brand" th:href="@{/}">財務会計システム</a>
|
|
439
|
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
|
440
|
+
data-bs-target="#navbarNav">
|
|
441
|
+
<span class="navbar-toggler-icon"></span>
|
|
442
|
+
</button>
|
|
443
|
+
<div class="collapse navbar-collapse" id="navbarNav">
|
|
444
|
+
<ul class="navbar-nav">
|
|
445
|
+
<li class="nav-item dropdown">
|
|
446
|
+
<a class="nav-link dropdown-toggle" href="#" role="button"
|
|
447
|
+
data-bs-toggle="dropdown">マスタ</a>
|
|
448
|
+
<ul class="dropdown-menu">
|
|
449
|
+
<li><a class="dropdown-item" th:href="@{/accounts}">勘定科目マスタ</a></li>
|
|
450
|
+
<li><a class="dropdown-item" th:href="@{/account-structures}">勘定科目構成</a></li>
|
|
451
|
+
<li><a class="dropdown-item" th:href="@{/tax-transactions}">課税取引マスタ</a></li>
|
|
452
|
+
<li><a class="dropdown-item" th:href="@{/departments}">部門マスタ</a></li>
|
|
453
|
+
</ul>
|
|
454
|
+
</li>
|
|
455
|
+
<li class="nav-item dropdown">
|
|
456
|
+
<a class="nav-link dropdown-toggle" href="#" role="button"
|
|
457
|
+
data-bs-toggle="dropdown">仕訳</a>
|
|
458
|
+
<ul class="dropdown-menu">
|
|
459
|
+
<li><a class="dropdown-item" th:href="@{/journals}">仕訳一覧</a></li>
|
|
460
|
+
<li><a class="dropdown-item" th:href="@{/journals/new}">仕訳入力</a></li>
|
|
461
|
+
<li><a class="dropdown-item" th:href="@{/journals/import}">仕訳取込</a></li>
|
|
462
|
+
</ul>
|
|
463
|
+
</li>
|
|
464
|
+
<li class="nav-item dropdown">
|
|
465
|
+
<a class="nav-link dropdown-toggle" href="#" role="button"
|
|
466
|
+
data-bs-toggle="dropdown">照会</a>
|
|
467
|
+
<ul class="dropdown-menu">
|
|
468
|
+
<li><a class="dropdown-item" th:href="@{/balances/daily}">日次残高照会</a></li>
|
|
469
|
+
<li><a class="dropdown-item" th:href="@{/balances/monthly}">月次残高照会</a></li>
|
|
470
|
+
</ul>
|
|
471
|
+
</li>
|
|
472
|
+
<li class="nav-item dropdown">
|
|
473
|
+
<a class="nav-link dropdown-toggle" href="#" role="button"
|
|
474
|
+
data-bs-toggle="dropdown">帳票</a>
|
|
475
|
+
<ul class="dropdown-menu">
|
|
476
|
+
<li><a class="dropdown-item" th:href="@{/reports/daily}">日計表</a></li>
|
|
477
|
+
<li><a class="dropdown-item" th:href="@{/reports/trial-balance}">合計残高試算表</a></li>
|
|
478
|
+
<li><a class="dropdown-item" th:href="@{/reports/ledger}">総勘定元帳</a></li>
|
|
479
|
+
<li><hr class="dropdown-divider"></li>
|
|
480
|
+
<li><a class="dropdown-item" th:href="@{/reports/balance-sheet}">貸借対照表</a></li>
|
|
481
|
+
<li><a class="dropdown-item" th:href="@{/reports/income-statement}">損益計算書</a></li>
|
|
482
|
+
</ul>
|
|
483
|
+
</li>
|
|
484
|
+
</ul>
|
|
485
|
+
</div>
|
|
486
|
+
</div>
|
|
487
|
+
</nav>
|
|
488
|
+
|
|
489
|
+
<!-- フラッシュメッセージ -->
|
|
490
|
+
<div class="container mt-3">
|
|
491
|
+
<div th:if="${successMessage}" class="alert alert-success alert-dismissible fade show" role="alert">
|
|
492
|
+
<span th:text="${successMessage}"></span>
|
|
493
|
+
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
494
|
+
</div>
|
|
495
|
+
<div th:if="${errorMessage}" class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
496
|
+
<span th:text="${errorMessage}"></span>
|
|
497
|
+
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
498
|
+
</div>
|
|
499
|
+
</div>
|
|
500
|
+
|
|
501
|
+
<!-- メインコンテンツ -->
|
|
502
|
+
<main class="container mt-4">
|
|
503
|
+
<div layout:fragment="content">
|
|
504
|
+
<!-- 各ページのコンテンツがここに挿入される -->
|
|
505
|
+
</div>
|
|
506
|
+
</main>
|
|
507
|
+
|
|
508
|
+
<!-- フッター -->
|
|
509
|
+
<footer class="footer mt-5 py-3 bg-light">
|
|
510
|
+
<div class="container text-center">
|
|
511
|
+
<span class="text-muted">財務会計システム © 2025</span>
|
|
512
|
+
</div>
|
|
513
|
+
</footer>
|
|
514
|
+
|
|
515
|
+
<!-- Bootstrap JS -->
|
|
516
|
+
<script th:src="@{/webjars/bootstrap/js/bootstrap.bundle.min.js}"></script>
|
|
517
|
+
|
|
518
|
+
<!-- ページ固有のスクリプト -->
|
|
519
|
+
<th:block layout:fragment="scripts"></th:block>
|
|
520
|
+
</body>
|
|
521
|
+
</html>
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
</details>
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
### 22.8 htmx による部分更新
|
|
529
|
+
|
|
530
|
+
モノリスアプリケーションでも、**htmx** を使用することで SPA のような操作性を実現できます。ページ全体をリロードせず、必要な部分だけを更新します。
|
|
531
|
+
|
|
532
|
+
```plantuml
|
|
533
|
+
@startuml htmx_flow
|
|
534
|
+
|
|
535
|
+
title htmx による部分更新
|
|
536
|
+
|
|
537
|
+
actor "ブラウザ" as Browser
|
|
538
|
+
participant "htmx" as htmx
|
|
539
|
+
participant "Controller" as Controller
|
|
540
|
+
participant "Thymeleaf\nフラグメント" as Fragment
|
|
541
|
+
|
|
542
|
+
Browser -> htmx : ボタンクリック
|
|
543
|
+
htmx -> Controller : AJAX リクエスト\n(hx-get/hx-post)
|
|
544
|
+
Controller -> Fragment : フラグメントを\nレンダリング
|
|
545
|
+
Fragment --> Controller : HTML フラグメント
|
|
546
|
+
Controller --> htmx : HTML レスポンス
|
|
547
|
+
htmx -> Browser : DOM を部分更新\n(hx-target)
|
|
548
|
+
|
|
549
|
+
note right of htmx
|
|
550
|
+
htmx は特別な属性(hx-*)を
|
|
551
|
+
使って AJAX 通信を行う
|
|
552
|
+
JavaScript を書かずに
|
|
553
|
+
インタラクティブな UI を実現
|
|
554
|
+
end note
|
|
555
|
+
|
|
556
|
+
@enduml
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
<details>
|
|
560
|
+
<summary>htmx の基本的な使い方</summary>
|
|
561
|
+
|
|
562
|
+
```html
|
|
563
|
+
<!-- 勘定科目検索(部分更新) -->
|
|
564
|
+
<div class="mb-3">
|
|
565
|
+
<input type="text"
|
|
566
|
+
class="form-control"
|
|
567
|
+
name="keyword"
|
|
568
|
+
placeholder="勘定科目コードまたは勘定科目名で検索"
|
|
569
|
+
hx-get="/accounts/search"
|
|
570
|
+
hx-trigger="keyup changed delay:300ms"
|
|
571
|
+
hx-target="#search-results"
|
|
572
|
+
hx-indicator="#loading">
|
|
573
|
+
<span id="loading" class="htmx-indicator">検索中...</span>
|
|
574
|
+
</div>
|
|
575
|
+
|
|
576
|
+
<!-- 検索結果がここに挿入される -->
|
|
577
|
+
<div id="search-results">
|
|
578
|
+
<!-- Controller から返される HTML フラグメント -->
|
|
579
|
+
</div>
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
</details>
|
|
583
|
+
|
|
584
|
+
<details>
|
|
585
|
+
<summary>部分更新用 Controller</summary>
|
|
586
|
+
|
|
587
|
+
```java
|
|
588
|
+
@Controller
|
|
589
|
+
@RequestMapping("/accounts")
|
|
590
|
+
public class AccountController {
|
|
591
|
+
|
|
592
|
+
private final AccountUseCase accountUseCase;
|
|
593
|
+
|
|
594
|
+
// ... コンストラクタ省略
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* htmx 用の検索エンドポイント(フラグメントを返す)
|
|
598
|
+
*/
|
|
599
|
+
@GetMapping("/search")
|
|
600
|
+
public String search(
|
|
601
|
+
@RequestParam(required = false) String keyword,
|
|
602
|
+
Model model) {
|
|
603
|
+
|
|
604
|
+
List<Account> accounts = accountUseCase.searchAccounts(keyword);
|
|
605
|
+
model.addAttribute("accounts", accounts);
|
|
606
|
+
|
|
607
|
+
// フラグメントのみを返す
|
|
608
|
+
return "accounts/search-results :: results";
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
</details>
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
### 22.9 API サーバー版との Controller の違い
|
|
618
|
+
|
|
619
|
+
<details>
|
|
620
|
+
<summary>API サーバー版(REST Controller)</summary>
|
|
621
|
+
|
|
622
|
+
```java
|
|
623
|
+
@RestController // JSON を返す
|
|
624
|
+
@RequestMapping("/api/accounts")
|
|
625
|
+
public class AccountApiController {
|
|
626
|
+
|
|
627
|
+
@GetMapping
|
|
628
|
+
public ResponseEntity<List<AccountResponse>> getAllAccounts() {
|
|
629
|
+
List<Account> accounts = accountUseCase.getAllAccounts();
|
|
630
|
+
return ResponseEntity.ok(accounts.stream()
|
|
631
|
+
.map(AccountResponse::from)
|
|
632
|
+
.toList());
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
@PostMapping
|
|
636
|
+
public ResponseEntity<AccountResponse> createAccount(
|
|
637
|
+
@Valid @RequestBody CreateAccountRequest request) { // JSON リクエスト
|
|
638
|
+
Account account = accountUseCase.createAccount(request.toCommand());
|
|
639
|
+
return ResponseEntity.status(HttpStatus.CREATED)
|
|
640
|
+
.body(AccountResponse.from(account));
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
</details>
|
|
646
|
+
|
|
647
|
+
<details>
|
|
648
|
+
<summary>モノリス版(MVC Controller)</summary>
|
|
649
|
+
|
|
650
|
+
```java
|
|
651
|
+
@Controller // HTML を返す
|
|
652
|
+
@RequestMapping("/accounts")
|
|
653
|
+
public class AccountController {
|
|
654
|
+
|
|
655
|
+
@GetMapping
|
|
656
|
+
public String list(Model model) {
|
|
657
|
+
List<Account> accounts = accountUseCase.getAllAccounts();
|
|
658
|
+
model.addAttribute("accounts", accounts);
|
|
659
|
+
return "accounts/list"; // Thymeleaf テンプレート
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
@PostMapping
|
|
663
|
+
public String create(
|
|
664
|
+
@Valid @ModelAttribute("form") AccountForm form, // フォームデータ
|
|
665
|
+
BindingResult bindingResult,
|
|
666
|
+
RedirectAttributes redirectAttributes) {
|
|
667
|
+
|
|
668
|
+
if (bindingResult.hasErrors()) {
|
|
669
|
+
return "accounts/new"; // バリデーションエラー時は入力画面に戻る
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
accountUseCase.createAccount(form.toCommand());
|
|
673
|
+
redirectAttributes.addFlashAttribute("successMessage", "勘定科目を登録しました");
|
|
674
|
+
return "redirect:/accounts"; // PRG パターン
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
</details>
|
|
680
|
+
|
|
681
|
+
**主な違い:**
|
|
682
|
+
|
|
683
|
+
| 観点 | API サーバー版 | モノリス版 |
|
|
684
|
+
|------|--------------|-----------|
|
|
685
|
+
| アノテーション | `@RestController` | `@Controller` |
|
|
686
|
+
| 戻り値 | `ResponseEntity<T>` | テンプレート名(String) |
|
|
687
|
+
| リクエスト | `@RequestBody`(JSON) | `@ModelAttribute`(フォーム) |
|
|
688
|
+
| バリデーション | 例外ハンドラで処理 | `BindingResult` で処理 |
|
|
689
|
+
| レスポンス | JSON | HTML(Thymeleaf) |
|
|
690
|
+
| リダイレクト | 不要 | PRG パターン |
|
|
691
|
+
|
|
692
|
+
---
|
|
693
|
+
|
|
694
|
+
## 第23章:マスタ画面の実装
|
|
695
|
+
|
|
696
|
+
### 23.1 勘定科目マスタ画面の設計
|
|
697
|
+
|
|
698
|
+
#### 画面一覧
|
|
699
|
+
|
|
700
|
+
| 画面 | URL | メソッド | 説明 |
|
|
701
|
+
|------|-----|---------|------|
|
|
702
|
+
| 勘定科目一覧 | /accounts | GET | 勘定科目の検索・一覧表示 |
|
|
703
|
+
| 勘定科目詳細 | /accounts/{accountCode} | GET | 勘定科目の詳細表示 |
|
|
704
|
+
| 勘定科目登録 | /accounts/new | GET | 登録フォーム表示 |
|
|
705
|
+
| 勘定科目登録処理 | /accounts | POST | 登録処理 |
|
|
706
|
+
| 勘定科目編集 | /accounts/{accountCode}/edit | GET | 編集フォーム表示 |
|
|
707
|
+
| 勘定科目更新処理 | /accounts/{accountCode} | POST | 更新処理(PUT 代替) |
|
|
708
|
+
| 勘定科目削除処理 | /accounts/{accountCode}/delete | POST | 削除処理(DELETE 代替) |
|
|
709
|
+
|
|
710
|
+
**注意**: HTML フォームは GET/POST のみ対応のため、PUT/DELETE は POST で代替します。
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
### 23.2 フォームオブジェクトの設計
|
|
715
|
+
|
|
716
|
+
<details>
|
|
717
|
+
<summary>AccountForm.java</summary>
|
|
718
|
+
|
|
719
|
+
```java
|
|
720
|
+
package com.example.accounting.infrastructure.web.form;
|
|
721
|
+
|
|
722
|
+
import com.example.accounting.application.port.in.CreateAccountCommand;
|
|
723
|
+
import com.example.accounting.domain.model.account.*;
|
|
724
|
+
import jakarta.validation.constraints.NotBlank;
|
|
725
|
+
import jakarta.validation.constraints.NotNull;
|
|
726
|
+
import jakarta.validation.constraints.Size;
|
|
727
|
+
import lombok.Data;
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* 勘定科目登録・編集フォーム
|
|
731
|
+
*/
|
|
732
|
+
@Data
|
|
733
|
+
public class AccountForm {
|
|
734
|
+
|
|
735
|
+
@NotBlank(message = "勘定科目コードは必須です")
|
|
736
|
+
@Size(max = 5, message = "勘定科目コードは5文字以内で入力してください")
|
|
737
|
+
private String accountCode;
|
|
738
|
+
|
|
739
|
+
@NotBlank(message = "勘定科目名は必須です")
|
|
740
|
+
@Size(max = 40, message = "勘定科目名は40文字以内で入力してください")
|
|
741
|
+
private String accountName;
|
|
742
|
+
|
|
743
|
+
@Size(max = 10, message = "勘定科目略名は10文字以内で入力してください")
|
|
744
|
+
private String accountShortName;
|
|
745
|
+
|
|
746
|
+
@Size(max = 40, message = "勘定科目カナは40文字以内で入力してください")
|
|
747
|
+
private String accountNameKana;
|
|
748
|
+
|
|
749
|
+
@NotNull(message = "BSPL区分は必須です")
|
|
750
|
+
private BsplType bsplType;
|
|
751
|
+
|
|
752
|
+
@NotNull(message = "貸借区分は必須です")
|
|
753
|
+
private DebitCreditType debitCreditType;
|
|
754
|
+
|
|
755
|
+
@NotNull(message = "取引要素区分は必須です")
|
|
756
|
+
private TransactionElementType transactionElementType;
|
|
757
|
+
|
|
758
|
+
@NotNull(message = "集計区分は必須です")
|
|
759
|
+
private AggregationType aggregationType;
|
|
760
|
+
|
|
761
|
+
private ManagementAccountType managementAccountType;
|
|
762
|
+
|
|
763
|
+
private ExpenseType expenseType;
|
|
764
|
+
|
|
765
|
+
private SubsidiaryType subsidiaryType;
|
|
766
|
+
|
|
767
|
+
private TaxCalculationType taxCalculationType;
|
|
768
|
+
|
|
769
|
+
private String taxTransactionCode;
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* フォームをコマンドに変換
|
|
773
|
+
*/
|
|
774
|
+
public CreateAccountCommand toCommand() {
|
|
775
|
+
return CreateAccountCommand.builder()
|
|
776
|
+
.accountCode(this.accountCode)
|
|
777
|
+
.accountName(this.accountName)
|
|
778
|
+
.accountShortName(this.accountShortName)
|
|
779
|
+
.accountNameKana(this.accountNameKana)
|
|
780
|
+
.bsplType(this.bsplType)
|
|
781
|
+
.debitCreditType(this.debitCreditType)
|
|
782
|
+
.transactionElementType(this.transactionElementType)
|
|
783
|
+
.aggregationType(this.aggregationType)
|
|
784
|
+
.managementAccountType(this.managementAccountType)
|
|
785
|
+
.expenseType(this.expenseType)
|
|
786
|
+
.subsidiaryType(this.subsidiaryType)
|
|
787
|
+
.taxCalculationType(this.taxCalculationType)
|
|
788
|
+
.taxTransactionCode(this.taxTransactionCode)
|
|
789
|
+
.build();
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* エンティティからフォームを生成
|
|
794
|
+
*/
|
|
795
|
+
public static AccountForm from(Account account) {
|
|
796
|
+
AccountForm form = new AccountForm();
|
|
797
|
+
form.setAccountCode(account.getAccountCode());
|
|
798
|
+
form.setAccountName(account.getAccountName());
|
|
799
|
+
form.setAccountShortName(account.getAccountShortName());
|
|
800
|
+
form.setAccountNameKana(account.getAccountNameKana());
|
|
801
|
+
form.setBsplType(account.getBsplType());
|
|
802
|
+
form.setDebitCreditType(account.getDebitCreditType());
|
|
803
|
+
form.setTransactionElementType(account.getTransactionElementType());
|
|
804
|
+
form.setAggregationType(account.getAggregationType());
|
|
805
|
+
form.setManagementAccountType(account.getManagementAccountType());
|
|
806
|
+
form.setExpenseType(account.getExpenseType());
|
|
807
|
+
form.setSubsidiaryType(account.getSubsidiaryType());
|
|
808
|
+
form.setTaxCalculationType(account.getTaxCalculationType());
|
|
809
|
+
form.setTaxTransactionCode(account.getTaxTransactionCode());
|
|
810
|
+
return form;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
</details>
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
819
|
+
### 23.3 勘定科目 Controller の TDD 実装
|
|
820
|
+
|
|
821
|
+
#### Red: 失敗するテストを書く
|
|
822
|
+
|
|
823
|
+
<details>
|
|
824
|
+
<summary>AccountControllerTest.java</summary>
|
|
825
|
+
|
|
826
|
+
```java
|
|
827
|
+
package com.example.accounting.infrastructure.web.controller;
|
|
828
|
+
|
|
829
|
+
import com.example.accounting.domain.model.account.*;
|
|
830
|
+
import com.example.accounting.infrastructure.persistence.mapper.AccountMapper;
|
|
831
|
+
import org.junit.jupiter.api.*;
|
|
832
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
833
|
+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
834
|
+
import org.springframework.boot.test.context.SpringBootTest;
|
|
835
|
+
import org.springframework.test.context.DynamicPropertyRegistry;
|
|
836
|
+
import org.springframework.test.context.DynamicPropertySource;
|
|
837
|
+
import org.springframework.test.web.servlet.MockMvc;
|
|
838
|
+
import org.testcontainers.containers.PostgreSQLContainer;
|
|
839
|
+
import org.testcontainers.junit.jupiter.Container;
|
|
840
|
+
import org.testcontainers.junit.jupiter.Testcontainers;
|
|
841
|
+
|
|
842
|
+
import static org.hamcrest.Matchers.*;
|
|
843
|
+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
844
|
+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
845
|
+
|
|
846
|
+
@SpringBootTest
|
|
847
|
+
@AutoConfigureMockMvc
|
|
848
|
+
@Testcontainers
|
|
849
|
+
@DisplayName("勘定科目マスタ画面")
|
|
850
|
+
class AccountControllerTest {
|
|
851
|
+
|
|
852
|
+
@Container
|
|
853
|
+
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16")
|
|
854
|
+
.withDatabaseName("accounting_test")
|
|
855
|
+
.withUsername("test")
|
|
856
|
+
.withPassword("test");
|
|
857
|
+
|
|
858
|
+
@DynamicPropertySource
|
|
859
|
+
static void configureProperties(DynamicPropertyRegistry registry) {
|
|
860
|
+
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
|
861
|
+
registry.add("spring.datasource.username", postgres::getUsername);
|
|
862
|
+
registry.add("spring.datasource.password", postgres::getPassword);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
@Autowired
|
|
866
|
+
private MockMvc mockMvc;
|
|
867
|
+
|
|
868
|
+
@Autowired
|
|
869
|
+
private AccountMapper accountMapper;
|
|
870
|
+
|
|
871
|
+
@BeforeEach
|
|
872
|
+
void setUp() {
|
|
873
|
+
accountMapper.deleteAll();
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
@Nested
|
|
877
|
+
@DisplayName("GET /accounts - 勘定科目一覧")
|
|
878
|
+
class AccountList {
|
|
879
|
+
|
|
880
|
+
@Test
|
|
881
|
+
@DisplayName("勘定科目一覧画面を表示できる")
|
|
882
|
+
void shouldDisplayAccountList() throws Exception {
|
|
883
|
+
// Arrange
|
|
884
|
+
insertTestAccount("11110", "現金", BsplType.BS, DebitCreditType.DEBIT);
|
|
885
|
+
|
|
886
|
+
// Act & Assert
|
|
887
|
+
mockMvc.perform(get("/accounts"))
|
|
888
|
+
.andExpect(status().isOk())
|
|
889
|
+
.andExpect(view().name("accounts/list"))
|
|
890
|
+
.andExpect(model().attributeExists("accounts"))
|
|
891
|
+
.andExpect(content().string(containsString("11110")))
|
|
892
|
+
.andExpect(content().string(containsString("現金")));
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
@Test
|
|
896
|
+
@DisplayName("BSPL区分でフィルタリングできる")
|
|
897
|
+
void shouldFilterByBsplType() throws Exception {
|
|
898
|
+
// Arrange
|
|
899
|
+
insertTestAccount("11110", "現金", BsplType.BS, DebitCreditType.DEBIT);
|
|
900
|
+
insertTestAccount("41100", "売上高", BsplType.PL, DebitCreditType.CREDIT);
|
|
901
|
+
|
|
902
|
+
// Act & Assert
|
|
903
|
+
mockMvc.perform(get("/accounts").param("bsplType", "BS"))
|
|
904
|
+
.andExpect(status().isOk())
|
|
905
|
+
.andExpect(model().attribute("accounts", hasSize(1)))
|
|
906
|
+
.andExpect(content().string(containsString("現金")))
|
|
907
|
+
.andExpect(content().string(not(containsString("売上高"))));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
@Nested
|
|
912
|
+
@DisplayName("POST /accounts - 勘定科目登録処理")
|
|
913
|
+
class CreateAccount {
|
|
914
|
+
|
|
915
|
+
@Test
|
|
916
|
+
@DisplayName("勘定科目を登録できる")
|
|
917
|
+
void shouldCreateAccount() throws Exception {
|
|
918
|
+
mockMvc.perform(post("/accounts")
|
|
919
|
+
.param("accountCode", "11120")
|
|
920
|
+
.param("accountName", "当座預金")
|
|
921
|
+
.param("bsplType", "BS")
|
|
922
|
+
.param("debitCreditType", "DEBIT")
|
|
923
|
+
.param("transactionElementType", "ASSET")
|
|
924
|
+
.param("aggregationType", "POSTING"))
|
|
925
|
+
.andExpect(status().is3xxRedirection())
|
|
926
|
+
.andExpect(redirectedUrl("/accounts"))
|
|
927
|
+
.andExpect(flash().attribute("successMessage", containsString("登録")));
|
|
928
|
+
|
|
929
|
+
// データベースに保存されていることを確認
|
|
930
|
+
var saved = accountMapper.findByCode("11120");
|
|
931
|
+
Assertions.assertNotNull(saved);
|
|
932
|
+
Assertions.assertEquals("当座預金", saved.getAccountName());
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
@Test
|
|
936
|
+
@DisplayName("バリデーションエラー時は入力画面に戻る")
|
|
937
|
+
void shouldReturnFormOnValidationError() throws Exception {
|
|
938
|
+
mockMvc.perform(post("/accounts")
|
|
939
|
+
.param("accountCode", "") // 必須項目が空
|
|
940
|
+
.param("accountName", "")
|
|
941
|
+
.param("bsplType", "BS"))
|
|
942
|
+
.andExpect(status().isOk())
|
|
943
|
+
.andExpect(view().name("accounts/new"))
|
|
944
|
+
.andExpect(model().attributeHasFieldErrors("form", "accountCode", "accountName"));
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
private void insertTestAccount(String code, String name, BsplType bsplType, DebitCreditType debitCreditType) {
|
|
949
|
+
accountMapper.insert(Account.builder()
|
|
950
|
+
.accountCode(code)
|
|
951
|
+
.accountName(name)
|
|
952
|
+
.accountShortName(name)
|
|
953
|
+
.accountNameKana("")
|
|
954
|
+
.bsplType(bsplType)
|
|
955
|
+
.debitCreditType(debitCreditType)
|
|
956
|
+
.transactionElementType(TransactionElementType.ASSET)
|
|
957
|
+
.aggregationType(AggregationType.POSTING)
|
|
958
|
+
.build());
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
</details>
|
|
964
|
+
|
|
965
|
+
#### Green: Controller の実装
|
|
966
|
+
|
|
967
|
+
<details>
|
|
968
|
+
<summary>AccountController.java</summary>
|
|
969
|
+
|
|
970
|
+
```java
|
|
971
|
+
package com.example.accounting.infrastructure.web.controller;
|
|
972
|
+
|
|
973
|
+
import com.example.accounting.application.port.in.*;
|
|
974
|
+
import com.example.accounting.domain.exception.AccountInUseException;
|
|
975
|
+
import com.example.accounting.domain.exception.AccountNotFoundException;
|
|
976
|
+
import com.example.accounting.domain.exception.DuplicateAccountException;
|
|
977
|
+
import com.example.accounting.domain.model.account.*;
|
|
978
|
+
import com.example.accounting.infrastructure.web.form.AccountForm;
|
|
979
|
+
import jakarta.validation.Valid;
|
|
980
|
+
import org.springframework.stereotype.Controller;
|
|
981
|
+
import org.springframework.ui.Model;
|
|
982
|
+
import org.springframework.validation.BindingResult;
|
|
983
|
+
import org.springframework.web.bind.annotation.*;
|
|
984
|
+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
985
|
+
|
|
986
|
+
import java.util.List;
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* 勘定科目マスタ Controller
|
|
990
|
+
*/
|
|
991
|
+
@Controller
|
|
992
|
+
@RequestMapping("/accounts")
|
|
993
|
+
public class AccountController {
|
|
994
|
+
|
|
995
|
+
private final AccountUseCase accountUseCase;
|
|
996
|
+
|
|
997
|
+
public AccountController(AccountUseCase accountUseCase) {
|
|
998
|
+
this.accountUseCase = accountUseCase;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* 勘定科目一覧画面
|
|
1003
|
+
*/
|
|
1004
|
+
@GetMapping
|
|
1005
|
+
public String list(
|
|
1006
|
+
@RequestParam(required = false) String keyword,
|
|
1007
|
+
@RequestParam(required = false) BsplType bsplType,
|
|
1008
|
+
@RequestParam(required = false) DebitCreditType debitCreditType,
|
|
1009
|
+
Model model) {
|
|
1010
|
+
|
|
1011
|
+
List<Account> accounts;
|
|
1012
|
+
if (keyword != null || bsplType != null || debitCreditType != null) {
|
|
1013
|
+
accounts = accountUseCase.searchAccounts(keyword, bsplType, debitCreditType);
|
|
1014
|
+
} else {
|
|
1015
|
+
accounts = accountUseCase.getAllAccounts();
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
model.addAttribute("accounts", accounts);
|
|
1019
|
+
model.addAttribute("keyword", keyword);
|
|
1020
|
+
model.addAttribute("selectedBsplType", bsplType);
|
|
1021
|
+
model.addAttribute("selectedDebitCreditType", debitCreditType);
|
|
1022
|
+
addEnumsToModel(model);
|
|
1023
|
+
|
|
1024
|
+
return "accounts/list";
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* 勘定科目登録画面
|
|
1029
|
+
*/
|
|
1030
|
+
@GetMapping("/new")
|
|
1031
|
+
public String newForm(Model model) {
|
|
1032
|
+
model.addAttribute("form", new AccountForm());
|
|
1033
|
+
addEnumsToModel(model);
|
|
1034
|
+
return "accounts/new";
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* 勘定科目登録処理
|
|
1039
|
+
*/
|
|
1040
|
+
@PostMapping
|
|
1041
|
+
public String create(
|
|
1042
|
+
@Valid @ModelAttribute("form") AccountForm form,
|
|
1043
|
+
BindingResult bindingResult,
|
|
1044
|
+
Model model,
|
|
1045
|
+
RedirectAttributes redirectAttributes) {
|
|
1046
|
+
|
|
1047
|
+
if (bindingResult.hasErrors()) {
|
|
1048
|
+
addEnumsToModel(model);
|
|
1049
|
+
return "accounts/new";
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
try {
|
|
1053
|
+
accountUseCase.createAccount(form.toCommand());
|
|
1054
|
+
redirectAttributes.addFlashAttribute("successMessage",
|
|
1055
|
+
"勘定科目「" + form.getAccountName() + "」を登録しました");
|
|
1056
|
+
return "redirect:/accounts";
|
|
1057
|
+
} catch (DuplicateAccountException e) {
|
|
1058
|
+
model.addAttribute("errorMessage",
|
|
1059
|
+
"勘定科目コード「" + form.getAccountCode() + "」は既に存在します");
|
|
1060
|
+
addEnumsToModel(model);
|
|
1061
|
+
return "accounts/new";
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* 勘定科目詳細画面
|
|
1067
|
+
*/
|
|
1068
|
+
@GetMapping("/{accountCode}")
|
|
1069
|
+
public String detail(@PathVariable String accountCode, Model model) {
|
|
1070
|
+
Account account = accountUseCase.getAccount(accountCode)
|
|
1071
|
+
.orElseThrow(() -> new AccountNotFoundException(accountCode));
|
|
1072
|
+
|
|
1073
|
+
model.addAttribute("account", account);
|
|
1074
|
+
return "accounts/detail";
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* 勘定科目削除処理
|
|
1079
|
+
*/
|
|
1080
|
+
@PostMapping("/{accountCode}/delete")
|
|
1081
|
+
public String delete(
|
|
1082
|
+
@PathVariable String accountCode,
|
|
1083
|
+
Model model,
|
|
1084
|
+
RedirectAttributes redirectAttributes) {
|
|
1085
|
+
|
|
1086
|
+
try {
|
|
1087
|
+
Account account = accountUseCase.getAccount(accountCode)
|
|
1088
|
+
.orElseThrow(() -> new AccountNotFoundException(accountCode));
|
|
1089
|
+
|
|
1090
|
+
accountUseCase.deleteAccount(accountCode);
|
|
1091
|
+
redirectAttributes.addFlashAttribute("successMessage",
|
|
1092
|
+
"勘定科目「" + account.getAccountName() + "」を削除しました");
|
|
1093
|
+
return "redirect:/accounts";
|
|
1094
|
+
} catch (AccountInUseException e) {
|
|
1095
|
+
Account account = accountUseCase.getAccount(accountCode).orElseThrow();
|
|
1096
|
+
model.addAttribute("account", account);
|
|
1097
|
+
model.addAttribute("errorMessage",
|
|
1098
|
+
"この勘定科目は仕訳で使用中のため削除できません");
|
|
1099
|
+
return "accounts/detail";
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* 列挙型をモデルに追加
|
|
1105
|
+
*/
|
|
1106
|
+
private void addEnumsToModel(Model model) {
|
|
1107
|
+
model.addAttribute("bsplTypes", BsplType.values());
|
|
1108
|
+
model.addAttribute("debitCreditTypes", DebitCreditType.values());
|
|
1109
|
+
model.addAttribute("transactionElementTypes", TransactionElementType.values());
|
|
1110
|
+
model.addAttribute("aggregationTypes", AggregationType.values());
|
|
1111
|
+
model.addAttribute("managementAccountTypes", ManagementAccountType.values());
|
|
1112
|
+
model.addAttribute("expenseTypes", ExpenseType.values());
|
|
1113
|
+
model.addAttribute("subsidiaryTypes", SubsidiaryType.values());
|
|
1114
|
+
model.addAttribute("taxCalculationTypes", TaxCalculationType.values());
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* 404 エラーハンドリング
|
|
1119
|
+
*/
|
|
1120
|
+
@ExceptionHandler(AccountNotFoundException.class)
|
|
1121
|
+
@ResponseStatus(org.springframework.http.HttpStatus.NOT_FOUND)
|
|
1122
|
+
public String handleNotFound(AccountNotFoundException e, Model model) {
|
|
1123
|
+
model.addAttribute("errorMessage", e.getMessage());
|
|
1124
|
+
return "error/404";
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
</details>
|
|
1130
|
+
|
|
1131
|
+
---
|
|
1132
|
+
|
|
1133
|
+
## 第24章:仕訳入力画面の実装
|
|
1134
|
+
|
|
1135
|
+
### 24.1 仕訳入力画面の設計
|
|
1136
|
+
|
|
1137
|
+
#### 画面一覧
|
|
1138
|
+
|
|
1139
|
+
| 画面 | URL | メソッド | 説明 |
|
|
1140
|
+
|------|-----|---------|------|
|
|
1141
|
+
| 仕訳一覧 | /journals | GET | 仕訳の検索・一覧表示 |
|
|
1142
|
+
| 仕訳詳細 | /journals/{journalNumber} | GET | 仕訳の詳細表示 |
|
|
1143
|
+
| 仕訳入力 | /journals/new | GET | 入力フォーム表示 |
|
|
1144
|
+
| 仕訳登録処理 | /journals | POST | 登録処理 |
|
|
1145
|
+
| 仕訳取消 | /journals/{journalNumber}/cancel | POST | 赤黒処理 |
|
|
1146
|
+
|
|
1147
|
+
---
|
|
1148
|
+
|
|
1149
|
+
### 24.2 仕訳入力フォームオブジェクト
|
|
1150
|
+
|
|
1151
|
+
<details>
|
|
1152
|
+
<summary>JournalForm.java</summary>
|
|
1153
|
+
|
|
1154
|
+
```java
|
|
1155
|
+
package com.example.accounting.infrastructure.web.form;
|
|
1156
|
+
|
|
1157
|
+
import com.example.accounting.application.port.in.CreateJournalCommand;
|
|
1158
|
+
import com.example.accounting.domain.model.journal.SingleComplexType;
|
|
1159
|
+
import jakarta.validation.Valid;
|
|
1160
|
+
import jakarta.validation.constraints.NotEmpty;
|
|
1161
|
+
import jakarta.validation.constraints.NotNull;
|
|
1162
|
+
import lombok.Data;
|
|
1163
|
+
|
|
1164
|
+
import java.time.LocalDate;
|
|
1165
|
+
import java.util.ArrayList;
|
|
1166
|
+
import java.util.List;
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* 仕訳入力フォーム
|
|
1170
|
+
*/
|
|
1171
|
+
@Data
|
|
1172
|
+
public class JournalForm {
|
|
1173
|
+
|
|
1174
|
+
@NotNull(message = "起票日は必須です")
|
|
1175
|
+
private LocalDate journalDate;
|
|
1176
|
+
|
|
1177
|
+
private String description;
|
|
1178
|
+
|
|
1179
|
+
private boolean closingJournal;
|
|
1180
|
+
|
|
1181
|
+
@NotNull(message = "単複区分は必須です")
|
|
1182
|
+
private SingleComplexType singleComplexType;
|
|
1183
|
+
|
|
1184
|
+
@Valid
|
|
1185
|
+
@NotEmpty(message = "仕訳明細は1行以上必要です")
|
|
1186
|
+
private List<JournalLineForm> lines = new ArrayList<>();
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* フォームをコマンドに変換
|
|
1190
|
+
*/
|
|
1191
|
+
public CreateJournalCommand toCommand() {
|
|
1192
|
+
return CreateJournalCommand.builder()
|
|
1193
|
+
.journalDate(this.journalDate)
|
|
1194
|
+
.description(this.description)
|
|
1195
|
+
.closingJournal(this.closingJournal)
|
|
1196
|
+
.singleComplexType(this.singleComplexType)
|
|
1197
|
+
.lines(this.lines.stream()
|
|
1198
|
+
.map(JournalLineForm::toCommand)
|
|
1199
|
+
.toList())
|
|
1200
|
+
.build();
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* 初期化(空の明細行を追加)
|
|
1205
|
+
*/
|
|
1206
|
+
public void initializeLines() {
|
|
1207
|
+
if (this.lines.isEmpty()) {
|
|
1208
|
+
// 借方1行、貸方1行を追加
|
|
1209
|
+
JournalLineForm debitLine = new JournalLineForm();
|
|
1210
|
+
debitLine.setDebitCredit("DEBIT");
|
|
1211
|
+
this.lines.add(debitLine);
|
|
1212
|
+
|
|
1213
|
+
JournalLineForm creditLine = new JournalLineForm();
|
|
1214
|
+
creditLine.setDebitCredit("CREDIT");
|
|
1215
|
+
this.lines.add(creditLine);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
```
|
|
1220
|
+
|
|
1221
|
+
</details>
|
|
1222
|
+
|
|
1223
|
+
<details>
|
|
1224
|
+
<summary>JournalLineForm.java</summary>
|
|
1225
|
+
|
|
1226
|
+
```java
|
|
1227
|
+
package com.example.accounting.infrastructure.web.form;
|
|
1228
|
+
|
|
1229
|
+
import com.example.accounting.application.port.in.CreateJournalLineCommand;
|
|
1230
|
+
import jakarta.validation.constraints.NotBlank;
|
|
1231
|
+
import jakarta.validation.constraints.NotNull;
|
|
1232
|
+
import jakarta.validation.constraints.Positive;
|
|
1233
|
+
import lombok.Data;
|
|
1234
|
+
|
|
1235
|
+
import java.math.BigDecimal;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* 仕訳明細行フォーム
|
|
1239
|
+
*/
|
|
1240
|
+
@Data
|
|
1241
|
+
public class JournalLineForm {
|
|
1242
|
+
|
|
1243
|
+
@NotBlank(message = "貸借区分は必須です")
|
|
1244
|
+
private String debitCredit; // "DEBIT" or "CREDIT"
|
|
1245
|
+
|
|
1246
|
+
@NotBlank(message = "勘定科目コードは必須です")
|
|
1247
|
+
private String accountCode;
|
|
1248
|
+
|
|
1249
|
+
private String subsidiaryCode;
|
|
1250
|
+
|
|
1251
|
+
@NotNull(message = "金額は必須です")
|
|
1252
|
+
@Positive(message = "金額は正の数で入力してください")
|
|
1253
|
+
private BigDecimal amount;
|
|
1254
|
+
|
|
1255
|
+
private String taxType;
|
|
1256
|
+
|
|
1257
|
+
private BigDecimal taxRate;
|
|
1258
|
+
|
|
1259
|
+
private String departmentCode;
|
|
1260
|
+
|
|
1261
|
+
private String projectCode;
|
|
1262
|
+
|
|
1263
|
+
private String lineDescription;
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* フォームをコマンドに変換
|
|
1267
|
+
*/
|
|
1268
|
+
public CreateJournalLineCommand toCommand() {
|
|
1269
|
+
return CreateJournalLineCommand.builder()
|
|
1270
|
+
.debitCredit(this.debitCredit)
|
|
1271
|
+
.accountCode(this.accountCode)
|
|
1272
|
+
.subsidiaryCode(this.subsidiaryCode)
|
|
1273
|
+
.amount(this.amount)
|
|
1274
|
+
.taxType(this.taxType)
|
|
1275
|
+
.taxRate(this.taxRate)
|
|
1276
|
+
.departmentCode(this.departmentCode)
|
|
1277
|
+
.projectCode(this.projectCode)
|
|
1278
|
+
.lineDescription(this.lineDescription)
|
|
1279
|
+
.build();
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
```
|
|
1283
|
+
|
|
1284
|
+
</details>
|
|
1285
|
+
|
|
1286
|
+
---
|
|
1287
|
+
|
|
1288
|
+
### 24.3 仕訳 Controller の実装
|
|
1289
|
+
|
|
1290
|
+
<details>
|
|
1291
|
+
<summary>JournalController.java</summary>
|
|
1292
|
+
|
|
1293
|
+
```java
|
|
1294
|
+
package com.example.accounting.infrastructure.web.controller;
|
|
1295
|
+
|
|
1296
|
+
import com.example.accounting.application.port.in.*;
|
|
1297
|
+
import com.example.accounting.domain.exception.DebitCreditImbalanceException;
|
|
1298
|
+
import com.example.accounting.domain.exception.JournalNotFoundException;
|
|
1299
|
+
import com.example.accounting.domain.model.journal.*;
|
|
1300
|
+
import com.example.accounting.infrastructure.web.form.JournalForm;
|
|
1301
|
+
import jakarta.validation.Valid;
|
|
1302
|
+
import org.springframework.format.annotation.DateTimeFormat;
|
|
1303
|
+
import org.springframework.stereotype.Controller;
|
|
1304
|
+
import org.springframework.ui.Model;
|
|
1305
|
+
import org.springframework.validation.BindingResult;
|
|
1306
|
+
import org.springframework.web.bind.annotation.*;
|
|
1307
|
+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
1308
|
+
|
|
1309
|
+
import java.time.LocalDate;
|
|
1310
|
+
import java.util.List;
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* 仕訳 Controller
|
|
1314
|
+
*/
|
|
1315
|
+
@Controller
|
|
1316
|
+
@RequestMapping("/journals")
|
|
1317
|
+
public class JournalController {
|
|
1318
|
+
|
|
1319
|
+
private final JournalUseCase journalUseCase;
|
|
1320
|
+
private final AccountUseCase accountUseCase;
|
|
1321
|
+
private final DepartmentUseCase departmentUseCase;
|
|
1322
|
+
|
|
1323
|
+
public JournalController(
|
|
1324
|
+
JournalUseCase journalUseCase,
|
|
1325
|
+
AccountUseCase accountUseCase,
|
|
1326
|
+
DepartmentUseCase departmentUseCase) {
|
|
1327
|
+
this.journalUseCase = journalUseCase;
|
|
1328
|
+
this.accountUseCase = accountUseCase;
|
|
1329
|
+
this.departmentUseCase = departmentUseCase;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
/**
|
|
1333
|
+
* 仕訳一覧画面
|
|
1334
|
+
*/
|
|
1335
|
+
@GetMapping
|
|
1336
|
+
public String list(
|
|
1337
|
+
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate,
|
|
1338
|
+
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate,
|
|
1339
|
+
@RequestParam(required = false) String accountCode,
|
|
1340
|
+
@RequestParam(required = false) JournalStatus status,
|
|
1341
|
+
Model model) {
|
|
1342
|
+
|
|
1343
|
+
// デフォルトは当月
|
|
1344
|
+
if (fromDate == null) {
|
|
1345
|
+
fromDate = LocalDate.now().withDayOfMonth(1);
|
|
1346
|
+
}
|
|
1347
|
+
if (toDate == null) {
|
|
1348
|
+
toDate = LocalDate.now();
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
List<Journal> journals = journalUseCase.searchJournals(fromDate, toDate, accountCode, status);
|
|
1352
|
+
|
|
1353
|
+
model.addAttribute("journals", journals);
|
|
1354
|
+
model.addAttribute("fromDate", fromDate);
|
|
1355
|
+
model.addAttribute("toDate", toDate);
|
|
1356
|
+
model.addAttribute("accountCode", accountCode);
|
|
1357
|
+
model.addAttribute("status", status);
|
|
1358
|
+
model.addAttribute("statuses", JournalStatus.values());
|
|
1359
|
+
|
|
1360
|
+
return "journals/list";
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* 仕訳入力画面
|
|
1365
|
+
*/
|
|
1366
|
+
@GetMapping("/new")
|
|
1367
|
+
public String newForm(Model model) {
|
|
1368
|
+
JournalForm form = new JournalForm();
|
|
1369
|
+
form.setJournalDate(LocalDate.now());
|
|
1370
|
+
form.setSingleComplexType(SingleComplexType.SINGLE);
|
|
1371
|
+
form.initializeLines();
|
|
1372
|
+
|
|
1373
|
+
model.addAttribute("form", form);
|
|
1374
|
+
addMasterDataToModel(model);
|
|
1375
|
+
|
|
1376
|
+
return "journals/new";
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* 仕訳登録処理
|
|
1381
|
+
*/
|
|
1382
|
+
@PostMapping
|
|
1383
|
+
public String create(
|
|
1384
|
+
@Valid @ModelAttribute("form") JournalForm form,
|
|
1385
|
+
BindingResult bindingResult,
|
|
1386
|
+
Model model,
|
|
1387
|
+
RedirectAttributes redirectAttributes) {
|
|
1388
|
+
|
|
1389
|
+
if (bindingResult.hasErrors()) {
|
|
1390
|
+
addMasterDataToModel(model);
|
|
1391
|
+
return "journals/new";
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
try {
|
|
1395
|
+
Journal journal = journalUseCase.createJournal(form.toCommand());
|
|
1396
|
+
redirectAttributes.addFlashAttribute("successMessage",
|
|
1397
|
+
"仕訳「" + journal.getJournalNumber() + "」を登録しました");
|
|
1398
|
+
return "redirect:/journals/" + journal.getJournalNumber();
|
|
1399
|
+
} catch (DebitCreditImbalanceException e) {
|
|
1400
|
+
model.addAttribute("errorMessage", "借方・貸方の合計が一致しません");
|
|
1401
|
+
addMasterDataToModel(model);
|
|
1402
|
+
return "journals/new";
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* 仕訳詳細画面
|
|
1408
|
+
*/
|
|
1409
|
+
@GetMapping("/{journalNumber}")
|
|
1410
|
+
public String detail(@PathVariable String journalNumber, Model model) {
|
|
1411
|
+
Journal journal = journalUseCase.getJournal(journalNumber)
|
|
1412
|
+
.orElseThrow(() -> new JournalNotFoundException(journalNumber));
|
|
1413
|
+
|
|
1414
|
+
model.addAttribute("journal", journal);
|
|
1415
|
+
return "journals/detail";
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* 仕訳取消処理(赤黒処理)
|
|
1420
|
+
*/
|
|
1421
|
+
@PostMapping("/{journalNumber}/cancel")
|
|
1422
|
+
public String cancel(
|
|
1423
|
+
@PathVariable String journalNumber,
|
|
1424
|
+
@RequestParam(required = false) String reason,
|
|
1425
|
+
RedirectAttributes redirectAttributes) {
|
|
1426
|
+
|
|
1427
|
+
Journal cancelJournal = journalUseCase.cancelJournal(journalNumber, reason);
|
|
1428
|
+
redirectAttributes.addFlashAttribute("successMessage",
|
|
1429
|
+
"仕訳「" + journalNumber + "」を取消しました。" +
|
|
1430
|
+
"取消仕訳「" + cancelJournal.getJournalNumber() + "」を作成しました。");
|
|
1431
|
+
return "redirect:/journals/" + cancelJournal.getJournalNumber();
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* マスタデータをモデルに追加
|
|
1436
|
+
*/
|
|
1437
|
+
private void addMasterDataToModel(Model model) {
|
|
1438
|
+
model.addAttribute("accounts", accountUseCase.getPostingAccounts());
|
|
1439
|
+
model.addAttribute("departments", departmentUseCase.getAllDepartments());
|
|
1440
|
+
model.addAttribute("singleComplexTypes", SingleComplexType.values());
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
```
|
|
1444
|
+
|
|
1445
|
+
</details>
|
|
1446
|
+
|
|
1447
|
+
---
|
|
1448
|
+
|
|
1449
|
+
## 第25章:帳票出力の実装
|
|
1450
|
+
|
|
1451
|
+
### 25.1 帳票出力の設計
|
|
1452
|
+
|
|
1453
|
+
財務会計システムでは、以下の帳票を出力します。
|
|
1454
|
+
|
|
1455
|
+
| 帳票名 | 説明 | 出力形式 |
|
|
1456
|
+
|-------|------|---------|
|
|
1457
|
+
| 日計表 | 日次の仕訳合計 | HTML / Excel / PDF |
|
|
1458
|
+
| 合計残高試算表 | 月次の勘定科目残高 | HTML / Excel / PDF |
|
|
1459
|
+
| 総勘定元帳 | 勘定科目別の仕訳明細 | HTML / Excel / PDF |
|
|
1460
|
+
| 貸借対照表 | 資産・負債・資本の状況 | HTML / Excel / PDF |
|
|
1461
|
+
| 損益計算書 | 収益・費用の状況 | HTML / Excel / PDF |
|
|
1462
|
+
|
|
1463
|
+
---
|
|
1464
|
+
|
|
1465
|
+
### 25.2 帳票 Controller の実装
|
|
1466
|
+
|
|
1467
|
+
<details>
|
|
1468
|
+
<summary>ReportController.java</summary>
|
|
1469
|
+
|
|
1470
|
+
```java
|
|
1471
|
+
package com.example.accounting.infrastructure.web.controller;
|
|
1472
|
+
|
|
1473
|
+
import com.example.accounting.application.port.in.*;
|
|
1474
|
+
import com.example.accounting.domain.model.report.*;
|
|
1475
|
+
import com.example.accounting.infrastructure.report.ExcelReportGenerator;
|
|
1476
|
+
import com.example.accounting.infrastructure.report.PdfReportGenerator;
|
|
1477
|
+
import org.springframework.format.annotation.DateTimeFormat;
|
|
1478
|
+
import org.springframework.http.HttpHeaders;
|
|
1479
|
+
import org.springframework.http.MediaType;
|
|
1480
|
+
import org.springframework.http.ResponseEntity;
|
|
1481
|
+
import org.springframework.stereotype.Controller;
|
|
1482
|
+
import org.springframework.ui.Model;
|
|
1483
|
+
import org.springframework.web.bind.annotation.*;
|
|
1484
|
+
|
|
1485
|
+
import java.time.LocalDate;
|
|
1486
|
+
import java.time.YearMonth;
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* 帳票出力 Controller
|
|
1490
|
+
*/
|
|
1491
|
+
@Controller
|
|
1492
|
+
@RequestMapping("/reports")
|
|
1493
|
+
public class ReportController {
|
|
1494
|
+
|
|
1495
|
+
private final ReportUseCase reportUseCase;
|
|
1496
|
+
private final ExcelReportGenerator excelGenerator;
|
|
1497
|
+
private final PdfReportGenerator pdfGenerator;
|
|
1498
|
+
|
|
1499
|
+
public ReportController(
|
|
1500
|
+
ReportUseCase reportUseCase,
|
|
1501
|
+
ExcelReportGenerator excelGenerator,
|
|
1502
|
+
PdfReportGenerator pdfGenerator) {
|
|
1503
|
+
this.reportUseCase = reportUseCase;
|
|
1504
|
+
this.excelGenerator = excelGenerator;
|
|
1505
|
+
this.pdfGenerator = pdfGenerator;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* 日計表画面
|
|
1510
|
+
*/
|
|
1511
|
+
@GetMapping("/daily")
|
|
1512
|
+
public String dailyReport(
|
|
1513
|
+
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
|
|
1514
|
+
Model model) {
|
|
1515
|
+
|
|
1516
|
+
if (date == null) {
|
|
1517
|
+
date = LocalDate.now();
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
DailyReport report = reportUseCase.getDailyReport(date);
|
|
1521
|
+
model.addAttribute("report", report);
|
|
1522
|
+
model.addAttribute("date", date);
|
|
1523
|
+
|
|
1524
|
+
return "reports/daily";
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* 日計表 Excel 出力
|
|
1529
|
+
*/
|
|
1530
|
+
@GetMapping("/daily/excel")
|
|
1531
|
+
public ResponseEntity<byte[]> dailyReportExcel(
|
|
1532
|
+
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
|
|
1533
|
+
|
|
1534
|
+
DailyReport report = reportUseCase.getDailyReport(date);
|
|
1535
|
+
byte[] excelData = excelGenerator.generateDailyReport(report);
|
|
1536
|
+
|
|
1537
|
+
return ResponseEntity.ok()
|
|
1538
|
+
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
1539
|
+
"attachment; filename=\"daily_report_" + date + ".xlsx\"")
|
|
1540
|
+
.contentType(MediaType.parseMediaType(
|
|
1541
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
|
|
1542
|
+
.body(excelData);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* 日計表 PDF 出力
|
|
1547
|
+
*/
|
|
1548
|
+
@GetMapping("/daily/pdf")
|
|
1549
|
+
public ResponseEntity<byte[]> dailyReportPdf(
|
|
1550
|
+
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
|
|
1551
|
+
|
|
1552
|
+
DailyReport report = reportUseCase.getDailyReport(date);
|
|
1553
|
+
byte[] pdfData = pdfGenerator.generateDailyReport(report);
|
|
1554
|
+
|
|
1555
|
+
return ResponseEntity.ok()
|
|
1556
|
+
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
1557
|
+
"attachment; filename=\"daily_report_" + date + ".pdf\"")
|
|
1558
|
+
.contentType(MediaType.APPLICATION_PDF)
|
|
1559
|
+
.body(pdfData);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
/**
|
|
1563
|
+
* 合計残高試算表画面
|
|
1564
|
+
*/
|
|
1565
|
+
@GetMapping("/trial-balance")
|
|
1566
|
+
public String trialBalance(
|
|
1567
|
+
@RequestParam(required = false) String fiscalYear,
|
|
1568
|
+
@RequestParam(required = false) Integer month,
|
|
1569
|
+
Model model) {
|
|
1570
|
+
|
|
1571
|
+
YearMonth yearMonth = (fiscalYear != null && month != null)
|
|
1572
|
+
? YearMonth.of(Integer.parseInt(fiscalYear), month)
|
|
1573
|
+
: YearMonth.now();
|
|
1574
|
+
|
|
1575
|
+
TrialBalance report = reportUseCase.getTrialBalance(yearMonth);
|
|
1576
|
+
model.addAttribute("report", report);
|
|
1577
|
+
model.addAttribute("yearMonth", yearMonth);
|
|
1578
|
+
|
|
1579
|
+
return "reports/trial-balance";
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* 合計残高試算表 Excel 出力
|
|
1584
|
+
*/
|
|
1585
|
+
@GetMapping("/trial-balance/excel")
|
|
1586
|
+
public ResponseEntity<byte[]> trialBalanceExcel(
|
|
1587
|
+
@RequestParam String fiscalYear,
|
|
1588
|
+
@RequestParam Integer month) {
|
|
1589
|
+
|
|
1590
|
+
YearMonth yearMonth = YearMonth.of(Integer.parseInt(fiscalYear), month);
|
|
1591
|
+
TrialBalance report = reportUseCase.getTrialBalance(yearMonth);
|
|
1592
|
+
byte[] excelData = excelGenerator.generateTrialBalance(report);
|
|
1593
|
+
|
|
1594
|
+
return ResponseEntity.ok()
|
|
1595
|
+
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
1596
|
+
"attachment; filename=\"trial_balance_" + yearMonth + ".xlsx\"")
|
|
1597
|
+
.contentType(MediaType.parseMediaType(
|
|
1598
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
|
|
1599
|
+
.body(excelData);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* 貸借対照表画面
|
|
1604
|
+
*/
|
|
1605
|
+
@GetMapping("/balance-sheet")
|
|
1606
|
+
public String balanceSheet(
|
|
1607
|
+
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
|
|
1608
|
+
Model model) {
|
|
1609
|
+
|
|
1610
|
+
if (date == null) {
|
|
1611
|
+
date = LocalDate.now();
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
BalanceSheet report = reportUseCase.getBalanceSheet(date);
|
|
1615
|
+
model.addAttribute("report", report);
|
|
1616
|
+
model.addAttribute("date", date);
|
|
1617
|
+
|
|
1618
|
+
return "reports/balance-sheet";
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* 損益計算書画面
|
|
1623
|
+
*/
|
|
1624
|
+
@GetMapping("/income-statement")
|
|
1625
|
+
public String incomeStatement(
|
|
1626
|
+
@RequestParam(required = false) String fiscalYear,
|
|
1627
|
+
@RequestParam(required = false) Integer fromMonth,
|
|
1628
|
+
@RequestParam(required = false) Integer toMonth,
|
|
1629
|
+
Model model) {
|
|
1630
|
+
|
|
1631
|
+
YearMonth from = (fiscalYear != null && fromMonth != null)
|
|
1632
|
+
? YearMonth.of(Integer.parseInt(fiscalYear), fromMonth)
|
|
1633
|
+
: YearMonth.now().withMonth(4); // 期首(4月)
|
|
1634
|
+
|
|
1635
|
+
YearMonth to = (fiscalYear != null && toMonth != null)
|
|
1636
|
+
? YearMonth.of(Integer.parseInt(fiscalYear), toMonth)
|
|
1637
|
+
: YearMonth.now();
|
|
1638
|
+
|
|
1639
|
+
IncomeStatement report = reportUseCase.getIncomeStatement(from, to);
|
|
1640
|
+
model.addAttribute("report", report);
|
|
1641
|
+
model.addAttribute("fromMonth", from);
|
|
1642
|
+
model.addAttribute("toMonth", to);
|
|
1643
|
+
|
|
1644
|
+
return "reports/income-statement";
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
```
|
|
1648
|
+
|
|
1649
|
+
</details>
|
|
1650
|
+
|
|
1651
|
+
---
|
|
1652
|
+
|
|
1653
|
+
### 25.3 Excel 帳票生成
|
|
1654
|
+
|
|
1655
|
+
<details>
|
|
1656
|
+
<summary>ExcelReportGenerator.java</summary>
|
|
1657
|
+
|
|
1658
|
+
```java
|
|
1659
|
+
package com.example.accounting.infrastructure.report;
|
|
1660
|
+
|
|
1661
|
+
import com.example.accounting.domain.model.report.*;
|
|
1662
|
+
import org.apache.poi.ss.usermodel.*;
|
|
1663
|
+
import org.apache.poi.ss.util.CellRangeAddress;
|
|
1664
|
+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
1665
|
+
import org.springframework.stereotype.Component;
|
|
1666
|
+
|
|
1667
|
+
import java.io.ByteArrayOutputStream;
|
|
1668
|
+
import java.io.IOException;
|
|
1669
|
+
import java.time.format.DateTimeFormatter;
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* Excel 帳票生成
|
|
1673
|
+
*/
|
|
1674
|
+
@Component
|
|
1675
|
+
public class ExcelReportGenerator {
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* 日計表 Excel 生成
|
|
1679
|
+
*/
|
|
1680
|
+
public byte[] generateDailyReport(DailyReport report) {
|
|
1681
|
+
try (Workbook workbook = new XSSFWorkbook()) {
|
|
1682
|
+
Sheet sheet = workbook.createSheet("日計表");
|
|
1683
|
+
|
|
1684
|
+
// スタイル設定
|
|
1685
|
+
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
1686
|
+
CellStyle amountStyle = createAmountStyle(workbook);
|
|
1687
|
+
|
|
1688
|
+
// タイトル
|
|
1689
|
+
Row titleRow = sheet.createRow(0);
|
|
1690
|
+
Cell titleCell = titleRow.createCell(0);
|
|
1691
|
+
titleCell.setCellValue("日 計 表");
|
|
1692
|
+
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
|
|
1693
|
+
|
|
1694
|
+
// 日付
|
|
1695
|
+
Row dateRow = sheet.createRow(1);
|
|
1696
|
+
dateRow.createCell(0).setCellValue(
|
|
1697
|
+
report.getDate().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
|
|
1698
|
+
|
|
1699
|
+
// ヘッダー
|
|
1700
|
+
Row headerRow = sheet.createRow(3);
|
|
1701
|
+
String[] headers = {"勘定科目コード", "勘定科目名", "借方金額", "貸方金額"};
|
|
1702
|
+
for (int i = 0; i < headers.length; i++) {
|
|
1703
|
+
Cell cell = headerRow.createCell(i);
|
|
1704
|
+
cell.setCellValue(headers[i]);
|
|
1705
|
+
cell.setCellStyle(headerStyle);
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// データ行
|
|
1709
|
+
int rowNum = 4;
|
|
1710
|
+
for (DailyReportLine line : report.getLines()) {
|
|
1711
|
+
Row row = sheet.createRow(rowNum++);
|
|
1712
|
+
row.createCell(0).setCellValue(line.getAccountCode());
|
|
1713
|
+
row.createCell(1).setCellValue(line.getAccountName());
|
|
1714
|
+
|
|
1715
|
+
Cell debitCell = row.createCell(2);
|
|
1716
|
+
debitCell.setCellValue(line.getDebitAmount().doubleValue());
|
|
1717
|
+
debitCell.setCellStyle(amountStyle);
|
|
1718
|
+
|
|
1719
|
+
Cell creditCell = row.createCell(3);
|
|
1720
|
+
creditCell.setCellValue(line.getCreditAmount().doubleValue());
|
|
1721
|
+
creditCell.setCellStyle(amountStyle);
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
// 合計行
|
|
1725
|
+
Row totalRow = sheet.createRow(rowNum);
|
|
1726
|
+
totalRow.createCell(1).setCellValue("合計");
|
|
1727
|
+
|
|
1728
|
+
Cell totalDebitCell = totalRow.createCell(2);
|
|
1729
|
+
totalDebitCell.setCellValue(report.getTotalDebit().doubleValue());
|
|
1730
|
+
totalDebitCell.setCellStyle(amountStyle);
|
|
1731
|
+
|
|
1732
|
+
Cell totalCreditCell = totalRow.createCell(3);
|
|
1733
|
+
totalCreditCell.setCellValue(report.getTotalCredit().doubleValue());
|
|
1734
|
+
totalCreditCell.setCellStyle(amountStyle);
|
|
1735
|
+
|
|
1736
|
+
// 列幅調整
|
|
1737
|
+
for (int i = 0; i < 4; i++) {
|
|
1738
|
+
sheet.autoSizeColumn(i);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
1742
|
+
workbook.write(out);
|
|
1743
|
+
return out.toByteArray();
|
|
1744
|
+
|
|
1745
|
+
} catch (IOException e) {
|
|
1746
|
+
throw new RuntimeException("Excel 生成エラー", e);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
private CellStyle createHeaderStyle(Workbook workbook) {
|
|
1751
|
+
CellStyle style = workbook.createCellStyle();
|
|
1752
|
+
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
1753
|
+
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
1754
|
+
style.setBorderBottom(BorderStyle.THIN);
|
|
1755
|
+
style.setBorderTop(BorderStyle.THIN);
|
|
1756
|
+
style.setBorderLeft(BorderStyle.THIN);
|
|
1757
|
+
style.setBorderRight(BorderStyle.THIN);
|
|
1758
|
+
style.setAlignment(HorizontalAlignment.CENTER);
|
|
1759
|
+
return style;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
private CellStyle createAmountStyle(Workbook workbook) {
|
|
1763
|
+
CellStyle style = workbook.createCellStyle();
|
|
1764
|
+
DataFormat format = workbook.createDataFormat();
|
|
1765
|
+
style.setDataFormat(format.getFormat("#,##0"));
|
|
1766
|
+
style.setAlignment(HorizontalAlignment.RIGHT);
|
|
1767
|
+
return style;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
```
|
|
1771
|
+
|
|
1772
|
+
</details>
|
|
1773
|
+
|
|
1774
|
+
---
|
|
1775
|
+
|
|
1776
|
+
## 第26章:ページネーションの実装
|
|
1777
|
+
|
|
1778
|
+
### 26.1 ページネーションの設計
|
|
1779
|
+
|
|
1780
|
+
一覧画面でデータ量が多い場合、すべてのデータを一度に表示するとパフォーマンスが低下します。ページネーションを実装して、データを分割して表示します。
|
|
1781
|
+
|
|
1782
|
+
| 要素 | 説明 |
|
|
1783
|
+
|------|------|
|
|
1784
|
+
| **PageResult<T>** | ページネーション結果を表す汎用クラス |
|
|
1785
|
+
| **LIMIT/OFFSET** | SQL でのページ分割 |
|
|
1786
|
+
| **表示件数** | ユーザーが選択可能(10/25/50/100件) |
|
|
1787
|
+
| **ページナビゲーション** | 最初/前/ページ番号/次/最後 |
|
|
1788
|
+
|
|
1789
|
+
---
|
|
1790
|
+
|
|
1791
|
+
### 26.2 PageResult クラス
|
|
1792
|
+
|
|
1793
|
+
<details>
|
|
1794
|
+
<summary>PageResult.java</summary>
|
|
1795
|
+
|
|
1796
|
+
```java
|
|
1797
|
+
package com.example.sms.domain.model.common;
|
|
1798
|
+
|
|
1799
|
+
import java.util.List;
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* ページネーション結果を表す汎用クラス.
|
|
1803
|
+
*
|
|
1804
|
+
* @param <T> コンテンツの型
|
|
1805
|
+
*/
|
|
1806
|
+
public class PageResult<T> {
|
|
1807
|
+
|
|
1808
|
+
private final List<T> content;
|
|
1809
|
+
private final int page;
|
|
1810
|
+
private final int size;
|
|
1811
|
+
private final long totalElements;
|
|
1812
|
+
private final int totalPages;
|
|
1813
|
+
|
|
1814
|
+
public PageResult(List<T> content, int page, int size, long totalElements) {
|
|
1815
|
+
this.content = content;
|
|
1816
|
+
this.page = page;
|
|
1817
|
+
this.size = size;
|
|
1818
|
+
this.totalElements = totalElements;
|
|
1819
|
+
this.totalPages = size > 0 ? (int) Math.ceil((double) totalElements / size) : 0;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
public List<T> getContent() {
|
|
1823
|
+
return content;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
public int getPage() {
|
|
1827
|
+
return page;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
public int getSize() {
|
|
1831
|
+
return size;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
public long getTotalElements() {
|
|
1835
|
+
return totalElements;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
public int getTotalPages() {
|
|
1839
|
+
return totalPages;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
public boolean isFirst() {
|
|
1843
|
+
return page == 0;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
public boolean isLast() {
|
|
1847
|
+
return page >= totalPages - 1;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
public boolean hasPrevious() {
|
|
1851
|
+
return page > 0;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
public boolean hasNext() {
|
|
1855
|
+
return page < totalPages - 1;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
```
|
|
1859
|
+
|
|
1860
|
+
</details>
|
|
1861
|
+
|
|
1862
|
+
---
|
|
1863
|
+
|
|
1864
|
+
### 26.3 Mapper 層の実装
|
|
1865
|
+
|
|
1866
|
+
ページネーション用のクエリと件数取得クエリを追加します。
|
|
1867
|
+
|
|
1868
|
+
<details>
|
|
1869
|
+
<summary>PartnerMapper.java(抜粋)</summary>
|
|
1870
|
+
|
|
1871
|
+
```java
|
|
1872
|
+
/**
|
|
1873
|
+
* ページネーション付きで取引先を検索.
|
|
1874
|
+
*/
|
|
1875
|
+
List<Partner> findWithPagination(
|
|
1876
|
+
@Param("offset") int offset,
|
|
1877
|
+
@Param("limit") int limit,
|
|
1878
|
+
@Param("type") String type,
|
|
1879
|
+
@Param("keyword") String keyword);
|
|
1880
|
+
|
|
1881
|
+
/**
|
|
1882
|
+
* 検索条件に一致する取引先の件数を取得.
|
|
1883
|
+
*/
|
|
1884
|
+
long count(@Param("type") String type, @Param("keyword") String keyword);
|
|
1885
|
+
```
|
|
1886
|
+
|
|
1887
|
+
</details>
|
|
1888
|
+
|
|
1889
|
+
<details>
|
|
1890
|
+
<summary>PartnerMapper.xml(抜粋)</summary>
|
|
1891
|
+
|
|
1892
|
+
```xml
|
|
1893
|
+
<select id="findWithPagination" resultMap="PartnerResultMap">
|
|
1894
|
+
SELECT * FROM "取引先マスタ"
|
|
1895
|
+
<where>
|
|
1896
|
+
<if test="type == 'customer'">
|
|
1897
|
+
"顧客区分" = TRUE
|
|
1898
|
+
</if>
|
|
1899
|
+
<if test="type == 'supplier'">
|
|
1900
|
+
"仕入先区分" = TRUE
|
|
1901
|
+
</if>
|
|
1902
|
+
<if test="keyword != null and keyword != ''">
|
|
1903
|
+
AND (LOWER("取引先コード") LIKE LOWER('%' || #{keyword} || '%')
|
|
1904
|
+
OR LOWER("取引先名") LIKE LOWER('%' || #{keyword} || '%'))
|
|
1905
|
+
</if>
|
|
1906
|
+
</where>
|
|
1907
|
+
ORDER BY "取引先コード"
|
|
1908
|
+
LIMIT #{limit} OFFSET #{offset}
|
|
1909
|
+
</select>
|
|
1910
|
+
|
|
1911
|
+
<select id="count" resultType="long">
|
|
1912
|
+
SELECT COUNT(*) FROM "取引先マスタ"
|
|
1913
|
+
<where>
|
|
1914
|
+
<if test="type == 'customer'">
|
|
1915
|
+
"顧客区分" = TRUE
|
|
1916
|
+
</if>
|
|
1917
|
+
<if test="type == 'supplier'">
|
|
1918
|
+
"仕入先区分" = TRUE
|
|
1919
|
+
</if>
|
|
1920
|
+
<if test="keyword != null and keyword != ''">
|
|
1921
|
+
AND (LOWER("取引先コード") LIKE LOWER('%' || #{keyword} || '%')
|
|
1922
|
+
OR LOWER("取引先名") LIKE LOWER('%' || #{keyword} || '%'))
|
|
1923
|
+
</if>
|
|
1924
|
+
</where>
|
|
1925
|
+
</select>
|
|
1926
|
+
```
|
|
1927
|
+
|
|
1928
|
+
</details>
|
|
1929
|
+
|
|
1930
|
+
---
|
|
1931
|
+
|
|
1932
|
+
### 26.4 Repository 層の実装
|
|
1933
|
+
|
|
1934
|
+
<details>
|
|
1935
|
+
<summary>PartnerRepository.java(抜粋)</summary>
|
|
1936
|
+
|
|
1937
|
+
```java
|
|
1938
|
+
/**
|
|
1939
|
+
* ページネーション付きで取引先を検索.
|
|
1940
|
+
*/
|
|
1941
|
+
PageResult<Partner> findWithPagination(int page, int size, String type, String keyword);
|
|
1942
|
+
```
|
|
1943
|
+
|
|
1944
|
+
</details>
|
|
1945
|
+
|
|
1946
|
+
<details>
|
|
1947
|
+
<summary>PartnerRepositoryImpl.java(抜粋)</summary>
|
|
1948
|
+
|
|
1949
|
+
```java
|
|
1950
|
+
@Override
|
|
1951
|
+
public PageResult<Partner> findWithPagination(int page, int size, String type, String keyword) {
|
|
1952
|
+
int offset = page * size;
|
|
1953
|
+
List<Partner> partners = partnerMapper.findWithPagination(offset, size, type, keyword);
|
|
1954
|
+
long totalElements = partnerMapper.count(type, keyword);
|
|
1955
|
+
return new PageResult<>(partners, page, size, totalElements);
|
|
1956
|
+
}
|
|
1957
|
+
```
|
|
1958
|
+
|
|
1959
|
+
</details>
|
|
1960
|
+
|
|
1961
|
+
---
|
|
1962
|
+
|
|
1963
|
+
### 26.5 UseCase / Service 層の実装
|
|
1964
|
+
|
|
1965
|
+
<details>
|
|
1966
|
+
<summary>PartnerUseCase.java(抜粋)</summary>
|
|
1967
|
+
|
|
1968
|
+
```java
|
|
1969
|
+
/**
|
|
1970
|
+
* ページネーション付きで取引先を取得.
|
|
1971
|
+
*/
|
|
1972
|
+
PageResult<Partner> getPartners(int page, int size, String type, String keyword);
|
|
1973
|
+
```
|
|
1974
|
+
|
|
1975
|
+
</details>
|
|
1976
|
+
|
|
1977
|
+
<details>
|
|
1978
|
+
<summary>PartnerService.java(抜粋)</summary>
|
|
1979
|
+
|
|
1980
|
+
```java
|
|
1981
|
+
@Override
|
|
1982
|
+
@Transactional(readOnly = true)
|
|
1983
|
+
public PageResult<Partner> getPartners(int page, int size, String type, String keyword) {
|
|
1984
|
+
return partnerRepository.findWithPagination(page, size, type, keyword);
|
|
1985
|
+
}
|
|
1986
|
+
```
|
|
1987
|
+
|
|
1988
|
+
</details>
|
|
1989
|
+
|
|
1990
|
+
---
|
|
1991
|
+
|
|
1992
|
+
### 26.6 Controller の実装
|
|
1993
|
+
|
|
1994
|
+
<details>
|
|
1995
|
+
<summary>PartnerWebController.java(抜粋)</summary>
|
|
1996
|
+
|
|
1997
|
+
```java
|
|
1998
|
+
@GetMapping
|
|
1999
|
+
public String list(
|
|
2000
|
+
@RequestParam(defaultValue = "0") int page,
|
|
2001
|
+
@RequestParam(defaultValue = "10") int size,
|
|
2002
|
+
@RequestParam(required = false) String type,
|
|
2003
|
+
@RequestParam(required = false) String keyword,
|
|
2004
|
+
Model model) {
|
|
2005
|
+
|
|
2006
|
+
PageResult<Partner> partnerPage = partnerUseCase.getPartners(page, size, type, keyword);
|
|
2007
|
+
|
|
2008
|
+
model.addAttribute("partners", partnerPage.getContent());
|
|
2009
|
+
model.addAttribute("page", partnerPage);
|
|
2010
|
+
model.addAttribute("selectedType", type);
|
|
2011
|
+
model.addAttribute("keyword", keyword);
|
|
2012
|
+
model.addAttribute("currentSize", size);
|
|
2013
|
+
|
|
2014
|
+
return "partners/list";
|
|
2015
|
+
}
|
|
2016
|
+
```
|
|
2017
|
+
|
|
2018
|
+
</details>
|
|
2019
|
+
|
|
2020
|
+
---
|
|
2021
|
+
|
|
2022
|
+
### 26.7 テンプレートの実装
|
|
2023
|
+
|
|
2024
|
+
<details>
|
|
2025
|
+
<summary>list.html ページネーション部分</summary>
|
|
2026
|
+
|
|
2027
|
+
```html
|
|
2028
|
+
<!-- 検索フォーム -->
|
|
2029
|
+
<div class="search-form">
|
|
2030
|
+
<form th:action="@{/partners}" method="get" class="row g-3">
|
|
2031
|
+
<!-- 表示件数 -->
|
|
2032
|
+
<div class="col-md-2">
|
|
2033
|
+
<label class="form-label">表示件数</label>
|
|
2034
|
+
<select name="size" class="form-select">
|
|
2035
|
+
<option value="10" th:selected="${currentSize == 10}">10件</option>
|
|
2036
|
+
<option value="25" th:selected="${currentSize == 25}">25件</option>
|
|
2037
|
+
<option value="50" th:selected="${currentSize == 50}">50件</option>
|
|
2038
|
+
<option value="100" th:selected="${currentSize == 100}">100件</option>
|
|
2039
|
+
</select>
|
|
2040
|
+
</div>
|
|
2041
|
+
<div class="col-md-2 d-flex align-items-end">
|
|
2042
|
+
<button type="submit" class="btn btn-secondary">検索</button>
|
|
2043
|
+
</div>
|
|
2044
|
+
</form>
|
|
2045
|
+
</div>
|
|
2046
|
+
|
|
2047
|
+
<!-- ページネーション -->
|
|
2048
|
+
<div class="mt-3">
|
|
2049
|
+
<!-- 件数表示 -->
|
|
2050
|
+
<div class="text-muted text-center mb-2">
|
|
2051
|
+
<span th:if="${page.totalElements > 0}">
|
|
2052
|
+
<span th:text="${page.page * page.size + 1}">1</span> -
|
|
2053
|
+
<span th:text="${page.page * page.size + #lists.size(partners)}">10</span> 件
|
|
2054
|
+
(全 <span th:text="${page.totalElements}">0</span> 件)
|
|
2055
|
+
</span>
|
|
2056
|
+
<span th:if="${page.totalElements == 0}">0 件</span>
|
|
2057
|
+
</div>
|
|
2058
|
+
|
|
2059
|
+
<!-- ページナビゲーション -->
|
|
2060
|
+
<nav th:if="${page.totalPages > 1}" aria-label="ページナビゲーション">
|
|
2061
|
+
<ul class="pagination justify-content-center mb-0">
|
|
2062
|
+
<!-- 最初のページへ -->
|
|
2063
|
+
<li class="page-item" th:classappend="${page.first} ? 'disabled'">
|
|
2064
|
+
<a class="page-link" th:href="@{/partners(page=0, size=${currentSize})}">«</a>
|
|
2065
|
+
</li>
|
|
2066
|
+
<!-- 前のページへ -->
|
|
2067
|
+
<li class="page-item" th:classappend="${!page.hasPrevious()} ? 'disabled'">
|
|
2068
|
+
<a class="page-link" th:href="@{/partners(page=${page.page - 1}, size=${currentSize})}">‹</a>
|
|
2069
|
+
</li>
|
|
2070
|
+
|
|
2071
|
+
<!-- ページ番号 -->
|
|
2072
|
+
<th:block th:with="startPage=${page.page > 2 ? page.page - 2 : 0},
|
|
2073
|
+
endPage=${page.page + 2 < page.totalPages - 1 ? page.page + 2 : page.totalPages - 1}">
|
|
2074
|
+
<li class="page-item" th:if="${startPage > 0}">
|
|
2075
|
+
<span class="page-link">...</span>
|
|
2076
|
+
</li>
|
|
2077
|
+
<li th:each="i : ${#numbers.sequence(startPage, endPage)}"
|
|
2078
|
+
class="page-item"
|
|
2079
|
+
th:classappend="${i == page.page} ? 'active'">
|
|
2080
|
+
<a class="page-link"
|
|
2081
|
+
th:href="@{/partners(page=${i}, size=${currentSize})}"
|
|
2082
|
+
th:text="${i + 1}">1</a>
|
|
2083
|
+
</li>
|
|
2084
|
+
<li class="page-item" th:if="${endPage < page.totalPages - 1}">
|
|
2085
|
+
<span class="page-link">...</span>
|
|
2086
|
+
</li>
|
|
2087
|
+
</th:block>
|
|
2088
|
+
|
|
2089
|
+
<!-- 次のページへ -->
|
|
2090
|
+
<li class="page-item" th:classappend="${!page.hasNext()} ? 'disabled'">
|
|
2091
|
+
<a class="page-link" th:href="@{/partners(page=${page.page + 1}, size=${currentSize})}">›</a>
|
|
2092
|
+
</li>
|
|
2093
|
+
<!-- 最後のページへ -->
|
|
2094
|
+
<li class="page-item" th:classappend="${page.last} ? 'disabled'">
|
|
2095
|
+
<a class="page-link" th:href="@{/partners(page=${page.totalPages - 1}, size=${currentSize})}">»</a>
|
|
2096
|
+
</li>
|
|
2097
|
+
</ul>
|
|
2098
|
+
</nav>
|
|
2099
|
+
</div>
|
|
2100
|
+
```
|
|
2101
|
+
|
|
2102
|
+
</details>
|
|
2103
|
+
|
|
2104
|
+
---
|
|
2105
|
+
|
|
2106
|
+
### 26.8 ページネーションの動作
|
|
2107
|
+
|
|
2108
|
+
```
|
|
2109
|
+
ページネーション処理フロー
|
|
2110
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
2111
|
+
│ ブラウザ │
|
|
2112
|
+
│ /partners?page=2&size=10&keyword=xxx │
|
|
2113
|
+
└─────────────────────────────────────────────────────────────┘
|
|
2114
|
+
│
|
|
2115
|
+
▼
|
|
2116
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
2117
|
+
│ Controller │
|
|
2118
|
+
│ - page, size, keyword パラメータを受け取る │
|
|
2119
|
+
│ - UseCase.getPartners(page, size, keyword) を呼び出す │
|
|
2120
|
+
└─────────────────────────────────────────────────────────────┘
|
|
2121
|
+
│
|
|
2122
|
+
▼
|
|
2123
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
2124
|
+
│ Service / Repository │
|
|
2125
|
+
│ - offset = page * size を計算 │
|
|
2126
|
+
│ - findWithPagination(offset, size, keyword) を実行 │
|
|
2127
|
+
│ - count(keyword) で総件数を取得 │
|
|
2128
|
+
│ - PageResult<T> を生成して返却 │
|
|
2129
|
+
└─────────────────────────────────────────────────────────────┘
|
|
2130
|
+
│
|
|
2131
|
+
▼
|
|
2132
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
2133
|
+
│ SQL (MyBatis) │
|
|
2134
|
+
│ SELECT * FROM "テーブル" │
|
|
2135
|
+
│ WHERE ... LIMIT 10 OFFSET 20 │
|
|
2136
|
+
└─────────────────────────────────────────────────────────────┘
|
|
2137
|
+
│
|
|
2138
|
+
▼
|
|
2139
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
2140
|
+
│ PageResult<T> │
|
|
2141
|
+
│ - content: データリスト (10件) │
|
|
2142
|
+
│ - page: 2 │
|
|
2143
|
+
│ - size: 10 │
|
|
2144
|
+
│ - totalElements: 57 │
|
|
2145
|
+
│ - totalPages: 6 │
|
|
2146
|
+
│ - isFirst/isLast/hasPrevious/hasNext メソッド │
|
|
2147
|
+
└─────────────────────────────────────────────────────────────┘
|
|
2148
|
+
```
|
|
2149
|
+
|
|
2150
|
+
---
|
|
2151
|
+
|
|
2152
|
+
### 26.9 検索条件の保持
|
|
2153
|
+
|
|
2154
|
+
ページ遷移時に検索条件を保持するため、すべてのリンクに検索パラメータを含めます。
|
|
2155
|
+
|
|
2156
|
+
```html
|
|
2157
|
+
<!-- 検索条件付きページネーションリンク -->
|
|
2158
|
+
<a th:href="@{/partners(
|
|
2159
|
+
page=${i},
|
|
2160
|
+
size=${currentSize},
|
|
2161
|
+
type=${selectedType},
|
|
2162
|
+
keyword=${keyword}
|
|
2163
|
+
)}">
|
|
2164
|
+
```
|
|
2165
|
+
|
|
2166
|
+
---
|
|
2167
|
+
|
|
2168
|
+
## まとめ
|
|
2169
|
+
|
|
2170
|
+
### 学んだこと
|
|
2171
|
+
|
|
2172
|
+
1. **帳票の種類**: 日計表、試算表、元帳、財務諸表
|
|
2173
|
+
2. **HTML 表示**: Thymeleaf による帳票画面の実装
|
|
2174
|
+
3. **Excel 出力**: Apache POI による Excel ファイル生成
|
|
2175
|
+
4. **PDF 出力**: iText による PDF ファイル生成
|
|
2176
|
+
5. **ダウンロード**: ResponseEntity による添付ファイル返却
|
|
2177
|
+
6. **ページネーション**: PageResult<T> による一覧画面のページ分割
|
|
2178
|
+
|
|
2179
|
+
---
|
|
2180
|
+
|
|
2181
|
+
### 実装した機能
|
|
2182
|
+
|
|
2183
|
+
| 機能 | 説明 |
|
|
2184
|
+
|------|------|
|
|
2185
|
+
| **ホーム画面** | ダッシュボード、クイックアクセス |
|
|
2186
|
+
| **勘定科目マスタ** | 一覧・登録・編集・削除・検索 |
|
|
2187
|
+
| **仕訳入力** | 複合仕訳対応、貸借チェック |
|
|
2188
|
+
| **帳票出力** | 日計表、試算表、財務諸表 |
|
|
2189
|
+
|
|
2190
|
+
### モノリス vs API サーバー
|
|
2191
|
+
|
|
2192
|
+
| 観点 | モノリス | API サーバー |
|
|
2193
|
+
|------|---------|-------------|
|
|
2194
|
+
| **適用場面** | 社内システム、小〜中規模 | 大規模、SPA 連携 |
|
|
2195
|
+
| **開発速度** | 高速 | 環境構築に時間 |
|
|
2196
|
+
| **保守性** | 適切な設計で高い | 高い |
|
|
2197
|
+
| **チーム構成** | フルスタック | フロント/バック分離 |
|
|
2198
|
+
|
|
2199
|
+
### 技術的なポイント
|
|
2200
|
+
|
|
2201
|
+
1. **ヘキサゴナルアーキテクチャ**: モノリスでも適用可能
|
|
2202
|
+
2. **Thymeleaf**: サーバーサイドレンダリング
|
|
2203
|
+
3. **htmx**: JavaScript 不要の部分更新
|
|
2204
|
+
4. **PRG パターン**: フォーム二重送信防止
|
|
2205
|
+
5. **帳票生成**: POI(Excel)、iText(PDF)
|