Prechádzať zdrojové kódy

作者:张哲
时间:2023/04/11
类型:优化
描述:里程碑(3) 专辑列表优化、统计分析年查询月份赋值

zizg 1 rok pred
rodič
commit
456c60ae59

+ 1 - 1
src/main/java/com/redxun/knowledge/analysis/mapper/AnalysisSynthesizeMapper.java

@@ -52,5 +52,5 @@ public interface AnalysisSynthesizeMapper {
      * @param module
      * @return
      */
-    List<CreateUserViewLabel> totalUserVisits(@Param("firstDay") String firstDay, @Param("lastDay") String lastDay,@Param("module") String module);
+    List<CreateUserViewLabel> totalUserVisits(@Param("firstDay") String firstDay, @Param("lastDay") String lastDay,@Param("module") String module,@Param("type") String type);
 }

+ 7 - 4
src/main/java/com/redxun/knowledge/analysis/service/AnalysisSynthesizeServiceImpl.java

@@ -175,15 +175,18 @@ public class AnalysisSynthesizeServiceImpl {
         Calendar calendar = Calendar.getInstance();
         int year = calendar.get(Calendar.YEAR);
         if (("total").equals(type)) {
-            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(null, null, module);
+            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(null, null, module,"total");
         } else if ("year".equals(type)) {
-            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(DateUtils.format(DateUtils.getFirstOfYear(year)),
-                    DateUtils.format(DateUtils.getLastOfYear(year)), module);
+            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("-"));
+            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(firstYear,lastYear, module,"year");
         } else if ("month".equals(type)) {
             int month = calendar.get(Calendar.MONTH);
             String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
             String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
-            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(firstOfMonth, lastOfMonth, module);
+            createUserViewLabel = analysisSynthesizeMapper.totalUserVisits(firstOfMonth, lastOfMonth, module,"month");
         }
         int sum = createUserViewLabel.stream().mapToInt(e -> e.getPv() + e.getUv()).sum();
         createUserView.setTotal(sum);

+ 66 - 19
src/main/resources/mapper/knowledge/album/AlbumInfoMapper.xml

@@ -51,26 +51,73 @@
     </select>
 
     <select id="findAllAlbumInfo" resultType="com.redxun.knowledge.album.entity.dao.AlbumInfo" parameterType="java.util.Map">
-        select ai.*,s2.FULLNAME_ from (
-        select * from (
-        select t1.*,nvl(t2.yelpCount,0) yelpTotal from (
-        select av.ALBUM_ID,nvl(sum(count(*)) over (partition by VERSION_ID),0) knowledgeTotal,av.STATE versionState
+        select pk_id,
+        category_id,
+        name,
+        cover,
+        owner_company_id,
+        owner_department_id,
+        owner_id,
+        state,
+        views,
+        is_del,
+        company_id_,
+        create_dep_id_,
+        tenant_id_,
+        create_by_,
+        create_time_,
+        update_by_,
+        update_time_,
+        nvl(knowledgetotal,0) knowledgeTotal,
+        nvl(yelptotal,0) yelpTotal,
+        fullname_,
+        versionState
+        from (
+        select ai.*, nvl(t2.yelpCount, 0) yelpTotal, s2.FULLNAME_, av.versionState versionState
+        from (
+        select *
+        from (
+        select t1.*
+        --, nvl(t2.yelpCount, 0) yelpTotal
+        from (
+        select av.ALBUM_ID,
+        nvl(sum(nvl(count(*), 0)) over (partition by VERSION_ID), 0) knowledgeTotal,
+        av.STATE                                                     versionStates
         from (
         select *
-        from (select b.*, (ROW_NUMBER() OVER (PARTITION BY b.ALBUM_ID ORDER BY b.CREATE_TIME_ desc)) rn
-        from KM_ALBUM_VERSION b where IS_DEL = 0)
+        from (select b.*,
+        (ROW_NUMBER()
+        OVER (PARTITION BY b.ALBUM_ID ORDER BY b.CREATE_TIME_ desc)) rn
+        from KM_ALBUM_VERSION b
+        where IS_DEL = 0)
         where rn = 1) av
-        left join KM_ALBUM_CATALOGUE catalogue on av.PK_ID = catalogue.VERSION_ID and catalogue.IS_DEL = 0
-        join KM_ALBUM_CATALOGUE_KNOWLEDGE knowledge ON catalogue.PK_ID = knowledge.CATALOGUE_ID and knowledge.IS_DEL = 0
-        group by VERSION_ID,av.ALBUM_ID,av.STATE) t1 left join (select ALBUM_ID, count(*) yelpCount
-        from KM_ALBUM_YELP
-        where IS_DEL = 0 and STATE = 1
-        group by ALBUM_ID) t2 on t1.ALBUM_ID = t2.ALBUM_ID) result1 join KM_ALBUM_INFO ai on result1.ALBUM_ID = ai.PK_ID where ai.IS_DEL = 0)
-        ai JOIN LEARNING_USER_DEV.OS_USER s2
+        left join KM_ALBUM_CATALOGUE catalogue
+        on av.PK_ID = catalogue.VERSION_ID and catalogue.IS_DEL = 0
+        join KM_ALBUM_CATALOGUE_KNOWLEDGE knowledge
+        ON catalogue.PK_ID = knowledge.CATALOGUE_ID and knowledge.IS_DEL = 0
+        group by VERSION_ID, av.ALBUM_ID, av.STATE) t1) result1
+        right join KM_ALBUM_INFO ai on result1.ALBUM_ID = ai.PK_ID
+        where ai.IS_DEL = 0) ai
+        JOIN LEARNING_USER_DEV.OS_USER s2
         ON OWNER_ID = USER_ID_
+        left join (select ALBUM_ID, count(*) yelpCount
+        from KM_ALBUM_YELP
+        where IS_DEL = 0
+        and STATE = 1
+        group by ALBUM_ID) t2 on ai.PK_ID = t2.ALBUM_ID
+        join (select av.ALBUM_ID,
+        av.STATE versionState
+        from (
+        select *
+        from (select b.*,
+        (ROW_NUMBER()
+        OVER (PARTITION BY b.ALBUM_ID ORDER BY b.CREATE_TIME_ desc)) rn
+        from KM_ALBUM_VERSION b
+        where IS_DEL = 0)
+        where rn = 1) av) av on av.ALBUM_ID = ai.PK_ID)
         <where>
             <if test="@rx.Ognl@isNotEmpty(params.name)">
-                instr(ai.NAME,#{params.name}) > 0
+                instr(name,#{params.name}) > 0
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.categoryId)">
                 and CATEGORY_ID IN (
@@ -82,20 +129,20 @@
                 and instr(FULLNAME_,#{params.ownerName}) > 0
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.state) and params.state == 0">
-                and ai.state = #{params.state}
+                and state = #{params.state}
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.state) and params.state != 0">
-                and ai.versionState = #{params.state}
+                and versionState = #{params.state} and state = 1
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.createTimeStart)">
-                and TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &gt;= #{params.createTimeStart}
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{params.createTimeStart}
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.createTimeEnd)">
-                and TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &lt;= #{params.createTimeEnd}
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{params.createTimeEnd}
             </if>
         </where>
         <if test="@rx.Ognl@isEmpty(order)">
-            ORDER BY ai.STATE DESC, ai.CREATE_TIME_ DESC
+            ORDER BY STATE DESC, CREATE_TIME_ DESC
         </if>
         <if test="@rx.Ognl@isNotEmpty(order)">
             ORDER BY ${order}

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

@@ -10,6 +10,7 @@
                 TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
             </if>
+            and module != '其他'
         </where>
         group by MODULE
     </select>
@@ -125,11 +126,15 @@
                 createTime &gt;= #{firstDay}
                 and createTime &lt;= #{lastDay}
             </if>
+            and module != '其他'
         </where>
         group by MODULE
     </select>
 
     <select id="totalUserVisits" resultType="com.redxun.knowledge.analysis.entity.vo.CreateUserViewLabel">
+        <if test="type != null and type == 'year'">
+            select t2.name,nvl(pv,0) pv,nvl(uv,0) uv from (
+        </if>
         select
         <if test="firstDay == null and lastDay == null">
             concat(concat(substr(to_char(CREATE_TIME_,'yyyy-mm'),1,instr(to_char(CREATE_TIME_,'yyyy-mm'),'-',-1) -
@@ -150,7 +155,11 @@
             <if test="module != null">
                 MODULE = #{module}
             </if>
-            <if test="firstDay != null and lastDay != null">
+            <if test="type != null and type == 'year'">
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm') &gt;= #{firstDay}
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm') &lt;= #{lastDay}
+            </if>
+            <if test="firstDay != null and lastDay != null and type != 'year'">
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
             </if>
@@ -161,7 +170,11 @@
             <if test="module != null">
                 MODULE = #{module}
             </if>
-            <if test="firstDay != null and lastDay != null">
+            <if test="type != null and type == 'year'">
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm') &gt;= #{firstDay}
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm') &lt;= #{lastDay}
+            </if>
+            <if test="firstDay != null and lastDay != null and type != 'year'">
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
             </if>
@@ -174,5 +187,19 @@
             group by to_char(CREATE_TIME_,'mm')
             order by to_char(CREATE_TIME_,'mm')
         </if>
+        <if test="type != null and type == 'year'">
+            ) t1
+            right join
+            (select concat(ltrim(to_char(monthlist, 'mm'), '0'), '月') name,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)) t2
+            on t1.name = t2.name
+            order by t2.monthlist
+        </if>
     </select>
 </mapper>