<?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.TOfficesupplyMapper">
    
    <resultMap type="TOfficesupply" id="TOfficesupplyResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="brand"    column="brand"    />
        <result property="name"    column="name"    />
        <result property="specs"    column="specs"    />
        <result property="goodsno"    column="goodsno"    />
        <result property="address"    column="address"    />
        <result property="unit"    column="unit"    />
        <result property="price"    column="price"    />
        <result property="count"    column="count"    />
        <result property="total"    column="total"    />
        <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="selectTOfficesupplyVo">
        select d.id, d.plant_code, d.serialnumber, d.brand, d.name, d.specs, d.goodsno, d.address, d.unit, d.price, d.count, d.total, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_officesupply d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTOfficesupplyList" parameterType="TOfficesupply" resultMap="TOfficesupplyResult">
        <include refid="selectTOfficesupplyVo"/>
        <where>  
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="serialnumber != null "> and serialnumber like concat(concat('%', #{serialnumber}), '%')</if>
            <if test="brand != null  and brand != ''"> and brand like concat(concat('%', #{brand}), '%')</if>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="specs != null  and specs != ''"> and specs like concat(concat('%', #{specs}), '%')</if>
            <if test="goodsno != null  and goodsno != ''"> and goodsno like concat(concat('%', #{goodsno}), '%')</if>
            <if test="address != null  and address != ''"> and address like concat(concat('%', #{address}), '%')</if>
            <if test="unit != null  and unit != ''"> and unit like concat(concat('%', #{unit}), '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.serialnumber asc
    </select>
    
    <select id="selectTOfficesupplyById" parameterType="String" resultMap="TOfficesupplyResult">
        <include refid="selectTOfficesupplyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTOfficesupply" parameterType="TOfficesupply">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_officesupply.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_officesupply
        <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="brand != null">brand,</if>
            <if test="name != null">name,</if>
            <if test="specs != null">specs,</if>
            <if test="goodsno != null">goodsno,</if>
            <if test="address != null">address,</if>
            <if test="unit != null">unit,</if>
            <if test="price != null">price,</if>
            <if test="count != null">count,</if>
            <if test="total != null">total,</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="brand != null">#{brand},</if>
            <if test="name != null">#{name},</if>
            <if test="specs != null">#{specs},</if>
            <if test="goodsno != null">#{goodsno},</if>
            <if test="address != null">#{address},</if>
            <if test="unit != null">#{unit},</if>
            <if test="price != null">#{price},</if>
            <if test="count != null">#{count},</if>
            <if test="total != null">#{total},</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="updateTOfficesupply" parameterType="TOfficesupply">
        update t_officesupply
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="name != null">name = #{name},</if>
            <if test="specs != null">specs = #{specs},</if>
            <if test="goodsno != null">goodsno = #{goodsno},</if>
            <if test="address != null">address = #{address},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="price != null">price = #{price},</if>
            <if test="count != null">count = #{count},</if>
            <if test="total != null">total = #{total},</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="deleteTOfficesupplyById" parameterType="String">
        update t_officesupply set del_flag = 2 where id = #{id}
    </update>

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