<?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.lz.modules.equipment.dao.EquipmentQrMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.equipment.entity.EquipmentQr">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="qr" property="qr"/>
        <result column="type" property="type"/>
        <result column="owner_id" property="ownerId"/>
        <result column="specs_id" property="specsId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, qr AS qr, type AS type, owner_id AS ownerId, specs_id AS specsId
    </sql>




    <select id="selectEquipmentQrById" resultType="EquipmentQr" >
        select * from equipment_qr  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertEquipmentQr" parameterType="EquipmentQr" useGeneratedKeys="true" keyProperty="id" >
        insert into equipment_qr(
        <if test="qr != null">qr, </if>
        <if test="type != null">type, </if>
        <if test="ownerId != null">owner_id, </if>
        <if test="specsId != null">specs_id, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="qr != null">#{ qr}, </if>
        <if test="type != null">#{ type}, </if>
        <if test="ownerId != null">#{ ownerId}, </if>
        <if test="specsId != null">#{ specsId}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateEquipmentQrById" parameterType="EquipmentQr" >
        update
        equipment_qr
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="qr != null">qr = #{qr},</if>
            <if test="type != null">type = #{type},</if>
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="specsId != null">specs_id = #{specsId}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEquipmentQrById" parameterType="EquipmentQr" >
        update
            equipment_qr
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            qr = #{qr},
            type = #{type},
            owner_id = #{ownerId},
            specs_id = #{specsId}
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteEquipmentQrById" parameterType="java.lang.Long">
        update equipment_qr set is_delete = 1 where id=#{id} limit 1
    </update>

    <select id="findRrBySpec" resultType="com.lz.modules.equipment.entity.EquipmentQr">
        select * from equipment_qr  where is_delete = 0
        <if test="specsId != null">
            and specs_id = #{specsId}
        </if>
    </select>

    <select id="selectByOwnerIdType" resultType="com.lz.modules.equipment.entity.EquipmentQr">
        select * from equipment_qr  where  type = #{type} and  owner_id = #{ownerId} and specs_id = #{specsId} and is_delete = 0 limit 1
    </select>



</mapper>