feat: 完善环境规则、会诊治理、知识审核与效果评估
This commit is contained in:
@@ -71,10 +71,10 @@ func getConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
func createConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var body struct {
|
||||
Title string `json:"title"`
|
||||
Summary *string `json:"summary"`
|
||||
RoomID *string `json:"roomId"`
|
||||
BatchID *string `json:"batchId"`
|
||||
Title string `json:"title"`
|
||||
Summary *string `json:"summary"`
|
||||
RoomID *string `json:"roomId"`
|
||||
BatchID *string `json:"batchId"`
|
||||
LampTestID *string `json:"lampTestId"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
@@ -93,7 +93,7 @@ func createConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
BatchID: body.BatchID,
|
||||
LampTestID: body.LampTestID,
|
||||
Summary: body.Summary,
|
||||
Status: "pending",
|
||||
Status: "unassigned",
|
||||
}
|
||||
if body.Title != "" {
|
||||
rec.Title = body.Title
|
||||
@@ -183,6 +183,16 @@ func updateConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "非法的会诊状态流转"})
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
switch to {
|
||||
case "assigned":
|
||||
updates["assigned_at"] = now
|
||||
updates["sla_deadline"] = now.Add(24 * time.Hour)
|
||||
case "accepted":
|
||||
updates["accepted_at"] = now
|
||||
case "needs_info":
|
||||
updates["needs_info_at"] = now
|
||||
}
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
db.Model(&model.Consultation{}).Where("id = ?", id).Updates(updates)
|
||||
@@ -208,6 +218,7 @@ func resolveConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
var body struct {
|
||||
Opinion string `json:"opinion"`
|
||||
Plan string `json:"plan"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -218,19 +229,44 @@ func resolveConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
authorID := currentUserID(c)
|
||||
updates := map[string]interface{}{
|
||||
"status": "resolved",
|
||||
"expert_id": currentUserID(c),
|
||||
"expert_id": authorID,
|
||||
"opinion": body.Opinion,
|
||||
"plan": body.Plan,
|
||||
"resolved_at": now,
|
||||
}
|
||||
db.Model(&model.Consultation{}).Where("id = ?", id).Updates(updates)
|
||||
var versionCount int64
|
||||
db.Model(&model.ConsultationOpinionVersion{}).Where("consultation_id = ?", id).Count(&versionCount)
|
||||
version := int(versionCount) + 1
|
||||
if err := db.Create(&model.ConsultationOpinionVersion{
|
||||
ConsultationID: id,
|
||||
Version: version,
|
||||
AuthorID: authorID,
|
||||
Opinion: body.Opinion,
|
||||
Plan: body.Plan,
|
||||
Reason: consultationStrPtr(body.Reason),
|
||||
}).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "保存意见版本失败"})
|
||||
return
|
||||
}
|
||||
if err := db.Model(&model.Consultation{}).Where("id = ?", id).Updates(updates).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "保存会诊方案失败"})
|
||||
return
|
||||
}
|
||||
db.Where("id = ?", id).First(&t)
|
||||
c.JSON(http.StatusOK, t)
|
||||
}
|
||||
}
|
||||
|
||||
func consultationStrPtr(value string) *string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
|
||||
// archiveConsultation 归档
|
||||
func archiveConsultation(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user