<?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.EquipmentBrandMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.equipment.entity.EquipmentBrand">
        <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="brand" property="brand"/>
        <result column="type_id" property="typeId"/>
        <result column="rank" property="rank"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, brand AS brand, type_id AS typeId, rank AS rank
    </sql>




    <select id="selectEquipmentBrandById" resultType="EquipmentBrand" >
        select * from equipment_brand  where id=#{id} and is_delete = 0 limit 1 
    </select>



    <insert id="insertEquipmentBrand" parameterType="EquipmentBrand" useGeneratedKeys="true" keyProperty="id" >
        insert into equipment_brand(
            <if test="brand != null">brand, </if>
            <if test="typeId != null">type_id, </if>
            <if test="rank != null">rank, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="brand != null">#{ brand}, </if>
            <if test="typeId != null">#{ typeId}, </if>
            <if test="rank != null">#{ rank}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateEquipmentBrandById" parameterType="EquipmentBrand" >
        update
            equipment_brand
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="rank != null">rank = #{rank}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEquipmentBrandById" parameterType="EquipmentBrand" >
        update
            equipment_brand    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            brand = #{brand},
            type_id = #{typeId},
            rank = #{rank}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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



    <select id="selectEquipmentBrandByTypeBrand"
            resultType="com.lz.modules.equipment.entity.EquipmentBrand">
             select * from equipment_brand  where is_delete = 0 and type_id = #{typeId} and brand = #{brand} limit 1
    </select>

    <select id="selectByCondition" resultType="com.lz.modules.equipment.entity.EquipmentBrand">
        select * from equipment_brand where is_delete = 0
        <if test="req.typeId != null">and type_id = #{req.typeId}</if>
        <if test="req.brand != null and req.brand != '' ">
            AND brand LIKE CONCAT('%',#{req.brand},'%')
        </if>
        order by rank desc , id desc
    </select>

    <select id="selectEquipmentBrandByTypeAndLikeBrand"
            resultType="com.lz.modules.equipment.entity.EquipmentBrand">
        select * from equipment_brand  where is_delete = 0 and type_id = #{typeId} and brand like concat('%', #{brand},'%')
    </select>


    <select id="selectAll" resultType="com.lz.modules.equipment.entity.EquipmentBrand">
        select * from equipment_brand  where  is_delete = 0  order by rank desc ,id desc
    </select>


    <select id="selectByTypeId" resultType="com.lz.modules.equipment.entity.EquipmentBrand">
        select * from equipment_brand  where  is_delete = 0 and type_id = #{typeId}  order by rank desc ,id desc
    </select>

    <select id="selectByBrand" resultType="com.lz.modules.equipment.entity.EquipmentBrand">
        select * from equipment_brand  where  is_delete = 0 and brand = #{brand}  limit 1
    </select>
</mapper>

