<?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.course.mapper.FsCourseSopMapper">

    <resultMap type="FsCourseSop" id="FsCourseSopResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="setting"    column="setting"    />
        <result property="companyId"    column="company_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="sopType"    column="sop_type"    />
        <result property="businessId"    column="business_id"    />
        <result property="url"    column="url"    />
        <result property="isAudit"    column="is_audit"    />
        <result property="corpId"    column="corp_id"    />
    </resultMap>

    <sql id="selectFsCourseSopVo">
        select id, name,is_audit, status, setting, company_id, create_by, create_time, sop_type, business_id, url, corp_id from fs_course_sop
    </sql>

    <select id="selectFsCourseSopList" parameterType="FsCourseSop" resultMap="FsCourseSopResult">
        <include refid="selectFsCourseSopVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="setting != null  and setting != ''"> and setting = #{setting}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="createTime != null "> and DATE(create_time) = #{createTime}</if>
            <if test="sopType != null "> and sop_type = #{sopType}</if>
            <if test="businessId != null "> and business_id = #{businessId}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="isAudit != null "> and is_audit = #{isAudit}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
        </where>
    </select>


    <select id="selectFsCourseSopById" parameterType="Long" resultMap="FsCourseSopResult">
        <include refid="selectFsCourseSopVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsCourseSop" parameterType="FsCourseSop" useGeneratedKeys="true" keyProperty="id">
        insert into fs_course_sop
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="status != null">status,</if>
            <if test="setting != null">setting,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="sopType != null">sop_type,</if>
            <if test="businessId != null">business_id,</if>
            <if test="url != null">url,</if>
            <if test="isAudit != null">is_audit,</if>
            <if test="corpId != null">corp_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="status != null">#{status},</if>
            <if test="setting != null">#{setting},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="sopType != null">#{sopType},</if>
            <if test="businessId != null">#{businessId},</if>
            <if test="url != null">#{url},</if>
            <if test="isAudit != null">#{isAudit},</if>
            <if test="corpId != null">#{corpId},</if>
         </trim>
    </insert>

    <update id="updateFsCourseSop" parameterType="FsCourseSop">
        update fs_course_sop
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="status != null">status = #{status},</if>
            <if test="setting != null">setting = #{setting},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="sopType != null">sop_type = #{sopType},</if>
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="url != null">url = #{url},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsCourseSopById" parameterType="Long">
        delete from fs_course_sop where id = #{id}
    </delete>

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