Ver Fonte

作者:张哲
时间:2023/03/27
类型:开发
描述:里程碑(3) 公司统计修改(知识统计)

zizg há 1 ano atrás
pai
commit
ea6da65a2f

+ 11 - 10
src/main/java/com/redxun/knowledge/analysis/controller/AnalysisCommonController.java

@@ -1,7 +1,11 @@
 package com.redxun.knowledge.analysis.controller;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.redxun.common.annotation.ClassDefine;
+import com.redxun.common.base.entity.JsonPageResult;
 import com.redxun.common.base.entity.JsonResult;
+import com.redxun.common.base.entity.QueryData;
+
 import com.redxun.knowledge.analysis.entity.vo.*;
 import com.redxun.knowledge.analysis.service.AnalysisAlbumServiceImpl;
 import com.redxun.knowledge.analysis.service.AnalysisCommonServiceImpl;
@@ -11,10 +15,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -91,12 +92,12 @@ public class AnalysisCommonController {
     }
 
     @ApiOperation("组织创建知识数量")
-    @GetMapping("organizationKnowledges")
-    public JsonResult organizationKnowledges(@RequestParam("type") String type,
-                                             @RequestParam(value = "tops",required = false,defaultValue = "10") Integer tops,
-                                             @RequestParam(value = "sort",required = false) String sort){
-        List<KnowledgeCompanyVo> knowledgeCompanyVoList = analysisCommonService.organizationKnowledges(type, tops, sort);
-        return JsonResult.getSuccessResult(knowledgeCompanyVoList);
+    @PostMapping("organizationKnowledges")
+    public JsonPageResult organizationKnowledges(@RequestBody QueryData queryData){
+        JsonPageResult jsonResult = JsonPageResult.getSuccess("");
+        IPage knowledgeCompanyVoList = analysisCommonService.organizationKnowledges(queryData);
+        jsonResult.setPageData(knowledgeCompanyVoList);
+        return jsonResult;
     }
 
     @ApiOperation("专辑创建总量")

+ 26 - 0
src/main/java/com/redxun/knowledge/analysis/entity/dao/KnowledgeDao.java

@@ -0,0 +1,26 @@
+package com.redxun.knowledge.analysis.entity.dao;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 文件名: KnowledgeDao
+ * 作者: zizg
+ * 时间: 2023/3/27
+ * 描述:
+ * 修改人:
+ * 修改时间:
+ * 修改内容:
+ */
+@Data
+public class KnowledgeDao implements Serializable {
+
+    private String companyId;
+
+    private List<Map<String, BigDecimal>> counts;
+}

+ 5 - 9
src/main/java/com/redxun/knowledge/analysis/mapper/AnalysisCommonMapper.java

@@ -1,6 +1,7 @@
 package com.redxun.knowledge.analysis.mapper;
 
 
+import com.redxun.knowledge.analysis.entity.dao.KnowledgeDao;
 import com.redxun.knowledge.analysis.entity.vo.SearchParticipleWordCloudVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -75,20 +76,15 @@ public interface AnalysisCommonMapper {
      */
     List<Integer> level1KnowledgeHistogram(@Param("categoryId") String categoryId, @Param("firstDay") String firstDay,@Param("lastDay") String lastDay);
 
-    /**
-     * 获取全部创建过知识的公司Id
-     * @return
-     */
-    List<String> selectCompanyId();
+
+
+    String selectCategoryName(String categoryId);
 
     /**
      * 获取各个公司创建的知识数量
-     * @param companyId
      * @param firstDay
      * @param lastDay
      * @return
      */
-    List<Integer> organizationKnowledges(@Param("companyId") String companyId,@Param("firstDay") String firstDay,@Param("lastDay") String lastDay);
-
-    String selectCategoryName(String categoryId);
+    List<KnowledgeDao> organizationKnowledges(@Param("firstDay") String firstDay, @Param("lastDay") String lastDay);
 }

+ 45 - 36
src/main/java/com/redxun/knowledge/analysis/service/AnalysisCommonServiceImpl.java

@@ -1,15 +1,17 @@
 package com.redxun.knowledge.analysis.service;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.redxun.common.base.entity.QueryData;
 import com.redxun.common.tool.StringUtils;
 import com.redxun.knowledge.analysis.entity.consts.PlatformConst;
+import com.redxun.knowledge.analysis.entity.dao.KnowledgeDao;
 import com.redxun.knowledge.analysis.entity.vo.*;
 import com.redxun.knowledge.analysis.mapper.AnalysisCommonMapper;
 import com.redxun.knowledge.analysis.mapper.PvLogMapper;
-import com.redxun.knowledge.common.UserService;
-import com.redxun.knowledge.mapper.KnowledgeCategoryMapper;
 import com.redxun.knowledge.utils.DateUtils;
 
+import com.redxun.knowledge.utils.PageListUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -37,12 +39,6 @@ public class AnalysisCommonServiceImpl {
     @Autowired
     private PvLogMapper pvLogMapper;
 
-    @Autowired
-    private KnowledgeCategoryMapper knowledgeCategoryMapper;
-
-    @Autowired
-    private UserService userService;
-
     /**
      * 各模块整体数量统计:知识仓库(知识总数量);知识地图(地图总数量);知识专辑(专辑总数量)
      *
@@ -238,42 +234,48 @@ public class AnalysisCommonServiceImpl {
 
     /**
      * 组织创建知识数量
-     *
-     * @param type
-     * @param tops
-     * @param sort
+     * @param queryData
      * @return
      */
-    public List<KnowledgeCompanyVo> organizationKnowledges(String type, Integer tops, String sort) {
-        //获取全部创建过知识的公司id
-        List<String> knowledgeCompanyIdList = analysisCommonMapper.selectCompanyId();
+    public IPage organizationKnowledges(QueryData queryData) {
         //获取当前年
         Calendar calendar = Calendar.getInstance();
         int year = calendar.get(Calendar.YEAR);
-        List<KnowledgeCompanyVo> result = knowledgeCompanyIdList.parallelStream().map(e -> {
+        List<KnowledgeDao> count = new ArrayList<>();
+        if (("total").equals(queryData.getParams().get("type"))) {
+            count = analysisCommonMapper.organizationKnowledges(null, null);
+        } else if ("year".equals(queryData.getParams().get("type"))) {
+            count = analysisCommonMapper.organizationKnowledges(DateUtils.format(DateUtils.getFirstOfYear(year)),
+                    DateUtils.format(DateUtils.getLastOfYear(year)));
+        } else if ("month".equals(queryData.getParams().get("type"))) {
+            int month = calendar.get(Calendar.MONTH);
+            String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
+            String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
+            count = analysisCommonMapper.organizationKnowledges(firstOfMonth, lastOfMonth);
+        }
+        List<KnowledgeCompanyVo> result = count.parallelStream().map(e -> {
             KnowledgeCompanyVo knowledgeCompanyVo = new KnowledgeCompanyVo();
-            List<Integer> count = new ArrayList<>();
-            if (("total").equals(type)) {
-                count = analysisCommonMapper.organizationKnowledges(e, null, null);
-            } else if ("year".equals(type)) {
-                count = analysisCommonMapper.organizationKnowledges(e, DateUtils.format(DateUtils.getFirstOfYear(year)),
-                        DateUtils.format(DateUtils.getLastOfYear(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);
-                count = analysisCommonMapper.organizationKnowledges(e, firstOfMonth, lastOfMonth);
+            knowledgeCompanyVo.setCompany(e.getCompanyId());
+            e.getCounts().forEach(c -> {
+                if (c.containsKey("type") && c.get("type").intValue() == 1) {
+                    knowledgeCompanyVo.setArchive(c.get("count").intValue());
+                }
+                if (c.containsKey("type") && c.get("type").intValue() == 2) {
+                    knowledgeCompanyVo.setWiki(c.get("count").intValue());
+                }
+            });
+            if (knowledgeCompanyVo.getArchive() == null){
+                knowledgeCompanyVo.setArchive(0);
             }
-            long archive = count.stream().filter(typeKnowledge -> typeKnowledge == 1).count();
-            long wiki = count.stream().filter(typeKnowledge -> typeKnowledge == 2).count();
-            knowledgeCompanyVo.setCompany(userService.findDeptByDeptId(e).getName());
-            knowledgeCompanyVo.setTotal(count.size());
-            knowledgeCompanyVo.setArchive((int) archive);
-            knowledgeCompanyVo.setWiki((int) wiki);
+            if (knowledgeCompanyVo.getWiki() == null){
+                knowledgeCompanyVo.setWiki(0);
+            }
+            knowledgeCompanyVo.setTotal(knowledgeCompanyVo.getArchive() + knowledgeCompanyVo.getWiki());
             return knowledgeCompanyVo;
         }).collect(Collectors.toList());
         //排序
-        if (sort != null){
+        String sort = queryData.getParams().get("sort");
+        if (sort != null) {
             switch (sort) {
                 case "totalDesc":
                     result = result.stream().sorted((t1, t2) -> t2.getTotal().compareTo(t1.getTotal())).collect(Collectors.toList());
@@ -297,8 +299,15 @@ public class AnalysisCommonServiceImpl {
         } else {
             result = result.stream().sorted((t1, t2) -> t2.getTotal().compareTo(t1.getTotal())).collect(Collectors.toList());
         }
+
         //获取top10公司数据
-        List<KnowledgeCompanyVo> resultTop = result.stream().limit(tops).collect(Collectors.toList());
-        return resultTop;
+        String tops = queryData.getParams().get("tops");
+        List<KnowledgeCompanyVo> resultTop = new ArrayList<>();
+        if (StringUtils.isNotEmpty(tops)){
+            resultTop = result.stream().limit(Long.parseLong(tops)).collect(Collectors.toList());
+        } else {
+            resultTop = result.stream().limit(10).collect(Collectors.toList());
+        }
+        return PageListUtils.getPages(queryData.getPageNo(),queryData.getPageSize(),resultTop);
     }
 }

+ 17 - 11
src/main/resources/mapper/knowledge/analysis/AnalysisCommonMapper.xml

@@ -58,23 +58,29 @@
         </where>
     </select>
 
-    <select id="selectCompanyId" resultType="string">
-        select distinct COMPANY_ID_ from KM_KNOWLEDGE
+    <select id="selectCategoryName" resultType="string">
+        select NAME from KM_KNOWLEDGE_CATEGORY where PK_ID = #{pkId}
     </select>
 
-    <select id="organizationKnowledges" resultType="int">
-        select type from KM_KNOWLEDGE
+    <resultMap id="info" type="com.redxun.knowledge.analysis.entity.dao.KnowledgeDao">
+        <result column="name" property="companyId"/>
+        <collection property="counts" ofType="map">
+            <result column="type" property="type"/>
+            <result column="count" property="count"/>
+        </collection>
+    </resultMap>
+    <select id="organizationKnowledges" resultMap="info">
+        select NAME_ as name,count(*) as count,TYPE as type
+        from KM_KNOWLEDGE ai
+                 join LEARNING_USER_DEV.OS_USER users on ai.CREATE_BY_ = users.USER_ID_
+                 join LEARNING_USER_DEV.OS_GROUP groups on users.COMPANY_ID_ = groups.GROUP_ID_
         <where>
-            COMPANY_ID_ = #{companyId}
             <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}
+                TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
+                and TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
             </if>
         </where>
-    </select>
-
-    <select id="selectCategoryName" resultType="string">
-        select NAME from KM_KNOWLEDGE_CATEGORY where PK_ID = #{pkId}
+        group by users.COMPANY_ID_,TYPE,NAME_
     </select>