feat(web/server-go): 技术员巡检记录页(#17,列表+详情+roomName)
This commit is contained in:
@@ -226,6 +226,20 @@ func listInspections(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
var list []model.InspectionRecord
|
||||
q.Order("created_at DESC").Limit(limit).Find(&list)
|
||||
// 联查蚕房名(非持久化字段)
|
||||
var rooms []model.Room
|
||||
db.Select("id", "name").Find(&rooms)
|
||||
roomNames := make(map[string]string, len(rooms))
|
||||
for _, r := range rooms {
|
||||
roomNames[r.ID] = r.Name
|
||||
}
|
||||
for i := range list {
|
||||
if list[i].RoomID != nil {
|
||||
if n, ok := roomNames[*list[i].RoomID]; ok {
|
||||
list[i].RoomName = &n
|
||||
}
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, list)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ type InspectionRecord struct {
|
||||
IdempotencyKey *string `gorm:"column:idempotency_key;size:128;uniqueIndex" json:"idempotencyKey,omitempty"`
|
||||
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
|
||||
RoomName *string `gorm:"-" json:"roomName,omitempty"`
|
||||
}
|
||||
|
||||
func (InspectionRecord) TableName() string { return "inspection_records" }
|
||||
|
||||
Reference in New Issue
Block a user