<?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.oa.mapper.CmcDeviceMapper">

    <resultMap type="CmcDevice" id="CmcDeviceResult">
        <result property="deviceId"    column="device_id"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="acquisitionTime"    column="acquisition_time"    />
        <result property="cost"    column="cost"    />
        <result property="expectLife"    column="expect_life"    />
        <result property="series"    column="series"    />
        <result property="brand"    column="brand"    />
        <result property="dayCost"    column="day_cost"    />
        <result property="place"    column="place"    />
        <result property="remark"    column="remark"    />
        <result property="checkTerm"    column="check_term"    />
        <result property="checkTime"    column="check_time"    />
        <result property="warranty"    column="warranty"    />
        <result property="manageDept"    column="manage_dept"    />
    </resultMap>

    <sql id="selectCmcDeviceVo">
        select device_id, device_number, code, name, type, acquisition_time, cost, expect_life, series, brand, day_cost, place, remark, check_term, check_time, warranty, manage_dept from cmc_device
    </sql>

    <select id="selectCmcDeviceList" parameterType="CmcDevice" resultMap="CmcDeviceResult">
        <include refid="selectCmcDeviceVo"/>
        <where>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number like concat('%', #{deviceNumber}, '%')</if>
            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type like concat('%', #{type}, '%')</if>
            <if test="acquisitionTime != null "> and acquisition_time = #{acquisitionTime}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="expectLife != null "> and expect_life = #{expectLife}</if>
            <if test="series != null  and series != ''"> and series like concat('%', #{series}, '%')</if>
            <if test="brand != null  and brand != ''"> and brand like concat('%', #{brand}, '%')</if>
            <if test="dayCost != null "> and day_cost = #{dayCost}</if>
            <if test="place != null  and place != ''"> and place like concat('%', #{place}, '%')</if>
            <if test="checkTerm != null "> and check_term = #{checkTerm}</if>
            <if test="checkTime != null "> and check_time = #{checkTime}</if>
            <if test="warranty != null "> and warranty = #{warranty}</if>
            <if test="manageDept != null "> and manage_dept = #{manageDept}</if>
        </where>
    </select>

    <select id="selectCmcDeviceByDeviceId" parameterType="Integer" resultMap="CmcDeviceResult">
        <include refid="selectCmcDeviceVo"/>
        where device_id = #{deviceId}
    </select>

    <insert id="insertCmcDevice" parameterType="CmcDevice" useGeneratedKeys="true" keyProperty="deviceId">
        insert into cmc_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceNumber != null">device_number,</if>
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="acquisitionTime != null">acquisition_time,</if>
            <if test="cost != null">cost,</if>
            <if test="expectLife != null">expect_life,</if>
            <if test="series != null">series,</if>
            <if test="brand != null">brand,</if>
            <if test="dayCost != null">day_cost,</if>
            <if test="place != null">place,</if>
            <if test="remark != null">remark,</if>
            <if test="checkTerm != null">check_term,</if>
            <if test="checkTime != null">check_time,</if>
            <if test="warranty != null">warranty,</if>
            <if test="manageDept != null">manage_dept,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceNumber != null">#{deviceNumber},</if>
            <if test="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="acquisitionTime != null">#{acquisitionTime},</if>
            <if test="cost != null">#{cost},</if>
            <if test="expectLife != null">#{expectLife},</if>
            <if test="series != null">#{series},</if>
            <if test="brand != null">#{brand},</if>
            <if test="dayCost != null">#{dayCost},</if>
            <if test="place != null">#{place},</if>
            <if test="remark != null">#{remark},</if>
            <if test="checkTerm != null">#{checkTerm},</if>
            <if test="checkTime != null">#{checkTime},</if>
            <if test="warranty != null">#{warranty},</if>
            <if test="manageDept != null">#{manageDept},</if>
        </trim>
    </insert>

    <update id="updateCmcDevice" parameterType="CmcDevice">
        update cmc_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="acquisitionTime != null">acquisition_time = #{acquisitionTime},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="expectLife != null">expect_life = #{expectLife},</if>
            <if test="series != null">series = #{series},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="dayCost != null">day_cost = #{dayCost},</if>
            <if test="place != null">place = #{place},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="checkTerm != null">check_term = #{checkTerm},</if>
            <if test="checkTime != null">check_time = #{checkTime},</if>
            <if test="warranty != null">warranty = #{warranty},</if>
            <if test="manageDept != null">manage_dept = #{manageDept},</if>
        </trim>
        where device_id = #{deviceId}
    </update>

    <delete id="deleteCmcDeviceByDeviceId" parameterType="Integer">
        delete from cmc_device where device_id = #{deviceId}
    </delete>

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