82 lines
3.9 KiB
XML
82 lines
3.9 KiB
XML
|
|
<?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>
|