<?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.manage.mapper.EquipmentManageMapper">
    
    <resultMap type="EquipmentManage" id="EquipmentManageResult">
        <result property="equipmentId"    column="equipment_id"    />
        <result property="equipmentIp"    column="equipment_ip"    />
        <result property="equipmentNum"    column="equipment_num"    />
        <result property="equipmentName"    column="equipment_name"    />
        <result property="equipmentType"    column="equipment_type"    />
        <result property="equipmentAddress"    column="equipment_address"    />
        <result property="equipmentRegion"    column="equipment_region"    />
        <result property="equipmentTime"    column="equipment_time"    />
        <result property="equipmentImage"    column="equipment_image"    />
        <result property="runState"    column="run_state"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="delFlag"    column="del_flag"    />
        <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>

    <sql id="selectEquipmentManageVo">
        select equipment_id,
               equipment_ip,
               equipment_num,
               equipment_name,
               equipment_type,
               equipment_address,
               equipment_region,
               equipment_time,
               equipment_image,
               run_state,
               dept_id,
               dept_name,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from equipment_manage
    </sql>

    <select id="selectEquipmentManageList" parameterType="EquipmentManage" resultMap="EquipmentManageResult">
        <include refid="selectEquipmentManageVo"/>
        <where>  
            <if test="equipmentNum != null  and equipmentNum != ''"> and equipment_num  like concat('%', #{equipmentNum}, '%')</if>
            <if test="equipmentIp != null  and equipmentIp != ''"> and equipment_id  like concat('%', #{equipmentIp}, '%')</if>
            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
            <if test="equipmentType != null  and equipmentType != ''"> and equipment_type = #{equipmentType}</if>
            <if test="equipmentAddress != null  and equipmentAddress != ''"> and equipment_address = #{equipmentAddress}</if>
            <if test="equipmentRegion != null  and equipmentRegion != ''"> and equipment_region = #{equipmentRegion}</if>
            <if test="equipmentTime != null "> and equipment_time = #{equipmentTime}</if>
            <if test="equipmentImage != null  and equipmentImage != ''"> and equipment_image = #{equipmentImage}</if>
            <if test="runState != null  and runState != ''"> and run_state = #{runState}</if>
            <if test="deptId != null  "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name = #{deptName}</if>
        </where>
    </select>

    <select id="selectEquipmentManageByEquipmentIp" parameterType="EquipmentManage" resultMap="EquipmentManageResult">
        <include refid="selectEquipmentManageVo"/>
        <where>
            <if test="equipmentIp != null  and equipmentIp != ''">and equipment_ip= #{equipmentIp}</if>
        </where>
    </select>
    <select id="selectEquipmentManageByEquipmentId" parameterType="Long" resultMap="EquipmentManageResult">
        <include refid="selectEquipmentManageVo"/>
        where equipment_id = #{equipmentId}
    </select>

    <insert id="insertEquipmentManage" parameterType="EquipmentManage" useGeneratedKeys="true" keyProperty="equipmentId">
        insert into equipment_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="equipmentIp != null">equipment_ip,</if>
            <if test="equipmentNum != null">equipment_num,</if>
            <if test="equipmentName != null">equipment_name,</if>
            <if test="equipmentType != null">equipment_type,</if>
            <if test="equipmentAddress != null">equipment_address,</if>
            <if test="equipmentRegion != null">equipment_region,</if>
            <if test="equipmentTime != null">equipment_time,</if>
            <if test="equipmentImage != null">equipment_image,</if>
            <if test="runState != null">run_state,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="delFlag != null">del_flag,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="equipmentIp != null">#{equipmentIp},</if>
            <if test="equipmentNum != null">#{equipmentNum},</if>
            <if test="equipmentName != null">#{equipmentName},</if>
            <if test="equipmentType != null">#{equipmentType},</if>
            <if test="equipmentAddress != null">#{equipmentAddress},</if>
            <if test="equipmentRegion != null">#{equipmentRegion},</if>
            <if test="equipmentTime != null">#{equipmentTime},</if>
            <if test="equipmentImage != null">#{equipmentImage},</if>
            <if test="runState != null">#{runState},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="delFlag != null">#{delFlag},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateEquipmentManage" parameterType="EquipmentManage">
        update equipment_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="equipmentIp != null">equipment_ip = #{equipmentIp},</if>
            <if test="equipmentNum != null">equipment_num = #{equipmentNum},</if>
            <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
            <if test="equipmentType != null">equipment_type = #{equipmentType},</if>
            <if test="equipmentAddress != null">equipment_address = #{equipmentAddress},</if>
            <if test="equipmentRegion != null">equipment_region = #{equipmentRegion},</if>
            <if test="equipmentTime != null">equipment_time = #{equipmentTime},</if>
            <if test="equipmentImage != null">equipment_image = #{equipmentImage},</if>
            <if test="runState != null">run_state = #{runState},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="remark != null">remark = #{remark},</if>
        </trim>
        where equipment_id = #{equipmentId}
    </update>

    <delete id="deleteEquipmentManageByEquipmentId" parameterType="Long">
        delete from equipment_manage where equipment_id = #{equipmentId}
    </delete>

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