<?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.ankaibei.workFlow.common.flow.dao.FlowWorkOrderMapper">
    <resultMap id="BaseResultMap" type="com.ankaibei.workFlow.common.flow.model.FlowWorkOrder">
        <id column="work_order_id" jdbcType="BIGINT" property="workOrderId"/>
        <result column="work_order_code" jdbcType="VARCHAR" property="workOrderCode"/>
        <result column="process_definition_key" jdbcType="VARCHAR" property="processDefinitionKey"/>
        <result column="process_definition_name" jdbcType="VARCHAR" property="processDefinitionName"/>
        <result column="process_definition_id" jdbcType="VARCHAR" property="processDefinitionId"/>
        <result column="process_instance_id" jdbcType="VARCHAR" property="processInstanceId"/>
        <result column="online_table_id" jdbcType="BIGINT" property="onlineTableId"/>
        <result column="table_name" jdbcType="VARCHAR" property="tableName"/>
        <result column="business_key" jdbcType="VARCHAR" property="businessKey"/>
        <result column="latest_approval_status" jdbcType="INTEGER" property="latestApprovalStatus"/>
        <result column="flow_status" jdbcType="INTEGER" property="flowStatus"/>
        <result column="submit_username" jdbcType="VARCHAR" property="submitUsername"/>
        <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
    </resultMap>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="inputFilterRef"/>
        AND zz_flow_work_order.deleted_flag = ${@com.ankaibei.workFlow.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="flowWorkOrderFilter != null">
            <if test="flowWorkOrderFilter.workOrderCode != null and flowWorkOrderFilter.workOrderCode != ''">
                AND zz_flow_work_order.work_order_code = #{flowWorkOrderFilter.workOrderCode}
            </if>
            <if test="flowWorkOrderFilter.processDefinitionKey != null and flowWorkOrderFilter.processDefinitionKey != ''">
                AND zz_flow_work_order.process_definition_key = #{flowWorkOrderFilter.processDefinitionKey}
            </if>
            <if test="flowWorkOrderFilter.latestApprovalStatus != null">
                AND zz_flow_work_order.latest_approval_status = #{flowWorkOrderFilter.latestApprovalStatus}
            </if>
            <if test="flowWorkOrderFilter.flowStatus != null">
                AND zz_flow_work_order.flow_status = #{flowWorkOrderFilter.flowStatus}
            </if>
            <if test="flowWorkOrderFilter.createTimeStart != null and flowWorkOrderFilter.createTimeStart != ''">
                AND zz_flow_work_order.create_time &gt;= #{flowWorkOrderFilter.createTimeStart}
            </if>
            <if test="flowWorkOrderFilter.createTimeEnd != null and flowWorkOrderFilter.createTimeEnd != ''">
                AND zz_flow_work_order.create_time &lt;= #{flowWorkOrderFilter.createTimeEnd}
            </if>
            <if test="flowWorkOrderFilter.createUserId != null">
                AND zz_flow_work_order.create_user_id = #{flowWorkOrderFilter.createUserId}
            </if>
        </if>
    </sql>

    <select id="getFlowWorkOrderList" resultMap="BaseResultMap"
            parameterType="com.ankaibei.workFlow.common.flow.model.FlowWorkOrder">
        SELECT * FROM zz_flow_work_order
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>

    <select id="findAllByProcessInstanceIdIn" resultMap="BaseResultMap">
        SELECT *
        FROM zz_flow_work_order
        where process_instance_id in
        <!-- for循环, item:循环后的值, index:循环下标列式for循环的 i ,collection:参数名-->
        <!-- open="(" close=")" separator="," 就是把循环的值组成 (item1,item2,item3)的格式-->
        <foreach item="item" index="index" collection="instanceIds" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
</mapper>
