package com.app.ydl.ydl.dao;

import com.app.ydl.ydl.view.CallRecordView;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@DS("ydl")
public interface CallRecordDao {

    @Select("SELECT r.id, r.relation_id, r.record_url FROM ydl.call_record r WHERE r.id = #{id}")
    CallRecordView getById(Long id);

    @Select("SELECT r.id, r.relation_id, r.record_url FROM ydl.call_record r " +
            "WHERE r.record_url != '' AND r.record_url != 'no' " +
            "AND r.relation_id = #{relationId}")
    List<CallRecordView> getByRelationId(String relationId);

    @Select("SELECT sos.standard_order_id AS order_id, sos.id AS relation_id, r.record_url, r.id FROM ydl.call_record r " +
            "LEFT JOIN ydl.standard_order_service sos ON sos.id = r.relation_id " +
            "WHERE r.record_url != '' AND r.record_url != 'no' " +
            "AND sos.id = #{orderServiceId} ;")
    List<CallRecordView> getByStandardOrderServiceId(Long orderServiceId);

    @Select("SELECT sos.standard_order_id AS order_id, sos.id AS relation_id, r.record_url, r.id FROM ydl.call_record r " +
            "LEFT JOIN ydl.standard_order_service sos ON sos.id = r.relation_id " +
            "WHERE r.record_url != '' AND r.record_url != 'no' " +
            "AND sos.standard_order_id = #{orderId} ;")
    List<CallRecordView> getByStandardOrderId(Long orderId);

    @Select("SELECT sos.standard_order_id AS order_id, sos.id AS relation_id, r.record_url, r.id FROM ydl.call_record r " +
            "LEFT JOIN ydl.standard_order_service sos ON sos.id = r.relation_id " +
            "WHERE r.record_url != '' AND r.record_url != 'no' " +
            "AND r.id = #{callRecordId} ;")
    List<CallRecordView> getByStandardOrderAndCallRecordId(Long callRecordId);
}