<?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.MidjourneyUserConversationMapper">


    <select id="getMjMirrorOrderDetail" resultType="com.cyksj.model.views.MidjourneyUserDetailView">
        select count(IF(muc.mode = 1, 1, NULL)) as useFastNum, count(if(muc.mode = 2, 1, NULL)) as useRelaxNum
        from (select id from midjourney_user where relation_id = #{relationId} limit 1) mu
        inner join midjourney_user_conversation muc on muc.user_id = mu.id
        where muc.status in ('SUCCESS', 'IN_PROGRESS')
        <if test="startTime != null">
            and created_time > #{startTime}
        </if>
        <if test="expiryTime != null">
            and created_time &lt; #{expiryTime}
        </if>
    </select>

    <select id="getMjCarHistory" resultType="com.cyksj.model.views.MidjourneyUserConversationRecordHistoryView">
        select r.user_token,r.prompt,r.conversation_id,r.created_time as conversationTime,r.car_id,r.car_name from (SELECT MAX(id) id from midjourney_user_conversation_record as m where m.user_token = #{userToken} GROUP BY m.car_id) t left join midjourney_user_conversation_record as r on t.id = r.id order by r.created_time desc
    </select>
</mapper>