feat: 完善环境规则、会诊治理、知识审核与效果评估

This commit is contained in:
weijuesen
2026-08-14 10:33:17 +08:00
parent 69ef5a0704
commit 126c215a6b
27 changed files with 963 additions and 88 deletions
+49
View File
@@ -80,6 +80,15 @@ func listDiseases(db *gorm.DB) gin.HandlerFunc {
if enabled := c.Query("enabled"); enabled != "" {
q = q.Where("enabled = ?", enabled == "true")
}
if status := c.Query("status"); status != "" {
if !canReviewKnowledge(c) {
c.JSON(http.StatusForbidden, gin.H{"error": "无权限查看未发布内容"})
return
}
q = q.Where("status = ?", status)
} else {
q = q.Where("status = 'published'")
}
var list []model.Disease
q.Order("sort_order ASC, name ASC").Find(&list)
c.JSON(http.StatusOK, list)
@@ -94,6 +103,10 @@ func getDisease(db *gorm.DB) gin.HandlerFunc {
c.JSON(http.StatusNotFound, gin.H{"error": "disease not found"})
return
}
if d.Status != "published" && !canReviewKnowledge(c) {
c.JSON(http.StatusNotFound, gin.H{"error": "disease not found"})
return
}
c.JSON(http.StatusOK, d)
}
}
@@ -107,6 +120,7 @@ func createDisease(db *gorm.DB) gin.HandlerFunc {
return
}
d.ID = ""
d.Status = "draft"
if d.Name == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "病种名称不能为空"})
return
@@ -134,6 +148,10 @@ func updateDisease(db *gorm.DB) gin.HandlerFunc {
return
}
if len(updates) > 0 {
if status, ok := updates["status"].(string); ok && !model.ValidKnowledgeTransition(d.Status, status) {
c.JSON(http.StatusBadRequest, gin.H{"error": "非法的知识状态流转"})
return
}
db.Model(&model.Disease{}).Where("id = ?", id).Updates(updates)
}
db.Where("id = ?", id).First(&d)
@@ -165,6 +183,15 @@ func listArticles(db *gorm.DB) gin.HandlerFunc {
if enabled := c.Query("enabled"); enabled != "" {
q = q.Where("enabled = ?", enabled == "true")
}
if status := c.Query("status"); status != "" {
if !canReviewKnowledge(c) {
c.JSON(http.StatusForbidden, gin.H{"error": "无权限查看未发布内容"})
return
}
q = q.Where("status = ?", status)
} else {
q = q.Where("status = 'published'")
}
var list []model.KnowledgeArticle
q.Order("sort_order ASC, created_at DESC").Find(&list)
c.JSON(http.StatusOK, list)
@@ -179,6 +206,10 @@ func getArticle(db *gorm.DB) gin.HandlerFunc {
c.JSON(http.StatusNotFound, gin.H{"error": "article not found"})
return
}
if a.Status != "published" && !canReviewKnowledge(c) {
c.JSON(http.StatusNotFound, gin.H{"error": "article not found"})
return
}
c.JSON(http.StatusOK, a)
}
}
@@ -192,6 +223,7 @@ func createArticle(db *gorm.DB) gin.HandlerFunc {
return
}
a.ID = ""
a.Status = "draft"
if a.Kind == "" || a.Title == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "文章类型和标题不能为空"})
return
@@ -219,6 +251,10 @@ func updateArticle(db *gorm.DB) gin.HandlerFunc {
return
}
if len(updates) > 0 {
if status, ok := updates["status"].(string); ok && !model.ValidKnowledgeTransition(a.Status, status) {
c.JSON(http.StatusBadRequest, gin.H{"error": "非法的知识状态流转"})
return
}
db.Model(&model.KnowledgeArticle{}).Where("id = ?", id).Updates(updates)
}
db.Where("id = ?", id).First(&a)
@@ -226,6 +262,19 @@ func updateArticle(db *gorm.DB) gin.HandlerFunc {
}
}
func canReviewKnowledge(c *gin.Context) bool {
user, ok := c.Get("user")
if !ok {
return false
}
m, ok := user.(map[string]interface{})
if !ok {
return false
}
role, _ := m["role"].(string)
return role == "admin" || role == "operator"
}
// deleteArticle 删除知识文章
func deleteArticle(db *gorm.DB) gin.HandlerFunc {
return func(c *gin.Context) {