<?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.xhpc.activity.mapper.XhpcUserMapper">


    <insert id="insertStatementBatch" parameterType="list">
        insert into xhpc_user_account_statement (user_id, amount, remaining_sum,
        charge_order_id, recharge_order_id, refund_order_id,
        `type`, `status`, del_flag,
        create_time, create_by, update_time,
        update_by, remark, tenant_id,
        `source`)
        values
        <foreach collection="domainList" separator="," item="domain" index="index">
            (#{domain.userId}, #{domain.amount}, #{domain.remainingSum},
            #{domain.chargeOrderId}, #{domain.rechargeOrderId}, #{domain.refundOrderId},
            #{domain.type}, #{domain.status}, 0,
            sysdate(), #{domain.createBy}, sysdate(),
            #{domain.updateBy}, #{domain.remark}, #{domain.tenantId},
            #{domain.source})
        </foreach>
    </insert>


    <insert id="insertStatement" >
        insert into xhpc_user_account_statement (user_id, amount, remaining_sum,
        charge_order_id, recharge_order_id, refund_order_id,
        `type`, `status`, del_flag,
        create_time, create_by, update_time,
        update_by, remark, tenant_id,
        `source`)
        values
            (#{domain.userId}, #{domain.amount}, #{domain.remainingSum},
            #{domain.chargeOrderId}, #{domain.rechargeOrderId}, #{domain.refundOrderId},
            #{domain.type}, #{domain.status}, 0,
            sysdate(), #{domain.createBy}, sysdate(),
            #{domain.updateBy}, #{domain.remark}, #{domain.tenantId},
            #{domain.source})
    </insert>


    <update id="updateBatchAppUser" parameterType="list">
        <foreach collection="domainList" index="index" item="domain" separator=";">
            update xhpc_app_user set balance=#{domain.balance} where app_user_id=#{domain.appUserId}
        </foreach>
    </update>


    <update id="updateBatchComUser" parameterType="list">
        <foreach collection="domainList" index="index" item="domain" separator=";">
            update xhpc_community_personnel set red_packet=#{domain.redPacket}, surplus_money=#{domain.surplusMoney}
            where community_personnel_id=#{domain.communityPersonnelId}
        </foreach>
    </update>


    <update id="updateBatchCusUser" parameterType="list">
        <foreach collection="domainList" index="index" item="domain" separator=";">
            update xhpc_customers_personnel set red_packet=#{domain.redPacket}, surplus_money=#{domain.surplusMoney}
            where customers_personnel_id=#{domain.customersPersonnelId}
        </foreach>
    </update>


    <update id="updateAppUser">
        update xhpc_app_user set balance=#{domain.balance} where app_user_id=#{domain.appUserId}
    </update>


    <update id="updateComUser">
            update xhpc_community_personnel set red_packet=#{domain.redPacket}, surplus_money=#{domain.surplusMoney}
            where community_personnel_id=#{domain.communityPersonnelId}

    </update>


    <update id="updateCusUser">
            update xhpc_customers_personnel set red_packet=#{domain.redPacket}, surplus_money=#{domain.surplusMoney}
            where customers_personnel_id=#{domain.customersPersonnelId}

    </update>


    <select id="selectAppUserById" resultType="com.xhpc.activity.domain.XhpcAppUserDomain">
        select app_user_id, phone, balance, `status`, tenant_id, del_flag
        from xhpc_app_user
        where status = 0
          and del_flag = 0
          and app_user_id = #{userId}
    </select>


    <select id="selectAppUserByPhone" resultType="com.xhpc.activity.domain.XhpcAppUserDomain">
        select app_user_id, phone, balance, `status`, tenant_id, del_flag
        from xhpc_app_user
        where status = 0
          and del_flag = 0
          and phone = #{phone}
    </select>


    <select id="selectAppUsersById" resultType="com.xhpc.activity.domain.XhpcAppUserDomain">
        select app_user_id, phone, balance, `status`, tenant_id, del_flag
        from xhpc_app_user
        where status = 0
          and del_flag = 0
          and find_in_set(app_user_id, #{userIds})
    </select>


    <select id="selectAppUsersByPhone" resultType="com.xhpc.activity.domain.XhpcAppUserDomain">
        select app_user_id, phone, balance, `status`, tenant_id, del_flag
        from xhpc_app_user
        where status = 0
          and del_flag = 0
          and find_in_set(phone, #{phones})
    </select>


    <select id="selectAppUsersAll" resultType="com.xhpc.activity.domain.XhpcAppUserDomain">
        select app_user_id, phone, balance, `status`, tenant_id, del_flag
        from xhpc_app_user
        where status = 0
          and del_flag = 0
    </select>


    <select id="selectComUserById" resultType="com.xhpc.activity.domain.XhpcCommunityPersonnelDomain">
        select community_personnel_id,
               community_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_community_personnel
        where status = 0
          and del_flag = 0
          and community_personnel_id = #{userId}
    </select>


    <select id="selectComUserByAccount" resultType="com.xhpc.activity.domain.XhpcCommunityPersonnelDomain">
        select community_personnel_id,
               community_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_community_personnel
        where status = 0
          and del_flag = 0
          and account = #{account}
    </select>


    <select id="selectComUsersById" resultType="com.xhpc.activity.domain.XhpcCommunityPersonnelDomain">
        select community_personnel_id,
               community_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_community_personnel
        where status = 0
          and del_flag = 0
          and find_in_set(community_personnel_id, #{userIds})
    </select>


    <select id="selectComUsersByAccount" resultType="com.xhpc.activity.domain.XhpcCommunityPersonnelDomain">
        select community_personnel_id,
               community_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_community_personnel
        where status = 0
          and del_flag = 0
          and find_in_set(account, #{accounts})
    </select>


    <select id="selectComUsersAll" resultType="com.xhpc.activity.domain.XhpcCommunityPersonnelDomain">
        select community_personnel_id,
               community_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_community_personnel
        where status = 0
          and del_flag = 0
    </select>


    <select id="selectCusUserById" resultType="com.xhpc.activity.domain.XhpcCustomersPersonnelDomain">
        select customers_personnel_id,
               customers_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_customers_personnel
        where status = 0
          and del_flag = 0
          and customers_personnel_id = #{userId}
    </select>


    <select id="selectCusUserByAccount" resultType="com.xhpc.activity.domain.XhpcCustomersPersonnelDomain">
        select customers_personnel_id,
               customers_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_customers_personnel
        where status = 0
          and del_flag = 0
          and account = #{account}
    </select>


    <select id="selectCusUsersById" resultType="com.xhpc.activity.domain.XhpcCustomersPersonnelDomain">
        select customers_personnel_id,
               customers_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_customers_personnel
        where status = 0
          and del_flag = 0
          and find_in_set(customers_personnel_id, #{userIds})
    </select>


    <select id="selectCusUsersByAccount" resultType="com.xhpc.activity.domain.XhpcCustomersPersonnelDomain">
        select customers_personnel_id,
               customers_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_customers_personnel
        where status = 0
          and del_flag = 0
          and find_in_set(account, #{accounts})
    </select>


    <select id="selectCusUsersAll" resultType="com.xhpc.activity.domain.XhpcCustomersPersonnelDomain">
        select customers_personnel_id,
               customers_id,
               name,
               account,
               recharge_money,
               consume_money,
               red_packet,
               surplus_money,
               phone,
               status,
               del_flag,
               tenant_id
        from xhpc_customers_personnel
        where status = 0
          and del_flag = 0
    </select>
</mapper>