<?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.affair.mapper.TIntercomMapper">
    
    <resultMap type="TIntercom" id="TIntercomResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="devno"    column="devno"    />
        <result property="devtype"    column="devtype"    />
        <result property="recvdept"    column="recvdept"    />
        <result property="fixedassetsno"    column="fixedassetsno"    />
        <result property="serialno"    column="serialno"    />
        <result property="costcenter"    column="costcenter"    />
        <result property="receiver"    column="receiver"    />
        <result property="euno"    column="euno"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTIntercomVo">
        select d.id, d.plant_code, d.serialnumber, d.devno, d.devtype, d.recvdept, d.fixedassetsno, d.serialno, d.costcenter, d.receiver, d.euno, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_intercom d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTIntercomList" parameterType="TIntercom" resultMap="TIntercomResult">
        <include refid="selectTIntercomVo"/>
        <where>
            <if test="devno != null  and devno != ''"> and devno like concat(concat('%', #{devno}), '%')</if>
            <if test="devtype != null  and devtype != ''"> and devtype like concat(concat('%', #{devtype}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.serialnumber asc
    </select>
    
    <select id="selectTIntercomById" parameterType="Long" resultMap="TIntercomResult">
        <include refid="selectTIntercomVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTIntercom" parameterType="TIntercom">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_intercom.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_intercom
        <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="devno != null">devno,</if>
            <if test="devtype != null">devtype,</if>
            <if test="recvdept != null">recvdept,</if>
            <if test="fixedassetsno != null">fixedassetsno,</if>
            <if test="serialno != null">serialno,</if>
            <if test="costcenter != null">costcenter,</if>
            <if test="receiver != null">receiver,</if>
            <if test="euno != null">euno,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</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="devno != null">#{devno},</if>
            <if test="devtype != null">#{devtype},</if>
            <if test="recvdept != null">#{recvdept},</if>
            <if test="fixedassetsno != null">#{fixedassetsno},</if>
            <if test="serialno != null">#{serialno},</if>
            <if test="costcenter != null">#{costcenter},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="euno != null">#{euno},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTIntercom" parameterType="TIntercom">
        update t_intercom
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="devno != null">devno = #{devno},</if>
            <if test="devtype != null">devtype = #{devtype},</if>
            <if test="recvdept != null">recvdept = #{recvdept},</if>
            <if test="fixedassetsno != null">fixedassetsno = #{fixedassetsno},</if>
            <if test="serialno != null">serialno = #{serialno},</if>
            <if test="costcenter != null">costcenter = #{costcenter},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="euno != null">euno = #{euno},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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