<?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.fs.company.mapper.CompanySmsTempMapper">
    
    <resultMap type="CompanySmsTemp" id="CompanySmsTempResult">
        <result property="tempId"    column="temp_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="tempCode"    column="temp_code"    />
        <result property="tempType"    column="temp_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="cateId"    column="cate_id"    />
        <result property="isAudit"    column="is_audit"    />
    </resultMap>

    <sql id="selectCompanySmsTempVo">
        select temp_id, company_id, title, content, temp_code, temp_type, create_time, update_time, status, cate_id,is_audit from company_sms_temp
    </sql>

    <select id="selectCompanySmsTempList" parameterType="CompanySmsTemp" resultMap="CompanySmsTempResult">
        <include refid="selectCompanySmsTempVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="tempCode != null  and tempCode != ''"> and temp_code = #{tempCode}</if>
            <if test="tempType != null "> and temp_type = #{tempType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="isAudit != null "> and is_audit = #{isAudit}</if>
        </where>
    </select>
    
    <select id="selectCompanySmsTempById" parameterType="Long" resultMap="CompanySmsTempResult">
        <include refid="selectCompanySmsTempVo"/>
        where temp_id = #{tempId}
    </select>
        
    <insert id="insertCompanySmsTemp" parameterType="CompanySmsTemp" useGeneratedKeys="true" keyProperty="tempId">
        insert into company_sms_temp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="tempCode != null">temp_code,</if>
            <if test="tempType != null">temp_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="isAudit != null">is_audit,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="tempCode != null">#{tempCode},</if>
            <if test="tempType != null">#{tempType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="isAudit != null">#{isAudit},</if>
         </trim>
    </insert>

    <update id="updateCompanySmsTemp" parameterType="CompanySmsTemp">
        update company_sms_temp
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="tempCode != null">temp_code = #{tempCode},</if>
            <if test="tempType != null">temp_type = #{tempType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
        </trim>
        where temp_id = #{tempId}
    </update>

    <delete id="deleteCompanySmsTempById" parameterType="Long">
        delete from company_sms_temp where temp_id = #{tempId}
    </delete>

    <delete id="deleteCompanySmsTempByIds" parameterType="String">
        delete from company_sms_temp where temp_id in 
        <foreach item="tempId" collection="array" open="(" separator="," close=")">
            #{tempId}
        </foreach>
    </delete>
    
</mapper>