<?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.CooperateMapper">
    
    <resultMap type="Cooperate" id="CooperateResult">
        <result property="id"    column="id"    />
        <result property="uid"    column="uid"    />
        <result property="company"    column="company"    />
        <result property="name"    column="name"    />
        <result property="phone"    column="phone"    />
        <result property="address"    column="address"    />
        <result property="info"    column="info"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectCooperateVo">
        select id, uid, company, name, phone, address, info, status, created_at, updated_at from cooperate
    </sql>

    <select id="selectCooperateList" parameterType="Cooperate" resultMap="CooperateResult">
        <include refid="selectCooperateVo"/>
        <where>  
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="company != null  and company != ''"> and company = #{company}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="info != null  and info != ''"> and info = #{info}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectCooperateById" parameterType="Long" resultMap="CooperateResult">
        <include refid="selectCooperateVo"/>
        where id = #{id}
    </select>

    <insert id="insertCooperate" parameterType="Cooperate" useGeneratedKeys="true" keyProperty="id">
        insert into cooperate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="company != null and company != ''">company,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="info != null and info != ''">info,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="company != null and company != ''">#{company},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="info != null and info != ''">#{info},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateCooperate" parameterType="Cooperate">
        update cooperate
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="company != null and company != ''">company = #{company},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="info != null and info != ''">info = #{info},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCooperateById" parameterType="Long">
        delete from cooperate where id = #{id}
    </delete>

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