Browse Source

Merge branch 'master' of https://git.proginn.com/zaixianjiaoyu/sourcecode

KaysonCui 5 years ago
parent
commit
ba5e1e35fd

+ 7 - 0
server/data/src/main/java/com/qxgmat/data/relation/UserCourseRecordRelationMapper.java

@@ -2,6 +2,7 @@ package com.qxgmat.data.relation;
 
 import com.qxgmat.data.dao.entity.UserReport;
 import com.qxgmat.data.relation.entity.UserCourseStatRelation;
+import com.qxgmat.data.relation.entity.UserRankStatRelation;
 import com.qxgmat.data.relation.entity.UserReportLimitRelation;
 import com.qxgmat.data.relation.entity.UserStudyStatRelation;
 import org.apache.ibatis.annotations.Param;
@@ -18,4 +19,10 @@ public interface UserCourseRecordRelationMapper {
             @Param("startTime") String startTime,
             @Param("endTime") String endTime
     );
+
+    List<UserRankStatRelation> rankByTime(
+            @Param("userId") Integer userId,
+            @Param("startTime") String startTime,
+            @Param("endTime") String endTime
+    );
 }

+ 13 - 0
server/data/src/main/java/com/qxgmat/data/relation/UserReportRelationMapper.java

@@ -1,6 +1,7 @@
 package com.qxgmat.data.relation;
 
 import com.qxgmat.data.dao.entity.UserReport;
+import com.qxgmat.data.relation.entity.UserRankStatRelation;
 import com.qxgmat.data.relation.entity.UserReportLimitRelation;
 import com.qxgmat.data.relation.entity.UserStudyStatRelation;
 import org.apache.ibatis.annotations.Param;
@@ -43,4 +44,16 @@ public interface UserReportRelationMapper {
             @Param("startTime") String startTime,
             @Param("endTime") String endTime
     );
+
+    List<UserRankStatRelation> rankExerciseByTime(
+        @Param("userId") Integer userId,
+        @Param("startTime") String startTime,
+        @Param("endTime") String endTime
+    );
+
+    List<UserRankStatRelation> rankExaminationByTime(
+            @Param("userId") Integer userId,
+            @Param("startTime") String startTime,
+            @Param("endTime") String endTime
+    );
 }

+ 33 - 0
server/data/src/main/java/com/qxgmat/data/relation/entity/UserRankStatRelation.java

@@ -0,0 +1,33 @@
+package com.qxgmat.data.relation.entity;
+
+import javax.persistence.Column;
+
+public class UserRankStatRelation {
+    /**
+     * 用户排行
+     */
+    @Column(name = "`rank`")
+    private Integer rank;
+
+    /**
+     * 总人数
+     */
+    @Column(name = "`total`")
+    private Integer total;
+
+    public Integer getRank() {
+        return rank;
+    }
+
+    public void setRank(Integer rank) {
+        this.rank = rank;
+    }
+
+    public Integer getTotal() {
+        return total;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
+}

+ 32 - 2
server/data/src/main/java/com/qxgmat/data/relation/mapping/UserCourseRecordRelationMapper.xml

@@ -14,6 +14,13 @@
     <id column="module" jdbcType="VERCHAR" property="module" />
     <id column="user_time" jdbcType="INTEGER" property="user_time" />
   </resultMap>
+  <resultMap id="rankMap" type="com.qxgmat.data.relation.entity.UserRankStatRelation">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="rank" jdbcType="INTEGER" property="user_number" />
+    <id column="total" jdbcType="INTEGER" property="user_time" />
+  </resultMap>
   <sql id="Id_Column_List">
     <!--
       WARNING - @mbg.generated
@@ -32,11 +39,34 @@
     where
     ucr.`user_id` = #{userId,jdbcType=VARCHAR}
     <if test="startTime != null">
-      and ur.`update_time` &gt; #{startTime,jdbcType=VARCHAR}
+      and ucr.`create_time` &gt; #{startTime,jdbcType=VARCHAR}
     </if>
     <if test="endTime != null">
-      and ur.`update_time` &lt; #{endTime,jdbcType=VARCHAR}
+      and ucr.`create_time` &lt; #{endTime,jdbcType=VARCHAR}
     </if>
     group cc.`question_type`
   </select>
+
+  <!--
+    用户听课记录排名
+  -->
+  <select id="rankByTime" resultMap="studyMap">
+    select ccc.`rank` as `rank`, 0 as `total`
+    from (
+      select aaa.`user_id` as `user_id`, (@rank:=@rank+1) as `rank`
+      from (
+        select sum(ucr.`user_time`) as `user_time`, ucr.`user_id` as `user_id`
+        from `user_course_record` ucr
+        where
+        1
+        <if test="startTime != null">
+          and ucr.`create_time` &gt; #{startTime,jdbcType=VARCHAR}
+        </if>
+        <if test="endTime != null">
+          and ur.`create_time` &lt; #{endTime,jdbcType=VARCHAR}
+        </if>
+        group by ucr.`user_id`
+      ) as aaa, (select @rank:=0) as bbb  order by `user_time` desc
+    ) as ccc where ccc.`user_id` = #{userId,jdbcType=VARCHAR}
+  </select>
 </mapper>

+ 53 - 0
server/data/src/main/java/com/qxgmat/data/relation/mapping/UserReportRelationMapper.xml

@@ -23,6 +23,13 @@
     <id column="user_time" jdbcType="INTEGER" property="user_time" />
     <id column="user_correct" jdbcType="INTEGER" property="user_correct" />
   </resultMap>
+  <resultMap id="rankMap" type="com.qxgmat.data.relation.entity.UserRankStatRelation">
+    <!--
+      WARNING - @mbg.generated
+    -->
+    <id column="rank" jdbcType="INTEGER" property="user_number" />
+    <id column="total" jdbcType="INTEGER" property="user_time" />
+  </resultMap>
   <sql id="Id_Column_List">
     <!--
       WARNING - @mbg.generated
@@ -132,4 +139,50 @@
     </if>
     group eq.`question_type`
   </select>
+
+  <!--
+    用户练习记录排名
+  -->
+  <select id="rankExerciseByTime" resultMap="studyMap">
+    select ccc.`rank` as `rank`, 0 as `total`
+    from (
+    select aaa.`user_id` as `user_id`, (@rank:=@rank+1) as `rank`
+    from (
+    select sum(ur.`user_time`) as `user_time`, ur.`user_id` as `user_id`
+    from `user_report` ur
+    where
+
+    <if test="startTime != null">
+      and ur.`update_time` &gt; #{startTime,jdbcType=VARCHAR}
+    </if>
+    <if test="endTime != null">
+      and ur.`update_time` &lt; #{endTime,jdbcType=VARCHAR}
+    </if>
+    group by ur.`user_id`
+    ) as aaa, (select @rank:=0) as bbb  order by `user_time` desc
+    ) as ccc where ccc.`user_id` = #{userId,jdbcType=VARCHAR}
+  </select>
+
+  <!--
+    用户模考记录排名
+  -->
+  <select id="rankExaminationByTime" resultMap="studyMap">
+    select ccc.`rank` as `rank`, 0 as `total`
+    from (
+    select aaa.`user_id` as `user_id`, (@rank:=@rank+1) as `rank`
+    from (
+    select sum(ucr.`user_time`) as `user_time`, ucr.`user_id` as `user_id`
+    from `user_course_record` ucr
+    where
+    1
+    <if test="startTime != null">
+      and ucr.`create_time` &gt; #{startTime,jdbcType=VARCHAR}
+    </if>
+    <if test="endTime != null">
+      and ur.`create_time` &lt; #{endTime,jdbcType=VARCHAR}
+    </if>
+    group by ucr.`user_id`
+    ) as aaa, (select @rank:=0) as bbb  order by `user_time` desc
+    ) as ccc where ccc.`user_id` = #{userId,jdbcType=VARCHAR}
+  </select>
 </mapper>

+ 13 - 28
server/gateway-api/src/main/java/com/qxgmat/controller/api/MyController.java

@@ -240,6 +240,9 @@ public class MyController {
             m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
         }
 
+        // 获取总用户数
+        Integer total = usersService.count();
+
         // 获取练习统计 - 按题型进行分组统计
         Integer exerciseTime = 0;
         Integer exerciseQuestion = 0;
@@ -251,10 +254,13 @@ public class MyController {
             exerciseList.add(new UserExerciseExtendDto(m.get(type.getModule()), type.getUserNumber(), type.getUserTime(), type.getUserCorrect()));
         }
         // todo 练习统计排行
+        UserRankStatRelation exerciseRank = userReportService.rankExerciseByTime(user.getId(), startTime, endTime);
+        exerciseRank.setTotal(total);
 
         dto.setExerciseTime(exerciseTime);
         dto.setExerciseQuestion(exerciseQuestion);
         dto.setExerciseList(exerciseList);
+        dto.setExerciseExceed(exerciseRank);
 
         // 获取模考统计 - 按卷子
         Integer examinationTime = 0;
@@ -272,10 +278,13 @@ public class MyController {
             examinationPaperList.add(d);
         }
         // todo 模考统计排行
+        UserRankStatRelation examinationRank = userReportService.rankExaminationByTime(user.getId(), startTime, endTime);
+        examinationRank.setTotal(total);
 
         dto.setExaminationTime(examinationTime);
         dto.setExaminationPaper(examinationPaper);
         dto.setExaminationList(examinationPaperList);
+        dto.setExaminationExceed(examinationRank);
 
         // 获取课程访问记录 - 按课时
         Integer classTime = 0;
@@ -297,10 +306,14 @@ public class MyController {
             courseResultList.add(d);
         }
         // todo 听课统计排行
+        UserRankStatRelation classRank = userCourseRecordService.rankByTime(user.getId(), startTime, endTime);
+        classRank.setTotal(total);
 
         dto.setClassTime(classTime);
         dto.setClassCourse(classCourse);
         dto.setClassList(courseResultList);
+        dto.setClassExceed(classRank);
+
 
         return ResponseHelp.success(dto);
     }
@@ -387,34 +400,6 @@ public class MyController {
         User user = (User) shiroHelp.getLoginUser();
         UserStudyDayDto dto = new UserStudyDayDto();
 
-        List<ExerciseStruct> p = exerciseStructService.main();
-        Map<String, String> m = new HashMap<>();
-        for (ExerciseStruct struct : p){
-            if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
-            m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
-        }
-
-        // 获取练习统计 - 按题型进行分组统计
-        Integer exerciseTime = 0;
-        Integer exerciseQuestion = 0;
-        List<UserExerciseExtendDto> exerciseList = new ArrayList<>();
-        List<UserStudyStatRelation> typeList = userReportService.statGroupExerciseType(user.getId(), startTime, endTime);
-        for(UserStudyStatRelation type:typeList){
-            exerciseTime += type.getUserTime();
-            exerciseQuestion += type.getUserNumber();
-            exerciseList.add(new UserExerciseExtendDto(m.get(type.getModule()), type.getUserNumber(), type.getUserTime(), type.getUserCorrect()));
-        }
-
-        dto.setExerciseTime(exerciseTime);
-        dto.setExerciseQuestion(exerciseQuestion);
-        dto.setExerciseList(exerciseList);
-
-        // 获取模考统计 - 按卷子
-
-        // 获取课程访问记录 - 按课时
-        Integer classTime = 0;
-        Integer classCourse = 0;
-
         return ResponseHelp.success(dto);
     }
 

+ 8 - 0
server/gateway-api/src/main/java/com/qxgmat/controller/api/QuestionController.java

@@ -365,6 +365,14 @@ public class QuestionController {
         return ResponseHelp.success(result);
     }
 
+    @RequestMapping(value = "/stage", method = RequestMethod.POST)
+    @ApiOperation(value = "本阶段完成", notes = "结束当前阶段: 达到阶段时间时调用,然后继续调用next", httpMethod = "POST")
+    public Response<Boolean> stage(@RequestBody @Validated ReportStageDto dto)  {
+        User user = (User) shiroHelp.getLoginUser();
+        Boolean result = questionFlowService.stage(user.getId(), dto.getUserReportId());
+        return ResponseHelp.success(result);
+    }
+
     @RequestMapping(value = "/restart/paper", method = RequestMethod.POST)
     @ApiOperation(value = "重置考试", notes = "重置考试", httpMethod = "POST")
     public Response<Boolean> restart(@RequestBody @Validated PaperRestartDto dto)  {

+ 13 - 0
server/gateway-api/src/main/java/com/qxgmat/dto/request/ReportStageDto.java

@@ -0,0 +1,13 @@
+package com.qxgmat.dto.request;
+
+public class ReportStageDto {
+    private Integer userReportId;
+
+    public Integer getUserReportId() {
+        return userReportId;
+    }
+
+    public void setUserReportId(Integer userReportId) {
+        this.userReportId = userReportId;
+    }
+}

+ 10 - 9
server/gateway-api/src/main/java/com/qxgmat/dto/response/UserStudyDayDto.java

@@ -1,5 +1,6 @@
 package com.qxgmat.dto.response;
 
+import com.qxgmat.data.relation.entity.UserRankStatRelation;
 import com.qxgmat.dto.extend.UserCourseResultExtendDto;
 import com.qxgmat.dto.extend.UserExerciseExtendDto;
 import com.qxgmat.dto.extend.UserPaperBaseExtendDto;
@@ -11,7 +12,7 @@ public class UserStudyDayDto {
 
     private Integer exerciseQuestion;
 
-    private Integer exerciseExceed;
+    private UserRankStatRelation exerciseExceed;
 
     private List<UserExerciseExtendDto> exerciseList;
 
@@ -19,7 +20,7 @@ public class UserStudyDayDto {
 
     private Integer examinationPaper;
 
-    private Integer examinationExceed;
+    private UserRankStatRelation examinationExceed;
 
     private List<UserPaperBaseExtendDto> examinationList;
 
@@ -27,7 +28,7 @@ public class UserStudyDayDto {
 
     private Integer classCourse;
 
-    private Integer classExceed;
+    private UserRankStatRelation classExceed;
 
     private List<UserCourseResultExtendDto> classList;
 
@@ -47,11 +48,11 @@ public class UserStudyDayDto {
         this.exerciseQuestion = exerciseQuestion;
     }
 
-    public Integer getExerciseExceed() {
+    public UserRankStatRelation getExerciseExceed() {
         return exerciseExceed;
     }
 
-    public void setExerciseExceed(Integer exerciseExceed) {
+    public void setExerciseExceed(UserRankStatRelation exerciseExceed) {
         this.exerciseExceed = exerciseExceed;
     }
 
@@ -79,11 +80,11 @@ public class UserStudyDayDto {
         this.examinationPaper = examinationPaper;
     }
 
-    public Integer getExaminationExceed() {
+    public UserRankStatRelation getExaminationExceed() {
         return examinationExceed;
     }
 
-    public void setExaminationExceed(Integer examinationExceed) {
+    public void setExaminationExceed(UserRankStatRelation examinationExceed) {
         this.examinationExceed = examinationExceed;
     }
 
@@ -111,11 +112,11 @@ public class UserStudyDayDto {
         this.classCourse = classCourse;
     }
 
-    public Integer getClassExceed() {
+    public UserRankStatRelation getClassExceed() {
         return classExceed;
     }
 
-    public void setClassExceed(Integer classExceed) {
+    public void setClassExceed(UserRankStatRelation classExceed) {
         this.classExceed = classExceed;
     }
 

+ 28 - 0
server/gateway-api/src/main/java/com/qxgmat/service/UsersService.java

@@ -226,11 +226,13 @@ public class UsersService extends AbstractService {
         return page(()->select(userMapper, example), page, size);
     }
 
+    // 通过手机号获取用户
     public User getByMobile(String mobile){
         User user = User.builder().mobile(mobile).build();
         return one(userMapper, user);
     }
 
+    // 通过openid获取用户
     public User getByOpen(String openId, String unionId, String platform){
         String platformField;
         String unionField;
@@ -277,10 +279,18 @@ public class UsersService extends AbstractService {
         return one(userMapper, example);
     }
 
+    /**
+     * 获取备考统计:身份
+     * @return
+     */
     public List<UserPrepareRelation> statPrepareStatus(){
         return userRelationMapper.groupPrepareString("prepare_status");
     }
 
+    /**
+     * 获取备考统计:目标分数
+     * @return
+     */
     public List<UserPrepareRelation> statPrepareGoal(){
         List<UserPrepareRelation> relations =  userRelationMapper.groupPrepareInteger("prepare_goal");
         // 按考分分组
@@ -313,10 +323,18 @@ public class UsersService extends AbstractService {
         return userPrepareRelationList;
     }
 
+    /**
+     * 获取备考统计:考试时间
+     * @return
+     */
     public List<UserPrepareRelation> statPrepareExaminationTime(){
         return userRelationMapper.groupPrepareString("prepare_examination_time");
     }
 
+    /**
+     * 获取备考统计:出分时间
+     * @return
+     */
     public List<UserPrepareRelation> statPrepareScoreTime(){
         // 直接按不同时间段统计
         Example example;
@@ -425,6 +443,16 @@ public class UsersService extends AbstractService {
         return p;
     }
 
+    /**
+     * 获取总用户数
+     * @return
+     */
+    public Integer count(){
+        Example example = new Example(User.class);
+
+        return count(userMapper, example);
+    }
+
     public boolean equalsPassword(User user, String password){
         return Objects.equals(user.getPassword(), Tools.stringMD5(Tools.stringMD5(password)));
     }

+ 12 - 0
server/gateway-api/src/main/java/com/qxgmat/service/extend/QuestionFlowService.java

@@ -514,6 +514,18 @@ public class QuestionFlowService {
     }
 
     /**
+     * 模考进入下一阶段
+     * @param userId
+     * @param userReportId
+     * @return
+     */
+    @Transactional
+    public Boolean stage(Integer userId, Integer userReportId){
+
+        return true;
+    }
+
+    /**
      * 完成试卷,进行试卷分析
      * @param userId
      * @param userReportId

+ 17 - 0
server/gateway-api/src/main/java/com/qxgmat/service/inline/UserCourseRecordService.java

@@ -9,6 +9,7 @@ import com.qxgmat.data.dao.UserCourseRecordMapper;
 import com.qxgmat.data.dao.entity.UserCourseRecord;
 import com.qxgmat.data.relation.UserCourseRecordRelationMapper;
 import com.qxgmat.data.relation.entity.UserCourseStatRelation;
+import com.qxgmat.data.relation.entity.UserRankStatRelation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -56,6 +57,22 @@ public class UserCourseRecordService extends AbstractService {
         return userCourseRecordRelationMapper.statGroupType(userId, startTime, endTime);
     }
 
+    /**
+     * 计算用户在指定时间内的学习排行
+     * @param userId
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public UserRankStatRelation rankByTime(Integer userId, String startTime, String endTime){
+        List<UserRankStatRelation> relation = userCourseRecordRelationMapper.rankByTime(userId, startTime, endTime);
+        if (relation != null && relation.size() > 0){
+            return relation.get(0);
+        }else{
+            return null;
+        }
+    }
+
     public UserCourseRecord add(UserCourseRecord record){
         int result = insert(userCourseRecordMapper, record);
         record = one(userCourseRecordMapper, record.getId());

+ 33 - 0
server/gateway-api/src/main/java/com/qxgmat/service/inline/UserReportService.java

@@ -12,6 +12,7 @@ import com.qxgmat.data.dao.entity.UserPaper;
 import com.qxgmat.data.dao.entity.UserQuestion;
 import com.qxgmat.data.dao.entity.UserReport;
 import com.qxgmat.data.relation.UserReportRelationMapper;
+import com.qxgmat.data.relation.entity.UserRankStatRelation;
 import com.qxgmat.data.relation.entity.UserReportLimitRelation;
 import com.qxgmat.data.relation.entity.UserStudyStatRelation;
 import com.qxgmat.service.annotation.InitReport;
@@ -115,6 +116,38 @@ public class UserReportService extends AbstractService {
     }
 
     /**
+     * 计算用户在指定时间内的练习排行
+     * @param userId
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public UserRankStatRelation rankExerciseByTime(Integer userId, String startTime, String endTime){
+        List<UserRankStatRelation> relation = userReportRelationMapper.rankExerciseByTime(userId, startTime, endTime);
+        if (relation != null && relation.size() > 0){
+            return relation.get(0);
+        }else{
+            return null;
+        }
+    }
+
+    /**
+     * 计算用户在指定时间内的模考排行
+     * @param userId
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public UserRankStatRelation rankExaminationByTime(Integer userId, String startTime, String endTime){
+        List<UserRankStatRelation> relation = userReportRelationMapper.rankExaminationByTime(userId, startTime, endTime);
+        if (relation != null && relation.size() > 0){
+            return relation.get(0);
+        }else{
+            return null;
+        }
+    }
+
+    /**
      * 根据用户paper生成一份新的report记录
      * @param paper
      * @param setting