<?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.cms.mapper.CompanyContactMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="CompanyContact" id="CompanyContactResult">
        <result property="id" column="id"/>
        <result property="companyId" column="company_id"/>
        <result property="contactPerson" column="contact_person"/>
        <result property="contactPersonPhone" column="contact_person_phone"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectCompanyContactVo">
        select id, company_id, contact_person, contact_person_phone, del_flag, create_by, create_time, update_by, update_time, remark from company_contact
    </sql>

    <select id="getSelectList" resultMap="CompanyContactResult" parameterType="CompanyContact">
        <include refid="selectCompanyContactVo"/>
        <where> del_flag = '0'
            <if test="companyId!=null and companyId!='' ">
                and company_id=#{companyId}
            </if>
            <if test="contactPerson!=null and contactPerson!='' ">
                and contact_person=#{contactPerson}
            </if>
            <if test="contactPersonPhone!=null and contactPersonPhone!='' ">
                and contact_person_phone=#{contactPersonPhone}
            </if>
        </where>
    </select>

    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO company_contact (
        company_id, contact_person, contact_person_phone,
        create_by, create_time, del_flag,remark
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.companyId}, #{item.contactPerson}, #{item.contactPersonPhone},
            #{item.createBy}, #{item.createTime}, #{item.delFlag},#{item.remark}
            )
        </foreach>
    </insert>

    <update id="batchUpdate" parameterType="java.util.List">
        UPDATE company_contact
        SET
        contact_person = CASE
        <foreach collection="list" item="item" separator="">
            WHEN id = #{item.id} THEN #{item.contactPerson}
        </foreach>
        ELSE contact_person
        END,
        contact_person_phone = CASE
        <foreach collection="list" item="item" separator="">
            WHEN id = #{item.id} THEN #{item.contactPersonPhone}
        </foreach>
        ELSE contact_person_phone
        END,
        update_by = CASE
        <foreach collection="list" item="item" separator="">
            WHEN id = #{item.id} THEN #{item.updateBy}
        </foreach>
        ELSE update_by
        END,
        update_time = CASE
        <foreach collection="list" item="item" separator="">
            WHEN id = #{item.id} THEN NOW()
        </foreach>
        ELSE update_time
        END,
        remark = CASE
        <foreach collection="list" item="item" separator="">
            WHEN id = #{item.id} THEN #{item.remark}
        </foreach>
        ELSE remark
        END
        WHERE
        id IN
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item.id}
        </foreach>
    </update>

</mapper>
