<?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.srs.diagnostic.mapper.DiaReportReleaseMapper">

    <resultMap type="DiaReportRelease" id="DiaReportReleaseResult">
        <result property="relId"    column="relId"    />
        <result property="reportId"    column="reportId"    />
        <result property="moduleName"    column="moduleName"    />
        <result property="reportName"    column="reportName"    />
        <result property="status"    column="status"    />
        <result property="termId"    column="term_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="stuYearName"    column="stu_year_name"    />
    </resultMap>

    <sql id="selectDiaReportReleaseVo">
        select relId, reportId, moduleName, reportName, status, term_id, create_by, create_time from dia_report_release
    </sql>

    <select id="selectDiaReportReleaseList" parameterType="DiaReportRelease" resultMap="DiaReportReleaseResult">
        <include refid="selectDiaReportReleaseVo"/>
        <where>
            <if test="moduleName != null  and moduleName != ''"> and moduleName like concat('%', #{moduleName}, '%')</if>
            <if test="reportName != null  and reportName != ''"> and reportName like concat('%', #{reportName}, '%')</if>
            <if test="termId !=0"> and term_id = #{termId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectDiaReportReleaseByRelId" parameterType="Long" resultMap="DiaReportReleaseResult">
        <include refid="selectDiaReportReleaseVo"/>
        where relId = #{relId}
    </select>



    <insert id="insertDiaReportRelease" parameterType="DiaReportRelease" useGeneratedKeys="true" keyProperty="relId">
        insert into dia_report_release
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportId != null">reportId,</if>
            <if test="moduleName != null and moduleName != ''">moduleName,</if>
            <if test="reportName != null and reportName != ''">reportName,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="termId !=0">term_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="stuYearName != null and stuYearName != ''">stu_year_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportId != null">#{reportId},</if>
            <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
            <if test="reportName != null and reportName != ''">#{reportName},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="termId !=0">#{termId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="stuYearName != null and stuYearName != ''">#{stuYearName},</if>
        </trim>
    </insert>
    <insert id="insertItems" parameterType="DiaReportItems" useGeneratedKeys="true" keyProperty="itemId">
        insert into dia_report_items
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportId != null">reportId,</if>
            <if test="dimension != null">dimension,</if>
            <if test="controlPoint != null">control_point,</if>
            <if test="indicatorName != null">indicator_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportId != null">#{reportId},</if>
            <if test="dimension != null">#{dimension},</if>
            <if test="controlPoint != null">#{controlPoint},</if>
            <if test="indicatorName != null">#{indicatorName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>

    </insert>

    <update id="updateDiaReportRelease" parameterType="DiaReportRelease">
        update dia_report_release
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportId != null">reportId = #{reportId},</if>
            <if test="moduleName != null and moduleName != ''">moduleName = #{moduleName},</if>
            <if test="reportName != null and reportName != ''">reportName = #{reportName},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="termId !=0">term_id = #{termId},</if> <!-- 修改判断条件 -->
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="stuYearName != null and stuYearName != ''">stu_year_name=#{stuYearName},</if>
        </trim>
        where relId = #{relId}
    </update>

    <delete id="deleteDiaReportReleaseByRelId" parameterType="Long">
        delete from dia_report_release where relId = #{relId}
    </delete>

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