TBoardStatisticMapper.xml 11.6 KB
<?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="cn.chnmuseum.party.mapper.TBoardStatisticMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.chnmuseum.party.model.TBoardStatistic">
        <id column="id" property="id" />
        <result column="board_id" property="boardId" />
        <result column="board_name" property="boardName" />
        <result column="organ_id" property="organId" />
        <result column="area_id" property="areaId" />
        <result column="play_number" property="playNumber" />
        <result column="play_date" property="playDate" />
    </resultMap>

    <!-- 播放排行结果 -->
    <resultMap id="rankMap" type="cn.chnmuseum.party.model.TBoardPlayRank">
        <id column="id" property="id"/>
        <result column="board_id" property="boardId"/>
        <result column="board_name" property="boardName"/>
        <result column="play_number" property="playNumber"/>
        <result column="play_date" property="playDate"/>
    </resultMap>

    <resultMap id="trendMap" type="cn.chnmuseum.party.model.TBoardPlayTrend">
        <result column="play_number" property="playNumber"/>
        <result column="play_date" property="playDate"/>
    </resultMap>

    <!-- 地区看板统计 -->
    <resultMap id="districtMap" type="cn.chnmuseum.party.model.TDistrictBoardStatistic">
        <result column="area_name" property="areaName"/>
        <result column="play_number" property="playNumber"/>
        <result column="board_cnt" property="boardCnt"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, board_id, board_name, organ_id, area_id, play_number, play_date
    </sql>

    <!-- 展板播放量统计 -->
    <select id="getBoardRankPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayRank" resultMap="rankMap">
        SELECT s.board_id,s.board_name,sum(s.play_number) play_number
        from t_board_statistic s
        left join t_organ o on o.id = s.organ_id
        LEFT JOIN exhibition_board b ON b.id=s.board_id
        <where>
            b.is_deleted=0
            <if test="rank.playDate != null">
                and s.play_date like concat( #{rank.playDate}, '%')
            </if>
            <if test="rank.organId != null">
                and s.organ_id = #{rank.organId}
            </if>
            <if test="rank.organCode != null">
                and o.code LIKE concat(#{rank.organCode}, '%')
            </if>
        </where>
        GROUP BY s.board_id,s.board_name
        ORDER BY sum(s.play_number) desc
    </select>

    <!-- 播放趋势统计 -->
    <select id="getBoardTrendPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayTrend" resultMap="trendMap">
        <if test="trend.playDate != null and trend.playDate.length() == 4">
            SELECT sum(s.play_number) play_number,left(s.play_date,6) play_date
            from t_board_statistic s
            left join t_organ o on o.id = s.organ_id
            where left(s.play_date,4) = ${trend.playDate}
            <if test="trend.organCode != null">
                and o.code LIKE concat(#{trend.organCode}, '%')
            </if>
            GROUP BY left(s.play_date,6)
            ORDER BY left(s.play_date,6)
        </if>
        <if test="trend.playDate != null and trend.playDate.length() == 6">
            SELECT sum(s.play_number) play_number,s.play_date
            from t_board_statistic s
            left join t_organ o on o.id = s.organ_id
            where left(s.play_date,6) = ${trend.playDate}
            <if test="trend.organCode != null">
                and o.code LIKE concat(#{trend.organCode}, '%')
            </if>
            GROUP BY s.play_date
            ORDER BY s.play_date
        </if>
        <if test="trend.playDate != null and trend.playDate.length() == 8">
            SELECT sum(s.play_number) play_number,s.play_date
            from t_board_statistic s
            left join t_organ o on o.id = s.organ_id
            where s.play_date = ${trend.playDate}
            <if test="trend.organCode != null">
                and o.code LIKE concat(#{trend.organCode}, '%')
            </if>
            GROUP BY s.play_date
            ORDER BY s.play_date
        </if>
    </select>


    <select id="getBoardPageList" parameterType="cn.chnmuseum.party.model.TBoardPlayTrend" resultMap="trendMap">
            SELECT sum(s.play_number) play_number,left(s.play_date,6) play_date
            from t_board_statistic s
            left join t_organ o on o.id = s.organ_id
            where
            left(s.play_date,6) between ${trend.beginDate} and ${trend.endDate}
            <if test="trend.organCode != null">
                and o.code LIKE concat(#{trend.organCode}, '%')
            </if>
            GROUP BY left(s.play_date,6)
            ORDER BY left(s.play_date,6)
    </select>

    <!-- 地区展板播放统计 -->
    <select id="getBoardDistrictPageList" resultMap="districtMap">
        SELECT a.name area_name,sum(s.play_number) play_number,count(s.board_id) board_cnt from t_board_statistic s
        left join t_area a on s.area_id = a.id
        left join t_organ o on o.id = s.organ_id
        <where>
            <if test="district.playDate != null and district.playDate.length() == 4">
                and left(s.play_date,4) = ${district.playDate}
            </if>
            <if test="district.playDate != null and district.playDate.length() == 6">
                and left(s.play_date,6) = ${district.playDate}
            </if>
            <if test="district.playDate != null and district.playDate.length() == 8">
                and s.play_date = ${district.playDate}
            </if>
            <if test="district.organCode != null">
                and o.code LIKE concat(#{district.organCode}, '%')
            </if>
        </where>
        GROUP BY s.area_id
        order by sum(s.play_number) desc,count(board_id) desc
    </select>


    <!-- 获取展板播放总量 -->
    <select id="getBoardPlayTotal" parameterType="cn.chnmuseum.party.model.TBoardSurvey" resultType="java.lang.Integer">
        SELECT sum(s.play_number) play_number
        from t_board_statistic s
        left join t_organ o on o.id = s.organ_id
        <where>
            <if test="statisticDate != null and statisticDate.length() == 4">
                and left(s.play_date,4) = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 6">
                and left(s.play_date,6) = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 8">
                and s.play_date = ${statisticDate}
            </if>
            <if test="areaId != null">
                and s.area_id like concat(#{areaId}, '%')
            </if>
            <if test="organId != null">
                and s.organ_id = #{organId}
            </if>
            <if test="organCode != null">
                and o.code LIKE concat(#{organCode}, '%')
            </if>
        </where>
    </select>

    <!-- 获取展板总量 -->
    <select id="getBoardTotal" resultType="java.lang.Integer">
        SELECT count( a.board_id )
            FROM
                ( SELECT s.board_id
                    FROM t_board_statistic s
                    left join t_organ o on o.id = s.organ_id
                    <where>
                        <if test="statisticDate != null and statisticDate.length() == 4">
                            left(s.play_date,4) = ${statisticDate}
                        </if>
                        <if test="statisticDate != null and statisticDate.length() == 6">
                            left(s.play_date,6) = ${statisticDate}
                        </if>
                        <if test="statisticDate != null and statisticDate.length() == 8">
                            s.play_date = ${statisticDate}
                        </if>
                        <if test="organCode != null">
                            and o.code LIKE concat(#{organCode}, '%')
                        </if>
                    </where>
                    GROUP BY s.board_id ) a
    </select>

    <!-- 获取播放展板的机构总量 -->
    <select id="getOrganTotal" resultType="java.lang.Integer">
        SELECT
	count( a.organ_id )
    FROM
	    ( SELECT s.organ_id FROM t_board_statistic s
        left join t_organ o on o.id = s.organ_id
            <where>
                <if test="statisticDate != null and statisticDate.length() == 4">
                    left(s.play_date,4) = ${statisticDate}
                </if>
                <if test="statisticDate != null and statisticDate.length() == 6">
                    left(s.play_date,6) = ${statisticDate}
                </if>
                <if test="statisticDate != null and statisticDate.length() == 8">
                    s.play_date = ${statisticDate}
                </if>
                <if test="organCode != null">
                    and o.code LIKE concat(#{organCode}, '%')
                </if>
            </where>
	        GROUP BY s.organ_id ) a
    </select>
    <!-- 获取互动总量 -->
    <select id="getInteractionTotal" resultType="java.lang.Integer">
        select count(i.id) from t_interaction i
        left join t_organ o on o.id = i.organ_id
        <where>
            <if test="statisticDate != null and statisticDate.length() == 4">
                DATE_FORMAT(i.create_time,'%Y') = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 6">
                DATE_FORMAT(i.create_time,'%Y%m') = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 8">
                DATE_FORMAT(i.create_time,'%Y%m%d') = ${statisticDate}
            </if>
            <if test="organCode != null">
                and o.code LIKE concat(#{organCode}, '%')
            </if>
        </where>
    </select>
    <!-- 互动频次统计 -->
    <select id="getInteractionFrequency" resultType="java.util.HashMap">
        <if test="frequencyDate != null and frequencyDate.length() == 4">
            SELECT o.name organName,count(i.organ_id) frequencyCnt
            from t_interaction i
            left join t_organ o on i.organ_id = o.id
            <where>
                DATE_FORMAT(i.create_time,'%Y') = ${frequencyDate}
                <if test="orgCode != null">
                    and o.code LIKE concat(#{orgCode}, '%')
                </if>
            </where>
            group by i.organ_id
            order by count(i.organ_id) desc
        </if>
        <if test="frequencyDate != null and frequencyDate.length() == 6">
            SELECT o.name organName,count(i.organ_id) frequencyCnt
            from t_interaction i
            left join t_organ o on i.organ_id = o.id
            <where>
                DATE_FORMAT(i.create_time,'%Y%m') = ${frequencyDate}
                <if test="orgCode != null">
                    and o.code LIKE concat(#{orgCode}, '%')
                </if>
            </where>
            group by i.organ_id
            order by count(i.organ_id) desc
        </if>
        <if test="frequencyDate != null and frequencyDate.length() == 8">
            SELECT o.name organName,count(i.organ_id) frequencyCnt
            from t_interaction i
            left join t_organ o on i.organ_id = o.id
            <where>
                DATE_FORMAT(i.create_time,'%Y%m%d') = ${frequencyDate}
                <if test="orgCode != null">
                    and o.code LIKE concat(#{orgCode}, '%')
                </if>
            </where>
            group by i.organ_id
            order by count(i.organ_id) desc
        </if>

    </select>


</mapper>