<?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.siwei.rsmonitoring.mapper.TDkAuditflowRecordMapper">

    <resultMap type="TDkAuditflowRecord" id="TDkAuditflowRecordResult">
        <result property="id"    column="id"    />
        <result property="dkjdxxId"    column="dkjdxx_id"    />
        <result property="auditflowType"    column="auditflow_type"    />
        <result property="auditflowStep"    column="auditflow_step"    />
        <result property="auditflowStepValue"    column="auditflow_step_value"    />
        <result property="auditflowOrder"    column="auditflow_order"    />
        <result property="auditflowOperateType"    column="auditflow_operate_type"    />
        <result property="auditflowOperationState"    column="auditflow_operation_state"    />
        <result property="auditflowOperateData"    column="auditflow_operate_data"    />
        <result property="auditflowState"    column="auditflow_state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="successType"    column="success_type"    />
        <result property="nextId"    column="next_id"    />
        <result property="previousId"    column="previous_id"    />
    </resultMap>

    <sql id="selectTDkAuditflowRecordVo">
        select id, dkjdxx_id, auditflow_type, auditflow_step, auditflow_order, auditflow_operate_type, auditflow_operation_state, auditflow_operate_data, auditflow_state, create_by, create_time, success_type, next_id, previous_id from t_dk_auditflow_record
    </sql>

    <select id="selectTDkAuditflowRecordList" parameterType="TDkAuditflowRecord" resultMap="TDkAuditflowRecordResult">
        <include refid="selectTDkAuditflowRecordVo"/>
        <where>
            <if test="dkjdxxId != null  and dkjdxxId != ''"> and dkjdxx_id = #{dkjdxxId}</if>
            <if test="auditflowType != null  and auditflowType != ''"> and auditflow_type = #{auditflowType}</if>
            <if test="auditflowStep != null  and auditflowStep != ''"> and auditflow_step = #{auditflowStep}</if>
            <if test="auditflowOrder != null "> and auditflow_order = #{auditflowOrder}</if>
            <if test="auditflowOperateType != null  and auditflowOperateType != ''"> and auditflow_operate_type = #{auditflowOperateType}</if>
            <if test="auditflowOperationState != null  and auditflowOperationState != ''"> and auditflow_operation_state = #{auditflowOperationState}</if>
            <if test="auditflowOperateData != null  and auditflowOperateData != ''"> and auditflow_operate_data = #{auditflowOperateData}</if>
            <if test="auditflowState != null  and auditflowState != ''"> and auditflow_state = #{auditflowState}</if>
            <if test="successType != null  and successType != ''"> and success_type = #{successType}</if>
            <if test="nextId != null  and nextId != ''"> and next_id = #{nextId}</if>
            <if test="previousId != null  and previousId != ''"> and previous_id = #{previousId}</if>
        </where>
        order by auditflow_order desc
    </select>

    <select id="selectTDkAuditflowRecordListBusiness" parameterType="TDkAuditflowRecord" resultMap="TDkAuditflowRecordResult">
        select t1.*,t2.step_value as auditflow_step_value  from (
        <include refid="selectTDkAuditflowRecordVo"/>
        <where>
            <if test="dkjdxxId != null  and dkjdxxId != ''"> and dkjdxx_id = #{dkjdxxId}</if>
            <if test="auditflowType != null  and auditflowType != ''"> and auditflow_type = #{auditflowType}</if>
            <if test="auditflowStep != null  and auditflowStep != ''"> and auditflow_step = #{auditflowStep}</if>
            <if test="auditflowOrder != null "> and auditflow_order = #{auditflowOrder}</if>
            <if test="auditflowOperateType != null  and auditflowOperateType != ''"> and auditflow_operate_type = #{auditflowOperateType}</if>
            <if test="auditflowOperationState != null  and auditflowOperationState != ''"> and auditflow_operation_state = #{auditflowOperationState}</if>
            <if test="auditflowOperateData != null  and auditflowOperateData != ''"> and auditflow_operate_data = #{auditflowOperateData}</if>
            <if test="auditflowState != null  and auditflowState != ''"> and auditflow_state = #{auditflowState}</if>
            <if test="successType != null  and successType != ''"> and success_type = #{successType}</if>
            <if test="nextId != null  and nextId != ''"> and next_id = #{nextId}</if>
            <if test="previousId != null  and previousId != ''"> and previous_id = #{previousId}</if>
        </where>
        )t1 left join t_dk_auditflow_step t2 on t2.auditflow_code = t1.auditflow_type and t2.step_code = t1.auditflow_step
        order by t1.auditflow_order desc
    </select>

    <select id="selectTDkAuditflowRecordById" parameterType="String" resultMap="TDkAuditflowRecordResult">
        <include refid="selectTDkAuditflowRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTDkAuditflowRecord" parameterType="TDkAuditflowRecord">
        insert into t_dk_auditflow_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="dkjdxxId != null">dkjdxx_id,</if>
            <if test="auditflowType != null">auditflow_type,</if>
            <if test="auditflowStep != null">auditflow_step,</if>
            <if test="auditflowOrder != null">auditflow_order,</if>
            <if test="auditflowOperateType != null">auditflow_operate_type,</if>
            <if test="auditflowOperationState != null">auditflow_operation_state,</if>
            <if test="auditflowOperateData != null">auditflow_operate_data,</if>
            <if test="auditflowState != null">auditflow_state,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="successType != null">success_type,</if>
            <if test="nextId != null">next_id,</if>
            <if test="previousId != null">previous_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="dkjdxxId != null">#{dkjdxxId},</if>
            <if test="auditflowType != null">#{auditflowType},</if>
            <if test="auditflowStep != null">#{auditflowStep},</if>
            <if test="auditflowOrder != null">#{auditflowOrder},</if>
            <if test="auditflowOperateType != null">#{auditflowOperateType},</if>
            <if test="auditflowOperationState != null">#{auditflowOperationState},</if>
            <if test="auditflowOperateData != null">#{auditflowOperateData},</if>
            <if test="auditflowState != null">#{auditflowState},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="successType != null">#{successType},</if>
            <if test="nextId != null">#{nextId},</if>
            <if test="previousId != null">#{previousId},</if>
        </trim>
    </insert>

    <update id="updateTDkAuditflowRecord" parameterType="TDkAuditflowRecord">
        update t_dk_auditflow_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="dkjdxxId != null">dkjdxx_id = #{dkjdxxId},</if>
            <if test="auditflowType != null">auditflow_type = #{auditflowType},</if>
            <if test="auditflowStep != null">auditflow_step = #{auditflowStep},</if>
            <if test="auditflowOrder != null">auditflow_order = #{auditflowOrder},</if>
            <if test="auditflowOperateType != null">auditflow_operate_type = #{auditflowOperateType},</if>
            <if test="auditflowOperationState != null">auditflow_operation_state = #{auditflowOperationState},</if>
            <if test="auditflowOperateData != null">auditflow_operate_data = #{auditflowOperateData},</if>
            <if test="auditflowState != null">auditflow_state = #{auditflowState},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="successType != null">success_type = #{successType},</if>
            <if test="nextId != null">next_id = #{nextId},</if>
            <if test="previousId != null">previous_id = #{previousId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTDkAuditflowRecordById" parameterType="String">
        delete from t_dk_auditflow_record where id = #{id}
    </delete>

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