<?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.cyksj.mapper.DoubleVerifyClickRecordMapper">


    <select id="getDoubleVerifyCodeList" resultType="com.cyksj.model.views.DoubleVerifyCodeView">
        select *
        from (select user_id, account_id, relation_id, 1 as `type`, code, if(remain_time = 0,null,remain_time) as remain_time, created_time
              from double_verify_click_record
              where user_id = #{userId}
                and relation_id = #{relationId}
              union all
              select dr.user_id, dr.account_id, dr.relation_id, 2 as `type`, dcr.code, if(dcr.remain_time = 0,null,dcr.remain_time) as remain_time, dcr.created_time
              from double_verify_click_record dr
                       inner join double_verify_click_refresh_record dcr
                                  on dcr.click_id = dr.id and dr.user_id = #{userId} and
                                     dr.relation_id = #{relationId}) s
        order by created_time desc
    </select>
</mapper>