<?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.sop.mapper.QwSopTempMapper">

    <resultMap type="QwSopTemp" id="QwSopTempResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="setting"    column="setting"    />
        <result property="status"    column="status"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="companyId"    column="company_id"    />
        <result property="gap"    column="gap"    />
        <result property="sendType"    column="send_type"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQwSopTempVo">
        select *  from qw_sop_temp
    </sql>

    <select id="selectQwSopTempList" resultType="QwSopTemp"  resultMap="QwSopTempResult">
        <include refid="selectQwSopTempVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="setting != null  and setting != ''"> and setting = #{setting}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="sendType != null "> and send_type = #{sendType}</if>
        </where>
    </select>
    <select id="selectQwSopTempListNew" resultType="QwSopTemp"  resultMap="QwSopTempResult">
        select * from qw_sop_temp
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="sendType != null "> and send_type = #{sendType}</if>
        </where>
    </select>

    <select id="selectQwSopTempById" parameterType="String" resultMap="QwSopTempResult">
        <include refid="selectQwSopTempVo"/>
        where id = #{id}
    </select>
    <select id="listTemp" resultType="com.fs.sop.domain.QwSopTemp">
        select * from qw_sop_temp_temp
    </select>
    <select id="selectListByIds" resultType="com.fs.sop.domain.QwSopTemp">
        select * from qw_sop_temp  where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="redList" resultType="com.fs.sop.vo.QwSopTempRedPackageVo">
        select * from
    </select>

    <insert id="insertQwSopTemp" parameterType="QwSopTemp" useGeneratedKeys="true" keyProperty="id">
        insert into qw_sop_temp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="data.id != null">id,</if>
            <if test="data.name != null">name,</if>
            <if test="data.setting != null">setting,</if>
            <if test="data.status != null">status,</if>
            <if test="data.sort != null">sort,</if>
            <if test="data.createTime != null">create_time,</if>
            <if test="data.createBy != null">create_by,</if>
            <if test="data.companyId != null">company_id,</if>
            <if test="data.gap != null">gap,</if>
            <if test="data.sendType != null">send_type,</if>
            <if test="data.updateTime != null">update_time,</if>
            <if test="data.project != null">project,</if>
            <if test="data.courseId != null">course_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="data.id != null">#{data.id},</if>
            <if test="data.name != null">#{data.name},</if>
            <if test="data.setting != null">#{data.setting},</if>
            <if test="data.status != null">#{data.status},</if>
            <if test="data.sort != null">#{data.sort},</if>
            <if test="data.createTime != null">#{data.createTime},</if>
            <if test="data.createBy != null">#{data.createBy},</if>
            <if test="data.companyId != null">#{data.companyId},</if>
            <if test="data.gap != null">#{data.gap},</if>
            <if test="data.sendType != null">#{data.sendType},</if>
            <if test="data.updateTime != null">#{data.updateTime},</if>
            <if test="data.project != null">#{data.project},</if>
            <if test="data.courseId != null">#{data.courseId},</if>
         </trim>
    </insert>

    <update id="updateQwSopTemp" parameterType="QwSopTemp" useGeneratedKeys="false" keyProperty="id" >
        update qw_sop_temp
        <trim prefix="SET" suffixOverrides=",">
            <if test="data.name != null">name = #{data.name},</if>
            <if test="data.setting != null">setting = #{data.setting},</if>
            <if test="data.status != null">status = #{data.status},</if>
            <if test="data.sort != null">sort = #{data.sort},</if>
            <if test="data.createTime != null">create_time = #{data.createTime},</if>
            <if test="data.createBy != null">create_by = #{data.createBy},</if>
            <if test="data.companyId != null">company_id = #{data.companyId},</if>
            <if test="data.gap != null">gap = #{data.gap},</if>
            <if test="data.sendType != null">send_type = #{data.sendType},</if>
            <if test="data.updateTime != null">update_time = #{data.updateTime},</if>
            <if test="data.project != null">project = #{data.project},</if>
            <if test="data.courseId != null">course_id = #{data.courseId},</if>
        </trim>
        where id = #{data.id}
    </update>

    <delete id="deleteQwSopTempById" parameterType="String">
        delete from  qw_sop_temp where id = #{id}
    </delete>

    <delete id="deleteQwSopTempByIds" parameterType="String">
        delete from qw_sop_temp  where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

<!--    <update id="updateQwSopTempByIds" parameterType="String">-->
<!--        ALTER TABLE qw_sop_temp-->
<!--        UPDATE status = 0-->
<!--        WHERE id IN-->
<!--        <foreach item="id" collection="ids" open="(" separator="," close=")">-->
<!--            CAST(#{id} AS UUID)-->
<!--        </foreach>-->
<!--    </update>-->
    <update id="updateQwSopTempByIds" parameterType="String">
        UPDATE qw_sop_temp set status = 0
        WHERE id IN
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
