Browse Source

测试接口并修复存在的错误

sunsheng 1 year ago
parent
commit
c37a83635f

+ 5 - 1
src/api/exeamLog.go

@@ -5,8 +5,10 @@ import (
 	"copter-train/db/repo"
 	"copter-train/log"
 	"errors"
+	"time"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 // 提交考核试题
@@ -22,6 +24,8 @@ func SubmitExeamLog(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, err
 	}
 	exeamLog.Uid = apictx.User.ID
+	exeamLog.CreateTime = time.Now()
+	exeamLog.UpdateTime = time.Now()
 	return repo.RepoAddDbDoc(apictx.CreateRepoCtx(), db, repo.CollectionExeamLog, exeamLog)
 }
 
@@ -39,6 +43,6 @@ func ExeamLogList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		Page:        page,
 		Size:        size,
 		Query:       query,
-		// Sort:        bson.D{bson.E{Key: "sort", Value: 1}, bson.E{Key: "createTime", Value: 1}},
+		Sort:        bson.M{"createTime": 1},
 	})
 }

+ 2 - 2
src/api/learnLog.go

@@ -41,6 +41,6 @@ func SyncLearnTime(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if objId.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	update := bson.M{"$inc": bson.M{"learnTime": 1}, "updateTime": time.Now()}
-	return repo.RepoUpdateDbSetDoc(apictx.CreateRepoCtx(), db, repo.CollectionLearnLog, id, update)
+	update := bson.M{"$inc": bson.M{"learnTime": 1}, "$set": bson.M{"updateTime": time.Now()}}
+	return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), db, repo.CollectionLearnLog, id, update)
 }

+ 1 - 1
src/api/router.go

@@ -53,7 +53,7 @@ func RegRouters(svc *Service) {
 
 	// 学习记录统计 / 考核记录统计
 	// 管理员:选择学员查看,理论和实操分开
-	// 学习记录统计: x月份 y时长
+	// 学习记录统计: x月份 y时长/ 本年
 	// 考核记录统计: 历史考核记录[v] | 考核列表
 
 	// 考虑创建一张统计表,学习完成把当前学习时长写入统计表

+ 1 - 1
src/api/user.go

@@ -116,7 +116,7 @@ func UserList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		Page:        page,
 		Size:        size,
 		Query:       query,
-		Project:     []string{"nickName", "loginName", "avatar", "roles", "createTime", "updateTime"},
+		Project:     []string{"nid", "name", "loginName", "avatar", "roles", "createTime", "updateTime"},
 	})
 
 }

+ 11 - 9
src/db/model/exeamLog.go

@@ -7,13 +7,15 @@ import (
 )
 
 type ExeamLog struct {
-	Id           primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Uid          string             `bson:"uid,omitempty" json:"uid"`                   // 用户id
-	Type         string             `bson:"type,omitempty" json:"type"`                 // 考核类型: 理论/实操
-	Correct      *int               `bson:"correct,omitempty" json:"correct"`           // 正确题目数
-	Error        *int               `bson:"error,omitempty" json:"error"`               // 错误题目数
-	TotalScore   *int               `bson:"totalScore,omitempty" json:"totalScore"`     // 总分
-	CompleteRate *int               `bson:"completeRate,omitempty" json:"completeRate"` // 完成进度
-	CreateTime   time.Time          `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime   time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Uid        string             `bson:"uid,omitempty" json:"uid"`               // 用户id
+	Type       string             `bson:"type,omitempty" json:"type"`             // 考核类型: 理论/实操
+	Correct    *int               `bson:"correct,omitempty" json:"correct"`       // 正确题目数
+	Error      *int               `bson:"error,omitempty" json:"error"`           // 错误题目数
+	TotalScore *int               `bson:"totalScore,omitempty" json:"totalScore"` // 总分
+	// 成绩
+	Socre        *int      `bson:"socre,omitempty" json:"socre"`               // 分数
+	CompleteRate *int      `bson:"completeRate,omitempty" json:"completeRate"` // 完成进度
+	CreateTime   time.Time `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime   time.Time `bson:"updateTime,omitempty" json:"updateTime"`
 }

+ 1 - 1
src/db/model/learnLog.go

@@ -12,7 +12,7 @@ import (
 type LearnLog struct {
 	Id  primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
 	Uid string             `bson:"uid,omitempty" json:"uid"` // 用户id
-	Cid string             `bson:"pid,omitempty" json:"pid"` // 分类配置id
+	Cid string             `bson:"cid,omitempty" json:"cid"` // 分类配置id
 	// Sid        string             `bson:"sid,omitempty" json:"sid"`             //subject id 学习主题id // 客户端用于标识题目的(因为服务端不存储题目)
 	Type       string    `bson:"type,omitempty" json:"type"`           // 学习类型: 理论/实操
 	LearnTime  *int      `bson:"learnTime,omitempty" json:"learnTime"` // 学习时长

+ 2 - 1
src/db/model/user.go

@@ -8,7 +8,8 @@ import (
 
 type User struct {
 	Id        primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
-	NickName  string             `bson:"nickName,omitempty" json:"nickName,omitempty"`
+	Nid       string             `bson:"nid,omitempty" json:"nid,omitempty"` // 编号
+	Name      string             `bson:"name,omitempty" json:"name,omitempty"`
 	LoginName string             `bson:"loginName,omitempty" json:"loginName,omitempty"`
 	Password  string             `bson:"password,omitempty" json:"password,omitempty"`
 	Avatar    string             `bson:"avatar,omitempty" json:"avatar,omitempty"`

+ 4 - 4
src/db/repo/repo.go

@@ -121,9 +121,9 @@ func RepoUpdateSetDoc(ctx *RepoSession, collectName string, idstr string, model
 	return colls.UpdateByID(ctx.Ctx, uid, update)
 }
 
-func RepoUpdateDbSetDoc(ctx *RepoSession, Db string, collectName string, idstr string, model interface{}) (*mongo.UpdateResult, error) {
+func RepoUpdateDbSetDoc(ctx *RepoSession, db string, collectName string, idstr string, model interface{}) (*mongo.UpdateResult, error) {
 
-	colls := ctx.Client.GetDbCollection(Db, collectName)
+	colls := ctx.Client.GetDbCollection(db, collectName)
 
 	update := bson.M{"$set": model}
 
@@ -145,9 +145,9 @@ func RepoUpsertSetDoc(ctx *RepoSession, collectName string, filter interface{},
 	return coll.UpdateOne(ctx.Ctx, filter, update, opts)
 }
 
-func RepoUpdateSetDocProps(ctx *RepoSession, collectName string, idstr string, update interface{}) (*mongo.UpdateResult, error) {
+func RepoUpdateSetDbDocProps(ctx *RepoSession, db string, collectName string, idstr string, update interface{}) (*mongo.UpdateResult, error) {
 
-	colls := ctx.Client.GetCollection(collectName)
+	colls := ctx.Client.GetDbCollection(db, collectName)
 	// update := bson.M{"$set": model}
 	uid, _ := primitive.ObjectIDFromHex(idstr)
 	return colls.UpdateByID(ctx.Ctx, uid, update)

+ 4 - 1
src/readme.md

@@ -25,4 +25,7 @@ db.createUser({user:"root",pwd:"copter-train-8888",roles:["dbOwner"]});
 
 ```
 创建默认管理员账号
-MONGO_MIGRATION: mongo-migrations==mongodb://root:copter-train-8888@127.0.0.1:27017/copter?authSource=admin
+MONGO_MIGRATION: mongo-migrations==mongodb://root:copter-train-8888@127.0.0.1:27017/copter?authSource=admin
+
+<!-- 
+eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDYxNTUwMzksImlkIjoiNjVhOGEwNGNhODU1NzUyYTU4YWNmYmY3Iiwib3JpZ19pYXQiOjE3MDU1NTAyMzl9.M3-RTgD65y8wg20dTCOyx79XMLfMVDoaNU_bDaHSpmY -->