<?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.ktg.iscs.mapper.IsHardwareMapper">

    <resultMap type="IsHardware" id="IsHardwareResult">
        <result property="id"    column="id"    />
        <result property="hardwareCode"    column="hardware_code"    />
        <result property="hardwareName"    column="hardware_name"    />
        <result property="hardwareBrand"    column="hardware_brand"    />
        <result property="hardwareSpec"    column="hardware_spec"    />
        <result property="hardwareTypeId"    column="hardware_type_id"    />
        <result property="hardwareTypeCode"    column="hardware_type_code"    />
        <result property="hardwareTypeName"    column="hardware_type_name"    />
        <result property="workshopId"    column="workshop_id"    />
        <result property="workshopCode"    column="workshop_code"    />
        <result property="workshopName"    column="workshop_name"    />
        <result property="status"    column="status"    />
        <result property="activationTime"    column="activation_time"    />
        <result property="availableTimes"    column="available_times"    />
        <result property="usedTimes"    column="used_times"    />
        <result property="availableLife"    column="available_life"    />
        <result property="usedLife"    column="used_life"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="serialNumber"    column="serial_number"    />
    </resultMap>

    <sql id="selectIsHardwareVo">
        select * from is_hardware
    </sql>

    <select id="selectIsHardwareList" parameterType="IsHardware" resultMap="IsHardwareResult">
        <include refid="selectIsHardwareVo"/>
        <where>
            <if test="hardwareCode != null  and hardwareCode != ''"> and hardware_code = #{hardwareCode}</if>
            <if test="hardwareName != null  and hardwareName != ''"> and hardware_name like concat('%', #{hardwareName}, '%')</if>
            <if test="hardwareBrand != null  and hardwareBrand != ''"> and hardware_brand = #{hardwareBrand}</if>
            <if test="hardwareSpec != null  and hardwareSpec != ''"> and hardware_spec = #{hardwareSpec}</if>
            <if test="hardwareTypeId != null "> and hardware_type_id = #{hardwareTypeId}</if>
            <if test="hardwareTypeCode != null  and hardwareTypeCode != ''"> and hardware_type_code = #{hardwareTypeCode}</if>
            <if test="hardwareTypeName != null  and hardwareTypeName != ''"> and hardware_type_name like concat('%', #{hardwareTypeName}, '%')</if>
            <if test="workshopId != null "> and workshop_id = #{workshopId}</if>
            <if test="workshopCode != null  and workshopCode != ''"> and workshop_code = #{workshopCode}</if>
            <if test="workshopName != null  and workshopName != ''"> and workshop_name like concat('%', #{workshopName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="activationTime != null "> and activation_time = #{activationTime}</if>
            <if test="availableTimes != null "> and available_times = #{availableTimes}</if>
            <if test="usedTimes != null "> and used_times = #{usedTimes}</if>
            <if test="availableLife != null "> and available_life = #{availableLife}</if>
            <if test="usedLife != null "> and used_life = #{usedLife}</if>
        </where>
    </select>

    <select id="selectIsHardwareById" parameterType="Long" resultMap="IsHardwareResult">
        <include refid="selectIsHardwareVo"/>
        where id = #{id}
    </select>

    <insert id="insertIsHardware" parameterType="IsHardware" useGeneratedKeys="true" keyProperty="id">
        insert into is_hardware
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hardwareCode != null and hardwareCode != ''">hardware_code,</if>
            <if test="hardwareName != null and hardwareName != ''">hardware_name,</if>
            <if test="hardwareBrand != null">hardware_brand,</if>
            <if test="hardwareSpec != null">hardware_spec,</if>
            <if test="hardwareTypeId != null">hardware_type_id,</if>
            <if test="hardwareTypeCode != null">hardware_type_code,</if>
            <if test="hardwareTypeName != null">hardware_type_name,</if>
            <if test="workshopId != null">workshop_id,</if>
            <if test="workshopCode != null">workshop_code,</if>
            <if test="workshopName != null">workshop_name,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="activationTime != null">activation_time,</if>
            <if test="availableTimes != null">available_times,</if>
            <if test="usedTimes != null">used_times,</if>
            <if test="availableLife != null">available_life,</if>
            <if test="usedLife != null">used_life,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="hardwareCode != null and hardwareCode != ''">#{hardwareCode},</if>
            <if test="hardwareName != null and hardwareName != ''">#{hardwareName},</if>
            <if test="hardwareBrand != null">#{hardwareBrand},</if>
            <if test="hardwareSpec != null">#{hardwareSpec},</if>
            <if test="hardwareTypeId != null">#{hardwareTypeId},</if>
            <if test="hardwareTypeCode != null">#{hardwareTypeCode},</if>
            <if test="hardwareTypeName != null">#{hardwareTypeName},</if>
            <if test="workshopId != null">#{workshopId},</if>
            <if test="workshopCode != null">#{workshopCode},</if>
            <if test="workshopName != null">#{workshopName},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="activationTime != null">#{activationTime},</if>
            <if test="availableTimes != null">#{availableTimes},</if>
            <if test="usedTimes != null">#{usedTimes},</if>
            <if test="availableLife != null">#{availableLife},</if>
            <if test="usedLife != null">#{usedLife},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
        </trim>
    </insert>

    <update id="updateIsHardware" parameterType="IsHardware">
        update is_hardware
        <trim prefix="SET" suffixOverrides=",">
            <if test="hardwareCode != null and hardwareCode != ''">hardware_code = #{hardwareCode},</if>
            <if test="hardwareName != null and hardwareName != ''">hardware_name = #{hardwareName},</if>
            <if test="hardwareBrand != null">hardware_brand = #{hardwareBrand},</if>
            <if test="hardwareSpec != null">hardware_spec = #{hardwareSpec},</if>
            <if test="hardwareTypeId != null">hardware_type_id = #{hardwareTypeId},</if>
            <if test="hardwareTypeCode != null">hardware_type_code = #{hardwareTypeCode},</if>
            <if test="hardwareTypeName != null">hardware_type_name = #{hardwareTypeName},</if>
            <if test="workshopId != null">workshop_id = #{workshopId},</if>
            <if test="workshopCode != null">workshop_code = #{workshopCode},</if>
            <if test="workshopName != null">workshop_name = #{workshopName},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="activationTime != null">activation_time = #{activationTime},</if>
            <if test="availableTimes != null">available_times = #{availableTimes},</if>
            <if test="usedTimes != null">used_times = #{usedTimes},</if>
            <if test="availableLife != null">available_life = #{availableLife},</if>
            <if test="usedLife != null">used_life = #{usedLife},</if>
            <if test="remark != null">remark = #{remark},</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="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIsHardwareById" parameterType="Long">
        delete from is_hardware where id = #{id}
    </delete>

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