<?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.cpms.project.asset.mapper.TAssetBasedocMapper">
    
    <resultMap type="TAssetBasedoc" id="TAssetBasedocResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="docName"    column="doc_name"    />
        <result property="docStatus"    column="doc_status"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="remarks"    column="remarks"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectTAssetBasedocVo">
        select id, type, doc_name, doc_status, creater_code, createdate, remarks, del_flag, updater_code, updatedate, dept_id from t_asset_basedoc
    </sql>

    <select id="selectTAssetBasedocList" parameterType="TAssetBasedoc" resultMap="TAssetBasedocResult">
        <include refid="selectTAssetBasedocVo"/>
        <where>  
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="docName != null  and docName != ''"> and doc_name like concat('%', #{docName}, '%')</if>
            <if test="docStatus != null  and docStatus != ''"> and doc_status = #{docStatus}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>
    
    <select id="selectTAssetBasedocById" parameterType="Long" resultMap="TAssetBasedocResult">
        <include refid="selectTAssetBasedocVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTAssetBasedoc" parameterType="TAssetBasedoc" useGeneratedKeys="true" keyProperty="id">
        insert into t_asset_basedoc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="docName != null">doc_name,</if>
            <if test="docStatus != null">doc_status,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="docName != null">#{docName},</if>
            <if test="docStatus != null">#{docStatus},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTAssetBasedoc" parameterType="TAssetBasedoc">
        update t_asset_basedoc
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="docName != null">doc_name = #{docName},</if>
            <if test="docStatus != null">doc_status = #{docStatus},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTAssetBasedocById" parameterType="Long">
        delete from t_asset_basedoc where id = #{id}
    </delete>

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