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

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


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


    <select id="selectEquipmentSpecsById" resultType="EquipmentSpecs">
        select * from equipment_specs  where id=#{id} and is_delete = 0 limit 1
    </select>

    <insert id="insertEquipmentSpecs" parameterType="EquipmentSpecs" useGeneratedKeys="true" keyProperty="id">
        insert into equipment_specs(
        <if test="specs != null">specs,</if>
        <if test="brandId != null">brand_id,</if>
        <if test="typeId != null">type_id,</if>
        <if test="rank != null">rank,</if>
        <if test="skus != null">skus,</if>
        <if test="remark != null">remark,</if>
        <if test="used != null">used,</if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="specs != null">#{ specs},</if>
        <if test="brandId != null">#{ brandId},</if>
        <if test="typeId != null">#{ typeId},</if>
        <if test="rank != null">#{ rank},</if>
        <if test="skus != null">#{ skus},</if>
        <if test="remark != null">#{ remark},</if>
        <if test="used != null">#{ used},</if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateEquipmentSpecsById" parameterType="EquipmentSpecs">
        update
        equipment_specs
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="specs != null">specs = #{specs},</if>
            <if test="brandId != null">brand_id = #{brandId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="rank != null">rank = #{rank},</if>
            <if test="skus != null">skus = #{skus},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="used != null">used = #{used}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEquipmentSpecsById" parameterType="EquipmentSpecs">
        update
            equipment_specs
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            specs = #{specs},
            brand_id = #{brandId},
            type_id = #{typeId},
            rank = #{rank},
            skus = #{skus},
            remark = #{remark},
            used = #{used}
        ,gmt_modified = now()
        where id = #{id}
    </update>


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


    <select id="selectEquipmentSpecsByTypeBrandSpecss"
            resultType="com.lz.modules.equipment.entity.EquipmentSpecs">
             select * from equipment_specs  where  is_delete = 0 and type_id = #{typeId}   and brand_id=#{brandId} and specs=#{specs} limit 1
    </select>


    <select id="selectByCondition" resultType="EquipmentSpecs">
        select * from equipment_specs where is_delete = 0
        <if test="req.typeId != null">and type_id = #{req.typeId}</if>
        <if test="req.brandId != null">and brand_id = #{req.brandId}</if>
        <if test="req.specs != null and req.specs != '' ">
            AND specs LIKE CONCAT('%',#{req.specs},'%')
        </if>
        order by rank desc, id desc
  </select>



    <select id="selectEquipmentSpecsByTypeBrandLikeSpecss"
            resultType="com.lz.modules.equipment.entity.EquipmentSpecs">
        select * from equipment_specs  where  is_delete = 0 and type_id = #{typeId} and brand_id=#{brandId} and specs like concat('%',#{specs},'%')
    </select>


    <select id="selectSpecs" resultType="com.lz.modules.equipment.entity.EquipmentSpecs">
        select * from equipment_specs  where  is_delete = 0 and specs = #{specs}  limit 1
    </select>
</mapper>

