<?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">
<!--suppress ALL -->
<mapper namespace="com.xhpc.user.mapper.XhpcCommonMapper">


    <select id="getAppUser" resultType="map">
        select
               app_user_id as appUserId,
               phone as phone,
               is_refund_application as isRefundApplication,
               is_refund as isRefund,
               soc as socUser,
               balance as balance,
               avatar as avatar,
               status,
               weixin_open_id as weixinlogin,
               alipay_open_id as alipayLogin,
               weixin_login as weixinOpenId,
               alipay_login as alipayLogin,
               del_flag delFlag,
               concat(0) as userType,
               concat("C") as userTypeName,
               tenant_id tenantId,
               soc_protect socProtect,
               create_time as createTime
        from xhpc_app_user
        where del_flag=0
        <if test="phone !=null and phone !=''">
            and phone =#{phone}
        </if>
        <if test="userId !=null">
            and app_user_id =#{userId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id =#{tenantId}
        </if>
    </select>

    <select id="getCommunityUser" resultType="map">
        select
            community_personnel_id as appUserId,
            account as account,
            phone as phone,
            is_refund_application as isRefundApplication,
            is_refund as isRefund,
            soc as socUser,
            surplus_money as balance,
            avatar as avatar,
            status,
            weixin_open_id as weixinlogin,
            alipay_open_id as alipayLogin,
            weixin_login as weixinOpenId,
            alipay_login as alipayLogin,
            tenant_id tenantId,
            del_flag delFlag,
            concat(2) as userType,
            soc_protect socProtect,
            concat("ST") as userTypeName,
        <if test="serialNumber !=null and serialNumber !=''">
            (select count(charging_station_id) from xhpc_mechanism where community_id=mechanism_id and source=0 and charging_station_id in (select charging_station_id from xhpc_terminal where 1=1 and del_flag=0 and serial_number=#{serialNumber})) as number,
        </if>
            create_time as createTime
        from xhpc_community_personnel
        where del_flag=0
        <if test="phone !=null and phone !=''">
            and account =#{phone}
        </if>
        <if test="userId !=null">
            and community_personnel_id =#{userId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id =#{tenantId}
        </if>
    </select>

    <select id="getCustomersUser" resultType="map">
        select
            customers_personnel_id as appUserId,
            account as account,
            phone as phone,
            is_refund_application as isRefundApplication,
            is_refund as isRefund,
            soc as socUser,
            surplus_money as balance,
            avatar as avatar,
            status,
            weixin_open_id as weixinlogin,
            alipay_open_id as alipayLogin,
            weixin_login as weixinOpenId,
            alipay_login as alipayLogin,
            del_flag delFlag,
            tenant_id tenantId,
            concat(3) as userType,
            soc_protect socProtect,
            concat("BE") as userTypeName,
         <if test="serialNumber !=null and serialNumber !=''">
             (select count(charging_station_id) from xhpc_mechanism where customers_id=mechanism_id and source=1 and charging_station_id in (select charging_station_id from xhpc_terminal where 1=1 and del_flag=0 and serial_number=#{serialNumber})) as number,
         </if>
            create_time as createTime
        from xhpc_customers_personnel
        where del_flag=0
        <if test="phone !=null and phone !=''">
            and account =#{phone}
        </if>
        <if test="userId !=null">
            and customers_personnel_id =#{userId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id =#{tenantId}
        </if>
    </select>
</mapper>
