<?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.device.mapper.BaseTypeMapper">
    
    <resultMap type="BaseType" id="BaseTypeResult">
        <result property="objId"    column="obj_id"    />
        <result property="deviceTypeName"    column="device_type_name"    />
        <result property="defaultPrice"    column="default_price"    />
        <result property="defaultTime"    column="default_time"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBaseTypeVo">
        select obj_id, device_type_name, default_price, default_time, create_by, create_time, update_by, update_time,remark from device_base_type
    </sql>

    <select id="selectBaseTypeList" parameterType="BaseType" resultMap="BaseTypeResult">
        <include refid="selectBaseTypeVo"/>
        <where>  
            <if test="deviceTypeName != null  and deviceTypeName != ''"> and device_type_name = #{deviceTypeName}</if>
        </where>
    </select>
    
    <select id="selectBaseTypeByObjId" parameterType="Long" resultMap="BaseTypeResult">
        <include refid="selectBaseTypeVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBaseType" parameterType="BaseType" useGeneratedKeys="true" keyProperty="objId">
        insert into device_base_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceTypeName != null">device_type_name,</if>
            <if test="defaultPrice != null">default_price,</if>
            <if test="defaultTime != null">default_time,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceTypeName != null">#{deviceTypeName},</if>
            <if test="defaultPrice != null">#{defaultPrice},</if>
            <if test="defaultTime != null">#{defaultTime},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBaseType" parameterType="BaseType">
        update device_base_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceTypeName != null">device_type_name = #{deviceTypeName},</if>
            <if test="defaultPrice != null">default_price = #{defaultPrice},</if>
            <if test="defaultTime != null">default_time = #{defaultTime},</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="remark != null">remark = #{remark},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBaseTypeByObjId" parameterType="Long">
        delete from device_base_type where obj_id = #{objId}
    </delete>

    <delete id="deleteBaseTypeByObjIds" parameterType="String">
        delete from device_base_type where obj_id in 
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>


    <select id="checkDeviceTypeName" resultMap="BaseTypeResult">
        <include refid="selectBaseTypeVo"/>
        where device_type_name = #{deviceTypeName} limit 1
    </select>

</mapper>