<?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.invoice.mapper.TInvoiceContractorMapper">

    <resultMap type="TInvoiceContractor" id="TInvoiceContractorResult">
        <result property="id"    column="id"    />
        <result property="contractorName"    column="contractor_name"    />
        <result property="contact"    column="contact"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="address"    column="address"    />
        <result property="username"    column="username"    />
        <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="selectTInvoiceContractorVo">
        select d.id, d.contractor_name, d.contact, d.phonenumber, d.address, d.username, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_invoice_contractor d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTInvoiceContractorList" parameterType="TInvoiceContractor" resultMap="TInvoiceContractorResult">
        select d.id, d.contractor_name, d.contact, d.phonenumber, d.address, d.username, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,u.password from t_invoice_contractor d
        left join sys_user u on d.username=u.user_name and u.del_flag=0
        <where>
            <if test="contractorName != null  and contractorName != ''"> and contractor_name like concat(concat('%', #{contractorName}), '%')</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="username != null  and username != ''"> and username = #{username}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTInvoiceContractorById" parameterType="Long" resultMap="TInvoiceContractorResult">
        <include refid="selectTInvoiceContractorVo"/>
        where id = #{id}
    </select>

    <select id="selectTInvoiceContractorByName" parameterType="String" resultMap="TInvoiceContractorResult">
        <include refid="selectTInvoiceContractorVo"/>
        where username = #{username}
    </select>

    <insert id="insertTInvoiceContractor" parameterType="TInvoiceContractor">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_invoice_contractor.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_invoice_contractor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="contractorName != null">contractor_name,</if>
            <if test="contact != null">contact,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="address != null">address,</if>
            <if test="username != null">username,</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="contractorName != null">#{contractorName},</if>
            <if test="contact != null">#{contact},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="address != null">#{address},</if>
            <if test="username != null">#{username},</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="updateTInvoiceContractor" parameterType="TInvoiceContractor">
        update t_invoice_contractor
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractorName != null">contractor_name = #{contractorName},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="address != null">address = #{address},</if>
            <if test="username != null">username = #{username},</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="deleteTInvoiceContractorById" parameterType="Long">
        update t_invoice_contractor set del_flag = 2 where id = #{id}
    </update>

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

</mapper>
