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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.equipment.entity.EquipmentType">
        <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="describe" property="describe"/>
        <result column="type" property="type"/>
        <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, describe AS describe, type AS type, rank AS rank
    </sql>




    <select id="selectEquipmentTypeById" resultType="EquipmentType" >
        select * from equipment_type  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertEquipmentType" parameterType="EquipmentType" useGeneratedKeys="true" keyProperty="id" >
        insert into equipment_type(
        <if test="describe != null">describe, </if>
        <if test="type != null">type, </if>
        <if test="rank != null">rank, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="describe != null">#{ describe}, </if>
        <if test="type != null">#{ type}, </if>
        <if test="rank != null">#{ rank}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateEquipmentTypeById" parameterType="EquipmentType" >
        update
        equipment_type
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="describe != null">describe = #{describe},</if>
            <if test="type != null">type = #{type},</if>
            <if test="rank != null">rank = #{rank}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEquipmentTypeById" parameterType="EquipmentType" >
        update
            equipment_type
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            describe = #{describe},
            type = #{type},
            rank = #{rank}
        ,gmt_modified = now()
        where id = #{id}
    </update>


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


    <select id="listEquipmentTypes" resultType="EquipmentType">
        select * from equipment_type  where  is_delete = 0
    </select>

    <select id="selectEquipmentTypeByType" resultType="EquipmentType">
        select * from equipment_type  where  is_delete = 0 and type = #{type}
    </select>

    <select id="selectByType" resultType="com.lz.modules.equipment.entity.EquipmentType">
           select * from equipment_type  where  is_delete = 0 and type like concat('%',#{type},'%')
    </select>


    <select id="selectByCondition" resultType="EquipmentType">
        select * from equipment_type where is_delete = 0
        <if test="req.type != null and req.type != '' ">
            AND type LIKE CONCAT('%',#{req.type},'%')
        </if>

          order by rank desc , id desc
    </select>


    <select id="selectAll" resultType="com.lz.modules.equipment.entity.EquipmentType">
         select * from equipment_type  where  is_delete = 0 order by id desc
    </select>

</mapper>

