<?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.asset.mapper.TbAssetMapper">
    
    <resultMap type="TbAsset" id="TbAssetResult">
        <result property="id"    column="id"    />
        <result property="barCode"    column="bar_code"    />
        <result property="number"    column="number"    />
        <result property="name"    column="name"    />
        <result property="kind"    column="kind"    />
        <result property="categoryNumber"    column="category_number"    />
        <result property="amount"    column="amount"    />
        <result property="quantity"    column="quantity"    />
        <result property="quantityUnit"    column="quantity_unit"    />
        <result property="buildDate"    column="build_date"    />
        <result property="placeName"    column="place_name"    />
        <result property="purpose"    column="purpose"    />
        <result property="deptId"    column="dept_id"    />
        <result property="registrant"    column="registrant"    />
        <result property="specificationsModel"    column="specifications_model"    />
        <result property="remark"    column="remark"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="brand"    column="brand"    />
        <result property="supplier"    column="supplier"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectTbAssetVo">
        select id, bar_code, number, name, kind, category_number, amount, quantity, quantity_unit, build_date, place_name, purpose, dept_id, registrant, specifications_model, remark, manufacturer, brand, supplier, status from tb_asset
    </sql>

    <select id="selectTbAssetList" parameterType="TbAsset" resultMap="TbAssetResult">
        <include refid="selectTbAssetVo"/>
        <where>  
            <if test="barCode != null  and barCode != ''"> and bar_code = #{barCode}</if>
            <if test="number != null  and number != ''"> and number = #{number}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="kind != null  and kind != ''"> and kind = #{kind}</if>
            <if test="categoryNumber != null  and categoryNumber != ''"> and category_number = #{categoryNumber}</if>
            <if test="buildDate != null "> and build_date = #{buildDate}</if>
            <if test="placeName != null  and placeName != ''"> and place_name like concat('%', #{placeName}, '%')</if>
            <if test="purpose != null  and purpose != ''"> and purpose = #{purpose}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="registrant != null  and registrant != ''"> and registrant = #{registrant}</if>
            <if test="remark != null  and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
            <if test="manufacturer != null  and manufacturer != ''"> and manufacturer = #{manufacturer}</if>
            <if test="brand != null  and brand != ''"> and brand = #{brand}</if>
            <if test="supplier != null  and supplier != ''"> and supplier = #{supplier}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectTbAssetById" parameterType="Long" resultMap="TbAssetResult">
        <include refid="selectTbAssetVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAsset" parameterType="TbAsset" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="barCode != null and barCode != ''">bar_code,</if>
            <if test="number != null and number != ''">number,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="kind != null and kind != ''">kind,</if>
            <if test="categoryNumber != null and categoryNumber != ''">category_number,</if>
            <if test="amount != null">amount,</if>
            <if test="quantity != null">quantity,</if>
            <if test="quantityUnit != null">quantity_unit,</if>
            <if test="buildDate != null">build_date,</if>
            <if test="placeName != null">place_name,</if>
            <if test="purpose != null">purpose,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="registrant != null and registrant != ''">registrant,</if>
            <if test="specificationsModel != null and specificationsModel != ''">specifications_model,</if>
            <if test="remark != null">remark,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="brand != null">brand,</if>
            <if test="supplier != null">supplier,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="barCode != null and barCode != ''">#{barCode},</if>
            <if test="number != null and number != ''">#{number},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="kind != null and kind != ''">#{kind},</if>
            <if test="categoryNumber != null and categoryNumber != ''">#{categoryNumber},</if>
            <if test="amount != null">#{amount},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="quantityUnit != null">#{quantityUnit},</if>
            <if test="buildDate != null">#{buildDate},</if>
            <if test="placeName != null">#{placeName},</if>
            <if test="purpose != null">#{purpose},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="registrant != null and registrant != ''">#{registrant},</if>
            <if test="specificationsModel != null and specificationsModel != ''">#{specificationsModel},</if>
            <if test="remark != null">#{remark},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="brand != null">#{brand},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateTbAsset" parameterType="TbAsset">
        update tb_asset
        <trim prefix="SET" suffixOverrides=",">
            <if test="barCode != null and barCode != ''">bar_code = #{barCode},</if>
            <if test="number != null and number != ''">number = #{number},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="kind != null and kind != ''">kind = #{kind},</if>
            <if test="categoryNumber != null and categoryNumber != ''">category_number = #{categoryNumber},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="quantityUnit != null">quantity_unit = #{quantityUnit},</if>
            <if test="buildDate != null">build_date = #{buildDate},</if>
            <if test="placeName != null">place_name = #{placeName},</if>
            <if test="purpose != null">purpose = #{purpose},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="registrant != null and registrant != ''">registrant = #{registrant},</if>
            <if test="specificationsModel != null and specificationsModel != ''">specifications_model = #{specificationsModel},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="supplier != null">supplier = #{supplier},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetById" parameterType="Long">
        delete from tb_asset where id = #{id}
    </delete>

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

    <insert id="replace" parameterType="TbAsset">
        replace into tb_asset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="barCode != null and barCode != ''">bar_code,</if>
            <if test="number != null and number != ''">number,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="kind != null and kind != ''">kind,</if>
            <if test="categoryNumber != null and categoryNumber != ''">category_number,</if>
            <if test="amount != null">amount,</if>
            <if test="quantity != null">quantity,</if>
            <if test="quantityUnit != null">quantity_unit,</if>
            <if test="buildDate != null">build_date,</if>
            <if test="placeName != null">place_name,</if>
            <if test="purpose != null">purpose,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="registrant != null and registrant != ''">registrant,</if>
            <if test="specificationsModel != null and specificationsModel != ''">specifications_model,</if>
            <if test="remark != null">remark,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="brand != null">brand,</if>
            <if test="supplier != null">supplier,</if>
            <if test="status != null">status,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="barCode != null and barCode != ''">#{barCode},</if>
            <if test="number != null and number != ''">#{number},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="kind != null and kind != ''">#{kind},</if>
            <if test="categoryNumber != null and categoryNumber != ''">#{categoryNumber},</if>
            <if test="amount != null">#{amount},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="quantityUnit != null">#{quantityUnit},</if>
            <if test="buildDate != null">#{buildDate},</if>
            <if test="placeName != null">#{placeName},</if>
            <if test="purpose != null">#{purpose},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="registrant != null and registrant != ''">#{registrant},</if>
            <if test="specificationsModel != null and specificationsModel != ''">#{specificationsModel},</if>
            <if test="remark != null">#{remark},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="brand != null">#{brand},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="status != null">#{status},</if>
        </trim>
    </insert>
</mapper>