<?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.DeviceLedgerMapper">
    <resultMap type="com.ruoyi.ems.domain.DeviceLedger" id="deviceLedgerResult">
        <result property="id" column="id"/>
        <result property="recordCode" column="record_code"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="objType" column="obj_type"/>
        <result property="objCode" column="obj_code"/>
        <result property="objName" column="obj_name"/>
        <result property="recordTime" column="record_time"/>
        <result property="insLocation" column="ins_location"/>
        <result property="maintainTitle" column="maintain_title"/>
        <result property="maintainContent" column="maintain_content"/>
        <result property="maintainPerson" column="maintain_person"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <sql id="selectDeviceLedgerVo">
        select id,
               record_code,
               area_code,
               obj_type,
               obj_code,
               obj_name,
               record_time,
               ins_location,
               maintain_title,
               maintain_content,
               maintain_person,
               create_time,
               update_time
        from adm_ems_device_ledger
    </sql>
    <select id="selectDeviceLedgerList" parameterType="com.ruoyi.ems.domain.DeviceLedger" resultMap="deviceLedgerResult">
        select
            r.id, r.record_code, r.area_code, a.area_name, r.obj_type, r.obj_code, r.obj_name, r.record_time, r.ins_location, r.maintain_title, r.maintain_content, r.maintain_person, r.create_time, r.update_time
        from adm_ems_device_ledger r
            left join adm_area a on r.area_code = a.area_code
        <where>
            <if test="areaCode != null and areaCode != '' and areaCode != '-1'">and r.area_code= #{areaCode}</if>
            <if test="objType != null "> and r.obj_type = #{objType}</if>
            <if test="objName != null and objName != ''"> and r.obj_name like concat('%', #{objName}, '%')</if>
            <if test="startRecTime != null  and startRecTime != '' and endRecTime != null and endRecTime !=''">
                and r.record_time &gt;= #{startRecTime} and r.record_time &lt;= #{endRecTime}
            </if>
        </where>
    </select>
    <select id="selectDeviceLedgerById" parameterType="Long" resultMap="deviceLedgerResult">
        <include refid="selectDeviceLedgerVo"/>
        where id = #{id}
    </select>
    <insert id="insertDeviceLedger" parameterType="com.ruoyi.ems.domain.DeviceLedger" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_device_ledger
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordCode != null and recordCode != ''">record_code,</if>
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="objType != null">obj_type,</if>
            <if test="objCode != null and objCode != ''">obj_code,</if>
            <if test="objName != null">obj_name,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="insLocation != null">ins_location,</if>
            <if test="maintainTitle != null and maintainTitle != ''">maintain_title,</if>
            <if test="maintainContent != null">maintain_content,</if>
            <if test="maintainPerson != null">maintain_person,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordCode != null and recordCode != ''">#{recordCode},</if>
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="objType != null">#{objType},</if>
            <if test="objCode != null and objCode != ''">#{objCode},</if>
            <if test="objName != null">#{objName},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="insLocation != null">#{insLocation},</if>
            <if test="maintainTitle != null and maintainTitle != ''">#{maintainTitle},</if>
            <if test="maintainContent != null">#{maintainContent},</if>
            <if test="maintainPerson != null">#{maintainPerson},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <update id="updateDeviceLedger" parameterType="com.ruoyi.ems.domain.DeviceLedger">
        update adm_ems_device_ledger
        <trim prefix="SET" suffixOverrides=",">
            <if test="recordCode != null and recordCode != ''">record_code = #{recordCode},</if>
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="objType != null">obj_type = #{objType},</if>
            <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
            <if test="objName != null">obj_name = #{objName},</if>
            <if test="objName != null">obj_name = #{objName},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="insLocation != null">ins_location = #{insLocation},</if>
            <if test="maintainTitle != null and maintainTitle != ''">maintain_title = #{maintainTitle},</if>
            <if test="maintainContent != null">maintain_content = #{maintainContent},</if>
            <if test="maintainPerson != null">maintain_person = #{maintainPerson},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
    <delete id="deleteDeviceLedgerById" parameterType="Long">
        delete from adm_ems_device_ledger where id = #{id}
    </delete>
    <delete id="deleteDeviceLedgerByIds" parameterType="String">
        delete from adm_ems_device_ledger where id in
        <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach>
    </delete>
</mapper>