Quellcode durchsuchen

添加直接修改操作得分

yaojianjun vor 9 Monaten
Ursprung
Commit
abaf56cfff

+ 2 - 1
Tech/conf/app.conf

@@ -11,7 +11,8 @@ ElectricalPort = 7314
 
 # 数据库配置
 DB.Adapter = mysql
-DB.URL = dbadmin:dbadmin@987(124.222.28.5:7312)/CCGD_project?charset=utf8
+DB.URL = dbadmin:dbadmin@987@(124.222.28.5:7312)/CCGD_project?charset=utf8
+#DB.URL = root:wl110@(127.0.0.1:3306)/CCGD_project?charset=utf8
 
 # 信息化服务器和地址
 ESYSIP = 124.222.28.5

+ 136 - 0
Tech/controllers/电子考评.go

@@ -1684,3 +1684,139 @@ func (c *EvaLogController) UploadTMS() {
 	c.ServeJSON()
 
 }
+
+// /evalog/setscore  设置课程得分
+
+// /evalog/setscore  设置课程得分
+
+func (c *EvaLogController) SetScore() {
+	type Request struct {
+		RunLogID int `json:"runLogID"`
+		SeqNo    int `json:"seqNo"`
+		EvaScore int `json:"evaScore"`
+	}
+
+	var req Request
+	requestBody := c.Ctx.Input.RequestBody
+	println("Request Body:", string(requestBody))
+
+	if err := json.Unmarshal(requestBody, &req); err != nil {
+		c.Ctx.Output.SetStatus(400)
+		c.Data["json"] = map[string]interface{}{
+			"code": 400,
+			"msg":  "请求参数格式错误: " + err.Error(),
+		}
+		c.ServeJSON()
+		return
+	}
+
+	if req.RunLogID == 0 || req.SeqNo == 0 {
+		c.Ctx.Output.SetStatus(400)
+		c.Data["json"] = map[string]interface{}{
+			"code": 400,
+			"msg":  "缺少必要参数",
+		}
+		c.ServeJSON()
+		return
+	}
+
+	o := orm.NewOrm()
+
+	// 查询对应的评价记录
+	var evaLog models.CourseEvaLog
+	err := o.Raw(`
+		SELECT *
+		FROM CourseEvaLog
+		WHERE 运行记录编号 = ? AND 序号 = ?
+	`, req.RunLogID, req.SeqNo).QueryRow(&evaLog)
+
+	if err != nil {
+		if err == orm.ErrNoRows {
+			c.Data["json"] = map[string]interface{}{
+				"code": 404,
+				"msg":  "未找到对应的评价记录",
+			}
+		} else {
+			c.Data["json"] = map[string]interface{}{
+				"code": 500,
+				"msg":  "查询评价记录失败: " + err.Error(),
+			}
+		}
+		c.ServeJSON()
+		return
+	}
+
+	// 验证分数范围应在0到评价赋分之间
+	if req.EvaScore < 0 || req.EvaScore > evaLog.EvaScore {
+		c.Data["json"] = map[string]interface{}{
+			"code": 400,
+			"msg":  fmt.Sprintf("分数应在0到%d之间", evaLog.EvaScore),
+		}
+		c.ServeJSON()
+		return
+	}
+
+	operScore := req.EvaScore
+
+	// 更新CourseEvaLog表中的操作得分
+	_, err = o.Raw(`
+		UPDATE CourseEvaLog 
+		SET 操作得分 = ?
+		WHERE 运行记录编号 = ? AND 序号 = ?
+	`, operScore, req.RunLogID, req.SeqNo).Exec()
+
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{
+			"code": 500,
+			"msg":  "更新评价分数失败: " + err.Error(),
+		}
+		c.ServeJSON()
+		return
+	}
+
+	// 重新计算整个课程的总得分
+	var totalScore float64
+	err = o.Raw(`
+		SELECT COALESCE(SUM(操作得分), 0) 
+		FROM CourseEvaLog 
+		WHERE 运行记录编号 = ?
+	`, req.RunLogID).QueryRow(&totalScore)
+
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{
+			"code": 500,
+			"msg":  "计算总得分失败: " + err.Error(),
+		}
+		c.ServeJSON()
+		return
+	}
+
+	// 更新课程运行日志中的总得分
+	_, err = o.Raw(`
+		UPDATE CourseRunLog 
+		SET 课程得分 = ? 
+		WHERE 运行记录编号 = ?
+	`, totalScore, req.RunLogID).Exec()
+
+	if err != nil {
+		c.Data["json"] = map[string]interface{}{
+			"code": 500,
+			"msg":  "更新总得分失败: " + err.Error(),
+		}
+		c.ServeJSON()
+		return
+	}
+
+	c.Data["json"] = map[string]interface{}{
+		"code": 200,
+		"msg":  "设置评价分数成功",
+		"data": map[string]interface{}{
+			"runLogID":   req.RunLogID,
+			"seqNo":      req.SeqNo,
+			"evaScore":   req.EvaScore,
+			"operScore":  operScore,
+			"totalScore": totalScore,
+		},
+	}
+	c.ServeJSON()
+}

+ 6 - 0
Tech/controllers/节点解析存储.go

@@ -233,6 +233,8 @@ func SaveCourseActionNode(classID int, parentID int, node *models.Node) (bool, e
 		if node.NodeData.OperationNode != nil {
 			courseEva.EvaScore = nodedata.OperationNode.Score
 			courseEva.EvaDeduction = nodedata.OperationNode.Deduction
+			// 0客观 1主观
+			courseEva.EvaType = nodedata.OperationNode.SubjectiveEvaluation
 		}
 		if node.NodeData.VoiceNode != nil {
 			courseEva.EvaScore = 0
@@ -293,6 +295,10 @@ func saveOperationNode(classID int, nodeID int, opNode *models.CourseOperationNo
 	// 设置课程ID
 	opNode.CourseID = classID
 	opNode.NodeID = nodeID
+	// 如果主观评价标记未设置,默认为0(客观评价)
+	if opNode.SubjectiveEvaluation == 0 {
+		opNode.SubjectiveEvaluation = 0 // 默认为客观评价
+	}
 	_, err := o.Insert(opNode)
 	if err != nil {
 		return false, fmt.Sprintf("保存操作节点失败,节点重复: %v", err)

+ 8 - 0
Tech/controllers/课程.go

@@ -1098,6 +1098,10 @@ func (c *CourseController) CourseCopy() {
 
 		for _, node := range operationNodes {
 			node.CourseID = newCourse.CourseID
+			// 如果主观评价标记未设置,默认为0(客观评价)
+			if node.SubjectiveEvaluation == 0 {
+				node.SubjectiveEvaluation = 0 // 默认为客观评价
+			}
 			_, _, err = o.ReadOrCreate(&node, "CourseID", "NodeID")
 			if err != nil {
 				failedCourses = append(failedCourses, map[string]interface{}{
@@ -1469,6 +1473,10 @@ func (c *CourseController) CourseImport() {
 		// 导入 CourseOperationNode
 		for _, node := range courseData.OperationNodes {
 			node.CourseID = newCourse.CourseID
+			// 如果主观评价标记未设置,默认为0(客观评价)
+			if node.SubjectiveEvaluation == 0 {
+				node.SubjectiveEvaluation = 0 // 默认为客观评价
+			}
 			_, _, err = o.ReadOrCreate(&node, "CourseID", "NodeID")
 			if err != nil {
 				importResults = append(importResults, map[string]interface{}{

+ 5 - 0
Tech/models/教员模型.go

@@ -90,6 +90,8 @@ type CourseOperationNode struct {
 	TextParam5 string `orm:"column(文本参数5);type(text)" json:"textParam5"`
 	Score      int    `orm:"column(赋分)" json:"score"`
 	Deduction  int    `orm:"column(失分)" json:"deduction"`
+	// 0主观评价1客观评价
+	SubjectiveEvaluation int `orm:"column(主观评价标记)" json:"subjectiveEvaluation"`
 }
 
 func (c *CourseOperationNode) TableName() string { return "CourseOperationNode" }
@@ -151,6 +153,9 @@ type TemplateOperation struct {
 	Param4Desc      string `orm:"column(参数4说明);type(text)" json:"param4Desc"`
 	Param5Type      int    `orm:"column(参数5类型)" json:"param5Type"`
 	Param5Desc      string `orm:"column(参数5说明);type(text)" json:"param5Desc"`
+
+	// 0客观 1主观
+	SubjectiveEvaluation int `orm:"column(主观评价标记)" json:"subjectiveEvaluation"`
 }
 
 func (t *TemplateOperation) TableName() string { return "TemplateOperation" }

+ 3 - 0
Tech/routers/router.go

@@ -111,4 +111,7 @@ func init() {
 
 	// /evalog/uploadtms 课程评价记录上传信息化系统
 	beego.Router("/evalog/uploadtms", &controllers.EvaLogController{}, "post:UploadTMS")
+
+	// /evalog/setscore
+	beego.Router("/evalog/setscore", &controllers.EvaLogController{}, "post:SetScore")
 }