<?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.DiaReportItemsMapper">

    <resultMap type="DiaReportItems" id="DiaReportItemsResult">
        <result property="itemId"    column="itemId"    />
        <result property="reportId"    column="reportId"    />
        <result property="dimension"    column="dimension"    />
        <result property="controlPoint"    column="control_point"    />
        <result property="indicatorName"    column="indicator_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDiaReportItemsVo">
        select itemId, reportId, dimension, control_point, indicator_name, create_by, create_time, update_by, update_time from dia_report_items
    </sql>

    <select id="selectDiaReportItemsList" parameterType="DiaReportItems" resultMap="DiaReportItemsResult">
        <include refid="selectDiaReportItemsVo"/>
        <where>
            <if test="reportId != null "> and reportId = #{reportId}</if>
            <if test="dimension != null  and dimension != ''"> and dimension = #{dimension}</if>
            <if test="controlPoint != null  and controlPoint != ''"> and control_point = #{controlPoint}</if>
            <if test="indicatorName != null  and indicatorName != ''"> and indicator_name like concat('%', #{indicatorName}, '%')</if>
        </where>
    </select>

    <select id="selectDiaReportItemsByItemId" parameterType="Long" resultMap="DiaReportItemsResult">
        <include refid="selectDiaReportItemsVo"/>
        where itemId = #{itemId}
    </select>

    <insert id="insertDiaReportItems" 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="updateDiaReportItems" parameterType="DiaReportItems">
        update dia_report_items
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportId != null">reportId = #{reportId},</if>
            <if test="dimension != null">dimension = #{dimension},</if>
            <if test="controlPoint != null">control_point = #{controlPoint},</if>
            <if test="indicatorName != null">indicator_name = #{indicatorName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where itemId = #{itemId}
    </update>

    <delete id="deleteDiaReportItemsByItemId" parameterType="Long">
        delete from dia_report_items where itemId = #{itemId}
    </delete>

    <delete id="deleteDiaReportItemsByItemIds" parameterType="String">
        delete from dia_report_items where itemId in
        <foreach item="itemId" collection="array" open="(" separator="," close=")">
            #{itemId}
        </foreach>
    </delete>
    <insert id="batchInsertReportItems" parameterType="java.util.List">
        INSERT INTO dia_report_items (
        reportId,
        dimension,
        control_point,
        indicator_name,
        create_by,
        create_time,
        update_by,
        update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.reportId},
            #{item.dimension},
            #{item.controlPoint},
            #{item.indicatorName},
            #{item.createBy},
            #{item.createTime},
            #{item.updateBy},
            #{item.updateTime}
            )
        </foreach>
    </insert>
</mapper>
