<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.modules.finance.mapper.BizShopFundLogMapper">

    <insert id="insert" parameterType="com.ruoyi.web.modules.finance.domain.BizShopFundLog" useGeneratedKeys="true" keyProperty="logId">
        insert into biz_shop_fund_log (
            shop_id, shop_name, biz_no, change_reason,
            balance_change, balance_after, frozen_change, frozen_after,
            ref_type, ref_id, create_time
        ) values (
            #{shopId}, #{shopName}, #{bizNo}, #{changeReason},
            #{balanceChange}, #{balanceAfter}, #{frozenChange}, #{frozenAfter},
            #{refType}, #{refId}, #{createTime}
        )
    </insert>

    <select id="countByRef" resultType="int">
        select count(1) from biz_shop_fund_log
        where ref_type = #{refType} and ref_id = #{refId}
    </select>

    <select id="selectByShopId" resultType="com.ruoyi.web.modules.finance.vo.FundLogListRowVO">
        select shop_name as shopName,
               create_time as changeTime,
               biz_no as bizNo,
               change_reason as changeReason,
               balance_change as balanceChange,
               balance_after as balanceAfter,
               frozen_change as frozenChange,
               frozen_after as frozenAfter
        from biz_shop_fund_log
        where shop_id = #{shopId}
        order by create_time desc, log_id desc
    </select>

    <select id="selectPlatformList" resultType="com.ruoyi.web.modules.finance.vo.FundLogListRowVO">
        select shop_name as shopName,
               create_time as changeTime,
               biz_no as bizNo,
               change_reason as changeReason,
               balance_change as balanceChange,
               balance_after as balanceAfter,
               frozen_change as frozenChange,
               frozen_after as frozenAfter
        from biz_shop_fund_log
        where 1 = 1
        <if test="query.shopName != null and query.shopName != ''">
            and shop_name like concat('%', #{query.shopName}, '%')
        </if>
        <if test="query.shopName == null or query.shopName == ''">
            <if test="query.shopId != null">
                and shop_id = #{query.shopId}
            </if>
        </if>
        <if test="query.beginChangeTime != null and query.beginChangeTime != ''">
            and create_time &gt;= concat(#{query.beginChangeTime}, ' 00:00:00')
        </if>
        <if test="query.endChangeTime != null and query.endChangeTime != ''">
            and create_time &lt;= concat(#{query.endChangeTime}, ' 23:59:59')
        </if>
        order by create_time desc, log_id desc
    </select>

</mapper>
