<?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.cftech.cms.exhibi_vocation.dao.Exhibi_vocationMapper">

    <resultMap id="resultMap" type="com.cftech.cms.exhibi_vocation.model.Exhibi_vocation">
        <id column="id" property="id"/>
        <result column="number" property="number"/>
        <result column="vocation" property="vocation"/>
        <result column="exhibi_id" property="exhibi_id"/>
        <result column="open_id" property="open_id"/>
        <result column="accounts_id" property="accountsId"/>
        <result column="del_flag" property="delFlag"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <result column="phone" property="phone"/>
        <result column="company" property="company"/>
        <result column="email" property="email"/>
    </resultMap>

    <resultMap id="resultMapDto" type="com.cftech.cms.exhibi_vocation.model.Exhibi_vocationDto">
        <id column="id" property="id"/>
        <result column="vocation" property="vocation" />
        <result column="nickname" property="nickname" />
        <result column="open_id" property="open_id" />
        <result column="create_time" property="create_time" />
        <result column="phone" property="phone"/>
        <result column="company" property="company"/>
        <result column="email" property="email"/>
    </resultMap>

    <sql id="sqlWhere">
        <if test="conds!=null">
            <trim prefix="WHERE" prefixOverrides="AND|OR">
                <foreach collection="conds.conds" index="index" item="cond">
                    ${cond.linkType}
                    <if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
                    <if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
                    <if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
                    <if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
                    <if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
                    <if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
                    <if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND
                        #{cond.endValue}
                    </if>
                    <if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
                    <if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
                    <if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
                    <if test="cond.condType == 'IN'">${cond.param} IN
                        <foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </foreach>
            </trim>
        </if>
    </sql>

    <sql id="sqlColumns">
                                    id,
                                                number,
                                                vocation,
                                                exhibi_id,
                                                open_id,
                                                accounts_id,
                                                del_flag,
                                                status,
                                                create_time,
                                                update_time,
                                                description,
                                                create_by,
                                                update_by,
                                                phone,
                                                company,
                                                email
                        </sql>


    <insert id="save" parameterType="com.cftech.cms.exhibi_vocation.model.Exhibi_vocation" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_mp_exhibi_vocation
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{number, jdbcType=VARCHAR},
        #{vocation, jdbcType=VARCHAR},
        #{exhibi_id, jdbcType=BIGINT},
        #{open_id, jdbcType=VARCHAR},
        #{accountsId, jdbcType=BIGINT},
        #{delFlag, jdbcType=TINYINT},
        #{status, jdbcType=VARCHAR},
        now(),
        now(),
        #{description, jdbcType=VARCHAR},
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT},
        #{phone},
        #{company},
        #{email}
        )
    </insert>

    <select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_mp_exhibi_vocation t
        WHERE t.id=#{id}
    </select>

    <select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT
       COUNT(1)
        FROM
        wx_mp_exhibi_vocation v LEFT JOIN wx_mp_fanss f ON v.open_id = f.openid
        <include refid="sqlWhere"/>

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMapDto">
        SELECT
        v.vocation,
        f.nickname,
        v.open_id,
        v.create_time,
        v.phone,
        v.company,
        v.email
        FROM
        wx_mp_exhibi_vocation v
        LEFT JOIN wx_mp_fanss f ON v.open_id = f.openid
        <include refid="sqlWhere"/>
        <if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
        <if test="limit>0">limit #{offset},#{limit}</if>
    </select>

    <update id="update" parameterType="com.cftech.cms.exhibi_vocation.model.Exhibi_vocation">
        update wx_mp_exhibi_vocation
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="number != null">
                number = #{number, jdbcType=VARCHAR},
            </if>
            <if test="vocation != null">
                vocation = #{vocation, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_id != null">
                exhibi_id = #{exhibi_id, jdbcType=BIGINT},
            </if>
            <if test="open_id != null">
                open_id = #{open_id, jdbcType=VARCHAR},
            </if>
            <if test="accountsId != null">
                accounts_id = #{accountsId, jdbcType=BIGINT},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag, jdbcType=TINYINT},
            </if>
            <if test="status != null">
                status = #{status, jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime, jdbcType=TIMESTAMP},
            </if>
            <if test="description != null">
                description = #{description, jdbcType=VARCHAR},
            </if>
            <if test="createBy != null">
                create_by = #{createBy, jdbcType=BIGINT},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy, jdbcType=BIGINT},
            </if>
            <if test="phone!=null">
                phone = #{phone},
            </if>
            <if test="company!=null">
                company = #{company},
            </if>
            <if test="email!=null">
                email = #{email},
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

    <update id="delete" parameterType="java.lang.Long">
        update wx_mp_exhibi_vocation set del_flag=1 where id=#{id,jdbcType=BIGINT}
    </update>

    <select id="selectByConds" parameterType="java.util.Map" resultType="com.cftech.cms.exhibi_vocation.model.Exhibi_vocation">
        SELECT
        <include refid="sqlColumns"/>
        FROM wx_mp_exhibi_vocation t
        <include refid="sqlWhere"/>
    </select>
</mapper>