<?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.dao.ExhibiMapper">

    <resultMap id="resultMap" type="com.cftech.cms.exhibi.model.Exhibi">
        <id column="id" property="id"/>
        <result column="number" property="number"/>
        <result column="exhibi_title" property="exhibi_title"/>
        <result column="exhibi_title_en" property="exhibi_title_en"/>
        <result column="exhibi_number" property="exhibi_number"/>
        <result column="exhibi_number_en" property="exhibi_number_en"/>
        <result column="content_exhibi" property="content_exhibi"/>
        <result column="content_exhibi_en" property="content_exhibi_en"/>
        <result column="exhibi_picture" property="exhibi_picture"/>
        <result column="exhibi_describe" property="exhibi_describe"/>
        <result column="exhibi_describe_en" property="exhibi_describe_en"/>
        <result column="exhibi_type" property="exhibi_type"/>
        <result column="exhibi_type_en" property="exhibi_type_en"/>
        <result column="reading" property="reading"/>
        <result column="fabulous" property="fabulous"/>
        <result column="reviews" property="reviews"/>
        <result column="selects" property="selects"/>
        <result column="releas" property="releas"/>
        <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="review_count" property="reviewCount"/>
        <result column="exhibi_cover" property="exhibi_cover"/>
        <result column="qr_code" property="qr_code"/>
        <result column="show_exhibits" property="show_exhibits" />
        <result column="show_inquiries" property="show_inquiries" />
        <result column="show_sample" property="show_sample" />
    </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,
                                                exhibi_title,
                                                exhibi_title_en,
                                                exhibi_number,
                                                exhibi_number_en,
                                                content_exhibi,
                                                content_exhibi_en,
                                                exhibi_picture,
                                                exhibi_describe,
                                                exhibi_describe_en,
                                                exhibi_type,
                                                exhibi_type_en,
                                                reading,
                                                fabulous,
                                                selects,
                                                reviews,
                                                releas,
                                                accounts_id,
                                                del_flag,
                                                status,
                                                create_time,
                                                update_time,
                                                description,
                                                create_by,
                                                update_by,
                                                exhibi_cover,
                                                qr_code,
                                                show_exhibits,
                                                show_inquiries,
                                                show_sample
                        </sql>

    <insert id="save" parameterType="com.cftech.cms.exhibi.model.Exhibi" useGeneratedKeys="true"
            keyProperty="id">
        insert into wx_mp_exhibi
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{number, jdbcType=VARCHAR},
        #{exhibi_title, jdbcType=VARCHAR},
        #{exhibi_title_en, jdbcType=VARCHAR},
        #{exhibi_number, jdbcType=VARCHAR},
        #{exhibi_number_en, jdbcType=VARCHAR},
        #{content_exhibi, jdbcType=CLOB},
        #{content_exhibi_en, jdbcType=CLOB},
        #{exhibi_picture, jdbcType=VARCHAR},
        #{exhibi_describe, jdbcType=VARCHAR},
        #{exhibi_describe_en, jdbcType=VARCHAR},
        #{exhibi_type, jdbcType=VARCHAR},
        #{exhibi_type_en, jdbcType=VARCHAR},
        #{reading , jdbcType=BIGINT},
        #{fabulous , jdbcType=BIGINT},
        #{selects , jdbcType=BIGINT},
        #{reviews , jdbcType=BIGINT},
        #{releas , jdbcType=VARCHAR},
        #{accountsId, jdbcType=BIGINT},
        #{delFlag, jdbcType=TINYINT},
        #{status, jdbcType=VARCHAR},
        now(),
        now(),
        #{description, jdbcType=VARCHAR},
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT},
        #{exhibi_cover},
        #{qr_code},
        #{show_exhibits},
        #{show_inquiries},
        #{show_sample}
        )
    </insert>


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

    <select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM wx_mp_exhibi
        <include refid="sqlWhere"/>

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>,(select count(1) from wx_review r where r.module_type = 0 and entity_id=e.id) review_count
        FROM wx_mp_exhibi e
        <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.model.Exhibi">
        update wx_mp_exhibi
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="number != null">
                number = #{number, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_title != null">
                exhibi_title = #{exhibi_title, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_title_en != null">
                exhibi_title_en = #{exhibi_title_en, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_number != null">
                exhibi_number = #{exhibi_number, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_number_en != null">
                exhibi_number_en = #{exhibi_number_en, jdbcType=VARCHAR},
            </if>
            <if test="content_exhibi != null">
                content_exhibi = #{content_exhibi, jdbcType=CLOB},
            </if>
            <if test="content_exhibi_en != null">
                content_exhibi_en = #{content_exhibi_en, jdbcType=CLOB},
            </if>
            <if test="exhibi_picture != null">
                exhibi_picture = #{exhibi_picture, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_describe != null">
                exhibi_describe = #{exhibi_describe, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_describe_en != null">
                exhibi_describe_en = #{exhibi_describe_en, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_type != null">
                exhibi_type = #{exhibi_type, jdbcType=VARCHAR},
            </if>
            <if test="exhibi_type_en != null">
                exhibi_type_en = #{exhibi_type_en, 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=" reading != null">
                reading = #{reading , jdbcType=BIGINT},
            </if>
            <if test=" fabulous != null">
                fabulous = #{fabulous , jdbcType=BIGINT},
            </if>
            <if test = "releas != null">
                releas = #{releas , jdbcType=VARCHAR},
            </if>
            <if test="exhibi_cover!=null">
                exhibi_cover = #{exhibi_cover},
            </if>
            <if test="qr_code!=null">
                qr_code = #{qr_code},
            </if>
            <if test="show_exhibits!=null">
                show_exhibits = #{show_exhibits,jdbcType=VARCHAR},
            </if>
            <if test="show_inquiries!=null">
                show_inquiries = #{show_inquiries,jdbcType=VARCHAR},
            </if>
            <if test="show_sample!=null">
                show_sample = #{show_sample,jdbcType=VARCHAR}
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

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



</mapper>