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

    <resultMap type="com.ruoyi.system.domain.CpsMeetingEnterprise" id="CpsMeetingEnterpriseResult">
        <result property="id" column="id"/>
        <result property="enterpriseName" column="enterprise_name"/>
        <result property="tel" column="tel"/>
        <result property="inCharge" column="in_charge"/>
        <result property="tripId" column="trip_id"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectCpsMeetingEnterpriseVo">
        select enterprise.id as id,
               enterprise.enterprise_name,
               enterprise.tel,
               enterprise.in_charge,
               enterprise.trip_id,
               trip.trip_name,
               enterprise.update_time,
               enterprise.create_time,
               enterprise.create_by,
               enterprise.update_by
        from cps_meeting_enterprise enterprise
                 left join cps_meeting_enterprise_trip_info trip on enterprise.trip_id = trip.id
    </sql>

    <select id="selectCpsMeetingEnterpriseList" parameterType="com.ruoyi.system.domain.CpsMeetingEnterprise"
            resultMap="CpsMeetingEnterpriseResult">
        <include refid="selectCpsMeetingEnterpriseVo"/>
        <where>
            <if test="enterpriseName != null  and enterpriseName != ''">and enterprise_name like concat('%',
                #{enterpriseName}, '%')
            </if>
            <if test="inCharge != null  and inCharge != ''">and in_charge = #{inCharge}</if>
        </where>
    </select>

    <select id="selectCpsMeetingEnterpriseById" parameterType="Long" resultMap="CpsMeetingEnterpriseResult">
        <include refid="selectCpsMeetingEnterpriseVo"/>
        where enterprise.id = #{id}
    </select>

    <insert id="insertCpsMeetingEnterprise" parameterType="com.ruoyi.system.domain.CpsMeetingEnterprise"
            useGeneratedKeys="true" keyProperty="id">
        insert into cps_meeting_enterprise
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="enterpriseName != null and enterpriseName != ''">enterprise_name,</if>
            <if test="tel != null">tel,</if>
            <if test="inCharge != null">in_charge,</if>
            <if test="tripId != null">trip_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="enterpriseName != null and enterpriseName != ''">#{enterpriseName},</if>
            <if test="tel != null">#{tel},</if>
            <if test="inCharge != null">#{inCharge},</if>
            <if test="tripId != null">#{tripId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateCpsMeetingEnterprise" parameterType="com.ruoyi.system.domain.CpsMeetingEnterprise">
        update cps_meeting_enterprise
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseName != null and enterpriseName != ''">enterprise_name = #{enterpriseName},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="inCharge != null">in_charge = #{inCharge},</if>
            <if test="tripId != null">trip_id = #{tripId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCpsMeetingEnterpriseById" parameterType="Long">
        delete
        from cps_meeting_enterprise
        where id = #{id}
    </delete>

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