소스 검색

feat:群管排行榜统计接口

caoliqin 2 주 전
부모
커밋
dd8ca9bcd3

+ 27 - 7
fs-company-app/src/main/java/com/fs/app/controller/FsUserController.java

@@ -142,11 +142,31 @@ public class FsUserController extends AppBaseController {
         return ResponseResult.ok(fsUserStatisticsVO);
     }
 
-//    @GetMapping("/firstPage/ranking")
-//    @ApiOperation("首页数据-排行榜统计")
-//    public ResponseResult<FsUserStatisticsVO> userRanking(@ApiParam(value = "课程id") @RequestParam(required = false) String courseId,
-//                                                          @ApiParam(value = "视频id") @RequestParam(required = false) String videoId) {
-//        long userId = Long.parseLong(getUserId());
-//        return ResponseResult.ok();
-//    }
+    @GetMapping("/firstPage/userRanking")
+    @ApiOperation("首页数据/详情-销售排行榜统计")
+    public ResponseResult<FsUserRankingVO> userRanking(
+            @ApiParam(value = "开始时间") @RequestParam String startTime,
+            @ApiParam(value = "结束时间") @RequestParam String endTime,
+            @ApiParam(value = "课程id") @RequestParam(required = false) String courseId,
+            @ApiParam(value = "视频id") @RequestParam(required = false) String videoId,
+            @ApiParam(value = "asc-正序,desc-倒序", required = true) @RequestParam String order,
+            @ApiParam(value = "类型,1-按完播率,2-按正确率", required = true) @RequestParam(required = false) Integer type
+            ) {
+        long userId = Long.parseLong(getUserId());
+        return ResponseResult.ok(fsUserService.userRanking(userId, startTime, endTime, courseId, videoId, order, type));
+    }
+
+    @GetMapping("/firstPage/courseRanking")
+    @ApiOperation("首页数据/详情-课程排行榜统计")
+    public ResponseResult<FsUserRankingVO> courseRanking(
+            @ApiParam(value = "开始时间") @RequestParam String startTime,
+            @ApiParam(value = "结束时间") @RequestParam String endTime,
+            @ApiParam(value = "课程id") @RequestParam(required = false) String courseId,
+            @ApiParam(value = "视频id") @RequestParam(required = false) String videoId,
+            @ApiParam(value = "asc-正序,desc-倒序", required = true) @RequestParam String order,
+            @ApiParam(value = "类型,1-按完播率,2-按正确率", required = true) @RequestParam(required = false) Integer type
+    ) {
+        long userId = Long.parseLong(getUserId());
+        return ResponseResult.ok();
+    }
 }

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsUserMapper.java

@@ -248,4 +248,9 @@ public interface FsUserMapper
     Map<String, Object> countUserRedPacket(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("courseId")String courseId, @Param("videoId")String videoId);
 
     Map<String, Long> countCourseDetails(@Param("userId") Long userId, @Param("courseId")String courseId, @Param("videoId")String videoId);
+
+    FsUserRankingVO countUserRanking(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("courseId")String courseId, @Param("videoId")String videoId, @Param("order")String order);
+
+    FsUserRankingVO countCourseRanking(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("courseId")String courseId, @Param("videoId")String videoId, @Param("order")String order);
+
 }

+ 2 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsUserService.java

@@ -159,4 +159,6 @@ public interface IFsUserService
 
     FsUserStatisticsVO userStatisticsDetails(Long userId, String courseId, String videoId);
 
+    FsUserRankingVO userRanking(Long userId, String startTime, String endTime, String courseId, String videoId, String order, Integer type);
+
 }

+ 14 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsUserServiceImpl.java

@@ -540,4 +540,18 @@ public class FsUserServiceImpl implements IFsUserService
         }
         return userStatisticsVO;
     }
+
+    @Override
+    public FsUserRankingVO userRanking(Long userId, String startTime, String endTime, String courseId, String videoId, String order, Integer type) {
+        FsUserRankingVO fsUserRankingVO = null;
+        if(type == 1){
+            //按完播率
+             fsUserRankingVO = fsUserMapper.countUserRanking(userId, startTime, endTime, courseId, videoId, order);
+        }
+        if(type == 2){
+            //按正确率
+             fsUserRankingVO = fsUserMapper.countCourseRanking(userId, startTime, endTime, courseId, videoId, order);
+        }
+        return fsUserRankingVO;
+    }
 }

+ 27 - 0
fs-service-system/src/main/java/com/fs/store/vo/h5/FsUserRankingVO.java

@@ -0,0 +1,27 @@
+package com.fs.store.vo.h5;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
+
+/**
+ * 首页-销售数据排行榜
+ */
+@Data
+@ApiModel
+@Accessors(chain = true)
+public class FsUserRankingVO {
+
+    @ApiModelProperty(value = "销售名称")
+    private int userName;
+
+    @ApiModelProperty(value = "完播率")
+    private BigDecimal completeRate;
+
+    @ApiModelProperty(value = "正确率")
+    private BigDecimal answerRightRate;
+
+}

+ 58 - 26
fs-service-system/src/main/resources/mapper/store/FsUserMapper.xml

@@ -812,32 +812,64 @@
          ) as courseUserNum
     </select>
 
-    <select id="countUserRanking" resultType="Map">
-     SELECT
-                 (
-                     SELECT
-                         count( fcc.user_id )
-                     FROM
-                         fs_user_course_count fcc
-                             LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
-                             LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-                             LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
-                     WHERE
-                         ( company_user.parent_id = 8563  )
-                       AND fcc.complete_watch_count > 0
-                     group by fcc.user_id  )
-                     /
-                 (SELECT
-                      count( fcc.user_id )
-                  FROM
-                      fs_user_course_count fcc
-                          LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
-                          LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-                          LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
-                  WHERE
-                      ( company_user.parent_id = 8563  )
-                  group by fcc.user_id
-                 ) as
+    <select id="countUserRanking" resultType="FsUserRankingVO">
+        SELECT
+        company_user.nick_name as userName,
+        ifnull(
+            ROUND((COUNT( CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count( fcc.user_id ))*100,2),0
+        ) as completeRate
+        FROM
+        fs_user_course_count fcc
+        LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
+        LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
+        LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
+        WHERE
+        company_user.parent_id = #{userId}
+        <if test="startTime != null and startTime !='' ">
+            AND fcc.create_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND fcc.create_time &lt;= #{endTime}
+        </if>
+        <if test="courseId != null and courseId != ''">
+            AND fcc.course_id =  #{courseId}
+        </if>
+        <if test="videoId != null and videoId != ''">
+            AND fcv.video_id = #{videoId}
+        </if>
+        group by fcc.user_id
+        order by completeRate #{order}
+        limit 20
+    </select>
+
+    <select id="countCourseRanking" resultType="FsUserRankingVO">
+        SELECT
+            company_user.nick_name as userName,
+            ifnull(ROUND(
+                           (COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count( fs_user.user_id ))
+                               *100,2),0
+            ) as answerRightRate
+        FROM
+            fs_course_answer_logs
+                LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
+                LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
+        WHERE
+            company_user.parent_id = #{userId}
+            <if test="startTime != null and startTime !='' ">
+                AND fs_course_answer_logs.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fs_course_answer_logs.create_time &lt;= #{endTime}
+            </if>
+            <if test="courseId != null and courseId != ''">
+                AND fs_course_answer_logs.course_id =  #{courseId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fs_course_answer_logs.video_id = #{videoId}
+            </if>
+        group by fs_user.user_id
+        order by answerRightRate #{order}
+        limit 20
     </select>
 
 </mapper>