<?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.ruoyi.ems.mapper.EmsFacsFlowRelMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsFacsFlowRel" id="EmsFacsFlowRelResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="exportFacsCode"    column="export_facs_code"    />
        <result property="exportFacsName"    column="export_facs_Name"    />
        <result property="inputFacsCode"    column="input_facs_code"    />
        <result property="inputFacsName"    column="input_facs_name"    />
        <result property="emsCls"    column="ems_cls"    />
        <result property="emsClsName" column="ems_cls_name" />
        <result property="state"    column="state"    />
        <result property="actionType"    column="action_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectEmsFacsFlowRelVo">
        select
            r.`id`, r.`code`, r.`export_facs_code`, f1.`facs_name` as export_facs_name, r.`input_facs_code`, f2.`facs_name` as input_facs_name, r.`ems_cls`, c.`name` as ems_cls_name, r.`state`, r.`action_type`, r.`create_time`, r.`update_time`
        from adm_ems_facs_flow_rel r
            LEFT JOIN adm_ems_facs f1 ON r.`export_facs_code` = f1.`facs_code`
            LEFT JOIN adm_ems_facs f2 ON r.input_facs_code = f2.`facs_code`
            LEFT JOIN dim_gb_ems_cls c ON r.`ems_cls` = c.`code`
    </sql>

    <select id="selectEmsFacsFlowRelList" parameterType="com.ruoyi.ems.domain.EmsFacsFlowRel" resultMap="EmsFacsFlowRelResult">
        <include refid="selectEmsFacsFlowRelVo"/>
        <where>  
            <if test="code != null  and code != ''"> and r.`code` = #{code}</if>
            <if test="exportFacsCode != null  and exportFacsCode != ''"> and r.`export_facs_code` = #{exportFacsCode}</if>
            <if test="inputFacsCode != null  and inputFacsCode != ''"> and r.`input_facs_code` = #{inputFacsCode}</if>
            <if test="emsCls != null  and emsCls != ''"> and r.`ems_cls` = #{emsCls}</if>
            <if test="state != null "> and r.`state` = #{state}</if>
            <if test="actionType != null  and actionType != ''"> and r.`action_type` = #{actionType}</if>
        </where>
    </select>
    
    <select id="selectEmsFacsFlowRelById" parameterType="Long" resultMap="EmsFacsFlowRelResult">
        <include refid="selectEmsFacsFlowRelVo"/>
        where r.`id` = #{id}
    </select>
        
    <insert id="insertEmsFacsFlowRel" parameterType="com.ruoyi.ems.domain.EmsFacsFlowRel" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_facs_flow_rel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">code,</if>
            <if test="exportFacsCode != null and exportFacsCode != ''">export_facs_code,</if>
            <if test="inputFacsCode != null and inputFacsCode != ''">input_facs_code,</if>
            <if test="emsCls != null and emsCls != ''">ems_cls,</if>
            <if test="state != null">state,</if>
            <if test="actionType != null and actionType != ''">action_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">#{code},</if>
            <if test="exportFacsCode != null and exportFacsCode != ''">#{exportFacsCode},</if>
            <if test="inputFacsCode != null and inputFacsCode != ''">#{inputFacsCode},</if>
            <if test="emsCls != null and emsCls != ''">#{emsCls},</if>
            <if test="state != null">#{state},</if>
            <if test="actionType != null and actionType != ''">#{actionType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateEmsFacsFlowRel" parameterType="com.ruoyi.ems.domain.EmsFacsFlowRel">
        update adm_ems_facs_flow_rel
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="exportFacsCode != null and exportFacsCode != ''">export_facs_code = #{exportFacsCode},</if>
            <if test="inputFacsCode != null and inputFacsCode != ''">input_facs_code = #{inputFacsCode},</if>
            <if test="emsCls != null and emsCls != ''">ems_cls = #{emsCls},</if>
            <if test="state != null">state = #{state},</if>
            <if test="actionType != null and actionType != ''">action_type = #{actionType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsFacsFlowRelById" parameterType="Long">
        delete from adm_ems_facs_flow_rel where id = #{id}
    </delete>

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