feat(server-go): 蚕匾/批次/饲养记录 CRUD 与权限(#7)

This commit is contained in:
weijuesen
2026-08-12 17:14:02 +08:00
parent f9d9202856
commit 362a70b8a8
5 changed files with 327 additions and 0 deletions
@@ -26,6 +26,12 @@ var AllPermissions = []PermissionDef{
{"knowledge:write", "知识库管理", "新增、编辑、删除知识库内容"},
{"inspection:create", "巡检创建", "发起 AI 拍照巡检"},
{"inspection:read", "巡检查看", "查看 AI 巡检记录"},
{"tray:read", "蚕匾查看", "查看蚕匾"},
{"tray:write", "蚕匾管理", "新增、编辑、删除蚕匾"},
{"batch:read", "批次查看", "查看蚕种批次与饲养记录"},
{"batch:write", "批次管理", "新增、编辑、删除批次"},
{"rearing:read", "饲养记录查看", "查看饲养记录"},
{"rearing:write", "饲养记录管理", "新增、编辑、删除饲养记录"},
{"user:manage", "用户管理", "管理用户、角色和权限"},
{"audit:read", "审计查看", "查看审计日志"},
}
@@ -38,6 +44,7 @@ var RolePermissionMap = map[string][]string{
"video:read", "video:record", "energy:view", "log:read",
"knowledge:read", "knowledge:write",
"inspection:create", "inspection:read",
"tray:read", "tray:write", "batch:read", "batch:write", "rearing:read", "rearing:write",
"user:manage", "audit:read",
},
RoleOperator: {
@@ -46,17 +53,20 @@ var RolePermissionMap = map[string][]string{
"video:read", "video:record", "energy:view", "log:read",
"knowledge:read", "knowledge:write",
"inspection:create", "inspection:read",
"tray:read", "tray:write", "batch:read", "batch:write", "rearing:read", "rearing:write",
},
RoleViewer: {
"dashboard:view", "room:read", "device:read",
"threshold:read", "alarm:read", "video:read", "energy:view",
"knowledge:read",
"inspection:read",
"tray:read", "batch:read", "rearing:read",
},
RoleFarmer: {
"dashboard:view", "room:read", "device:read", "device:control",
"alarm:read", "alarm:ack", "video:read", "energy:view",
"knowledge:read",
"inspection:create", "inspection:read",
"tray:read", "batch:read", "rearing:read",
},
}
+52
View File
@@ -0,0 +1,52 @@
package model
import "time"
// Tray 蚕匾
type Tray struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"size:64" json:"name"`
Code *string `gorm:"size:64" json:"code,omitempty"`
Position *string `gorm:"size:128" json:"position,omitempty"`
RoomID string `gorm:"column:room_id;type:uuid;index" json:"roomId"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
}
func (Tray) TableName() string { return "trays" }
// Batch 蚕种批次
type Batch struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
RoomID string `gorm:"column:room_id;type:uuid;index" json:"roomId"`
Name string `gorm:"size:64" json:"name"`
Variety *string `gorm:"size:64" json:"variety,omitempty"` // 品种
Source *string `gorm:"size:128" json:"source,omitempty"` // 蚕种来源/供应商
SeedBatchNo *string `gorm:"column:seed_batch_no;size:64" json:"seedBatchNo,omitempty"` // 蚕种批次号
QuarantineNo *string `gorm:"column:quarantine_no;size:64" json:"quarantineNo,omitempty"` // 检疫证明编号
Instar *int `gorm:"type:int" json:"instar,omitempty"` // 龄期 1-5
EnteredAt *time.Time `gorm:"column:entered_at;type:timestamptz" json:"enteredAt,omitempty"` // 入房时间
MountAt *time.Time `gorm:"column:mount_at;type:timestamptz" json:"mountAt,omitempty"` // 上蔟时间
Status string `gorm:"size:16;default:rearing" json:"status"` // rearing/mounted/finished
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 (Batch) TableName() string { return "batches" }
// RearingRecord 饲养记录
type RearingRecord struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
BatchID string `gorm:"column:batch_id;type:uuid;index" json:"batchId"`
RecordDate time.Time `gorm:"column:record_date;type:timestamptz" json:"recordDate"`
Instar *int `gorm:"type:int" json:"instar,omitempty"`
MulberrySource *string `gorm:"column:mulberry_source;size:128" json:"mulberrySource,omitempty"` // 桑叶来源
Density *string `gorm:"size:64" json:"density,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 (RearingRecord) TableName() string { return "rearing_records" }