<?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="cn.roadm.admin.mapper.SmsMasterplateMapper">
    <resultMap id="SmsMasterplateDO" type="cn.roadm.admin.dto.SmsMasterplateDO">
        <id property="id" column="id"/>
        <result property="content" column="content"/>
        <result property="spId" column="sp_id"/>
        <result property="apiValid" column="api_valid"/>
        <result property="platformValid" column="platform_valid"/>
        <result property="spName" column="sp_name"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <result property="type" column="type"/>
        <result property="createtime" column="createtime"/>
        <result property="starttime" column="starttime"/>
        <result property="endtime" column="endtime"/>
        <result property="mobilechannel" column="mobilechannel"/>
        <result property="unicomchannel" column="unicomchannel"/>
        <result property="telecomchannel" column="telecomchannel"/>
    </resultMap>

    <select id="listPageQuerySmsMasterplate" resultMap="SmsMasterplateDO">
        select s.id,
               s.content,
               s.sp_id,
               s.api_valid,
               s.platform_valid,
               sp.sp_name,
               s.remark,
               s.status,
               s.type,
               starttime,
               endtime,
               mobilechannel,
               unicomchannel,
               telecomchannel,
               DATE_FORMAT(s.createtime, '%Y-%m-%d %H:%i:%s') as createTime
        from sms_masterplate s
                 left join sms_sp_info sp on sp.id = s.sp_id
        <where>
            <if test="queryVO.id != null and queryVO.id != ''">
                and s.id = #{queryVO.id}
            </if>
            <if test="queryVO.content != null and queryVO.content != ''">
                and s.content like CONCAT('%', #{queryVO.content}, '%')
            </if>
            <if test="queryVO.spId != null and queryVO.spId != ''">
                and s.sp_id = #{queryVO.spId}
            </if>
            <if test="queryVO.spName != null and queryVO.spName != ''">
                and sp.sp_name like CONCAT('%', #{queryVO.spName}, '%')
            </if>
            <if test="queryVO.status != null">
                and s.status = #{queryVO.status}
            </if>
            <if test="queryVO.mobileChannel != null and queryVO.mobileChannel != '-1'">
                and mobilechannel = #{queryVO.mobileChannel}
            </if>
            <if test="queryVO.unicomChannel != null and queryVO.unicomChannel != '-1'">
                and unicomchannel = #{queryVO.unicomChannel}
            </if>
            <if test="queryVO.telecomChannel != null and queryVO.telecomChannel != '-1'">
                and telecomchannel = #{queryVO.telecomChannel}
            </if>
        </where>

        order by s.createtime desc
    </select>
</mapper>
