<?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.bonus.canteen.core.android.mapper.UserMapper">
    <select id="getUserInfo" resultType="com.bonus.canteen.core.android.vo.UserInfoVo">
        select
            su.user_id as userId,
            su.user_name as userName,
            su.nick_name as nickName,
            ac.acc_id as accId,
            ac.card_num as cardNum,
            ac.serial_num as serialNum,
            ai.acc_status as accStatus,
            su.phonenumber as phone,
            su.login_type as loginType
        from sys_user su
        left join acc_card ac on ac.user_id = su.user_id
        left join acc_info ai on ai.user_id = su.user_id
        where ai.del_flag = '0'
            <if test="type == 'user'">
                <if test="time != null and time != ''">
                    AND su.update_time >= #{time} - INTERVAL 5 SECOND;
                </if>
            </if>
            <if test="type == 'card'">
                <if test="time != null and time != ''">
                    AND ac.update_time >= #{time} - INTERVAL 5 SECOND;
                </if>
            </if>
            <if test="userId != null and userId != '' and userId != 0 and userId != '0'">
                AND su.user_id = #{userId}
            </if>
    </select>
    <select id="getMoneyList" resultType="com.bonus.canteen.core.android.vo.UserInfoVo">
        SELECT
            sum(r.personalWalletBalance) as personalWalletBalance,
            sum(r.subsidiesBalance) as subsidiesBalance,
            r.user_id as userId
        from( select
                  user_id,
                  IF(wallet_id = 1,wallet_bal,0) as personalWalletBalance,
                  IF(wallet_id = 2,wallet_bal,0) as subsidiesBalance,
                  wallet_bal
              from acc_wallet_info)r
        GROUP BY r.user_id
    </select>
</mapper>