- budget 테이블에 year/month 추가, (member,category)→(member,category,year,month) 유니크 교체 기존 상시 예산은 현재 월로 1회 이관 - 예산 조회/생성/현황/기간차트를 월별로(findByMember에 year/month) - copyMonth: 다른 월 예산을 대상 월로 복사(같은 분류 덮어씀) + POST /budgets/copy - 백업 복구 시 예산은 현재 월로 등록 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -14,15 +14,19 @@
|
||||
<result property="weekly" column="weekly"/>
|
||||
<result property="monthly" column="monthly"/>
|
||||
<result property="yearly" column="yearly"/>
|
||||
<result property="year" column="year"/>
|
||||
<result property="month" column="month"/>
|
||||
<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>
|
||||
daily, weekly, monthly, yearly, `year`, `month`, 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 id="findByMember" resultMap="budgetResultMap">
|
||||
SELECT <include refid="cols"/> FROM budget
|
||||
WHERE member_id = #{memberId} AND `year` = #{year} AND `month` = #{month}
|
||||
ORDER BY category
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="budgetResultMap">
|
||||
@@ -32,15 +36,30 @@
|
||||
<select id="countByCategory" resultType="int">
|
||||
SELECT COUNT(*) FROM budget
|
||||
WHERE member_id = #{memberId} AND category = #{category}
|
||||
AND `year` = #{year} AND `month` = #{month}
|
||||
<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)
|
||||
daily, weekly, monthly, yearly, `year`, `month`, created_at, updated_at)
|
||||
VALUES (#{memberId}, #{category}, #{fixed}, #{baseUnit}, #{baseAmount},
|
||||
#{daily}, #{weekly}, #{monthly}, #{yearly}, NOW(), NOW())
|
||||
#{daily}, #{weekly}, #{monthly}, #{yearly}, #{year}, #{month}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<!-- 전월(또는 임의 월) 예산을 다른 월로 복사. 같은 분류는 덮어씀(ON DUPLICATE) -->
|
||||
<insert id="copyMonth">
|
||||
INSERT INTO budget (member_id, category, fixed, base_unit, base_amount,
|
||||
daily, weekly, monthly, yearly, `year`, `month`, created_at, updated_at)
|
||||
SELECT member_id, category, fixed, base_unit, base_amount,
|
||||
daily, weekly, monthly, yearly, #{toYear}, #{toMonth}, NOW(), NOW()
|
||||
FROM budget
|
||||
WHERE member_id = #{memberId} AND `year` = #{fromYear} AND `month` = #{fromMonth}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
fixed = VALUES(fixed), base_unit = VALUES(base_unit), base_amount = VALUES(base_amount),
|
||||
daily = VALUES(daily), weekly = VALUES(weekly), monthly = VALUES(monthly),
|
||||
yearly = VALUES(yearly), updated_at = NOW()
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.Budget">
|
||||
|
||||
Reference in New Issue
Block a user