add New Model About Animal
This commit is contained in:
parent
d935a473e7
commit
48564dab02
@ -18,6 +18,8 @@ type Animal struct {
|
|||||||
Gender uint8 `json:"gender,omitempty"` // 性别
|
Gender uint8 `json:"gender,omitempty"` // 性别
|
||||||
Breed uint8 `json:"breed,omitempty"` // 品种
|
Breed uint8 `json:"breed,omitempty"` // 品种
|
||||||
Sterilization uint8 `json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育
|
Sterilization uint8 `json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育
|
||||||
|
Vaccination uint8 `json:"vaccination,omitempty"` // 免疫状态
|
||||||
|
Deworming uint8 `json:"deworming,omitempty"` // 驱虫状态
|
||||||
NickNames string `gorm:"type:varchar(31)" json:"nick_names,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适
|
NickNames string `gorm:"type:varchar(31)" json:"nick_names,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适
|
||||||
Status uint8 `json:"status,omitempty"` // 状态
|
Status uint8 `json:"status,omitempty"` // 状态
|
||||||
Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍
|
Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍
|
||||||
|
@ -19,3 +19,11 @@ type AnmStatus struct {
|
|||||||
type AnmGender struct {
|
type AnmGender struct {
|
||||||
BriefModel
|
BriefModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AnmVaccination struct {
|
||||||
|
BriefModel
|
||||||
|
}
|
||||||
|
|
||||||
|
type AnmDeworming struct {
|
||||||
|
BriefModel
|
||||||
|
}
|
||||||
|
@ -14,7 +14,8 @@ var DB *gorm.DB // 这种写法是方柏包外使用
|
|||||||
|
|
||||||
// 自动迁移表
|
// 自动迁移表
|
||||||
func autoMigrateTable() {
|
func autoMigrateTable() {
|
||||||
err := DB.AutoMigrate(&model.Animal{}, &model.AnmBreed{}, &model.AnmSterilzation{}, &model.AnmStatus{}, &model.AnmGender{})
|
err := DB.AutoMigrate(&model.Animal{}, &model.AnmBreed{}, &model.AnmSterilzation{}, &model.AnmStatus{}, &model.AnmGender{},
|
||||||
|
&model.AnmVaccination{}, &model.AnmDeworming{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("autoMigrateTable error:", err)
|
fmt.Println("autoMigrateTable error:", err)
|
||||||
}
|
}
|
||||||
@ -99,24 +100,70 @@ func testInsertStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testInsertVaccination() {
|
||||||
|
// 定义状态数据
|
||||||
|
vaccinationsZH := []string{"不明", "未接种", "部分接种", "完全接种"}
|
||||||
|
vaccinationsEN := []string{"unknown", "unvaccinated", "partially_vaccinated", "fully_vaccinated"}
|
||||||
|
|
||||||
|
for i := 0; i < len(vaccinationsZH); i++ {
|
||||||
|
vaccination := model.AnmVaccination{
|
||||||
|
BriefModel: model.BriefModel{
|
||||||
|
NameZh: vaccinationsZH[i],
|
||||||
|
NameEn: vaccinationsEN[i],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := DB.Create(&vaccination)
|
||||||
|
if tx.Error != nil {
|
||||||
|
fmt.Println("insert vaccination error:", tx.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInsertDeworming() {
|
||||||
|
// 定义状态数据
|
||||||
|
dewormingZH := []string{"不明", "未驱虫", "已驱虫"}
|
||||||
|
dewormingEN := []string{"unknown", "undewormed", "dewormed"}
|
||||||
|
|
||||||
|
for i := 0; i < len(dewormingZH); i++ {
|
||||||
|
deworming := model.AnmDeworming{
|
||||||
|
BriefModel: model.BriefModel{
|
||||||
|
NameZh: dewormingZH[i],
|
||||||
|
NameEn: dewormingEN[i],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := DB.Create(&deworming)
|
||||||
|
if tx.Error != nil {
|
||||||
|
fmt.Println("insert vaccination error:", tx.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func insertData() {
|
func insertData() {
|
||||||
// testInsertSterilzation()
|
// testInsertSterilzation()
|
||||||
// fmt.Println("testInsertSterilzation success.")
|
// fmt.Println("testInsertSterilzation success.")
|
||||||
|
|
||||||
testInsertBreed()
|
// testInsertBreed()
|
||||||
fmt.Println("testInsertBreed success.")
|
// fmt.Println("testInsertBreed success.")
|
||||||
|
|
||||||
// testInsertStatus()
|
// testInsertStatus()
|
||||||
// fmt.Println("testInsertStatus success.")
|
// fmt.Println("testInsertStatus success.")
|
||||||
|
|
||||||
// testInsertAnmGender()
|
// testInsertAnmGender()
|
||||||
// fmt.Println("testInsertAnmGender success.")
|
// fmt.Println("testInsertAnmGender success.")
|
||||||
|
|
||||||
|
testInsertVaccination()
|
||||||
|
fmt.Println("testInsertVaccination success.")
|
||||||
|
|
||||||
|
testInsertDeworming()
|
||||||
|
fmt.Println("testInsertDeworming success.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 1.
|
// 1.
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
|
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
|
||||||
"root", "Havocantelope412#", "113.44.68.213", "3306", "hav_cats") // danger MySQL
|
"root", "Havocantelope412#", "113.44.68.213", "3306", "hav_cats") // ATT MySQL
|
||||||
fmt.Println("dsn:", dsn)
|
fmt.Println("dsn:", dsn)
|
||||||
dbMySQL, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
dbMySQL, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user