<?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.dsk.system.mapper.BusinessRelateCompanyMapper">

    <resultMap type="com.dsk.common.core.domain.entity.BusinessRelateCompany" id="BusinessRelateCompanyResult">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="companyRole" column="company_role"/>
        <result property="responsiblePerson" column="responsible_person"/>
        <result property="phone" column="phone"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="depth" column="depth"/>
    </resultMap>

    <sql id="selectBusinessRelateCompanyVo">
        select id,
               business_id,
               company_id,
               company_name,
               company_role,
               responsible_person,
               phone,
               depth,
               create_time,
               update_time
        from business_relate_company
    </sql>

    <select id="selectBusinessRelateCompanyList" parameterType="com.dsk.common.core.domain.entity.BusinessRelateCompany"
            resultMap="BusinessRelateCompanyResult">
        <include refid="selectBusinessRelateCompanyVo"/>
        <where>
            <if test="businessId != null ">and business_id = #{businessId}</if>
            <if test="companyId != null ">and company_id = #{companyId}</if>
            <if test="companyName != null  and companyName != ''">and company_name like concat('%', #{companyName},
                '%')
            </if>
            <if test="companyRole != null  and companyRole != ''">and company_role = #{companyRole}</if>
            <if test="depth != null  and depth != ''">and depth = #{depth}</if>
            <if test="responsiblePerson != null  and responsiblePerson != ''">and responsible_person =
                #{responsiblePerson}
            </if>
            <if test="phone != null  and phone != ''">and phone = #{phone}</if>
        </where>
    </select>

    <select id="selectBusinessRelateCompanyById" parameterType="Long" resultMap="BusinessRelateCompanyResult">
        <include refid="selectBusinessRelateCompanyVo"/>
        where id = #{id}
    </select>

    <insert id="insertBusinessRelateCompany" parameterType="com.dsk.common.core.domain.entity.BusinessRelateCompany" useGeneratedKeys="true"
            keyProperty="id">
        insert into business_relate_company
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyName != null">company_name,</if>
            <if test="depth != null">depth,</if>
            <if test="companyRole != null">company_role,</if>
            <if test="responsiblePerson != null">responsible_person,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="depth != null">#{depth},</if>
            <if test="companyRole != null">#{companyRole},</if>
            <if test="responsiblePerson != null">#{responsiblePerson},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateBusinessRelateCompany" parameterType="com.dsk.common.core.domain.entity.BusinessRelateCompany">
        update business_relate_company
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="depth != null">depth = #{depth},</if>
            <if test="companyRole != null">company_role = #{companyRole},</if>
            <if test="responsiblePerson != null">responsible_person = #{responsiblePerson},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusinessRelateCompanyById" parameterType="Long">
        delete
        from business_relate_company
        where id = #{id}
    </delete>

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