@k2works/claude-code-booster 3.4.1 → 3.6.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/LICENSE +21 -21
- package/README.md +42 -42
- package/bin/claude-code-booster +90 -90
- package/lib/assets/.claude/README.md +239 -239
- package/lib/assets/.claude/scripts/generate-inception-deck.mjs +911 -911
- package/lib/assets/.claude/settings.json +11 -11
- package/lib/assets/.claude/skills/ai-agent-guidelines/SKILL.md +111 -111
- package/lib/assets/.claude/skills/analyzing-architecture/SKILL.md +83 -83
- package/lib/assets/.claude/skills/analyzing-business/SKILL.md +95 -95
- package/lib/assets/.claude/skills/analyzing-data-model/SKILL.md +77 -77
- package/lib/assets/.claude/skills/analyzing-domain-model/SKILL.md +117 -88
- package/lib/assets/.claude/skills/analyzing-inception-deck/SKILL.md +84 -84
- package/lib/assets/.claude/skills/analyzing-non-functional/SKILL.md +95 -95
- package/lib/assets/.claude/skills/analyzing-operation/SKILL.md +95 -95
- package/lib/assets/.claude/skills/analyzing-requirements/SKILL.md +91 -91
- package/lib/assets/.claude/skills/analyzing-tech-stack/SKILL.md +101 -101
- package/lib/assets/.claude/skills/analyzing-test-strategy/SKILL.md +89 -89
- package/lib/assets/.claude/skills/analyzing-ui-design/SKILL.md +80 -80
- package/lib/assets/.claude/skills/analyzing-usecases/SKILL.md +72 -72
- package/lib/assets/.claude/skills/creating-adr/SKILL.md +113 -113
- package/lib/assets/.claude/skills/developing-backend/SKILL.md +100 -100
- package/lib/assets/.claude/skills/developing-frontend/SKILL.md +93 -93
- package/lib/assets/.claude/skills/developing-release/SKILL.md +120 -120
- package/lib/assets/.claude/skills/generating-slides/SKILL.md +94 -94
- package/lib/assets/.claude/skills/git-commit/SKILL.md +81 -81
- package/lib/assets/.claude/skills/killing-processes/SKILL.md +44 -44
- package/lib/assets/.claude/skills/operating-backup/SKILL.md +59 -59
- package/lib/assets/.claude/skills/operating-cicd/SKILL.md +54 -54
- package/lib/assets/.claude/skills/operating-deploy/SKILL.md +67 -67
- package/lib/assets/.claude/skills/operating-docs/SKILL.md +219 -219
- package/lib/assets/.claude/skills/operating-provision/SKILL.md +77 -77
- package/lib/assets/.claude/skills/operating-setup/SKILL.md +63 -63
- package/lib/assets/.claude/skills/orchestrating-analysis/SKILL.md +104 -104
- package/lib/assets/.claude/skills/orchestrating-development/SKILL.md +162 -161
- package/lib/assets/.claude/skills/orchestrating-operation/SKILL.md +158 -158
- package/lib/assets/.claude/skills/orchestrating-project/SKILL.md +144 -144
- package/lib/assets/.claude/skills/planning-releases/SKILL.md +119 -119
- package/lib/assets/.claude/skills/syncing-github-project/SKILL.md +151 -151
- package/lib/assets/.claude/skills/tracking-progress/SKILL.md +91 -91
- package/lib/assets/.claude/skills/validating-iteration-plan/SKILL.md +29 -1
- package/lib/assets/.devcontainer/devcontainer.json +34 -34
- package/lib/assets/.env.example +17 -17
- package/lib/assets/.gitattributes +4 -4
- package/lib/assets/.github/workflows/docker-publish.yml +77 -77
- package/lib/assets/.github/workflows/mkdocs.yml +39 -39
- package/lib/assets/AGENTS.md +94 -94
- package/lib/assets/CLAUDE.md +183 -183
- package/lib/assets/README.md +254 -254
- package/lib/assets/docker-compose.yml +33 -33
- package/lib/assets/docs/adr/index.md +10 -10
- package/lib/assets/docs/article/functional-desgin-ppp/all/01-immutability-and-data-transformation.md +475 -475
- package/lib/assets/docs/article/functional-desgin-ppp/all/02-function-composition.md +519 -519
- package/lib/assets/docs/article/functional-desgin-ppp/all/03-polymorphism.md +537 -537
- package/lib/assets/docs/article/functional-desgin-ppp/all/04-data-validation.md +300 -300
- package/lib/assets/docs/article/functional-desgin-ppp/all/05-property-based-testing.md +320 -320
- package/lib/assets/docs/article/functional-desgin-ppp/all/06-tdd-and-functional.md +498 -498
- package/lib/assets/docs/article/functional-desgin-ppp/all/07-composite-pattern.md +298 -298
- package/lib/assets/docs/article/functional-desgin-ppp/all/08-decorator-pattern.md +291 -291
- package/lib/assets/docs/article/functional-desgin-ppp/all/09-adapter-pattern.md +336 -336
- package/lib/assets/docs/article/functional-desgin-ppp/all/10-strategy-pattern.md +303 -303
- package/lib/assets/docs/article/functional-desgin-ppp/all/11-command-pattern.md +286 -286
- package/lib/assets/docs/article/functional-desgin-ppp/all/12-visitor-pattern.md +322 -322
- package/lib/assets/docs/article/functional-desgin-ppp/all/13-abstract-factory-pattern.md +319 -319
- package/lib/assets/docs/article/functional-desgin-ppp/all/14-abstract-server-pattern.md +365 -365
- package/lib/assets/docs/article/functional-desgin-ppp/all/15-gossiping-bus-drivers.md +156 -156
- package/lib/assets/docs/article/functional-desgin-ppp/all/16-payroll-system.md +178 -178
- package/lib/assets/docs/article/functional-desgin-ppp/all/17-video-rental-system.md +312 -312
- package/lib/assets/docs/article/functional-desgin-ppp/all/18-concurrency-system.md +287 -287
- package/lib/assets/docs/article/functional-desgin-ppp/all/19-wa-tor-simulation.md +286 -286
- package/lib/assets/docs/article/functional-desgin-ppp/all/20-pattern-interactions.md +274 -274
- package/lib/assets/docs/article/functional-desgin-ppp/all/21-best-practices.md +294 -294
- package/lib/assets/docs/article/functional-desgin-ppp/all/22-oo-to-fp-migration.md +337 -337
- package/lib/assets/docs/article/functional-desgin-ppp/all/index.md +388 -388
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/01-immutability-and-data-transformation.md +273 -273
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/02-function-composition.md +380 -380
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/03-polymorphism.md +384 -384
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/04-clojure-spec.md +350 -350
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/05-property-based-testing.md +352 -352
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/06-tdd-in-functional.md +383 -383
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/07-composite-pattern.md +529 -529
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/08-decorator-pattern.md +395 -395
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/09-adapter-pattern.md +399 -399
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/10-strategy-pattern.md +485 -485
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/11-command-pattern.md +566 -566
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/12-visitor-pattern.md +567 -567
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/13-abstract-factory-pattern.md +475 -475
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/14-abstract-server-pattern.md +462 -462
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/15-gossiping-bus-drivers.md +325 -325
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/16-payroll-system.md +401 -401
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/17-video-rental-system.md +450 -450
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/18-concurrency-system.md +475 -475
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/19-wator-simulation.md +739 -739
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/20-pattern-interactions.md +567 -567
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/21-best-practices.md +518 -518
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/22-oo-to-fp-migration.md +532 -532
- package/lib/assets/docs/article/functional-desgin-ppp/clojure/index.md +241 -241
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/01-immutability-and-data-transformation.md +383 -383
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/02-function-composition.md +374 -374
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/03-polymorphism.md +375 -375
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/04-data-validation.md +195 -195
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/05-property-based-testing.md +268 -268
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/06-tdd-and-fp.md +294 -294
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/07-effects-and-pure-functions.md +164 -164
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/08-error-handling-strategies.md +168 -168
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/09-io-and-external-systems.md +254 -254
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/10-concurrency-patterns.md +269 -269
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/11-command-pattern.md +148 -148
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/12-visitor-pattern.md +176 -176
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/13-abstract-factory-pattern.md +604 -604
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/14-abstract-server-pattern.md +729 -729
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/15-gossiping-bus-drivers.md +291 -291
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/16-payroll-system.md +420 -420
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/17-video-rental-system.md +319 -319
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/18-concurrency-system.md +466 -466
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/19-wator-simulation.md +523 -523
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/20-pattern-interactions.md +287 -287
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/21-best-practices.md +340 -340
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/22-oo-to-fp-migration.md +395 -395
- package/lib/assets/docs/article/functional-desgin-ppp/elixir/index.md +248 -248
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/01-immutability-and-data-transformation.md +384 -384
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/02-function-composition.md +452 -452
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/03-polymorphism.md +495 -495
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/04-data-validation.md +416 -416
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/05-property-based-testing.md +382 -382
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/06-tdd-functional.md +687 -687
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/07-composite-pattern.md +442 -442
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/08-decorator-pattern.md +479 -479
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/09-adapter-pattern.md +479 -479
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/10-strategy-pattern.md +427 -427
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/11-command-pattern.md +428 -428
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/12-visitor-pattern.md +339 -339
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/13-abstract-factory-pattern.md +309 -309
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/14-abstract-server-pattern.md +596 -596
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/15-gossiping-bus-drivers.md +355 -355
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/16-payroll-system.md +350 -350
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/17-video-rental-system.md +414 -414
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/18-concurrency-system.md +367 -367
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/19-wator-simulation.md +403 -403
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/20-pattern-interactions.md +291 -291
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/21-best-practices.md +324 -324
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/22-oo-to-fp-migration.md +332 -332
- package/lib/assets/docs/article/functional-desgin-ppp/fsharp/index.md +274 -274
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/01-immutability-and-data-transformation.md +298 -298
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/02-function-composition.md +304 -304
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/03-polymorphism.md +362 -362
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/04-data-validation.md +257 -257
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/05-property-based-testing.md +254 -254
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/06-tdd-functional.md +283 -283
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/07-composite-pattern.md +395 -395
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/08-decorator-pattern.md +319 -319
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/09-adapter-pattern.md +382 -382
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/10-strategy-pattern.md +287 -287
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/11-command-pattern.md +303 -303
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/12-visitor-pattern.md +326 -326
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/13-abstract-factory-pattern.md +332 -332
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/14-abstract-server-pattern.md +379 -379
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/15-gossiping-bus-drivers.md +177 -177
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/16-payroll-system.md +219 -219
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/17-video-rental-system.md +244 -244
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/18-concurrency-system.md +363 -363
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/19-wator-simulation.md +438 -438
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/20-pattern-interactions.md +325 -325
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/21-best-practices.md +403 -403
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/22-oo-to-fp-migration.md +469 -469
- package/lib/assets/docs/article/functional-desgin-ppp/haskell/index.md +174 -174
- package/lib/assets/docs/article/functional-desgin-ppp/index.md +90 -90
- package/lib/assets/docs/article/functional-desgin-ppp/rust/01-immutability-and-data-transformation.md +450 -450
- package/lib/assets/docs/article/functional-desgin-ppp/rust/02-function-composition.md +463 -463
- package/lib/assets/docs/article/functional-desgin-ppp/rust/03-polymorphism.md +425 -425
- package/lib/assets/docs/article/functional-desgin-ppp/rust/04-data-validation.md +273 -273
- package/lib/assets/docs/article/functional-desgin-ppp/rust/05-property-based-testing.md +247 -247
- package/lib/assets/docs/article/functional-desgin-ppp/rust/06-tdd-and-functional.md +841 -841
- package/lib/assets/docs/article/functional-desgin-ppp/rust/07-composite-pattern.md +384 -384
- package/lib/assets/docs/article/functional-desgin-ppp/rust/08-decorator-pattern.md +383 -383
- package/lib/assets/docs/article/functional-desgin-ppp/rust/09-adapter-pattern.md +339 -339
- package/lib/assets/docs/article/functional-desgin-ppp/rust/10-strategy-pattern.md +331 -331
- package/lib/assets/docs/article/functional-desgin-ppp/rust/11-command-pattern.md +356 -356
- package/lib/assets/docs/article/functional-desgin-ppp/rust/12-visitor-pattern.md +379 -379
- package/lib/assets/docs/article/functional-desgin-ppp/rust/13-abstract-factory-pattern.md +361 -361
- package/lib/assets/docs/article/functional-desgin-ppp/rust/14-abstract-server-pattern.md +392 -392
- package/lib/assets/docs/article/functional-desgin-ppp/rust/15-gossiping-bus-drivers.md +300 -300
- package/lib/assets/docs/article/functional-desgin-ppp/rust/16-payroll-system.md +297 -297
- package/lib/assets/docs/article/functional-desgin-ppp/rust/17-video-rental-system.md +304 -304
- package/lib/assets/docs/article/functional-desgin-ppp/rust/18-concurrency-system.md +315 -315
- package/lib/assets/docs/article/functional-desgin-ppp/rust/19-wator-simulation.md +311 -311
- package/lib/assets/docs/article/functional-desgin-ppp/rust/20-pattern-interactions.md +304 -304
- package/lib/assets/docs/article/functional-desgin-ppp/rust/21-best-practices.md +336 -336
- package/lib/assets/docs/article/functional-desgin-ppp/rust/22-oo-to-fp-migration.md +349 -349
- package/lib/assets/docs/article/functional-desgin-ppp/rust/index.md +243 -243
- package/lib/assets/docs/article/functional-desgin-ppp/scala/01-immutability-and-data-transformation.md +328 -328
- package/lib/assets/docs/article/functional-desgin-ppp/scala/02-function-composition.md +348 -348
- package/lib/assets/docs/article/functional-desgin-ppp/scala/03-polymorphism.md +357 -357
- package/lib/assets/docs/article/functional-desgin-ppp/scala/04-data-validation.md +364 -364
- package/lib/assets/docs/article/functional-desgin-ppp/scala/05-property-based-testing.md +515 -515
- package/lib/assets/docs/article/functional-desgin-ppp/scala/06-tdd-functional.md +557 -557
- package/lib/assets/docs/article/functional-desgin-ppp/scala/07-composite-pattern.md +363 -363
- package/lib/assets/docs/article/functional-desgin-ppp/scala/08-decorator-pattern.md +327 -327
- package/lib/assets/docs/article/functional-desgin-ppp/scala/09-adapter-pattern.md +517 -517
- package/lib/assets/docs/article/functional-desgin-ppp/scala/10-strategy-pattern.md +441 -441
- package/lib/assets/docs/article/functional-desgin-ppp/scala/11-command-pattern.md +407 -407
- package/lib/assets/docs/article/functional-desgin-ppp/scala/12-visitor-pattern.md +379 -379
- package/lib/assets/docs/article/functional-desgin-ppp/scala/13-abstract-factory-pattern.md +398 -398
- package/lib/assets/docs/article/functional-desgin-ppp/scala/14-abstract-server-pattern.md +476 -476
- package/lib/assets/docs/article/functional-desgin-ppp/scala/15-gossiping-bus-drivers.md +391 -391
- package/lib/assets/docs/article/functional-desgin-ppp/scala/16-payroll-system.md +342 -342
- package/lib/assets/docs/article/functional-desgin-ppp/scala/17-video-rental-system.md +324 -324
- package/lib/assets/docs/article/functional-desgin-ppp/scala/18-concurrency-system.md +730 -730
- package/lib/assets/docs/article/functional-desgin-ppp/scala/19-wator-simulation.md +624 -624
- package/lib/assets/docs/article/functional-desgin-ppp/scala/20-pattern-interactions.md +512 -512
- package/lib/assets/docs/article/functional-desgin-ppp/scala/21-best-practices.md +433 -433
- package/lib/assets/docs/article/functional-desgin-ppp/scala/22-oo-to-fp-migration.md +688 -688
- package/lib/assets/docs/article/functional-desgin-ppp/scala/index.md +243 -243
- package/lib/assets/docs/article/getting-start-tdd/clojure/01-todo-list-and-first-test.md +166 -166
- package/lib/assets/docs/article/getting-start-tdd/clojure/02-fake-it-and-triangulation.md +162 -162
- package/lib/assets/docs/article/getting-start-tdd/clojure/03-obvious-implementation-and-refactoring.md +135 -135
- package/lib/assets/docs/article/getting-start-tdd/clojure/04-version-control-and-conventional-commits.md +88 -88
- package/lib/assets/docs/article/getting-start-tdd/clojure/05-package-management-and-static-analysis.md +299 -299
- package/lib/assets/docs/article/getting-start-tdd/clojure/06-task-runner-and-ci-cd.md +241 -241
- package/lib/assets/docs/article/getting-start-tdd/clojure/07-protocols-and-records.md +131 -131
- package/lib/assets/docs/article/getting-start-tdd/clojure/08-multimethods-and-design-patterns.md +130 -130
- package/lib/assets/docs/article/getting-start-tdd/clojure/09-namespaces-and-module-design.md +127 -127
- package/lib/assets/docs/article/getting-start-tdd/clojure/10-higher-order-functions-and-composition.md +114 -114
- package/lib/assets/docs/article/getting-start-tdd/clojure/11-persistent-data-and-pipeline.md +138 -138
- package/lib/assets/docs/article/getting-start-tdd/clojure/12-error-handling-and-spec.md +161 -161
- package/lib/assets/docs/article/getting-start-tdd/clojure/index.md +65 -65
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter01.md +232 -232
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter02.md +244 -244
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter03.md +202 -202
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter04.md +92 -92
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter05.md +256 -256
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter06.md +195 -195
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter07.md +214 -214
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter08.md +249 -249
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter09.md +174 -174
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter10.md +166 -166
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter11.md +192 -192
- package/lib/assets/docs/article/getting-start-tdd/csharp/chapter12.md +211 -211
- package/lib/assets/docs/article/getting-start-tdd/csharp/index.md +83 -83
- package/lib/assets/docs/article/getting-start-tdd/elixir/01-todo-list-and-first-test.md +87 -87
- package/lib/assets/docs/article/getting-start-tdd/elixir/02-fake-it-and-triangulation.md +95 -95
- package/lib/assets/docs/article/getting-start-tdd/elixir/03-obvious-implementation-and-refactoring.md +109 -109
- package/lib/assets/docs/article/getting-start-tdd/elixir/04-version-control-and-conventional-commits.md +96 -96
- package/lib/assets/docs/article/getting-start-tdd/elixir/05-package-management-and-static-analysis.md +88 -88
- package/lib/assets/docs/article/getting-start-tdd/elixir/06-task-runner-and-ci-cd.md +71 -71
- package/lib/assets/docs/article/getting-start-tdd/elixir/07-structs-and-protocols.md +110 -110
- package/lib/assets/docs/article/getting-start-tdd/elixir/08-pattern-matching-and-guards.md +108 -108
- package/lib/assets/docs/article/getting-start-tdd/elixir/09-module-design-and-behaviours.md +104 -104
- package/lib/assets/docs/article/getting-start-tdd/elixir/10-higher-order-functions-and-pipeline.md +178 -178
- package/lib/assets/docs/article/getting-start-tdd/elixir/11-stream-and-lazy-evaluation.md +142 -142
- package/lib/assets/docs/article/getting-start-tdd/elixir/12-error-handling-and-with.md +145 -145
- package/lib/assets/docs/article/getting-start-tdd/elixir/index.md +35 -35
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter01.md +202 -202
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter02.md +246 -246
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter03.md +218 -218
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter04.md +179 -179
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter05.md +267 -267
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter06.md +190 -190
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter07.md +161 -161
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter08.md +175 -175
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter09.md +222 -222
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter10.md +189 -189
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter11.md +212 -212
- package/lib/assets/docs/article/getting-start-tdd/fsharp/chapter12.md +215 -215
- package/lib/assets/docs/article/getting-start-tdd/fsharp/index.md +71 -71
- package/lib/assets/docs/article/getting-start-tdd/go/01-todo-list-and-first-test.md +213 -213
- package/lib/assets/docs/article/getting-start-tdd/go/02-fake-it-and-triangulation.md +302 -302
- package/lib/assets/docs/article/getting-start-tdd/go/03-obvious-implementation-and-refactoring.md +339 -339
- package/lib/assets/docs/article/getting-start-tdd/go/04-version-control-and-conventional-commits.md +112 -112
- package/lib/assets/docs/article/getting-start-tdd/go/05-package-management-and-static-analysis.md +272 -272
- package/lib/assets/docs/article/getting-start-tdd/go/06-task-runner-and-ci-cd.md +233 -233
- package/lib/assets/docs/article/getting-start-tdd/go/07-encapsulation-and-polymorphism.md +394 -394
- package/lib/assets/docs/article/getting-start-tdd/go/08-design-patterns.md +422 -422
- package/lib/assets/docs/article/getting-start-tdd/go/09-solid-principles-and-module-design.md +400 -400
- package/lib/assets/docs/article/getting-start-tdd/go/10-higher-order-functions-and-composition.md +226 -226
- package/lib/assets/docs/article/getting-start-tdd/go/11-immutable-data-and-pipeline.md +296 -296
- package/lib/assets/docs/article/getting-start-tdd/go/12-error-handling-and-type-safety.md +411 -411
- package/lib/assets/docs/article/getting-start-tdd/go/index.md +83 -83
- package/lib/assets/docs/article/getting-start-tdd/haskell/01-todo-list-and-first-test.md +279 -279
- package/lib/assets/docs/article/getting-start-tdd/haskell/02-fake-it-and-triangulation.md +337 -337
- package/lib/assets/docs/article/getting-start-tdd/haskell/03-obvious-implementation-and-refactoring.md +257 -257
- package/lib/assets/docs/article/getting-start-tdd/haskell/04-version-control-and-conventional-commits.md +182 -182
- package/lib/assets/docs/article/getting-start-tdd/haskell/05-package-management-and-static-analysis.md +313 -313
- package/lib/assets/docs/article/getting-start-tdd/haskell/06-task-runner-and-ci-cd.md +309 -309
- package/lib/assets/docs/article/getting-start-tdd/haskell/07-algebraic-data-types-and-type-classes.md +412 -412
- package/lib/assets/docs/article/getting-start-tdd/haskell/08-pattern-matching-and-guards.md +390 -390
- package/lib/assets/docs/article/getting-start-tdd/haskell/09-module-design-and-smart-constructors.md +461 -461
- package/lib/assets/docs/article/getting-start-tdd/haskell/10-higher-order-functions-and-currying.md +434 -434
- package/lib/assets/docs/article/getting-start-tdd/haskell/11-function-composition-and-point-free.md +392 -392
- package/lib/assets/docs/article/getting-start-tdd/haskell/12-monad-and-error-handling.md +631 -631
- package/lib/assets/docs/article/getting-start-tdd/haskell/index.md +49 -49
- package/lib/assets/docs/article/getting-start-tdd/index.md +93 -93
- package/lib/assets/docs/article/getting-start-tdd/integration/01-language-overview.md +375 -375
- package/lib/assets/docs/article/getting-start-tdd/integration/02-test-framework-comparison.md +349 -349
- package/lib/assets/docs/article/getting-start-tdd/integration/03-tdd-pattern-comparison.md +445 -445
- package/lib/assets/docs/article/getting-start-tdd/integration/04-type-system-comparison.md +409 -409
- package/lib/assets/docs/article/getting-start-tdd/integration/05-dev-environment-comparison.md +330 -330
- package/lib/assets/docs/article/getting-start-tdd/integration/06-learning-roadmap.md +290 -290
- package/lib/assets/docs/article/getting-start-tdd/integration/index.md +69 -69
- package/lib/assets/docs/article/getting-start-tdd/java/01-todo-list-and-first-test.md +234 -234
- package/lib/assets/docs/article/getting-start-tdd/java/02-fake-it-and-triangulation.md +261 -261
- package/lib/assets/docs/article/getting-start-tdd/java/03-obvious-implementation-and-refactoring.md +185 -185
- package/lib/assets/docs/article/getting-start-tdd/java/04-version-control-and-conventional-commits.md +115 -115
- package/lib/assets/docs/article/getting-start-tdd/java/05-package-management-and-static-analysis.md +382 -382
- package/lib/assets/docs/article/getting-start-tdd/java/06-task-runner-and-ci-cd.md +272 -272
- package/lib/assets/docs/article/getting-start-tdd/java/07-encapsulation-and-polymorphism.md +626 -626
- package/lib/assets/docs/article/getting-start-tdd/java/08-design-patterns.md +393 -393
- package/lib/assets/docs/article/getting-start-tdd/java/09-solid-principles-and-module-design.md +310 -310
- package/lib/assets/docs/article/getting-start-tdd/java/10-higher-order-functions-and-composition.md +188 -188
- package/lib/assets/docs/article/getting-start-tdd/java/11-immutable-data-and-pipeline.md +167 -167
- package/lib/assets/docs/article/getting-start-tdd/java/12-error-handling-and-type-safety.md +205 -205
- package/lib/assets/docs/article/getting-start-tdd/java/index.md +61 -61
- package/lib/assets/docs/article/getting-start-tdd/node/01-todo-list-and-first-test.md +244 -244
- package/lib/assets/docs/article/getting-start-tdd/node/02-fake-it-and-triangulation.md +262 -262
- package/lib/assets/docs/article/getting-start-tdd/node/03-obvious-implementation-and-refactoring.md +169 -169
- package/lib/assets/docs/article/getting-start-tdd/node/04-version-control-and-conventional-commits.md +112 -112
- package/lib/assets/docs/article/getting-start-tdd/node/05-package-management-and-static-analysis.md +314 -314
- package/lib/assets/docs/article/getting-start-tdd/node/06-task-runner-and-ci-cd.md +235 -235
- package/lib/assets/docs/article/getting-start-tdd/node/07-encapsulation-and-polymorphism.md +327 -327
- package/lib/assets/docs/article/getting-start-tdd/node/08-design-patterns.md +322 -322
- package/lib/assets/docs/article/getting-start-tdd/node/09-solid-principles-and-module-design.md +285 -285
- package/lib/assets/docs/article/getting-start-tdd/node/10-higher-order-functions-and-composition.md +199 -199
- package/lib/assets/docs/article/getting-start-tdd/node/11-immutable-data-and-pipeline.md +207 -207
- package/lib/assets/docs/article/getting-start-tdd/node/12-error-handling-and-type-safety.md +295 -295
- package/lib/assets/docs/article/getting-start-tdd/node/index.md +56 -56
- package/lib/assets/docs/article/getting-start-tdd/php/01-todo-list-and-first-test.md +259 -259
- package/lib/assets/docs/article/getting-start-tdd/php/02-fake-it-and-triangulation.md +200 -200
- package/lib/assets/docs/article/getting-start-tdd/php/03-obvious-implementation-and-refactoring.md +248 -248
- package/lib/assets/docs/article/getting-start-tdd/php/04-version-control-and-conventional-commits.md +141 -141
- package/lib/assets/docs/article/getting-start-tdd/php/05-package-management-and-static-analysis.md +410 -410
- package/lib/assets/docs/article/getting-start-tdd/php/06-task-runner-and-ci-cd.md +321 -321
- package/lib/assets/docs/article/getting-start-tdd/php/07-encapsulation-and-polymorphism.md +372 -372
- package/lib/assets/docs/article/getting-start-tdd/php/08-design-patterns.md +453 -453
- package/lib/assets/docs/article/getting-start-tdd/php/09-solid-principles-and-module-design.md +460 -460
- package/lib/assets/docs/article/getting-start-tdd/php/10-higher-order-functions-and-composition.md +182 -182
- package/lib/assets/docs/article/getting-start-tdd/php/11-immutable-data-and-pipeline.md +266 -266
- package/lib/assets/docs/article/getting-start-tdd/php/12-error-handling-and-type-safety.md +308 -308
- package/lib/assets/docs/article/getting-start-tdd/php/index.md +84 -84
- package/lib/assets/docs/article/getting-start-tdd/python/01-todo-list-and-first-test.md +201 -201
- package/lib/assets/docs/article/getting-start-tdd/python/02-fake-it-and-triangulation.md +247 -247
- package/lib/assets/docs/article/getting-start-tdd/python/03-obvious-implementation-and-refactoring.md +199 -199
- package/lib/assets/docs/article/getting-start-tdd/python/04-version-control-and-conventional-commits.md +87 -87
- package/lib/assets/docs/article/getting-start-tdd/python/05-package-management-and-static-analysis.md +274 -274
- package/lib/assets/docs/article/getting-start-tdd/python/06-task-runner-and-ci-cd.md +190 -190
- package/lib/assets/docs/article/getting-start-tdd/python/07-encapsulation-and-polymorphism.md +208 -208
- package/lib/assets/docs/article/getting-start-tdd/python/08-design-patterns.md +172 -172
- package/lib/assets/docs/article/getting-start-tdd/python/09-solid-principles-and-module-design.md +130 -130
- package/lib/assets/docs/article/getting-start-tdd/python/10-higher-order-functions-and-composition.md +122 -122
- package/lib/assets/docs/article/getting-start-tdd/python/11-immutable-data-and-pipeline.md +116 -116
- package/lib/assets/docs/article/getting-start-tdd/python/12-error-handling-and-type-safety.md +126 -126
- package/lib/assets/docs/article/getting-start-tdd/python/index.md +55 -55
- package/lib/assets/docs/article/getting-start-tdd/ruby/01-todo-list-and-first-test.md +231 -231
- package/lib/assets/docs/article/getting-start-tdd/ruby/02-fake-it-and-triangulation.md +238 -238
- package/lib/assets/docs/article/getting-start-tdd/ruby/03-obvious-implementation-and-refactoring.md +228 -228
- package/lib/assets/docs/article/getting-start-tdd/ruby/04-version-control-and-conventional-commits.md +112 -112
- package/lib/assets/docs/article/getting-start-tdd/ruby/05-package-management-and-static-analysis.md +287 -287
- package/lib/assets/docs/article/getting-start-tdd/ruby/06-task-runner-and-ci-cd.md +248 -248
- package/lib/assets/docs/article/getting-start-tdd/ruby/07-encapsulation-and-polymorphism.md +279 -279
- package/lib/assets/docs/article/getting-start-tdd/ruby/08-design-patterns.md +329 -329
- package/lib/assets/docs/article/getting-start-tdd/ruby/09-solid-principles-and-module-design.md +196 -196
- package/lib/assets/docs/article/getting-start-tdd/ruby/10-higher-order-functions-and-composition.md +175 -175
- package/lib/assets/docs/article/getting-start-tdd/ruby/11-immutable-data-and-pipeline.md +237 -237
- package/lib/assets/docs/article/getting-start-tdd/ruby/12-error-handling-and-type-safety.md +398 -398
- package/lib/assets/docs/article/getting-start-tdd/ruby/index.md +83 -83
- package/lib/assets/docs/article/getting-start-tdd/rust/01-todo-list-and-first-test.md +211 -211
- package/lib/assets/docs/article/getting-start-tdd/rust/02-fake-it-and-triangulation.md +264 -264
- package/lib/assets/docs/article/getting-start-tdd/rust/03-obvious-implementation-and-refactoring.md +233 -233
- package/lib/assets/docs/article/getting-start-tdd/rust/04-version-control-and-conventional-commits.md +92 -92
- package/lib/assets/docs/article/getting-start-tdd/rust/05-package-management-and-static-analysis.md +212 -212
- package/lib/assets/docs/article/getting-start-tdd/rust/06-task-runner-and-ci-cd.md +164 -164
- package/lib/assets/docs/article/getting-start-tdd/rust/07-encapsulation-and-polymorphism.md +142 -142
- package/lib/assets/docs/article/getting-start-tdd/rust/08-design-patterns.md +145 -145
- package/lib/assets/docs/article/getting-start-tdd/rust/09-solid-principles-and-module-design.md +110 -110
- package/lib/assets/docs/article/getting-start-tdd/rust/10-higher-order-functions-and-composition.md +94 -94
- package/lib/assets/docs/article/getting-start-tdd/rust/11-immutable-data-and-pipeline.md +105 -105
- package/lib/assets/docs/article/getting-start-tdd/rust/12-error-handling-and-type-safety.md +112 -112
- package/lib/assets/docs/article/getting-start-tdd/rust/index.md +83 -83
- package/lib/assets/docs/article/getting-start-tdd/scala/01-todo-list-and-first-test.md +111 -111
- package/lib/assets/docs/article/getting-start-tdd/scala/02-fake-it-and-triangulation.md +107 -107
- package/lib/assets/docs/article/getting-start-tdd/scala/03-obvious-implementation-and-refactoring.md +99 -99
- package/lib/assets/docs/article/getting-start-tdd/scala/04-version-control-and-conventional-commits.md +123 -123
- package/lib/assets/docs/article/getting-start-tdd/scala/05-package-management-and-static-analysis.md +196 -196
- package/lib/assets/docs/article/getting-start-tdd/scala/06-task-runner-and-ci-cd.md +186 -186
- package/lib/assets/docs/article/getting-start-tdd/scala/07-case-classes-and-traits.md +139 -139
- package/lib/assets/docs/article/getting-start-tdd/scala/08-pattern-matching-and-sealed-traits.md +106 -106
- package/lib/assets/docs/article/getting-start-tdd/scala/09-packages-and-module-design.md +75 -75
- package/lib/assets/docs/article/getting-start-tdd/scala/10-higher-order-functions-and-composition.md +104 -104
- package/lib/assets/docs/article/getting-start-tdd/scala/11-collections-and-lazy-evaluation.md +94 -94
- package/lib/assets/docs/article/getting-start-tdd/scala/12-error-handling-and-type-safety.md +92 -92
- package/lib/assets/docs/article/getting-start-tdd/scala/index.md +65 -65
- package/lib/assets/docs/article/grokking-concurrency/all/index.md +404 -404
- package/lib/assets/docs/article/grokking-concurrency/all/part-1-ch02-sequential.md +554 -554
- package/lib/assets/docs/article/grokking-concurrency/all/part-2-ch04-05-threads.md +469 -469
- package/lib/assets/docs/article/grokking-concurrency/all/part-3-ch06-multitasking.md +520 -520
- package/lib/assets/docs/article/grokking-concurrency/all/part-4-ch07-parallel-patterns.md +420 -420
- package/lib/assets/docs/article/grokking-concurrency/all/part-5-ch08-09-synchronization.md +510 -510
- package/lib/assets/docs/article/grokking-concurrency/all/part-6-ch10-11-nonblocking-io.md +435 -435
- package/lib/assets/docs/article/grokking-concurrency/all/part-7-ch12-async.md +465 -465
- package/lib/assets/docs/article/grokking-concurrency/all/part-8-ch13-mapreduce.md +377 -377
- package/lib/assets/docs/article/grokking-concurrency/clojure/index.md +116 -116
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-1.md +108 -108
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-2.md +101 -101
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-3.md +122 -122
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-4.md +123 -123
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-5.md +118 -118
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-6.md +89 -89
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-7.md +100 -100
- package/lib/assets/docs/article/grokking-concurrency/clojure/part-8.md +120 -120
- package/lib/assets/docs/article/grokking-concurrency/csharp/index.md +101 -101
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-1.md +97 -97
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-2.md +123 -123
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-3.md +101 -101
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-4.md +112 -112
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-5.md +99 -99
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-6.md +61 -61
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-7.md +84 -84
- package/lib/assets/docs/article/grokking-concurrency/csharp/part-8.md +92 -92
- package/lib/assets/docs/article/grokking-concurrency/fsharp/index.md +65 -65
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-1.md +80 -80
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-2.md +103 -103
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-3.md +94 -94
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-4.md +110 -110
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-5.md +104 -104
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-6.md +93 -93
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-7.md +121 -121
- package/lib/assets/docs/article/grokking-concurrency/fsharp/part-8.md +107 -107
- package/lib/assets/docs/article/grokking-concurrency/haskell/index.md +248 -248
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-1.md +96 -96
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-2.md +96 -96
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-3.md +91 -91
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-4.md +106 -106
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-5.md +99 -99
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-6.md +95 -95
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-7.md +111 -111
- package/lib/assets/docs/article/grokking-concurrency/haskell/part-8.md +118 -118
- package/lib/assets/docs/article/grokking-concurrency/index.md +66 -66
- package/lib/assets/docs/article/grokking-concurrency/java/index.md +102 -102
- package/lib/assets/docs/article/grokking-concurrency/java/part-1.md +308 -308
- package/lib/assets/docs/article/grokking-concurrency/java/part-2.md +334 -334
- package/lib/assets/docs/article/grokking-concurrency/java/part-3.md +221 -221
- package/lib/assets/docs/article/grokking-concurrency/java/part-4.md +213 -213
- package/lib/assets/docs/article/grokking-concurrency/java/part-5.md +112 -112
- package/lib/assets/docs/article/grokking-concurrency/java/part-6.md +69 -69
- package/lib/assets/docs/article/grokking-concurrency/java/part-7.md +101 -101
- package/lib/assets/docs/article/grokking-concurrency/java/part-8.md +101 -101
- package/lib/assets/docs/article/grokking-concurrency/python/index.md +313 -313
- package/lib/assets/docs/article/grokking-concurrency/python/part-1.md +239 -239
- package/lib/assets/docs/article/grokking-concurrency/python/part-2.md +418 -418
- package/lib/assets/docs/article/grokking-concurrency/python/part-3.md +227 -227
- package/lib/assets/docs/article/grokking-concurrency/python/part-4.md +299 -299
- package/lib/assets/docs/article/grokking-concurrency/python/part-5.md +315 -315
- package/lib/assets/docs/article/grokking-concurrency/python/part-6.md +297 -297
- package/lib/assets/docs/article/grokking-concurrency/python/part-7.md +314 -314
- package/lib/assets/docs/article/grokking-concurrency/python/part-8.md +360 -360
- package/lib/assets/docs/article/grokking-concurrency/rust/index.md +270 -270
- package/lib/assets/docs/article/grokking-concurrency/rust/part-1.md +108 -108
- package/lib/assets/docs/article/grokking-concurrency/rust/part-2.md +120 -120
- package/lib/assets/docs/article/grokking-concurrency/rust/part-3.md +126 -126
- package/lib/assets/docs/article/grokking-concurrency/rust/part-4.md +175 -175
- package/lib/assets/docs/article/grokking-concurrency/rust/part-5.md +158 -158
- package/lib/assets/docs/article/grokking-concurrency/rust/part-6.md +94 -94
- package/lib/assets/docs/article/grokking-concurrency/rust/part-7.md +133 -133
- package/lib/assets/docs/article/grokking-concurrency/rust/part-8.md +155 -155
- package/lib/assets/docs/article/grokking-concurrency/scala/index.md +69 -69
- package/lib/assets/docs/article/grokking-concurrency/scala/part-1.md +78 -78
- package/lib/assets/docs/article/grokking-concurrency/scala/part-2.md +112 -112
- package/lib/assets/docs/article/grokking-concurrency/scala/part-3.md +93 -93
- package/lib/assets/docs/article/grokking-concurrency/scala/part-4.md +110 -110
- package/lib/assets/docs/article/grokking-concurrency/scala/part-5.md +119 -119
- package/lib/assets/docs/article/grokking-concurrency/scala/part-6.md +83 -83
- package/lib/assets/docs/article/grokking-concurrency/scala/part-7.md +131 -131
- package/lib/assets/docs/article/grokking-concurrency/scala/part-8.md +129 -129
- package/lib/assets/docs/article/grokkingfp/all/index.md +368 -368
- package/lib/assets/docs/article/grokkingfp/all/part-1-ch01-fp-introduction.md +530 -530
- package/lib/assets/docs/article/grokkingfp/all/part-1-ch02-pure-functions.md +923 -923
- package/lib/assets/docs/article/grokkingfp/all/part-2-ch03-immutable-data.md +1128 -1128
- package/lib/assets/docs/article/grokkingfp/all/part-2-ch04-higher-order-functions.md +1104 -1104
- package/lib/assets/docs/article/grokkingfp/all/part-2-ch05-flatmap.md +1026 -1026
- package/lib/assets/docs/article/grokkingfp/all/part-3-ch06-option.md +785 -785
- package/lib/assets/docs/article/grokkingfp/all/part-3-ch07-either-adt.md +871 -871
- package/lib/assets/docs/article/grokkingfp/all/part-4-ch08-io-monad.md +972 -972
- package/lib/assets/docs/article/grokkingfp/all/part-4-ch09-streams.md +926 -926
- package/lib/assets/docs/article/grokkingfp/all/part-5-ch10-concurrency.md +870 -870
- package/lib/assets/docs/article/grokkingfp/all/part-6-ch11-application.md +715 -715
- package/lib/assets/docs/article/grokkingfp/all/part-6-ch12-testing.md +626 -626
- package/lib/assets/docs/article/grokkingfp/all/writing-plan.md +712 -712
- package/lib/assets/docs/article/grokkingfp/clojure/index.md +276 -276
- package/lib/assets/docs/article/grokkingfp/clojure/part-1.md +667 -667
- package/lib/assets/docs/article/grokkingfp/clojure/part-2.md +643 -643
- package/lib/assets/docs/article/grokkingfp/clojure/part-3.md +620 -620
- package/lib/assets/docs/article/grokkingfp/clojure/part-4.md +697 -697
- package/lib/assets/docs/article/grokkingfp/clojure/part-5.md +751 -751
- package/lib/assets/docs/article/grokkingfp/clojure/part-6.md +721 -721
- package/lib/assets/docs/article/grokkingfp/csharp/index.md +246 -246
- package/lib/assets/docs/article/grokkingfp/csharp/part-1.md +811 -811
- package/lib/assets/docs/article/grokkingfp/csharp/part-2.md +971 -971
- package/lib/assets/docs/article/grokkingfp/csharp/part-3.md +981 -981
- package/lib/assets/docs/article/grokkingfp/csharp/part-4.md +949 -949
- package/lib/assets/docs/article/grokkingfp/csharp/part-5.md +947 -947
- package/lib/assets/docs/article/grokkingfp/csharp/part-6.md +739 -739
- package/lib/assets/docs/article/grokkingfp/elixir/index.md +203 -203
- package/lib/assets/docs/article/grokkingfp/elixir/part-1.md +712 -712
- package/lib/assets/docs/article/grokkingfp/elixir/part-2.md +838 -838
- package/lib/assets/docs/article/grokkingfp/elixir/part-3.md +985 -985
- package/lib/assets/docs/article/grokkingfp/elixir/part-4.md +974 -974
- package/lib/assets/docs/article/grokkingfp/elixir/part-5.md +1286 -1286
- package/lib/assets/docs/article/grokkingfp/elixir/part-6.md +1049 -1049
- package/lib/assets/docs/article/grokkingfp/fsharp/index.md +210 -210
- package/lib/assets/docs/article/grokkingfp/fsharp/part-1.md +714 -714
- package/lib/assets/docs/article/grokkingfp/fsharp/part-2.md +961 -961
- package/lib/assets/docs/article/grokkingfp/fsharp/part-3.md +972 -972
- package/lib/assets/docs/article/grokkingfp/fsharp/part-4.md +832 -832
- package/lib/assets/docs/article/grokkingfp/fsharp/part-5.md +911 -911
- package/lib/assets/docs/article/grokkingfp/fsharp/part-6.md +922 -922
- package/lib/assets/docs/article/grokkingfp/haskell/index.md +234 -234
- package/lib/assets/docs/article/grokkingfp/haskell/part-1.md +591 -591
- package/lib/assets/docs/article/grokkingfp/haskell/part-2.md +866 -866
- package/lib/assets/docs/article/grokkingfp/haskell/part-3.md +915 -915
- package/lib/assets/docs/article/grokkingfp/haskell/part-4.md +878 -878
- package/lib/assets/docs/article/grokkingfp/haskell/part-5.md +845 -845
- package/lib/assets/docs/article/grokkingfp/haskell/part-6.md +844 -844
- package/lib/assets/docs/article/grokkingfp/index.md +143 -143
- package/lib/assets/docs/article/grokkingfp/java/index.md +211 -211
- package/lib/assets/docs/article/grokkingfp/java/part-1.md +648 -648
- package/lib/assets/docs/article/grokkingfp/java/part-2.md +675 -675
- package/lib/assets/docs/article/grokkingfp/java/part-3.md +672 -672
- package/lib/assets/docs/article/grokkingfp/java/part-4.md +771 -771
- package/lib/assets/docs/article/grokkingfp/java/part-5.md +959 -959
- package/lib/assets/docs/article/grokkingfp/java/part-6.md +1328 -1328
- package/lib/assets/docs/article/grokkingfp/python/index.md +258 -258
- package/lib/assets/docs/article/grokkingfp/python/part-1.md +443 -443
- package/lib/assets/docs/article/grokkingfp/python/part-2.md +958 -958
- package/lib/assets/docs/article/grokkingfp/python/part-3.md +1004 -1004
- package/lib/assets/docs/article/grokkingfp/python/part-4.md +765 -765
- package/lib/assets/docs/article/grokkingfp/python/part-5.md +747 -747
- package/lib/assets/docs/article/grokkingfp/python/part-6.md +861 -861
- package/lib/assets/docs/article/grokkingfp/ruby/index.md +330 -330
- package/lib/assets/docs/article/grokkingfp/ruby/part-1.md +755 -755
- package/lib/assets/docs/article/grokkingfp/ruby/part-2.md +938 -938
- package/lib/assets/docs/article/grokkingfp/ruby/part-3.md +946 -946
- package/lib/assets/docs/article/grokkingfp/ruby/part-4.md +921 -921
- package/lib/assets/docs/article/grokkingfp/ruby/part-5.md +908 -908
- package/lib/assets/docs/article/grokkingfp/ruby/part-6.md +1412 -1412
- package/lib/assets/docs/article/grokkingfp/rust/index.md +242 -242
- package/lib/assets/docs/article/grokkingfp/rust/part-1.md +634 -634
- package/lib/assets/docs/article/grokkingfp/rust/part-2.md +1060 -1060
- package/lib/assets/docs/article/grokkingfp/rust/part-3.md +994 -994
- package/lib/assets/docs/article/grokkingfp/rust/part-4.md +573 -573
- package/lib/assets/docs/article/grokkingfp/rust/part-5.md +705 -705
- package/lib/assets/docs/article/grokkingfp/rust/part-6.md +508 -508
- package/lib/assets/docs/article/grokkingfp/scala/index.md +171 -171
- package/lib/assets/docs/article/grokkingfp/scala/part-1.md +543 -543
- package/lib/assets/docs/article/grokkingfp/scala/part-2.md +946 -946
- package/lib/assets/docs/article/grokkingfp/scala/part-3.md +919 -919
- package/lib/assets/docs/article/grokkingfp/scala/part-4.md +742 -742
- package/lib/assets/docs/article/grokkingfp/scala/part-5.md +722 -722
- package/lib/assets/docs/article/grokkingfp/scala/part-6.md +867 -867
- package/lib/assets/docs/article/grokkingfp/typescript/index.md +273 -273
- package/lib/assets/docs/article/grokkingfp/typescript/part-1.md +561 -561
- package/lib/assets/docs/article/grokkingfp/typescript/part-2.md +1129 -1129
- package/lib/assets/docs/article/grokkingfp/typescript/part-3.md +842 -842
- package/lib/assets/docs/article/grokkingfp/typescript/part-4.md +1087 -1087
- package/lib/assets/docs/article/grokkingfp/typescript/part-5.md +717 -717
- package/lib/assets/docs/article/grokkingfp/typescript/part-6.md +982 -982
- package/lib/assets/docs/article/practical-database-design/index.md +121 -121
- package/lib/assets/docs/article/practical-database-design/part1/chapter01.md +288 -288
- package/lib/assets/docs/article/practical-database-design/part1/chapter02.md +518 -518
- package/lib/assets/docs/article/practical-database-design/part1/chapter03.md +557 -557
- package/lib/assets/docs/article/practical-database-design/part2/chapter04.md +924 -924
- package/lib/assets/docs/article/practical-database-design/part2/chapter05.md +1627 -1627
- package/lib/assets/docs/article/practical-database-design/part2/chapter06.md +2716 -2716
- package/lib/assets/docs/article/practical-database-design/part2/chapter07.md +2082 -2082
- package/lib/assets/docs/article/practical-database-design/part2/chapter08.md +2105 -2105
- package/lib/assets/docs/article/practical-database-design/part2/chapter09.md +2031 -2031
- package/lib/assets/docs/article/practical-database-design/part2/chapter10.md +1387 -1387
- package/lib/assets/docs/article/practical-database-design/part2/chapter11.md +1677 -1677
- package/lib/assets/docs/article/practical-database-design/part2/chapter12.md +1417 -1417
- package/lib/assets/docs/article/practical-database-design/part2/chapter13.md +1434 -1434
- package/lib/assets/docs/article/practical-database-design/part3/chapter14.md +667 -667
- package/lib/assets/docs/article/practical-database-design/part3/chapter15.md +1625 -1625
- package/lib/assets/docs/article/practical-database-design/part3/chapter16.md +1915 -1915
- package/lib/assets/docs/article/practical-database-design/part3/chapter17.md +1708 -1708
- package/lib/assets/docs/article/practical-database-design/part3/chapter18.md +2095 -2095
- package/lib/assets/docs/article/practical-database-design/part3/chapter19.md +1123 -1123
- package/lib/assets/docs/article/practical-database-design/part3/chapter20.md +1031 -1031
- package/lib/assets/docs/article/practical-database-design/part3/chapter21.md +1382 -1382
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter14-orm.md +991 -991
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter15-orm.md +1300 -1300
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter16-orm.md +1166 -1166
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter17-orm.md +1584 -1584
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter18-orm.md +1183 -1183
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter19-orm.md +1016 -1016
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter20-orm.md +1753 -1753
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter21-orm.md +1447 -1447
- package/lib/assets/docs/article/practical-database-design/part3-orm/chapter22-orm.md +1878 -1878
- package/lib/assets/docs/article/practical-database-design/part4/chapter22.md +965 -965
- package/lib/assets/docs/article/practical-database-design/part4/chapter23.md +2069 -2069
- package/lib/assets/docs/article/practical-database-design/part4/chapter24.md +2439 -2439
- package/lib/assets/docs/article/practical-database-design/part4/chapter25.md +3661 -3661
- package/lib/assets/docs/article/practical-database-design/part4/chapter26.md +2916 -2916
- package/lib/assets/docs/article/practical-database-design/part4/chapter27.md +3105 -3105
- package/lib/assets/docs/article/practical-database-design/part4/chapter28.md +2697 -2697
- package/lib/assets/docs/article/practical-database-design/part4/chapter29.md +2544 -2544
- package/lib/assets/docs/article/practical-database-design/part4/chapter30.md +2180 -2180
- package/lib/assets/docs/article/practical-database-design/part4/chapter31.md +1192 -1192
- package/lib/assets/docs/article/practical-database-design/part4/chapter32.md +2101 -2101
- package/lib/assets/docs/article/practical-database-design/part5/chapter33.md +1032 -1032
- package/lib/assets/docs/article/practical-database-design/part5/chapter34.md +1609 -1609
- package/lib/assets/docs/article/practical-database-design/part5/chapter35.md +1453 -1453
- package/lib/assets/docs/article/practical-database-design/part5/chapter36.md +1292 -1292
- package/lib/assets/docs/article/practical-database-design/part5/chapter37.md +1470 -1470
- package/lib/assets/docs/article/practical-database-design/part5/chapter38.md +1698 -1698
- package/lib/assets/docs/article/practical-database-design/part5/chapter39.md +2334 -2334
- package/lib/assets/docs/article/practical-database-design/study/study2-1.md +1693 -1693
- package/lib/assets/docs/article/practical-database-design/study/study2-2.md +1347 -1347
- package/lib/assets/docs/article/practical-database-design/study/study2-3.md +2044 -2044
- package/lib/assets/docs/article/practical-database-design/study/study2-4.md +2229 -2229
- package/lib/assets/docs/article/practical-database-design/study/study2-5.md +2418 -2418
- package/lib/assets/docs/article/practical-database-design/study/study3-1.md +2205 -2205
- package/lib/assets/docs/article/practical-database-design/study/study3-2.md +2221 -2221
- package/lib/assets/docs/article/practical-database-design/study/study3-3.md +2253 -2253
- package/lib/assets/docs/article/practical-database-design/study/study3-4.md +2106 -2106
- package/lib/assets/docs/article/practical-database-design/study/study3-5.md +2507 -2507
- package/lib/assets/docs/article/practical-database-design/study/study4-1.md +2587 -2587
- package/lib/assets/docs/article/practical-database-design/study/study4-2.md +2075 -2075
- package/lib/assets/docs/article/practical-database-design/study/study4-3.md +1805 -1805
- package/lib/assets/docs/article/practical-database-design/study/study4-4.md +1895 -1895
- package/lib/assets/docs/article/practical-database-design/study/study4-5.md +2878 -2878
- package/lib/assets/docs/assets/css/extra.css +29 -29
- package/lib/assets/docs/assets/js/extra.js +44 -44
- package/lib/assets/docs/development/index.md +39 -39
- package/lib/assets/docs/operation/index.md +11 -11
- package/lib/assets/docs/reference/CodexCLIMCP/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/351/226/213/347/231/272/343/203/225/343/203/255/343/203/274.md +532 -532
- package/lib/assets/docs/reference/CodexCLIMCP/343/202/265/343/203/274/343/203/220/343/203/274/350/250/255/345/256/232/346/211/213/351/240/206.md +341 -341
- package/lib/assets/docs/reference/Java/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/347/222/260/345/242/203/346/247/213/347/257/211/343/202/254/343/202/244/343/203/211.md +581 -580
- package/lib/assets/docs/reference/SonarQube/343/203/255/343/203/274/343/202/253/343/203/253/347/222/260/345/242/203/343/202/273/343/203/203/343/203/210/343/202/242/343/203/203/343/203/227/346/211/213/351/240/206/346/233/270.md +642 -642
- package/lib/assets/docs/reference/TypeScript/343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/347/222/260/345/242/203/346/247/213/347/257/211/343/202/254/343/202/244/343/203/211.md +465 -465
- package/lib/assets/docs/reference/UI/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +450 -450
- package/lib/assets/docs/reference/images/Ansoff.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/BrandBasicStrategy.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/BrandCategorization.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/BrandRecurutementStrategy.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/BrandValue.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/BusinessActivitiy.svg +3 -3
- package/lib/assets/docs/reference/images/HRM.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/MarketingStructure.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/OrganizationElemnts.svg +3 -3
- package/lib/assets/docs/reference/images/PPM.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/PositioningMap.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/ProductLayer.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/ProductMix.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/SWOT.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/TargetMarket.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/ThreeGenericStrategies.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/VRIO.drawio.svg +3 -3
- package/lib/assets/docs/reference/images/ValueChain.drawio.svg +3 -3
- package/lib/assets/docs/reference/index.md +52 -52
- package/lib/assets/docs/reference//343/202/210/343/201/204/343/202/275/343/203/225/343/203/210/343/202/246/343/202/247/343/202/242/343/201/250/343/201/257.md +250 -242
- package/lib/assets/docs/reference//343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +2216 -2216
- package/lib/assets/docs/reference//343/202/244/343/203/263/343/203/225/343/203/251/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +1878 -1878
- package/lib/assets/docs/reference//343/202/250/343/202/257/343/202/271/343/203/210/343/203/252/343/203/274/343/203/240/343/203/227/343/203/255/343/202/260/343/203/251/343/203/237/343/203/263/343/202/260.md +550 -544
- package/lib/assets/docs/reference//343/202/263/343/203/274/343/203/207/343/202/243/343/203/263/343/202/260/343/201/250/343/203/206/343/202/271/343/203/210/343/202/254/343/202/244/343/203/211.md +705 -705
- package/lib/assets/docs/reference//343/203/206/343/202/271/343/203/210/346/210/246/347/225/245/343/202/254/343/202/244/343/203/211.md +1313 -1313
- package/lib/assets/docs/reference//343/203/207/343/203/274/343/202/277/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +311 -311
- package/lib/assets/docs/reference//343/203/211/343/203/241/343/202/244/343/203/263/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +599 -599
- package/lib/assets/docs/reference//343/203/223/343/202/270/343/203/215/343/202/271/343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243/345/210/206/346/236/220/343/202/254/343/202/244/343/203/211.md +528 -528
- package/lib/assets/docs/reference//343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271/344/275/234/346/210/220/343/202/254/343/202/244/343/203/211.md +689 -682
- package/lib/assets/docs/reference//343/203/252/343/203/252/343/203/274/343/202/271/343/202/254/343/202/244/343/203/211.md +461 -461
- package/lib/assets/docs/reference//343/203/252/343/203/252/343/203/274/343/202/271/343/203/273/343/202/244/343/203/206/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263/350/250/210/347/224/273/343/202/254/343/202/244/343/203/211.md +580 -560
- package/lib/assets/docs/reference//343/203/255/343/202/270/343/202/253/343/203/253/343/202/267/343/203/263/343/202/255/343/203/263/343/202/260.md +1367 -1367
- package/lib/assets/docs/reference//344/274/201/346/245/255/347/265/214/345/226/266/350/253/226.md +2637 -2636
- package/lib/assets/docs/reference//347/222/260/345/242/203/345/244/211/346/225/260/347/256/241/347/220/206/343/202/254/343/202/244/343/203/211.md +665 -663
- package/lib/assets/docs/reference//350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +1248 -1248
- package/lib/assets/docs/reference//350/250/200/350/252/236/345/210/245/351/226/213/347/231/272/343/202/254/343/202/244/343/203/211.md +28 -0
- package/lib/assets/docs/reference//351/201/213/345/226/266/347/256/241/347/220/206.md +1482 -1482
- package/lib/assets/docs/reference//351/201/213/347/224/250/343/202/271/343/202/257/343/203/252/343/203/227/343/203/210/344/275/234/346/210/220/343/202/254/343/202/244/343/203/211.md +421 -421
- package/lib/assets/docs/reference//351/201/213/347/224/250/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +392 -392
- package/lib/assets/docs/reference//351/226/213/347/231/272/343/202/254/343/202/244/343/203/211.md +299 -299
- package/lib/assets/docs/reference//351/235/236/346/251/237/350/203/275/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +1236 -1236
- package/lib/assets/docs/review/index.md +5 -5
- package/lib/assets/docs/strategy/index.md +1 -1
- package/lib/assets/docs/template/ADR.md +30 -30
- package/lib/assets/docs/template/AWS/343/202/271/343/203/206/343/203/274/343/202/270/343/203/263/343/202/260/347/222/260/345/242/203/343/202/273/343/203/203/343/203/210/343/202/242/343/203/203/343/203/227/346/211/213/351/240/206/346/233/270.md +1366 -1366
- package/lib/assets/docs/template/AWS/343/203/227/343/203/255/343/203/200/343/202/257/343/202/267/343/203/247/343/203/263/347/222/260/345/242/203/343/202/273/343/203/203/343/203/210/343/202/242/343/203/203/343/203/227/346/211/213/351/240/206/346/233/270.md +634 -634
- package/lib/assets/docs/template/README.md +50 -50
- package/lib/assets/docs/template/index.md +23 -23
- package/lib/assets/docs/template//343/201/276/343/201/232/343/201/223/343/202/214/343/202/222/350/252/255/343/202/202/343/201/206/343/203/252/343/202/271/343/203/210.md +12 -12
- package/lib/assets/docs/template//343/202/242/343/203/227/343/203/252/343/202/261/343/203/274/343/202/267/343/203/247/343/203/263/351/226/213/347/231/272/347/222/260/345/242/203/343/202/273/343/203/203/343/203/210/343/202/242/343/203/203/343/203/227/346/211/213/351/240/206/346/233/270.md +547 -547
- package/lib/assets/docs/template//343/202/244/343/203/206/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263/345/256/214/344/272/206/345/240/261/345/221/212/346/233/270.md +58 -58
- package/lib/assets/docs/template//343/202/244/343/203/263/343/202/273/343/203/227/343/202/267/343/203/247/343/203/263/343/203/207/343/203/203/343/202/255.md +13 -13
- package/lib/assets/docs/template//343/203/223/343/202/270/343/203/215/343/202/271/343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243.md +379 -379
- package/lib/assets/docs/template//344/274/201/346/245/255/345/210/206/346/236/220.md +573 -573
- package/lib/assets/docs/template//345/256/214/345/205/250/345/275/242/345/274/217/343/201/256/343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271.md +69 -68
- package/lib/assets/docs/template//350/246/201/344/273/266/345/256/232/347/276/251.md +669 -669
- package/lib/assets/docs/template//350/250/255/350/250/210.md +173 -173
- package/lib/assets/docs/template//351/226/213/347/231/272/347/222/260/345/242/203/343/202/273/343/203/203/343/203/210/343/202/242/343/203/203/343/203/227/346/211/213/351/240/206/346/233/270.md +688 -688
- package/lib/assets/gulpfile.js +25 -25
- package/lib/assets/mkdocs.yml +136 -135
- package/lib/assets/ops/docker/mkdoc/Dockerfile +19 -19
- package/lib/assets/ops/scripts/journal.js +180 -180
- package/lib/assets/ops/scripts/mkdocs.js +82 -82
- package/lib/assets/ops/scripts/release.js +431 -431
- package/lib/assets/ops/scripts/sonar_local.js +726 -726
- package/lib/assets/ops/scripts/ssh.js +190 -190
- package/lib/assets/ops/scripts/vault.js +299 -299
- package/lib/assets/package-lock.json +1653 -1653
- package/lib/assets/package.json +40 -40
- package/lib/gulpfile.js +37 -37
- package/package.json +41 -41
- package/lib/assets/.claude/agent-memory/xp-programmer/MEMORY.md +0 -6
- package/lib/assets/.claude/agent-memory/xp-programmer/project_cargo_tracker.md +0 -11
- package/lib/assets/.claude/agent-memory/xp-programmer/project_ddd_patterns.md +0 -27
- package/lib/assets/.claude/agent-memory/xp-programmer/project_us07_route_assignment.md +0 -19
|
@@ -1,2253 +1,2253 @@
|
|
|
1
|
-
# 研究 3:gRPC サービスの実装
|
|
2
|
-
|
|
3
|
-
## はじめに
|
|
4
|
-
|
|
5
|
-
本パートでは、API サーバー構成とは異なるアプローチとして、**gRPC** による財務会計システムを実装します。Protocol Buffers による高効率なバイナリシリアライゼーションと、HTTP/2 によるストリーミング通信を活用し、高性能なマイクロサービス間通信を実現します。
|
|
6
|
-
|
|
7
|
-
ヘキサゴナルアーキテクチャ(ドメイン層・アプリケーション層)はそのまま共有し、**Input Adapter として gRPC サービス層のみを追加**します。
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## 第 22 章:gRPC サーバーの基礎
|
|
12
|
-
|
|
13
|
-
### 22.1 gRPC とは
|
|
14
|
-
|
|
15
|
-
gRPC は Google が開発したオープンソースの高性能 RPC(Remote Procedure Call)フレームワークです。HTTP/2 プロトコルと Protocol Buffers を基盤とし、マイクロサービス間通信に最適化されています。
|
|
16
|
-
|
|
17
|
-
```plantuml
|
|
18
|
-
@startuml grpc_architecture
|
|
19
|
-
!define RECTANGLE class
|
|
20
|
-
|
|
21
|
-
skinparam backgroundColor #FEFEFE
|
|
22
|
-
|
|
23
|
-
package "gRPC Architecture (財務会計システム)" {
|
|
24
|
-
|
|
25
|
-
package "Client Side" {
|
|
26
|
-
RECTANGLE "gRPC Client\n(Generated Stub)" as client {
|
|
27
|
-
- 単項 RPC
|
|
28
|
-
- サーバーストリーミング
|
|
29
|
-
- クライアントストリーミング
|
|
30
|
-
- 双方向ストリーミング
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
package "Server Side" {
|
|
35
|
-
RECTANGLE "gRPC Server\n(grpc-spring-boot-starter)" as server {
|
|
36
|
-
- AccountService
|
|
37
|
-
- JournalService
|
|
38
|
-
- BalanceService
|
|
39
|
-
- ReportService
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
package "Shared" {
|
|
44
|
-
RECTANGLE "Protocol Buffers\n(.proto files)" as proto {
|
|
45
|
-
- account.proto
|
|
46
|
-
- journal.proto
|
|
47
|
-
- balance.proto
|
|
48
|
-
- common.proto
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
client --> proto : ".proto からスタブ生成"
|
|
54
|
-
server --> proto : ".proto からスケルトン生成"
|
|
55
|
-
client <--> server : "HTTP/2\n(Binary Protocol)"
|
|
56
|
-
|
|
57
|
-
note bottom of proto
|
|
58
|
-
スキーマ駆動開発
|
|
59
|
-
言語中立なインターフェース定義
|
|
60
|
-
高効率なバイナリシリアライゼーション
|
|
61
|
-
end note
|
|
62
|
-
|
|
63
|
-
@enduml
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
**gRPC の主な特徴:**
|
|
67
|
-
|
|
68
|
-
| 特徴 | 説明 |
|
|
69
|
-
|------|------|
|
|
70
|
-
| HTTP/2 | 多重化、ヘッダー圧縮、バイナリフレーミング |
|
|
71
|
-
| Protocol Buffers | 高速なバイナリシリアライゼーション |
|
|
72
|
-
| 多言語サポート | Java, Go, Python, C#, Node.js 等 |
|
|
73
|
-
| ストリーミング | 4 つの RPC パターンをサポート |
|
|
74
|
-
| デッドライン | タイムアウト管理の組み込みサポート |
|
|
75
|
-
| 認証 | TLS/SSL、トークンベース認証のサポート |
|
|
76
|
-
|
|
77
|
-
### 22.2 REST API / GraphQL との比較
|
|
78
|
-
|
|
79
|
-
```plantuml
|
|
80
|
-
@startuml api_comparison
|
|
81
|
-
skinparam backgroundColor #FEFEFE
|
|
82
|
-
|
|
83
|
-
rectangle "REST API" as rest {
|
|
84
|
-
(HTTP/1.1 or 2)
|
|
85
|
-
(JSON/XML)
|
|
86
|
-
(OpenAPI)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
rectangle "gRPC" as grpc {
|
|
90
|
-
(HTTP/2)
|
|
91
|
-
(Protocol Buffers)
|
|
92
|
-
(.proto)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
rectangle "GraphQL" as graphql {
|
|
96
|
-
(HTTP/1.1 or 2)
|
|
97
|
-
(JSON)
|
|
98
|
-
(.graphqls)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
note bottom of rest
|
|
102
|
-
汎用性が高い
|
|
103
|
-
ブラウザ直接アクセス可能
|
|
104
|
-
人間が読みやすい
|
|
105
|
-
end note
|
|
106
|
-
|
|
107
|
-
note bottom of grpc
|
|
108
|
-
高性能
|
|
109
|
-
マイクロサービス向け
|
|
110
|
-
型安全
|
|
111
|
-
end note
|
|
112
|
-
|
|
113
|
-
note bottom of graphql
|
|
114
|
-
柔軟なクエリ
|
|
115
|
-
フロントエンド向け
|
|
116
|
-
単一エンドポイント
|
|
117
|
-
end note
|
|
118
|
-
|
|
119
|
-
@enduml
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
**詳細比較表:**
|
|
123
|
-
|
|
124
|
-
| 特徴 | REST API | gRPC | GraphQL |
|
|
125
|
-
|------|----------|------|---------|
|
|
126
|
-
| プロトコル | HTTP/1.1 | HTTP/2 | HTTP/1.1 or HTTP/2 |
|
|
127
|
-
| データ形式 | JSON | Protocol Buffers | JSON |
|
|
128
|
-
| スキーマ | OpenAPI (任意) | .proto (必須) | .graphqls (必須) |
|
|
129
|
-
| シリアライゼーション | テキスト | バイナリ | テキスト |
|
|
130
|
-
| パフォーマンス | 中 | 高 | 中 |
|
|
131
|
-
| ストリーミング | WebSocket 別実装 | ネイティブサポート | Subscription |
|
|
132
|
-
| ブラウザ対応 | ◎ | △ (gRPC-Web) | ◎ |
|
|
133
|
-
| 学習コスト | 低 | 中 | 中 |
|
|
134
|
-
| 主な用途 | 汎用 API | マイクロサービス | フロントエンド向け |
|
|
135
|
-
|
|
136
|
-
**財務会計システムで gRPC を選択する場面:**
|
|
137
|
-
|
|
138
|
-
1. **基幹システム間連携**: 販売管理・購買管理との高性能な内部通信
|
|
139
|
-
2. **リアルタイム残高更新**: ストリーミングによる即時反映通知
|
|
140
|
-
3. **一括仕訳処理**: クライアントストリーミングによる大量データ転送
|
|
141
|
-
4. **月次締め処理**: 長時間処理の進捗通知
|
|
142
|
-
|
|
143
|
-
### 22.3 4 つの RPC パターン
|
|
144
|
-
|
|
145
|
-
gRPC は 4 つの RPC パターンをサポートします。
|
|
146
|
-
|
|
147
|
-
```plantuml
|
|
148
|
-
@startuml grpc_patterns
|
|
149
|
-
skinparam backgroundColor #FEFEFE
|
|
150
|
-
|
|
151
|
-
rectangle "1. 単項 RPC (Unary)" as unary {
|
|
152
|
-
(Client) -right-> (Server) : "Request"
|
|
153
|
-
(Server) -left-> (Client) : "Response"
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
rectangle "2. サーバーストリーミング RPC" as server_stream {
|
|
157
|
-
(Client2) -right-> (Server2) : "Request"
|
|
158
|
-
(Server2) -left-> (Client2) : "Response 1"
|
|
159
|
-
(Server2) -left-> (Client2) : "Response 2"
|
|
160
|
-
(Server2) -left-> (Client2) : "Response N"
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
rectangle "3. クライアントストリーミング RPC" as client_stream {
|
|
164
|
-
(Client3) -right-> (Server3) : "Request 1"
|
|
165
|
-
(Client3) -right-> (Server3) : "Request 2"
|
|
166
|
-
(Client3) -right-> (Server3) : "Request N"
|
|
167
|
-
(Server3) -left-> (Client3) : "Response"
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
rectangle "4. 双方向ストリーミング RPC" as bidirectional {
|
|
171
|
-
(Client4) <-right-> (Server4) : "Request/Response Stream"
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@enduml
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
**各パターンの用途(財務会計システム):**
|
|
178
|
-
|
|
179
|
-
| パターン | 用途例 |
|
|
180
|
-
|----------|---------------------------|
|
|
181
|
-
| 単項 RPC | 勘定科目取得、仕訳登録 |
|
|
182
|
-
| サーバーストリーミング | 仕訳一覧取得、残高照会 |
|
|
183
|
-
| クライアントストリーミング | 仕訳明細の一括登録 |
|
|
184
|
-
| 双方向ストリーミング | リアルタイム残高同期 |
|
|
185
|
-
|
|
186
|
-
### 22.4 gRPC におけるヘキサゴナルアーキテクチャ
|
|
187
|
-
|
|
188
|
-
gRPC を導入しても、ヘキサゴナルアーキテクチャ(ドメイン層・アプリケーション層)はそのまま共有し、**Input Adapter として gRPC サービス層のみを追加**します。
|
|
189
|
-
|
|
190
|
-
```plantuml
|
|
191
|
-
@startuml hexagonal_grpc
|
|
192
|
-
!define RECTANGLE class
|
|
193
|
-
|
|
194
|
-
package "Hexagonal Architecture (gRPC版)" {
|
|
195
|
-
|
|
196
|
-
RECTANGLE "Application Core\n(Domain + Use Cases)" as core {
|
|
197
|
-
- Account (勘定科目)
|
|
198
|
-
- Journal (仕訳)
|
|
199
|
-
- DailyBalance (日次残高)
|
|
200
|
-
- MonthlyBalance (月次残高)
|
|
201
|
-
- AccountUseCase
|
|
202
|
-
- JournalUseCase
|
|
203
|
-
- BalanceUseCase
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
RECTANGLE "Input Adapters\n(Driving Side)" as input {
|
|
207
|
-
- REST Controller(既存)
|
|
208
|
-
- gRPC Service(新規追加)
|
|
209
|
-
- StreamObserver
|
|
210
|
-
- ServerInterceptor
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
RECTANGLE "Output Adapters\n(Driven Side)" as output {
|
|
214
|
-
- MyBatis Repository
|
|
215
|
-
- Database Access
|
|
216
|
-
- Entity Mapping
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
input --> core : "Input Ports\n(Use Cases)"
|
|
221
|
-
core --> output : "Output Ports\n(Repository Interfaces)"
|
|
222
|
-
|
|
223
|
-
note top of core
|
|
224
|
-
既存のビジネスロジック
|
|
225
|
-
REST API 版と完全に共有
|
|
226
|
-
gRPC 固有のコードは含まない
|
|
227
|
-
end note
|
|
228
|
-
|
|
229
|
-
note left of input
|
|
230
|
-
gRPC サービスを
|
|
231
|
-
Input Adapter として追加
|
|
232
|
-
既存の REST と共存可能
|
|
233
|
-
end note
|
|
234
|
-
|
|
235
|
-
note right of output
|
|
236
|
-
既存の Repository を
|
|
237
|
-
そのまま使用
|
|
238
|
-
変更不要
|
|
239
|
-
end note
|
|
240
|
-
|
|
241
|
-
@enduml
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
### 22.5 ディレクトリ構成
|
|
245
|
-
|
|
246
|
-
既存の構成に `infrastructure/in/grpc/` を追加するだけです。
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
src/main/java/com/example/accounting/
|
|
250
|
-
├── domain/ # ドメイン層(API版と共通)
|
|
251
|
-
│ ├── model/
|
|
252
|
-
│ │ ├── account/ # 勘定科目ドメイン
|
|
253
|
-
│ │ ├── journal/ # 仕訳ドメイン
|
|
254
|
-
│ │ ├── balance/ # 残高ドメイン
|
|
255
|
-
│ │ └── tax/ # 課税取引ドメイン
|
|
256
|
-
│ └── exception/
|
|
257
|
-
│
|
|
258
|
-
├── application/ # アプリケーション層(API版と共通)
|
|
259
|
-
│ ├── port/
|
|
260
|
-
│ │ ├── in/ # Input Port(ユースケース)
|
|
261
|
-
│ │ └── out/ # Output Port(リポジトリ)
|
|
262
|
-
│ └── service/
|
|
263
|
-
│
|
|
264
|
-
├── infrastructure/
|
|
265
|
-
│ ├── in/
|
|
266
|
-
│ │ ├── api/ # Input Adapter(REST実装)- 既存
|
|
267
|
-
│ │ └── grpc/ # Input Adapter(gRPC実装)- 新規追加
|
|
268
|
-
│ │ ├── service/ # gRPC サービス実装
|
|
269
|
-
│ │ ├── interceptor/ # インターセプター
|
|
270
|
-
│ │ └── converter/ # ドメイン ↔ Proto 変換
|
|
271
|
-
│ └── out/
|
|
272
|
-
│ └── persistence/ # Output Adapter(DB実装)- 既存
|
|
273
|
-
│ ├── mapper/
|
|
274
|
-
│ └── repository/
|
|
275
|
-
│
|
|
276
|
-
├── config/
|
|
277
|
-
│
|
|
278
|
-
└── src/main/proto/ # Protocol Buffers 定義
|
|
279
|
-
├── common.proto
|
|
280
|
-
├── account.proto
|
|
281
|
-
├── journal.proto
|
|
282
|
-
├── balance.proto
|
|
283
|
-
└── report.proto
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### 22.6 技術スタックの追加
|
|
287
|
-
|
|
288
|
-
既存の `build.gradle.kts` に gRPC 関連の依存関係を追加します。
|
|
289
|
-
|
|
290
|
-
<details>
|
|
291
|
-
<summary>build.gradle.kts(差分)</summary>
|
|
292
|
-
|
|
293
|
-
```kotlin
|
|
294
|
-
import com.google.protobuf.gradle.*
|
|
295
|
-
|
|
296
|
-
plugins {
|
|
297
|
-
// 既存のプラグイン
|
|
298
|
-
id("java")
|
|
299
|
-
id("org.springframework.boot") version "3.2.0"
|
|
300
|
-
id("io.spring.dependency-management") version "1.1.4"
|
|
301
|
-
|
|
302
|
-
// gRPC 関連を追加
|
|
303
|
-
id("com.google.protobuf") version "0.9.4"
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
dependencies {
|
|
307
|
-
// 既存の依存関係(Spring Boot, MyBatis, PostgreSQL等)はそのまま
|
|
308
|
-
|
|
309
|
-
// gRPC 関連を追加
|
|
310
|
-
implementation("net.devh:grpc-spring-boot-starter:3.1.0.RELEASE")
|
|
311
|
-
implementation("io.grpc:grpc-protobuf:1.62.2")
|
|
312
|
-
implementation("io.grpc:grpc-stub:1.62.2")
|
|
313
|
-
implementation("io.grpc:grpc-services:1.62.2") // ヘルスチェック、リフレクション
|
|
314
|
-
|
|
315
|
-
// Protocol Buffers
|
|
316
|
-
implementation("com.google.protobuf:protobuf-java:3.25.3")
|
|
317
|
-
implementation("com.google.protobuf:protobuf-java-util:3.25.3") // JSON 変換
|
|
318
|
-
|
|
319
|
-
// Jakarta Annotation (gRPC generated code で必要)
|
|
320
|
-
compileOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
|
|
321
|
-
|
|
322
|
-
// Test
|
|
323
|
-
testImplementation("io.grpc:grpc-testing:1.62.2")
|
|
324
|
-
testImplementation("net.devh:grpc-client-spring-boot-starter:3.1.0.RELEASE")
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
protobuf {
|
|
328
|
-
protoc {
|
|
329
|
-
artifact = "com.google.protobuf:protoc:3.25.3"
|
|
330
|
-
}
|
|
331
|
-
plugins {
|
|
332
|
-
create("grpc") {
|
|
333
|
-
artifact = "io.grpc:protoc-gen-grpc-java:1.62.2"
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
generateProtoTasks {
|
|
337
|
-
all().forEach { task ->
|
|
338
|
-
task.plugins {
|
|
339
|
-
create("grpc")
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// 生成コードのソースパス追加
|
|
346
|
-
sourceSets {
|
|
347
|
-
main {
|
|
348
|
-
java {
|
|
349
|
-
srcDirs(
|
|
350
|
-
"build/generated/source/proto/main/java",
|
|
351
|
-
"build/generated/source/proto/main/grpc"
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
</details>
|
|
359
|
-
|
|
360
|
-
<details>
|
|
361
|
-
<summary>application.yml(差分)</summary>
|
|
362
|
-
|
|
363
|
-
```yaml
|
|
364
|
-
# 既存の設定はそのまま
|
|
365
|
-
|
|
366
|
-
# gRPC サーバー設定
|
|
367
|
-
grpc:
|
|
368
|
-
server:
|
|
369
|
-
port: 9090
|
|
370
|
-
reflection-service-enabled: true # gRPC リフレクション有効化
|
|
371
|
-
health-service-enabled: true # ヘルスチェック有効化
|
|
372
|
-
max-inbound-message-size: 4194304 # 4MB
|
|
373
|
-
max-inbound-metadata-size: 8192 # 8KB
|
|
374
|
-
|
|
375
|
-
# ログ設定
|
|
376
|
-
logging:
|
|
377
|
-
level:
|
|
378
|
-
net.devh.boot.grpc: DEBUG
|
|
379
|
-
io.grpc: INFO
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
</details>
|
|
383
|
-
|
|
384
|
-
---
|
|
385
|
-
|
|
386
|
-
## 第 23 章:Protocol Buffers 定義
|
|
387
|
-
|
|
388
|
-
### 23.1 共通メッセージ定義
|
|
389
|
-
|
|
390
|
-
<details>
|
|
391
|
-
<summary>src/main/proto/common.proto</summary>
|
|
392
|
-
|
|
393
|
-
```protobuf
|
|
394
|
-
syntax = "proto3";
|
|
395
|
-
|
|
396
|
-
package com.example.accounting;
|
|
397
|
-
|
|
398
|
-
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
399
|
-
option java_outer_classname = "CommonProto";
|
|
400
|
-
option java_multiple_files = true;
|
|
401
|
-
|
|
402
|
-
import "google/protobuf/timestamp.proto";
|
|
403
|
-
import "google/protobuf/wrappers.proto";
|
|
404
|
-
|
|
405
|
-
// 共通のページネーション
|
|
406
|
-
message PageRequest {
|
|
407
|
-
int32 page = 1;
|
|
408
|
-
int32 size = 2;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
message PageInfo {
|
|
412
|
-
int32 page = 1;
|
|
413
|
-
int32 size = 2;
|
|
414
|
-
int32 total_elements = 3;
|
|
415
|
-
int32 total_pages = 4;
|
|
416
|
-
bool has_next = 5;
|
|
417
|
-
bool has_previous = 6;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// 共通のエラー応答
|
|
421
|
-
message ErrorDetail {
|
|
422
|
-
string field = 1;
|
|
423
|
-
string message = 2;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
message ErrorResponse {
|
|
427
|
-
string code = 1;
|
|
428
|
-
string message = 2;
|
|
429
|
-
repeated ErrorDetail details = 3;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// 金額型(Decimal 相当)
|
|
433
|
-
message Money {
|
|
434
|
-
int64 units = 1; // 整数部
|
|
435
|
-
int32 nanos = 2; // 小数部(10億分の1単位)
|
|
436
|
-
string currency = 3; // 通貨コード(JPY等)
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// 日付型(Date 相当)
|
|
440
|
-
message Date {
|
|
441
|
-
int32 year = 1;
|
|
442
|
-
int32 month = 2;
|
|
443
|
-
int32 day = 3;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// 年月型
|
|
447
|
-
message YearMonth {
|
|
448
|
-
int32 year = 1;
|
|
449
|
-
int32 month = 2;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// 決算期
|
|
453
|
-
message FiscalPeriod {
|
|
454
|
-
int32 fiscal_year = 1; // 決算年度
|
|
455
|
-
int32 fiscal_month = 2; // 決算月度(1-12)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// 監査情報
|
|
459
|
-
message AuditInfo {
|
|
460
|
-
google.protobuf.Timestamp created_at = 1;
|
|
461
|
-
string created_by = 2;
|
|
462
|
-
google.protobuf.Timestamp updated_at = 3;
|
|
463
|
-
string updated_by = 4;
|
|
464
|
-
}
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
</details>
|
|
468
|
-
|
|
469
|
-
### 23.2 勘定科目 Protocol Buffers
|
|
470
|
-
|
|
471
|
-
<details>
|
|
472
|
-
<summary>src/main/proto/account.proto</summary>
|
|
473
|
-
|
|
474
|
-
```protobuf
|
|
475
|
-
syntax = "proto3";
|
|
476
|
-
|
|
477
|
-
package com.example.accounting;
|
|
478
|
-
|
|
479
|
-
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
480
|
-
option java_outer_classname = "AccountProto";
|
|
481
|
-
option java_multiple_files = true;
|
|
482
|
-
|
|
483
|
-
import "common.proto";
|
|
484
|
-
import "google/protobuf/empty.proto";
|
|
485
|
-
|
|
486
|
-
// BSPL区分
|
|
487
|
-
enum BsplType {
|
|
488
|
-
BSPL_TYPE_UNSPECIFIED = 0;
|
|
489
|
-
BSPL_TYPE_BS = 1; // 貸借対照表
|
|
490
|
-
BSPL_TYPE_PL = 2; // 損益計算書
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// 貸借区分
|
|
494
|
-
enum DebitCreditType {
|
|
495
|
-
DEBIT_CREDIT_TYPE_UNSPECIFIED = 0;
|
|
496
|
-
DEBIT_CREDIT_TYPE_DEBIT = 1; // 借方
|
|
497
|
-
DEBIT_CREDIT_TYPE_CREDIT = 2; // 貸方
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// 取引要素区分
|
|
501
|
-
enum ElementType {
|
|
502
|
-
ELEMENT_TYPE_UNSPECIFIED = 0;
|
|
503
|
-
ELEMENT_TYPE_ASSET = 1; // 資産
|
|
504
|
-
ELEMENT_TYPE_LIABILITY = 2; // 負債
|
|
505
|
-
ELEMENT_TYPE_EQUITY = 3; // 資本
|
|
506
|
-
ELEMENT_TYPE_REVENUE = 4; // 収益
|
|
507
|
-
ELEMENT_TYPE_EXPENSE = 5; // 費用
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// 集計区分
|
|
511
|
-
enum AggregationType {
|
|
512
|
-
AGGREGATION_TYPE_UNSPECIFIED = 0;
|
|
513
|
-
AGGREGATION_TYPE_HEADING = 1; // 見出科目
|
|
514
|
-
AGGREGATION_TYPE_SUMMARY = 2; // 集計科目
|
|
515
|
-
AGGREGATION_TYPE_POSTING = 3; // 計上科目
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// 勘定科目メッセージ
|
|
519
|
-
message Account {
|
|
520
|
-
string account_code = 1; // 勘定科目コード
|
|
521
|
-
string account_name = 2; // 勘定科目名
|
|
522
|
-
BsplType bspl_type = 3; // BSPL区分
|
|
523
|
-
DebitCreditType debit_credit_type = 4; // 貸借区分
|
|
524
|
-
ElementType element_type = 5; // 取引要素区分
|
|
525
|
-
AggregationType aggregation_type = 6; // 集計区分
|
|
526
|
-
string parent_account_code = 7; // 親勘定科目コード
|
|
527
|
-
string account_path = 8; // 勘定科目パス
|
|
528
|
-
int32 display_order = 9; // 表示順
|
|
529
|
-
bool is_active = 10; // 有効フラグ
|
|
530
|
-
AuditInfo audit = 11; // 監査情報
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// 勘定科目構成メッセージ
|
|
534
|
-
message AccountStructure {
|
|
535
|
-
string account_code = 1; // 勘定科目コード
|
|
536
|
-
string account_path = 2; // 勘定科目パス(~区切り)
|
|
537
|
-
int32 level = 3; // 階層レベル
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// 課税取引マスタ
|
|
541
|
-
message TaxTransaction {
|
|
542
|
-
string tax_code = 1; // 課税取引コード
|
|
543
|
-
string tax_name = 2; // 課税取引名
|
|
544
|
-
int32 tax_rate = 3; // 税率(パーセント * 100)
|
|
545
|
-
Date effective_from = 4; // 適用開始日
|
|
546
|
-
Date effective_to = 5; // 適用終了日
|
|
547
|
-
bool is_active = 6; // 有効フラグ
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// === リクエスト/レスポンス ===
|
|
551
|
-
|
|
552
|
-
// 勘定科目取得
|
|
553
|
-
message GetAccountRequest {
|
|
554
|
-
string account_code = 1;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
message GetAccountResponse {
|
|
558
|
-
Account account = 1;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// 勘定科目一覧取得
|
|
562
|
-
message ListAccountsRequest {
|
|
563
|
-
PageRequest page = 1;
|
|
564
|
-
BsplType bspl_type = 2; // フィルタ(オプション)
|
|
565
|
-
ElementType element_type = 3; // フィルタ(オプション)
|
|
566
|
-
AggregationType aggregation_type = 4; // フィルタ(オプション)
|
|
567
|
-
string keyword = 5; // 検索キーワード
|
|
568
|
-
bool active_only = 6; // 有効のみ
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
message ListAccountsResponse {
|
|
572
|
-
repeated Account accounts = 1;
|
|
573
|
-
PageInfo page_info = 2;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// 勘定科目登録
|
|
577
|
-
message CreateAccountRequest {
|
|
578
|
-
string account_code = 1;
|
|
579
|
-
string account_name = 2;
|
|
580
|
-
BsplType bspl_type = 3;
|
|
581
|
-
DebitCreditType debit_credit_type = 4;
|
|
582
|
-
ElementType element_type = 5;
|
|
583
|
-
AggregationType aggregation_type = 6;
|
|
584
|
-
string parent_account_code = 7;
|
|
585
|
-
int32 display_order = 8;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
message CreateAccountResponse {
|
|
589
|
-
Account account = 1;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// 勘定科目更新
|
|
593
|
-
message UpdateAccountRequest {
|
|
594
|
-
string account_code = 1;
|
|
595
|
-
string account_name = 2;
|
|
596
|
-
BsplType bspl_type = 3;
|
|
597
|
-
DebitCreditType debit_credit_type = 4;
|
|
598
|
-
ElementType element_type = 5;
|
|
599
|
-
AggregationType aggregation_type = 6;
|
|
600
|
-
string parent_account_code = 7;
|
|
601
|
-
int32 display_order = 8;
|
|
602
|
-
bool is_active = 9;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
message UpdateAccountResponse {
|
|
606
|
-
Account account = 1;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// 勘定科目削除
|
|
610
|
-
message DeleteAccountRequest {
|
|
611
|
-
string account_code = 1;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
message DeleteAccountResponse {
|
|
615
|
-
bool success = 1;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// 勘定科目一括登録(クライアントストリーミング)
|
|
619
|
-
message BulkCreateAccountRequest {
|
|
620
|
-
CreateAccountRequest account = 1;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
message BulkCreateAccountResponse {
|
|
624
|
-
int32 success_count = 1;
|
|
625
|
-
int32 failure_count = 2;
|
|
626
|
-
repeated ErrorDetail errors = 3;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// 勘定科目ツリー取得
|
|
630
|
-
message GetAccountTreeRequest {
|
|
631
|
-
BsplType bspl_type = 1; // BS または PL
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
message GetAccountTreeResponse {
|
|
635
|
-
repeated AccountNode nodes = 1;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
message AccountNode {
|
|
639
|
-
Account account = 1;
|
|
640
|
-
repeated AccountNode children = 2;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// 課税取引マスタ取得
|
|
644
|
-
message GetTaxTransactionRequest {
|
|
645
|
-
string tax_code = 1;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
message GetTaxTransactionResponse {
|
|
649
|
-
TaxTransaction tax_transaction = 1;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// 課税取引マスタ一覧
|
|
653
|
-
message ListTaxTransactionsRequest {
|
|
654
|
-
Date as_of_date = 1; // 適用日(オプション)
|
|
655
|
-
bool active_only = 2;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
message ListTaxTransactionsResponse {
|
|
659
|
-
repeated TaxTransaction tax_transactions = 1;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// === サービス定義 ===
|
|
663
|
-
|
|
664
|
-
service AccountService {
|
|
665
|
-
// 単項 RPC
|
|
666
|
-
rpc GetAccount(GetAccountRequest) returns (GetAccountResponse);
|
|
667
|
-
rpc CreateAccount(CreateAccountRequest) returns (CreateAccountResponse);
|
|
668
|
-
rpc UpdateAccount(UpdateAccountRequest) returns (UpdateAccountResponse);
|
|
669
|
-
rpc DeleteAccount(DeleteAccountRequest) returns (DeleteAccountResponse);
|
|
670
|
-
|
|
671
|
-
// サーバーストリーミング RPC(大量データ取得)
|
|
672
|
-
rpc ListAccounts(ListAccountsRequest) returns (stream Account);
|
|
673
|
-
|
|
674
|
-
// クライアントストリーミング RPC(一括登録)
|
|
675
|
-
rpc BulkCreateAccounts(stream BulkCreateAccountRequest) returns (BulkCreateAccountResponse);
|
|
676
|
-
|
|
677
|
-
// 勘定科目構成
|
|
678
|
-
rpc GetAccountTree(GetAccountTreeRequest) returns (GetAccountTreeResponse);
|
|
679
|
-
|
|
680
|
-
// 課税取引マスタ
|
|
681
|
-
rpc GetTaxTransaction(GetTaxTransactionRequest) returns (GetTaxTransactionResponse);
|
|
682
|
-
rpc ListTaxTransactions(ListTaxTransactionsRequest) returns (ListTaxTransactionsResponse);
|
|
683
|
-
}
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
</details>
|
|
687
|
-
|
|
688
|
-
### 23.3 仕訳 Protocol Buffers
|
|
689
|
-
|
|
690
|
-
<details>
|
|
691
|
-
<summary>src/main/proto/journal.proto</summary>
|
|
692
|
-
|
|
693
|
-
```protobuf
|
|
694
|
-
syntax = "proto3";
|
|
695
|
-
|
|
696
|
-
package com.example.accounting;
|
|
697
|
-
|
|
698
|
-
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
699
|
-
option java_outer_classname = "JournalProto";
|
|
700
|
-
option java_multiple_files = true;
|
|
701
|
-
|
|
702
|
-
import "common.proto";
|
|
703
|
-
import "account.proto";
|
|
704
|
-
import "google/protobuf/empty.proto";
|
|
705
|
-
|
|
706
|
-
// 仕訳伝票区分
|
|
707
|
-
enum JournalType {
|
|
708
|
-
JOURNAL_TYPE_UNSPECIFIED = 0;
|
|
709
|
-
JOURNAL_TYPE_NORMAL = 1; // 通常仕訳
|
|
710
|
-
JOURNAL_TYPE_CLOSING = 2; // 決算仕訳
|
|
711
|
-
JOURNAL_TYPE_ADJUSTMENT = 3; // 調整仕訳
|
|
712
|
-
JOURNAL_TYPE_REVERSAL = 4; // 取消仕訳
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// 仕訳ステータス
|
|
716
|
-
enum JournalStatus {
|
|
717
|
-
JOURNAL_STATUS_UNSPECIFIED = 0;
|
|
718
|
-
JOURNAL_STATUS_DRAFT = 1; // 下書き
|
|
719
|
-
JOURNAL_STATUS_PENDING = 2; // 承認待ち
|
|
720
|
-
JOURNAL_STATUS_APPROVED = 3; // 承認済み
|
|
721
|
-
JOURNAL_STATUS_POSTED = 4; // 転記済み
|
|
722
|
-
JOURNAL_STATUS_CANCELED = 5; // 取消済み
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// 仕訳伝票メッセージ
|
|
726
|
-
message Journal {
|
|
727
|
-
string slip_number = 1; // 伝票番号
|
|
728
|
-
Date journal_date = 2; // 起票日
|
|
729
|
-
Date input_date = 3; // 入力日
|
|
730
|
-
string summary = 4; // 伝票摘要
|
|
731
|
-
JournalType journal_type = 5; // 仕訳伝票区分
|
|
732
|
-
JournalStatus status = 6; // ステータス
|
|
733
|
-
bool is_closing_journal = 7; // 決算仕訳フラグ
|
|
734
|
-
FiscalPeriod fiscal_period = 8; // 決算期
|
|
735
|
-
Money total_debit = 9; // 借方合計
|
|
736
|
-
Money total_credit = 10; // 貸方合計
|
|
737
|
-
repeated JournalDetail details = 11; // 仕訳明細
|
|
738
|
-
string reversal_slip_number = 12; // 取消元伝票番号
|
|
739
|
-
AuditInfo audit = 13; // 監査情報
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
// 仕訳明細メッセージ
|
|
743
|
-
message JournalDetail {
|
|
744
|
-
int32 line_number = 1; // 行番号
|
|
745
|
-
string line_summary = 2; // 行摘要
|
|
746
|
-
repeated JournalDebitCreditDetail debit_credit_details = 3; // 貸借明細
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// 仕訳貸借明細メッセージ
|
|
750
|
-
message JournalDebitCreditDetail {
|
|
751
|
-
DebitCreditType debit_credit_type = 1; // 借方/貸方
|
|
752
|
-
string account_code = 2; // 勘定科目コード
|
|
753
|
-
string account_name = 3; // 勘定科目名(参照用)
|
|
754
|
-
string sub_account_code = 4; // 補助科目コード
|
|
755
|
-
string department_code = 5; // 部門コード
|
|
756
|
-
string project_code = 6; // プロジェクトコード
|
|
757
|
-
Money amount = 7; // 金額
|
|
758
|
-
Money base_currency_amount = 8; // 基軸通貨金額
|
|
759
|
-
string tax_code = 9; // 課税取引コード
|
|
760
|
-
int32 tax_rate = 10; // 税率
|
|
761
|
-
Money tax_amount = 11; // 消費税額
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// === リクエスト/レスポンス ===
|
|
765
|
-
|
|
766
|
-
// 仕訳取得
|
|
767
|
-
message GetJournalRequest {
|
|
768
|
-
string slip_number = 1;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
message GetJournalResponse {
|
|
772
|
-
Journal journal = 1;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// 仕訳一覧取得
|
|
776
|
-
message ListJournalsRequest {
|
|
777
|
-
PageRequest page = 1;
|
|
778
|
-
Date date_from = 2; // 起票日From
|
|
779
|
-
Date date_to = 3; // 起票日To
|
|
780
|
-
FiscalPeriod fiscal_period = 4; // 決算期
|
|
781
|
-
JournalType journal_type = 5; // 仕訳伝票区分
|
|
782
|
-
JournalStatus status = 6; // ステータス
|
|
783
|
-
string account_code = 7; // 勘定科目コード
|
|
784
|
-
string keyword = 8; // 検索キーワード
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
message ListJournalsResponse {
|
|
788
|
-
repeated Journal journals = 1;
|
|
789
|
-
PageInfo page_info = 2;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
// 仕訳登録
|
|
793
|
-
message CreateJournalRequest {
|
|
794
|
-
Date journal_date = 1;
|
|
795
|
-
string summary = 2;
|
|
796
|
-
JournalType journal_type = 3;
|
|
797
|
-
bool is_closing_journal = 4;
|
|
798
|
-
repeated CreateJournalDetailRequest details = 5;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
message CreateJournalDetailRequest {
|
|
802
|
-
int32 line_number = 1;
|
|
803
|
-
string line_summary = 2;
|
|
804
|
-
repeated CreateJournalDebitCreditRequest debit_credit_details = 3;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
message CreateJournalDebitCreditRequest {
|
|
808
|
-
DebitCreditType debit_credit_type = 1;
|
|
809
|
-
string account_code = 2;
|
|
810
|
-
string sub_account_code = 3;
|
|
811
|
-
string department_code = 4;
|
|
812
|
-
string project_code = 5;
|
|
813
|
-
Money amount = 6;
|
|
814
|
-
string tax_code = 7;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
message CreateJournalResponse {
|
|
818
|
-
Journal journal = 1;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
// 仕訳更新
|
|
822
|
-
message UpdateJournalRequest {
|
|
823
|
-
string slip_number = 1;
|
|
824
|
-
Date journal_date = 2;
|
|
825
|
-
string summary = 3;
|
|
826
|
-
JournalType journal_type = 4;
|
|
827
|
-
bool is_closing_journal = 5;
|
|
828
|
-
repeated CreateJournalDetailRequest details = 6;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
message UpdateJournalResponse {
|
|
832
|
-
Journal journal = 1;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
// 仕訳取消(赤黒処理)
|
|
836
|
-
message CancelJournalRequest {
|
|
837
|
-
string slip_number = 1;
|
|
838
|
-
string cancel_reason = 2;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
message CancelJournalResponse {
|
|
842
|
-
Journal original_journal = 1; // 元の仕訳
|
|
843
|
-
Journal reversal_journal = 2; // 取消仕訳
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// 仕訳承認
|
|
847
|
-
message ApproveJournalRequest {
|
|
848
|
-
string slip_number = 1;
|
|
849
|
-
string approver_comment = 2;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
message ApproveJournalResponse {
|
|
853
|
-
Journal journal = 1;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// 仕訳一括登録(クライアントストリーミング)
|
|
857
|
-
message BulkCreateJournalRequest {
|
|
858
|
-
CreateJournalRequest journal = 1;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
message BulkCreateJournalResponse {
|
|
862
|
-
int32 success_count = 1;
|
|
863
|
-
int32 failure_count = 2;
|
|
864
|
-
repeated ErrorDetail errors = 3;
|
|
865
|
-
repeated string created_slip_numbers = 4;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// 貸借バランスチェック
|
|
869
|
-
message ValidateBalanceRequest {
|
|
870
|
-
repeated CreateJournalDetailRequest details = 1;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
message ValidateBalanceResponse {
|
|
874
|
-
bool is_balanced = 1;
|
|
875
|
-
Money total_debit = 2;
|
|
876
|
-
Money total_credit = 3;
|
|
877
|
-
Money difference = 4;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
// === サービス定義 ===
|
|
881
|
-
|
|
882
|
-
service JournalService {
|
|
883
|
-
// 単項 RPC
|
|
884
|
-
rpc GetJournal(GetJournalRequest) returns (GetJournalResponse);
|
|
885
|
-
rpc CreateJournal(CreateJournalRequest) returns (CreateJournalResponse);
|
|
886
|
-
rpc UpdateJournal(UpdateJournalRequest) returns (UpdateJournalResponse);
|
|
887
|
-
rpc CancelJournal(CancelJournalRequest) returns (CancelJournalResponse);
|
|
888
|
-
rpc ApproveJournal(ApproveJournalRequest) returns (ApproveJournalResponse);
|
|
889
|
-
rpc ValidateBalance(ValidateBalanceRequest) returns (ValidateBalanceResponse);
|
|
890
|
-
|
|
891
|
-
// サーバーストリーミング RPC
|
|
892
|
-
rpc ListJournals(ListJournalsRequest) returns (stream Journal);
|
|
893
|
-
|
|
894
|
-
// クライアントストリーミング RPC
|
|
895
|
-
rpc BulkCreateJournals(stream BulkCreateJournalRequest) returns (BulkCreateJournalResponse);
|
|
896
|
-
|
|
897
|
-
// 双方向ストリーミング RPC(リアルタイム仕訳入力)
|
|
898
|
-
rpc StreamJournalEntry(stream CreateJournalRequest) returns (stream CreateJournalResponse);
|
|
899
|
-
}
|
|
900
|
-
```
|
|
901
|
-
|
|
902
|
-
</details>
|
|
903
|
-
|
|
904
|
-
### 23.4 残高 Protocol Buffers
|
|
905
|
-
|
|
906
|
-
<details>
|
|
907
|
-
<summary>src/main/proto/balance.proto</summary>
|
|
908
|
-
|
|
909
|
-
```protobuf
|
|
910
|
-
syntax = "proto3";
|
|
911
|
-
|
|
912
|
-
package com.example.accounting;
|
|
913
|
-
|
|
914
|
-
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
915
|
-
option java_outer_classname = "BalanceProto";
|
|
916
|
-
option java_multiple_files = true;
|
|
917
|
-
|
|
918
|
-
import "common.proto";
|
|
919
|
-
import "account.proto";
|
|
920
|
-
|
|
921
|
-
// 日次勘定科目残高
|
|
922
|
-
message DailyBalance {
|
|
923
|
-
Date balance_date = 1; // 残高日
|
|
924
|
-
string account_code = 2; // 勘定科目コード
|
|
925
|
-
string account_name = 3; // 勘定科目名
|
|
926
|
-
string sub_account_code = 4; // 補助科目コード
|
|
927
|
-
string department_code = 5; // 部門コード
|
|
928
|
-
Money previous_balance = 6; // 前日残高
|
|
929
|
-
Money debit_amount = 7; // 借方金額
|
|
930
|
-
Money credit_amount = 8; // 貸方金額
|
|
931
|
-
Money current_balance = 9; // 当日残高
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// 月次勘定科目残高
|
|
935
|
-
message MonthlyBalance {
|
|
936
|
-
FiscalPeriod fiscal_period = 1; // 決算期
|
|
937
|
-
string account_code = 2; // 勘定科目コード
|
|
938
|
-
string account_name = 3; // 勘定科目名
|
|
939
|
-
string sub_account_code = 4; // 補助科目コード
|
|
940
|
-
string department_code = 5; // 部門コード
|
|
941
|
-
Money opening_balance = 6; // 月初残高
|
|
942
|
-
Money debit_amount = 7; // 借方金額
|
|
943
|
-
Money credit_amount = 8; // 貸方金額
|
|
944
|
-
Money closing_balance = 9; // 月末残高
|
|
945
|
-
Money closing_debit_balance = 10; // 決算借方金額
|
|
946
|
-
Money closing_credit_balance = 11; // 決算貸方金額
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
// 残高サマリー
|
|
950
|
-
message BalanceSummary {
|
|
951
|
-
string account_code = 1;
|
|
952
|
-
string account_name = 2;
|
|
953
|
-
BsplType bspl_type = 3;
|
|
954
|
-
ElementType element_type = 4;
|
|
955
|
-
Money balance = 5;
|
|
956
|
-
int32 level = 6;
|
|
957
|
-
bool is_leaf = 7;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
// === リクエスト/レスポンス ===
|
|
961
|
-
|
|
962
|
-
// 日次残高取得
|
|
963
|
-
message GetDailyBalanceRequest {
|
|
964
|
-
Date balance_date = 1;
|
|
965
|
-
string account_code = 2;
|
|
966
|
-
string sub_account_code = 3;
|
|
967
|
-
string department_code = 4;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
message GetDailyBalanceResponse {
|
|
971
|
-
DailyBalance balance = 1;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
// 日次残高一覧取得
|
|
975
|
-
message ListDailyBalancesRequest {
|
|
976
|
-
Date balance_date = 1;
|
|
977
|
-
BsplType bspl_type = 2;
|
|
978
|
-
ElementType element_type = 3;
|
|
979
|
-
string department_code = 4;
|
|
980
|
-
bool posting_accounts_only = 5; // 計上科目のみ
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
message ListDailyBalancesResponse {
|
|
984
|
-
repeated DailyBalance balances = 1;
|
|
985
|
-
Money total_debit = 2;
|
|
986
|
-
Money total_credit = 3;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
// 月次残高取得
|
|
990
|
-
message GetMonthlyBalanceRequest {
|
|
991
|
-
FiscalPeriod fiscal_period = 1;
|
|
992
|
-
string account_code = 2;
|
|
993
|
-
string sub_account_code = 3;
|
|
994
|
-
string department_code = 4;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
message GetMonthlyBalanceResponse {
|
|
998
|
-
MonthlyBalance balance = 1;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
// 月次残高一覧取得
|
|
1002
|
-
message ListMonthlyBalancesRequest {
|
|
1003
|
-
FiscalPeriod fiscal_period = 1;
|
|
1004
|
-
BsplType bspl_type = 2;
|
|
1005
|
-
ElementType element_type = 3;
|
|
1006
|
-
string department_code = 4;
|
|
1007
|
-
bool include_closing = 5; // 決算仕訳含む
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
message ListMonthlyBalancesResponse {
|
|
1011
|
-
repeated MonthlyBalance balances = 1;
|
|
1012
|
-
Money total_debit = 2;
|
|
1013
|
-
Money total_credit = 3;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// 勘定科目別残高照会
|
|
1017
|
-
message GetAccountBalanceRequest {
|
|
1018
|
-
string account_code = 1;
|
|
1019
|
-
Date date_from = 2;
|
|
1020
|
-
Date date_to = 3;
|
|
1021
|
-
string sub_account_code = 4;
|
|
1022
|
-
string department_code = 5;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
message GetAccountBalanceResponse {
|
|
1026
|
-
string account_code = 1;
|
|
1027
|
-
string account_name = 2;
|
|
1028
|
-
Money opening_balance = 3; // 期首残高
|
|
1029
|
-
Money total_debit = 4; // 期間借方合計
|
|
1030
|
-
Money total_credit = 5; // 期間貸方合計
|
|
1031
|
-
Money closing_balance = 6; // 期末残高
|
|
1032
|
-
repeated DailyBalance daily_movements = 7; // 日別推移
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
// 残高サマリー取得(試算表用)
|
|
1036
|
-
message GetBalanceSummaryRequest {
|
|
1037
|
-
Date as_of_date = 1;
|
|
1038
|
-
BsplType bspl_type = 2;
|
|
1039
|
-
bool include_sub_accounts = 3;
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
message GetBalanceSummaryResponse {
|
|
1043
|
-
repeated BalanceSummary summaries = 1;
|
|
1044
|
-
Money bs_total_debit = 2; // BS借方合計
|
|
1045
|
-
Money bs_total_credit = 3; // BS貸方合計
|
|
1046
|
-
Money pl_total_debit = 4; // PL借方合計
|
|
1047
|
-
Money pl_total_credit = 5; // PL貸方合計
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
// 残高更新(仕訳転記時)
|
|
1051
|
-
message UpdateBalanceRequest {
|
|
1052
|
-
string slip_number = 1;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
message UpdateBalanceResponse {
|
|
1056
|
-
bool success = 1;
|
|
1057
|
-
int32 updated_daily_records = 2;
|
|
1058
|
-
int32 updated_monthly_records = 3;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
// === サービス定義 ===
|
|
1062
|
-
|
|
1063
|
-
service BalanceService {
|
|
1064
|
-
// 単項 RPC
|
|
1065
|
-
rpc GetDailyBalance(GetDailyBalanceRequest) returns (GetDailyBalanceResponse);
|
|
1066
|
-
rpc GetMonthlyBalance(GetMonthlyBalanceRequest) returns (GetMonthlyBalanceResponse);
|
|
1067
|
-
rpc GetAccountBalance(GetAccountBalanceRequest) returns (GetAccountBalanceResponse);
|
|
1068
|
-
rpc GetBalanceSummary(GetBalanceSummaryRequest) returns (GetBalanceSummaryResponse);
|
|
1069
|
-
rpc UpdateBalance(UpdateBalanceRequest) returns (UpdateBalanceResponse);
|
|
1070
|
-
|
|
1071
|
-
// サーバーストリーミング RPC
|
|
1072
|
-
rpc ListDailyBalances(ListDailyBalancesRequest) returns (stream DailyBalance);
|
|
1073
|
-
rpc ListMonthlyBalances(ListMonthlyBalancesRequest) returns (stream MonthlyBalance);
|
|
1074
|
-
|
|
1075
|
-
// 双方向ストリーミング(リアルタイム残高監視)
|
|
1076
|
-
rpc WatchBalance(stream GetAccountBalanceRequest) returns (stream GetAccountBalanceResponse);
|
|
1077
|
-
}
|
|
1078
|
-
```
|
|
1079
|
-
|
|
1080
|
-
</details>
|
|
1081
|
-
|
|
1082
|
-
---
|
|
1083
|
-
|
|
1084
|
-
## 第 24 章:gRPC サービス実装
|
|
1085
|
-
|
|
1086
|
-
### 24.1 勘定科目サービス実装
|
|
1087
|
-
|
|
1088
|
-
<details>
|
|
1089
|
-
<summary>GrpcAccountService.java</summary>
|
|
1090
|
-
|
|
1091
|
-
```java
|
|
1092
|
-
package com.example.accounting.infrastructure.in.grpc.service;
|
|
1093
|
-
|
|
1094
|
-
import com.example.accounting.application.port.in.AccountUseCase;
|
|
1095
|
-
import com.example.accounting.domain.model.account.Account;
|
|
1096
|
-
import com.example.accounting.domain.model.account.AccountCode;
|
|
1097
|
-
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1098
|
-
import com.example.accounting.infrastructure.in.grpc.converter.AccountConverter;
|
|
1099
|
-
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1100
|
-
import io.grpc.Status;
|
|
1101
|
-
import io.grpc.stub.StreamObserver;
|
|
1102
|
-
import net.devh.boot.grpc.server.service.GrpcService;
|
|
1103
|
-
import org.slf4j.Logger;
|
|
1104
|
-
import org.slf4j.LoggerFactory;
|
|
1105
|
-
|
|
1106
|
-
import java.util.List;
|
|
1107
|
-
import java.util.concurrent.atomic.AtomicInteger;
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* 勘定科目 gRPC サービス実装
|
|
1111
|
-
*/
|
|
1112
|
-
@GrpcService
|
|
1113
|
-
public class GrpcAccountService extends AccountServiceGrpc.AccountServiceImplBase {
|
|
1114
|
-
|
|
1115
|
-
private static final Logger log = LoggerFactory.getLogger(GrpcAccountService.class);
|
|
1116
|
-
|
|
1117
|
-
private final AccountUseCase accountUseCase;
|
|
1118
|
-
private final AccountConverter converter;
|
|
1119
|
-
|
|
1120
|
-
public GrpcAccountService(AccountUseCase accountUseCase, AccountConverter converter) {
|
|
1121
|
-
this.accountUseCase = accountUseCase;
|
|
1122
|
-
this.converter = converter;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* 単項 RPC: 勘定科目取得
|
|
1127
|
-
*/
|
|
1128
|
-
@Override
|
|
1129
|
-
public void getAccount(GetAccountRequest request,
|
|
1130
|
-
StreamObserver<GetAccountResponse> responseObserver) {
|
|
1131
|
-
log.info("getAccount: {}", request.getAccountCode());
|
|
1132
|
-
|
|
1133
|
-
try {
|
|
1134
|
-
AccountCode code = new AccountCode(request.getAccountCode());
|
|
1135
|
-
Account account = accountUseCase.findByCode(code)
|
|
1136
|
-
.orElseThrow(() -> new ResourceNotFoundException(
|
|
1137
|
-
"勘定科目", request.getAccountCode()));
|
|
1138
|
-
|
|
1139
|
-
GetAccountResponse response = GetAccountResponse.newBuilder()
|
|
1140
|
-
.setAccount(converter.toProto(account))
|
|
1141
|
-
.build();
|
|
1142
|
-
|
|
1143
|
-
responseObserver.onNext(response);
|
|
1144
|
-
responseObserver.onCompleted();
|
|
1145
|
-
|
|
1146
|
-
} catch (ResourceNotFoundException e) {
|
|
1147
|
-
log.warn("Account not found: {}", request.getAccountCode());
|
|
1148
|
-
responseObserver.onError(
|
|
1149
|
-
Status.NOT_FOUND
|
|
1150
|
-
.withDescription("勘定科目が見つかりません: " + request.getAccountCode())
|
|
1151
|
-
.asRuntimeException()
|
|
1152
|
-
);
|
|
1153
|
-
} catch (Exception e) {
|
|
1154
|
-
log.error("Error getting account", e);
|
|
1155
|
-
responseObserver.onError(
|
|
1156
|
-
Status.INTERNAL
|
|
1157
|
-
.withDescription("内部エラーが発生しました")
|
|
1158
|
-
.withCause(e)
|
|
1159
|
-
.asRuntimeException()
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* 単項 RPC: 勘定科目登録
|
|
1166
|
-
*/
|
|
1167
|
-
@Override
|
|
1168
|
-
public void createAccount(CreateAccountRequest request,
|
|
1169
|
-
StreamObserver<CreateAccountResponse> responseObserver) {
|
|
1170
|
-
log.info("createAccount: {}", request.getAccountCode());
|
|
1171
|
-
|
|
1172
|
-
try {
|
|
1173
|
-
Account account = converter.toDomain(request);
|
|
1174
|
-
Account created = accountUseCase.create(account);
|
|
1175
|
-
|
|
1176
|
-
CreateAccountResponse response = CreateAccountResponse.newBuilder()
|
|
1177
|
-
.setAccount(converter.toProto(created))
|
|
1178
|
-
.build();
|
|
1179
|
-
|
|
1180
|
-
responseObserver.onNext(response);
|
|
1181
|
-
responseObserver.onCompleted();
|
|
1182
|
-
|
|
1183
|
-
} catch (IllegalArgumentException e) {
|
|
1184
|
-
log.warn("Invalid request: {}", e.getMessage());
|
|
1185
|
-
responseObserver.onError(
|
|
1186
|
-
Status.INVALID_ARGUMENT
|
|
1187
|
-
.withDescription(e.getMessage())
|
|
1188
|
-
.asRuntimeException()
|
|
1189
|
-
);
|
|
1190
|
-
} catch (Exception e) {
|
|
1191
|
-
log.error("Error creating account", e);
|
|
1192
|
-
responseObserver.onError(
|
|
1193
|
-
Status.INTERNAL
|
|
1194
|
-
.withDescription("内部エラーが発生しました")
|
|
1195
|
-
.asRuntimeException()
|
|
1196
|
-
);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
/**
|
|
1201
|
-
* サーバーストリーミング RPC: 勘定科目一覧取得
|
|
1202
|
-
*/
|
|
1203
|
-
@Override
|
|
1204
|
-
public void listAccounts(ListAccountsRequest request,
|
|
1205
|
-
StreamObserver<com.example.accounting.infrastructure.in.grpc.proto.Account> responseObserver) {
|
|
1206
|
-
log.info("listAccounts: bsplType={}, keyword={}",
|
|
1207
|
-
request.getBsplType(), request.getKeyword());
|
|
1208
|
-
|
|
1209
|
-
try {
|
|
1210
|
-
List<Account> accounts = accountUseCase.findAll(
|
|
1211
|
-
converter.toCriteria(request)
|
|
1212
|
-
);
|
|
1213
|
-
|
|
1214
|
-
// ストリーミングで勘定科目を1件ずつ送信
|
|
1215
|
-
for (Account account : accounts) {
|
|
1216
|
-
responseObserver.onNext(converter.toProto(account));
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
responseObserver.onCompleted();
|
|
1220
|
-
log.info("listAccounts completed: {} items", accounts.size());
|
|
1221
|
-
|
|
1222
|
-
} catch (Exception e) {
|
|
1223
|
-
log.error("Error listing accounts", e);
|
|
1224
|
-
responseObserver.onError(
|
|
1225
|
-
Status.INTERNAL
|
|
1226
|
-
.withDescription("内部エラーが発生しました")
|
|
1227
|
-
.asRuntimeException()
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
/**
|
|
1233
|
-
* クライアントストリーミング RPC: 勘定科目一括登録
|
|
1234
|
-
*/
|
|
1235
|
-
@Override
|
|
1236
|
-
public StreamObserver<BulkCreateAccountRequest> bulkCreateAccounts(
|
|
1237
|
-
StreamObserver<BulkCreateAccountResponse> responseObserver) {
|
|
1238
|
-
|
|
1239
|
-
log.info("bulkCreateAccounts: started");
|
|
1240
|
-
|
|
1241
|
-
AtomicInteger successCount = new AtomicInteger(0);
|
|
1242
|
-
AtomicInteger failureCount = new AtomicInteger(0);
|
|
1243
|
-
List<ErrorDetail> errors = new java.util.ArrayList<>();
|
|
1244
|
-
|
|
1245
|
-
return new StreamObserver<BulkCreateAccountRequest>() {
|
|
1246
|
-
@Override
|
|
1247
|
-
public void onNext(BulkCreateAccountRequest request) {
|
|
1248
|
-
try {
|
|
1249
|
-
CreateAccountRequest accountRequest = request.getAccount();
|
|
1250
|
-
Account account = converter.toDomain(accountRequest);
|
|
1251
|
-
accountUseCase.create(account);
|
|
1252
|
-
successCount.incrementAndGet();
|
|
1253
|
-
log.debug("Created account: {}", accountRequest.getAccountCode());
|
|
1254
|
-
|
|
1255
|
-
} catch (Exception e) {
|
|
1256
|
-
failureCount.incrementAndGet();
|
|
1257
|
-
errors.add(ErrorDetail.newBuilder()
|
|
1258
|
-
.setField(request.getAccount().getAccountCode())
|
|
1259
|
-
.setMessage(e.getMessage())
|
|
1260
|
-
.build());
|
|
1261
|
-
log.warn("Failed to create account: {}",
|
|
1262
|
-
request.getAccount().getAccountCode(), e);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
@Override
|
|
1267
|
-
public void onError(Throwable t) {
|
|
1268
|
-
log.error("bulkCreateAccounts error", t);
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
@Override
|
|
1272
|
-
public void onCompleted() {
|
|
1273
|
-
BulkCreateAccountResponse response = BulkCreateAccountResponse.newBuilder()
|
|
1274
|
-
.setSuccessCount(successCount.get())
|
|
1275
|
-
.setFailureCount(failureCount.get())
|
|
1276
|
-
.addAllErrors(errors)
|
|
1277
|
-
.build();
|
|
1278
|
-
|
|
1279
|
-
responseObserver.onNext(response);
|
|
1280
|
-
responseObserver.onCompleted();
|
|
1281
|
-
|
|
1282
|
-
log.info("bulkCreateAccounts completed: success={}, failure={}",
|
|
1283
|
-
successCount.get(), failureCount.get());
|
|
1284
|
-
}
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
/**
|
|
1289
|
-
* 勘定科目ツリー取得
|
|
1290
|
-
*/
|
|
1291
|
-
@Override
|
|
1292
|
-
public void getAccountTree(GetAccountTreeRequest request,
|
|
1293
|
-
StreamObserver<GetAccountTreeResponse> responseObserver) {
|
|
1294
|
-
log.info("getAccountTree: bsplType={}", request.getBsplType());
|
|
1295
|
-
|
|
1296
|
-
try {
|
|
1297
|
-
var tree = accountUseCase.getAccountTree(
|
|
1298
|
-
converter.toDomainBsplType(request.getBsplType())
|
|
1299
|
-
);
|
|
1300
|
-
|
|
1301
|
-
GetAccountTreeResponse response = GetAccountTreeResponse.newBuilder()
|
|
1302
|
-
.addAllNodes(converter.toProtoTree(tree))
|
|
1303
|
-
.build();
|
|
1304
|
-
|
|
1305
|
-
responseObserver.onNext(response);
|
|
1306
|
-
responseObserver.onCompleted();
|
|
1307
|
-
|
|
1308
|
-
} catch (Exception e) {
|
|
1309
|
-
log.error("Error getting account tree", e);
|
|
1310
|
-
responseObserver.onError(
|
|
1311
|
-
Status.INTERNAL
|
|
1312
|
-
.withDescription("内部エラーが発生しました")
|
|
1313
|
-
.asRuntimeException()
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
```
|
|
1319
|
-
|
|
1320
|
-
</details>
|
|
1321
|
-
|
|
1322
|
-
### 24.2 仕訳サービス実装
|
|
1323
|
-
|
|
1324
|
-
<details>
|
|
1325
|
-
<summary>GrpcJournalService.java</summary>
|
|
1326
|
-
|
|
1327
|
-
```java
|
|
1328
|
-
package com.example.accounting.infrastructure.in.grpc.service;
|
|
1329
|
-
|
|
1330
|
-
import com.example.accounting.application.port.in.JournalUseCase;
|
|
1331
|
-
import com.example.accounting.domain.model.journal.Journal;
|
|
1332
|
-
import com.example.accounting.domain.model.journal.SlipNumber;
|
|
1333
|
-
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1334
|
-
import com.example.accounting.domain.exception.BalanceNotMatchException;
|
|
1335
|
-
import com.example.accounting.infrastructure.in.grpc.converter.JournalConverter;
|
|
1336
|
-
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1337
|
-
import io.grpc.Status;
|
|
1338
|
-
import io.grpc.stub.StreamObserver;
|
|
1339
|
-
import net.devh.boot.grpc.server.service.GrpcService;
|
|
1340
|
-
import org.slf4j.Logger;
|
|
1341
|
-
import org.slf4j.LoggerFactory;
|
|
1342
|
-
|
|
1343
|
-
import java.util.List;
|
|
1344
|
-
import java.util.concurrent.atomic.AtomicInteger;
|
|
1345
|
-
|
|
1346
|
-
/**
|
|
1347
|
-
* 仕訳 gRPC サービス実装
|
|
1348
|
-
*/
|
|
1349
|
-
@GrpcService
|
|
1350
|
-
public class GrpcJournalService extends JournalServiceGrpc.JournalServiceImplBase {
|
|
1351
|
-
|
|
1352
|
-
private static final Logger log = LoggerFactory.getLogger(GrpcJournalService.class);
|
|
1353
|
-
|
|
1354
|
-
private final JournalUseCase journalUseCase;
|
|
1355
|
-
private final JournalConverter converter;
|
|
1356
|
-
|
|
1357
|
-
public GrpcJournalService(JournalUseCase journalUseCase, JournalConverter converter) {
|
|
1358
|
-
this.journalUseCase = journalUseCase;
|
|
1359
|
-
this.converter = converter;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
/**
|
|
1363
|
-
* 単項 RPC: 仕訳取得
|
|
1364
|
-
*/
|
|
1365
|
-
@Override
|
|
1366
|
-
public void getJournal(GetJournalRequest request,
|
|
1367
|
-
StreamObserver<GetJournalResponse> responseObserver) {
|
|
1368
|
-
log.info("getJournal: {}", request.getSlipNumber());
|
|
1369
|
-
|
|
1370
|
-
try {
|
|
1371
|
-
SlipNumber slipNumber = new SlipNumber(request.getSlipNumber());
|
|
1372
|
-
Journal journal = journalUseCase.findBySlipNumber(slipNumber)
|
|
1373
|
-
.orElseThrow(() -> new ResourceNotFoundException(
|
|
1374
|
-
"仕訳", request.getSlipNumber()));
|
|
1375
|
-
|
|
1376
|
-
GetJournalResponse response = GetJournalResponse.newBuilder()
|
|
1377
|
-
.setJournal(converter.toProto(journal))
|
|
1378
|
-
.build();
|
|
1379
|
-
|
|
1380
|
-
responseObserver.onNext(response);
|
|
1381
|
-
responseObserver.onCompleted();
|
|
1382
|
-
|
|
1383
|
-
} catch (ResourceNotFoundException e) {
|
|
1384
|
-
log.warn("Journal not found: {}", request.getSlipNumber());
|
|
1385
|
-
responseObserver.onError(
|
|
1386
|
-
Status.NOT_FOUND
|
|
1387
|
-
.withDescription("仕訳が見つかりません: " + request.getSlipNumber())
|
|
1388
|
-
.asRuntimeException()
|
|
1389
|
-
);
|
|
1390
|
-
} catch (Exception e) {
|
|
1391
|
-
log.error("Error getting journal", e);
|
|
1392
|
-
responseObserver.onError(
|
|
1393
|
-
Status.INTERNAL
|
|
1394
|
-
.withDescription("内部エラーが発生しました")
|
|
1395
|
-
.asRuntimeException()
|
|
1396
|
-
);
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* 単項 RPC: 仕訳登録
|
|
1402
|
-
*/
|
|
1403
|
-
@Override
|
|
1404
|
-
public void createJournal(CreateJournalRequest request,
|
|
1405
|
-
StreamObserver<CreateJournalResponse> responseObserver) {
|
|
1406
|
-
log.info("createJournal: date={}", request.getJournalDate());
|
|
1407
|
-
|
|
1408
|
-
try {
|
|
1409
|
-
Journal journal = converter.toDomain(request);
|
|
1410
|
-
Journal created = journalUseCase.create(journal);
|
|
1411
|
-
|
|
1412
|
-
CreateJournalResponse response = CreateJournalResponse.newBuilder()
|
|
1413
|
-
.setJournal(converter.toProto(created))
|
|
1414
|
-
.build();
|
|
1415
|
-
|
|
1416
|
-
responseObserver.onNext(response);
|
|
1417
|
-
responseObserver.onCompleted();
|
|
1418
|
-
|
|
1419
|
-
} catch (BalanceNotMatchException e) {
|
|
1420
|
-
log.warn("Balance not match: {}", e.getMessage());
|
|
1421
|
-
responseObserver.onError(
|
|
1422
|
-
Status.FAILED_PRECONDITION
|
|
1423
|
-
.withDescription("貸借が一致しません: " + e.getMessage())
|
|
1424
|
-
.asRuntimeException()
|
|
1425
|
-
);
|
|
1426
|
-
} catch (IllegalArgumentException e) {
|
|
1427
|
-
log.warn("Invalid request: {}", e.getMessage());
|
|
1428
|
-
responseObserver.onError(
|
|
1429
|
-
Status.INVALID_ARGUMENT
|
|
1430
|
-
.withDescription(e.getMessage())
|
|
1431
|
-
.asRuntimeException()
|
|
1432
|
-
);
|
|
1433
|
-
} catch (Exception e) {
|
|
1434
|
-
log.error("Error creating journal", e);
|
|
1435
|
-
responseObserver.onError(
|
|
1436
|
-
Status.INTERNAL
|
|
1437
|
-
.withDescription("内部エラーが発生しました")
|
|
1438
|
-
.asRuntimeException()
|
|
1439
|
-
);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
/**
|
|
1444
|
-
* 単項 RPC: 仕訳取消(赤黒処理)
|
|
1445
|
-
*/
|
|
1446
|
-
@Override
|
|
1447
|
-
public void cancelJournal(CancelJournalRequest request,
|
|
1448
|
-
StreamObserver<CancelJournalResponse> responseObserver) {
|
|
1449
|
-
log.info("cancelJournal: {}", request.getSlipNumber());
|
|
1450
|
-
|
|
1451
|
-
try {
|
|
1452
|
-
SlipNumber slipNumber = new SlipNumber(request.getSlipNumber());
|
|
1453
|
-
var result = journalUseCase.cancel(slipNumber, request.getCancelReason());
|
|
1454
|
-
|
|
1455
|
-
CancelJournalResponse response = CancelJournalResponse.newBuilder()
|
|
1456
|
-
.setOriginalJournal(converter.toProto(result.getOriginal()))
|
|
1457
|
-
.setReversalJournal(converter.toProto(result.getReversal()))
|
|
1458
|
-
.build();
|
|
1459
|
-
|
|
1460
|
-
responseObserver.onNext(response);
|
|
1461
|
-
responseObserver.onCompleted();
|
|
1462
|
-
|
|
1463
|
-
} catch (ResourceNotFoundException e) {
|
|
1464
|
-
log.warn("Journal not found for cancel: {}", request.getSlipNumber());
|
|
1465
|
-
responseObserver.onError(
|
|
1466
|
-
Status.NOT_FOUND
|
|
1467
|
-
.withDescription("取消対象の仕訳が見つかりません: " + request.getSlipNumber())
|
|
1468
|
-
.asRuntimeException()
|
|
1469
|
-
);
|
|
1470
|
-
} catch (Exception e) {
|
|
1471
|
-
log.error("Error canceling journal", e);
|
|
1472
|
-
responseObserver.onError(
|
|
1473
|
-
Status.INTERNAL
|
|
1474
|
-
.withDescription("内部エラーが発生しました")
|
|
1475
|
-
.asRuntimeException()
|
|
1476
|
-
);
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
/**
|
|
1481
|
-
* サーバーストリーミング RPC: 仕訳一覧取得
|
|
1482
|
-
*/
|
|
1483
|
-
@Override
|
|
1484
|
-
public void listJournals(ListJournalsRequest request,
|
|
1485
|
-
StreamObserver<com.example.accounting.infrastructure.in.grpc.proto.Journal> responseObserver) {
|
|
1486
|
-
log.info("listJournals: dateFrom={}, dateTo={}",
|
|
1487
|
-
request.getDateFrom(), request.getDateTo());
|
|
1488
|
-
|
|
1489
|
-
try {
|
|
1490
|
-
List<Journal> journals = journalUseCase.findAll(
|
|
1491
|
-
converter.toCriteria(request)
|
|
1492
|
-
);
|
|
1493
|
-
|
|
1494
|
-
// ストリーミングで仕訳を1件ずつ送信
|
|
1495
|
-
for (Journal journal : journals) {
|
|
1496
|
-
responseObserver.onNext(converter.toProto(journal));
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
responseObserver.onCompleted();
|
|
1500
|
-
log.info("listJournals completed: {} items", journals.size());
|
|
1501
|
-
|
|
1502
|
-
} catch (Exception e) {
|
|
1503
|
-
log.error("Error listing journals", e);
|
|
1504
|
-
responseObserver.onError(
|
|
1505
|
-
Status.INTERNAL
|
|
1506
|
-
.withDescription("内部エラーが発生しました")
|
|
1507
|
-
.asRuntimeException()
|
|
1508
|
-
);
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
/**
|
|
1513
|
-
* クライアントストリーミング RPC: 仕訳一括登録
|
|
1514
|
-
*/
|
|
1515
|
-
@Override
|
|
1516
|
-
public StreamObserver<BulkCreateJournalRequest> bulkCreateJournals(
|
|
1517
|
-
StreamObserver<BulkCreateJournalResponse> responseObserver) {
|
|
1518
|
-
|
|
1519
|
-
log.info("bulkCreateJournals: started");
|
|
1520
|
-
|
|
1521
|
-
AtomicInteger successCount = new AtomicInteger(0);
|
|
1522
|
-
AtomicInteger failureCount = new AtomicInteger(0);
|
|
1523
|
-
List<ErrorDetail> errors = new java.util.ArrayList<>();
|
|
1524
|
-
List<String> createdSlipNumbers = new java.util.ArrayList<>();
|
|
1525
|
-
|
|
1526
|
-
return new StreamObserver<BulkCreateJournalRequest>() {
|
|
1527
|
-
@Override
|
|
1528
|
-
public void onNext(BulkCreateJournalRequest request) {
|
|
1529
|
-
try {
|
|
1530
|
-
CreateJournalRequest journalRequest = request.getJournal();
|
|
1531
|
-
Journal journal = converter.toDomain(journalRequest);
|
|
1532
|
-
Journal created = journalUseCase.create(journal);
|
|
1533
|
-
successCount.incrementAndGet();
|
|
1534
|
-
createdSlipNumbers.add(created.getSlipNumber().getValue());
|
|
1535
|
-
log.debug("Created journal: {}", created.getSlipNumber().getValue());
|
|
1536
|
-
|
|
1537
|
-
} catch (Exception e) {
|
|
1538
|
-
failureCount.incrementAndGet();
|
|
1539
|
-
errors.add(ErrorDetail.newBuilder()
|
|
1540
|
-
.setField("journal")
|
|
1541
|
-
.setMessage(e.getMessage())
|
|
1542
|
-
.build());
|
|
1543
|
-
log.warn("Failed to create journal", e);
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
@Override
|
|
1548
|
-
public void onError(Throwable t) {
|
|
1549
|
-
log.error("bulkCreateJournals error", t);
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
@Override
|
|
1553
|
-
public void onCompleted() {
|
|
1554
|
-
BulkCreateJournalResponse response = BulkCreateJournalResponse.newBuilder()
|
|
1555
|
-
.setSuccessCount(successCount.get())
|
|
1556
|
-
.setFailureCount(failureCount.get())
|
|
1557
|
-
.addAllErrors(errors)
|
|
1558
|
-
.addAllCreatedSlipNumbers(createdSlipNumbers)
|
|
1559
|
-
.build();
|
|
1560
|
-
|
|
1561
|
-
responseObserver.onNext(response);
|
|
1562
|
-
responseObserver.onCompleted();
|
|
1563
|
-
|
|
1564
|
-
log.info("bulkCreateJournals completed: success={}, failure={}",
|
|
1565
|
-
successCount.get(), failureCount.get());
|
|
1566
|
-
}
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
/**
|
|
1571
|
-
* 単項 RPC: 貸借バランスチェック
|
|
1572
|
-
*/
|
|
1573
|
-
@Override
|
|
1574
|
-
public void validateBalance(ValidateBalanceRequest request,
|
|
1575
|
-
StreamObserver<ValidateBalanceResponse> responseObserver) {
|
|
1576
|
-
log.info("validateBalance");
|
|
1577
|
-
|
|
1578
|
-
try {
|
|
1579
|
-
var result = journalUseCase.validateBalance(
|
|
1580
|
-
converter.toDetailDomainList(request.getDetailsList())
|
|
1581
|
-
);
|
|
1582
|
-
|
|
1583
|
-
ValidateBalanceResponse response = ValidateBalanceResponse.newBuilder()
|
|
1584
|
-
.setIsBalanced(result.isBalanced())
|
|
1585
|
-
.setTotalDebit(converter.toProtoMoney(result.getTotalDebit()))
|
|
1586
|
-
.setTotalCredit(converter.toProtoMoney(result.getTotalCredit()))
|
|
1587
|
-
.setDifference(converter.toProtoMoney(result.getDifference()))
|
|
1588
|
-
.build();
|
|
1589
|
-
|
|
1590
|
-
responseObserver.onNext(response);
|
|
1591
|
-
responseObserver.onCompleted();
|
|
1592
|
-
|
|
1593
|
-
} catch (Exception e) {
|
|
1594
|
-
log.error("Error validating balance", e);
|
|
1595
|
-
responseObserver.onError(
|
|
1596
|
-
Status.INTERNAL
|
|
1597
|
-
.withDescription("内部エラーが発生しました")
|
|
1598
|
-
.asRuntimeException()
|
|
1599
|
-
);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
```
|
|
1604
|
-
|
|
1605
|
-
</details>
|
|
1606
|
-
|
|
1607
|
-
### 24.3 コンバーター実装
|
|
1608
|
-
|
|
1609
|
-
<details>
|
|
1610
|
-
<summary>AccountConverter.java</summary>
|
|
1611
|
-
|
|
1612
|
-
```java
|
|
1613
|
-
package com.example.accounting.infrastructure.in.grpc.converter;
|
|
1614
|
-
|
|
1615
|
-
import com.example.accounting.domain.model.account.*;
|
|
1616
|
-
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1617
|
-
import org.springframework.stereotype.Component;
|
|
1618
|
-
|
|
1619
|
-
import java.util.List;
|
|
1620
|
-
import java.util.stream.Collectors;
|
|
1621
|
-
|
|
1622
|
-
/**
|
|
1623
|
-
* 勘定科目ドメインモデル ⇔ Protocol Buffers 変換
|
|
1624
|
-
*/
|
|
1625
|
-
@Component
|
|
1626
|
-
public class AccountConverter {
|
|
1627
|
-
|
|
1628
|
-
/**
|
|
1629
|
-
* ドメインモデル → Proto
|
|
1630
|
-
*/
|
|
1631
|
-
public com.example.accounting.infrastructure.in.grpc.proto.Account toProto(Account domain) {
|
|
1632
|
-
return com.example.accounting.infrastructure.in.grpc.proto.Account.newBuilder()
|
|
1633
|
-
.setAccountCode(domain.getAccountCode().getValue())
|
|
1634
|
-
.setAccountName(domain.getAccountName())
|
|
1635
|
-
.setBsplType(toProtoBsplType(domain.getBsplType()))
|
|
1636
|
-
.setDebitCreditType(toProtoDebitCreditType(domain.getDebitCreditType()))
|
|
1637
|
-
.setElementType(toProtoElementType(domain.getElementType()))
|
|
1638
|
-
.setAggregationType(toProtoAggregationType(domain.getAggregationType()))
|
|
1639
|
-
.setParentAccountCode(nullToEmpty(domain.getParentAccountCode()))
|
|
1640
|
-
.setAccountPath(nullToEmpty(domain.getAccountPath()))
|
|
1641
|
-
.setDisplayOrder(domain.getDisplayOrder())
|
|
1642
|
-
.setIsActive(domain.isActive())
|
|
1643
|
-
.build();
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
/**
|
|
1647
|
-
* CreateAccountRequest → ドメインモデル
|
|
1648
|
-
*/
|
|
1649
|
-
public Account toDomain(CreateAccountRequest request) {
|
|
1650
|
-
return Account.builder()
|
|
1651
|
-
.accountCode(new AccountCode(request.getAccountCode()))
|
|
1652
|
-
.accountName(request.getAccountName())
|
|
1653
|
-
.bsplType(toDomainBsplType(request.getBsplType()))
|
|
1654
|
-
.debitCreditType(toDomainDebitCreditType(request.getDebitCreditType()))
|
|
1655
|
-
.elementType(toDomainElementType(request.getElementType()))
|
|
1656
|
-
.aggregationType(toDomainAggregationType(request.getAggregationType()))
|
|
1657
|
-
.parentAccountCode(emptyToNull(request.getParentAccountCode()))
|
|
1658
|
-
.displayOrder(request.getDisplayOrder())
|
|
1659
|
-
.isActive(true)
|
|
1660
|
-
.build();
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
/**
|
|
1664
|
-
* ListAccountsRequest → 検索条件
|
|
1665
|
-
*/
|
|
1666
|
-
public AccountSearchCriteria toCriteria(ListAccountsRequest request) {
|
|
1667
|
-
return AccountSearchCriteria.builder()
|
|
1668
|
-
.bsplType(request.hasBsplType()
|
|
1669
|
-
? toDomainBsplType(request.getBsplType()) : null)
|
|
1670
|
-
.elementType(request.hasElementType()
|
|
1671
|
-
? toDomainElementType(request.getElementType()) : null)
|
|
1672
|
-
.aggregationType(request.hasAggregationType()
|
|
1673
|
-
? toDomainAggregationType(request.getAggregationType()) : null)
|
|
1674
|
-
.keyword(emptyToNull(request.getKeyword()))
|
|
1675
|
-
.activeOnly(request.getActiveOnly())
|
|
1676
|
-
.page(request.hasPage() ? request.getPage().getPage() : 0)
|
|
1677
|
-
.size(request.hasPage() ? request.getPage().getSize() : 20)
|
|
1678
|
-
.build();
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
/**
|
|
1682
|
-
* ツリー構造を Proto に変換
|
|
1683
|
-
*/
|
|
1684
|
-
public List<AccountNode> toProtoTree(List<AccountTreeNode> tree) {
|
|
1685
|
-
return tree.stream()
|
|
1686
|
-
.map(this::toProtoNode)
|
|
1687
|
-
.collect(Collectors.toList());
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
private AccountNode toProtoNode(AccountTreeNode node) {
|
|
1691
|
-
AccountNode.Builder builder = AccountNode.newBuilder()
|
|
1692
|
-
.setAccount(toProto(node.getAccount()));
|
|
1693
|
-
|
|
1694
|
-
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
1695
|
-
builder.addAllChildren(
|
|
1696
|
-
node.getChildren().stream()
|
|
1697
|
-
.map(this::toProtoNode)
|
|
1698
|
-
.collect(Collectors.toList())
|
|
1699
|
-
);
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
return builder.build();
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
// === 区分変換 ===
|
|
1706
|
-
|
|
1707
|
-
public BsplType toProtoBsplType(
|
|
1708
|
-
com.example.accounting.domain.model.account.BsplType domain) {
|
|
1709
|
-
return switch (domain) {
|
|
1710
|
-
case BS -> BsplType.BSPL_TYPE_BS;
|
|
1711
|
-
case PL -> BsplType.BSPL_TYPE_PL;
|
|
1712
|
-
};
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
public com.example.accounting.domain.model.account.BsplType toDomainBsplType(
|
|
1716
|
-
BsplType proto) {
|
|
1717
|
-
return switch (proto) {
|
|
1718
|
-
case BSPL_TYPE_BS -> com.example.accounting.domain.model.account.BsplType.BS;
|
|
1719
|
-
case BSPL_TYPE_PL -> com.example.accounting.domain.model.account.BsplType.PL;
|
|
1720
|
-
default -> throw new IllegalArgumentException("Unknown BSPL type: " + proto);
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
private DebitCreditType toProtoDebitCreditType(
|
|
1725
|
-
com.example.accounting.domain.model.account.DebitCreditType domain) {
|
|
1726
|
-
return switch (domain) {
|
|
1727
|
-
case DEBIT -> DebitCreditType.DEBIT_CREDIT_TYPE_DEBIT;
|
|
1728
|
-
case CREDIT -> DebitCreditType.DEBIT_CREDIT_TYPE_CREDIT;
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
private com.example.accounting.domain.model.account.DebitCreditType toDomainDebitCreditType(
|
|
1733
|
-
DebitCreditType proto) {
|
|
1734
|
-
return switch (proto) {
|
|
1735
|
-
case DEBIT_CREDIT_TYPE_DEBIT ->
|
|
1736
|
-
com.example.accounting.domain.model.account.DebitCreditType.DEBIT;
|
|
1737
|
-
case DEBIT_CREDIT_TYPE_CREDIT ->
|
|
1738
|
-
com.example.accounting.domain.model.account.DebitCreditType.CREDIT;
|
|
1739
|
-
default -> throw new IllegalArgumentException("Unknown debit/credit type: " + proto);
|
|
1740
|
-
};
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
private ElementType toProtoElementType(
|
|
1744
|
-
com.example.accounting.domain.model.account.ElementType domain) {
|
|
1745
|
-
return switch (domain) {
|
|
1746
|
-
case ASSET -> ElementType.ELEMENT_TYPE_ASSET;
|
|
1747
|
-
case LIABILITY -> ElementType.ELEMENT_TYPE_LIABILITY;
|
|
1748
|
-
case EQUITY -> ElementType.ELEMENT_TYPE_EQUITY;
|
|
1749
|
-
case REVENUE -> ElementType.ELEMENT_TYPE_REVENUE;
|
|
1750
|
-
case EXPENSE -> ElementType.ELEMENT_TYPE_EXPENSE;
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
private com.example.accounting.domain.model.account.ElementType toDomainElementType(
|
|
1755
|
-
ElementType proto) {
|
|
1756
|
-
return switch (proto) {
|
|
1757
|
-
case ELEMENT_TYPE_ASSET ->
|
|
1758
|
-
com.example.accounting.domain.model.account.ElementType.ASSET;
|
|
1759
|
-
case ELEMENT_TYPE_LIABILITY ->
|
|
1760
|
-
com.example.accounting.domain.model.account.ElementType.LIABILITY;
|
|
1761
|
-
case ELEMENT_TYPE_EQUITY ->
|
|
1762
|
-
com.example.accounting.domain.model.account.ElementType.EQUITY;
|
|
1763
|
-
case ELEMENT_TYPE_REVENUE ->
|
|
1764
|
-
com.example.accounting.domain.model.account.ElementType.REVENUE;
|
|
1765
|
-
case ELEMENT_TYPE_EXPENSE ->
|
|
1766
|
-
com.example.accounting.domain.model.account.ElementType.EXPENSE;
|
|
1767
|
-
default -> throw new IllegalArgumentException("Unknown element type: " + proto);
|
|
1768
|
-
};
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
private AggregationType toProtoAggregationType(
|
|
1772
|
-
com.example.accounting.domain.model.account.AggregationType domain) {
|
|
1773
|
-
return switch (domain) {
|
|
1774
|
-
case HEADING -> AggregationType.AGGREGATION_TYPE_HEADING;
|
|
1775
|
-
case SUMMARY -> AggregationType.AGGREGATION_TYPE_SUMMARY;
|
|
1776
|
-
case POSTING -> AggregationType.AGGREGATION_TYPE_POSTING;
|
|
1777
|
-
};
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
private com.example.accounting.domain.model.account.AggregationType toDomainAggregationType(
|
|
1781
|
-
AggregationType proto) {
|
|
1782
|
-
return switch (proto) {
|
|
1783
|
-
case AGGREGATION_TYPE_HEADING ->
|
|
1784
|
-
com.example.accounting.domain.model.account.AggregationType.HEADING;
|
|
1785
|
-
case AGGREGATION_TYPE_SUMMARY ->
|
|
1786
|
-
com.example.accounting.domain.model.account.AggregationType.SUMMARY;
|
|
1787
|
-
case AGGREGATION_TYPE_POSTING ->
|
|
1788
|
-
com.example.accounting.domain.model.account.AggregationType.POSTING;
|
|
1789
|
-
default -> throw new IllegalArgumentException("Unknown aggregation type: " + proto);
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
// === ユーティリティ ===
|
|
1794
|
-
|
|
1795
|
-
private String nullToEmpty(String value) {
|
|
1796
|
-
return value == null ? "" : value;
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
private String emptyToNull(String value) {
|
|
1800
|
-
return value == null || value.isEmpty() ? null : value;
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
```
|
|
1804
|
-
|
|
1805
|
-
</details>
|
|
1806
|
-
|
|
1807
|
-
---
|
|
1808
|
-
|
|
1809
|
-
## 第 25 章:gRPC インターセプター
|
|
1810
|
-
|
|
1811
|
-
### 25.1 ログインターセプター
|
|
1812
|
-
|
|
1813
|
-
<details>
|
|
1814
|
-
<summary>LoggingInterceptor.java</summary>
|
|
1815
|
-
|
|
1816
|
-
```java
|
|
1817
|
-
package com.example.accounting.infrastructure.in.grpc.interceptor;
|
|
1818
|
-
|
|
1819
|
-
import io.grpc.*;
|
|
1820
|
-
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
|
|
1821
|
-
import org.slf4j.Logger;
|
|
1822
|
-
import org.slf4j.LoggerFactory;
|
|
1823
|
-
import org.slf4j.MDC;
|
|
1824
|
-
|
|
1825
|
-
import java.util.UUID;
|
|
1826
|
-
|
|
1827
|
-
/**
|
|
1828
|
-
* gRPC ログインターセプター
|
|
1829
|
-
*/
|
|
1830
|
-
@GrpcGlobalServerInterceptor
|
|
1831
|
-
public class LoggingInterceptor implements ServerInterceptor {
|
|
1832
|
-
|
|
1833
|
-
private static final Logger log = LoggerFactory.getLogger(LoggingInterceptor.class);
|
|
1834
|
-
|
|
1835
|
-
@Override
|
|
1836
|
-
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
|
1837
|
-
ServerCall<ReqT, RespT> call,
|
|
1838
|
-
Metadata headers,
|
|
1839
|
-
ServerCallHandler<ReqT, RespT> next) {
|
|
1840
|
-
|
|
1841
|
-
String requestId = UUID.randomUUID().toString();
|
|
1842
|
-
String methodName = call.getMethodDescriptor().getFullMethodName();
|
|
1843
|
-
long startTime = System.currentTimeMillis();
|
|
1844
|
-
|
|
1845
|
-
MDC.put("requestId", requestId);
|
|
1846
|
-
log.info("gRPC Request: method={}", methodName);
|
|
1847
|
-
|
|
1848
|
-
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(
|
|
1849
|
-
next.startCall(
|
|
1850
|
-
new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
|
|
1851
|
-
@Override
|
|
1852
|
-
public void close(Status status, Metadata trailers) {
|
|
1853
|
-
long duration = System.currentTimeMillis() - startTime;
|
|
1854
|
-
log.info("gRPC Response: method={}, status={}, duration={}ms",
|
|
1855
|
-
methodName, status.getCode(), duration);
|
|
1856
|
-
MDC.clear();
|
|
1857
|
-
super.close(status, trailers);
|
|
1858
|
-
}
|
|
1859
|
-
},
|
|
1860
|
-
headers
|
|
1861
|
-
)
|
|
1862
|
-
) {
|
|
1863
|
-
@Override
|
|
1864
|
-
public void onMessage(ReqT message) {
|
|
1865
|
-
log.debug("gRPC Request message: {}", message);
|
|
1866
|
-
super.onMessage(message);
|
|
1867
|
-
}
|
|
1868
|
-
};
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
```
|
|
1872
|
-
|
|
1873
|
-
</details>
|
|
1874
|
-
|
|
1875
|
-
### 25.2 例外インターセプター
|
|
1876
|
-
|
|
1877
|
-
<details>
|
|
1878
|
-
<summary>ExceptionInterceptor.java</summary>
|
|
1879
|
-
|
|
1880
|
-
```java
|
|
1881
|
-
package com.example.accounting.infrastructure.in.grpc.interceptor;
|
|
1882
|
-
|
|
1883
|
-
import com.example.accounting.domain.exception.BusinessException;
|
|
1884
|
-
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1885
|
-
import com.example.accounting.domain.exception.ValidationException;
|
|
1886
|
-
import com.example.accounting.domain.exception.BalanceNotMatchException;
|
|
1887
|
-
import io.grpc.*;
|
|
1888
|
-
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
|
|
1889
|
-
import org.slf4j.Logger;
|
|
1890
|
-
import org.slf4j.LoggerFactory;
|
|
1891
|
-
|
|
1892
|
-
/**
|
|
1893
|
-
* gRPC 例外インターセプター
|
|
1894
|
-
*/
|
|
1895
|
-
@GrpcGlobalServerInterceptor
|
|
1896
|
-
public class ExceptionInterceptor implements ServerInterceptor {
|
|
1897
|
-
|
|
1898
|
-
private static final Logger log = LoggerFactory.getLogger(ExceptionInterceptor.class);
|
|
1899
|
-
|
|
1900
|
-
@Override
|
|
1901
|
-
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
|
1902
|
-
ServerCall<ReqT, RespT> call,
|
|
1903
|
-
Metadata headers,
|
|
1904
|
-
ServerCallHandler<ReqT, RespT> next) {
|
|
1905
|
-
|
|
1906
|
-
return new ExceptionHandlingListener<>(
|
|
1907
|
-
next.startCall(call, headers),
|
|
1908
|
-
call
|
|
1909
|
-
);
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
private class ExceptionHandlingListener<ReqT, RespT>
|
|
1913
|
-
extends ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT> {
|
|
1914
|
-
|
|
1915
|
-
private final ServerCall<ReqT, RespT> call;
|
|
1916
|
-
|
|
1917
|
-
protected ExceptionHandlingListener(
|
|
1918
|
-
ServerCall.Listener<ReqT> delegate,
|
|
1919
|
-
ServerCall<ReqT, RespT> call) {
|
|
1920
|
-
super(delegate);
|
|
1921
|
-
this.call = call;
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
@Override
|
|
1925
|
-
public void onHalfClose() {
|
|
1926
|
-
try {
|
|
1927
|
-
super.onHalfClose();
|
|
1928
|
-
} catch (Exception e) {
|
|
1929
|
-
handleException(e);
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1933
|
-
private void handleException(Exception e) {
|
|
1934
|
-
Status status;
|
|
1935
|
-
String message;
|
|
1936
|
-
|
|
1937
|
-
if (e instanceof ResourceNotFoundException) {
|
|
1938
|
-
status = Status.NOT_FOUND;
|
|
1939
|
-
message = e.getMessage();
|
|
1940
|
-
log.warn("Resource not found: {}", message);
|
|
1941
|
-
|
|
1942
|
-
} else if (e instanceof ValidationException) {
|
|
1943
|
-
status = Status.INVALID_ARGUMENT;
|
|
1944
|
-
message = e.getMessage();
|
|
1945
|
-
log.warn("Validation error: {}", message);
|
|
1946
|
-
|
|
1947
|
-
} else if (e instanceof BalanceNotMatchException) {
|
|
1948
|
-
status = Status.FAILED_PRECONDITION;
|
|
1949
|
-
message = e.getMessage();
|
|
1950
|
-
log.warn("Balance not match: {}", message);
|
|
1951
|
-
|
|
1952
|
-
} else if (e instanceof BusinessException) {
|
|
1953
|
-
status = Status.FAILED_PRECONDITION;
|
|
1954
|
-
message = e.getMessage();
|
|
1955
|
-
log.warn("Business rule violation: {}", message);
|
|
1956
|
-
|
|
1957
|
-
} else if (e instanceof IllegalArgumentException) {
|
|
1958
|
-
status = Status.INVALID_ARGUMENT;
|
|
1959
|
-
message = e.getMessage();
|
|
1960
|
-
log.warn("Invalid argument: {}", message);
|
|
1961
|
-
|
|
1962
|
-
} else {
|
|
1963
|
-
status = Status.INTERNAL;
|
|
1964
|
-
message = "内部エラーが発生しました";
|
|
1965
|
-
log.error("Internal error", e);
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
call.close(status.withDescription(message), new Metadata());
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
```
|
|
1973
|
-
|
|
1974
|
-
</details>
|
|
1975
|
-
|
|
1976
|
-
---
|
|
1977
|
-
|
|
1978
|
-
## 第 26 章:動作確認とテスト
|
|
1979
|
-
|
|
1980
|
-
### 26.1 grpcurl による動作確認
|
|
1981
|
-
|
|
1982
|
-
```bash
|
|
1983
|
-
# サーバー起動確認(リフレクションサービス経由)
|
|
1984
|
-
grpcurl -plaintext localhost:9090 list
|
|
1985
|
-
|
|
1986
|
-
# 勘定科目サービスのメソッド一覧
|
|
1987
|
-
grpcurl -plaintext localhost:9090 list com.example.accounting.AccountService
|
|
1988
|
-
|
|
1989
|
-
# 勘定科目取得
|
|
1990
|
-
grpcurl -plaintext -d '{"account_code": "1110"}' \
|
|
1991
|
-
localhost:9090 com.example.accounting.AccountService/GetAccount
|
|
1992
|
-
|
|
1993
|
-
# 勘定科目登録
|
|
1994
|
-
grpcurl -plaintext -d '{
|
|
1995
|
-
"account_code": "1111",
|
|
1996
|
-
"account_name": "普通預金(みずほ銀行)",
|
|
1997
|
-
"bspl_type": "BSPL_TYPE_BS",
|
|
1998
|
-
"debit_credit_type": "DEBIT_CREDIT_TYPE_DEBIT",
|
|
1999
|
-
"element_type": "ELEMENT_TYPE_ASSET",
|
|
2000
|
-
"aggregation_type": "AGGREGATION_TYPE_POSTING",
|
|
2001
|
-
"parent_account_code": "1110",
|
|
2002
|
-
"display_order": 10
|
|
2003
|
-
}' localhost:9090 com.example.accounting.AccountService/CreateAccount
|
|
2004
|
-
|
|
2005
|
-
# 勘定科目一覧取得(ストリーミング)
|
|
2006
|
-
grpcurl -plaintext -d '{
|
|
2007
|
-
"bspl_type": "BSPL_TYPE_BS",
|
|
2008
|
-
"active_only": true
|
|
2009
|
-
}' localhost:9090 com.example.accounting.AccountService/ListAccounts
|
|
2010
|
-
|
|
2011
|
-
# 仕訳登録
|
|
2012
|
-
grpcurl -plaintext -d '{
|
|
2013
|
-
"journal_date": {"year": 2025, "month": 1, "day": 15},
|
|
2014
|
-
"summary": "売上計上",
|
|
2015
|
-
"journal_type": "JOURNAL_TYPE_NORMAL",
|
|
2016
|
-
"details": [{
|
|
2017
|
-
"line_number": 1,
|
|
2018
|
-
"line_summary": "A社への売上",
|
|
2019
|
-
"debit_credit_details": [
|
|
2020
|
-
{
|
|
2021
|
-
"debit_credit_type": "DEBIT_CREDIT_TYPE_DEBIT",
|
|
2022
|
-
"account_code": "1310",
|
|
2023
|
-
"amount": {"units": 110000, "currency": "JPY"}
|
|
2024
|
-
},
|
|
2025
|
-
{
|
|
2026
|
-
"debit_credit_type": "DEBIT_CREDIT_TYPE_CREDIT",
|
|
2027
|
-
"account_code": "4100",
|
|
2028
|
-
"amount": {"units": 100000, "currency": "JPY"}
|
|
2029
|
-
},
|
|
2030
|
-
{
|
|
2031
|
-
"debit_credit_type": "DEBIT_CREDIT_TYPE_CREDIT",
|
|
2032
|
-
"account_code": "2110",
|
|
2033
|
-
"amount": {"units": 10000, "currency": "JPY"}
|
|
2034
|
-
}
|
|
2035
|
-
]
|
|
2036
|
-
}]
|
|
2037
|
-
}' localhost:9090 com.example.accounting.JournalService/CreateJournal
|
|
2038
|
-
|
|
2039
|
-
# ヘルスチェック
|
|
2040
|
-
grpcurl -plaintext localhost:9090 grpc.health.v1.Health/Check
|
|
2041
|
-
```
|
|
2042
|
-
|
|
2043
|
-
### 26.2 統合テスト
|
|
2044
|
-
|
|
2045
|
-
<details>
|
|
2046
|
-
<summary>GrpcAccountServiceTest.java</summary>
|
|
2047
|
-
|
|
2048
|
-
```java
|
|
2049
|
-
package com.example.accounting.infrastructure.in.grpc.service;
|
|
2050
|
-
|
|
2051
|
-
import com.example.accounting.application.port.in.AccountUseCase;
|
|
2052
|
-
import com.example.accounting.domain.model.account.*;
|
|
2053
|
-
import com.example.accounting.infrastructure.in.grpc.converter.AccountConverter;
|
|
2054
|
-
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
2055
|
-
import io.grpc.StatusRuntimeException;
|
|
2056
|
-
import net.devh.boot.grpc.client.inject.GrpcClient;
|
|
2057
|
-
import org.junit.jupiter.api.*;
|
|
2058
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
2059
|
-
import org.springframework.boot.test.context.SpringBootTest;
|
|
2060
|
-
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
2061
|
-
import org.springframework.test.context.ActiveProfiles;
|
|
2062
|
-
|
|
2063
|
-
import java.util.Iterator;
|
|
2064
|
-
import java.util.List;
|
|
2065
|
-
import java.util.Optional;
|
|
2066
|
-
|
|
2067
|
-
import static org.assertj.core.api.Assertions.*;
|
|
2068
|
-
import static org.mockito.ArgumentMatchers.any;
|
|
2069
|
-
import static org.mockito.Mockito.*;
|
|
2070
|
-
|
|
2071
|
-
@SpringBootTest(properties = {
|
|
2072
|
-
"grpc.server.port=9091",
|
|
2073
|
-
"grpc.server.in-process-name=test"
|
|
2074
|
-
})
|
|
2075
|
-
@ActiveProfiles("test")
|
|
2076
|
-
class GrpcAccountServiceTest {
|
|
2077
|
-
|
|
2078
|
-
@MockBean
|
|
2079
|
-
private AccountUseCase accountUseCase;
|
|
2080
|
-
|
|
2081
|
-
@GrpcClient("inProcess")
|
|
2082
|
-
private AccountServiceGrpc.AccountServiceBlockingStub blockingStub;
|
|
2083
|
-
|
|
2084
|
-
private Account sampleAccount;
|
|
2085
|
-
|
|
2086
|
-
@BeforeEach
|
|
2087
|
-
void setUp() {
|
|
2088
|
-
sampleAccount = Account.builder()
|
|
2089
|
-
.accountCode(new AccountCode("1110"))
|
|
2090
|
-
.accountName("現金")
|
|
2091
|
-
.bsplType(com.example.accounting.domain.model.account.BsplType.BS)
|
|
2092
|
-
.debitCreditType(
|
|
2093
|
-
com.example.accounting.domain.model.account.DebitCreditType.DEBIT)
|
|
2094
|
-
.elementType(
|
|
2095
|
-
com.example.accounting.domain.model.account.ElementType.ASSET)
|
|
2096
|
-
.aggregationType(
|
|
2097
|
-
com.example.accounting.domain.model.account.AggregationType.POSTING)
|
|
2098
|
-
.isActive(true)
|
|
2099
|
-
.build();
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
|
-
@Test
|
|
2103
|
-
@DisplayName("勘定科目取得 - 存在する科目を取得できること")
|
|
2104
|
-
void getAccount_found() {
|
|
2105
|
-
// Given
|
|
2106
|
-
when(accountUseCase.findByCode(any(AccountCode.class)))
|
|
2107
|
-
.thenReturn(Optional.of(sampleAccount));
|
|
2108
|
-
|
|
2109
|
-
GetAccountRequest request = GetAccountRequest.newBuilder()
|
|
2110
|
-
.setAccountCode("1110")
|
|
2111
|
-
.build();
|
|
2112
|
-
|
|
2113
|
-
// When
|
|
2114
|
-
GetAccountResponse response = blockingStub.getAccount(request);
|
|
2115
|
-
|
|
2116
|
-
// Then
|
|
2117
|
-
assertThat(response.getAccount().getAccountCode()).isEqualTo("1110");
|
|
2118
|
-
assertThat(response.getAccount().getAccountName()).isEqualTo("現金");
|
|
2119
|
-
assertThat(response.getAccount().getBsplType())
|
|
2120
|
-
.isEqualTo(BsplType.BSPL_TYPE_BS);
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
@Test
|
|
2124
|
-
@DisplayName("勘定科目取得 - 存在しない科目は NOT_FOUND")
|
|
2125
|
-
void getAccount_notFound() {
|
|
2126
|
-
// Given
|
|
2127
|
-
when(accountUseCase.findByCode(any(AccountCode.class)))
|
|
2128
|
-
.thenReturn(Optional.empty());
|
|
2129
|
-
|
|
2130
|
-
GetAccountRequest request = GetAccountRequest.newBuilder()
|
|
2131
|
-
.setAccountCode("9999")
|
|
2132
|
-
.build();
|
|
2133
|
-
|
|
2134
|
-
// When & Then
|
|
2135
|
-
assertThatThrownBy(() -> blockingStub.getAccount(request))
|
|
2136
|
-
.isInstanceOf(StatusRuntimeException.class)
|
|
2137
|
-
.satisfies(e -> {
|
|
2138
|
-
StatusRuntimeException sre = (StatusRuntimeException) e;
|
|
2139
|
-
assertThat(sre.getStatus().getCode())
|
|
2140
|
-
.isEqualTo(io.grpc.Status.NOT_FOUND.getCode());
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2144
|
-
@Test
|
|
2145
|
-
@DisplayName("勘定科目一覧取得 - ストリーミングで取得できること")
|
|
2146
|
-
void listAccounts_streaming() {
|
|
2147
|
-
// Given
|
|
2148
|
-
List<Account> accounts = List.of(
|
|
2149
|
-
sampleAccount,
|
|
2150
|
-
Account.builder()
|
|
2151
|
-
.accountCode(new AccountCode("1120"))
|
|
2152
|
-
.accountName("普通預金")
|
|
2153
|
-
.bsplType(com.example.accounting.domain.model.account.BsplType.BS)
|
|
2154
|
-
.debitCreditType(
|
|
2155
|
-
com.example.accounting.domain.model.account.DebitCreditType.DEBIT)
|
|
2156
|
-
.elementType(
|
|
2157
|
-
com.example.accounting.domain.model.account.ElementType.ASSET)
|
|
2158
|
-
.aggregationType(
|
|
2159
|
-
com.example.accounting.domain.model.account.AggregationType.POSTING)
|
|
2160
|
-
.isActive(true)
|
|
2161
|
-
.build()
|
|
2162
|
-
);
|
|
2163
|
-
when(accountUseCase.findAll(any())).thenReturn(accounts);
|
|
2164
|
-
|
|
2165
|
-
ListAccountsRequest request = ListAccountsRequest.newBuilder()
|
|
2166
|
-
.setBsplType(BsplType.BSPL_TYPE_BS)
|
|
2167
|
-
.setActiveOnly(true)
|
|
2168
|
-
.build();
|
|
2169
|
-
|
|
2170
|
-
// When
|
|
2171
|
-
Iterator<com.example.accounting.infrastructure.in.grpc.proto.Account> iterator =
|
|
2172
|
-
blockingStub.listAccounts(request);
|
|
2173
|
-
|
|
2174
|
-
// Then
|
|
2175
|
-
int count = 0;
|
|
2176
|
-
while (iterator.hasNext()) {
|
|
2177
|
-
com.example.accounting.infrastructure.in.grpc.proto.Account account = iterator.next();
|
|
2178
|
-
assertThat(account.getAccountCode()).matches("11\\d+");
|
|
2179
|
-
count++;
|
|
2180
|
-
}
|
|
2181
|
-
assertThat(count).isEqualTo(2);
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
```
|
|
2185
|
-
|
|
2186
|
-
</details>
|
|
2187
|
-
|
|
2188
|
-
---
|
|
2189
|
-
|
|
2190
|
-
## 第 27 章:まとめ
|
|
2191
|
-
|
|
2192
|
-
### 27.1 学習した内容
|
|
2193
|
-
|
|
2194
|
-
1. **gRPC の基本概念**: Protocol Buffers、HTTP/2、4 つの RPC パターン
|
|
2195
|
-
2. **REST/GraphQL との比較**: 用途に応じた適切な選択
|
|
2196
|
-
3. **ヘキサゴナルアーキテクチャとの統合**: Input Adapter として gRPC サービスを追加
|
|
2197
|
-
4. **技術スタック**: grpc-spring-boot-starter、Protocol Buffers
|
|
2198
|
-
5. **Protocol Buffers 定義**: 共通型、勘定科目、仕訳、残高のメッセージとサービス定義
|
|
2199
|
-
6. **gRPC サービス実装**: 単項 RPC、ストリーミング RPC
|
|
2200
|
-
7. **インターセプター**: ログ、例外ハンドリング
|
|
2201
|
-
8. **テスト**: gRPC クライアントを使用した統合テスト
|
|
2202
|
-
|
|
2203
|
-
### 27.2 gRPC が適するユースケース
|
|
2204
|
-
|
|
2205
|
-
| ユースケース | 理由 |
|
|
2206
|
-
|-------------|------|
|
|
2207
|
-
| 基幹システム連携 | 高性能なバイナリ通信 |
|
|
2208
|
-
| 大量仕訳一括登録 | クライアントストリーミング |
|
|
2209
|
-
| リアルタイム残高監視 | 双方向ストリーミング |
|
|
2210
|
-
| 月次締め進捗通知 | サーバーストリーミング |
|
|
2211
|
-
| マイクロサービス間通信 | 型安全な API 定義 |
|
|
2212
|
-
|
|
2213
|
-
### 27.3 API アーキテクチャ選択ガイド
|
|
2214
|
-
|
|
2215
|
-
```plantuml
|
|
2216
|
-
@startuml api_selection
|
|
2217
|
-
!define RECTANGLE class
|
|
2218
|
-
|
|
2219
|
-
skinparam backgroundColor #FEFEFE
|
|
2220
|
-
|
|
2221
|
-
start
|
|
2222
|
-
|
|
2223
|
-
:API が必要;
|
|
2224
|
-
|
|
2225
|
-
if (ブラウザから直接アクセス?) then (はい)
|
|
2226
|
-
if (柔軟なクエリが必要?) then (はい)
|
|
2227
|
-
:GraphQL;
|
|
2228
|
-
else (いいえ)
|
|
2229
|
-
:REST API;
|
|
2230
|
-
endif
|
|
2231
|
-
else (いいえ)
|
|
2232
|
-
if (高性能が必要?) then (はい)
|
|
2233
|
-
:gRPC;
|
|
2234
|
-
else (いいえ)
|
|
2235
|
-
if (ストリーミングが必要?) then (はい)
|
|
2236
|
-
:gRPC;
|
|
2237
|
-
else (いいえ)
|
|
2238
|
-
:REST API;
|
|
2239
|
-
endif
|
|
2240
|
-
endif
|
|
2241
|
-
endif
|
|
2242
|
-
|
|
2243
|
-
stop
|
|
2244
|
-
|
|
2245
|
-
@enduml
|
|
2246
|
-
```
|
|
2247
|
-
|
|
2248
|
-
### 27.4 次のステップ
|
|
2249
|
-
|
|
2250
|
-
- gRPC-Web による Web フロントエンド対応
|
|
2251
|
-
- 認証・認可(JWT トークン検証)
|
|
2252
|
-
- ロードバランシングとサービスメッシュ
|
|
2253
|
-
- Observability(メトリクス、トレーシング)
|
|
1
|
+
# 研究 3:gRPC サービスの実装
|
|
2
|
+
|
|
3
|
+
## はじめに
|
|
4
|
+
|
|
5
|
+
本パートでは、API サーバー構成とは異なるアプローチとして、**gRPC** による財務会計システムを実装します。Protocol Buffers による高効率なバイナリシリアライゼーションと、HTTP/2 によるストリーミング通信を活用し、高性能なマイクロサービス間通信を実現します。
|
|
6
|
+
|
|
7
|
+
ヘキサゴナルアーキテクチャ(ドメイン層・アプリケーション層)はそのまま共有し、**Input Adapter として gRPC サービス層のみを追加**します。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 第 22 章:gRPC サーバーの基礎
|
|
12
|
+
|
|
13
|
+
### 22.1 gRPC とは
|
|
14
|
+
|
|
15
|
+
gRPC は Google が開発したオープンソースの高性能 RPC(Remote Procedure Call)フレームワークです。HTTP/2 プロトコルと Protocol Buffers を基盤とし、マイクロサービス間通信に最適化されています。
|
|
16
|
+
|
|
17
|
+
```plantuml
|
|
18
|
+
@startuml grpc_architecture
|
|
19
|
+
!define RECTANGLE class
|
|
20
|
+
|
|
21
|
+
skinparam backgroundColor #FEFEFE
|
|
22
|
+
|
|
23
|
+
package "gRPC Architecture (財務会計システム)" {
|
|
24
|
+
|
|
25
|
+
package "Client Side" {
|
|
26
|
+
RECTANGLE "gRPC Client\n(Generated Stub)" as client {
|
|
27
|
+
- 単項 RPC
|
|
28
|
+
- サーバーストリーミング
|
|
29
|
+
- クライアントストリーミング
|
|
30
|
+
- 双方向ストリーミング
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
package "Server Side" {
|
|
35
|
+
RECTANGLE "gRPC Server\n(grpc-spring-boot-starter)" as server {
|
|
36
|
+
- AccountService
|
|
37
|
+
- JournalService
|
|
38
|
+
- BalanceService
|
|
39
|
+
- ReportService
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
package "Shared" {
|
|
44
|
+
RECTANGLE "Protocol Buffers\n(.proto files)" as proto {
|
|
45
|
+
- account.proto
|
|
46
|
+
- journal.proto
|
|
47
|
+
- balance.proto
|
|
48
|
+
- common.proto
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
client --> proto : ".proto からスタブ生成"
|
|
54
|
+
server --> proto : ".proto からスケルトン生成"
|
|
55
|
+
client <--> server : "HTTP/2\n(Binary Protocol)"
|
|
56
|
+
|
|
57
|
+
note bottom of proto
|
|
58
|
+
スキーマ駆動開発
|
|
59
|
+
言語中立なインターフェース定義
|
|
60
|
+
高効率なバイナリシリアライゼーション
|
|
61
|
+
end note
|
|
62
|
+
|
|
63
|
+
@enduml
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**gRPC の主な特徴:**
|
|
67
|
+
|
|
68
|
+
| 特徴 | 説明 |
|
|
69
|
+
|------|------|
|
|
70
|
+
| HTTP/2 | 多重化、ヘッダー圧縮、バイナリフレーミング |
|
|
71
|
+
| Protocol Buffers | 高速なバイナリシリアライゼーション |
|
|
72
|
+
| 多言語サポート | Java, Go, Python, C#, Node.js 等 |
|
|
73
|
+
| ストリーミング | 4 つの RPC パターンをサポート |
|
|
74
|
+
| デッドライン | タイムアウト管理の組み込みサポート |
|
|
75
|
+
| 認証 | TLS/SSL、トークンベース認証のサポート |
|
|
76
|
+
|
|
77
|
+
### 22.2 REST API / GraphQL との比較
|
|
78
|
+
|
|
79
|
+
```plantuml
|
|
80
|
+
@startuml api_comparison
|
|
81
|
+
skinparam backgroundColor #FEFEFE
|
|
82
|
+
|
|
83
|
+
rectangle "REST API" as rest {
|
|
84
|
+
(HTTP/1.1 or 2)
|
|
85
|
+
(JSON/XML)
|
|
86
|
+
(OpenAPI)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
rectangle "gRPC" as grpc {
|
|
90
|
+
(HTTP/2)
|
|
91
|
+
(Protocol Buffers)
|
|
92
|
+
(.proto)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
rectangle "GraphQL" as graphql {
|
|
96
|
+
(HTTP/1.1 or 2)
|
|
97
|
+
(JSON)
|
|
98
|
+
(.graphqls)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
note bottom of rest
|
|
102
|
+
汎用性が高い
|
|
103
|
+
ブラウザ直接アクセス可能
|
|
104
|
+
人間が読みやすい
|
|
105
|
+
end note
|
|
106
|
+
|
|
107
|
+
note bottom of grpc
|
|
108
|
+
高性能
|
|
109
|
+
マイクロサービス向け
|
|
110
|
+
型安全
|
|
111
|
+
end note
|
|
112
|
+
|
|
113
|
+
note bottom of graphql
|
|
114
|
+
柔軟なクエリ
|
|
115
|
+
フロントエンド向け
|
|
116
|
+
単一エンドポイント
|
|
117
|
+
end note
|
|
118
|
+
|
|
119
|
+
@enduml
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**詳細比較表:**
|
|
123
|
+
|
|
124
|
+
| 特徴 | REST API | gRPC | GraphQL |
|
|
125
|
+
|------|----------|------|---------|
|
|
126
|
+
| プロトコル | HTTP/1.1 | HTTP/2 | HTTP/1.1 or HTTP/2 |
|
|
127
|
+
| データ形式 | JSON | Protocol Buffers | JSON |
|
|
128
|
+
| スキーマ | OpenAPI (任意) | .proto (必須) | .graphqls (必須) |
|
|
129
|
+
| シリアライゼーション | テキスト | バイナリ | テキスト |
|
|
130
|
+
| パフォーマンス | 中 | 高 | 中 |
|
|
131
|
+
| ストリーミング | WebSocket 別実装 | ネイティブサポート | Subscription |
|
|
132
|
+
| ブラウザ対応 | ◎ | △ (gRPC-Web) | ◎ |
|
|
133
|
+
| 学習コスト | 低 | 中 | 中 |
|
|
134
|
+
| 主な用途 | 汎用 API | マイクロサービス | フロントエンド向け |
|
|
135
|
+
|
|
136
|
+
**財務会計システムで gRPC を選択する場面:**
|
|
137
|
+
|
|
138
|
+
1. **基幹システム間連携**: 販売管理・購買管理との高性能な内部通信
|
|
139
|
+
2. **リアルタイム残高更新**: ストリーミングによる即時反映通知
|
|
140
|
+
3. **一括仕訳処理**: クライアントストリーミングによる大量データ転送
|
|
141
|
+
4. **月次締め処理**: 長時間処理の進捗通知
|
|
142
|
+
|
|
143
|
+
### 22.3 4 つの RPC パターン
|
|
144
|
+
|
|
145
|
+
gRPC は 4 つの RPC パターンをサポートします。
|
|
146
|
+
|
|
147
|
+
```plantuml
|
|
148
|
+
@startuml grpc_patterns
|
|
149
|
+
skinparam backgroundColor #FEFEFE
|
|
150
|
+
|
|
151
|
+
rectangle "1. 単項 RPC (Unary)" as unary {
|
|
152
|
+
(Client) -right-> (Server) : "Request"
|
|
153
|
+
(Server) -left-> (Client) : "Response"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
rectangle "2. サーバーストリーミング RPC" as server_stream {
|
|
157
|
+
(Client2) -right-> (Server2) : "Request"
|
|
158
|
+
(Server2) -left-> (Client2) : "Response 1"
|
|
159
|
+
(Server2) -left-> (Client2) : "Response 2"
|
|
160
|
+
(Server2) -left-> (Client2) : "Response N"
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
rectangle "3. クライアントストリーミング RPC" as client_stream {
|
|
164
|
+
(Client3) -right-> (Server3) : "Request 1"
|
|
165
|
+
(Client3) -right-> (Server3) : "Request 2"
|
|
166
|
+
(Client3) -right-> (Server3) : "Request N"
|
|
167
|
+
(Server3) -left-> (Client3) : "Response"
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
rectangle "4. 双方向ストリーミング RPC" as bidirectional {
|
|
171
|
+
(Client4) <-right-> (Server4) : "Request/Response Stream"
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@enduml
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**各パターンの用途(財務会計システム):**
|
|
178
|
+
|
|
179
|
+
| パターン | 用途例 |
|
|
180
|
+
|----------|---------------------------|
|
|
181
|
+
| 単項 RPC | 勘定科目取得、仕訳登録 |
|
|
182
|
+
| サーバーストリーミング | 仕訳一覧取得、残高照会 |
|
|
183
|
+
| クライアントストリーミング | 仕訳明細の一括登録 |
|
|
184
|
+
| 双方向ストリーミング | リアルタイム残高同期 |
|
|
185
|
+
|
|
186
|
+
### 22.4 gRPC におけるヘキサゴナルアーキテクチャ
|
|
187
|
+
|
|
188
|
+
gRPC を導入しても、ヘキサゴナルアーキテクチャ(ドメイン層・アプリケーション層)はそのまま共有し、**Input Adapter として gRPC サービス層のみを追加**します。
|
|
189
|
+
|
|
190
|
+
```plantuml
|
|
191
|
+
@startuml hexagonal_grpc
|
|
192
|
+
!define RECTANGLE class
|
|
193
|
+
|
|
194
|
+
package "Hexagonal Architecture (gRPC版)" {
|
|
195
|
+
|
|
196
|
+
RECTANGLE "Application Core\n(Domain + Use Cases)" as core {
|
|
197
|
+
- Account (勘定科目)
|
|
198
|
+
- Journal (仕訳)
|
|
199
|
+
- DailyBalance (日次残高)
|
|
200
|
+
- MonthlyBalance (月次残高)
|
|
201
|
+
- AccountUseCase
|
|
202
|
+
- JournalUseCase
|
|
203
|
+
- BalanceUseCase
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
RECTANGLE "Input Adapters\n(Driving Side)" as input {
|
|
207
|
+
- REST Controller(既存)
|
|
208
|
+
- gRPC Service(新規追加)
|
|
209
|
+
- StreamObserver
|
|
210
|
+
- ServerInterceptor
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
RECTANGLE "Output Adapters\n(Driven Side)" as output {
|
|
214
|
+
- MyBatis Repository
|
|
215
|
+
- Database Access
|
|
216
|
+
- Entity Mapping
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
input --> core : "Input Ports\n(Use Cases)"
|
|
221
|
+
core --> output : "Output Ports\n(Repository Interfaces)"
|
|
222
|
+
|
|
223
|
+
note top of core
|
|
224
|
+
既存のビジネスロジック
|
|
225
|
+
REST API 版と完全に共有
|
|
226
|
+
gRPC 固有のコードは含まない
|
|
227
|
+
end note
|
|
228
|
+
|
|
229
|
+
note left of input
|
|
230
|
+
gRPC サービスを
|
|
231
|
+
Input Adapter として追加
|
|
232
|
+
既存の REST と共存可能
|
|
233
|
+
end note
|
|
234
|
+
|
|
235
|
+
note right of output
|
|
236
|
+
既存の Repository を
|
|
237
|
+
そのまま使用
|
|
238
|
+
変更不要
|
|
239
|
+
end note
|
|
240
|
+
|
|
241
|
+
@enduml
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 22.5 ディレクトリ構成
|
|
245
|
+
|
|
246
|
+
既存の構成に `infrastructure/in/grpc/` を追加するだけです。
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
src/main/java/com/example/accounting/
|
|
250
|
+
├── domain/ # ドメイン層(API版と共通)
|
|
251
|
+
│ ├── model/
|
|
252
|
+
│ │ ├── account/ # 勘定科目ドメイン
|
|
253
|
+
│ │ ├── journal/ # 仕訳ドメイン
|
|
254
|
+
│ │ ├── balance/ # 残高ドメイン
|
|
255
|
+
│ │ └── tax/ # 課税取引ドメイン
|
|
256
|
+
│ └── exception/
|
|
257
|
+
│
|
|
258
|
+
├── application/ # アプリケーション層(API版と共通)
|
|
259
|
+
│ ├── port/
|
|
260
|
+
│ │ ├── in/ # Input Port(ユースケース)
|
|
261
|
+
│ │ └── out/ # Output Port(リポジトリ)
|
|
262
|
+
│ └── service/
|
|
263
|
+
│
|
|
264
|
+
├── infrastructure/
|
|
265
|
+
│ ├── in/
|
|
266
|
+
│ │ ├── api/ # Input Adapter(REST実装)- 既存
|
|
267
|
+
│ │ └── grpc/ # Input Adapter(gRPC実装)- 新規追加
|
|
268
|
+
│ │ ├── service/ # gRPC サービス実装
|
|
269
|
+
│ │ ├── interceptor/ # インターセプター
|
|
270
|
+
│ │ └── converter/ # ドメイン ↔ Proto 変換
|
|
271
|
+
│ └── out/
|
|
272
|
+
│ └── persistence/ # Output Adapter(DB実装)- 既存
|
|
273
|
+
│ ├── mapper/
|
|
274
|
+
│ └── repository/
|
|
275
|
+
│
|
|
276
|
+
├── config/
|
|
277
|
+
│
|
|
278
|
+
└── src/main/proto/ # Protocol Buffers 定義
|
|
279
|
+
├── common.proto
|
|
280
|
+
├── account.proto
|
|
281
|
+
├── journal.proto
|
|
282
|
+
├── balance.proto
|
|
283
|
+
└── report.proto
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### 22.6 技術スタックの追加
|
|
287
|
+
|
|
288
|
+
既存の `build.gradle.kts` に gRPC 関連の依存関係を追加します。
|
|
289
|
+
|
|
290
|
+
<details>
|
|
291
|
+
<summary>build.gradle.kts(差分)</summary>
|
|
292
|
+
|
|
293
|
+
```kotlin
|
|
294
|
+
import com.google.protobuf.gradle.*
|
|
295
|
+
|
|
296
|
+
plugins {
|
|
297
|
+
// 既存のプラグイン
|
|
298
|
+
id("java")
|
|
299
|
+
id("org.springframework.boot") version "3.2.0"
|
|
300
|
+
id("io.spring.dependency-management") version "1.1.4"
|
|
301
|
+
|
|
302
|
+
// gRPC 関連を追加
|
|
303
|
+
id("com.google.protobuf") version "0.9.4"
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
dependencies {
|
|
307
|
+
// 既存の依存関係(Spring Boot, MyBatis, PostgreSQL等)はそのまま
|
|
308
|
+
|
|
309
|
+
// gRPC 関連を追加
|
|
310
|
+
implementation("net.devh:grpc-spring-boot-starter:3.1.0.RELEASE")
|
|
311
|
+
implementation("io.grpc:grpc-protobuf:1.62.2")
|
|
312
|
+
implementation("io.grpc:grpc-stub:1.62.2")
|
|
313
|
+
implementation("io.grpc:grpc-services:1.62.2") // ヘルスチェック、リフレクション
|
|
314
|
+
|
|
315
|
+
// Protocol Buffers
|
|
316
|
+
implementation("com.google.protobuf:protobuf-java:3.25.3")
|
|
317
|
+
implementation("com.google.protobuf:protobuf-java-util:3.25.3") // JSON 変換
|
|
318
|
+
|
|
319
|
+
// Jakarta Annotation (gRPC generated code で必要)
|
|
320
|
+
compileOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
|
|
321
|
+
|
|
322
|
+
// Test
|
|
323
|
+
testImplementation("io.grpc:grpc-testing:1.62.2")
|
|
324
|
+
testImplementation("net.devh:grpc-client-spring-boot-starter:3.1.0.RELEASE")
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
protobuf {
|
|
328
|
+
protoc {
|
|
329
|
+
artifact = "com.google.protobuf:protoc:3.25.3"
|
|
330
|
+
}
|
|
331
|
+
plugins {
|
|
332
|
+
create("grpc") {
|
|
333
|
+
artifact = "io.grpc:protoc-gen-grpc-java:1.62.2"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
generateProtoTasks {
|
|
337
|
+
all().forEach { task ->
|
|
338
|
+
task.plugins {
|
|
339
|
+
create("grpc")
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 生成コードのソースパス追加
|
|
346
|
+
sourceSets {
|
|
347
|
+
main {
|
|
348
|
+
java {
|
|
349
|
+
srcDirs(
|
|
350
|
+
"build/generated/source/proto/main/java",
|
|
351
|
+
"build/generated/source/proto/main/grpc"
|
|
352
|
+
)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
</details>
|
|
359
|
+
|
|
360
|
+
<details>
|
|
361
|
+
<summary>application.yml(差分)</summary>
|
|
362
|
+
|
|
363
|
+
```yaml
|
|
364
|
+
# 既存の設定はそのまま
|
|
365
|
+
|
|
366
|
+
# gRPC サーバー設定
|
|
367
|
+
grpc:
|
|
368
|
+
server:
|
|
369
|
+
port: 9090
|
|
370
|
+
reflection-service-enabled: true # gRPC リフレクション有効化
|
|
371
|
+
health-service-enabled: true # ヘルスチェック有効化
|
|
372
|
+
max-inbound-message-size: 4194304 # 4MB
|
|
373
|
+
max-inbound-metadata-size: 8192 # 8KB
|
|
374
|
+
|
|
375
|
+
# ログ設定
|
|
376
|
+
logging:
|
|
377
|
+
level:
|
|
378
|
+
net.devh.boot.grpc: DEBUG
|
|
379
|
+
io.grpc: INFO
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
</details>
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## 第 23 章:Protocol Buffers 定義
|
|
387
|
+
|
|
388
|
+
### 23.1 共通メッセージ定義
|
|
389
|
+
|
|
390
|
+
<details>
|
|
391
|
+
<summary>src/main/proto/common.proto</summary>
|
|
392
|
+
|
|
393
|
+
```protobuf
|
|
394
|
+
syntax = "proto3";
|
|
395
|
+
|
|
396
|
+
package com.example.accounting;
|
|
397
|
+
|
|
398
|
+
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
399
|
+
option java_outer_classname = "CommonProto";
|
|
400
|
+
option java_multiple_files = true;
|
|
401
|
+
|
|
402
|
+
import "google/protobuf/timestamp.proto";
|
|
403
|
+
import "google/protobuf/wrappers.proto";
|
|
404
|
+
|
|
405
|
+
// 共通のページネーション
|
|
406
|
+
message PageRequest {
|
|
407
|
+
int32 page = 1;
|
|
408
|
+
int32 size = 2;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
message PageInfo {
|
|
412
|
+
int32 page = 1;
|
|
413
|
+
int32 size = 2;
|
|
414
|
+
int32 total_elements = 3;
|
|
415
|
+
int32 total_pages = 4;
|
|
416
|
+
bool has_next = 5;
|
|
417
|
+
bool has_previous = 6;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 共通のエラー応答
|
|
421
|
+
message ErrorDetail {
|
|
422
|
+
string field = 1;
|
|
423
|
+
string message = 2;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
message ErrorResponse {
|
|
427
|
+
string code = 1;
|
|
428
|
+
string message = 2;
|
|
429
|
+
repeated ErrorDetail details = 3;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// 金額型(Decimal 相当)
|
|
433
|
+
message Money {
|
|
434
|
+
int64 units = 1; // 整数部
|
|
435
|
+
int32 nanos = 2; // 小数部(10億分の1単位)
|
|
436
|
+
string currency = 3; // 通貨コード(JPY等)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// 日付型(Date 相当)
|
|
440
|
+
message Date {
|
|
441
|
+
int32 year = 1;
|
|
442
|
+
int32 month = 2;
|
|
443
|
+
int32 day = 3;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// 年月型
|
|
447
|
+
message YearMonth {
|
|
448
|
+
int32 year = 1;
|
|
449
|
+
int32 month = 2;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// 決算期
|
|
453
|
+
message FiscalPeriod {
|
|
454
|
+
int32 fiscal_year = 1; // 決算年度
|
|
455
|
+
int32 fiscal_month = 2; // 決算月度(1-12)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// 監査情報
|
|
459
|
+
message AuditInfo {
|
|
460
|
+
google.protobuf.Timestamp created_at = 1;
|
|
461
|
+
string created_by = 2;
|
|
462
|
+
google.protobuf.Timestamp updated_at = 3;
|
|
463
|
+
string updated_by = 4;
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
</details>
|
|
468
|
+
|
|
469
|
+
### 23.2 勘定科目 Protocol Buffers
|
|
470
|
+
|
|
471
|
+
<details>
|
|
472
|
+
<summary>src/main/proto/account.proto</summary>
|
|
473
|
+
|
|
474
|
+
```protobuf
|
|
475
|
+
syntax = "proto3";
|
|
476
|
+
|
|
477
|
+
package com.example.accounting;
|
|
478
|
+
|
|
479
|
+
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
480
|
+
option java_outer_classname = "AccountProto";
|
|
481
|
+
option java_multiple_files = true;
|
|
482
|
+
|
|
483
|
+
import "common.proto";
|
|
484
|
+
import "google/protobuf/empty.proto";
|
|
485
|
+
|
|
486
|
+
// BSPL区分
|
|
487
|
+
enum BsplType {
|
|
488
|
+
BSPL_TYPE_UNSPECIFIED = 0;
|
|
489
|
+
BSPL_TYPE_BS = 1; // 貸借対照表
|
|
490
|
+
BSPL_TYPE_PL = 2; // 損益計算書
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// 貸借区分
|
|
494
|
+
enum DebitCreditType {
|
|
495
|
+
DEBIT_CREDIT_TYPE_UNSPECIFIED = 0;
|
|
496
|
+
DEBIT_CREDIT_TYPE_DEBIT = 1; // 借方
|
|
497
|
+
DEBIT_CREDIT_TYPE_CREDIT = 2; // 貸方
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// 取引要素区分
|
|
501
|
+
enum ElementType {
|
|
502
|
+
ELEMENT_TYPE_UNSPECIFIED = 0;
|
|
503
|
+
ELEMENT_TYPE_ASSET = 1; // 資産
|
|
504
|
+
ELEMENT_TYPE_LIABILITY = 2; // 負債
|
|
505
|
+
ELEMENT_TYPE_EQUITY = 3; // 資本
|
|
506
|
+
ELEMENT_TYPE_REVENUE = 4; // 収益
|
|
507
|
+
ELEMENT_TYPE_EXPENSE = 5; // 費用
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 集計区分
|
|
511
|
+
enum AggregationType {
|
|
512
|
+
AGGREGATION_TYPE_UNSPECIFIED = 0;
|
|
513
|
+
AGGREGATION_TYPE_HEADING = 1; // 見出科目
|
|
514
|
+
AGGREGATION_TYPE_SUMMARY = 2; // 集計科目
|
|
515
|
+
AGGREGATION_TYPE_POSTING = 3; // 計上科目
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// 勘定科目メッセージ
|
|
519
|
+
message Account {
|
|
520
|
+
string account_code = 1; // 勘定科目コード
|
|
521
|
+
string account_name = 2; // 勘定科目名
|
|
522
|
+
BsplType bspl_type = 3; // BSPL区分
|
|
523
|
+
DebitCreditType debit_credit_type = 4; // 貸借区分
|
|
524
|
+
ElementType element_type = 5; // 取引要素区分
|
|
525
|
+
AggregationType aggregation_type = 6; // 集計区分
|
|
526
|
+
string parent_account_code = 7; // 親勘定科目コード
|
|
527
|
+
string account_path = 8; // 勘定科目パス
|
|
528
|
+
int32 display_order = 9; // 表示順
|
|
529
|
+
bool is_active = 10; // 有効フラグ
|
|
530
|
+
AuditInfo audit = 11; // 監査情報
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// 勘定科目構成メッセージ
|
|
534
|
+
message AccountStructure {
|
|
535
|
+
string account_code = 1; // 勘定科目コード
|
|
536
|
+
string account_path = 2; // 勘定科目パス(~区切り)
|
|
537
|
+
int32 level = 3; // 階層レベル
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// 課税取引マスタ
|
|
541
|
+
message TaxTransaction {
|
|
542
|
+
string tax_code = 1; // 課税取引コード
|
|
543
|
+
string tax_name = 2; // 課税取引名
|
|
544
|
+
int32 tax_rate = 3; // 税率(パーセント * 100)
|
|
545
|
+
Date effective_from = 4; // 適用開始日
|
|
546
|
+
Date effective_to = 5; // 適用終了日
|
|
547
|
+
bool is_active = 6; // 有効フラグ
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// === リクエスト/レスポンス ===
|
|
551
|
+
|
|
552
|
+
// 勘定科目取得
|
|
553
|
+
message GetAccountRequest {
|
|
554
|
+
string account_code = 1;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
message GetAccountResponse {
|
|
558
|
+
Account account = 1;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// 勘定科目一覧取得
|
|
562
|
+
message ListAccountsRequest {
|
|
563
|
+
PageRequest page = 1;
|
|
564
|
+
BsplType bspl_type = 2; // フィルタ(オプション)
|
|
565
|
+
ElementType element_type = 3; // フィルタ(オプション)
|
|
566
|
+
AggregationType aggregation_type = 4; // フィルタ(オプション)
|
|
567
|
+
string keyword = 5; // 検索キーワード
|
|
568
|
+
bool active_only = 6; // 有効のみ
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
message ListAccountsResponse {
|
|
572
|
+
repeated Account accounts = 1;
|
|
573
|
+
PageInfo page_info = 2;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// 勘定科目登録
|
|
577
|
+
message CreateAccountRequest {
|
|
578
|
+
string account_code = 1;
|
|
579
|
+
string account_name = 2;
|
|
580
|
+
BsplType bspl_type = 3;
|
|
581
|
+
DebitCreditType debit_credit_type = 4;
|
|
582
|
+
ElementType element_type = 5;
|
|
583
|
+
AggregationType aggregation_type = 6;
|
|
584
|
+
string parent_account_code = 7;
|
|
585
|
+
int32 display_order = 8;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
message CreateAccountResponse {
|
|
589
|
+
Account account = 1;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// 勘定科目更新
|
|
593
|
+
message UpdateAccountRequest {
|
|
594
|
+
string account_code = 1;
|
|
595
|
+
string account_name = 2;
|
|
596
|
+
BsplType bspl_type = 3;
|
|
597
|
+
DebitCreditType debit_credit_type = 4;
|
|
598
|
+
ElementType element_type = 5;
|
|
599
|
+
AggregationType aggregation_type = 6;
|
|
600
|
+
string parent_account_code = 7;
|
|
601
|
+
int32 display_order = 8;
|
|
602
|
+
bool is_active = 9;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
message UpdateAccountResponse {
|
|
606
|
+
Account account = 1;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// 勘定科目削除
|
|
610
|
+
message DeleteAccountRequest {
|
|
611
|
+
string account_code = 1;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
message DeleteAccountResponse {
|
|
615
|
+
bool success = 1;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// 勘定科目一括登録(クライアントストリーミング)
|
|
619
|
+
message BulkCreateAccountRequest {
|
|
620
|
+
CreateAccountRequest account = 1;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
message BulkCreateAccountResponse {
|
|
624
|
+
int32 success_count = 1;
|
|
625
|
+
int32 failure_count = 2;
|
|
626
|
+
repeated ErrorDetail errors = 3;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// 勘定科目ツリー取得
|
|
630
|
+
message GetAccountTreeRequest {
|
|
631
|
+
BsplType bspl_type = 1; // BS または PL
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
message GetAccountTreeResponse {
|
|
635
|
+
repeated AccountNode nodes = 1;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
message AccountNode {
|
|
639
|
+
Account account = 1;
|
|
640
|
+
repeated AccountNode children = 2;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// 課税取引マスタ取得
|
|
644
|
+
message GetTaxTransactionRequest {
|
|
645
|
+
string tax_code = 1;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
message GetTaxTransactionResponse {
|
|
649
|
+
TaxTransaction tax_transaction = 1;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// 課税取引マスタ一覧
|
|
653
|
+
message ListTaxTransactionsRequest {
|
|
654
|
+
Date as_of_date = 1; // 適用日(オプション)
|
|
655
|
+
bool active_only = 2;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
message ListTaxTransactionsResponse {
|
|
659
|
+
repeated TaxTransaction tax_transactions = 1;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// === サービス定義 ===
|
|
663
|
+
|
|
664
|
+
service AccountService {
|
|
665
|
+
// 単項 RPC
|
|
666
|
+
rpc GetAccount(GetAccountRequest) returns (GetAccountResponse);
|
|
667
|
+
rpc CreateAccount(CreateAccountRequest) returns (CreateAccountResponse);
|
|
668
|
+
rpc UpdateAccount(UpdateAccountRequest) returns (UpdateAccountResponse);
|
|
669
|
+
rpc DeleteAccount(DeleteAccountRequest) returns (DeleteAccountResponse);
|
|
670
|
+
|
|
671
|
+
// サーバーストリーミング RPC(大量データ取得)
|
|
672
|
+
rpc ListAccounts(ListAccountsRequest) returns (stream Account);
|
|
673
|
+
|
|
674
|
+
// クライアントストリーミング RPC(一括登録)
|
|
675
|
+
rpc BulkCreateAccounts(stream BulkCreateAccountRequest) returns (BulkCreateAccountResponse);
|
|
676
|
+
|
|
677
|
+
// 勘定科目構成
|
|
678
|
+
rpc GetAccountTree(GetAccountTreeRequest) returns (GetAccountTreeResponse);
|
|
679
|
+
|
|
680
|
+
// 課税取引マスタ
|
|
681
|
+
rpc GetTaxTransaction(GetTaxTransactionRequest) returns (GetTaxTransactionResponse);
|
|
682
|
+
rpc ListTaxTransactions(ListTaxTransactionsRequest) returns (ListTaxTransactionsResponse);
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
</details>
|
|
687
|
+
|
|
688
|
+
### 23.3 仕訳 Protocol Buffers
|
|
689
|
+
|
|
690
|
+
<details>
|
|
691
|
+
<summary>src/main/proto/journal.proto</summary>
|
|
692
|
+
|
|
693
|
+
```protobuf
|
|
694
|
+
syntax = "proto3";
|
|
695
|
+
|
|
696
|
+
package com.example.accounting;
|
|
697
|
+
|
|
698
|
+
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
699
|
+
option java_outer_classname = "JournalProto";
|
|
700
|
+
option java_multiple_files = true;
|
|
701
|
+
|
|
702
|
+
import "common.proto";
|
|
703
|
+
import "account.proto";
|
|
704
|
+
import "google/protobuf/empty.proto";
|
|
705
|
+
|
|
706
|
+
// 仕訳伝票区分
|
|
707
|
+
enum JournalType {
|
|
708
|
+
JOURNAL_TYPE_UNSPECIFIED = 0;
|
|
709
|
+
JOURNAL_TYPE_NORMAL = 1; // 通常仕訳
|
|
710
|
+
JOURNAL_TYPE_CLOSING = 2; // 決算仕訳
|
|
711
|
+
JOURNAL_TYPE_ADJUSTMENT = 3; // 調整仕訳
|
|
712
|
+
JOURNAL_TYPE_REVERSAL = 4; // 取消仕訳
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// 仕訳ステータス
|
|
716
|
+
enum JournalStatus {
|
|
717
|
+
JOURNAL_STATUS_UNSPECIFIED = 0;
|
|
718
|
+
JOURNAL_STATUS_DRAFT = 1; // 下書き
|
|
719
|
+
JOURNAL_STATUS_PENDING = 2; // 承認待ち
|
|
720
|
+
JOURNAL_STATUS_APPROVED = 3; // 承認済み
|
|
721
|
+
JOURNAL_STATUS_POSTED = 4; // 転記済み
|
|
722
|
+
JOURNAL_STATUS_CANCELED = 5; // 取消済み
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// 仕訳伝票メッセージ
|
|
726
|
+
message Journal {
|
|
727
|
+
string slip_number = 1; // 伝票番号
|
|
728
|
+
Date journal_date = 2; // 起票日
|
|
729
|
+
Date input_date = 3; // 入力日
|
|
730
|
+
string summary = 4; // 伝票摘要
|
|
731
|
+
JournalType journal_type = 5; // 仕訳伝票区分
|
|
732
|
+
JournalStatus status = 6; // ステータス
|
|
733
|
+
bool is_closing_journal = 7; // 決算仕訳フラグ
|
|
734
|
+
FiscalPeriod fiscal_period = 8; // 決算期
|
|
735
|
+
Money total_debit = 9; // 借方合計
|
|
736
|
+
Money total_credit = 10; // 貸方合計
|
|
737
|
+
repeated JournalDetail details = 11; // 仕訳明細
|
|
738
|
+
string reversal_slip_number = 12; // 取消元伝票番号
|
|
739
|
+
AuditInfo audit = 13; // 監査情報
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// 仕訳明細メッセージ
|
|
743
|
+
message JournalDetail {
|
|
744
|
+
int32 line_number = 1; // 行番号
|
|
745
|
+
string line_summary = 2; // 行摘要
|
|
746
|
+
repeated JournalDebitCreditDetail debit_credit_details = 3; // 貸借明細
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// 仕訳貸借明細メッセージ
|
|
750
|
+
message JournalDebitCreditDetail {
|
|
751
|
+
DebitCreditType debit_credit_type = 1; // 借方/貸方
|
|
752
|
+
string account_code = 2; // 勘定科目コード
|
|
753
|
+
string account_name = 3; // 勘定科目名(参照用)
|
|
754
|
+
string sub_account_code = 4; // 補助科目コード
|
|
755
|
+
string department_code = 5; // 部門コード
|
|
756
|
+
string project_code = 6; // プロジェクトコード
|
|
757
|
+
Money amount = 7; // 金額
|
|
758
|
+
Money base_currency_amount = 8; // 基軸通貨金額
|
|
759
|
+
string tax_code = 9; // 課税取引コード
|
|
760
|
+
int32 tax_rate = 10; // 税率
|
|
761
|
+
Money tax_amount = 11; // 消費税額
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// === リクエスト/レスポンス ===
|
|
765
|
+
|
|
766
|
+
// 仕訳取得
|
|
767
|
+
message GetJournalRequest {
|
|
768
|
+
string slip_number = 1;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
message GetJournalResponse {
|
|
772
|
+
Journal journal = 1;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// 仕訳一覧取得
|
|
776
|
+
message ListJournalsRequest {
|
|
777
|
+
PageRequest page = 1;
|
|
778
|
+
Date date_from = 2; // 起票日From
|
|
779
|
+
Date date_to = 3; // 起票日To
|
|
780
|
+
FiscalPeriod fiscal_period = 4; // 決算期
|
|
781
|
+
JournalType journal_type = 5; // 仕訳伝票区分
|
|
782
|
+
JournalStatus status = 6; // ステータス
|
|
783
|
+
string account_code = 7; // 勘定科目コード
|
|
784
|
+
string keyword = 8; // 検索キーワード
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
message ListJournalsResponse {
|
|
788
|
+
repeated Journal journals = 1;
|
|
789
|
+
PageInfo page_info = 2;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// 仕訳登録
|
|
793
|
+
message CreateJournalRequest {
|
|
794
|
+
Date journal_date = 1;
|
|
795
|
+
string summary = 2;
|
|
796
|
+
JournalType journal_type = 3;
|
|
797
|
+
bool is_closing_journal = 4;
|
|
798
|
+
repeated CreateJournalDetailRequest details = 5;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
message CreateJournalDetailRequest {
|
|
802
|
+
int32 line_number = 1;
|
|
803
|
+
string line_summary = 2;
|
|
804
|
+
repeated CreateJournalDebitCreditRequest debit_credit_details = 3;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
message CreateJournalDebitCreditRequest {
|
|
808
|
+
DebitCreditType debit_credit_type = 1;
|
|
809
|
+
string account_code = 2;
|
|
810
|
+
string sub_account_code = 3;
|
|
811
|
+
string department_code = 4;
|
|
812
|
+
string project_code = 5;
|
|
813
|
+
Money amount = 6;
|
|
814
|
+
string tax_code = 7;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
message CreateJournalResponse {
|
|
818
|
+
Journal journal = 1;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// 仕訳更新
|
|
822
|
+
message UpdateJournalRequest {
|
|
823
|
+
string slip_number = 1;
|
|
824
|
+
Date journal_date = 2;
|
|
825
|
+
string summary = 3;
|
|
826
|
+
JournalType journal_type = 4;
|
|
827
|
+
bool is_closing_journal = 5;
|
|
828
|
+
repeated CreateJournalDetailRequest details = 6;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
message UpdateJournalResponse {
|
|
832
|
+
Journal journal = 1;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// 仕訳取消(赤黒処理)
|
|
836
|
+
message CancelJournalRequest {
|
|
837
|
+
string slip_number = 1;
|
|
838
|
+
string cancel_reason = 2;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
message CancelJournalResponse {
|
|
842
|
+
Journal original_journal = 1; // 元の仕訳
|
|
843
|
+
Journal reversal_journal = 2; // 取消仕訳
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// 仕訳承認
|
|
847
|
+
message ApproveJournalRequest {
|
|
848
|
+
string slip_number = 1;
|
|
849
|
+
string approver_comment = 2;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
message ApproveJournalResponse {
|
|
853
|
+
Journal journal = 1;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// 仕訳一括登録(クライアントストリーミング)
|
|
857
|
+
message BulkCreateJournalRequest {
|
|
858
|
+
CreateJournalRequest journal = 1;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
message BulkCreateJournalResponse {
|
|
862
|
+
int32 success_count = 1;
|
|
863
|
+
int32 failure_count = 2;
|
|
864
|
+
repeated ErrorDetail errors = 3;
|
|
865
|
+
repeated string created_slip_numbers = 4;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// 貸借バランスチェック
|
|
869
|
+
message ValidateBalanceRequest {
|
|
870
|
+
repeated CreateJournalDetailRequest details = 1;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
message ValidateBalanceResponse {
|
|
874
|
+
bool is_balanced = 1;
|
|
875
|
+
Money total_debit = 2;
|
|
876
|
+
Money total_credit = 3;
|
|
877
|
+
Money difference = 4;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// === サービス定義 ===
|
|
881
|
+
|
|
882
|
+
service JournalService {
|
|
883
|
+
// 単項 RPC
|
|
884
|
+
rpc GetJournal(GetJournalRequest) returns (GetJournalResponse);
|
|
885
|
+
rpc CreateJournal(CreateJournalRequest) returns (CreateJournalResponse);
|
|
886
|
+
rpc UpdateJournal(UpdateJournalRequest) returns (UpdateJournalResponse);
|
|
887
|
+
rpc CancelJournal(CancelJournalRequest) returns (CancelJournalResponse);
|
|
888
|
+
rpc ApproveJournal(ApproveJournalRequest) returns (ApproveJournalResponse);
|
|
889
|
+
rpc ValidateBalance(ValidateBalanceRequest) returns (ValidateBalanceResponse);
|
|
890
|
+
|
|
891
|
+
// サーバーストリーミング RPC
|
|
892
|
+
rpc ListJournals(ListJournalsRequest) returns (stream Journal);
|
|
893
|
+
|
|
894
|
+
// クライアントストリーミング RPC
|
|
895
|
+
rpc BulkCreateJournals(stream BulkCreateJournalRequest) returns (BulkCreateJournalResponse);
|
|
896
|
+
|
|
897
|
+
// 双方向ストリーミング RPC(リアルタイム仕訳入力)
|
|
898
|
+
rpc StreamJournalEntry(stream CreateJournalRequest) returns (stream CreateJournalResponse);
|
|
899
|
+
}
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
</details>
|
|
903
|
+
|
|
904
|
+
### 23.4 残高 Protocol Buffers
|
|
905
|
+
|
|
906
|
+
<details>
|
|
907
|
+
<summary>src/main/proto/balance.proto</summary>
|
|
908
|
+
|
|
909
|
+
```protobuf
|
|
910
|
+
syntax = "proto3";
|
|
911
|
+
|
|
912
|
+
package com.example.accounting;
|
|
913
|
+
|
|
914
|
+
option java_package = "com.example.accounting.infrastructure.in.grpc.proto";
|
|
915
|
+
option java_outer_classname = "BalanceProto";
|
|
916
|
+
option java_multiple_files = true;
|
|
917
|
+
|
|
918
|
+
import "common.proto";
|
|
919
|
+
import "account.proto";
|
|
920
|
+
|
|
921
|
+
// 日次勘定科目残高
|
|
922
|
+
message DailyBalance {
|
|
923
|
+
Date balance_date = 1; // 残高日
|
|
924
|
+
string account_code = 2; // 勘定科目コード
|
|
925
|
+
string account_name = 3; // 勘定科目名
|
|
926
|
+
string sub_account_code = 4; // 補助科目コード
|
|
927
|
+
string department_code = 5; // 部門コード
|
|
928
|
+
Money previous_balance = 6; // 前日残高
|
|
929
|
+
Money debit_amount = 7; // 借方金額
|
|
930
|
+
Money credit_amount = 8; // 貸方金額
|
|
931
|
+
Money current_balance = 9; // 当日残高
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// 月次勘定科目残高
|
|
935
|
+
message MonthlyBalance {
|
|
936
|
+
FiscalPeriod fiscal_period = 1; // 決算期
|
|
937
|
+
string account_code = 2; // 勘定科目コード
|
|
938
|
+
string account_name = 3; // 勘定科目名
|
|
939
|
+
string sub_account_code = 4; // 補助科目コード
|
|
940
|
+
string department_code = 5; // 部門コード
|
|
941
|
+
Money opening_balance = 6; // 月初残高
|
|
942
|
+
Money debit_amount = 7; // 借方金額
|
|
943
|
+
Money credit_amount = 8; // 貸方金額
|
|
944
|
+
Money closing_balance = 9; // 月末残高
|
|
945
|
+
Money closing_debit_balance = 10; // 決算借方金額
|
|
946
|
+
Money closing_credit_balance = 11; // 決算貸方金額
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// 残高サマリー
|
|
950
|
+
message BalanceSummary {
|
|
951
|
+
string account_code = 1;
|
|
952
|
+
string account_name = 2;
|
|
953
|
+
BsplType bspl_type = 3;
|
|
954
|
+
ElementType element_type = 4;
|
|
955
|
+
Money balance = 5;
|
|
956
|
+
int32 level = 6;
|
|
957
|
+
bool is_leaf = 7;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// === リクエスト/レスポンス ===
|
|
961
|
+
|
|
962
|
+
// 日次残高取得
|
|
963
|
+
message GetDailyBalanceRequest {
|
|
964
|
+
Date balance_date = 1;
|
|
965
|
+
string account_code = 2;
|
|
966
|
+
string sub_account_code = 3;
|
|
967
|
+
string department_code = 4;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
message GetDailyBalanceResponse {
|
|
971
|
+
DailyBalance balance = 1;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// 日次残高一覧取得
|
|
975
|
+
message ListDailyBalancesRequest {
|
|
976
|
+
Date balance_date = 1;
|
|
977
|
+
BsplType bspl_type = 2;
|
|
978
|
+
ElementType element_type = 3;
|
|
979
|
+
string department_code = 4;
|
|
980
|
+
bool posting_accounts_only = 5; // 計上科目のみ
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
message ListDailyBalancesResponse {
|
|
984
|
+
repeated DailyBalance balances = 1;
|
|
985
|
+
Money total_debit = 2;
|
|
986
|
+
Money total_credit = 3;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// 月次残高取得
|
|
990
|
+
message GetMonthlyBalanceRequest {
|
|
991
|
+
FiscalPeriod fiscal_period = 1;
|
|
992
|
+
string account_code = 2;
|
|
993
|
+
string sub_account_code = 3;
|
|
994
|
+
string department_code = 4;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
message GetMonthlyBalanceResponse {
|
|
998
|
+
MonthlyBalance balance = 1;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// 月次残高一覧取得
|
|
1002
|
+
message ListMonthlyBalancesRequest {
|
|
1003
|
+
FiscalPeriod fiscal_period = 1;
|
|
1004
|
+
BsplType bspl_type = 2;
|
|
1005
|
+
ElementType element_type = 3;
|
|
1006
|
+
string department_code = 4;
|
|
1007
|
+
bool include_closing = 5; // 決算仕訳含む
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
message ListMonthlyBalancesResponse {
|
|
1011
|
+
repeated MonthlyBalance balances = 1;
|
|
1012
|
+
Money total_debit = 2;
|
|
1013
|
+
Money total_credit = 3;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// 勘定科目別残高照会
|
|
1017
|
+
message GetAccountBalanceRequest {
|
|
1018
|
+
string account_code = 1;
|
|
1019
|
+
Date date_from = 2;
|
|
1020
|
+
Date date_to = 3;
|
|
1021
|
+
string sub_account_code = 4;
|
|
1022
|
+
string department_code = 5;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
message GetAccountBalanceResponse {
|
|
1026
|
+
string account_code = 1;
|
|
1027
|
+
string account_name = 2;
|
|
1028
|
+
Money opening_balance = 3; // 期首残高
|
|
1029
|
+
Money total_debit = 4; // 期間借方合計
|
|
1030
|
+
Money total_credit = 5; // 期間貸方合計
|
|
1031
|
+
Money closing_balance = 6; // 期末残高
|
|
1032
|
+
repeated DailyBalance daily_movements = 7; // 日別推移
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// 残高サマリー取得(試算表用)
|
|
1036
|
+
message GetBalanceSummaryRequest {
|
|
1037
|
+
Date as_of_date = 1;
|
|
1038
|
+
BsplType bspl_type = 2;
|
|
1039
|
+
bool include_sub_accounts = 3;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
message GetBalanceSummaryResponse {
|
|
1043
|
+
repeated BalanceSummary summaries = 1;
|
|
1044
|
+
Money bs_total_debit = 2; // BS借方合計
|
|
1045
|
+
Money bs_total_credit = 3; // BS貸方合計
|
|
1046
|
+
Money pl_total_debit = 4; // PL借方合計
|
|
1047
|
+
Money pl_total_credit = 5; // PL貸方合計
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// 残高更新(仕訳転記時)
|
|
1051
|
+
message UpdateBalanceRequest {
|
|
1052
|
+
string slip_number = 1;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
message UpdateBalanceResponse {
|
|
1056
|
+
bool success = 1;
|
|
1057
|
+
int32 updated_daily_records = 2;
|
|
1058
|
+
int32 updated_monthly_records = 3;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// === サービス定義 ===
|
|
1062
|
+
|
|
1063
|
+
service BalanceService {
|
|
1064
|
+
// 単項 RPC
|
|
1065
|
+
rpc GetDailyBalance(GetDailyBalanceRequest) returns (GetDailyBalanceResponse);
|
|
1066
|
+
rpc GetMonthlyBalance(GetMonthlyBalanceRequest) returns (GetMonthlyBalanceResponse);
|
|
1067
|
+
rpc GetAccountBalance(GetAccountBalanceRequest) returns (GetAccountBalanceResponse);
|
|
1068
|
+
rpc GetBalanceSummary(GetBalanceSummaryRequest) returns (GetBalanceSummaryResponse);
|
|
1069
|
+
rpc UpdateBalance(UpdateBalanceRequest) returns (UpdateBalanceResponse);
|
|
1070
|
+
|
|
1071
|
+
// サーバーストリーミング RPC
|
|
1072
|
+
rpc ListDailyBalances(ListDailyBalancesRequest) returns (stream DailyBalance);
|
|
1073
|
+
rpc ListMonthlyBalances(ListMonthlyBalancesRequest) returns (stream MonthlyBalance);
|
|
1074
|
+
|
|
1075
|
+
// 双方向ストリーミング(リアルタイム残高監視)
|
|
1076
|
+
rpc WatchBalance(stream GetAccountBalanceRequest) returns (stream GetAccountBalanceResponse);
|
|
1077
|
+
}
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
</details>
|
|
1081
|
+
|
|
1082
|
+
---
|
|
1083
|
+
|
|
1084
|
+
## 第 24 章:gRPC サービス実装
|
|
1085
|
+
|
|
1086
|
+
### 24.1 勘定科目サービス実装
|
|
1087
|
+
|
|
1088
|
+
<details>
|
|
1089
|
+
<summary>GrpcAccountService.java</summary>
|
|
1090
|
+
|
|
1091
|
+
```java
|
|
1092
|
+
package com.example.accounting.infrastructure.in.grpc.service;
|
|
1093
|
+
|
|
1094
|
+
import com.example.accounting.application.port.in.AccountUseCase;
|
|
1095
|
+
import com.example.accounting.domain.model.account.Account;
|
|
1096
|
+
import com.example.accounting.domain.model.account.AccountCode;
|
|
1097
|
+
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1098
|
+
import com.example.accounting.infrastructure.in.grpc.converter.AccountConverter;
|
|
1099
|
+
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1100
|
+
import io.grpc.Status;
|
|
1101
|
+
import io.grpc.stub.StreamObserver;
|
|
1102
|
+
import net.devh.boot.grpc.server.service.GrpcService;
|
|
1103
|
+
import org.slf4j.Logger;
|
|
1104
|
+
import org.slf4j.LoggerFactory;
|
|
1105
|
+
|
|
1106
|
+
import java.util.List;
|
|
1107
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* 勘定科目 gRPC サービス実装
|
|
1111
|
+
*/
|
|
1112
|
+
@GrpcService
|
|
1113
|
+
public class GrpcAccountService extends AccountServiceGrpc.AccountServiceImplBase {
|
|
1114
|
+
|
|
1115
|
+
private static final Logger log = LoggerFactory.getLogger(GrpcAccountService.class);
|
|
1116
|
+
|
|
1117
|
+
private final AccountUseCase accountUseCase;
|
|
1118
|
+
private final AccountConverter converter;
|
|
1119
|
+
|
|
1120
|
+
public GrpcAccountService(AccountUseCase accountUseCase, AccountConverter converter) {
|
|
1121
|
+
this.accountUseCase = accountUseCase;
|
|
1122
|
+
this.converter = converter;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* 単項 RPC: 勘定科目取得
|
|
1127
|
+
*/
|
|
1128
|
+
@Override
|
|
1129
|
+
public void getAccount(GetAccountRequest request,
|
|
1130
|
+
StreamObserver<GetAccountResponse> responseObserver) {
|
|
1131
|
+
log.info("getAccount: {}", request.getAccountCode());
|
|
1132
|
+
|
|
1133
|
+
try {
|
|
1134
|
+
AccountCode code = new AccountCode(request.getAccountCode());
|
|
1135
|
+
Account account = accountUseCase.findByCode(code)
|
|
1136
|
+
.orElseThrow(() -> new ResourceNotFoundException(
|
|
1137
|
+
"勘定科目", request.getAccountCode()));
|
|
1138
|
+
|
|
1139
|
+
GetAccountResponse response = GetAccountResponse.newBuilder()
|
|
1140
|
+
.setAccount(converter.toProto(account))
|
|
1141
|
+
.build();
|
|
1142
|
+
|
|
1143
|
+
responseObserver.onNext(response);
|
|
1144
|
+
responseObserver.onCompleted();
|
|
1145
|
+
|
|
1146
|
+
} catch (ResourceNotFoundException e) {
|
|
1147
|
+
log.warn("Account not found: {}", request.getAccountCode());
|
|
1148
|
+
responseObserver.onError(
|
|
1149
|
+
Status.NOT_FOUND
|
|
1150
|
+
.withDescription("勘定科目が見つかりません: " + request.getAccountCode())
|
|
1151
|
+
.asRuntimeException()
|
|
1152
|
+
);
|
|
1153
|
+
} catch (Exception e) {
|
|
1154
|
+
log.error("Error getting account", e);
|
|
1155
|
+
responseObserver.onError(
|
|
1156
|
+
Status.INTERNAL
|
|
1157
|
+
.withDescription("内部エラーが発生しました")
|
|
1158
|
+
.withCause(e)
|
|
1159
|
+
.asRuntimeException()
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* 単項 RPC: 勘定科目登録
|
|
1166
|
+
*/
|
|
1167
|
+
@Override
|
|
1168
|
+
public void createAccount(CreateAccountRequest request,
|
|
1169
|
+
StreamObserver<CreateAccountResponse> responseObserver) {
|
|
1170
|
+
log.info("createAccount: {}", request.getAccountCode());
|
|
1171
|
+
|
|
1172
|
+
try {
|
|
1173
|
+
Account account = converter.toDomain(request);
|
|
1174
|
+
Account created = accountUseCase.create(account);
|
|
1175
|
+
|
|
1176
|
+
CreateAccountResponse response = CreateAccountResponse.newBuilder()
|
|
1177
|
+
.setAccount(converter.toProto(created))
|
|
1178
|
+
.build();
|
|
1179
|
+
|
|
1180
|
+
responseObserver.onNext(response);
|
|
1181
|
+
responseObserver.onCompleted();
|
|
1182
|
+
|
|
1183
|
+
} catch (IllegalArgumentException e) {
|
|
1184
|
+
log.warn("Invalid request: {}", e.getMessage());
|
|
1185
|
+
responseObserver.onError(
|
|
1186
|
+
Status.INVALID_ARGUMENT
|
|
1187
|
+
.withDescription(e.getMessage())
|
|
1188
|
+
.asRuntimeException()
|
|
1189
|
+
);
|
|
1190
|
+
} catch (Exception e) {
|
|
1191
|
+
log.error("Error creating account", e);
|
|
1192
|
+
responseObserver.onError(
|
|
1193
|
+
Status.INTERNAL
|
|
1194
|
+
.withDescription("内部エラーが発生しました")
|
|
1195
|
+
.asRuntimeException()
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* サーバーストリーミング RPC: 勘定科目一覧取得
|
|
1202
|
+
*/
|
|
1203
|
+
@Override
|
|
1204
|
+
public void listAccounts(ListAccountsRequest request,
|
|
1205
|
+
StreamObserver<com.example.accounting.infrastructure.in.grpc.proto.Account> responseObserver) {
|
|
1206
|
+
log.info("listAccounts: bsplType={}, keyword={}",
|
|
1207
|
+
request.getBsplType(), request.getKeyword());
|
|
1208
|
+
|
|
1209
|
+
try {
|
|
1210
|
+
List<Account> accounts = accountUseCase.findAll(
|
|
1211
|
+
converter.toCriteria(request)
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
// ストリーミングで勘定科目を1件ずつ送信
|
|
1215
|
+
for (Account account : accounts) {
|
|
1216
|
+
responseObserver.onNext(converter.toProto(account));
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
responseObserver.onCompleted();
|
|
1220
|
+
log.info("listAccounts completed: {} items", accounts.size());
|
|
1221
|
+
|
|
1222
|
+
} catch (Exception e) {
|
|
1223
|
+
log.error("Error listing accounts", e);
|
|
1224
|
+
responseObserver.onError(
|
|
1225
|
+
Status.INTERNAL
|
|
1226
|
+
.withDescription("内部エラーが発生しました")
|
|
1227
|
+
.asRuntimeException()
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* クライアントストリーミング RPC: 勘定科目一括登録
|
|
1234
|
+
*/
|
|
1235
|
+
@Override
|
|
1236
|
+
public StreamObserver<BulkCreateAccountRequest> bulkCreateAccounts(
|
|
1237
|
+
StreamObserver<BulkCreateAccountResponse> responseObserver) {
|
|
1238
|
+
|
|
1239
|
+
log.info("bulkCreateAccounts: started");
|
|
1240
|
+
|
|
1241
|
+
AtomicInteger successCount = new AtomicInteger(0);
|
|
1242
|
+
AtomicInteger failureCount = new AtomicInteger(0);
|
|
1243
|
+
List<ErrorDetail> errors = new java.util.ArrayList<>();
|
|
1244
|
+
|
|
1245
|
+
return new StreamObserver<BulkCreateAccountRequest>() {
|
|
1246
|
+
@Override
|
|
1247
|
+
public void onNext(BulkCreateAccountRequest request) {
|
|
1248
|
+
try {
|
|
1249
|
+
CreateAccountRequest accountRequest = request.getAccount();
|
|
1250
|
+
Account account = converter.toDomain(accountRequest);
|
|
1251
|
+
accountUseCase.create(account);
|
|
1252
|
+
successCount.incrementAndGet();
|
|
1253
|
+
log.debug("Created account: {}", accountRequest.getAccountCode());
|
|
1254
|
+
|
|
1255
|
+
} catch (Exception e) {
|
|
1256
|
+
failureCount.incrementAndGet();
|
|
1257
|
+
errors.add(ErrorDetail.newBuilder()
|
|
1258
|
+
.setField(request.getAccount().getAccountCode())
|
|
1259
|
+
.setMessage(e.getMessage())
|
|
1260
|
+
.build());
|
|
1261
|
+
log.warn("Failed to create account: {}",
|
|
1262
|
+
request.getAccount().getAccountCode(), e);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
@Override
|
|
1267
|
+
public void onError(Throwable t) {
|
|
1268
|
+
log.error("bulkCreateAccounts error", t);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
@Override
|
|
1272
|
+
public void onCompleted() {
|
|
1273
|
+
BulkCreateAccountResponse response = BulkCreateAccountResponse.newBuilder()
|
|
1274
|
+
.setSuccessCount(successCount.get())
|
|
1275
|
+
.setFailureCount(failureCount.get())
|
|
1276
|
+
.addAllErrors(errors)
|
|
1277
|
+
.build();
|
|
1278
|
+
|
|
1279
|
+
responseObserver.onNext(response);
|
|
1280
|
+
responseObserver.onCompleted();
|
|
1281
|
+
|
|
1282
|
+
log.info("bulkCreateAccounts completed: success={}, failure={}",
|
|
1283
|
+
successCount.get(), failureCount.get());
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* 勘定科目ツリー取得
|
|
1290
|
+
*/
|
|
1291
|
+
@Override
|
|
1292
|
+
public void getAccountTree(GetAccountTreeRequest request,
|
|
1293
|
+
StreamObserver<GetAccountTreeResponse> responseObserver) {
|
|
1294
|
+
log.info("getAccountTree: bsplType={}", request.getBsplType());
|
|
1295
|
+
|
|
1296
|
+
try {
|
|
1297
|
+
var tree = accountUseCase.getAccountTree(
|
|
1298
|
+
converter.toDomainBsplType(request.getBsplType())
|
|
1299
|
+
);
|
|
1300
|
+
|
|
1301
|
+
GetAccountTreeResponse response = GetAccountTreeResponse.newBuilder()
|
|
1302
|
+
.addAllNodes(converter.toProtoTree(tree))
|
|
1303
|
+
.build();
|
|
1304
|
+
|
|
1305
|
+
responseObserver.onNext(response);
|
|
1306
|
+
responseObserver.onCompleted();
|
|
1307
|
+
|
|
1308
|
+
} catch (Exception e) {
|
|
1309
|
+
log.error("Error getting account tree", e);
|
|
1310
|
+
responseObserver.onError(
|
|
1311
|
+
Status.INTERNAL
|
|
1312
|
+
.withDescription("内部エラーが発生しました")
|
|
1313
|
+
.asRuntimeException()
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
```
|
|
1319
|
+
|
|
1320
|
+
</details>
|
|
1321
|
+
|
|
1322
|
+
### 24.2 仕訳サービス実装
|
|
1323
|
+
|
|
1324
|
+
<details>
|
|
1325
|
+
<summary>GrpcJournalService.java</summary>
|
|
1326
|
+
|
|
1327
|
+
```java
|
|
1328
|
+
package com.example.accounting.infrastructure.in.grpc.service;
|
|
1329
|
+
|
|
1330
|
+
import com.example.accounting.application.port.in.JournalUseCase;
|
|
1331
|
+
import com.example.accounting.domain.model.journal.Journal;
|
|
1332
|
+
import com.example.accounting.domain.model.journal.SlipNumber;
|
|
1333
|
+
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1334
|
+
import com.example.accounting.domain.exception.BalanceNotMatchException;
|
|
1335
|
+
import com.example.accounting.infrastructure.in.grpc.converter.JournalConverter;
|
|
1336
|
+
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1337
|
+
import io.grpc.Status;
|
|
1338
|
+
import io.grpc.stub.StreamObserver;
|
|
1339
|
+
import net.devh.boot.grpc.server.service.GrpcService;
|
|
1340
|
+
import org.slf4j.Logger;
|
|
1341
|
+
import org.slf4j.LoggerFactory;
|
|
1342
|
+
|
|
1343
|
+
import java.util.List;
|
|
1344
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* 仕訳 gRPC サービス実装
|
|
1348
|
+
*/
|
|
1349
|
+
@GrpcService
|
|
1350
|
+
public class GrpcJournalService extends JournalServiceGrpc.JournalServiceImplBase {
|
|
1351
|
+
|
|
1352
|
+
private static final Logger log = LoggerFactory.getLogger(GrpcJournalService.class);
|
|
1353
|
+
|
|
1354
|
+
private final JournalUseCase journalUseCase;
|
|
1355
|
+
private final JournalConverter converter;
|
|
1356
|
+
|
|
1357
|
+
public GrpcJournalService(JournalUseCase journalUseCase, JournalConverter converter) {
|
|
1358
|
+
this.journalUseCase = journalUseCase;
|
|
1359
|
+
this.converter = converter;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* 単項 RPC: 仕訳取得
|
|
1364
|
+
*/
|
|
1365
|
+
@Override
|
|
1366
|
+
public void getJournal(GetJournalRequest request,
|
|
1367
|
+
StreamObserver<GetJournalResponse> responseObserver) {
|
|
1368
|
+
log.info("getJournal: {}", request.getSlipNumber());
|
|
1369
|
+
|
|
1370
|
+
try {
|
|
1371
|
+
SlipNumber slipNumber = new SlipNumber(request.getSlipNumber());
|
|
1372
|
+
Journal journal = journalUseCase.findBySlipNumber(slipNumber)
|
|
1373
|
+
.orElseThrow(() -> new ResourceNotFoundException(
|
|
1374
|
+
"仕訳", request.getSlipNumber()));
|
|
1375
|
+
|
|
1376
|
+
GetJournalResponse response = GetJournalResponse.newBuilder()
|
|
1377
|
+
.setJournal(converter.toProto(journal))
|
|
1378
|
+
.build();
|
|
1379
|
+
|
|
1380
|
+
responseObserver.onNext(response);
|
|
1381
|
+
responseObserver.onCompleted();
|
|
1382
|
+
|
|
1383
|
+
} catch (ResourceNotFoundException e) {
|
|
1384
|
+
log.warn("Journal not found: {}", request.getSlipNumber());
|
|
1385
|
+
responseObserver.onError(
|
|
1386
|
+
Status.NOT_FOUND
|
|
1387
|
+
.withDescription("仕訳が見つかりません: " + request.getSlipNumber())
|
|
1388
|
+
.asRuntimeException()
|
|
1389
|
+
);
|
|
1390
|
+
} catch (Exception e) {
|
|
1391
|
+
log.error("Error getting journal", e);
|
|
1392
|
+
responseObserver.onError(
|
|
1393
|
+
Status.INTERNAL
|
|
1394
|
+
.withDescription("内部エラーが発生しました")
|
|
1395
|
+
.asRuntimeException()
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* 単項 RPC: 仕訳登録
|
|
1402
|
+
*/
|
|
1403
|
+
@Override
|
|
1404
|
+
public void createJournal(CreateJournalRequest request,
|
|
1405
|
+
StreamObserver<CreateJournalResponse> responseObserver) {
|
|
1406
|
+
log.info("createJournal: date={}", request.getJournalDate());
|
|
1407
|
+
|
|
1408
|
+
try {
|
|
1409
|
+
Journal journal = converter.toDomain(request);
|
|
1410
|
+
Journal created = journalUseCase.create(journal);
|
|
1411
|
+
|
|
1412
|
+
CreateJournalResponse response = CreateJournalResponse.newBuilder()
|
|
1413
|
+
.setJournal(converter.toProto(created))
|
|
1414
|
+
.build();
|
|
1415
|
+
|
|
1416
|
+
responseObserver.onNext(response);
|
|
1417
|
+
responseObserver.onCompleted();
|
|
1418
|
+
|
|
1419
|
+
} catch (BalanceNotMatchException e) {
|
|
1420
|
+
log.warn("Balance not match: {}", e.getMessage());
|
|
1421
|
+
responseObserver.onError(
|
|
1422
|
+
Status.FAILED_PRECONDITION
|
|
1423
|
+
.withDescription("貸借が一致しません: " + e.getMessage())
|
|
1424
|
+
.asRuntimeException()
|
|
1425
|
+
);
|
|
1426
|
+
} catch (IllegalArgumentException e) {
|
|
1427
|
+
log.warn("Invalid request: {}", e.getMessage());
|
|
1428
|
+
responseObserver.onError(
|
|
1429
|
+
Status.INVALID_ARGUMENT
|
|
1430
|
+
.withDescription(e.getMessage())
|
|
1431
|
+
.asRuntimeException()
|
|
1432
|
+
);
|
|
1433
|
+
} catch (Exception e) {
|
|
1434
|
+
log.error("Error creating journal", e);
|
|
1435
|
+
responseObserver.onError(
|
|
1436
|
+
Status.INTERNAL
|
|
1437
|
+
.withDescription("内部エラーが発生しました")
|
|
1438
|
+
.asRuntimeException()
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* 単項 RPC: 仕訳取消(赤黒処理)
|
|
1445
|
+
*/
|
|
1446
|
+
@Override
|
|
1447
|
+
public void cancelJournal(CancelJournalRequest request,
|
|
1448
|
+
StreamObserver<CancelJournalResponse> responseObserver) {
|
|
1449
|
+
log.info("cancelJournal: {}", request.getSlipNumber());
|
|
1450
|
+
|
|
1451
|
+
try {
|
|
1452
|
+
SlipNumber slipNumber = new SlipNumber(request.getSlipNumber());
|
|
1453
|
+
var result = journalUseCase.cancel(slipNumber, request.getCancelReason());
|
|
1454
|
+
|
|
1455
|
+
CancelJournalResponse response = CancelJournalResponse.newBuilder()
|
|
1456
|
+
.setOriginalJournal(converter.toProto(result.getOriginal()))
|
|
1457
|
+
.setReversalJournal(converter.toProto(result.getReversal()))
|
|
1458
|
+
.build();
|
|
1459
|
+
|
|
1460
|
+
responseObserver.onNext(response);
|
|
1461
|
+
responseObserver.onCompleted();
|
|
1462
|
+
|
|
1463
|
+
} catch (ResourceNotFoundException e) {
|
|
1464
|
+
log.warn("Journal not found for cancel: {}", request.getSlipNumber());
|
|
1465
|
+
responseObserver.onError(
|
|
1466
|
+
Status.NOT_FOUND
|
|
1467
|
+
.withDescription("取消対象の仕訳が見つかりません: " + request.getSlipNumber())
|
|
1468
|
+
.asRuntimeException()
|
|
1469
|
+
);
|
|
1470
|
+
} catch (Exception e) {
|
|
1471
|
+
log.error("Error canceling journal", e);
|
|
1472
|
+
responseObserver.onError(
|
|
1473
|
+
Status.INTERNAL
|
|
1474
|
+
.withDescription("内部エラーが発生しました")
|
|
1475
|
+
.asRuntimeException()
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* サーバーストリーミング RPC: 仕訳一覧取得
|
|
1482
|
+
*/
|
|
1483
|
+
@Override
|
|
1484
|
+
public void listJournals(ListJournalsRequest request,
|
|
1485
|
+
StreamObserver<com.example.accounting.infrastructure.in.grpc.proto.Journal> responseObserver) {
|
|
1486
|
+
log.info("listJournals: dateFrom={}, dateTo={}",
|
|
1487
|
+
request.getDateFrom(), request.getDateTo());
|
|
1488
|
+
|
|
1489
|
+
try {
|
|
1490
|
+
List<Journal> journals = journalUseCase.findAll(
|
|
1491
|
+
converter.toCriteria(request)
|
|
1492
|
+
);
|
|
1493
|
+
|
|
1494
|
+
// ストリーミングで仕訳を1件ずつ送信
|
|
1495
|
+
for (Journal journal : journals) {
|
|
1496
|
+
responseObserver.onNext(converter.toProto(journal));
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
responseObserver.onCompleted();
|
|
1500
|
+
log.info("listJournals completed: {} items", journals.size());
|
|
1501
|
+
|
|
1502
|
+
} catch (Exception e) {
|
|
1503
|
+
log.error("Error listing journals", e);
|
|
1504
|
+
responseObserver.onError(
|
|
1505
|
+
Status.INTERNAL
|
|
1506
|
+
.withDescription("内部エラーが発生しました")
|
|
1507
|
+
.asRuntimeException()
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/**
|
|
1513
|
+
* クライアントストリーミング RPC: 仕訳一括登録
|
|
1514
|
+
*/
|
|
1515
|
+
@Override
|
|
1516
|
+
public StreamObserver<BulkCreateJournalRequest> bulkCreateJournals(
|
|
1517
|
+
StreamObserver<BulkCreateJournalResponse> responseObserver) {
|
|
1518
|
+
|
|
1519
|
+
log.info("bulkCreateJournals: started");
|
|
1520
|
+
|
|
1521
|
+
AtomicInteger successCount = new AtomicInteger(0);
|
|
1522
|
+
AtomicInteger failureCount = new AtomicInteger(0);
|
|
1523
|
+
List<ErrorDetail> errors = new java.util.ArrayList<>();
|
|
1524
|
+
List<String> createdSlipNumbers = new java.util.ArrayList<>();
|
|
1525
|
+
|
|
1526
|
+
return new StreamObserver<BulkCreateJournalRequest>() {
|
|
1527
|
+
@Override
|
|
1528
|
+
public void onNext(BulkCreateJournalRequest request) {
|
|
1529
|
+
try {
|
|
1530
|
+
CreateJournalRequest journalRequest = request.getJournal();
|
|
1531
|
+
Journal journal = converter.toDomain(journalRequest);
|
|
1532
|
+
Journal created = journalUseCase.create(journal);
|
|
1533
|
+
successCount.incrementAndGet();
|
|
1534
|
+
createdSlipNumbers.add(created.getSlipNumber().getValue());
|
|
1535
|
+
log.debug("Created journal: {}", created.getSlipNumber().getValue());
|
|
1536
|
+
|
|
1537
|
+
} catch (Exception e) {
|
|
1538
|
+
failureCount.incrementAndGet();
|
|
1539
|
+
errors.add(ErrorDetail.newBuilder()
|
|
1540
|
+
.setField("journal")
|
|
1541
|
+
.setMessage(e.getMessage())
|
|
1542
|
+
.build());
|
|
1543
|
+
log.warn("Failed to create journal", e);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
@Override
|
|
1548
|
+
public void onError(Throwable t) {
|
|
1549
|
+
log.error("bulkCreateJournals error", t);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
@Override
|
|
1553
|
+
public void onCompleted() {
|
|
1554
|
+
BulkCreateJournalResponse response = BulkCreateJournalResponse.newBuilder()
|
|
1555
|
+
.setSuccessCount(successCount.get())
|
|
1556
|
+
.setFailureCount(failureCount.get())
|
|
1557
|
+
.addAllErrors(errors)
|
|
1558
|
+
.addAllCreatedSlipNumbers(createdSlipNumbers)
|
|
1559
|
+
.build();
|
|
1560
|
+
|
|
1561
|
+
responseObserver.onNext(response);
|
|
1562
|
+
responseObserver.onCompleted();
|
|
1563
|
+
|
|
1564
|
+
log.info("bulkCreateJournals completed: success={}, failure={}",
|
|
1565
|
+
successCount.get(), failureCount.get());
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
/**
|
|
1571
|
+
* 単項 RPC: 貸借バランスチェック
|
|
1572
|
+
*/
|
|
1573
|
+
@Override
|
|
1574
|
+
public void validateBalance(ValidateBalanceRequest request,
|
|
1575
|
+
StreamObserver<ValidateBalanceResponse> responseObserver) {
|
|
1576
|
+
log.info("validateBalance");
|
|
1577
|
+
|
|
1578
|
+
try {
|
|
1579
|
+
var result = journalUseCase.validateBalance(
|
|
1580
|
+
converter.toDetailDomainList(request.getDetailsList())
|
|
1581
|
+
);
|
|
1582
|
+
|
|
1583
|
+
ValidateBalanceResponse response = ValidateBalanceResponse.newBuilder()
|
|
1584
|
+
.setIsBalanced(result.isBalanced())
|
|
1585
|
+
.setTotalDebit(converter.toProtoMoney(result.getTotalDebit()))
|
|
1586
|
+
.setTotalCredit(converter.toProtoMoney(result.getTotalCredit()))
|
|
1587
|
+
.setDifference(converter.toProtoMoney(result.getDifference()))
|
|
1588
|
+
.build();
|
|
1589
|
+
|
|
1590
|
+
responseObserver.onNext(response);
|
|
1591
|
+
responseObserver.onCompleted();
|
|
1592
|
+
|
|
1593
|
+
} catch (Exception e) {
|
|
1594
|
+
log.error("Error validating balance", e);
|
|
1595
|
+
responseObserver.onError(
|
|
1596
|
+
Status.INTERNAL
|
|
1597
|
+
.withDescription("内部エラーが発生しました")
|
|
1598
|
+
.asRuntimeException()
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
```
|
|
1604
|
+
|
|
1605
|
+
</details>
|
|
1606
|
+
|
|
1607
|
+
### 24.3 コンバーター実装
|
|
1608
|
+
|
|
1609
|
+
<details>
|
|
1610
|
+
<summary>AccountConverter.java</summary>
|
|
1611
|
+
|
|
1612
|
+
```java
|
|
1613
|
+
package com.example.accounting.infrastructure.in.grpc.converter;
|
|
1614
|
+
|
|
1615
|
+
import com.example.accounting.domain.model.account.*;
|
|
1616
|
+
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
1617
|
+
import org.springframework.stereotype.Component;
|
|
1618
|
+
|
|
1619
|
+
import java.util.List;
|
|
1620
|
+
import java.util.stream.Collectors;
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* 勘定科目ドメインモデル ⇔ Protocol Buffers 変換
|
|
1624
|
+
*/
|
|
1625
|
+
@Component
|
|
1626
|
+
public class AccountConverter {
|
|
1627
|
+
|
|
1628
|
+
/**
|
|
1629
|
+
* ドメインモデル → Proto
|
|
1630
|
+
*/
|
|
1631
|
+
public com.example.accounting.infrastructure.in.grpc.proto.Account toProto(Account domain) {
|
|
1632
|
+
return com.example.accounting.infrastructure.in.grpc.proto.Account.newBuilder()
|
|
1633
|
+
.setAccountCode(domain.getAccountCode().getValue())
|
|
1634
|
+
.setAccountName(domain.getAccountName())
|
|
1635
|
+
.setBsplType(toProtoBsplType(domain.getBsplType()))
|
|
1636
|
+
.setDebitCreditType(toProtoDebitCreditType(domain.getDebitCreditType()))
|
|
1637
|
+
.setElementType(toProtoElementType(domain.getElementType()))
|
|
1638
|
+
.setAggregationType(toProtoAggregationType(domain.getAggregationType()))
|
|
1639
|
+
.setParentAccountCode(nullToEmpty(domain.getParentAccountCode()))
|
|
1640
|
+
.setAccountPath(nullToEmpty(domain.getAccountPath()))
|
|
1641
|
+
.setDisplayOrder(domain.getDisplayOrder())
|
|
1642
|
+
.setIsActive(domain.isActive())
|
|
1643
|
+
.build();
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* CreateAccountRequest → ドメインモデル
|
|
1648
|
+
*/
|
|
1649
|
+
public Account toDomain(CreateAccountRequest request) {
|
|
1650
|
+
return Account.builder()
|
|
1651
|
+
.accountCode(new AccountCode(request.getAccountCode()))
|
|
1652
|
+
.accountName(request.getAccountName())
|
|
1653
|
+
.bsplType(toDomainBsplType(request.getBsplType()))
|
|
1654
|
+
.debitCreditType(toDomainDebitCreditType(request.getDebitCreditType()))
|
|
1655
|
+
.elementType(toDomainElementType(request.getElementType()))
|
|
1656
|
+
.aggregationType(toDomainAggregationType(request.getAggregationType()))
|
|
1657
|
+
.parentAccountCode(emptyToNull(request.getParentAccountCode()))
|
|
1658
|
+
.displayOrder(request.getDisplayOrder())
|
|
1659
|
+
.isActive(true)
|
|
1660
|
+
.build();
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* ListAccountsRequest → 検索条件
|
|
1665
|
+
*/
|
|
1666
|
+
public AccountSearchCriteria toCriteria(ListAccountsRequest request) {
|
|
1667
|
+
return AccountSearchCriteria.builder()
|
|
1668
|
+
.bsplType(request.hasBsplType()
|
|
1669
|
+
? toDomainBsplType(request.getBsplType()) : null)
|
|
1670
|
+
.elementType(request.hasElementType()
|
|
1671
|
+
? toDomainElementType(request.getElementType()) : null)
|
|
1672
|
+
.aggregationType(request.hasAggregationType()
|
|
1673
|
+
? toDomainAggregationType(request.getAggregationType()) : null)
|
|
1674
|
+
.keyword(emptyToNull(request.getKeyword()))
|
|
1675
|
+
.activeOnly(request.getActiveOnly())
|
|
1676
|
+
.page(request.hasPage() ? request.getPage().getPage() : 0)
|
|
1677
|
+
.size(request.hasPage() ? request.getPage().getSize() : 20)
|
|
1678
|
+
.build();
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
/**
|
|
1682
|
+
* ツリー構造を Proto に変換
|
|
1683
|
+
*/
|
|
1684
|
+
public List<AccountNode> toProtoTree(List<AccountTreeNode> tree) {
|
|
1685
|
+
return tree.stream()
|
|
1686
|
+
.map(this::toProtoNode)
|
|
1687
|
+
.collect(Collectors.toList());
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
private AccountNode toProtoNode(AccountTreeNode node) {
|
|
1691
|
+
AccountNode.Builder builder = AccountNode.newBuilder()
|
|
1692
|
+
.setAccount(toProto(node.getAccount()));
|
|
1693
|
+
|
|
1694
|
+
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
1695
|
+
builder.addAllChildren(
|
|
1696
|
+
node.getChildren().stream()
|
|
1697
|
+
.map(this::toProtoNode)
|
|
1698
|
+
.collect(Collectors.toList())
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
return builder.build();
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
// === 区分変換 ===
|
|
1706
|
+
|
|
1707
|
+
public BsplType toProtoBsplType(
|
|
1708
|
+
com.example.accounting.domain.model.account.BsplType domain) {
|
|
1709
|
+
return switch (domain) {
|
|
1710
|
+
case BS -> BsplType.BSPL_TYPE_BS;
|
|
1711
|
+
case PL -> BsplType.BSPL_TYPE_PL;
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
public com.example.accounting.domain.model.account.BsplType toDomainBsplType(
|
|
1716
|
+
BsplType proto) {
|
|
1717
|
+
return switch (proto) {
|
|
1718
|
+
case BSPL_TYPE_BS -> com.example.accounting.domain.model.account.BsplType.BS;
|
|
1719
|
+
case BSPL_TYPE_PL -> com.example.accounting.domain.model.account.BsplType.PL;
|
|
1720
|
+
default -> throw new IllegalArgumentException("Unknown BSPL type: " + proto);
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
private DebitCreditType toProtoDebitCreditType(
|
|
1725
|
+
com.example.accounting.domain.model.account.DebitCreditType domain) {
|
|
1726
|
+
return switch (domain) {
|
|
1727
|
+
case DEBIT -> DebitCreditType.DEBIT_CREDIT_TYPE_DEBIT;
|
|
1728
|
+
case CREDIT -> DebitCreditType.DEBIT_CREDIT_TYPE_CREDIT;
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
private com.example.accounting.domain.model.account.DebitCreditType toDomainDebitCreditType(
|
|
1733
|
+
DebitCreditType proto) {
|
|
1734
|
+
return switch (proto) {
|
|
1735
|
+
case DEBIT_CREDIT_TYPE_DEBIT ->
|
|
1736
|
+
com.example.accounting.domain.model.account.DebitCreditType.DEBIT;
|
|
1737
|
+
case DEBIT_CREDIT_TYPE_CREDIT ->
|
|
1738
|
+
com.example.accounting.domain.model.account.DebitCreditType.CREDIT;
|
|
1739
|
+
default -> throw new IllegalArgumentException("Unknown debit/credit type: " + proto);
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
private ElementType toProtoElementType(
|
|
1744
|
+
com.example.accounting.domain.model.account.ElementType domain) {
|
|
1745
|
+
return switch (domain) {
|
|
1746
|
+
case ASSET -> ElementType.ELEMENT_TYPE_ASSET;
|
|
1747
|
+
case LIABILITY -> ElementType.ELEMENT_TYPE_LIABILITY;
|
|
1748
|
+
case EQUITY -> ElementType.ELEMENT_TYPE_EQUITY;
|
|
1749
|
+
case REVENUE -> ElementType.ELEMENT_TYPE_REVENUE;
|
|
1750
|
+
case EXPENSE -> ElementType.ELEMENT_TYPE_EXPENSE;
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
private com.example.accounting.domain.model.account.ElementType toDomainElementType(
|
|
1755
|
+
ElementType proto) {
|
|
1756
|
+
return switch (proto) {
|
|
1757
|
+
case ELEMENT_TYPE_ASSET ->
|
|
1758
|
+
com.example.accounting.domain.model.account.ElementType.ASSET;
|
|
1759
|
+
case ELEMENT_TYPE_LIABILITY ->
|
|
1760
|
+
com.example.accounting.domain.model.account.ElementType.LIABILITY;
|
|
1761
|
+
case ELEMENT_TYPE_EQUITY ->
|
|
1762
|
+
com.example.accounting.domain.model.account.ElementType.EQUITY;
|
|
1763
|
+
case ELEMENT_TYPE_REVENUE ->
|
|
1764
|
+
com.example.accounting.domain.model.account.ElementType.REVENUE;
|
|
1765
|
+
case ELEMENT_TYPE_EXPENSE ->
|
|
1766
|
+
com.example.accounting.domain.model.account.ElementType.EXPENSE;
|
|
1767
|
+
default -> throw new IllegalArgumentException("Unknown element type: " + proto);
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
private AggregationType toProtoAggregationType(
|
|
1772
|
+
com.example.accounting.domain.model.account.AggregationType domain) {
|
|
1773
|
+
return switch (domain) {
|
|
1774
|
+
case HEADING -> AggregationType.AGGREGATION_TYPE_HEADING;
|
|
1775
|
+
case SUMMARY -> AggregationType.AGGREGATION_TYPE_SUMMARY;
|
|
1776
|
+
case POSTING -> AggregationType.AGGREGATION_TYPE_POSTING;
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
private com.example.accounting.domain.model.account.AggregationType toDomainAggregationType(
|
|
1781
|
+
AggregationType proto) {
|
|
1782
|
+
return switch (proto) {
|
|
1783
|
+
case AGGREGATION_TYPE_HEADING ->
|
|
1784
|
+
com.example.accounting.domain.model.account.AggregationType.HEADING;
|
|
1785
|
+
case AGGREGATION_TYPE_SUMMARY ->
|
|
1786
|
+
com.example.accounting.domain.model.account.AggregationType.SUMMARY;
|
|
1787
|
+
case AGGREGATION_TYPE_POSTING ->
|
|
1788
|
+
com.example.accounting.domain.model.account.AggregationType.POSTING;
|
|
1789
|
+
default -> throw new IllegalArgumentException("Unknown aggregation type: " + proto);
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
// === ユーティリティ ===
|
|
1794
|
+
|
|
1795
|
+
private String nullToEmpty(String value) {
|
|
1796
|
+
return value == null ? "" : value;
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
private String emptyToNull(String value) {
|
|
1800
|
+
return value == null || value.isEmpty() ? null : value;
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
```
|
|
1804
|
+
|
|
1805
|
+
</details>
|
|
1806
|
+
|
|
1807
|
+
---
|
|
1808
|
+
|
|
1809
|
+
## 第 25 章:gRPC インターセプター
|
|
1810
|
+
|
|
1811
|
+
### 25.1 ログインターセプター
|
|
1812
|
+
|
|
1813
|
+
<details>
|
|
1814
|
+
<summary>LoggingInterceptor.java</summary>
|
|
1815
|
+
|
|
1816
|
+
```java
|
|
1817
|
+
package com.example.accounting.infrastructure.in.grpc.interceptor;
|
|
1818
|
+
|
|
1819
|
+
import io.grpc.*;
|
|
1820
|
+
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
|
|
1821
|
+
import org.slf4j.Logger;
|
|
1822
|
+
import org.slf4j.LoggerFactory;
|
|
1823
|
+
import org.slf4j.MDC;
|
|
1824
|
+
|
|
1825
|
+
import java.util.UUID;
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* gRPC ログインターセプター
|
|
1829
|
+
*/
|
|
1830
|
+
@GrpcGlobalServerInterceptor
|
|
1831
|
+
public class LoggingInterceptor implements ServerInterceptor {
|
|
1832
|
+
|
|
1833
|
+
private static final Logger log = LoggerFactory.getLogger(LoggingInterceptor.class);
|
|
1834
|
+
|
|
1835
|
+
@Override
|
|
1836
|
+
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
|
1837
|
+
ServerCall<ReqT, RespT> call,
|
|
1838
|
+
Metadata headers,
|
|
1839
|
+
ServerCallHandler<ReqT, RespT> next) {
|
|
1840
|
+
|
|
1841
|
+
String requestId = UUID.randomUUID().toString();
|
|
1842
|
+
String methodName = call.getMethodDescriptor().getFullMethodName();
|
|
1843
|
+
long startTime = System.currentTimeMillis();
|
|
1844
|
+
|
|
1845
|
+
MDC.put("requestId", requestId);
|
|
1846
|
+
log.info("gRPC Request: method={}", methodName);
|
|
1847
|
+
|
|
1848
|
+
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(
|
|
1849
|
+
next.startCall(
|
|
1850
|
+
new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
|
|
1851
|
+
@Override
|
|
1852
|
+
public void close(Status status, Metadata trailers) {
|
|
1853
|
+
long duration = System.currentTimeMillis() - startTime;
|
|
1854
|
+
log.info("gRPC Response: method={}, status={}, duration={}ms",
|
|
1855
|
+
methodName, status.getCode(), duration);
|
|
1856
|
+
MDC.clear();
|
|
1857
|
+
super.close(status, trailers);
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
headers
|
|
1861
|
+
)
|
|
1862
|
+
) {
|
|
1863
|
+
@Override
|
|
1864
|
+
public void onMessage(ReqT message) {
|
|
1865
|
+
log.debug("gRPC Request message: {}", message);
|
|
1866
|
+
super.onMessage(message);
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
```
|
|
1872
|
+
|
|
1873
|
+
</details>
|
|
1874
|
+
|
|
1875
|
+
### 25.2 例外インターセプター
|
|
1876
|
+
|
|
1877
|
+
<details>
|
|
1878
|
+
<summary>ExceptionInterceptor.java</summary>
|
|
1879
|
+
|
|
1880
|
+
```java
|
|
1881
|
+
package com.example.accounting.infrastructure.in.grpc.interceptor;
|
|
1882
|
+
|
|
1883
|
+
import com.example.accounting.domain.exception.BusinessException;
|
|
1884
|
+
import com.example.accounting.domain.exception.ResourceNotFoundException;
|
|
1885
|
+
import com.example.accounting.domain.exception.ValidationException;
|
|
1886
|
+
import com.example.accounting.domain.exception.BalanceNotMatchException;
|
|
1887
|
+
import io.grpc.*;
|
|
1888
|
+
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
|
|
1889
|
+
import org.slf4j.Logger;
|
|
1890
|
+
import org.slf4j.LoggerFactory;
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* gRPC 例外インターセプター
|
|
1894
|
+
*/
|
|
1895
|
+
@GrpcGlobalServerInterceptor
|
|
1896
|
+
public class ExceptionInterceptor implements ServerInterceptor {
|
|
1897
|
+
|
|
1898
|
+
private static final Logger log = LoggerFactory.getLogger(ExceptionInterceptor.class);
|
|
1899
|
+
|
|
1900
|
+
@Override
|
|
1901
|
+
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
|
1902
|
+
ServerCall<ReqT, RespT> call,
|
|
1903
|
+
Metadata headers,
|
|
1904
|
+
ServerCallHandler<ReqT, RespT> next) {
|
|
1905
|
+
|
|
1906
|
+
return new ExceptionHandlingListener<>(
|
|
1907
|
+
next.startCall(call, headers),
|
|
1908
|
+
call
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
private class ExceptionHandlingListener<ReqT, RespT>
|
|
1913
|
+
extends ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT> {
|
|
1914
|
+
|
|
1915
|
+
private final ServerCall<ReqT, RespT> call;
|
|
1916
|
+
|
|
1917
|
+
protected ExceptionHandlingListener(
|
|
1918
|
+
ServerCall.Listener<ReqT> delegate,
|
|
1919
|
+
ServerCall<ReqT, RespT> call) {
|
|
1920
|
+
super(delegate);
|
|
1921
|
+
this.call = call;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
@Override
|
|
1925
|
+
public void onHalfClose() {
|
|
1926
|
+
try {
|
|
1927
|
+
super.onHalfClose();
|
|
1928
|
+
} catch (Exception e) {
|
|
1929
|
+
handleException(e);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
private void handleException(Exception e) {
|
|
1934
|
+
Status status;
|
|
1935
|
+
String message;
|
|
1936
|
+
|
|
1937
|
+
if (e instanceof ResourceNotFoundException) {
|
|
1938
|
+
status = Status.NOT_FOUND;
|
|
1939
|
+
message = e.getMessage();
|
|
1940
|
+
log.warn("Resource not found: {}", message);
|
|
1941
|
+
|
|
1942
|
+
} else if (e instanceof ValidationException) {
|
|
1943
|
+
status = Status.INVALID_ARGUMENT;
|
|
1944
|
+
message = e.getMessage();
|
|
1945
|
+
log.warn("Validation error: {}", message);
|
|
1946
|
+
|
|
1947
|
+
} else if (e instanceof BalanceNotMatchException) {
|
|
1948
|
+
status = Status.FAILED_PRECONDITION;
|
|
1949
|
+
message = e.getMessage();
|
|
1950
|
+
log.warn("Balance not match: {}", message);
|
|
1951
|
+
|
|
1952
|
+
} else if (e instanceof BusinessException) {
|
|
1953
|
+
status = Status.FAILED_PRECONDITION;
|
|
1954
|
+
message = e.getMessage();
|
|
1955
|
+
log.warn("Business rule violation: {}", message);
|
|
1956
|
+
|
|
1957
|
+
} else if (e instanceof IllegalArgumentException) {
|
|
1958
|
+
status = Status.INVALID_ARGUMENT;
|
|
1959
|
+
message = e.getMessage();
|
|
1960
|
+
log.warn("Invalid argument: {}", message);
|
|
1961
|
+
|
|
1962
|
+
} else {
|
|
1963
|
+
status = Status.INTERNAL;
|
|
1964
|
+
message = "内部エラーが発生しました";
|
|
1965
|
+
log.error("Internal error", e);
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
call.close(status.withDescription(message), new Metadata());
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
```
|
|
1973
|
+
|
|
1974
|
+
</details>
|
|
1975
|
+
|
|
1976
|
+
---
|
|
1977
|
+
|
|
1978
|
+
## 第 26 章:動作確認とテスト
|
|
1979
|
+
|
|
1980
|
+
### 26.1 grpcurl による動作確認
|
|
1981
|
+
|
|
1982
|
+
```bash
|
|
1983
|
+
# サーバー起動確認(リフレクションサービス経由)
|
|
1984
|
+
grpcurl -plaintext localhost:9090 list
|
|
1985
|
+
|
|
1986
|
+
# 勘定科目サービスのメソッド一覧
|
|
1987
|
+
grpcurl -plaintext localhost:9090 list com.example.accounting.AccountService
|
|
1988
|
+
|
|
1989
|
+
# 勘定科目取得
|
|
1990
|
+
grpcurl -plaintext -d '{"account_code": "1110"}' \
|
|
1991
|
+
localhost:9090 com.example.accounting.AccountService/GetAccount
|
|
1992
|
+
|
|
1993
|
+
# 勘定科目登録
|
|
1994
|
+
grpcurl -plaintext -d '{
|
|
1995
|
+
"account_code": "1111",
|
|
1996
|
+
"account_name": "普通預金(みずほ銀行)",
|
|
1997
|
+
"bspl_type": "BSPL_TYPE_BS",
|
|
1998
|
+
"debit_credit_type": "DEBIT_CREDIT_TYPE_DEBIT",
|
|
1999
|
+
"element_type": "ELEMENT_TYPE_ASSET",
|
|
2000
|
+
"aggregation_type": "AGGREGATION_TYPE_POSTING",
|
|
2001
|
+
"parent_account_code": "1110",
|
|
2002
|
+
"display_order": 10
|
|
2003
|
+
}' localhost:9090 com.example.accounting.AccountService/CreateAccount
|
|
2004
|
+
|
|
2005
|
+
# 勘定科目一覧取得(ストリーミング)
|
|
2006
|
+
grpcurl -plaintext -d '{
|
|
2007
|
+
"bspl_type": "BSPL_TYPE_BS",
|
|
2008
|
+
"active_only": true
|
|
2009
|
+
}' localhost:9090 com.example.accounting.AccountService/ListAccounts
|
|
2010
|
+
|
|
2011
|
+
# 仕訳登録
|
|
2012
|
+
grpcurl -plaintext -d '{
|
|
2013
|
+
"journal_date": {"year": 2025, "month": 1, "day": 15},
|
|
2014
|
+
"summary": "売上計上",
|
|
2015
|
+
"journal_type": "JOURNAL_TYPE_NORMAL",
|
|
2016
|
+
"details": [{
|
|
2017
|
+
"line_number": 1,
|
|
2018
|
+
"line_summary": "A社への売上",
|
|
2019
|
+
"debit_credit_details": [
|
|
2020
|
+
{
|
|
2021
|
+
"debit_credit_type": "DEBIT_CREDIT_TYPE_DEBIT",
|
|
2022
|
+
"account_code": "1310",
|
|
2023
|
+
"amount": {"units": 110000, "currency": "JPY"}
|
|
2024
|
+
},
|
|
2025
|
+
{
|
|
2026
|
+
"debit_credit_type": "DEBIT_CREDIT_TYPE_CREDIT",
|
|
2027
|
+
"account_code": "4100",
|
|
2028
|
+
"amount": {"units": 100000, "currency": "JPY"}
|
|
2029
|
+
},
|
|
2030
|
+
{
|
|
2031
|
+
"debit_credit_type": "DEBIT_CREDIT_TYPE_CREDIT",
|
|
2032
|
+
"account_code": "2110",
|
|
2033
|
+
"amount": {"units": 10000, "currency": "JPY"}
|
|
2034
|
+
}
|
|
2035
|
+
]
|
|
2036
|
+
}]
|
|
2037
|
+
}' localhost:9090 com.example.accounting.JournalService/CreateJournal
|
|
2038
|
+
|
|
2039
|
+
# ヘルスチェック
|
|
2040
|
+
grpcurl -plaintext localhost:9090 grpc.health.v1.Health/Check
|
|
2041
|
+
```
|
|
2042
|
+
|
|
2043
|
+
### 26.2 統合テスト
|
|
2044
|
+
|
|
2045
|
+
<details>
|
|
2046
|
+
<summary>GrpcAccountServiceTest.java</summary>
|
|
2047
|
+
|
|
2048
|
+
```java
|
|
2049
|
+
package com.example.accounting.infrastructure.in.grpc.service;
|
|
2050
|
+
|
|
2051
|
+
import com.example.accounting.application.port.in.AccountUseCase;
|
|
2052
|
+
import com.example.accounting.domain.model.account.*;
|
|
2053
|
+
import com.example.accounting.infrastructure.in.grpc.converter.AccountConverter;
|
|
2054
|
+
import com.example.accounting.infrastructure.in.grpc.proto.*;
|
|
2055
|
+
import io.grpc.StatusRuntimeException;
|
|
2056
|
+
import net.devh.boot.grpc.client.inject.GrpcClient;
|
|
2057
|
+
import org.junit.jupiter.api.*;
|
|
2058
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
2059
|
+
import org.springframework.boot.test.context.SpringBootTest;
|
|
2060
|
+
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
2061
|
+
import org.springframework.test.context.ActiveProfiles;
|
|
2062
|
+
|
|
2063
|
+
import java.util.Iterator;
|
|
2064
|
+
import java.util.List;
|
|
2065
|
+
import java.util.Optional;
|
|
2066
|
+
|
|
2067
|
+
import static org.assertj.core.api.Assertions.*;
|
|
2068
|
+
import static org.mockito.ArgumentMatchers.any;
|
|
2069
|
+
import static org.mockito.Mockito.*;
|
|
2070
|
+
|
|
2071
|
+
@SpringBootTest(properties = {
|
|
2072
|
+
"grpc.server.port=9091",
|
|
2073
|
+
"grpc.server.in-process-name=test"
|
|
2074
|
+
})
|
|
2075
|
+
@ActiveProfiles("test")
|
|
2076
|
+
class GrpcAccountServiceTest {
|
|
2077
|
+
|
|
2078
|
+
@MockBean
|
|
2079
|
+
private AccountUseCase accountUseCase;
|
|
2080
|
+
|
|
2081
|
+
@GrpcClient("inProcess")
|
|
2082
|
+
private AccountServiceGrpc.AccountServiceBlockingStub blockingStub;
|
|
2083
|
+
|
|
2084
|
+
private Account sampleAccount;
|
|
2085
|
+
|
|
2086
|
+
@BeforeEach
|
|
2087
|
+
void setUp() {
|
|
2088
|
+
sampleAccount = Account.builder()
|
|
2089
|
+
.accountCode(new AccountCode("1110"))
|
|
2090
|
+
.accountName("現金")
|
|
2091
|
+
.bsplType(com.example.accounting.domain.model.account.BsplType.BS)
|
|
2092
|
+
.debitCreditType(
|
|
2093
|
+
com.example.accounting.domain.model.account.DebitCreditType.DEBIT)
|
|
2094
|
+
.elementType(
|
|
2095
|
+
com.example.accounting.domain.model.account.ElementType.ASSET)
|
|
2096
|
+
.aggregationType(
|
|
2097
|
+
com.example.accounting.domain.model.account.AggregationType.POSTING)
|
|
2098
|
+
.isActive(true)
|
|
2099
|
+
.build();
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
@Test
|
|
2103
|
+
@DisplayName("勘定科目取得 - 存在する科目を取得できること")
|
|
2104
|
+
void getAccount_found() {
|
|
2105
|
+
// Given
|
|
2106
|
+
when(accountUseCase.findByCode(any(AccountCode.class)))
|
|
2107
|
+
.thenReturn(Optional.of(sampleAccount));
|
|
2108
|
+
|
|
2109
|
+
GetAccountRequest request = GetAccountRequest.newBuilder()
|
|
2110
|
+
.setAccountCode("1110")
|
|
2111
|
+
.build();
|
|
2112
|
+
|
|
2113
|
+
// When
|
|
2114
|
+
GetAccountResponse response = blockingStub.getAccount(request);
|
|
2115
|
+
|
|
2116
|
+
// Then
|
|
2117
|
+
assertThat(response.getAccount().getAccountCode()).isEqualTo("1110");
|
|
2118
|
+
assertThat(response.getAccount().getAccountName()).isEqualTo("現金");
|
|
2119
|
+
assertThat(response.getAccount().getBsplType())
|
|
2120
|
+
.isEqualTo(BsplType.BSPL_TYPE_BS);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
@Test
|
|
2124
|
+
@DisplayName("勘定科目取得 - 存在しない科目は NOT_FOUND")
|
|
2125
|
+
void getAccount_notFound() {
|
|
2126
|
+
// Given
|
|
2127
|
+
when(accountUseCase.findByCode(any(AccountCode.class)))
|
|
2128
|
+
.thenReturn(Optional.empty());
|
|
2129
|
+
|
|
2130
|
+
GetAccountRequest request = GetAccountRequest.newBuilder()
|
|
2131
|
+
.setAccountCode("9999")
|
|
2132
|
+
.build();
|
|
2133
|
+
|
|
2134
|
+
// When & Then
|
|
2135
|
+
assertThatThrownBy(() -> blockingStub.getAccount(request))
|
|
2136
|
+
.isInstanceOf(StatusRuntimeException.class)
|
|
2137
|
+
.satisfies(e -> {
|
|
2138
|
+
StatusRuntimeException sre = (StatusRuntimeException) e;
|
|
2139
|
+
assertThat(sre.getStatus().getCode())
|
|
2140
|
+
.isEqualTo(io.grpc.Status.NOT_FOUND.getCode());
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
@Test
|
|
2145
|
+
@DisplayName("勘定科目一覧取得 - ストリーミングで取得できること")
|
|
2146
|
+
void listAccounts_streaming() {
|
|
2147
|
+
// Given
|
|
2148
|
+
List<Account> accounts = List.of(
|
|
2149
|
+
sampleAccount,
|
|
2150
|
+
Account.builder()
|
|
2151
|
+
.accountCode(new AccountCode("1120"))
|
|
2152
|
+
.accountName("普通預金")
|
|
2153
|
+
.bsplType(com.example.accounting.domain.model.account.BsplType.BS)
|
|
2154
|
+
.debitCreditType(
|
|
2155
|
+
com.example.accounting.domain.model.account.DebitCreditType.DEBIT)
|
|
2156
|
+
.elementType(
|
|
2157
|
+
com.example.accounting.domain.model.account.ElementType.ASSET)
|
|
2158
|
+
.aggregationType(
|
|
2159
|
+
com.example.accounting.domain.model.account.AggregationType.POSTING)
|
|
2160
|
+
.isActive(true)
|
|
2161
|
+
.build()
|
|
2162
|
+
);
|
|
2163
|
+
when(accountUseCase.findAll(any())).thenReturn(accounts);
|
|
2164
|
+
|
|
2165
|
+
ListAccountsRequest request = ListAccountsRequest.newBuilder()
|
|
2166
|
+
.setBsplType(BsplType.BSPL_TYPE_BS)
|
|
2167
|
+
.setActiveOnly(true)
|
|
2168
|
+
.build();
|
|
2169
|
+
|
|
2170
|
+
// When
|
|
2171
|
+
Iterator<com.example.accounting.infrastructure.in.grpc.proto.Account> iterator =
|
|
2172
|
+
blockingStub.listAccounts(request);
|
|
2173
|
+
|
|
2174
|
+
// Then
|
|
2175
|
+
int count = 0;
|
|
2176
|
+
while (iterator.hasNext()) {
|
|
2177
|
+
com.example.accounting.infrastructure.in.grpc.proto.Account account = iterator.next();
|
|
2178
|
+
assertThat(account.getAccountCode()).matches("11\\d+");
|
|
2179
|
+
count++;
|
|
2180
|
+
}
|
|
2181
|
+
assertThat(count).isEqualTo(2);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
```
|
|
2185
|
+
|
|
2186
|
+
</details>
|
|
2187
|
+
|
|
2188
|
+
---
|
|
2189
|
+
|
|
2190
|
+
## 第 27 章:まとめ
|
|
2191
|
+
|
|
2192
|
+
### 27.1 学習した内容
|
|
2193
|
+
|
|
2194
|
+
1. **gRPC の基本概念**: Protocol Buffers、HTTP/2、4 つの RPC パターン
|
|
2195
|
+
2. **REST/GraphQL との比較**: 用途に応じた適切な選択
|
|
2196
|
+
3. **ヘキサゴナルアーキテクチャとの統合**: Input Adapter として gRPC サービスを追加
|
|
2197
|
+
4. **技術スタック**: grpc-spring-boot-starter、Protocol Buffers
|
|
2198
|
+
5. **Protocol Buffers 定義**: 共通型、勘定科目、仕訳、残高のメッセージとサービス定義
|
|
2199
|
+
6. **gRPC サービス実装**: 単項 RPC、ストリーミング RPC
|
|
2200
|
+
7. **インターセプター**: ログ、例外ハンドリング
|
|
2201
|
+
8. **テスト**: gRPC クライアントを使用した統合テスト
|
|
2202
|
+
|
|
2203
|
+
### 27.2 gRPC が適するユースケース
|
|
2204
|
+
|
|
2205
|
+
| ユースケース | 理由 |
|
|
2206
|
+
|-------------|------|
|
|
2207
|
+
| 基幹システム連携 | 高性能なバイナリ通信 |
|
|
2208
|
+
| 大量仕訳一括登録 | クライアントストリーミング |
|
|
2209
|
+
| リアルタイム残高監視 | 双方向ストリーミング |
|
|
2210
|
+
| 月次締め進捗通知 | サーバーストリーミング |
|
|
2211
|
+
| マイクロサービス間通信 | 型安全な API 定義 |
|
|
2212
|
+
|
|
2213
|
+
### 27.3 API アーキテクチャ選択ガイド
|
|
2214
|
+
|
|
2215
|
+
```plantuml
|
|
2216
|
+
@startuml api_selection
|
|
2217
|
+
!define RECTANGLE class
|
|
2218
|
+
|
|
2219
|
+
skinparam backgroundColor #FEFEFE
|
|
2220
|
+
|
|
2221
|
+
start
|
|
2222
|
+
|
|
2223
|
+
:API が必要;
|
|
2224
|
+
|
|
2225
|
+
if (ブラウザから直接アクセス?) then (はい)
|
|
2226
|
+
if (柔軟なクエリが必要?) then (はい)
|
|
2227
|
+
:GraphQL;
|
|
2228
|
+
else (いいえ)
|
|
2229
|
+
:REST API;
|
|
2230
|
+
endif
|
|
2231
|
+
else (いいえ)
|
|
2232
|
+
if (高性能が必要?) then (はい)
|
|
2233
|
+
:gRPC;
|
|
2234
|
+
else (いいえ)
|
|
2235
|
+
if (ストリーミングが必要?) then (はい)
|
|
2236
|
+
:gRPC;
|
|
2237
|
+
else (いいえ)
|
|
2238
|
+
:REST API;
|
|
2239
|
+
endif
|
|
2240
|
+
endif
|
|
2241
|
+
endif
|
|
2242
|
+
|
|
2243
|
+
stop
|
|
2244
|
+
|
|
2245
|
+
@enduml
|
|
2246
|
+
```
|
|
2247
|
+
|
|
2248
|
+
### 27.4 次のステップ
|
|
2249
|
+
|
|
2250
|
+
- gRPC-Web による Web フロントエンド対応
|
|
2251
|
+
- 認証・認可(JWT トークン検証)
|
|
2252
|
+
- ロードバランシングとサービスメッシュ
|
|
2253
|
+
- Observability(メトリクス、トレーシング)
|