<?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.willalp.flow.mapper.HsFlowRunningRecordMapper">

    <resultMap type="com.willalp.flow.domain.HsFlowRunningRecord" id="HsFlowRunningRecordResult">
        <result property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="baseId" column="base_id"/>
        <result property="yesOrNo" column="yes_or_no"/>
        <result property="comment" column="comment"/>
        <result property="operator" column="operator"/>
        <result property="isDelete" column="is_delete"/>
        <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="selectHsFlowRunningRecordVo">
        select hfrr.id,
               task_id,
               hfrr.base_id,
               yes_or_no,
               comment,
               hopf.user_name operator,
               hfrr.is_delete,
               hfrr.create_by,
               hfrr.create_time,
               hfrr.update_by,
               hfrr.update_time,
               hfrr.remark
        from hs_flow_running_record hfrr
                 left join hs_org_personnel_files hopf on hopf.user_code = hfrr.operator
    </sql>

    <select id="selectHsFlowRunningRecordList" parameterType="HsFlowRunningRecord"
            resultMap="HsFlowRunningRecordResult">
        <include refid="selectHsFlowRunningRecordVo"/>
        <where>
            hfrr.is_delete = 0 AND hopf.is_delete = 0
            <if test="taskId != null  and taskId != ''">
                and task_id = #{taskId}
            </if>
            <if test="baseId != null  and baseId != ''">
                and base_id = #{baseId}
            </if>
            <if test="yesOrNo != null  and yesOrNo != ''">
                and yes_or_no = #{yesOrNo}
            </if>
            <if test="comment != null  and comment != ''">
                and comment = #{comment}
            </if>
            <if test="operator != null  and operator != ''">
                and operator = #{operator}
            </if>
        </where>
        order by create_time
    </select>
    <select id="selectHsFlowRunningRecordTrue" resultMap="HsFlowRunningRecordResult">
        select
        base_id,
        operator
        from hs_flow_running_record hfrr
        <where>
            task_id = #{taskId}
            AND yes_or_no = #{yon}
        </where>
        order by create_time
    </select>
    <select id="getFlowRecordByBusinessId" resultType="com.willalp.flow.domain.HsFlowRunningRecord">
        select hfrr.id,
               hfrr.base_id,
               yes_or_no,
               comment,
               hopf.user_name operator
        from hs_flow_running_record hfrr
                 left join hs_org_personnel_files hopf on hopf.user_code = hfrr.operator
                 left join hs_flow_task hft on hfrr.task_id = hft.id
        where hfrr.is_delete = 0
          AND hopf.is_delete = 0
          AND hft.is_delete = 0
          AND hft.business_id = #{businessId}
        order by hfrr.create_time
    </select>
</mapper>
