sunsheng há 1 ano atrás
pai
commit
72b4298ca3
3 ficheiros alterados com 12 adições e 2 exclusões
  1. 3 0
      src/api/exeamLog.go
  2. 2 0
      src/api/statistics.go
  3. 7 2
      src/api/user.go

+ 3 - 0
src/api/exeamLog.go

@@ -39,6 +39,9 @@ func ExeamLogList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("scope不能为空")
 	}
 	page, size, query := UtilQueryPageSize(c)
+	if _, ok := query["uid"]; !ok {
+		query["uid"] = apictx.User.ID
+	}
 	return repo.RepoDbPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
 		Db:          db,
 		CollectName: repo.CollectionExeamLog,

+ 2 - 0
src/api/statistics.go

@@ -85,6 +85,8 @@ func AggregateMonthlyLearnTime(colls *mongo.Collection, uid string, learnType st
 
 		{
 			{Key: "$match", Value: bson.D{
+				{Key: "uid", Value: uid},
+				{Key: "type", Value: learnType},
 				{Key: "createTime", Value: bson.D{
 					{Key: "$gte", Value: time.Date(year, time.January, 1, 0, 0, 0, 0, chinaTimeZone)},
 					{Key: "$lt", Value: time.Date(year+1, time.January, 1, 0, 0, 0, 0, chinaTimeZone)},

+ 7 - 2
src/api/user.go

@@ -117,14 +117,19 @@ func DeleteUser(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 func UserList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	// 验证是否为管理员
-	isAdmin, err := IsAdmin(c, apictx)
+	isStudent, err := IsStudent(c, apictx)
 	if err != nil {
 		return nil, err
 	}
-	if !isAdmin {
+	if isStudent {
 		return nil, errors.New("没有权限")
 	}
 	page, size, query := UtilQueryPageSize(c)
+	role := c.Query("role")
+	if len(role) > 0 {
+		query["roles"] = bson.M{"$elemMatch": bson.M{"$eq": role}}
+	}
+
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
 		CollectName: repo.CollectionUser,
 		Page:        page,