yaojianjun месяцев назад: 9
Родитель
Сommit
1af913201d
2 измененных файлов с 258 добавлено и 4 удалено
  1. 211 4
      Tech/controllers/电调.go
  2. 47 0
      Tech/自动评价流程图.md

+ 211 - 4
Tech/controllers/电调.go

@@ -190,9 +190,208 @@ type Addctrllog_req struct {
 	Param5      string `json:"Param5"`
 }
 
+// 自动评价数据结构体
+type AutoEvaData struct {
+	RunLogID   int    `orm:"column(运行记录编号)" json:"runLogID"`
+	SeqNo      int    `orm:"column(序号)" json:"seqNo"`
+	EvaName    string `orm:"column(评价名称)" json:"evaName"`
+	CourseID   int    `orm:"column(课程ID)" json:"courseID"`
+	IsOperated int    `orm:"column(是否操作)" json:"isOperated"`
+	NodeID     int    `orm:"column(节点ID)" json:"nodeID"`
+	EvaType    int    `orm:"column(评价类型)" json:"evaType"`
+	TextParam1 string `orm:"column(文本参数1)" json:"textParam1"`
+	TextParam2 string `orm:"column(文本参数2)" json:"textParam2"`
+	TextParam3 string `orm:"column(文本参数3)" json:"textParam3"`
+	TextParam4 string `orm:"column(文本参数4)" json:"textParam4"`
+	TextParam5 string `orm:"column(文本参数5)" json:"textParam5"`
+}
+
+// 评价结果结构体
+type EvaResult struct {
+	Code        int     `json:"code"`        // 状态码:200-成功,400-失败
+	Message     string  `json:"message"`     // 描述信息
+	EvaName     string  `json:"evaName"`     // 评价名称
+	IsOperated  int     `json:"isOperated"`  // 是否操作:0-未操作,1-已操作
+	OperScore   float64 `json:"operScore"`   // 操作得分
+	CourseScore float64 `json:"courseScore"` // 课程总分
+	SeqNo       int     `json:"seqNo"`       // 序号
+}
+
 // /实现自动评价
-func (c *EDispatchController) Eqpmtlist(req Addctrllog_req) {
+func (c *EDispatchController) DoAutoEva(req Addctrllog_req) EvaResult {
+	// 获取数据库连接
+	o := orm.NewOrm()
+
+	// 查找当前正在运行的课程
+	var runningCourse models.CourseRunLog
+	err := o.QueryTable(new(models.CourseRunLog)).
+		Filter("CourseTime", 0).
+		OrderBy("-RunLogID").
+		One(&runningCourse)
+
+	if err != nil {
+		// 如果没有找到正在运行的课程,返回错误结果
+		return EvaResult{
+			Code:    400,
+			Message: "没有找到正在运行的课程",
+		}
+	}
+
+	// 使用自定义SQL查询获取自动评价所需数据
+	var autoEvaData []AutoEvaData
+	sql := `SELECT a.运行记录编号, a.序号, a.评价名称, b.课程ID, a.是否操作, b.节点ID,
+			a.评价类型, b.文本参数1, b.文本参数2, b.文本参数3, b.文本参数4, b.文本参数5
+			FROM CourseEvaLog a JOIN CourseOperationNode b ON a.评价映射ID = b.节点ID 
+			WHERE a.运行记录编号 = ? AND a.评价类型 = 1 ORDER BY a.序号`
+
+	_, err = o.Raw(sql, runningCourse.RunLogID).QueryRows(&autoEvaData)
+	if err != nil {
+		return EvaResult{
+			Code:    400,
+			Message: "查询评价数据失败: " + err.Error(),
+		}
+	}
+
+	// 如果没有评价数据,返回提示信息
+	if len(autoEvaData) == 0 {
+		return EvaResult{
+			Code:        200,
+			Message:     "当前课程没有评价数据",
+			CourseScore: runningCourse.CourseScore,
+		}
+	}
+
+	// 查找第一个未操作的记录
+	var foundEvaData *AutoEvaData
+	var firstSeqNo int = -1
+
+	for _, evaData := range autoEvaData {
+		if evaData.IsOperated == 0 {
+			if firstSeqNo == -1 {
+				firstSeqNo = evaData.SeqNo
+			}
+			// 检查当前操作的序号是否是第一个未操作的序号
+			if evaData.SeqNo == firstSeqNo {
+				foundEvaData = &evaData
+				break
+			}
+		}
+	}
 
+	// 如果没有找到未操作的记录,返回已完成提示
+	if foundEvaData == nil {
+		return EvaResult{
+			Code:        200,
+			Message:     "所有评价项已完成",
+			CourseScore: runningCourse.CourseScore,
+		}
+	}
+
+	// 比较参数1和参数2
+	if req.Param1 == foundEvaData.TextParam1 && req.Param2 == foundEvaData.TextParam2 {
+		// 参数匹配,需要更新对应的CourseEvaLog记录
+		var evaLog models.CourseEvaLog
+		err = o.QueryTable(new(models.CourseEvaLog)).
+			Filter("RunLogID", foundEvaData.RunLogID).
+			Filter("SeqNo", foundEvaData.SeqNo).
+			One(&evaLog)
+		if err != nil {
+			return EvaResult{
+				Code:    400,
+				Message: "查询评价记录失败: " + err.Error(),
+			}
+		}
+
+		// 计算操作时间
+		operTime := 0
+		// 只有在课程未结束时才计算操作时间(暂停标记为-1表示课程结束)
+		if runningCourse.PauseFlag != -1 {
+			// 解析课程开始时间
+			startTime, err := time.ParseInLocation("2006-01-02 15:04:05", runningCourse.RunDateTime, time.Local)
+			if err != nil {
+				return EvaResult{
+					Code:    400,
+					Message: "解析课程开始时间失败: " + err.Error(),
+				}
+			}
+
+			operTime = int(time.Since(startTime).Seconds()) - runningCourse.PauseTotalTime
+			// 确保操作时间不为负数
+			if operTime < 0 {
+				operTime = 0
+			}
+		}
+
+		// 计算操作得分
+		operScore := 0.0
+		// 已操作,得分为评价赋分-评价失分
+		operScore = float64(evaLog.EvaScore - evaLog.EvaDeduction)
+
+		// 更新CourseEvaLog表中的是否操作字段、操作得分和操作时间
+		_, err = o.Raw(`
+			UPDATE CourseEvaLog 
+			SET 是否操作 = ?, 操作得分 = ?, 操作时间 = ?
+			WHERE 运行记录编号 = ? AND 序号 = ?
+		`, 1, operScore, operTime, foundEvaData.RunLogID, foundEvaData.SeqNo).Exec()
+		
+		if err != nil {
+			return EvaResult{
+				Code:    400,
+				Message: "更新节点操作状态失败: " + err.Error(),
+			}
+		}
+
+		// 重新计算整个课程的总得分
+		var totalScore float64
+		err = o.Raw(`
+			SELECT COALESCE(SUM(操作得分), 0) 
+			FROM CourseEvaLog 
+			WHERE 运行记录编号 = ?
+		`, foundEvaData.RunLogID).QueryRow(&totalScore)
+
+		if err != nil {
+			return EvaResult{
+				Code:    400,
+				Message: "计算总得分失败: " + err.Error(),
+			}
+		}
+
+		// 更新课程运行日志中的总得分
+		_, err = o.Raw(`
+			UPDATE CourseRunLog 
+			SET 课程得分 = ? 
+			WHERE 运行记录编号 = ?
+		`, totalScore, foundEvaData.RunLogID).Exec()
+
+		if err != nil {
+			return EvaResult{
+				Code:    400,
+				Message: "更新总得分失败: " + err.Error(),
+			}
+		}
+
+		// 返回成功结果
+		return EvaResult{
+			Code:        200,
+			Message:     "评价成功",
+			EvaName:     foundEvaData.EvaName,
+			IsOperated:  1,
+			OperScore:   operScore,
+			CourseScore: totalScore,
+			SeqNo:       foundEvaData.SeqNo,
+		}
+	} else {
+		// 参数不匹配
+		return EvaResult{
+			Code:        400,
+			Message:     "操作参数不匹配",
+			EvaName:     foundEvaData.EvaName,
+			IsOperated:  0,
+			OperScore:   0,
+			CourseScore: runningCourse.CourseScore,
+			SeqNo:       foundEvaData.SeqNo,
+		}
+	}
 }
 
 // /courserun/add_ctrl_log 添加电调控制日志
@@ -211,7 +410,8 @@ func (c *EDispatchController) Addctrllog() {
 		return
 	}
 
-	c.Eqpmtlist(req)
+	// 调用自动评价函数并获取评价结果
+	evaResult := c.DoAutoEva(req)
 
 	// 获取数据库连接
 	o := orm.NewOrm()
@@ -301,9 +501,16 @@ func (c *EDispatchController) Addctrllog() {
 		return
 	}
 
+	// 返回包含评价结果的信息
 	c.Data["json"] = map[string]interface{}{
-		"code": 200,
-		"msg":  "添加操作日志成功",
+		"code":        evaResult.Code,
+		"msg":         "添加操作日志成功",
+		"evaMessage":  evaResult.Message,
+		"evaName":     evaResult.EvaName,
+		"isOperated":  evaResult.IsOperated,
+		"operScore":   evaResult.OperScore,
+		"courseScore": evaResult.CourseScore,
+		"seqNo":       evaResult.SeqNo,
 	}
 	c.ServeJSON()
 }

+ 47 - 0
Tech/自动评价流程图.md

@@ -0,0 +1,47 @@
+# 自动评价流程图(简化版)
+
+```mermaid
+flowchart TD
+    A[开始] --> B[查找正在运行的课程]
+    B --> C[获取评价数据]
+    C --> D[查找第一个未操作的记录]
+    D --> E{参数是否匹配?}
+    E -->|否| F[返回参数不匹配]
+    E -->|是| G[计算操作时间和得分]
+    G --> H[更新评价记录]
+    H --> I[更新课程总分]
+    I --> J[返回评价结果]
+    F --> K[结束]
+    J --> K
+```
+
+## 简化流程说明
+
+1. **查找正在运行的课程**
+   - 获取当前CourseTime=0的课程
+
+2. **获取评价数据**
+   - 查询该课程的客观评价数据(EvaType=1)
+   - 按序号排序
+
+3. **查找第一个未操作的记录**
+   - 找到IsOperated=0的第一个记录
+
+4. **参数匹配检查**
+   - 比较请求参数Param1和TextParam1
+   - 比较请求参数Param2和TextParam2
+
+5. **计算操作时间和得分**
+   - 计算从课程开始到现在的操作时间
+   - 计算操作得分:得分 = 评价赋分 - 评价失分
+
+6. **更新评价记录**
+   - 标记为已操作(IsOperated=1)
+   - 更新操作得分和时间
+
+7. **更新课程总分**
+   - 重新计算所有已操作项的总分
+   - 更新课程的总得分
+
+8. **返回评价结果**
+   - 包含操作状态、得分等信息