<?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.project.reliability.mapper.TAssetlistMapper">
    
    <resultMap type="TAssetlist" id="TAssetlistResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="assetclass"    column="assetclass"    />
        <result property="assetno"    column="assetno"    />
        <result property="assetnoref"    column="assetnoref"    />
        <result property="costcenter"    column="costcenter"    />
        <result property="capitalizedon"    column="capitalizedon"    />
        <result property="description"    column="description"    />
        <result property="responsible"    column="responsible"    />
        <result property="room"    column="room"    />
        <result property="tagno"    column="tagno"    />
        <result property="assetresult"    column="assetresult"    />
        <result property="comments"    column="comments"    />
        <result property="ccmanager"    column="ccmanager"    />
        <result property="bu"    column="bu"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
        <result property="startDate"    column="capitalizedon"    />
        <result property="endDate"    column="capitalizedon"    />
    </resultMap>

    <sql id="selectTAssetlistVo">
        select d.id, d.plant_code, d.serialnumber, d.assetclass, d.assetno, d.assetnoref, d.costcenter, d.capitalizedon, d.description, d.responsible, d.room, d.tagno, d.assetresult, d.comments, d.ccmanager, d.bu, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_assetlist d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAssetlistList" parameterType="TAssetlist" resultMap="TAssetlistResult">
        <include refid="selectTAssetlistVo"/>
        <where>  
            <if test="assetclass != null  and assetclass != ''"> and assetclass like concat(concat('%', #{assetclass}), '%')</if>
            <if test="assetno != null  and assetno != ''"> and assetno like concat(concat('%', #{assetno}), '%')</if>
            <if test="startDate != null ">and capitalizedon <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and capitalizedon <![CDATA[<=]]>#{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTAssetlistById" parameterType="Long" resultMap="TAssetlistResult">
        <include refid="selectTAssetlistVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTAssetlist" parameterType="TAssetlist">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_assetlist.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_assetlist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="serialnumber != null">serialnumber,</if>
            <if test="assetclass != null and assetclass != ''">assetclass,</if>
            <if test="assetno != null and assetno != ''">assetno,</if>
            <if test="assetnoref != null">assetnoref,</if>
            <if test="costcenter != null">costcenter,</if>
            <if test="capitalizedon != null">capitalizedon,</if>
            <if test="description != null">description,</if>
            <if test="responsible != null">responsible,</if>
            <if test="room != null">room,</if>
            <if test="tagno != null">tagno,</if>
            <if test="assetresult != null">assetresult,</if>
            <if test="comments != null">comments,</if>
            <if test="ccmanager != null">ccmanager,</if>
            <if test="bu != null">bu,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="serialnumber != null">#{serialnumber},</if>
            <if test="assetclass != null and assetclass != ''">#{assetclass},</if>
            <if test="assetno != null and assetno != ''">#{assetno},</if>
            <if test="assetnoref != null">#{assetnoref},</if>
            <if test="costcenter != null">#{costcenter},</if>
            <if test="capitalizedon != null">#{capitalizedon},</if>
            <if test="description != null">#{description},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="room != null">#{room},</if>
            <if test="tagno != null">#{tagno},</if>
            <if test="assetresult != null">#{assetresult},</if>
            <if test="comments != null">#{comments},</if>
            <if test="ccmanager != null">#{ccmanager},</if>
            <if test="bu != null">#{bu},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTAssetlist" parameterType="TAssetlist">
        update t_assetlist
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="assetclass != null and assetclass != ''">assetclass = #{assetclass},</if>
            <if test="assetno != null and assetno != ''">assetno = #{assetno},</if>
            <if test="assetnoref != null">assetnoref = #{assetnoref},</if>
            <if test="costcenter != null">costcenter = #{costcenter},</if>
            <if test="capitalizedon != null">capitalizedon = #{capitalizedon},</if>
            <if test="description != null">description = #{description},</if>
            <if test="responsible != null">responsible = #{responsible},</if>
            <if test="room != null">room = #{room},</if>
            <if test="tagno != null">tagno = #{tagno},</if>
            <if test="assetresult != null">assetresult = #{assetresult},</if>
            <if test="comments != null">comments = #{comments},</if>
            <if test="ccmanager != null">ccmanager = #{ccmanager},</if>
            <if test="bu != null">bu = #{bu},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTAssetlistById" parameterType="Long">
        update t_assetlist set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTAssetlistByIds" parameterType="String">
        update t_assetlist set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>