feat: 가계부·게시판 백엔드 API 구현
- com.sb.web 패키지로 재구성: account / auth / board / user / admin / common - 가계부(account): 내역(필터), 계좌·순자산, 예산, 분류, 정기 거래, 투자 포트폴리오 (종목·매매 이력, 이동평균 평단·실현/평가손익) - MyBatis + MariaDB + Redis 세션, BCrypt - 스키마 자동 초기화(db/*.sql, 멱등), 사용자별 데이터 격리(member_id) - 문서: docs/BACKEND.md, .env.example Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -4,28 +4,39 @@ server:
|
||||
context-path: /
|
||||
|
||||
spring:
|
||||
# 로컬 개발 시 .env(properties 형식, git 미추적)에서 환경변수 로드. 없으면 OS/컨테이너 환경변수 사용.
|
||||
config:
|
||||
import: optional:file:.env[.properties]
|
||||
|
||||
application:
|
||||
name: sb_bt
|
||||
|
||||
# ===== MariaDB =====
|
||||
# ===== SQL 초기화 ===== 기동 시 member 테이블 자동 생성(IF NOT EXISTS 라 멱등)
|
||||
sql:
|
||||
init:
|
||||
mode: always
|
||||
schema-locations: classpath:db/member.sql,classpath:db/board.sql,classpath:db/account.sql,classpath:db/dev-seed.sql
|
||||
continue-on-error: true
|
||||
|
||||
# ===== MariaDB ===== (접속 정보는 환경변수로 외부화)
|
||||
datasource:
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
url: jdbc:mariadb://localhost:3306/sb_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul
|
||||
username: sb_user
|
||||
password: sb_pass
|
||||
url: ${DB_URL:jdbc:mariadb://localhost:3306/sb_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul}
|
||||
username: ${DB_USERNAME:root}
|
||||
password: ${DB_PASSWORD:}
|
||||
hikari:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 2
|
||||
connection-timeout: 30000
|
||||
pool-name: sbHikariPool
|
||||
|
||||
# ===== Redis =====
|
||||
# ===== Redis ===== (접속 정보는 환경변수로 외부화)
|
||||
data:
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password:
|
||||
database: 0
|
||||
host: ${REDIS_HOST:localhost}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PASSWORD:}
|
||||
database: ${REDIS_DATABASE:0}
|
||||
timeout: 3000ms
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -35,7 +46,7 @@ spring:
|
||||
|
||||
# ===== MyBatis =====
|
||||
mybatis:
|
||||
type-aliases-package: com.example.sb_bt.domain
|
||||
type-aliases-package: com.sb.web.user.domain,com.sb.web.auth.domain
|
||||
mapper-locations: classpath:mapper/**/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
@@ -47,5 +58,6 @@ mybatis:
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
com.example.sb_bt: DEBUG
|
||||
com.example.sb_bt.mapper: DEBUG
|
||||
com.sb.web: DEBUG
|
||||
com.sb.web.user.mapper: DEBUG
|
||||
com.sb.web.auth.mapper: DEBUG
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
-- ============================================================
|
||||
-- 가계부 스키마 (MariaDB) — account_entry
|
||||
-- 본인(member)이 등록한 내역만 조회 가능 (소유자 격리)
|
||||
-- 실행: 애플리케이션 기동 시 연결된 DB(sbdb)에 자동 생성 (IF NOT EXISTS)
|
||||
-- ============================================================
|
||||
|
||||
-- 계좌/카드/대출 (사용자별) — BANK(은행) / CARD(카드) / LOAN(대출)
|
||||
-- 잔액 부호: 자산(+) / 부채(카드·대출, −). opening_balance 는 기준일의 부호있는 시작 잔액.
|
||||
CREATE TABLE IF NOT EXISTS wallet (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
type VARCHAR(10) NOT NULL COMMENT 'BANK / CARD / LOAN / INVEST',
|
||||
name VARCHAR(50) NOT NULL COMMENT '별칭',
|
||||
issuer VARCHAR(50) NULL COMMENT '은행명/카드사/대출기관/증권사',
|
||||
account_number VARCHAR(50) NULL COMMENT '계좌번호(BANK)',
|
||||
card_type VARCHAR(10) NULL COMMENT 'CREDIT / CHECK (CARD)',
|
||||
opening_balance BIGINT NOT NULL DEFAULT 0 COMMENT '초기 잔액(부호있음: 자산+, 부채-)',
|
||||
opening_date DATE NULL COMMENT '초기잔액 기준일',
|
||||
current_value BIGINT NULL COMMENT '현재 평가금액(INVEST, 수동 갱신)',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_wallet_member (member_id, type)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 기존 wallet 컬럼 추가 (멱등)
|
||||
ALTER TABLE wallet ADD COLUMN IF NOT EXISTS opening_balance BIGINT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE wallet ADD COLUMN IF NOT EXISTS opening_date DATE NULL;
|
||||
ALTER TABLE wallet ADD COLUMN IF NOT EXISTS current_value BIGINT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS account_entry (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
entry_date DATE NOT NULL COMMENT '거래일',
|
||||
type VARCHAR(10) NOT NULL COMMENT 'INCOME / EXPENSE / TRANSFER',
|
||||
category VARCHAR(50) NULL COMMENT '분류(식비, 급여 등)',
|
||||
amount BIGINT NOT NULL COMMENT '금액(원, 양수)',
|
||||
memo VARCHAR(255) NULL,
|
||||
wallet_id BIGINT NULL COMMENT '발생/출금 계좌(wallet.id)',
|
||||
to_wallet_id BIGINT NULL COMMENT '이체 입금 계좌(TRANSFER)',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_account_member_date (member_id, entry_date)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 기존 account_entry 컬럼 추가 (멱등)
|
||||
ALTER TABLE account_entry ADD COLUMN IF NOT EXISTS wallet_id BIGINT NULL;
|
||||
ALTER TABLE account_entry ADD COLUMN IF NOT EXISTS to_wallet_id BIGINT NULL;
|
||||
|
||||
-- 가계부 태그 (사용자별 관리 — 게시판 태그와 분리)
|
||||
CREATE TABLE IF NOT EXISTS account_tag (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
name VARCHAR(50) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_account_tag_member_name (member_id, name),
|
||||
KEY idx_account_tag_member (member_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 정기/반복 거래 규칙 (사용자별)
|
||||
CREATE TABLE IF NOT EXISTS recurring (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
title VARCHAR(100) NOT NULL COMMENT '이름(월세, 급여 등)',
|
||||
type VARCHAR(10) NOT NULL COMMENT 'INCOME/EXPENSE/TRANSFER',
|
||||
amount BIGINT NOT NULL,
|
||||
category VARCHAR(50) NULL,
|
||||
memo VARCHAR(255) NULL,
|
||||
wallet_id BIGINT NULL COMMENT '발생/출금 계좌',
|
||||
to_wallet_id BIGINT NULL COMMENT '이체 입금 계좌',
|
||||
frequency VARCHAR(10) NOT NULL COMMENT 'DAILY/WEEKLY/MONTHLY/YEARLY',
|
||||
day_of_month INT NULL COMMENT 'MONTHLY/YEARLY (1~31)',
|
||||
day_of_week INT NULL COMMENT 'WEEKLY (1=월~7=일)',
|
||||
month_of_year INT NULL COMMENT 'YEARLY (1~12)',
|
||||
start_date DATE NOT NULL,
|
||||
end_date DATE NULL,
|
||||
last_run_date DATE NULL COMMENT '마지막 생성된 거래일',
|
||||
active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_recurring_member (member_id, active)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 분류(카테고리) — 사용자별, 수입/지출 타입
|
||||
CREATE TABLE IF NOT EXISTS account_category (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
type VARCHAR(10) NOT NULL COMMENT 'INCOME / EXPENSE',
|
||||
name VARCHAR(50) NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_category_member_type_name (member_id, type, name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 예산 (사용자별, 카테고리별)
|
||||
-- fixed=1(고정): base_unit/base_amount 로 일수기준 환산 / fixed=0(비고정): daily/weekly/monthly/yearly 직접
|
||||
CREATE TABLE IF NOT EXISTS budget (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
category VARCHAR(50) NOT NULL COMMENT '지출 분류',
|
||||
fixed TINYINT(1) NOT NULL DEFAULT 0,
|
||||
base_unit VARCHAR(10) NULL COMMENT 'DAY/WEEK/MONTH (고정)',
|
||||
base_amount BIGINT NULL COMMENT '고정 기준 금액',
|
||||
daily BIGINT NULL,
|
||||
weekly BIGINT NULL,
|
||||
monthly BIGINT NULL,
|
||||
yearly BIGINT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_budget_member_category (member_id, category)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 가계부 항목 - 태그 (다대다, tag_id 는 account_tag.id 참조)
|
||||
CREATE TABLE IF NOT EXISTS account_entry_tag (
|
||||
entry_id BIGINT NOT NULL,
|
||||
tag_id BIGINT NOT NULL,
|
||||
PRIMARY KEY (entry_id, tag_id),
|
||||
KEY idx_aet_tag (tag_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 투자 보유 종목 (INVEST 지갑별 · 사용자별)
|
||||
CREATE TABLE IF NOT EXISTS invest_holding (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
wallet_id BIGINT NOT NULL COMMENT '투자(INVEST) 지갑 wallet.id',
|
||||
name VARCHAR(100) NOT NULL COMMENT '종목명',
|
||||
ticker VARCHAR(20) NULL COMMENT '종목코드(선택)',
|
||||
current_price BIGINT NULL COMMENT '현재가(원, 수동 갱신)',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_holding_member_wallet (member_id, wallet_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 투자 매매 이력 (종목별 매수/매도)
|
||||
CREATE TABLE IF NOT EXISTS invest_trade (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
holding_id BIGINT NOT NULL COMMENT 'invest_holding.id',
|
||||
trade_type VARCHAR(10) NOT NULL COMMENT 'BUY / SELL',
|
||||
trade_date DATE NOT NULL,
|
||||
quantity BIGINT NOT NULL COMMENT '수량(주)',
|
||||
price BIGINT NOT NULL COMMENT '단가(원)',
|
||||
fee BIGINT NOT NULL DEFAULT 0 COMMENT '수수료/세금(원)',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_trade_member_holding (member_id, holding_id),
|
||||
KEY idx_trade_date (holding_id, trade_date, id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,79 @@
|
||||
-- ============================================================
|
||||
-- 자유게시판 스키마 (MariaDB) — post / tag / post_tag / comment
|
||||
-- 실행: 애플리케이션 기동 시 연결된 DB(sbdb)에 자동 생성됨 (IF NOT EXISTS)
|
||||
-- ============================================================
|
||||
|
||||
-- 게시글
|
||||
CREATE TABLE IF NOT EXISTS post (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
content LONGTEXT NOT NULL,
|
||||
author_id BIGINT NOT NULL COMMENT 'member.id',
|
||||
author_name VARCHAR(100) NOT NULL COMMENT '표시용(비정규화)',
|
||||
view_count INT NOT NULL DEFAULT 0,
|
||||
blocked TINYINT(1) NOT NULL DEFAULT 0 COMMENT '관리자 열람 제한 여부',
|
||||
block_reason VARCHAR(255) NULL COMMENT '제한 사유',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_post_created (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 기존 post 테이블에 컬럼 추가 (멱등)
|
||||
ALTER TABLE post ADD COLUMN IF NOT EXISTS blocked TINYINT(1) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE post ADD COLUMN IF NOT EXISTS block_reason VARCHAR(255) NULL;
|
||||
-- 큰 이미지(base64 인라인) 수용을 위해 content 를 LONGTEXT 로 확대 (멱등)
|
||||
ALTER TABLE post MODIFY content LONGTEXT NOT NULL;
|
||||
|
||||
-- 태그 카테고리(그룹) — 예: 게시판, 게시판2 ...
|
||||
CREATE TABLE IF NOT EXISTS tag_category (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_tag_category_name (name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 태그 (카테고리에 소속)
|
||||
CREATE TABLE IF NOT EXISTS tag (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
category_id BIGINT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_tag_name (name),
|
||||
KEY idx_tag_category (category_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 기존 tag 테이블에 category_id 가 없으면 추가 (멱등)
|
||||
ALTER TABLE tag ADD COLUMN IF NOT EXISTS category_id BIGINT NULL;
|
||||
|
||||
-- 게시글-태그 (다대다)
|
||||
CREATE TABLE IF NOT EXISTS post_tag (
|
||||
post_id BIGINT NOT NULL,
|
||||
tag_id BIGINT NOT NULL,
|
||||
PRIMARY KEY (post_id, tag_id),
|
||||
KEY idx_post_tag_tag (tag_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 게시판 설정 (단일 행) — 게시판에서 사용할 태그 카테고리 지정
|
||||
CREATE TABLE IF NOT EXISTS board_setting (
|
||||
id BIGINT NOT NULL,
|
||||
tag_category_id BIGINT NULL COMMENT '이 게시판에서 사용 가능한 태그 카테고리',
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO board_setting (id, tag_category_id) VALUES (1, NULL);
|
||||
|
||||
-- 댓글
|
||||
CREATE TABLE IF NOT EXISTS comment (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
post_id BIGINT NOT NULL,
|
||||
author_id BIGINT NOT NULL,
|
||||
author_name VARCHAR(100) NOT NULL,
|
||||
content VARCHAR(1000) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_comment_post (post_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,11 @@
|
||||
-- ============================================================
|
||||
-- 개발용 시드 (매 기동 시 실행, 멱등)
|
||||
-- ⚠️ 운영 배포 시에는 제거하세요.
|
||||
-- ============================================================
|
||||
|
||||
-- 테스트 계정 testuser01 을 관리자(ADMIN)로 승격
|
||||
UPDATE member SET role = 'ADMIN' WHERE login_id = 'testuser01';
|
||||
|
||||
-- 레거시(카테고리 미지정) 태그 정리: 새 태그 체계는 모두 카테고리에 소속됨
|
||||
DELETE FROM post_tag WHERE tag_id IN (SELECT id FROM (SELECT id FROM tag WHERE category_id IS NULL) x);
|
||||
DELETE FROM tag WHERE category_id IS NULL;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- ============================================================
|
||||
-- 회원(member) 테이블 (MariaDB)
|
||||
-- 로컬(아이디/비밀번호) + 소셜(네이버 등) 로그인 확장을 고려한 설계
|
||||
-- 실행: 애플리케이션 기동 시 연결된 DB(sbdb)에 자동 생성됨
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS member (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
login_id VARCHAR(50) NULL COMMENT '로컬 로그인 아이디 (소셜 전용 계정은 NULL)',
|
||||
password VARCHAR(100) NULL COMMENT 'BCrypt 해시 (소셜 전용 계정은 NULL)',
|
||||
name VARCHAR(100) NOT NULL COMMENT '이름/닉네임',
|
||||
email VARCHAR(255) NULL,
|
||||
provider VARCHAR(20) NOT NULL DEFAULT 'LOCAL' COMMENT 'LOCAL / NAVER',
|
||||
provider_id VARCHAR(100) NULL COMMENT '소셜 제공자 측 고유 사용자 ID',
|
||||
role VARCHAR(20) NOT NULL DEFAULT 'USER' COMMENT 'USER / ADMIN',
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE' COMMENT 'ACTIVE / SUSPENDED / WITHDRAWN',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_member_login_id (login_id),
|
||||
UNIQUE KEY uk_member_provider (provider, provider_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.AccountEntryMapper">
|
||||
|
||||
<resultMap id="entryResultMap" type="com.sb.web.account.domain.AccountEntry">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="entryDate" column="entry_date"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="category" column="category"/>
|
||||
<result property="amount" column="amount"/>
|
||||
<result property="memo" column="memo"/>
|
||||
<result property="walletId" column="wallet_id"/>
|
||||
<result property="walletName" column="wallet_name"/>
|
||||
<result property="toWalletId" column="to_wallet_id"/>
|
||||
<result property="toWalletName" column="to_wallet_name"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="periodFilter">
|
||||
<if test="year != null">AND YEAR(entry_date) = #{year}</if>
|
||||
<if test="month != null">AND MONTH(entry_date) = #{month}</if>
|
||||
</sql>
|
||||
|
||||
<sql id="entryCols">
|
||||
e.id, e.member_id, e.entry_date, e.type, e.category, e.amount, e.memo,
|
||||
e.wallet_id, w.name AS wallet_name,
|
||||
e.to_wallet_id, tw.name AS to_wallet_name,
|
||||
e.created_at, e.updated_at
|
||||
</sql>
|
||||
<sql id="entryJoins">
|
||||
FROM account_entry e
|
||||
LEFT JOIN wallet w ON w.id = e.wallet_id
|
||||
LEFT JOIN wallet tw ON tw.id = e.to_wallet_id
|
||||
</sql>
|
||||
|
||||
<select id="findByMember" resultMap="entryResultMap">
|
||||
SELECT <include refid="entryCols"/>
|
||||
<include refid="entryJoins"/>
|
||||
WHERE e.member_id = #{memberId}
|
||||
<if test="year != null">AND YEAR(e.entry_date) = #{year}</if>
|
||||
<if test="month != null">AND MONTH(e.entry_date) = #{month}</if>
|
||||
<if test="type != null and type != ''">AND e.type = #{type}</if>
|
||||
<if test="category != null and category != ''">AND e.category = #{category}</if>
|
||||
<if test="walletId != null">AND (e.wallet_id = #{walletId} OR e.to_wallet_id = #{walletId})</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (e.memo LIKE CONCAT('%', #{keyword}, '%') OR e.category LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
<if test="tagId != null">
|
||||
AND EXISTS (SELECT 1 FROM account_entry_tag aet WHERE aet.entry_id = e.id AND aet.tag_id = #{tagId})
|
||||
</if>
|
||||
ORDER BY e.entry_date DESC, e.id DESC
|
||||
</select>
|
||||
|
||||
<select id="findByWalletAndMember" resultMap="entryResultMap">
|
||||
SELECT <include refid="entryCols"/>
|
||||
<include refid="entryJoins"/>
|
||||
WHERE e.member_id = #{memberId}
|
||||
AND (e.wallet_id = #{walletId} OR e.to_wallet_id = #{walletId})
|
||||
ORDER BY e.entry_date DESC, e.id DESC
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="entryResultMap">
|
||||
SELECT <include refid="entryCols"/>
|
||||
<include refid="entryJoins"/>
|
||||
WHERE e.id = #{id} AND e.member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="sumByType" resultType="map">
|
||||
SELECT type AS type, COALESCE(SUM(amount), 0) AS total
|
||||
FROM account_entry
|
||||
WHERE member_id = #{memberId}
|
||||
<include refid="periodFilter"/>
|
||||
GROUP BY type
|
||||
</select>
|
||||
|
||||
<select id="sumExpenseByCategory" resultType="map">
|
||||
SELECT COALESCE(category, '') AS category, COALESCE(SUM(amount), 0) AS total
|
||||
FROM account_entry
|
||||
WHERE member_id = #{memberId} AND type = 'EXPENSE'
|
||||
<include refid="periodFilter"/>
|
||||
GROUP BY category
|
||||
</select>
|
||||
|
||||
<select id="sumByCategory" resultType="map">
|
||||
SELECT COALESCE(NULLIF(category, ''), '미분류') AS category, COALESCE(SUM(amount), 0) AS total
|
||||
FROM account_entry
|
||||
WHERE member_id = #{memberId} AND type = #{type}
|
||||
<include refid="periodFilter"/>
|
||||
GROUP BY COALESCE(NULLIF(category, ''), '미분류')
|
||||
ORDER BY total DESC
|
||||
</select>
|
||||
|
||||
<select id="monthlyWalletFlow" resultType="map">
|
||||
SELECT DATE_FORMAT(entry_date, '%Y-%m') AS ym,
|
||||
COALESCE(SUM(CASE WHEN type = 'INCOME' THEN amount
|
||||
WHEN type = 'EXPENSE' THEN -amount
|
||||
ELSE 0 END), 0) AS net
|
||||
FROM account_entry
|
||||
WHERE member_id = #{memberId} AND wallet_id IS NOT NULL AND type IN ('INCOME', 'EXPENSE')
|
||||
GROUP BY ym
|
||||
ORDER BY ym
|
||||
</select>
|
||||
|
||||
<select id="statsByPeriod" resultType="map">
|
||||
SELECT
|
||||
<choose>
|
||||
<when test="unit == 'DAY'">DAY(entry_date)</when>
|
||||
<when test="unit == 'WEEK'">FLOOR((DAY(entry_date) - 1) / 7) + 1</when>
|
||||
<when test="unit == 'YEAR'">YEAR(entry_date)</when>
|
||||
<otherwise>MONTH(entry_date)</otherwise>
|
||||
</choose> AS bucket,
|
||||
COALESCE(SUM(CASE WHEN type = 'INCOME' THEN amount ELSE 0 END), 0) AS income,
|
||||
COALESCE(SUM(CASE WHEN type = 'EXPENSE' THEN amount ELSE 0 END), 0) AS expense
|
||||
FROM account_entry
|
||||
WHERE member_id = #{memberId}
|
||||
<if test="unit == 'DAY' or unit == 'WEEK' or unit == 'MONTH'">AND YEAR(entry_date) = #{year}</if>
|
||||
<if test="unit == 'DAY' or unit == 'WEEK'">AND MONTH(entry_date) = #{month}</if>
|
||||
GROUP BY bucket
|
||||
ORDER BY bucket
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.AccountEntry"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO account_entry (member_id, entry_date, type, category, amount, memo,
|
||||
wallet_id, to_wallet_id, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{entryDate}, #{type}, #{category}, #{amount}, #{memo},
|
||||
#{walletId}, #{toWalletId}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.AccountEntry">
|
||||
UPDATE account_entry
|
||||
SET entry_date = #{entryDate}, type = #{type}, category = #{category},
|
||||
amount = #{amount}, memo = #{memo}, wallet_id = #{walletId}, to_wallet_id = #{toWalletId}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM account_entry WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<select id="findDistinctCategories" resultType="string">
|
||||
SELECT DISTINCT category FROM account_entry
|
||||
WHERE member_id = #{memberId} AND type = #{type}
|
||||
AND category IS NOT NULL AND category != ''
|
||||
ORDER BY category
|
||||
</select>
|
||||
|
||||
<update id="renameCategory">
|
||||
UPDATE account_entry SET category = #{newName}
|
||||
WHERE member_id = #{memberId} AND type = #{type} AND category = #{oldName}
|
||||
</update>
|
||||
|
||||
<!-- ===== 항목-태그 ===== -->
|
||||
<insert id="insertEntryTag">
|
||||
INSERT INTO account_entry_tag (entry_id, tag_id) VALUES (#{entryId}, #{tagId})
|
||||
</insert>
|
||||
|
||||
<delete id="deleteEntryTagsByEntryId" parameterType="long">
|
||||
DELETE FROM account_entry_tag WHERE entry_id = #{entryId}
|
||||
</delete>
|
||||
|
||||
<select id="findTagNamesByEntryId" parameterType="long" resultType="string">
|
||||
SELECT t.name
|
||||
FROM account_tag t
|
||||
JOIN account_entry_tag aet ON aet.tag_id = t.id
|
||||
WHERE aet.entry_id = #{entryId}
|
||||
ORDER BY t.name
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.AccountTagMapper">
|
||||
|
||||
<resultMap id="tagResultMap" type="com.sb.web.account.domain.AccountTag">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="tagResultMap">
|
||||
SELECT id, member_id, name, created_at
|
||||
FROM account_tag
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="tagResultMap">
|
||||
SELECT id, member_id, name, created_at
|
||||
FROM account_tag
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM account_tag
|
||||
WHERE member_id = #{memberId} AND name = #{name}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.AccountTag"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO account_tag (member_id, name, created_at)
|
||||
VALUES (#{memberId}, #{name}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.AccountTag">
|
||||
UPDATE account_tag SET name = #{name}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM account_tag WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<select id="findExistingIds" resultType="long">
|
||||
SELECT id FROM account_tag
|
||||
WHERE member_id = #{memberId} AND id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<delete id="deleteEntryLinksByTagId" parameterType="long">
|
||||
DELETE FROM account_entry_tag WHERE tag_id = #{tagId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.board.mapper.BoardSettingMapper">
|
||||
|
||||
<select id="findTagCategoryId" resultType="java.lang.Long">
|
||||
SELECT tag_category_id FROM board_setting WHERE id = 1
|
||||
</select>
|
||||
|
||||
<update id="updateTagCategoryId">
|
||||
UPDATE board_setting SET tag_category_id = #{categoryId} WHERE id = 1
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.BudgetMapper">
|
||||
|
||||
<resultMap id="budgetResultMap" type="com.sb.web.account.domain.Budget">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="category" column="category"/>
|
||||
<result property="fixed" column="fixed"/>
|
||||
<result property="baseUnit" column="base_unit"/>
|
||||
<result property="baseAmount" column="base_amount"/>
|
||||
<result property="daily" column="daily"/>
|
||||
<result property="weekly" column="weekly"/>
|
||||
<result property="monthly" column="monthly"/>
|
||||
<result property="yearly" column="yearly"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="cols">id, member_id, category, fixed, base_unit, base_amount,
|
||||
daily, weekly, monthly, yearly, created_at, updated_at</sql>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="budgetResultMap">
|
||||
SELECT <include refid="cols"/> FROM budget WHERE member_id = #{memberId} ORDER BY category
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="budgetResultMap">
|
||||
SELECT <include refid="cols"/> FROM budget WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="countByCategory" resultType="int">
|
||||
SELECT COUNT(*) FROM budget
|
||||
WHERE member_id = #{memberId} AND category = #{category}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.Budget"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO budget (member_id, category, fixed, base_unit, base_amount,
|
||||
daily, weekly, monthly, yearly, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{category}, #{fixed}, #{baseUnit}, #{baseAmount},
|
||||
#{daily}, #{weekly}, #{monthly}, #{yearly}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.Budget">
|
||||
UPDATE budget
|
||||
SET category = #{category}, fixed = #{fixed}, base_unit = #{baseUnit}, base_amount = #{baseAmount},
|
||||
daily = #{daily}, weekly = #{weekly}, monthly = #{monthly}, yearly = #{yearly}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM budget WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<update id="renameCategory">
|
||||
UPDATE budget SET category = #{newName}
|
||||
WHERE member_id = #{memberId} AND category = #{oldName}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.CategoryMapper">
|
||||
|
||||
<resultMap id="categoryResultMap" type="com.sb.web.account.domain.AccountCategory">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="categoryResultMap">
|
||||
SELECT id, member_id, type, name, sort_order, created_at
|
||||
FROM account_category
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY type, sort_order, name
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="categoryResultMap">
|
||||
SELECT id, member_id, type, name, sort_order, created_at
|
||||
FROM account_category
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM account_category
|
||||
WHERE member_id = #{memberId} AND type = #{type} AND name = #{name}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.AccountCategory"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO account_category (member_id, type, name, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, #{sortOrder}, NOW())
|
||||
</insert>
|
||||
|
||||
<insert id="insertIgnore" parameterType="com.sb.web.account.domain.AccountCategory">
|
||||
INSERT IGNORE INTO account_category (member_id, type, name, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, 0, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.AccountCategory">
|
||||
UPDATE account_category SET name = #{name}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM account_category WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.board.mapper.CommentMapper">
|
||||
|
||||
<resultMap id="commentResultMap" type="com.sb.web.board.domain.Comment">
|
||||
<id property="id" column="id"/>
|
||||
<result property="postId" column="post_id"/>
|
||||
<result property="authorId" column="author_id"/>
|
||||
<result property="authorName" column="author_name"/>
|
||||
<result property="content" column="content"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findByPostId" parameterType="long" resultMap="commentResultMap">
|
||||
SELECT id, post_id, author_id, author_name, content, created_at
|
||||
FROM comment
|
||||
WHERE post_id = #{postId}
|
||||
ORDER BY id ASC
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="commentResultMap">
|
||||
SELECT id, post_id, author_id, author_name, content, created_at
|
||||
FROM comment
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.board.domain.Comment"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO comment (post_id, author_id, author_name, content, created_at)
|
||||
VALUES (#{postId}, #{authorId}, #{authorName}, #{content}, NOW())
|
||||
</insert>
|
||||
|
||||
<delete id="delete" parameterType="long">
|
||||
DELETE FROM comment WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByPostId" parameterType="long">
|
||||
DELETE FROM comment WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.InvestMapper">
|
||||
|
||||
<resultMap id="holdingMap" type="com.sb.web.account.domain.InvestHolding">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="walletId" column="wallet_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="ticker" column="ticker"/>
|
||||
<result property="currentPrice" column="current_price"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="tradeMap" type="com.sb.web.account.domain.InvestTrade">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="holdingId" column="holding_id"/>
|
||||
<result property="tradeType" column="trade_type"/>
|
||||
<result property="tradeDate" column="trade_date"/>
|
||||
<result property="quantity" column="quantity"/>
|
||||
<result property="price" column="price"/>
|
||||
<result property="fee" column="fee"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="holdingCols">id, member_id, wallet_id, name, ticker, current_price, created_at, updated_at</sql>
|
||||
<sql id="tradeCols">id, member_id, holding_id, trade_type, trade_date, quantity, price, fee, created_at</sql>
|
||||
|
||||
<!-- ===== 보유 종목 ===== -->
|
||||
<select id="findHoldingsByMember" resultMap="holdingMap">
|
||||
SELECT <include refid="holdingCols"/> FROM invest_holding
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY id
|
||||
</select>
|
||||
|
||||
<select id="findHoldingsByWallet" resultMap="holdingMap">
|
||||
SELECT <include refid="holdingCols"/> FROM invest_holding
|
||||
WHERE member_id = #{memberId} AND wallet_id = #{walletId}
|
||||
ORDER BY id
|
||||
</select>
|
||||
|
||||
<select id="findHoldingByIdAndMember" resultMap="holdingMap">
|
||||
SELECT <include refid="holdingCols"/> FROM invest_holding
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<insert id="insertHolding" parameterType="com.sb.web.account.domain.InvestHolding"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO invest_holding (member_id, wallet_id, name, ticker, current_price, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{walletId}, #{name}, #{ticker}, #{currentPrice}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="updateHolding" parameterType="com.sb.web.account.domain.InvestHolding">
|
||||
UPDATE invest_holding
|
||||
SET name = #{name}, ticker = #{ticker}, current_price = #{currentPrice}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteHolding">
|
||||
DELETE FROM invest_holding WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<!-- ===== 매매 이력 ===== -->
|
||||
<select id="findTradesByMember" resultMap="tradeMap">
|
||||
SELECT <include refid="tradeCols"/> FROM invest_trade
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY holding_id, trade_date, id
|
||||
</select>
|
||||
|
||||
<select id="findTradesByHolding" resultMap="tradeMap">
|
||||
SELECT <include refid="tradeCols"/> FROM invest_trade
|
||||
WHERE holding_id = #{holdingId} AND member_id = #{memberId}
|
||||
ORDER BY trade_date, id
|
||||
</select>
|
||||
|
||||
<select id="findTradeByIdAndMember" resultMap="tradeMap">
|
||||
SELECT <include refid="tradeCols"/> FROM invest_trade
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<insert id="insertTrade" parameterType="com.sb.web.account.domain.InvestTrade"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO invest_trade (member_id, holding_id, trade_type, trade_date, quantity, price, fee, created_at)
|
||||
VALUES (#{memberId}, #{holdingId}, #{tradeType}, #{tradeDate}, #{quantity}, #{price}, #{fee}, NOW())
|
||||
</insert>
|
||||
|
||||
<delete id="deleteTrade">
|
||||
DELETE FROM invest_trade WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTradesByHolding">
|
||||
DELETE FROM invest_trade WHERE holding_id = #{holdingId} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.auth.mapper.MemberMapper">
|
||||
|
||||
<resultMap id="memberResultMap" type="com.sb.web.auth.domain.Member">
|
||||
<id property="id" column="id"/>
|
||||
<result property="loginId" column="login_id"/>
|
||||
<result property="password" column="password"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="email" column="email"/>
|
||||
<result property="provider" column="provider"/>
|
||||
<result property="providerId" column="provider_id"/>
|
||||
<result property="role" column="role"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="columns">
|
||||
id, login_id, password, name, email, provider, provider_id, role, status, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="memberResultMap">
|
||||
SELECT <include refid="columns"/> FROM member WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findByLoginId" parameterType="string" resultMap="memberResultMap">
|
||||
SELECT <include refid="columns"/> FROM member WHERE login_id = #{loginId}
|
||||
</select>
|
||||
|
||||
<select id="findByProvider" resultMap="memberResultMap">
|
||||
SELECT <include refid="columns"/>
|
||||
FROM member
|
||||
WHERE provider = #{provider} AND provider_id = #{providerId}
|
||||
</select>
|
||||
|
||||
<select id="countByLoginId" parameterType="string" resultType="int">
|
||||
SELECT COUNT(*) FROM member WHERE login_id = #{loginId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.auth.domain.Member"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO member (login_id, password, name, email, provider, provider_id, role, status, created_at, updated_at)
|
||||
VALUES (#{loginId}, #{password}, #{name}, #{email},
|
||||
#{provider}, #{providerId}, #{role}, #{status}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.board.mapper.PostMapper">
|
||||
|
||||
<sql id="filter">
|
||||
<if test="tag != null and tag != ''">
|
||||
JOIN post_tag pt ON pt.post_id = p.id
|
||||
JOIN tag t ON t.id = pt.tag_id
|
||||
</if>
|
||||
<where>
|
||||
<if test="tag != null and tag != ''">
|
||||
t.name = #{tag}
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
<choose>
|
||||
<when test="searchType == 'content'">
|
||||
AND p.content LIKE CONCAT('%', #{keyword}, '%')
|
||||
</when>
|
||||
<when test="searchType == 'comment'">
|
||||
AND EXISTS (SELECT 1 FROM comment c
|
||||
WHERE c.post_id = p.id
|
||||
AND c.content LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</when>
|
||||
<otherwise>
|
||||
AND p.title LIKE CONCAT('%', #{keyword}, '%')
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findPage" resultType="com.sb.web.board.dto.PostSummary">
|
||||
SELECT
|
||||
p.id, p.title, p.author_name, p.view_count, p.blocked, p.created_at,
|
||||
(SELECT COUNT(*) FROM comment c WHERE c.post_id = p.id) AS comment_count
|
||||
FROM post p
|
||||
<include refid="filter"/>
|
||||
ORDER BY p.id DESC
|
||||
LIMIT #{size} OFFSET #{offset}
|
||||
</select>
|
||||
|
||||
<select id="countPage" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM post p
|
||||
<include refid="filter"/>
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="long" resultType="com.sb.web.board.domain.Post">
|
||||
SELECT id, title, content, author_id, author_name, view_count,
|
||||
blocked, block_reason, created_at, updated_at
|
||||
FROM post
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.board.domain.Post"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO post (title, content, author_id, author_name, view_count, created_at, updated_at)
|
||||
VALUES (#{title}, #{content}, #{authorId}, #{authorName}, 0, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.board.domain.Post">
|
||||
UPDATE post
|
||||
SET title = #{title}, content = #{content}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete" parameterType="long">
|
||||
DELETE FROM post WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="increaseViewCount" parameterType="long">
|
||||
UPDATE post SET view_count = view_count + 1 WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateBlocked">
|
||||
UPDATE post SET blocked = #{blocked}, block_reason = #{blockReason} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.RecurringMapper">
|
||||
|
||||
<resultMap id="recurringResultMap" type="com.sb.web.account.domain.Recurring">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="title" column="title"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="amount" column="amount"/>
|
||||
<result property="category" column="category"/>
|
||||
<result property="memo" column="memo"/>
|
||||
<result property="walletId" column="wallet_id"/>
|
||||
<result property="walletName" column="wallet_name"/>
|
||||
<result property="toWalletId" column="to_wallet_id"/>
|
||||
<result property="toWalletName" column="to_wallet_name"/>
|
||||
<result property="frequency" column="frequency"/>
|
||||
<result property="dayOfMonth" column="day_of_month"/>
|
||||
<result property="dayOfWeek" column="day_of_week"/>
|
||||
<result property="monthOfYear" column="month_of_year"/>
|
||||
<result property="startDate" column="start_date"/>
|
||||
<result property="endDate" column="end_date"/>
|
||||
<result property="lastRunDate" column="last_run_date"/>
|
||||
<result property="active" column="active"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectJoin">
|
||||
SELECT r.id, r.member_id, r.title, r.type, r.amount, r.category, r.memo,
|
||||
r.wallet_id, w.name AS wallet_name, r.to_wallet_id, tw.name AS to_wallet_name,
|
||||
r.frequency, r.day_of_month, r.day_of_week, r.month_of_year,
|
||||
r.start_date, r.end_date, r.last_run_date, r.active
|
||||
FROM recurring r
|
||||
LEFT JOIN wallet w ON w.id = r.wallet_id
|
||||
LEFT JOIN wallet tw ON tw.id = r.to_wallet_id
|
||||
</sql>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="recurringResultMap">
|
||||
<include refid="selectJoin"/>
|
||||
WHERE r.member_id = #{memberId}
|
||||
ORDER BY r.active DESC, r.title
|
||||
</select>
|
||||
|
||||
<select id="findActiveByMember" parameterType="long" resultMap="recurringResultMap">
|
||||
<include refid="selectJoin"/>
|
||||
WHERE r.member_id = #{memberId} AND r.active = 1
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="recurringResultMap">
|
||||
<include refid="selectJoin"/>
|
||||
WHERE r.id = #{id} AND r.member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.Recurring"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO recurring (member_id, title, type, amount, category, memo, wallet_id, to_wallet_id,
|
||||
frequency, day_of_month, day_of_week, month_of_year,
|
||||
start_date, end_date, last_run_date, active, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{title}, #{type}, #{amount}, #{category}, #{memo}, #{walletId}, #{toWalletId},
|
||||
#{frequency}, #{dayOfMonth}, #{dayOfWeek}, #{monthOfYear},
|
||||
#{startDate}, #{endDate}, #{lastRunDate}, #{active}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.Recurring">
|
||||
UPDATE recurring
|
||||
SET title = #{title}, type = #{type}, amount = #{amount}, category = #{category}, memo = #{memo},
|
||||
wallet_id = #{walletId}, to_wallet_id = #{toWalletId},
|
||||
frequency = #{frequency}, day_of_month = #{dayOfMonth}, day_of_week = #{dayOfWeek},
|
||||
month_of_year = #{monthOfYear}, start_date = #{startDate}, end_date = #{endDate}, active = #{active}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM recurring WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
<update id="updateLastRun">
|
||||
UPDATE recurring SET last_run_date = #{lastRunDate} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.board.mapper.TagCategoryMapper">
|
||||
|
||||
<resultMap id="categoryResultMap" type="com.sb.web.board.domain.TagCategory">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findAll" resultMap="categoryResultMap">
|
||||
SELECT id, name, sort_order, created_at
|
||||
FROM tag_category
|
||||
ORDER BY sort_order ASC, id ASC
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="categoryResultMap">
|
||||
SELECT id, name, sort_order, created_at
|
||||
FROM tag_category
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM tag_category
|
||||
WHERE name = #{name}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.board.domain.TagCategory"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO tag_category (name, sort_order, created_at)
|
||||
VALUES (#{name}, #{sortOrder}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.board.domain.TagCategory">
|
||||
UPDATE tag_category
|
||||
SET name = #{name}, sort_order = #{sortOrder}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete" parameterType="long">
|
||||
DELETE FROM tag_category WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.board.mapper.TagMapper">
|
||||
|
||||
<resultMap id="tagResultMap" type="com.sb.web.board.domain.Tag">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="categoryId" column="category_id"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- ===== 게시글 작성/표시 ===== -->
|
||||
<select id="findNamesByPostId" parameterType="long" resultType="string">
|
||||
SELECT t.name
|
||||
FROM tag t
|
||||
JOIN post_tag pt ON pt.tag_id = t.id
|
||||
WHERE pt.post_id = #{postId}
|
||||
ORDER BY t.name
|
||||
</select>
|
||||
|
||||
<select id="findAllNames" resultType="string">
|
||||
SELECT name FROM tag ORDER BY name
|
||||
</select>
|
||||
|
||||
<insert id="insertPostTag">
|
||||
INSERT INTO post_tag (post_id, tag_id) VALUES (#{postId}, #{tagId})
|
||||
</insert>
|
||||
|
||||
<delete id="deletePostTagsByPostId" parameterType="long">
|
||||
DELETE FROM post_tag WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
<select id="findExistingIds" resultType="long">
|
||||
SELECT id FROM tag
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- ===== 관리자 태그 CRUD ===== -->
|
||||
<select id="findAll" resultMap="tagResultMap">
|
||||
SELECT id, name, category_id FROM tag ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="findByCategoryId" parameterType="long" resultMap="tagResultMap">
|
||||
SELECT id, name, category_id FROM tag WHERE category_id = #{categoryId} ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="tagResultMap">
|
||||
SELECT id, name, category_id FROM tag WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM tag
|
||||
WHERE name = #{name}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.board.domain.Tag"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO tag (name, category_id) VALUES (#{name}, #{categoryId})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.board.domain.Tag">
|
||||
UPDATE tag SET name = #{name}, category_id = #{categoryId} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete" parameterType="long">
|
||||
DELETE FROM tag WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deletePostTagsByTagId" parameterType="long">
|
||||
DELETE FROM post_tag WHERE tag_id = #{tagId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.sb_bt.mapper.UserMapper">
|
||||
<mapper namespace="com.sb.web.user.mapper.UserMapper">
|
||||
|
||||
<resultMap id="userResultMap" type="User">
|
||||
<id property="id" column="id"/>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.account.mapper.WalletMapper">
|
||||
|
||||
<resultMap id="walletResultMap" type="com.sb.web.account.domain.Wallet">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="issuer" column="issuer"/>
|
||||
<result property="accountNumber" column="account_number"/>
|
||||
<result property="cardType" column="card_type"/>
|
||||
<result property="openingBalance" column="opening_balance"/>
|
||||
<result property="openingDate" column="opening_date"/>
|
||||
<result property="currentValue" column="current_value"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="cols">id, member_id, type, name, issuer, account_number, card_type,
|
||||
opening_balance, opening_date, current_value, created_at, updated_at</sql>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="walletResultMap">
|
||||
SELECT <include refid="cols"/> FROM wallet
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY type, name
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="walletResultMap">
|
||||
SELECT <include refid="cols"/> FROM wallet
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.Wallet"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wallet (member_id, type, name, issuer, account_number, card_type,
|
||||
opening_balance, opening_date, current_value, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, #{issuer}, #{accountNumber}, #{cardType},
|
||||
#{openingBalance}, #{openingDate}, #{currentValue}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.Wallet">
|
||||
UPDATE wallet
|
||||
SET type = #{type}, name = #{name}, issuer = #{issuer},
|
||||
account_number = #{accountNumber}, card_type = #{cardType},
|
||||
opening_balance = #{openingBalance}, opening_date = #{openingDate},
|
||||
current_value = #{currentValue}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
<!-- 계좌별 현재 잔액 = 초기잔액 + 수입 - 지출 - 이체출금 + 이체입금 -->
|
||||
<select id="findBalances" parameterType="long" resultType="map">
|
||||
SELECT w.id AS id,
|
||||
w.opening_balance
|
||||
+ COALESCE((SELECT SUM(e.amount) FROM account_entry e
|
||||
WHERE e.member_id = w.member_id AND e.type = 'INCOME' AND e.wallet_id = w.id), 0)
|
||||
- COALESCE((SELECT SUM(e.amount) FROM account_entry e
|
||||
WHERE e.member_id = w.member_id AND e.type = 'EXPENSE' AND e.wallet_id = w.id), 0)
|
||||
- COALESCE((SELECT SUM(e.amount) FROM account_entry e
|
||||
WHERE e.member_id = w.member_id AND e.type = 'TRANSFER' AND e.wallet_id = w.id), 0)
|
||||
+ COALESCE((SELECT SUM(e.amount) FROM account_entry e
|
||||
WHERE e.member_id = w.member_id AND e.type = 'TRANSFER' AND e.to_wallet_id = w.id), 0)
|
||||
AS balance
|
||||
FROM wallet w
|
||||
WHERE w.member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM wallet WHERE id = #{id} AND member_id = #{memberId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user