feat(server-go): LAMP 检测管理(任务单/步骤/结果录入/结果图片,#14)

This commit is contained in:
weijuesen
2026-08-12 17:48:46 +08:00
parent 713d34a3b5
commit c6e5a76e71
6 changed files with 331 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
package model
import (
"encoding/json"
"time"
)
// LampTest LAMP 检测任务单
type LampTest struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
RoomID *string `gorm:"column:room_id;type:uuid;index" json:"roomId,omitempty"`
BatchID *string `gorm:"column:batch_id;type:uuid;index" json:"batchId,omitempty"`
Diseases json.RawMessage `gorm:"type:jsonb" json:"diseases,omitempty"`
Status string `gorm:"size:16;default:pending" json:"status"` // pending/testing/resulted
SampleInfo *string `gorm:"column:sample_info;size:255" json:"sampleInfo,omitempty"`
Result *string `gorm:"size:16" json:"result,omitempty"` // positive/negative/invalid
ResultImageURL *string `gorm:"column:result_image_url;size:512" json:"resultImageUrl,omitempty"`
OperatorID *string `gorm:"column:operator_id;type:uuid" json:"operatorId,omitempty"`
ResultedAt *time.Time `gorm:"column:resulted_at;type:timestamptz" json:"resultedAt,omitempty"`
Note *string `gorm:"type:text" json:"note,omitempty"`
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
}
func (LampTest) TableName() string { return "lamp_tests" }
// LampTestStep LAMP 检测步骤
type LampTestStep struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
LampTestID string `gorm:"column:lamp_test_id;type:uuid;index" json:"lampTestId"`
StepNo int `gorm:"column:step_no;type:int" json:"stepNo"`
Name string `gorm:"size:64" json:"name"`
Done bool `gorm:"default:false" json:"done"`
DoneAt *time.Time `gorm:"column:done_at;type:timestamptz" json:"doneAt,omitempty"`
Note *string `gorm:"type:text" json:"note,omitempty"`
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
}
func (LampTestStep) TableName() string { return "lamp_test_steps" }
// DefaultLampSteps LAMP 标准 5 步流程(规格书 3.3.2.1)
func DefaultLampSteps() []string {
return []string{"采样", "DNA提取", "反应体系配制", "恒温反应", "结果判读"}
}
// ValidLampResult 校验 LAMP 结果枚举
func ValidLampResult(result string) bool {
switch result {
case "positive", "negative", "invalid":
return true
default:
return false
}
}
@@ -0,0 +1,30 @@
package model
import "testing"
func TestDefaultLampSteps(t *testing.T) {
steps := DefaultLampSteps()
want := []string{"采样", "DNA提取", "反应体系配制", "恒温反应", "结果判读"}
if len(steps) != len(want) {
t.Fatalf("步骤数 = %d, want %d", len(steps), len(want))
}
for i, name := range want {
if steps[i] != name {
t.Errorf("步骤 %d = %s, want %s", i+1, steps[i], name)
}
}
}
func TestValidLampResult(t *testing.T) {
for _, r := range []string{"positive", "negative", "invalid"} {
if !ValidLampResult(r) {
t.Errorf("%s 应为合法结果", r)
}
}
if ValidLampResult("unknown") {
t.Error("unknown 不应为合法结果")
}
if ValidLampResult("") {
t.Error("空结果不应为合法结果")
}
}
@@ -35,6 +35,8 @@ var AllPermissions = []PermissionDef{
{"notification:read", "订阅查看", "查看微信订阅绑定状态"},
{"notification:write", "订阅管理", "绑定微信并管理订阅授权"},
{"weather:read", "天气查看", "查看天气与高发病天气预警"},
{"lamp:read", "LAMP 检测查看", "查看 LAMP 检测任务单与结果"},
{"lamp:write", "LAMP 检测管理", "新建、编辑、录入 LAMP 检测结果"},
{"user:manage", "用户管理", "管理用户、角色和权限"},
{"audit:read", "审计查看", "查看审计日志"},
}
@@ -50,6 +52,7 @@ var RolePermissionMap = map[string][]string{
"tray:read", "tray:write", "batch:read", "batch:write", "rearing:read", "rearing:write",
"notification:read", "notification:write",
"weather:read",
"lamp:read", "lamp:write",
"user:manage", "audit:read",
},
RoleOperator: {
@@ -61,6 +64,7 @@ var RolePermissionMap = map[string][]string{
"tray:read", "tray:write", "batch:read", "batch:write", "rearing:read", "rearing:write",
"notification:read", "notification:write",
"weather:read",
"lamp:read", "lamp:write",
},
RoleViewer: {
"dashboard:view", "room:read", "device:read",
@@ -70,6 +74,7 @@ var RolePermissionMap = map[string][]string{
"tray:read", "batch:read", "rearing:read",
"notification:read",
"weather:read",
"lamp:read",
},
RoleFarmer: {
"dashboard:view", "room:read", "device:read", "device:control",
@@ -79,5 +84,6 @@ var RolePermissionMap = map[string][]string{
"tray:read", "batch:read", "rearing:read",
"notification:read", "notification:write",
"weather:read",
"lamp:read",
},
}