<?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.pdaaphm.system.mapper.TDataProcessMapper">
    
    <resultMap type="TDataProcess" id="TDataProcessResult">
        <result property="id"    column="id"    />
        <result property="processType"    column="process_type"    />
        <result property="processAlgId"    column="process_alg_id"    />
        <result property="processedDataId"    column="processed_data_id"    />
        <result property="processedDataName"    column="processed_data_name"    />
        <result property="resultDataId"    column="result_data_id"    />
        <result property="resultDataName"    column="result_data_name"    />
        <result property="processStatus"    column="process_status"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="log"    column="log"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTDataProcessVo">
        SELECT
            dp.id,
            dp.process_type,
            dp.process_alg_id,
            dp.processed_data_id,
            d.data_name processed_data_name,
            dp.result_data_id,
            d2.data_name result_data_name,
            dp.process_status,
            dp.start_time,
            dp.end_time,
            dp.log,
            dp.create_by,
            dp.create_time,
            dp.update_by,
            dp.update_time,
            dp.remark
        FROM
            t_data_process dp LEFT JOIN t_data d on dp.processed_data_id = d.id
        LEFT JOIN t_data d2 on dp.result_data_id = d2.id
    </sql>

    <select id="selectTDataProcessList" parameterType="TDataProcess" resultMap="TDataProcessResult">
        <include refid="selectTDataProcessVo"/>
        <where>  
            <if test="processType != null  and processType != ''"> and dp.process_type = #{processType}</if>
            <if test="processAlgId != null "> and dp.process_alg_id = #{processAlgId}</if>
            <if test="processedDataId != null "> and dp.processed_data_id = #{processedDataId}</if>
            <if test="resultDataId != null "> and dp.result_data_id = #{resultDataId}</if>
            <if test="processStatus != null  and processStatus != ''"> and dp.process_status = #{processStatus}</if>
            <if test="startTime != null "> and dp.start_time = #{startTime}</if>
            <if test="endTime != null "> and dp.end_time = #{endTime}</if>
            <if test="log != null  and log != ''"> and dp.log = #{log}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectPreprocessDataList" parameterType="TDataProcess" resultMap="TDataProcessResult">
        <include refid="selectTDataProcessVo"/>
        <where>
            dp.process_type in ('0','1','2')
            <if test="processType != null  and processType != ''"> and dp.process_type = #{processType}</if>
            <if test="processAlgId != null "> and dp.process_alg_id = #{processAlgId}</if>
            <if test="processedDataId != null "> and dp.processed_data_id = #{processedDataId}</if>
            <if test="resultDataId != null "> and dp.result_data_id = #{resultDataId}</if>
            <if test="processStatus != null  and processStatus != ''"> and dp.process_status = #{processStatus}</if>
            <if test="startTime != null "> and dp.start_time = #{startTime}</if>
            <if test="endTime != null "> and dp.end_time = #{endTime}</if>
            <if test="log != null  and log != ''"> and dp.log = #{log}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectTDataProcessById" parameterType="Long" resultMap="TDataProcessResult">
        <include refid="selectTDataProcessVo"/>
        where dp.id = #{id}
    </select>
        
    <insert id="insertTDataProcess" parameterType="TDataProcess" useGeneratedKeys="true" keyProperty="id">
        insert into t_data_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="processAlgId != null">process_type,</if>
            <if test="processAlgId != null">process_alg_id,</if>
            <if test="processedDataId != null">processed_data_id,</if>
            <if test="resultDataId != null">result_data_id,</if>
            <if test="processStatus != null">process_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="log != null">log,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="processAlgId != null">(select ac.alg_type from  t_alg_config ac where ac.id = #{processAlgId}),</if>
            <if test="processAlgId != null">#{processAlgId},</if>
            <if test="processedDataId != null">#{processedDataId},</if>
            <if test="resultDataId != null">#{resultDataId},</if>
            <if test="processStatus != null">#{processStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="log != null">#{log},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTDataProcess" parameterType="TDataProcess">
        update t_data_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="processAlgId != null">process_type = (select ac.alg_type from  t_alg_config ac where ac.id = #{processAlgId}),</if>
            <if test="processAlgId != null">process_alg_id = #{processAlgId},</if>
            <if test="processedDataId != null">processed_data_id = #{processedDataId},</if>
            <if test="resultDataId != null">result_data_id = #{resultDataId},</if>
            <if test="processStatus != null">process_status = #{processStatus},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="log != null">log = #{log},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTDataProcessById" parameterType="Long">
        delete from t_data_process where id = #{id}
    </delete>

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