# KOREA-RESEARCH μμ€ν
## π νλ‘μ νΈ κ°μ
**KOREA-RESEARCH**λ μκ° ν¨λμ μΌκ³λΆ μμ§ λ° κ΄λ¦¬λ₯Ό μν μμ€ν
μ
λλ€.
μ΄ μμ€ν
μ ν₯μ¬κ³ λ μν€ν
μ²(Ports & Adapters) ν¨ν΄μ μ μ©ν Spring Boot κΈ°λ°μ λ©ν°λͺ¨λ νλ μμν¬λ₯Ό κΈ°λ°μΌλ‘ νμ¬ μμ± λμμ΅λλ€.
---
## β
Prerequisites
- JDK 17+
- Maven
- PostgreSQL
---
## π νλ‘μ νΈ κ΅¬μ‘°
```
βββ admin # κ΄λ¦¬μ μ΄ν리μΌμ΄μ
βββ core # κ³΅ν΅ λλ©μΈ λ° λ‘μ§
βββ front # μ¬μ©μ μ΄ν리μΌμ΄μ
βββ pom.xml
```
> λͺ¨λ μ ν리μΌμ΄μ
μ `core` λͺ¨λμ μ€μ¬μΌλ‘ ν¬νΈ, μ΄λν° κ΅¬μ‘°λ‘ κ΅¬μ±λ©λλ€.
### π¦ ν₯μ¬κ³ λ ꡬ쑰 μμ
```
usecase/
βββ daily/
βββ expense/
βββ ports/
β βββ application/
β β βββ DailyExpenseService.java
β βββ DailyExpensePortIn.java
β βββ DailyExpensePortOut.java
βββ adapters/
βββ persistence/
β βββ DailyExpenseDao.java
βββ web/
βββ DailyExpenseController.java
````
---
## βοΈ VM Options
```bash
-Dspring.profiles.active=prod
-Dserver.port=8081
-Dfile.encoding=UTF-8
-Dspring.sql.init.mode=never
-Djava.net.preferIPv4Stack=true
-Dlogging.level.org.springframework.security=DEBUG
-Daes.secret-key=092HW829O0A0AVR0
-Dpath.upload.storage=LOCAL
-Dpath.upload.public=/home/etribe/data/upload
-Dpath.upload.tmpdir=/home/etribe/data/upload/tmp
-Djasypt.encryptor.password=ko-research
-Djasypt.encryptor.algorithm=PBEWITHHMACSHA512ANDAES_256
````
## π» λ‘컬 ꡬλ μ νμ μ€μ
λ‘컬 νκ²½μμ ꡬλ μ μλ JVM μ΅μ
λ€μ νκ²½μ λ§κ² μ€μ ν΄ μ£ΌμΈμ
```bash
-Dspring.profiles.active=local
-Dpath.upload.public=/home/etribe/data/upload
-Dpath.upload.tmpdir=/home/etribe/data/upload/tmp
-Djasypt.encryptor.password=ko-research
-Djasypt.encryptor.algorithm=PBEWITHHMACSHA512ANDAES_256
```
> π‘ `-Djasypt.encryptor.password`μ `-Djasypt.encryptor.algorithm`λ νκ²½μ λ°λΌ **μμ κ°λ₯**ν©λλ€.
---
## β οΈ λ‘컬 DB μ°κ²° κ΄λ ¨ μλ΄
νμ¬ μ 곡λ DB μ€μ μ **μ΄μ μλ²μ© μ 보**λ§ ν¬ν¨λμ΄ μμ΅λλ€.
λ‘컬 νκ²½μμ ꡬλνκΈ° μν΄μλ **λ‘컬 DB μ€μ μ λ³λλ‘ κ΅¬μ±ν΄μΌ ν©λλ€.**
* `application-local.yml`μ λ‘컬 DB μ μ μ 보λ₯Ό μ
λ ₯ν΄μΌ ν©λλ€.
* μ΄μ DBμ μ§μ μ κ·Όνμ¬ κ°λ°νμ§ μλλ‘ μ£Όμκ° νμν©λλ€
* `Jasypt`λ‘ μνΈνλ DB κ³μ μ λ³΄κ° μλ κ²½μ°, λ‘컬 λΉλ°λ²νΈ 볡νΈνλ₯Ό μν `encryptor.password`κ° λ°λμ νμν©λλ€.
--
λ€μμ `-Dspring.sql.init.mode=always` μ΅μ
κ΄λ ¨ λ΄μ©μ **μΈμμΈκ³ λ¬Έμ** νμμΌλ‘ μ 리ν μμμ
λλ€. μ΄μ νκ²½μμμ μνμ±κΉμ§ κ°μ‘°ν΄μ μμ±νμ΅λλ€.
---
## βοΈ λ‘컬 DB μ΄κΈ°ν λ° `initData` μ μ© λ°©λ²
### β
Spring Boot νλ‘μ νΈμμλ `initData` SQL μ€ν¬λ¦½νΈλ₯Ό ν΅ν΄ λ‘컬 DBμ μ΄κΈ° λ°μ΄ν°λ₯Ό μ½μ
ν μ μμ΅λλ€. μ΄λ₯Ό μν΄ **VM μ΅μ
μ€μ μ΄ λ°λμ νμ**ν©λλ€.
---
### π οΈ μ μ© λ°©λ²
1. **VM μ΅μ
μΆκ°**
```
-Dspring.sql.init.mode=always
```
2. **μλ² μ¬κΈ°λ**
* μ μ΅μ
μ μ μ©νκ³ μλ²λ₯Ό μ¬κΈ°λνλ©΄ λ€μκ³Ό κ°μ λμμ΄ μνλ©λλ€:
* **λͺ¨λ ν
μ΄λΈ DROP**
* **μ€ν€λ§ μ¬μμ± (CREATE)**
* **`01.init-data.sql` λ±μ μ΄κΈ°ν SQL μ€ν**
3. **μ΄κΈ°ν μλ£ ν νμ μμ
βΌοΈ**
```
VM μ΅μ
μ λ°λμ μλμ κ°μ΄ λ³κ²½:
-Dspring.sql.init.mode=never
```
* κ³μ `always` μνλ‘ λλ©΄, μλ² κΈ°λ μλ§λ€ λ°μ΄ν°κ° **λͺ¨λ μμ λ¨** β οΈβ οΈβ οΈ
---
### β οΈ μ΄μ νκ²½ μ£Όμμ¬ν
> π₯ **μ΄μ μλ²μλ μ λ `-Dspring.sql.init.mode=always` μ€μ μ μ¬μ©νμ§ λ§μΈμ!!**
> μ΄ μ€μ μ λͺ¨λ ν
μ΄λΈκ³Ό λ°μ΄ν°λ₯Ό μ κ±°νκ³ λ€μ μμ±νλ―λ‘,
> μ΄μ DBμ μ μ© μ **μΉλͺ
μ μΈ λ°μ΄ν° μμ€**μ΄ λ°μν μ μμ΅λλ€.
---
### βΉοΈ μ΅μ
μ€λͺ
| μ΅μ
κ° | μ€λͺ
|
| -------- | ----------------------------- |
| `never` | SQL μ΄κΈ°ν μ€ν¬λ¦½νΈ **μ€ννμ§ μμ** (κΈ°λ³Έ) |
| `always` | SQL μ΄κΈ°ν μ€ν¬λ¦½νΈ **νμ μ€νν¨** |
---
### π μ΄κΈ°ν μ€ν¬λ¦½νΈ μμΉ μμ
* `core/src/main/resources/sql/schema/02_create-table.sql` (DDL)
* `core/src/main/resources/sql/schema/02_create-function.sql` (DDL)
* `core/src/main/resources/sql/schema/02_create-view.sql` (DDL)
* `core/src/main/resources/sql/data/01_init_data.sql` (DML)
---
---
## π Jasypt μνΈν
* DB 컀λ₯μ
μ 보λ Jasyptλ‘ μνΈνλμ΄ μ¬μ©λ©λλ€.
* `admin`, `front` λͺ¨λ κ°κ°μ `JasyptConfig.java` μ€μ μ΄ ν¬ν¨λμ΄ μμ΅λλ€.
```yaml
jasypt:
encryptor:
password: # λ³λ κ΄λ¦¬
algorithm: # λ³λ κ΄λ¦¬
```
μμ:
```yaml
spring:
datasource:
kri:
jdbc-url: ENC(...)
username: ENC(...)
password: ENC(...)
mms:
jdbc-url: ENC(...)
username: ENC(...)
password: ENC(...)
```
μμ±_1 : pom.xmlμ μμ‘΄μ±μΆκ°
```pom
com.github.ulisesbocchio
jasypt-spring-boot-starter
3.0.5
```
μμ±_2 : ν΄λμ€ μμ± ν μ€ν
```java
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
public class EncryptTest {
public static void main(String[] args) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("λ΄JasyptλΉλ²"); // jasypt.encryptor.password κ°κ³Ό λμΌ
encryptor.setAlgorithm("PBEWITHHMACSHA512ANDAES_256"); // μ€μ μ λ§μΆ€
String plainText = "dbUserPassword"; // νλ¬Έ
String encrypted = encryptor.encrypt(plainText);
System.out.println("ENC(" + encrypted + ")");
}
}
```
μμ±_3 : μνΈν λ¬Έμμ΄ μμ±
```scss
ENC(mF3Z0fgCagFruOk/F2Z2PYzXhwGedE1secfYDgci+ke9z8xFEZ/GWbgXA4XeSq5D...)
```
μμ±_4 : 볡νΈν
```java
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
public class DecryptTest {
public static void main(String[] args) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("λ΄JasyptλΉλ²");
encryptor.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
String encrypted = "mF3Z0fgCagFruOk/..."; // ENC(...) μμͺ½
String decrypted = encryptor.decrypt(encrypted);
System.out.println("볡νΈν κ²°κ³Ό = " + decrypted);
}
}
```
---
## ποΈ DB ꡬμ±
| λͺ¨λ | μ°κ²° DB |
| ------- | ----------------------- |
| `admin` | kri DB, mms DB (λ¬Έμ λ°μ‘μ©) |
| `front` | kri DB |
---
## π λ€μ€ DB μ€μ (admin)
* `admin` λͺ¨λμλ `MMSDBConfig.java`λ₯Ό ν΅ν **mms μ μ© DataSource** μ€μ μ΄ μμ΅λλ€.
* MyBatis λ§€νΌλ λ³λ μμΉλ‘ ꡬλΆλ©λλ€.
```yaml
mybatis:
mapper-locations:
kri: classpath*:mappers/**/*Mapper.xml
mms: classpath*:mappers/mms/*Mapper.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
```
---
## π§© MyBatis λ€μ€ DB μ€μ μμ (`MMSDBConfig.java`)
```java
@MapperScan(
basePackages = "app.module.mms.**.persistence",
sqlSessionFactoryRef = "mmsSqlSessionFactory")
```
## π§ μΌκ³λΆ λ±λ‘ κ°λ₯ λ μ§
`DailyRecordConstants.java`λ **μΌκ³λΆ λ±λ‘ λ° μμ κ°λ₯ μμ μ λν μ μ±
μμ**λ₯Ό μ μνκ³ μμ΅λλ€.
---
### β
μ μ±
μ μ
| νλͺ© | μ μ±
μ€λͺ
| μμλͺ
| κ° |
| ------- | ------------------------ | ---------------------- |------------------------|
| λ±λ‘ κ°λ₯ μ | ν΄λΉ μ κΈ°μ€, **μ΄μ μλ§ λ±λ‘ κ°λ₯** | `REGISTER_LIMIT_MONTH` | `1` β *μμλ‘ `4` μ€μ μ€* |
| λ±λ‘ κ°λ₯ μΌ | ν΄λΉ μ **15μΌκΉμ§λ§ λ±λ‘ κ°λ₯** | `REGISTER_LIMIT_DAY` | `15` β *μμλ‘ `31` μ€μ μ€* |
| μμ κ°λ₯ μ | ν΄λΉ μ κΈ°μ€, **μ΄μ μλ§ μμ κ°λ₯** | `MODIFY_LIMIT_MONTH` | `1` β *μμλ‘ `4` μ€μ μ€* |
| μμ κ°λ₯ μΌ | ν΄λΉ μ **15μΌκΉμ§λ§ μμ κ°λ₯** | `MODIFY_LIMIT_DAY` | `15` β *μμλ‘ `31` μ€μ μ€* |
---
### β οΈ νμ¬ μμ μ€μ μ¬ν
νμ¬ μμ€ν
μμλ **λ±λ‘ κ°λ₯ μ(`REGISTER_LIMIT_MONTH`)** λ° **μμ κ°λ₯ μ(`MODIFY_LIMIT_MONTH`)** κ°μ **μμλ‘ `4λ¬` **λ±λ‘ κ°λ₯ μΌ(`REGISTER_LIMIT_DAY`)** λ° **μμ κ°λ₯ μΌ(`MODIFY_LIMIT_DAY`)** κ°μ **μμλ‘ `31μΌ`λ‘ μ€μ **ν΄ λμμΌλ©°,
**μ μ±
μ μλλ `15μΌ`λ‘ μ ν**λμ΄μΌ ν©λλ€.
> π ν₯ν μ΄μ μ μ±
μ λ°λΌ **`μ΄μ μ`** **`15μΌ`λ‘ λ³΅μ μμ **μΌλ‘ ν΄λΉκ°μΌλ‘ μμ ν warνμΌ μ 곡
---
## π€ νμΌ μ
λ‘λ
```bash
-Dpath.upload.public=/home/etribe/data/upload
```
νμΌ μ μ₯ ꡬ쑰λ `μ£Όμ /λ
μμΌ/νμΌλͺ
`μ΄λ©°, `FileUploadType` Enumμ λ°λΌ κ²½λ‘κ° κ²°μ λ©λλ€.
```java
fileUrlPortIn.getInline(type, path, name);
fileUrlPortIn.getAttachment(type, id);
```
---
## π§Ύ Audit κ³΅ν΅ νλ μλ μ£Όμ
* AOP κΈ°λ° μλ μ£Όμ
λ°©μμΌλ‘ μμ±/μμ /μμ μ νλ λ°λ³΅μ μ΅μνν©λλ€.
* κ³΅ν΅ νλ: `createdAt`, `createdBy`, `updatedAt`, `updatedBy`, `deletedAt`, `deletedBy`, `isDeleted`
| μ΄λ
Έν
μ΄μ
| μ£Όμ
νλ |
| ---------------- | ------------------------------------------ |
| `@CreateCommand` | createdAt, createdBy, updatedAt, updatedBy |
| `@UpdateCommand` | updatedAt, updatedBy |
| `@DeleteCommand` | deletedAt, deletedBy |
### β
κΈ°λ³Έ μ¬μ©λ²
λͺ¨λ Commandλ AuditCommandλ₯Ό μμνκ³ , Service/DAO λ©μλμ μ΄λ
Έν
μ΄μ
λ§ λΆμ΄λ©΄ μλμΌλ‘ νλμ κ°μ΄ μ£Όμ
λ©λλ€.
```java
@UpdateCommand
public void update(UpdateCmd cmd) {
mapper.update(cmd); // updatedAt, updatedBy μλ μ£Όμ
}
```
```java
public class UpdateCmd extends AuditCommand {
private Long seq;
}
```
### β
볡ν©μ μΈ CRUD μ²λ¦¬ μ
νλμ λ‘μ§ μμμ insert, update, delete λ± μ¬λ¬ DB μμ
μ΄ ν¨κ» μ²λ¦¬λλ κ²½μ°, `AuditUtil`μ μ νΈ λ©μλλ₯Ό μ¬μ©ν©λλ€.
```java
// κ΄λ¦¬μ λ±λ‘
mapper.insertAdmin(AuditUtil.create(cmd));
// κ΄λ¦¬μ μν λ§€ν (λ€κ±΄)
mapper.insertAdminHasRoles(
AuditUtil.create(new SaveAdminHasRoleParam(cmd.getSeq(), cmd.getRoleIds()))
);
```
---
## π XML κ³΅ν΅ νλ include
```xml
```
κ³΅ν΅ SQLμ `CommonFieldsMapper.xml` μ μ μλμ΄ μμ΅λλ€.
---
## π¦ ν¨ν€μ§ (WAR)
```bash
$ mvn clean package -P war
```
---
## π API νΈμΆ λ°©μ
### BO (κ΄λ¦¬μ)
| κΈ°λ₯ | λ°©μ | URI μμ |
| ------- | ---- | -------------------------------------- |
| λͺ©λ‘/λ±λ‘ λ± | Ajax | `/api/household/daily/list`, `/save` λ± |
| μμΈ μ‘°ν | SSR | `/household/{id}` |
### FO (μ¬μ©μ)
| κΈ°λ₯ | λ°©μ | URI μμ |
| -------- | ---- | -------------------------------------------------------- |
| λ±λ‘/μμ /μμ | Ajax | `/api/record/income/{searchMonth}/{groupNo}/form/{id}` λ± |
| λͺ©λ‘/μμΈ μ‘°ν | SSR | `/record/income/{searchMonth}/{groupNo}`, `/form/{id}` λ± |
---
## π λ‘κ·Έ μ€μ
```bash
-Dlogging.file.path=~/logs
```
| νμΌ μ΄λ¦ | μ€λͺ
|
| --------------------- | ------------ |
| `admin-app.log` | κ΄λ¦¬μ μ 체 λ‘κ·Έ |
| `admin-app-ERROR.log` | κ΄λ¦¬μ μλ¬ μ μ© λ‘κ·Έ |
| `front-app.log` | νλ‘ νΈ μ 체 λ‘κ·Έ |
| `front-app-ERROR.log` | νλ‘ νΈ μλ¬ μ μ© λ‘κ·Έ |
---
## β±οΈ λ°°μΉ μ€μΌμ€λ¬
`AutoSchedulesController.java`μ μ μλμ΄ μμΌλ©°, μ΄ 3κ°μ λ°°μΉκ° μ‘΄μ¬ν©λλ€.
| λ°°μΉλͺ
| μ€ν μ£ΌκΈ° | μ€λͺ
|
| ----------- | ------------ | -------------------------- |
| μλ³ μ
λ ₯ μν λ±λ‘ | λ§€μ 1μΌ 0μ 0μ΄ | μλ³ μ
λ ₯ μνλ₯Ό μ΄κΈ°ν λ±λ‘ν¨ |
| λ¬Έμ μλ λ°μ‘ | λ§€μΌ 17μ 0λΆ | mms DBλ‘λΆν° μμ λμ μΆμΆ ν λ¬Έμ λ°μ‘ |
| μμ΄ μ΄μκΈ λ±λ‘ | λ§€μ 16μΌ 0μ 0μ΄ | μ΄μ λ¬ λ°μ΄ν°λ₯Ό κΈ°μ€μΌλ‘ μ΄μκΈ λ±λ‘ |
---
## π€μ΄μμλ² ν
μ€νΈ κ³μ
κ³μ ID | λΉλ°λ²νΈ | κΆν |
| ------------ | ------- | ------- |
| `koadmin` | `0701!` | κ΄λ¦¬μ κΆν |
| `kolocal` | `0701@` | μ§λ°©μ€μ¬ κΆν |
| `kosearcher` | `0701#` | μ‘°μ¬μ κΆν |
---
## π§Ύ μ΄μμλ² μκ° κ³μ λͺ©λ‘
| μκ°λ²νΈ | λΉλ°λ²νΈ |
|---------| ------ |
| `22221` | `1111` |
| `22222` | `1111` |
| `22223` | `1111` |
| `22224` | `1111` |
| `22225` | `1111` |
| `22226` | `1111` |
---
## β μ€μ¬μ§μ μ€μ μ£Όμμ¬ν
ν
μ€νΈ κ³μ λ€μ **μ€μ¬μ§μμ΄ `ν
μ€νΈ`λ‘ μ§μ **λμ΄ μμ΅λλ€.
> μ΄λ‘ μΈν΄ ν΄λΉ κ³μ μΌλ‘ μμ§λ λ°μ΄ν°λ **ν΅κ³μ λ°μλμ§ μμ΅λλ€.**
**μ£Όμ:**β οΈ ν΅κ³μ ν¬ν¨λλλ‘ νλ €λ©΄ **μ€μ μ€μ¬μ§μ**μΌλ‘ λ§€νμ΄ νμν©λλ€.
---