- default_category 테이블(전체 공용) + 도메인/매퍼/서비스 - 관리자 API /api/admin/default-categories (CRUD·reorder, ADMIN 보호) - 사용자 /account/categories/import: 기존 내역 기반 → 기본분류 복사로 변경 (대/소분류 계층 유지, 같은 이름은 건너뜀; CategoryMapper.findByMemberTypeName 추가) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,18 @@ CREATE TABLE IF NOT EXISTS account_category (
|
||||
-- 대/소분류 계층 추가(기존 DB 마이그레이션) — 소분류 이름은 그대로, parent_id 만 부여
|
||||
ALTER TABLE account_category ADD COLUMN IF NOT EXISTS parent_id BIGINT NULL COMMENT '대분류 id. NULL=대분류, 값=소분류';
|
||||
|
||||
-- 기본(디폴트) 분류 — 전체 사용자 공용 템플릿(관리자 관리). 사용자가 '기본 분류 불러오기'로 자기 분류에 복사.
|
||||
CREATE TABLE IF NOT EXISTS default_category (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
type VARCHAR(10) NOT NULL COMMENT 'INCOME / EXPENSE',
|
||||
name VARCHAR(50) NOT NULL,
|
||||
parent_id BIGINT NULL COMMENT '대분류 id(default_category.id). NULL=대분류, 값=소분류',
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_default_category_type_name (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 (
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
WHERE member_id = #{memberId} AND parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="findByMemberTypeName" resultMap="categoryResultMap">
|
||||
SELECT id, member_id, type, name, parent_id, sort_order, created_at
|
||||
FROM account_category
|
||||
WHERE member_id = #{memberId} AND type = #{type} AND name = #{name}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM account_category
|
||||
WHERE member_id = #{memberId} AND type = #{type} AND name = #{name}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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.DefaultCategoryMapper">
|
||||
|
||||
<resultMap id="defaultCategoryResultMap" type="com.sb.web.account.domain.DefaultCategory">
|
||||
<id property="id" column="id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findAll" resultMap="defaultCategoryResultMap">
|
||||
SELECT id, type, name, parent_id, sort_order, created_at
|
||||
FROM default_category
|
||||
ORDER BY type, sort_order, name
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="defaultCategoryResultMap">
|
||||
SELECT id, type, name, parent_id, sort_order, created_at
|
||||
FROM default_category
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="countChildren" resultType="int">
|
||||
SELECT COUNT(*) FROM default_category WHERE parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM default_category
|
||||
WHERE type = #{type} AND name = #{name}
|
||||
<if test="excludeId != null">AND id != #{excludeId}</if>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.DefaultCategory"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO default_category (type, name, parent_id, sort_order, created_at)
|
||||
VALUES (#{type}, #{name}, #{parentId}, #{sortOrder}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.DefaultCategory">
|
||||
UPDATE default_category SET name = #{name}, parent_id = #{parentId}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM default_category WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="updateSortOrder">
|
||||
UPDATE default_category SET sort_order = #{sortOrder} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="maxSortOrder" resultType="java.lang.Integer">
|
||||
SELECT MAX(sort_order) FROM default_category WHERE type = #{type}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user