feat: 完善环境规则、会诊治理、知识审核与效果评估
This commit is contained in:
@@ -24,6 +24,9 @@ func RegisterHealthProfileRoutes(rg *gin.RouterGroup, db *gorm.DB) {
|
||||
rg.GET("/health-profiles/:roomId",
|
||||
middleware.RequirePermission(db, "room:read"),
|
||||
roomHealthProfile(db))
|
||||
rg.GET("/health-profiles/:roomId/effect",
|
||||
middleware.RequirePermission(db, "room:read"),
|
||||
roomEffectReport(db))
|
||||
}
|
||||
|
||||
// roomHealthProfile 单蚕房健康画像:巡检风险/检测结果/事件聚合 → 综合健康分
|
||||
@@ -99,3 +102,54 @@ func roomHealthProfile(db *gorm.DB) gin.HandlerFunc {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// roomEffectReport 处置前后窗口效果报告。
|
||||
func roomEffectReport(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
roomID := c.Param("roomId")
|
||||
now := time.Now()
|
||||
parse := func(key string, fallback time.Time) time.Time {
|
||||
raw := c.Query(key)
|
||||
if raw == "" {
|
||||
return fallback
|
||||
}
|
||||
t, err := time.Parse(time.RFC3339, raw)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return t
|
||||
}
|
||||
window := service.EffectWindow{
|
||||
BeforeStart: parse("beforeStart", now.Add(-60*24*time.Hour)),
|
||||
BeforeEnd: parse("beforeEnd", now.Add(-30*24*time.Hour)),
|
||||
AfterStart: parse("afterStart", now.Add(-30*24*time.Hour)),
|
||||
AfterEnd: parse("afterEnd", now),
|
||||
}
|
||||
before, after := service.EffectMetrics{}, service.EffectMetrics{}
|
||||
loadEffectMetrics := func(start, end time.Time) service.EffectMetrics {
|
||||
metrics := service.EffectMetrics{}
|
||||
db.Table("inspection_records").
|
||||
Where("room_id = ? AND ai_status = 'done' AND COALESCE(is_mock, false) = false AND risk_score IS NOT NULL AND created_at >= ? AND created_at < ?", roomID, start, end).
|
||||
Pluck("risk_score", &metrics.RiskSamples)
|
||||
var lampTotal int64
|
||||
db.Model(&model.LampTest{}).
|
||||
Where("room_id = ? AND status = 'resulted' AND created_at >= ? AND created_at < ?", roomID, start, end).
|
||||
Count(&lampTotal)
|
||||
metrics.LampTotal = int(lampTotal)
|
||||
var lampPositive int64
|
||||
db.Model(&model.LampTest{}).
|
||||
Where("room_id = ? AND status = 'resulted' AND result = 'positive' AND created_at >= ? AND created_at < ?", roomID, start, end).
|
||||
Count(&lampPositive)
|
||||
metrics.LampPositive = int(lampPositive)
|
||||
return metrics
|
||||
}
|
||||
before = loadEffectMetrics(window.BeforeStart, window.BeforeEnd)
|
||||
after = loadEffectMetrics(window.AfterStart, window.AfterEnd)
|
||||
var recurrences int64
|
||||
db.Model(&model.DiseaseEvent{}).
|
||||
Where("room_id = ? AND status = 'reopened' AND created_at >= ? AND created_at < ?", roomID, window.AfterStart, window.AfterEnd).
|
||||
Count(&recurrences)
|
||||
after.Recurrences = int(recurrences)
|
||||
c.JSON(http.StatusOK, service.EvaluateControlEffect(roomID, window, before, after))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user