<?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.dcs.hnyz.mapper.PipelineInstanceMapper">

    <resultMap type="PipelineInstance" id="PipelineInstanceResult">
        <result property="id" column="id"/>
        <result property="pageId" column="page_id"/>
        <result property="x" column="x"/>
        <result property="y" column="y"/>
        <result property="pipeLength" column="pipe_length"/>
        <result property="pipeWidth" column="pipe_width"/>
        <result property="rotate" column="rotate"/>
        <result property="modelId" column="model_id"/>
        <result property="pipeClass" column="pipe_class"/>
        <result property="flowCondition" column="flow_condition"/>
        <result property="dynamicPipelineCondition" column="dynamic_pipeline_condition"/>
        <result property="reverseCondition" column="reverse_condition"/>
        <result property="status" column="status"/>
        <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>

    <resultMap id="PipelineInstanceFormResult" type="com.dcs.hnyz.domain.vo.PipeLineInstanceFormVO" extends="PipelineInstanceResult">
        <result property="pageName" column="page_name"/>
    </resultMap>

    <sql id="selectPipelineInstanceVo">
        select id,
               page_id,
               x,
               y,
               pipe_length,
               pipe_width,
               rotate,
               model_id,
               pipe_class,
               flow_condition,
               dynamic_pipeline_condition,
               reverse_condition,
               status,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from pipeline_instance
    </sql>

    <sql id="selectPipelineInstanceFormVo">
        select pi.id,
               pi.page_id,
               pi.x,
               pi.y,
               pi.pipe_length,
               pi.pipe_width,
               pi.rotate,
               pi.model_id,
               pi.pipe_class,
               pi.flow_condition,
               pi.dynamic_pipeline_condition,
               pi.reverse_condition,
               pi.status,
               pi.create_by,
               pi.create_time,
               pi.update_by,
               pi.update_time,
               pi.remark,
               f.page_name
        from pipeline_instance pi
                 left join page_control f on pi.page_id = f.page_id
    </sql>

    <select id="selectPipelineInstanceList" parameterType="PipelineInstance" resultMap="PipelineInstanceFormResult">
        <include refid="selectPipelineInstanceFormVo"/>
        <where>
            <if test="pageId != null ">and pi.page_id = #{pageId}</if>
            <if test="x != null  and x != ''">and x = #{x}</if>
            <if test="y != null  and y != ''">and y = #{y}</if>
            <if test="pipeLength != null ">and pipe_length = #{pipeLength}</if>
            <if test="pipeWidth != null ">and pipe_width = #{pipeWidth}</if>
            <if test="rotate != null ">and rotate = #{rotate}</if>
            <if test="modelId != null ">and model_id = #{modelId}</if>
            <if test="pipeClass != null  and pipeClass != ''">and pipe_class = #{pipeClass}</if>
            <if test="remark != null  and remark != ''">and pi.remark like concat('%', #{remark}, '%')</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="selectPipelineInstanceById" parameterType="Long" resultMap="PipelineInstanceResult">
        <include refid="selectPipelineInstanceVo"/>
        where id = #{id}
    </select>

</mapper>