<?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.sckw.mine.mapper.WorkFlowMapper">

    <sql id="Base_Column_List">
        id,
                tenant_id,
                work_code,
                work_name,
                work_type,
                node_count,
                use_order_count,
                `status`,
                remark,
                create_by,
                update_by,
                create_time,
                update_time,
                del_flag
    </sql>

    <resultMap id="flowNodeMap" type="com.sckw.mine.entity.res.WorkFlowPageListRes">
        <id column="id" property="id"/>
        <result column="work_name" property="workName"/>
        <result column="work_code" property="workCode"/>
        <result column="work_type" property="workType"/>
        <result column="node_count" property="nodeCount"/>
        <result column="use_order_count" property="useOrderCount"/>
        <result column="status" property="status"/>
        <result column="remark" property="remark"/>
        <result column="create_by" property="createBy"/>
        <collection property="workFlowNodeList" column="id" select="selectFlowNodeList" />
    </resultMap>

    <select id="pageList"
            parameterType="com.sckw.mine.entity.req.WorkFlowPageListParam"
            resultType="com.sckw.mine.entity.res.WorkFlowPageListRes"
            resultMap="flowNodeMap">
        select <include refid="Base_Column_List" /> from kw_business_work_flow
        <where>
            del_flag = 0
            <if test="param.workName != null and param.workName != ''">
               and work_name like concat('%',#{param.workName},'%')
            </if>
            <if test="param.workCode != null and param.workCode != ''">
               and work_code like concat('%',#{param.workCode},'%')
            </if>
            <if test="param.tenantId != null and param.tenantId != ''">
               and tenant_id = #{param.tenantId}
            </if>
        </where>

        order by create_time desc


    </select>

    <select id="selectFlowNodeList" resultType="com.sckw.mine.entity.dto.WorkFlowNodeDTO">
        select id,node_name, flow_id,node_id from kw_business_work_flow_node where del_flag = 0 and flow_id = #{id}
    </select>


</mapper>