<?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.business.mapper.HwMonitorUnitTypeMapper">

    <resultMap type="HwMonitorUnitType" id="HwMonitorUnitTypeResult">
        <result property="monitorUnitTypeId"    column="monitor_unit_type_id"    />
        <result property="monitorUnitTypeName"    column="monitor_unit_type_name"    />
        <result property="vitualFlag"    column="vitual_flag"    />
        <result property="monitorUnitTypeStatus"    column="monitor_unit_type_status"    />
        <result property="languageCode"    column="language_code"    />
        <result property="commonFlag"    column="common_flag"    />
        <result property="sceneId"    column="scene_id"    />
        <result property="remark"    column="remark"    />
        <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="unitTypeIcon"    column="unit_type_icon"    />
        <result property="unitTypeField"    column="unit_type_field"    />
        <result property="sceneName"    column="scene_name"    />
        <result property="tenantName"    column="tenant_name"    />
    </resultMap>

    <sql id="selectHwMonitorUnitTypeVo">
        select monitor_unit_type_id, monitor_unit_type_name, vitual_flag, monitor_unit_type_status, language_code, common_flag, scene_id, remark, create_by, create_time, update_by, update_time, unit_type_icon, unit_type_field from hw_monitor_unit_type
    </sql>

    <select id="selectHwMonitorUnitTypeByMonitorUnitTypeId" parameterType="Long" resultMap="HwMonitorUnitTypeResult">
        <include refid="selectHwMonitorUnitTypeVo"/>
        where monitor_unit_type_id = #{monitorUnitTypeId}
    </select>
    <select id="selectHwMonitorUnitTypeList" parameterType="HwMonitorUnitType" resultMap="HwMonitorUnitTypeResult">
        <include refid="selectHwMonitorUnitTypeVo"/>
        <where>
            <if test="monitorUnitTypeName != null  and monitorUnitTypeName != ''"> and monitor_unit_type_name like concat('%', #{monitorUnitTypeName}, '%')</if>
            <if test="vitualFlag != null  and vitualFlag != ''"> and vitual_flag = #{vitualFlag}</if>
            <if test="monitorUnitTypeStatus != null  and monitorUnitTypeStatus != ''"> and monitor_unit_type_status = #{monitorUnitTypeStatus}</if>
            <if test="languageCode != null  and languageCode != ''"> and language_code = #{languageCode}</if>
            <if test="commonFlag != null  and commonFlag != ''"> and common_flag = #{commonFlag}</if>
            <if test="sceneId != null "> and scene_id = #{sceneId}</if>
            <if test="unitTypeIcon != null  and unitTypeIcon != ''"> and unit_type_icon = #{unitTypeIcon}</if>
            <if test="unitTypeField != null  and unitTypeField != ''"> and unit_type_field = #{unitTypeField}</if>
        </where>
    </select>



    <insert id="insertHwMonitorUnitType" parameterType="HwMonitorUnitType" useGeneratedKeys="true" keyProperty="monitorUnitTypeId">
        insert into hw_monitor_unit_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorUnitTypeName != null and monitorUnitTypeName != ''">monitor_unit_type_name,</if>
            <if test="vitualFlag != null and vitualFlag != ''">vitual_flag,</if>
            <if test="monitorUnitTypeStatus != null and monitorUnitTypeStatus != ''">monitor_unit_type_status,</if>
            <if test="languageCode != null">language_code,</if>
            <if test="commonFlag != null and commonFlag != ''">common_flag,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="sceneId != null">scene_id,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="unitTypeIcon != null">unit_type_icon,</if>
            <if test="unitTypeField != null">unit_type_field,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorUnitTypeName != null and monitorUnitTypeName != ''">#{monitorUnitTypeName},</if>
            <if test="vitualFlag != null and vitualFlag != ''">#{vitualFlag},</if>
            <if test="monitorUnitTypeStatus != null and monitorUnitTypeStatus != ''">#{monitorUnitTypeStatus},</if>
            <if test="languageCode != null">#{languageCode},</if>
            <if test="commonFlag != null and commonFlag != ''">#{commonFlag},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="sceneId != null">#{sceneId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="unitTypeIcon != null">#{unitTypeIcon},</if>
            <if test="unitTypeField != null">#{unitTypeField},</if>
         </trim>
    </insert>

    <update id="updateHwMonitorUnitType" parameterType="HwMonitorUnitType">
        update hw_monitor_unit_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorUnitTypeName != null and monitorUnitTypeName != ''">monitor_unit_type_name = #{monitorUnitTypeName},</if>
            <if test="vitualFlag != null and vitualFlag != ''">vitual_flag = #{vitualFlag},</if>
            <if test="monitorUnitTypeStatus != null and monitorUnitTypeStatus != ''">monitor_unit_type_status = #{monitorUnitTypeStatus},</if>
            <if test="languageCode != null">language_code = #{languageCode},</if>
            <if test="commonFlag != null and commonFlag != ''">common_flag = #{commonFlag},</if>
            <if test="sceneId != null">scene_id = #{sceneId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="unitTypeIcon != null">unit_type_icon = #{unitTypeIcon},</if>
            <if test="unitTypeField != null">unit_type_field = #{unitTypeField},</if>
        </trim>
        where monitor_unit_type_id = #{monitorUnitTypeId}
    </update>

    <delete id="deleteHwMonitorUnitTypeByMonitorUnitTypeId" parameterType="Long">
        delete from hw_monitor_unit_type where monitor_unit_type_id = #{monitorUnitTypeId}
    </delete>

    <delete id="deleteHwMonitorUnitTypeByMonitorUnitTypeIds" parameterType="String">
        delete from hw_monitor_unit_type where monitor_unit_type_id in
        <foreach item="monitorUnitTypeId" collection="array" open="(" separator="," close=")">
            #{monitorUnitTypeId}
        </foreach>
    </delete>


    <select id="selectHwMonitorUnitTypeJoinList" parameterType="HwMonitorUnitType" resultMap="HwMonitorUnitTypeResult">
        select hmut.*,ht.tenant_name,hs.scene_name from hw_monitor_unit_type hmut
        left join hw_tenant ht on hmut.tenant_id = ht.tenant_id
        left join hw_scene hs on hmut.scene_id = hs.scene_id
        <where>
            <if test="monitorUnitTypeName != null  and monitorUnitTypeName != ''"> and hmut.monitor_unit_type_name like concat('%', #{monitorUnitTypeName}, '%')</if>
            <if test="vitualFlag != null  and vitualFlag != ''"> and hmut.vitual_flag = #{vitualFlag}</if>
            <if test="monitorUnitTypeStatus != null  and monitorUnitTypeStatus != ''"> and hmut.monitor_unit_type_status = #{monitorUnitTypeStatus}</if>
            <if test="languageCode != null  and languageCode != ''"> and hmut.language_code = #{languageCode}</if>
            <if test="commonFlag != null  and commonFlag != ''"> and hmut.common_flag = #{commonFlag}</if>
            <if test="sceneId != null "> and hmut.scene_id = #{sceneId}</if>
            <if test="tenantId != null "> and hmut.tenant_id = #{tenantId}</if>
            <if test="unitTypeIcon != null  and unitTypeIcon != ''"> and hmut.unit_type_icon = #{unitTypeIcon}</if>
            <if test="unitTypeField != null  and unitTypeField != ''"> and hmut.unit_type_field = #{unitTypeField}</if>
            <!-- 租户数据范围过滤 -->
            ${params.tenantDataScope}
        </where>
    </select>

</mapper>
