<?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.DmsBaseDeviceDepreciationMapper">

    <resultMap type="DmsBaseDeviceDepreciation" id="DmsBaseDeviceDepreciationResult">
        <result property="deviceDepreciationId"    column="device_depreciation_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="repairFrequency"    column="repair_frequency"    />
        <result property="repairCosts"    column="repair_costs"    />
        <result property="depreciationCost"    column="depreciation_cost"    />
        <result property="putintoTime"    column="putinto_time"    />
        <result property="useLife"    column="use_life"    />
        <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="selectDmsBaseDeviceDepreciationVo">
        select device_depreciation_id, device_id, repair_frequency, repair_costs, depreciation_cost, putinto_time, use_life, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_device_depreciation
    </sql>

    <select id="selectDmsBaseDeviceDepreciationList" parameterType="DmsBaseDeviceDepreciation" resultMap="DmsBaseDeviceDepreciationResult">
        select a.device_depreciation_id, a.device_id, a.repair_frequency, a.repair_costs, a.depreciation_cost, a.putinto_time, a.use_life, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_device_depreciation 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="repairFrequency != null "> and a.repair_frequency = #{repairFrequency}</if>
            <if test="repairCosts != null "> and a.repair_costs = #{repairCosts}</if>
            <if test="depreciationCost != null "> and a.depreciation_cost = #{depreciationCost}</if>
            <if test="params.beginTime != null and params.endTime != null">and a.putinto_time between #{params.beginTime} and #{params.endTime}</if>
            <if test="useLife != null "> and a.use_life = #{useLife}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
            <if test="deviceName != null "> and b.device_name like concat('%', #{deviceName},'%')</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceDepreciationByDeviceDepreciationId" parameterType="Long" resultMap="DmsBaseDeviceDepreciationResult">
        <include refid="selectDmsBaseDeviceDepreciationVo"/>
        where device_depreciation_id = #{deviceDepreciationId}
    </select>

    <insert id="insertDmsBaseDeviceDepreciation" parameterType="DmsBaseDeviceDepreciation" useGeneratedKeys="true" keyProperty="deviceDepreciationId">
        insert into dms_base_device_depreciation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="repairFrequency != null">repair_frequency,</if>
            <if test="repairCosts != null">repair_costs,</if>
            <if test="depreciationCost != null">depreciation_cost,</if>
            <if test="putintoTime != null">putinto_time,</if>
            <if test="useLife != null">use_life,</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="repairFrequency != null">#{repairFrequency},</if>
            <if test="repairCosts != null">#{repairCosts},</if>
            <if test="depreciationCost != null">#{depreciationCost},</if>
            <if test="putintoTime != null">#{putintoTime},</if>
            <if test="useLife != null">#{useLife},</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="updateDmsBaseDeviceDepreciation" parameterType="DmsBaseDeviceDepreciation">
        update dms_base_device_depreciation
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="repairFrequency != null">repair_frequency = #{repairFrequency},</if>
            <if test="repairCosts != null">repair_costs = #{repairCosts},</if>
            <if test="depreciationCost != null">depreciation_cost = #{depreciationCost},</if>
            <if test="putintoTime != null">putinto_time = #{putintoTime},</if>
            <if test="useLife != null">use_life = #{useLife},</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_depreciation_id = #{deviceDepreciationId}
    </update>

    <delete id="deleteDmsBaseDeviceDepreciationByDeviceDepreciationId" parameterType="Long">
        delete from dms_base_device_depreciation where device_depreciation_id = #{deviceDepreciationId}
    </delete>

    <delete id="deleteDmsBaseDeviceDepreciationByDeviceDepreciationIds" parameterType="String">
        delete from dms_base_device_depreciation where device_depreciation_id in
        <foreach item="deviceDepreciationId" collection="array" open="(" separator="," close=")">
            #{deviceDepreciationId}
        </foreach>
    </delete>
</mapper>
