<?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.BizShopPayAccountMapper">

    <select id="selectByShopId" resultType="com.ruoyi.web.modules.finance.vo.PayAccountListRowVO">
        select account_id as accountId,
               account_type as accountType,
               real_name as realName,
               account_no as accountNo,
               create_time as createTime
        from biz_shop_pay_account
        where shop_id = #{shopId} and del_flag = '0'
        order by create_time desc, account_id desc
    </select>

    <select id="selectOptionsByShopId" resultType="com.ruoyi.web.modules.finance.vo.PayAccountOptionVO">
        select account_id as accountId,
               account_type as accountType,
               real_name as realName,
               account_no as accountNo
        from biz_shop_pay_account
        where shop_id = #{shopId} and del_flag = '0'
        order by create_time desc, account_id desc
    </select>

    <select id="selectByIdAndShop" resultType="com.ruoyi.web.modules.finance.domain.BizShopPayAccount">
        select account_id as accountId, shop_id as shopId, account_type as accountType,
               real_name as realName, account_no as accountNo, del_flag as delFlag
        from biz_shop_pay_account
        where account_id = #{accountId} and shop_id = #{shopId} and del_flag = '0'
    </select>

    <select id="countBankByShopId" resultType="int">
        select count(1) from biz_shop_pay_account
        where shop_id = #{shopId} and del_flag = '0' and account_type = '1'
    </select>

    <select id="countByShopIdAndAccountNo" resultType="int">
        select count(1) from biz_shop_pay_account
        where shop_id = #{shopId} and account_no = #{accountNo} and del_flag = '0'
    </select>

    <insert id="insert" parameterType="com.ruoyi.web.modules.finance.domain.BizShopPayAccount" useGeneratedKeys="true" keyProperty="accountId">
        insert into biz_shop_pay_account (
            shop_id, account_type, real_name, account_no, del_flag, create_by, create_time
        ) values (
            #{shopId}, #{accountType}, #{realName}, #{accountNo}, #{delFlag}, #{createBy}, #{createTime}
        )
    </insert>

    <update id="update" parameterType="com.ruoyi.web.modules.finance.domain.BizShopPayAccount">
        update biz_shop_pay_account
        set account_type = #{accountType},
            real_name = #{realName},
            account_no = #{accountNo},
            update_by = #{updateBy},
            update_time = #{updateTime}
        where account_id = #{accountId} and shop_id = #{shopId} and del_flag = '0'
    </update>

    <update id="logicDelete">
        update biz_shop_pay_account
        set del_flag = '2', update_by = #{updateBy}, update_time = #{updateTime}
        where account_id = #{accountId} and shop_id = #{shopId} and del_flag = '0'
    </update>

</mapper>
