<?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.hw.dms.mapper.DmsBaseDeviceFilesMapper">

    <resultMap type="DmsBaseDeviceFiles" id="DmsBaseDeviceFilesResult">
        <result property="deviceFilesId"    column="device_files_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="filesCode"    column="files_code"    />
        <result property="filesName"    column="files_name"    />
        <result property="filesPath"    column="files_path"    />
        <result property="isFlag"    column="is_flag"    />
        <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"    />
    </resultMap>

    <sql id="selectDmsBaseDeviceFilesVo">
        select device_files_id, device_id, files_code, files_name, files_path, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_device_files
    </sql>

    <select id="selectDmsBaseDeviceFilesList" parameterType="DmsBaseDeviceFiles" resultMap="DmsBaseDeviceFilesResult">
        select a.device_files_id, a.device_id, a.files_code, a.files_name, a.files_path, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_device_files a
        left join dms_base_device_ledger b on a.device_id = b.device_id
        <where>
            <if test="deviceId != null "> and a.device_id = #{deviceId}</if>
            <if test="deviceName != null "> and b.device_name like concat ('%', #{deviceName} ,'%')</if>
            <if test="filesCode != null  and filesCode != ''"> and a.files_code = #{filesCode}</if>
            <if test="filesName != null  and filesName != ''"> and a.files_name like concat('%', #{filesName}, '%')</if>
            <if test="filesPath != null  and filesPath != ''"> and a.files_path = #{filesPath}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceFilesByDeviceFilesId" parameterType="Long" resultMap="DmsBaseDeviceFilesResult">
        <include refid="selectDmsBaseDeviceFilesVo"/>
        where device_files_id = #{deviceFilesId}
    </select>

    <insert id="insertDmsBaseDeviceFiles" parameterType="DmsBaseDeviceFiles" useGeneratedKeys="true" keyProperty="deviceFilesId">
        insert into dms_base_device_files
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="filesCode != null">files_code,</if>
            <if test="filesName != null and filesName != ''">files_name,</if>
            <if test="filesPath != null and filesPath != ''">files_path,</if>
            <if test="isFlag != null">is_flag,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="filesCode != null">#{filesCode},</if>
            <if test="filesName != null and filesName != ''">#{filesName},</if>
            <if test="filesPath != null and filesPath != ''">#{filesPath},</if>
            <if test="isFlag != null">#{isFlag},</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>
         </trim>
    </insert>

    <update id="updateDmsBaseDeviceFiles" parameterType="DmsBaseDeviceFiles">
        update dms_base_device_files
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="filesCode != null">files_code = #{filesCode},</if>
            <if test="filesName != null and filesName != ''">files_name = #{filesName},</if>
            <if test="filesPath != null and filesPath != ''">files_path = #{filesPath},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</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>
        </trim>
        where device_files_id = #{deviceFilesId}
    </update>

    <delete id="deleteDmsBaseDeviceFilesByDeviceFilesId" parameterType="Long">
        delete from dms_base_device_files where device_files_id = #{deviceFilesId}
    </delete>

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