Переглянути джерело

作者:张哲
时间:2023/08/28
类型:开发
描述:问题7:新增员工行为tab

zizg 1 рік тому
батько
коміт
992653b194

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

@@ -11,6 +11,7 @@ import com.redxun.knowledge.analysis.entity.dto.PersonVisitDto;
 import com.redxun.knowledge.analysis.entity.page.MyJsonResult;
 import com.redxun.knowledge.analysis.entity.vo.*;
 import com.redxun.knowledge.analysis.service.*;
+import com.redxun.knowledge.utils.DateUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -337,20 +338,23 @@ public class AnalysisCommonController {
 
     }
 
-    @ApiOperation("展示当前登陆员工的知识上传数和专辑评论数")
-    @GetMapping("knowledgeSumAndYelpSumByLogin")
-    public JsonResult knowledgeSumAndYelpSumByLogin(){
+    @ApiOperation("展示员工的知识上传数和专辑评论数")
+    @GetMapping("knowledgeSumAndYelpSumByUserId")
+    public JsonResult knowledgeSumAndYelpSumByUserId(@RequestParam(value = "beginTime",required = false) String beginTime,
+                                                    @RequestParam(value = "endTime",required = false) String endTime,
+                                                    @RequestParam(value = "userId",required = false) String userId){
         JsonResult jsonResult = JsonResult.getSuccessResult("");
-        Map<String,Object> result = analysisCommonService.knowledgeSumAndYelpSumByLogin();
+        Map<String,Object> result = analysisCommonService.knowledgeSumAndYelpSumByLogin(beginTime,endTime,userId);
         return jsonResult.setData(result);
     }
 
     @ApiOperation("展示员工知识上传数和专辑评论数列表")
-    @PostMapping("knowledgeSumAndYelpSumList")
-    public JsonPageResult knowledgeSumAndYelpSumList(@RequestBody QueryData queryData){
-        JsonPageResult jsonResult = JsonPageResult.getSuccess("");
-        IPage result = analysisCommonService.knowledgeSumAndYelpSumList(queryData);
-        jsonResult.setPageData(result);
-        return jsonResult;
+    @GetMapping("knowledgeSumAndYelpSumList")
+    public JsonResult knowledgeSumAndYelpSumList(@RequestParam(value = "beginTime",required = false) String beginTime,
+                                                     @RequestParam(value = "endTime",required = false) String endTime,
+                                                     @RequestParam(value = "type") Integer type){
+        JsonResult jsonResult = JsonResult.getSuccessResult("");
+        List<KnowledgeSumAndYelpSumListVo> result = analysisCommonService.knowledgeSumAndYelpSumList(type,beginTime,endTime);
+        return jsonResult.setData(result);
     }
 }

+ 4 - 2
src/main/java/com/redxun/knowledge/analysis/entity/vo/KnowledgeSumAndYelpSumListVo.java

@@ -20,7 +20,9 @@ public class KnowledgeSumAndYelpSumListVo implements Serializable {
 
     private String userName;
 
-    private Integer knowledgeSum;
+    private Integer total;
 
-    private Integer yelpSum;
+    private String deptId;
+
+    private String deptName;
 }

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

@@ -1,8 +1,8 @@
 package com.redxun.knowledge.analysis.mapper;
 
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.redxun.knowledge.analysis.entity.dao.KnowledgeDao;
+import com.redxun.knowledge.analysis.entity.vo.KnowledgeSumAndYelpSumListVo;
 import com.redxun.knowledge.analysis.entity.vo.SearchParticipleWordCloudVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -115,19 +115,19 @@ public interface AnalysisCommonMapper {
      * @param userId
      * @return
      */
-    Integer knowledgeSum(@Param("userId") String userId);
+    Integer knowledgeSum(@Param("userId") String userId,@Param("beginTime") String beginTime,@Param("endTime") String endTime);
 
     /**
      * 当前用户专辑评论量
      * @param userId
      * @return
      */
-    Integer yelpSum(@Param("userId") String userId);
+    Integer yelpSum(@Param("userId") String userId,@Param("beginTime") String beginTime,@Param("endTime") String endTime);
 
     /**
      * 展示员工知识上传数和专辑评论数列表
-     * @param sort
      * @return
      */
-    IPage knowledgeSumAndYelpSumList(IPage page, @Param("sort") String sort);
+    List<KnowledgeSumAndYelpSumListVo> knowledgeSumAndYelpSumList(@Param("beginTime") String beginTime, @Param("endTime") String endTime,
+                                                                  @Param("pageNo") Integer pageNo, @Param("pageSize")Integer pageSize);
 }

+ 67 - 18
src/main/java/com/redxun/knowledge/analysis/service/AnalysisCommonServiceImpl.java

@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -426,13 +427,42 @@ public class AnalysisCommonServiceImpl {
      * 员工的知识上传数和专辑评论数
      * @return
      */
-    public Map<String, Object> knowledgeSumAndYelpSumByLogin() {
-        Map<String, Object> map = new HashMap<>();
-        String userId = userService.queryLoginUser();
-        //知识上传量
-        Integer knowledgeSum = analysisCommonMapper.knowledgeSum(userId);
-        //专辑点评量
-        Integer yelpSum = analysisCommonMapper.yelpSum(userId);
+    public Map<String, Object> knowledgeSumAndYelpSumByLogin(String beginTime,String endTime,String userId) {
+        Map<String, Object> map = new LinkedHashMap<>();
+        Integer knowledgeSum = 0;
+        Integer yelpSum = 0;
+        if (StringUtils.isEmpty(userId)){
+            userId = userService.queryLoginUser();
+        }
+        //获取当前年
+        Calendar calendar = Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
+        if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)) {
+            knowledgeSum = analysisCommonMapper.knowledgeSum(userId,beginTime,endTime);
+            //专辑点评量
+            yelpSum = analysisCommonMapper.yelpSum(userId,beginTime,endTime);
+        } else {
+            //知识上传量
+            knowledgeSum = analysisCommonMapper.knowledgeSum(userId,DateUtils.format(DateUtils.getFirstOfYear(year)),
+                    DateUtils.format(DateUtils.getLastOfYear(year)));
+            //专辑点评量
+            yelpSum = analysisCommonMapper.yelpSum(userId,DateUtils.format(DateUtils.getFirstOfYear(year)),
+                    DateUtils.format(DateUtils.getLastOfYear(year)));
+        }
+        String deptPath = pvLogMapper.findAllDeptIdByDeptId(userService.queryUser(userId).getDeptId());
+        if (StringUtils.isNotEmpty(deptPath)) {
+            deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
+            String[] split = deptPath.split("\\.");
+            if (split.length > 6) {
+                String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                map.put("organization",first + ">...>" + end);
+            } else {
+                String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                map.put("organization",organization);
+            }
+        }
+        map.put("totalSum",knowledgeSum + yelpSum);
         map.put("knowledgeSum",knowledgeSum);
         map.put("yelpSum",yelpSum);
         return map;
@@ -441,20 +471,39 @@ public class AnalysisCommonServiceImpl {
 
     /**
      * 展示员工知识上传数和专辑评论数列表
-     * @param queryData
+     * @param beginTime
+     * @param endTime
+     * @param type
      * @return
      */
-    public IPage knowledgeSumAndYelpSumList(QueryData queryData) {
-        String sort = null;
-        //获取排序规则
-        if (StringUtils.isNotEmpty( queryData.getSortField())){
-            sort = queryData.getSortField();
-            if (StringUtils.isNotEmpty(sort)) {
-                sort = sort + queryData.getSortOrder();
-            }
+    public List<KnowledgeSumAndYelpSumListVo> knowledgeSumAndYelpSumList(Integer type, String beginTime, String endTime) {
+        List<KnowledgeSumAndYelpSumListVo> result = new ArrayList<>();
+        int pageNo;
+        int pageSize;
+        if (type == 1){
+            //取排行前3数据
+            pageNo = 1;
+            pageSize = 3;
+        } else if (type == 2){
+            //取前15个,跨过3个
+            pageNo = 4;
+            pageSize = 15;
+        } else {
+            throw new RuntimeException("参数不正确");
+        }
+        //获取当前年
+        Calendar calendar = Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
+        if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)) {
+            result = analysisCommonMapper.knowledgeSumAndYelpSumList(beginTime,endTime,pageNo,pageSize);
+        } else {
+            result = analysisCommonMapper.knowledgeSumAndYelpSumList(DateUtils.format(DateUtils.getFirstOfYear(year)),
+                    DateUtils.format(DateUtils.getLastOfYear(year)),pageNo,pageSize);
         }
-        IPage page = new Page(queryData.getPageNo(),queryData.getPageSize());
-        IPage result = analysisCommonMapper.knowledgeSumAndYelpSumList(page,sort);
+        result.forEach(e -> {
+            e.setDeptId(userService.queryUser(e.getUserId()).getDeptId());
+            e.setDeptName(userService.queryUser(e.getUserId()).getDeptName());
+        });
         return result;
     }
 }

+ 14 - 20
src/main/resources/mapper/knowledge/analysis/AnalysisCommonMapper.xml

@@ -134,7 +134,7 @@
         select count(*)
         from KM_KNOWLEDGE
         <where>
-            APPROVAL_STATUS = 5
+            APPROVAL_STATUS = 5 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{beginTime} and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{endTime}
             <if test="userId != null">
                 and CREATE_BY_ = #{userId}
             </if>
@@ -145,7 +145,7 @@
         select count(*)
         from KM_ALBUM_YELP
         <where>
-            APPROVAL_STATE = 5
+            APPROVAL_STATE = 5 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{beginTime} and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{endTime}
             <if test="userId != null">
                 and CREATE_BY_ = #{userId}
             </if>
@@ -153,34 +153,28 @@
     </select>
 
     <select id="knowledgeSumAndYelpSumList" resultType="com.redxun.knowledge.analysis.entity.vo.KnowledgeSumAndYelpSumListVo">
-        select users.USER_ID_ as userId,FULLNAME_ as userName,NVL(info.knowledgeSum, 0) knowledgeSum,NVL(info.yelpSum, 0) yelpSum
+        select userId,userName,total from(
+        select userId,userName,total,ROWNUM rn from(
+        select users.USER_ID_ as userId,FULLNAME_ as userName,(NVL(info.knowledgeSum, 0) + NVL(info.yelpSum, 0)) total
         from
             (select createBy,knowledge.knowledgeSum,yelp.yelpSum
              from (
                    (select count(*) as knowledgeSum, CREATE_BY_ as createBy
                     from KM_KNOWLEDGE
-                    where APPROVAL_STATUS = 5
+                   <where>
+                       APPROVAL_STATUS = 5 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{beginTime} and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{endTime}
+                   </where>
                     group by CREATE_BY_) knowledge
                       full join
                   (select count(*) as yelpSum, CREATE_BY_ as createBy
                    from KM_ALBUM_YELP
-                   where APPROVAL_STATE = 5
+                   <where>
+                       APPROVAL_STATE = 5 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{beginTime} and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{endTime}
+                   </where>
                    group by CREATE_BY_) yelp using (createBy))) info right join LEARNING_USER_DEV.OS_USER users on users.USER_ID_ = info.createBy
-        <if test="sort == null">
-            order by knowledgeSum desc
-        </if>
-        <if test="sort == 'knowledgeSumdesc'">
-            order by knowledgeSum desc
-        </if>
-        <if test="sort == 'knowledgeSumasc'">
-            order by knowledgeSum
-        </if>
-        <if test="sort == 'yelpSumdesc'">
-            order by yelpSum desc
-        </if>
-        <if test="sort == 'yelpSumasc'">
-            order by yelpSum
-        </if>
+        where STATUS_ = 1
+        order by total desc))
+        where rn &gt;= #{pageNo} and rn &lt;= #{pageSize}
     </select>