<?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.baseinfo.mapper.BaseDeviceInfoMapper">

    <resultMap type="BaseDeviceInfo" id="BaseDeviceInfoResult">
        <result property="objid"    column="objid"    />
        <result property="deviceId"    column="device_id"    />
        <result property="workingProcedureId"    column="working_procedure_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="price"    column="price"    />
        <result property="deviceType"    column="device_type"    />
        <result property="status"    column="status"    />
        <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"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="workingProcedureName"    column="working_procedure_name"    />
    </resultMap>

    <sql id="selectBaseDeviceInfoVo">
        select objid, device_id, working_procedure_id, device_name, price, device_type, status, remark, create_by, create_time, update_by, update_time, del_flag from base_device_info
    </sql>

    <select id="selectBaseDeviceInfoList" parameterType="BaseDeviceInfo" resultMap="BaseDeviceInfoResult">
        select t1.objid, t1.device_id, t1.working_procedure_id,t2.working_procedure_name, t1.device_name, t1.price, t1.device_type, t1.status, t1.remark, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag from base_device_info t1
        left join base_workingprocedure_info t2 on t1.working_procedure_id = t2.working_procedure_id
        <where>
            <if test="deviceId != null  and deviceId != ''"> and t1.device_id = #{deviceId}</if>
            <if test="workingProcedureId != null  and workingProcedureId != ''"> and t1.working_procedure_id = #{workingProcedureId}</if>
            <if test="deviceName != null  and deviceName != ''"> and t1.device_name like ('%' + #{deviceName} + '%')</if>
            <if test="price != null "> and t1.price = #{price}</if>
            <if test="deviceType != null  and deviceType != ''"> and t1.device_type = #{deviceType}</if>
            <if test="status != null  and status != ''"> and t1.status = #{status}</if>
        </where>
    </select>

    <select id="selectBaseDeviceInfoById" parameterType="Long" resultMap="BaseDeviceInfoResult">
        <include refid="selectBaseDeviceInfoVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseDeviceInfo" parameterType="BaseDeviceInfo">
        insert into base_device_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objid != null">objid,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="workingProcedureId != null">working_procedure_id,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="price != null">price,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="status != null">status,</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>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objid != null">#{objid},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="workingProcedureId != null">#{workingProcedureId},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="price != null">#{price},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="status != null">#{status},</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>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateBaseDeviceInfo" parameterType="BaseDeviceInfo">
        update base_device_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="workingProcedureId != null">working_procedure_id = #{workingProcedureId},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="price != null">price = #{price},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="status != null">status = #{status},</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>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseDeviceInfoById" parameterType="Long">
        delete from base_device_info where objid = #{objid}
    </delete>

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

</mapper>
