sunsheng 1 year ago
parent
commit
72f26d6a3b
5 changed files with 8 additions and 13 deletions
  1. BIN
      package/copter-train.exe
  2. 2 0
      package/readme.md
  3. 4 11
      src/api/exeamLog.go
  4. 1 1
      src/api/router.go
  5. 1 1
      src/app.yaml

BIN
package/copter-train.exe


+ 2 - 0
package/readme.md

@@ -26,3 +26,5 @@ 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
+
+go build -ldflags -H=windowsgui .

+ 4 - 11
src/api/exeamLog.go

@@ -69,13 +69,6 @@ type HandleLatestExamLog struct {
 
 // 导出学生最后一场考核成绩
 func LatestExamExportExcel(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	isAdmin, err := IsAdmin(c, apictx)
-	if err != nil {
-		return nil, err
-	}
-	if !isAdmin {
-		return nil, errors.New("没有权限")
-	}
 	db := c.Param("scope")
 	if len(db) == 0 {
 		return nil, errors.New("scope不能为空")
@@ -85,6 +78,7 @@ func LatestExamExportExcel(c *gin.Context, apictx *ApiSession) (interface{}, err
 	flagIndex := -1
 
 	examTypes := []string{"理论", "实操"}
+	// examTypes := []string{"实操"}
 
 	for _, examType := range examTypes {
 
@@ -114,7 +108,7 @@ func LatestExamExportExcel(c *gin.Context, apictx *ApiSession) (interface{}, err
 	c.Header("Content-Disposition", "attachment; filename="+fileName)
 	c.Header("Content-Transfer-Encoding", "binary")
 
-	err = f.Write(c.Writer)
+	err := f.Write(c.Writer)
 	if err != nil {
 		return nil, err
 	}
@@ -128,7 +122,6 @@ func getTotalLearnTime(apictx *ApiSession, db string, uid string) (int32, error)
 	// 定义聚合管道
 	pipeline := mongo.Pipeline{
 		{{Key: "$match", Value: bson.D{{Key: "uid", Value: uid}}}},
-		{{Key: "$sort", Value: bson.D{{Key: "createTime", Value: -1}, {Key: "uid", Value: -1}}}},
 		{{Key: "$group", Value: bson.D{
 			{Key: "_id", Value: "$uid"},
 			{Key: "totalLearnTime", Value: bson.D{{Key: "$sum", Value: "$learnTime"}}},
@@ -148,7 +141,6 @@ func getTotalLearnTime(apictx *ApiSession, db string, uid string) (int32, error)
 		log.Error(err)
 		return 0, err
 	}
-	fmt.Println(results)
 	if len(results) > 0 {
 		return results[0]["totalLearnTime"].(int32), err
 	}
@@ -161,11 +153,12 @@ func getHandleLatestExamLog(apictx *ApiSession, db string, examType string) ([]*
 
 	pipeline := mongo.Pipeline{
 		{{Key: "$match", Value: bson.D{{Key: "type", Value: examType}}}},
-		{{Key: "$sort", Value: bson.D{{Key: "uid", Value: -1}}}},
+		{{Key: "$sort", Value: bson.D{{Key: "createTime", Value: -1}}}},
 		{{Key: "$group", Value: bson.D{
 			{Key: "_id", Value: "$uid"},
 			{Key: "latestExeamLog", Value: bson.D{{Key: "$first", Value: "$$ROOT"}}},
 		}}},
+		{{Key: "$sort", Value: bson.D{{Key: "_id", Value: -1}}}},
 	}
 
 	// 执行聚合管道

+ 1 - 1
src/api/router.go

@@ -58,7 +58,7 @@ func RegRouters(svc *Service) {
 	// 考核记录列表
 	root.GETJWT("/exeamLog/list/:scope", ExeamLogList)
 
-	root.GETJWT("/exeamLog/latest/export/:scope", LatestExamExportExcel)
+	root.GET("/exeamLog/latest/export/:scope", LatestExamExportExcel)
 
 	// 用户id,可选:没有这个参数时是自己的信息,否则是指定id的信息
 	// 本年每月学习时长 *type/year/uid

+ 1 - 1
src/app.yaml

@@ -1,4 +1,4 @@
-port: 8102
+port: 8101
 name: copter-train
 version: 1.0.0