TBoardStatisticMapper.xml 8.13 KB
Newer Older
yangtianyou's avatar
yangtianyou committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<?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.wisenergy.chnmuseum.party.mapper.TBoardStatisticMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.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.wisenergy.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.wisenergy.chnmuseum.party.model.TBoardPlayTrend">
        <result column="play_number" property="playNumber"/>
        <result column="play_date" property="playDate"/>
    </resultMap>

    <!-- 地区看板统计 -->
    <resultMap id="districtMap" type="cn.wisenergy.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.wisenergy.chnmuseum.party.model.TBoardPlayRank" resultMap="rankMap">
        SELECT board_id,board_name,sum(play_number) play_number from t_board_statistic
        <where>
            <if test="rank.playDate != null">
                and play_date like concat( #{rank.playDate}, '%')
            </if>
            <if test="rank.organId != null">
                and organ_id = #{rank.organId}
            </if>
        </where>
        GROUP BY board_id,board_name
        ORDER BY sum(play_number) desc
    </select>

    <!-- 播放趋势统计 -->
    <select id="getBoardTrendPageList" parameterType="cn.wisenergy.chnmuseum.party.model.TBoardPlayTrend" resultMap="trendMap">
        <if test="trend.playDate != null and trend.playDate.length() == 4">
            SELECT sum(play_number) play_number,left(play_date,6) play_date from t_board_statistic
            where left(play_date,4) = ${trend.playDate}
            GROUP BY left(play_date,6)
            ORDER BY left(play_date,6)
        </if>
        <if test="trend.playDate != null and trend.playDate.length() == 6">
            SELECT sum(play_number) play_number,play_date from t_board_statistic
            where left(play_date,6) = ${trend.playDate}
            GROUP BY play_date
            ORDER BY play_date
        </if>
    </select>

    <!-- 地区展板播放统计 -->
    <select id="getBoardDistrictPageList" resultMap="districtMap">
        SELECT a.name area_name,sum(play_number) play_number,count(board_id) board_cnt from t_board_statistic s
        left join t_area a on s.area_id = a.id
yangtianyou's avatar
yangtianyou committed
77 78 79 80 81 82 83 84 85 86 87
        <where>
            <if test="district.playDate != null and district.playDate.length() == 4">
                left(play_date,4) = ${district.playDate}
            </if>
            <if test="district.playDate != null and district.playDate.length() == 6">
                left(play_date,6) = ${district.playDate}
            </if>
            <if test="district.playDate != null and district.playDate.length() == 6">
                play_date = ${district.playDate}
            </if>
        </where>
yangtianyou's avatar
yangtianyou committed
88 89 90 91 92
        GROUP BY area_id
        order by sum(play_number) desc,count(board_id) desc
    </select>


yangtianyou's avatar
yangtianyou committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    <!-- 获取展板播放总量 -->
    <select id="getBoardPlayTotal" parameterType="cn.wisenergy.chnmuseum.party.model.TBoardSurvey" resultType="java.lang.Integer">
        SELECT sum(play_number) play_number
        from t_board_statistic s
        <where>
            <if test="statisticDate != null and statisticDate.length() == 4">
                and left(play_date,4) = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 6">
                and left(play_date,6) = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 8">
                and play_date = ${statisticDate}
            </if>
            <if test="areaId != null">
                and area_id like concat(#{areaId}, '%')
            </if>
            <if test="organId != null">
                and organ_id = #{organId}
            </if>
        </where>
    </select>

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

    <!-- 获取播放展板的机构总量 -->
    <select id="getOrganTotal" resultType="java.lang.Integer">
        SELECT
	count( a.organ_id )
    FROM
	    ( SELECT organ_id FROM t_board_statistic
            <where>
                <if test="statisticDate != null and statisticDate.length() == 4">
                    left(play_date,4) = ${statisticDate}
                </if>
                <if test="statisticDate != null and statisticDate.length() == 6">
                    left(play_date,6) = ${statisticDate}
                </if>
                <if test="statisticDate != null and statisticDate.length() == 8">
                    play_date = ${statisticDate}
                </if>
            </where>
	        GROUP BY organ_id ) a
    </select>
    <!-- 获取互动总量 -->
    <select id="getInteractionTotal" resultType="java.lang.Integer">
        select count(id) from t_interaction
        <where>
            <if test="statisticDate != null and statisticDate.length() == 4">
                DATE_FORMAT(create_time,'%Y') = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 6">
                DATE_FORMAT(create_time,'%Y%m') = ${statisticDate}
            </if>
            <if test="statisticDate != null and statisticDate.length() == 8">
                DATE_FORMAT(create_time,'%Y%m%d') = ${statisticDate}
            </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}
            </where>
            group by i.organ_id
        </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}
            </where>
            group by i.organ_id
        </if>

    </select>


yangtianyou's avatar
yangtianyou committed
194
</mapper>