<?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.lz.modules.flow.dao.FlowChartDetailRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.FlowChartDetailRecord">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="chart_id" property="chartId"/>
        <result column="evaluation_group_id" property="evaluationGroupId"/>
        <result column="status" property="status"/>
        <result column="opt_ids" property="optIds"/>
        <result column="opt_type" property="optType"/>
        <result column="role_ids" property="roleIds"/>
        <result column="step_type" property="stepType"/>
        <result column="step_index" property="stepIndex"/>
        <result column="weight" property="weight"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, chart_id AS chartId, evaluation_group_id AS evaluationGroupId, status AS status, opt_ids AS optIds, opt_type AS optType, role_ids AS roleIds, step_type AS stepType, step_index AS stepIndex, weight AS weight
    </sql>




    <select id="selectFlowChartDetailRecordById" resultType="FlowChartDetailRecord" >
        select * from lz_flow_chart_detail_record  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertFlowChartDetailRecord" parameterType="FlowChartDetailRecord" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_flow_chart_detail_record(
            <if test="chartId != null">chart_id, </if>
            <if test="evaluationGroupId != null">evaluation_group_id, </if>
            <if test="status != null">status, </if>
            <if test="optIds != null">opt_ids, </if>
            <if test="optType != null">opt_type, </if>
            <if test="roleIds != null">role_ids, </if>
            <if test="stepType != null">step_type, </if>
            <if test="stepIndex != null">step_index, </if>
            <if test="weight != null">weight, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="chartId != null">#{ chartId}, </if>
            <if test="evaluationGroupId != null">#{ evaluationGroupId}, </if>
            <if test="status != null">#{ status}, </if>
            <if test="optIds != null">#{ optIds}, </if>
            <if test="optType != null">#{ optType}, </if>
            <if test="roleIds != null">#{ roleIds}, </if>
            <if test="stepType != null">#{ stepType}, </if>
            <if test="stepIndex != null">#{ stepIndex}, </if>
            <if test="weight != null">#{ weight}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateFlowChartDetailRecordById" parameterType="FlowChartDetailRecord" >
        update
            lz_flow_chart_detail_record
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="chartId != null">chart_id = #{chartId},</if>
            <if test="evaluationGroupId != null">evaluation_group_id = #{evaluationGroupId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="optIds != null">opt_ids = #{optIds},</if>
            <if test="optType != null">opt_type = #{optType},</if>
            <if test="roleIds != null">role_ids = #{roleIds},</if>
            <if test="stepType != null">step_type = #{stepType},</if>
            <if test="stepIndex != null">step_index = #{stepIndex},</if>
            <if test="weight != null">weight = #{weight}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverFlowChartDetailRecordById" parameterType="FlowChartDetailRecord" >
        update
            lz_flow_chart_detail_record    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            chart_id = #{chartId},
            evaluation_group_id = #{evaluationGroupId},
            status = #{status},
            opt_ids = #{optIds},
            opt_type = #{optType},
            role_ids = #{roleIds},
            step_type = #{stepType},
            step_index = #{stepIndex},
            weight = #{weight}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteFlowChartDetailRecordById" parameterType="java.lang.Long">
        update lz_flow_chart_detail_record set is_delete = 1 where id=#{id} limit 1  
    </update>

    <select id="selectFlowChartDetailRecordByGroupIdAndChartId" resultType="FlowChartDetailRecord" >
        select * from lz_flow_chart_detail_record  where evaluation_group_id=#{groupId} and chart_id = #{chartId} and is_delete = 0 order by step_index asc
    </select>

    <select id="selectFlowChartDetailRecordByGroupId" resultType="FlowChartDetailRecord" >
        select * from lz_flow_chart_detail_record  where evaluation_group_id=#{groupId} and is_delete = 0 order by step_index asc
    </select>

    <insert id="insertFlowChartDetailRecords" parameterType="FlowChartDetailRecord" useGeneratedKeys="true" keyProperty="id" >

        insert into lz_flow_chart_detail_record(
        chart_id,
        evaluation_group_id,
        status,
        opt_ids,
        opt_type,
        role_ids,
        step_type,
        step_index,
        weight,
        is_delete
            )values
        <foreach collection="list" item="item" separator=",">(

            #{ item.chartId},
            #{ item.evaluationGroupId},
            #{ item.status},
            #{ item.optIds},
            #{ item.optType},
            #{ item.roleIds},
            #{ item.stepType},
            #{ item.stepIndex},
            #{ item.weight},
            0
            )
        </foreach>
    ;
    </insert>

    <update id="updateCoverFlowChartDetailRecordByIds" parameterType="FlowChartDetailRecord" useGeneratedKeys="true" keyProperty="id" >
        <foreach collection="list" item="item" separator=";">
            update
            lz_flow_chart_detail_record
            set
            <if test="item.isDelete != null">is_delete = #{item.isDelete},</if>
            <if test="item.chartId != null">chart_id = #{ item.chartId},</if>
            <if test="item.evaluationGroupId != null">evaluation_group_id = #{ item.evaluationGroupId},</if>
            <if test="item.status != null">status = #{ item.status},</if>
            <if test="item.optIds != null">opt_ids = #{ item.optIds},</if>
            <if test="item.optType != null">opt_type = #{ item.optType},</if>
            <if test="item.roleIds != null">role_ids = #{ item.roleIds},</if>
            <if test="item.stepType != null">step_type = #{ item.stepType},</if>
            <if test="item.stepIndex != null">step_index = #{ item.stepIndex},</if>
            <if test="item.weight != null">weight = #{ item.weight}</if>
            ,gmt_modified = now()
            where id = #{item.id}
        </foreach>

    </update>

</mapper>

