|
@@ -142,7 +142,9 @@ func StatisticsTotalLearnTime(c *gin.Context, apictx *ApiSession) (interface{},
|
|
uid = apictx.User.ID
|
|
uid = apictx.User.ID
|
|
}
|
|
}
|
|
|
|
|
|
- colls := apictx.CreateRepoCtx().Client.GetDbCollection(db, repo.CollectionLearnLog)
|
|
|
|
|
|
+ // colls := apictx.CreateRepoCtx().Client.GetDbCollection(db, repo.CollectionLearnLog)
|
|
|
|
+ // ! 优化查询性能,使用统计表
|
|
|
|
+ colls := apictx.CreateRepoCtx().Client.GetDbCollection(db, repo.CollectionLearnLogStatistics)
|
|
return AggregateTotalLearnTime(colls, uid)
|
|
return AggregateTotalLearnTime(colls, uid)
|
|
|
|
|
|
}
|
|
}
|
|
@@ -241,47 +243,47 @@ func StatisticsBestExeamScore(c *gin.Context, apictx *ApiSession) (interface{},
|
|
return exeamLog.Score, nil
|
|
return exeamLog.Score, nil
|
|
}
|
|
}
|
|
|
|
|
|
-// 个人: 已学习模块数
|
|
|
|
-// 统计各个模块的学习总时长,根据总时长时间判断是否已学习
|
|
|
|
-// 只需要返回统计各个模块的时长汇总,cid相同的为同一个模块
|
|
|
|
-func StatisticsLearnedModules(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
- db := c.Param("scope")
|
|
|
|
- if len(db) == 0 {
|
|
|
|
- return nil, errors.New("scope不能为空")
|
|
|
|
- }
|
|
|
|
- // 如果没有uid参数,则查询当前用户的
|
|
|
|
- uid := c.Query("uid")
|
|
|
|
- if len(uid) == 0 {
|
|
|
|
- uid = apictx.User.ID
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- colls := apictx.CreateRepoCtx().Client.GetDbCollection(db, repo.CollectionLearnLog)
|
|
|
|
- pipeline := mongo.Pipeline{
|
|
|
|
- {
|
|
|
|
- {Key: "$match", Value: bson.D{
|
|
|
|
- {Key: "uid", Value: uid},
|
|
|
|
- }},
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- {Key: "$group", Value: bson.D{
|
|
|
|
- {Key: "_id", Value: "$cid"},
|
|
|
|
- {Key: "totalLearnTime", Value: bson.D{{Key: "$sum", Value: "$learnTime"}}},
|
|
|
|
- }},
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cursor, err := colls.Aggregate(apictx.CreateRepoCtx().Ctx, pipeline)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var results []bson.M
|
|
|
|
- if err = cursor.All(apictx.CreateRepoCtx().Ctx, &results); err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return results, nil
|
|
|
|
-}
|
|
|
|
|
|
+// // 个人: 已学习模块数
|
|
|
|
+// // 统计各个模块的学习总时长,根据总时长时间判断是否已学习
|
|
|
|
+// // 只需要返回统计各个模块的时长汇总,cid相同的为同一个模块
|
|
|
|
+// func StatisticsLearnedModules(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
+// db := c.Param("scope")
|
|
|
|
+// if len(db) == 0 {
|
|
|
|
+// return nil, errors.New("scope不能为空")
|
|
|
|
+// }
|
|
|
|
+// // 如果没有uid参数,则查询当前用户的
|
|
|
|
+// uid := c.Query("uid")
|
|
|
|
+// if len(uid) == 0 {
|
|
|
|
+// uid = apictx.User.ID
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// colls := apictx.CreateRepoCtx().Client.GetDbCollection(db, repo.CollectionLearnLog)
|
|
|
|
+// pipeline := mongo.Pipeline{
|
|
|
|
+// {
|
|
|
|
+// {Key: "$match", Value: bson.D{
|
|
|
|
+// {Key: "uid", Value: uid},
|
|
|
|
+// }},
|
|
|
|
+// },
|
|
|
|
+// {
|
|
|
|
+// {Key: "$group", Value: bson.D{
|
|
|
|
+// {Key: "_id", Value: "$cid"},
|
|
|
|
+// {Key: "totalLearnTime", Value: bson.D{{Key: "$sum", Value: "$learnTime"}}},
|
|
|
|
+// }},
|
|
|
|
+// },
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// cursor, err := colls.Aggregate(apictx.CreateRepoCtx().Ctx, pipeline)
|
|
|
|
+// if err != nil {
|
|
|
|
+// return nil, err
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// var results []bson.M
|
|
|
|
+// if err = cursor.All(apictx.CreateRepoCtx().Ctx, &results); err != nil {
|
|
|
|
+// return nil, err
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// return results, nil
|
|
|
|
+// }
|
|
|
|
|
|
// 个人: 统计用户本年每月考核正确和错误数
|
|
// 个人: 统计用户本年每月考核正确和错误数
|
|
func StatisticsExeamTFRate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
func StatisticsExeamTFRate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|