<?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.bonus.material.ma.mapper.DeviceManageMapper">
    <resultMap type="com.bonus.material.ma.domain.DeviceManage" id="DeviceManageResult">
        <result property="deviceId"    column="device_id"    />
        <result property="itemType"    column="item_type"    />
        <result property="deviceType"    column="device_type"    />
        <result property="specsModel"    column="specs_model"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="deviceStatus"    column="device_status"    />
        <result property="fixedAssetsNumber"    column="fixed_assets_number"    />
        <result property="deviceOriginalNumber"    column="device_original_number"    />
        <result property="purchaseBatch"    column="purchase_batch"    />
        <result property="lebelId"    column="lebel_id"    />
        <result property="houseId"    column="house_id"    />
        <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="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectDeviceManageVo">
        select device_id, item_type, device_type, specs_model, device_number, device_status, fixed_assets_number, device_original_number, purchase_batch, lebel_id, house_id, del_flag, create_by, create_time, update_by, update_time, company_id from ma_device_manage
    </sql>

    <select id="selectDeviceManageList" parameterType="com.bonus.material.ma.domain.DeviceManage" resultMap="DeviceManageResult">
        <include refid="selectDeviceManageVo"/>
        <where>  
            <if test="itemType != null  and itemType != ''"> and item_type = #{itemType}</if>
            <if test="deviceType != null  and deviceType != ''"> and device_type = #{deviceType}</if>
            <if test="specsModel != null  and specsModel != ''"> and specs_model = #{specsModel}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="deviceStatus != null "> and device_status = #{deviceStatus}</if>
            <if test="fixedAssetsNumber != null  and fixedAssetsNumber != ''"> and fixed_assets_number = #{fixedAssetsNumber}</if>
            <if test="deviceOriginalNumber != null  and deviceOriginalNumber != ''"> and device_original_number = #{deviceOriginalNumber}</if>
            <if test="purchaseBatch != null  and purchaseBatch != ''"> and purchase_batch = #{purchaseBatch}</if>
            <if test="lebelId != null "> and lebel_id = #{lebelId}</if>
            <if test="houseId != null "> and house_id = #{houseId}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectDeviceManageByDeviceId" parameterType="Long" resultMap="DeviceManageResult">
        <include refid="selectDeviceManageVo"/>
        where device_id = #{deviceId}
    </select>
        
    <insert id="insertDeviceManage" parameterType="com.bonus.material.ma.domain.DeviceManage" useGeneratedKeys="true" keyProperty="deviceId">
        insert into ma_device_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemType != null">item_type,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="specsModel != null">specs_model,</if>
            <if test="deviceNumber != null">device_number,</if>
            <if test="deviceStatus != null">device_status,</if>
            <if test="fixedAssetsNumber != null">fixed_assets_number,</if>
            <if test="deviceOriginalNumber != null">device_original_number,</if>
            <if test="purchaseBatch != null">purchase_batch,</if>
            <if test="lebelId != null">lebel_id,</if>
            <if test="houseId != null">house_id,</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="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="itemType != null">#{itemType},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="specsModel != null">#{specsModel},</if>
            <if test="deviceNumber != null">#{deviceNumber},</if>
            <if test="deviceStatus != null">#{deviceStatus},</if>
            <if test="fixedAssetsNumber != null">#{fixedAssetsNumber},</if>
            <if test="deviceOriginalNumber != null">#{deviceOriginalNumber},</if>
            <if test="purchaseBatch != null">#{purchaseBatch},</if>
            <if test="lebelId != null">#{lebelId},</if>
            <if test="houseId != null">#{houseId},</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="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateDeviceManage" parameterType="com.bonus.material.ma.domain.DeviceManage">
        update ma_device_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="itemType != null">item_type = #{itemType},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="specsModel != null">specs_model = #{specsModel},</if>
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="deviceStatus != null">device_status = #{deviceStatus},</if>
            <if test="fixedAssetsNumber != null">fixed_assets_number = #{fixedAssetsNumber},</if>
            <if test="deviceOriginalNumber != null">device_original_number = #{deviceOriginalNumber},</if>
            <if test="purchaseBatch != null">purchase_batch = #{purchaseBatch},</if>
            <if test="lebelId != null">lebel_id = #{lebelId},</if>
            <if test="houseId != null">house_id = #{houseId},</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="companyId != null">company_id = #{companyId},</if>
        </trim>
        where device_id = #{deviceId}
    </update>

    <delete id="deleteDeviceManageByDeviceId" parameterType="Long">
        delete from ma_device_manage where device_id = #{deviceId}
    </delete>

    <delete id="deleteDeviceManageByDeviceIds" parameterType="String">
        delete from ma_device_manage where device_id in 
        <foreach item="deviceId" collection="array" open="(" separator="," close=")">
            #{deviceId}
        </foreach>
    </delete>
</mapper>