<?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.core.customer.mapper.CustAccTempMapper">

    <resultMap id="custAccTempMap" type="com.bonus.core.customer.model.CustAccTemp">
        <id property="id" column="id"/>
        <result property="custId" column="cust_id"/>
        <result property="custNum" column="cust_num"/>
        <result property="custName" column="cust_name"/>
        <result property="custLimitId" column="cust_limit_id"/>
        <result property="mobile" column="mobile"/>
        <result property="idCard" column="id_card"/>
        <result property="sex" column="sex"/>
        <result property="age" column="age"/>
        <result property="birthday" column="birthday"/>
        <result property="custPhotoUrl" column="cust_photo_url"/>
        <result property="orgId" column="org_id"/>
        <result property="orgNum" column="org_num"/>
        <result property="orgFullName" column="org_full_name"/>
        <result property="placeId" column="place_id"/>
        <result property="placeNum" column="place_num"/>
        <result property="placeFullName" column="place_full_name"/>
        <result property="psnType" column="psn_type"/>
        <result property="homeAddr" column="home_addr"/>
        <result property="custState" column="cust_state"/>
        <result property="cardNum" column="card_num"/>
        <result property="serialNum" column="serial_num"/>
        <result property="cardType" column="card_type"/>
        <result property="cardStatus" column="card_status"/>
        <result property="accStatus" column="acc_status"/>
        <result property="revision" column="revision"/>
        <result property="crby" column="crby"/>
        <result property="crtime" column="crtime"/>
        <result property="upby" column="upby"/>
        <result property="uptime" column="uptime"/>
    </resultMap>


    <!-- 查询人员信息，根据时间和限制条数 -->
    <select id="querypersonalbytimesize" resultType="com.bonus.core.customer.vo.CustAccTempVo"
            parameterType="com.bonus.core.customer.dto.CustAccTempQueryDto">
        select t1.*, CONCAT('xnznkjxnznkj', t1.cust_id) as idtemporary
        from cust_acc_temp t1
        where t1.uptime > #{custAccTempQueryDto.time,jdbcType=VARCHAR}
        order by t1.uptime asc
            limit #{custAccTempQueryDto.pagesize,jdbcType=INTEGER}

    </select>


    <!-- 查询人员信息，根据时间和限制条数 -->
    <select id="querypersonalbytimesizebetween" resultType="com.bonus.core.customer.vo.CustAccTempVo"
            parameterType="com.bonus.core.customer.dto.CustAccTempQueryDto">
        select t1.*, CONCAT('xnznkjxnznkj', t1.cust_id) as idtemporary
        from cust_acc_temp t1
        where <![CDATA[t1.uptime > #{custAccTempQueryDto.time,jdbcType=VARCHAR}
          and t1.uptime <= #{custAccTempQueryDto.endtime,jdbcType=VARCHAR}]]>
        order by t1.uptime asc
    </select>


    <!-- 查询人员信息-->
    <select id="querypersonal" resultType="com.bonus.core.customer.vo.CustAccTempVo"
            parameterType="com.bonus.core.customer.dto.CustAccQueryTempDto">
        select *
        from cust_acc_temp t1
        where t1.cust_state=1
        <if test="custAccQueryTempDto.custId != null">
            and t1.cust_id = #{custAccQueryTempDto.custId,jdbcType=BIGINT}
        </if>
        <if test="custAccQueryTempDto.mobile != null and custAccQueryTempDto.mobile != ''">
            and t1.mobile = #{custAccQueryTempDto.mobile,jdbcType=VARCHAR, typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
        </if>
        <if test="custAccQueryTempDto.custName != null and custAccQueryTempDto.custName != ''">
            and t1.cust_name = #{custAccQueryTempDto.custName,jdbcType=VARCHAR, typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
        </if>
        <if test="custAccQueryTempDto.idCard != null and custAccQueryTempDto.idCard != ''">
            and t1.id_card = #{custAccQueryTempDto.idCard,jdbcType=VARCHAR, typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
        </if>
        <if test="custAccQueryTempDto.orgId != null">
            and t1.org_id = #{custAccQueryTempDto.orgId,jdbcType=BIGINT}
        </if>
        <if test="custAccQueryTempDto.psnType != null">
            and t1.psn_type = #{custAccQueryTempDto.psnType,jdbcType=INTEGER}
        </if>
        <if test="custAccQueryTempDto.custState != null">
            and t1.cust_state = #{custAccQueryTempDto.custState,jdbcType=INTEGER}
        </if>
        <if test="custAccQueryTempDto.cardNum != null and custAccQueryTempDto.cardNum != ''">
            and t1.card_num = #{custAccQueryTempDto.cardNum,jdbcType=VARCHAR}
        </if>
        <if test="custAccQueryTempDto.serialNum != null and custAccQueryTempDto.serialNum != ''">
            and t1.serial_num = #{custAccQueryTempDto.serialNum,jdbcType=VARCHAR}
        </if>
        <if test="custAccQueryTempDto.cardType != null and custAccQueryTempDto.cardType != ''">
            and t1.card_type = #{custAccQueryTempDto.cardType,jdbcType=VARCHAR}
        </if>
        <if test="custAccQueryTempDto.cardStatus != null and custAccQueryTempDto.cardStatus != ''">
            and t1.card_status = #{custAccQueryTempDto.cardStatus,jdbcType=VARCHAR}
        </if>
        <if test="custAccQueryTempDto.accStatus != null and custAccQueryTempDto.accStatus != ''">
            and t1.acc_status = #{custAccQueryTempDto.accStatus,jdbcType=VARCHAR}
        </if>
        order by uptime desc

    </select>

    <select id="pullCustInfoAz" resultType="com.bonus.core.device.manage.controller.depreacted.vo.CustInfoAzVo">
        SELECT
            *
        FROM
            (
                SELECT
                    t1.alipay_contract_num,
                    t1.cust_id,
                    serial_num,
                    cust_num,
                    cust_name,
                    org_full_name AS department,
                    birthday,
                    cust_photo_url,
                    card_status,
                    acc_status,
                    cust_state,
                    t1.uptime,
                    concat(UNIX_TIMESTAMP( t1.uptime ), RIGHT ( t1.cust_id, 15 )) AS updateId,
                    t2.openid AS aliopenid
                FROM
                    cust_acc_temp t1
                        LEFT JOIN cust_casual t2 ON t1.cust_id = t2.cust_id
                        AND t2.source_type = 5
            ) b
        WHERE
            updateId > #{updateId}
        ORDER BY
            updateId
    </select>

    <select id="pullCardInfoQuery" resultType="com.bonus.core.device.android.common.vo.CustCardPullVO">
        SELECT b.*
        FROM (SELECT concat(UNIX_TIMESTAMP(t1.uptime), RIGHT(t1.cust_id, 15)) AS updateId,
                     t1.cust_id,
                     t1.serial_num,
                     t1.validity_date,
                     t1.card_status
              FROM acc_card t1) b
        WHERE b.updateId > #{updateId}
        ORDER BY b.updateId
    </select>

    <select id="queryCustAccTempList" resultType="com.bonus.core.customer.model.CustAccTemp">
        select
        B.card_status as cardStatus,
        B.serial_num as serialNum,
        B.card_num as serialNum,
        B.card_type as cardType,
        A.cust_id,
        A.cust_num,
        A.cust_name,
        A.cust_limit_id,
        A.mobile,
        A.id_card,
        A.sex,
        A.age,
        A.cust_photo_url,
        A.org_id,
        A.org_num,
        A.org_full_name,
        A.place_id,
        A.place_num,
        A.place_full_name,
        A.psn_type
        from cust_acc_temp A left JOIN acc_card B on A.cust_id = B.cust_id and  B.card_status in (1,4)
        <where>
            A.cust_state = 1
            <if test="machineAccountInfoV3DTO.custId != null">
                and A.cust_id = #{machineAccountInfoV3DTO.custId}
            </if>
            <if test="machineAccountInfoV3DTO.custThirdId != null and machineAccountInfoV3DTO.custThirdId != ''">
                and A.cust_third_id =  #{machineAccountInfoV3DTO.custThirdId}
            </if>
            <if test="machineAccountInfoV3DTO.idCard != null and machineAccountInfoV3DTO.idCard != ''">
                and A.id_card =  #{machineAccountInfoV3DTO.idCard,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
            </if>
            <if test="machineAccountInfoV3DTO.mobile != null and machineAccountInfoV3DTO.mobile != ''">
                and A.mobile =  #{machineAccountInfoV3DTO.mobile,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
            </if>
            <if test="machineAccountInfoV3DTO.custNum != null and machineAccountInfoV3DTO.custNum != ''">
                and A.cust_num =  #{machineAccountInfoV3DTO.custNum}
            </if>
            <if test="machineAccountInfoV3DTO.custName != null and machineAccountInfoV3DTO.custName != ''">
                and A.cust_name =  #{machineAccountInfoV3DTO.custName,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
            </if>
            <if test="machineAccountInfoV3DTO.serialNum != null and machineAccountInfoV3DTO.serialNum != ''">
                and B.serial_num = #{machineAccountInfoV3DTO.serialNum}
            </if>
        </where>
    </select>
</mapper>
