<?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.fs.company.mapper.CompanyUserCardMapper">

    <resultMap type="CompanyUserCard" id="CompanyUserCardResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="urlScheme"    column="url_scheme"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="shortUrl"    column="short_url"    />
        <result property="type"    column="type"    />
        <result property="isVisit"    column="is_visit"    />
        <result property="lookNum"    column="look_num"    />
        <result property="createTime"    column="create_time"    />
        <result property="personNum"    column="person_num"    />
        <result property="ipNum"    column="ip_num"    />
    </resultMap>

    <sql id="selectCompanyUserCardVo">
        select id,title, user_id,company_id, url_scheme, image_url,short_url, type, is_visit, look_num,create_time, person_num, ip_num from company_user_card
    </sql>

    <select id="selectCompanyUserCardList" parameterType="CompanyUserCard" resultMap="CompanyUserCardResult">
        <include refid="selectCompanyUserCardVo"/>
        <where>
            <if test="companyId != null "> and user_id = #{companyId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="urlScheme != null  and urlScheme != ''"> and url_scheme = #{urlScheme}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="shortUrl != null  and shortUrl != ''"> and short_url = #{shortUrl}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="isVisit != null  and isVisit != ''"> and is_visit = #{isVisit}</if>
            <if test="lookNum != null "> and look_num = #{lookNum}</if>
            <if test="createTime != null "> and create_time = #{lookNum}</if>
            <if test="personNum != null "> and person_num = #{personNum}</if>
            <if test="ipNum != null "> and ip_num = #{ipNum}</if>
        </where>
    </select>

    <select id="selectCompanyUserCardById" parameterType="Long" resultMap="CompanyUserCardResult">
        <include refid="selectCompanyUserCardVo"/>
        where id = #{id}
    </select>

    <insert id="insertCompanyUserCard" parameterType="com.fs.company.domain.CompanyUserCard" useGeneratedKeys="true" keyProperty="id">
        insert into company_user_card
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="companyId != null">company_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="urlScheme != null">url_scheme,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="shortUrl != null">short_url,</if>
            <if test="type != null">type,</if>
            <if test="isVisit != null">is_visit,</if>
            <if test="lookNum != null">look_num,</if>
            <if test="createTime != null">create_time,</if>
            <if test="personNum != null">person_num,</if>
            <if test="ipNum != null">ip_num,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="title != null">#{title},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="urlScheme != null">#{urlScheme},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="shortUrl != null">#{shortUrl},</if>
            <if test="type != null">#{type},</if>
            <if test="isVisit != null">#{isVisit},</if>
            <if test="lookNum != null">#{lookNum},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="personNum != null">#{personNum},</if>
            <if test="ipNum != null">#{ipNum},</if>
        </trim>
    </insert>

    <update id="updateCompanyUserCard" parameterType="CompanyUserCard">
        update company_user_card
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">user_id = #{companyId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="urlScheme != null">url_scheme = #{urlScheme},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="shortUrl != null">short_url = #{shortUrl},</if>
            <if test="type != null">type = #{type},</if>
            <if test="isVisit != null">is_visit = #{isVisit},</if>
            <if test="lookNum != null">look_num = #{lookNum},</if>
            <if test="createTime != null">create_time = #{lookNum},</if>
            <if test="personNum != null">person_num = #{personNum},</if>
            <if test="ipNum != null">ip_num = #{ipNum},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyUserCardById" parameterType="Long">
        delete from company_user_card where id = #{id}
    </delete>

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

</mapper>
