<?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.base.mapper.EmsBaseMonitorWorkUnitMapper">

    <resultMap type="EmsBaseMonitorWorkUnit" id="EmsBaseMonitorWorkUnitResult">
        <result property="objId" column="obj_id"/>
        <result property="monitorCode" column="monitor_code"/>
        <result property="monitorName" column="monitor_name"/>
        <result property="workUnitCode" column="work_unit_code"/>
        <result property="workUnitName" column="work_unit_name"/>
        <result property="monitorStatus" column="monitor_status"/>
        <result property="monitorType" column="monitor_type"/>
        <result property="formulaMode" column="formula_mode"/>
        <result property="proportion" column="proportion"/>
        <result property="remark" column="remark"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
    </resultMap>

    <sql id="selectEmsBaseMonitorWorkUnitVo">
        select ebmwu.obj_id,
               ebmwu.monitor_code,
               ebmi.monitor_name,
               ebmwu.work_unit_code,
               ebwu.work_unit_name,
               ebmwu.monitor_status,
               ebmwu.monitor_type,
               ebmwu.formula_mode,
               ebmwu.proportion,
               ebmwu.remark,
               ebmwu.is_flag,
               ebmwu.created_by,
               ebmwu.created_time,
               ebmwu.updated_by,
               ebmwu.updated_time
        from ems_base_monitor_work_unit ebmwu
                 left join ems_base_monitor_info ebmi on ebmi.monitor_code = ebmwu.monitor_code
                 left join ems_base_work_unit ebwu on ebwu.work_unit_code = ebmwu.work_unit_code
    </sql>

    <select id="selectEmsBaseMonitorWorkUnitList" parameterType="EmsBaseMonitorWorkUnit"
            resultMap="EmsBaseMonitorWorkUnitResult">
        <include refid="selectEmsBaseMonitorWorkUnitVo"/>
        <where>
            <if test="monitorCode != null  and monitorCode != ''">and ebmwu.monitor_code = #{monitorCode}</if>
            <if test="workUnitCode != null  and workUnitCode != ''">and ebmwu.work_unit_code = #{workUnitCode}</if>
            <if test="monitorStatus != null ">and ebmwu.monitor_status = #{monitorStatus}</if>
            <if test="monitorType != null ">and ebmwu.monitor_type = #{monitorType}</if>
            <if test="formulaMode != null ">and ebmwu.formula_mode = #{formulaMode}</if>
            <if test="proportion != null ">and ebmwu.proportion = #{proportion}</if>
            <if test="isFlag != null  and isFlag != ''">and ebmwu.is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''">and ebmwu.created_by = #{createdBy}</if>
            <if test="createdTime != null ">and ebmwu.created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and ebmwu.updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and ebmwu.updated_time = #{updatedTime}</if>
        </where>
        order by ebwu.work_unit_type, ebmwu.work_unit_code, ebmwu.monitor_code
    </select>

    <select id="selectEmsBaseMonitorWorkUnitByObjId" parameterType="Long" resultMap="EmsBaseMonitorWorkUnitResult">
        <include refid="selectEmsBaseMonitorWorkUnitVo"/>
        where ebmwu.obj_id = #{objId}
    </select>

    <insert id="insertEmsBaseMonitorWorkUnit" parameterType="EmsBaseMonitorWorkUnit" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_base_monitor_work_unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null and monitorCode != ''">monitor_code,</if>
            <if test="workUnitCode != null">work_unit_code,</if>
            <if test="monitorStatus != null">monitor_status,</if>
            <if test="monitorType != null">monitor_type,</if>
            <if test="formulaMode != null">formula_mode,</if>
            <if test="proportion != null">proportion,</if>
            <if test="remark != null">remark,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null and monitorCode != ''">#{monitorCode},</if>
            <if test="workUnitCode != null">#{workUnitCode},</if>
            <if test="monitorStatus != null">#{monitorStatus},</if>
            <if test="monitorType != null">#{monitorType},</if>
            <if test="formulaMode != null">#{formulaMode},</if>
            <if test="proportion != null">#{proportion},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateEmsBaseMonitorWorkUnit" parameterType="EmsBaseMonitorWorkUnit">
        update ems_base_monitor_work_unit
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorCode != null and monitorCode != ''">monitor_code = #{monitorCode},</if>
            <if test="workUnitCode != null">work_unit_code = #{workUnitCode},</if>
            <if test="monitorStatus != null">monitor_status = #{monitorStatus},</if>
            <if test="monitorType != null">monitor_type = #{monitorType},</if>
            <if test="formulaMode != null">formula_mode = #{formulaMode},</if>
            <if test="proportion != null">proportion = #{proportion},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteEmsBaseMonitorWorkUnitByObjId" parameterType="Long">
        delete
        from ems_base_monitor_work_unit
        where obj_id = #{objId}
    </delete>

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