<?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.fdage.dao.cust.TbExhibitionMapperCust">
    <select id="findCollectionByExhibition" parameterType="java.lang.Long" resultType="com.fdage.respon.ResponExhibition">
        select b.name, c.name as timeName, d.name as typeName, b.id
        FROM tb_exhibition_collection a LEFT JOIN tb_collection b ON a.collection_id = b.id
        LEFT JOIN tb_collection_time c ON b.time_id = c.id
        LEFT JOIN tb_exhibition_type d on b.type_id = d.id
        where a.exhibition_id = #{id}
    </select>

    <select id="findList" parameterType="com.fdage.request.RequestExhibition" resultType="com.fdage.respon.ResponExhibition">
        select a.id, a.name , b.name as equipmentName, c.name as typeName, a.create_time as createTime, a.state,
          b.id as equipmentId, c.id as typeId, a.description, a.web_url as webUrl
        FROM tb_exhibition a LEFT JOIN tb_equipment b ON a.equipment_id = b.id
        LEFT JOIN tb_exhibition_type c on a.type_id = c.id
        where 1 = 1
        <if test="name != null and name != ''">
            and a.name LIKE CONCAT('%', #{name}, '%')
        </if>
        <if test="state != null">
            and a.state = #{state}
        </if>
    </select>

    <select id="getExhibitionByEquipmentId" parameterType="java.lang.Long" resultType="com.fdage.respon.ResponExhibition">
        select a.id, a.name , b.name as equipmentName, c.name as typeName, a.create_time as createTime, a.state, a.web_url as webUrl
        FROM tb_exhibition a LEFT JOIN tb_equipment b ON a.equipment_id = b.id
        LEFT JOIN tb_exhibition_type c on a.type_id = c.id
        where a.state = 0 and a.equipment_id = #{id}
    </select>

    <update id="updateStateByEquipmentId" parameterType="java.lang.Long">
        update tb_exhibition
        set state = 1
        where equipment_id = #{id,jdbcType=BIGINT}
    </update>

    <select id="typeList" resultType="com.fdage.pojo.TbExhibitionType">
        select id, name
        from tb_exhibition_type
    </select>

    <update id="addOpenNum" parameterType="java.lang.Long">
        update tb_exhibition
        set open_num = open_num + 1
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="exhibitionTotal" resultType="java.lang.Long">
        SELECT COUNT(DISTINCT(collection_id))
        FROM `tb_exhibition_collection`
    </select>

    <select id="findListOrderBy" resultType="com.fdage.respon.ResponExhibition">
        select a.id, a.name , b.name as equipmentName, c.name as typeName, a.create_time as createTime, a.state,
        b.id as equipmentId, c.id as typeId, a.description, a.web_url as webUrl, a.open_num as openNum
        FROM tb_exhibition a LEFT JOIN tb_equipment b ON a.equipment_id = b.id
        LEFT JOIN tb_exhibition_type c on a.type_id = c.id
        ORDER BY a.open_num desc
    </select>
</mapper>