Browse Source

作者:张哲
时间:2023/04/06
类型:优化
描述:里程碑(3) 搜索访问量分布接口修改

zizg 1 year ago
parent
commit
f7c87f353d

+ 2 - 2
src/main/java/com/redxun/knowledge/analysis/entity/consts/ComanyColumnsConst.java

@@ -21,8 +21,8 @@ public class ComanyColumnsConst {
         list.add(new CompanyColumns("公司名称","company",""));
         list.add(new CompanyColumns("访问总量","total","total"));
         list.add(new CompanyColumns("知识管理平台","zs","zs"));
-        list.add(new CompanyColumns("eip系统","eip","eip"));
-        list.add(new CompanyColumns("dcc系统","dcc","dcc"));
+        list.add(new CompanyColumns("EIP系统","eip","eip"));
+        list.add(new CompanyColumns("DCC系统","dcc","dcc"));
         list.add(new CompanyColumns("工作管理系统","gz","gz"));
         list.add(new CompanyColumns("平展系统","pz","pz"));
         list.add(new CompanyColumns("云盘系统","wp","wp"));

+ 2 - 2
src/main/java/com/redxun/knowledge/analysis/entity/consts/PlatformConst.java

@@ -19,9 +19,9 @@ public class PlatformConst {
         list.add("知识管理平台");
         list.add("平展系统");
         list.add("工作管理系统");
-        list.add("eip系统");
+        list.add("EIP系统");
         list.add("云盘系统");
-        list.add("dcc系统");
+        list.add("DCC系统");
         return list;
     }
 }

+ 10 - 19
src/main/java/com/redxun/knowledge/analysis/mapper/PvLogMapper.java

@@ -4,9 +4,11 @@ package com.redxun.knowledge.analysis.mapper;
 import com.redxun.common.base.db.BaseDao;
 import com.redxun.knowledge.analysis.entity.dao.PvLog;
 import com.redxun.knowledge.analysis.entity.vo.AlbumDetailVisitsVo;
+import com.redxun.knowledge.analysis.entity.vo.SearchVisitHistogramVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 
@@ -16,25 +18,6 @@ import java.util.List;
 @Mapper
 public interface PvLogMapper extends BaseDao<PvLog> {
 
-    /**
-     * 统计当前年的搜索访问总量
-     * @param firstYearDate
-     * @param lastYearDate
-     * @return
-     */
-    Integer selectYearTotal(@Param("firstYearDate") String firstYearDate, @Param("lastYearDate") String lastYearDate);
-
-    /**
-     * 根据月份查询各个业务系统访问量
-     * @param firstOfMonth
-     * @param lastOfMonth
-     * @param platform
-     * @return
-     */
-    Integer selectSearchVisitHistogramByMonth(@Param("firstOfMonth") String firstOfMonth,
-                                              @Param("lastOfMonth") String lastOfMonth,
-                                              @Param("platform") String platform);
-
     /**
      * 专辑详情Top访问量(pv)统计
      * @param firstDay
@@ -42,4 +25,12 @@ public interface PvLogMapper extends BaseDao<PvLog> {
      * @return
      */
     List<AlbumDetailVisitsVo> albumDetailVisits(@Param("firstDay") String firstDay,@Param("lastDay") String lastDay);
+
+    /**
+     * 获取搜索服务访问量分布柱状图数据,查看一次详情算一次PV
+     * @param firstOfYear
+     * @param lastOfYear
+     * @return
+     */
+    SearchVisitHistogramVo searchVisitHistogram(@Param("firstDay")String firstOfYear,@Param("lastDay") String lastOfYear);
 }

+ 6 - 9
src/main/java/com/redxun/knowledge/analysis/service/AnalysisCommonServiceImpl.java

@@ -90,16 +90,13 @@ public class AnalysisCommonServiceImpl {
      * @return
      */
     public SearchVisitHistogramVo searchVisitHistogram() {
-        SearchVisitHistogramVo searchVisitHistogramVo = new SearchVisitHistogramVo();
-        Calendar calendar = Calendar.getInstance();
-        int year = calendar.get(Calendar.YEAR);
         //统计当前年的搜索访问总量
-        int yearTotal = pvLogMapper.selectYearTotal(DateUtils.format(DateUtils.getFirstOfYear(year)),
-                DateUtils.format(DateUtils.getLastOfYear(year)));
-        //统计每月各个系统的搜索访问量
-        List<LablesVo> lablesVoList = new ArrayList<>();
-        searchVisitHistogramVo.setTotal(yearTotal);
-        searchVisitHistogramVo.setLables(lablesVoList);
+        String firstYear = DateUtils.format(DateUtils.getFirstOfYear(1));
+        String lastYear = DateUtils.format(DateUtils.getLastOfYear(1));
+        firstYear = firstYear.substring(0,firstYear.lastIndexOf("-"));
+        lastYear = lastYear.substring(0,lastYear.lastIndexOf("-"));
+        SearchVisitHistogramVo searchVisitHistogramVo = pvLogMapper.
+                searchVisitHistogram(firstYear,lastYear);
         return searchVisitHistogramVo;
     }
 

+ 2 - 2
src/main/resources/mapper/knowledge/analysis/AnalysisSearchMapper.xml

@@ -56,7 +56,7 @@
         (select COMPANY_ID as companyId, count(*) eip
         from KM_PV_LOG
         <where>
-            PLATFORM = 'eip系统'
+            PLATFORM = 'EIP系统'
             <if test="firstDay != null and lastDay != null">
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
@@ -92,7 +92,7 @@
         (select COMPANY_ID as companyId, count(*) dcc
         from KM_PV_LOG
         <where>
-            PLATFORM = 'dcc系统'
+            PLATFORM = 'DCC系统'
             <if test="firstDay != null and lastDay != null">
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}

+ 50 - 15
src/main/resources/mapper/knowledge/analysis/PvLogMapper.xml

@@ -50,23 +50,58 @@
                 #{updateTime})
     </insert>
 
-    <select id="selectYearTotal" resultType="int">
-        select count(*) from KM_PV_LOG
-        where
-        TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstYearDate}
-        and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastYearDate}
-    </select>
+    <resultMap id="searchVisitHistogram" type="com.redxun.knowledge.analysis.entity.vo.SearchVisitHistogramVo">
+        <result column="total" property="total"/>
+        <collection property="lables" resultMap="lablesVo"/>
+    </resultMap>
 
-    <select id="selectSearchVisitHistogramByMonth" resultType="int">
-        select count(*)
+    <resultMap id="lablesVo" type="com.redxun.knowledge.analysis.entity.vo.LablesVo">
+        <result property="name" column="name"/>
+        <collection property="values" ofType="map">
+            <result column="legend" property="legend"/>
+            <result column="value" property="value"/>
+            <result column="percentage" property="percentage"/>
+        </collection>
+    </resultMap>
+    <select id="searchVisitHistogram" resultMap="searchVisitHistogram">
+        select nvl(value,0) value , s2.name, s2.legend, nvl(percentage,0.00) percentage,sum(value) over () total
+        from (
+        select value, concat(ltrim(to_char(dates, 'mm'), '0'), '月') name, legend, percentage
+        from (
+        select nvl(value, 0) value, to_date(monthlist, 'yyyy-mm') dates, legend, percentage
+        from (
+        select count(*)                         value,
+        round(count(*) / sum(count(*)) over (partition by to_char(CREATE_TIME_, 'yyyy-mm')),
+        2)                         percentage,
+        to_char(CREATE_TIME_, 'yyyy-mm') name,
+        PLATFORM                         legend
         from KM_PV_LOG
-        <where>
-            TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstOfMonth}
-            and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastOfMonth}
-            <if test="platform != null">
-                and PLATFORM = #{platform}
-            </if>
-        </where>
+        where to_char(CREATE_TIME_, 'yyyy-mm') &lt;= #{lastDay}
+        and to_char(CREATE_TIME_, 'yyyy-mm') &gt;= #{firstDay}
+        group by to_char(CREATE_TIME_, 'yyyy-mm'), PLATFORM
+        ) t1
+        right join (SELECT TO_CHAR(ADD_MONTHS(TO_DATE(#{firstDay}, 'yyyy-MM'), ROWNUM - 1),
+        'yyyy-MM') as monthlist
+        FROM DUAL
+        CONNECT BY ROWNUM &lt;=
+        months_between(to_date(#{lastDay}, 'yyyy-MM'),
+        to_date(#{firstDay}, 'yyyy-MM')) + 1) t2
+        on t1.name = t2.monthlist
+        order by dates)) s1
+        right join (
+        select concat(ltrim(to_char(monthlist, 'mm'), '0'), '月') name, legend,monthlist
+        from (
+        SELECT ADD_MONTHS(TO_DATE(#{firstDay}, 'yyyy-MM'), ROWNUM - 1) as monthlist
+        FROM DUAL
+        CONNECT BY ROWNUM &lt;=
+        months_between(to_date(#{lastDay}, 'yyyy-MM'),
+        to_date(#{firstDay}, 'yyyy-MM')) + 1 order by monthlist),
+        (SELECT dic.NAME_  legend,
+        dic.VALUE_ legendValue
+        FROM LEARNING_SYSTEM_DEV.SYS_TREE tree
+        INNER JOIN LEARNING_SYSTEM_DEV.SYS_DIC dic ON tree.TREE_ID_ = dic.TREE_ID_
+        WHERE ALIAS_ = 'KNOWLEDGE_PLATFORM') order by monthlist
+        ) s2 on s1.name = s2.name and s1.legend = s2.legend order by s2.monthlist
     </select>
 
     <select id="albumDetailVisits" resultType="com.redxun.knowledge.analysis.entity.vo.AlbumDetailVisitsVo">