diff --git a/app/model/animal.go b/app/model/animal.go index a69a642..d8b9656 100644 --- a/app/model/animal.go +++ b/app/model/animal.go @@ -12,24 +12,29 @@ func CreateAnimalFactory(sqlType string) *Animal { } type Animal struct { - BaseModel // 假设 BaseModel 中不需要添加 omitempty 标签 - Name string `gorm:"type:varchar(20)" json:"name,omitempty"` // 名称 - Birthday string `json:"birthday,omitempty"` // 生日 - Gender uint8 `json:"gender,omitempty"` // 性别 - Breed uint8 `json:"breed,omitempty"` // 品种 - Sterilization uint8 `json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育 - NickName string `gorm:"type:varchar(31)" json:"nick_name,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适 - Status uint8 `json:"status,omitempty"` // 状态 - Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍 - Avatar string `gorm:"type:varchar(10)" json:"avatar,omitempty"` // 缩略图 url,为 Go 获取 Photo 之后压缩处理后的图像,单独存储。 - AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 - AvatarWidth uint16 `json:"avatar_width,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 - HeadImg string `gorm:"type:varchar(10)" json:"head_img,omitempty"` // Head 默认处理为正方形。 - Photos string `gorm:"type:varchar(100)" json:"photos,omitempty"` // 图片数组 - Latitude float64 `json:"latitude,omitempty"` // POI 位置相关 - Longitude float64 `json:"longitude,omitempty"` // POI 位置相关 - ActivityRadius uint64 `json:"activity_radius,omitempty"` - Tags string `json:"tags,omitempty"` // 活动半径 + BaseModel // 假设 BaseModel 中不需要添加 omitempty 标签 + Name string `gorm:"type:varchar(20)" json:"name,omitempty"` // 名称 + Birthday string `json:"birthday,omitempty"` // 生日 + Gender uint8 `json:"gender,omitempty"` // 性别 + Breed uint8 `json:"breed,omitempty"` // 品种 + Sterilization uint8 `json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育 + NickName string `gorm:"type:varchar(31)" json:"nick_name,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适 + Status uint8 `json:"status,omitempty"` // 状态 + Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍 + Tags string `json:"tags,omitempty"` + // TAG imaegs + Avatar string `gorm:"type:varchar(10)" json:"avatar,omitempty"` // 缩略图 url,为 Go 获取 Photo 之后压缩处理后的图像,单独存储。 + AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 // INFO 暂时没用到 + AvatarWidth uint16 `json:"avatar_width,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 + HeadImg string `gorm:"type:varchar(10)" json:"head_img,omitempty"` // Head 默认处理为正方形。 + Photos string `gorm:"type:varchar(100)" json:"photos,omitempty"` // 图片数组 + // TAG POI + Latitude float64 `json:"latitude,omitempty"` // POI 位置相关 + Longitude float64 `json:"longitude,omitempty"` // POI 位置相关 + ActivityRadius uint64 `json:"activity_radius,omitempty"` // 活动半径 + // CatFace + FaceBreeds string `json:"face_breeds,omitempty" gorm:"size:20"` + FaceBreedProbs string `json:"face_breed_probs" gorm:"size:20"` } func (a *Animal) TableName() string { diff --git a/app/model/animal_face_breed.go b/app/model/animal_face_breed.go deleted file mode 100644 index 1598b17..0000000 --- a/app/model/animal_face_breed.go +++ /dev/null @@ -1,20 +0,0 @@ -package model - -// INFO 写在前面:实际上这个模块是 CatFace 子模块在维护,所以对应的 curd 都交给 python 了。 - -/** - * @description: 保留 Top 3, 辅助 catface - breed 子模型判断; 单独建表,因为只会被 CatFace 模块使用。 - * @return {*} - */ -type AnmFaceBreed struct { // TODO 迁移 python 的时候再考虑一下细节 - BaseModel - Top1 uint8 - Prob1 float64 - Top2 uint8 - Prob2 float64 - Top3 uint8 - Prob3 float64 - - AnimalId int64 `gorm:"index;column:animal_id"` // INFO 外键设定? - Animal Animal -} diff --git a/app/model/migrate/AutoMigrate.go b/app/model/migrate/AutoMigrate.go index ae7ab00..3d77dac 100644 --- a/app/model/migrate/AutoMigrate.go +++ b/app/model/migrate/AutoMigrate.go @@ -40,8 +40,12 @@ func testInsertSterilzation() { func testInsertBreed() { // INFO 为方便之后扩展,将 unknown 默认为 1 - colorsZH := []string{"不明", "橘白", "奶牛", "白猫", "黑猫", "橘猫", "狸花", "狸白", "简州", "三花", "彩狸"} - colorsEN := []string{"unknown", "orange", "cow", "white", "black", "orangeCat", "tabby", "tabbyWhite", "jianzhong", "threeColor", "colorCat"} + colorsZH := []string{ + "不明", "橘白", "奶牛", "白猫", "黑猫", "橘猫", "狸花", "狸白", "三花", "玳瑁", "简州", "彩狸", + } + colorsEN := []string{ + "unknown", "orgwhite", "milk", "white", "black", "orange", "li", "liwhite", "flower", "tortoiseshell", "jianzhou", "color", + } for i := 0; i < len(colorsZH); i++ { breed := model.AnmBreed{ BriefModel: model.BriefModel{ @@ -96,8 +100,8 @@ func testInsertStatus() { } func insertData() { - testInsertSterilzation() - fmt.Println("testInsertSterilzation success.") + // testInsertSterilzation() + // fmt.Println("testInsertSterilzation success.") testInsertBreed() fmt.Println("testInsertBreed success.") @@ -123,5 +127,5 @@ func main() { autoMigrateTable() fmt.Println("autoMigrateTable over.") - // insertData() // INFO 记得用完注释掉 + insertData() // INFO 记得用完注释掉 } diff --git a/test/animal_face_breed_test.go b/test/animal_face_breed_test.go deleted file mode 100644 index 4b1b148..0000000 --- a/test/animal_face_breed_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package test - -import ( - "catface/app/model" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestAnmFaceBreed(t *testing.T) { - Init() - - err := DB.AutoMigrate(&model.AnmFaceBreed{}) - if err != nil { - t.Error(err) - } - - // // INFO 查询表上的所有索引 - // var indexes []struct { - // IndexName string - // ColumnName string - // } - // DB.Raw(`SELECT INDEX_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?`, "Hav'sCats", "anm_face_breeds").Scan(&indexes) - // fmt.Println("All Indexes:", len(indexes)) // QUESTION 输出 0 ? - // for _, index := range indexes { - // fmt.Printf("Index Name: %s, Column Name: %s\n", index.IndexName, index.ColumnName) - // } - - animalFaceBreed := model.AnmFaceBreed{ - AnimalId: 1, - Top1: 3, - Prob1: 0.9, - Top2: 4, - Prob2: 0.05, - Top3: 5, - Prob3: 0.05, - } - - // res := DB.Create(&animalFaceBreed) - // assert.Nil(t, res.Error) - - // 可以进一步检查数据是否正确插入,例如通过查询数据库来验证 - var temp model.AnmFaceBreed - result := DB.First(&temp, 1) //animalFaceBreed.BaseModel.Id) // ATT 这里用 Id 直接去拿到默认值 0 - assert.Nil(t, result.Error) - assert.Equal(t, animalFaceBreed.Top1, temp.Top1) -}