<?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.store.mapper.BizMerchantAccountMapper">

    <resultMap id="BizMerchantAccountResult" type="com.ruoyi.web.modules.store.domain.BizMerchantAccount">
        <id property="accountId" column="account_id"/>
        <result property="merchantId" column="merchant_id"/>
        <result property="loginName" column="login_name"/>
        <result property="adminName" column="admin_name"/>
        <result property="password" column="password"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="selectByMerchantId" resultMap="BizMerchantAccountResult">
        select account_id, merchant_id, login_name, admin_name, password, del_flag,
               create_by, create_time, update_by, update_time
        from biz_merchant_account
        where merchant_id = #{merchantId} and del_flag = '0'
        limit 1
    </select>

    <select id="selectByLoginName" resultMap="BizMerchantAccountResult">
        select account_id, merchant_id, login_name, admin_name, password, del_flag,
               create_by, create_time, update_by, update_time
        from biz_merchant_account
        where login_name = #{loginName} and del_flag = '0'
        limit 1
    </select>

    <select id="countByLoginName" resultType="int">
        select count(1) from biz_merchant_account
        where login_name = #{loginName} and del_flag = '0'
        <if test="excludeAccountId != null">
            and account_id != #{excludeAccountId}
        </if>
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="accountId">
        insert into biz_merchant_account (
            merchant_id, login_name, admin_name, password, del_flag, create_by, create_time
        ) values (
            #{merchantId}, #{loginName}, #{adminName}, #{password}, #{delFlag}, #{createBy}, sysdate()
        )
    </insert>

    <update id="update">
        update biz_merchant_account
        <set>
            <if test="loginName != null">login_name = #{loginName},</if>
            <if test="adminName != null">admin_name = #{adminName},</if>
            <if test="password != null">password = #{password},</if>
            update_by = #{updateBy},
            update_time = sysdate()
        </set>
        where account_id = #{accountId} and del_flag = '0'
    </update>
</mapper>
