init: initial commit

This commit is contained in:
Blizzard
2026-02-06 14:44:06 +08:00
commit 3115b58cb2
133 changed files with 25889 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
package plant
import (
"sundynix-go/global"
"sundynix-go/model/system"
"sundynix-go/utils/timer"
"time"
"gorm.io/gorm"
)
// MyPlant 我的植物
type MyPlant struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
Name string `json:"name" form:"name" gorm:"size:20;column:name;comment:名称"`
PlantTime time.Time `json:"plantTime" form:"plantTime" gorm:"column:plant_time;comment:种植时间"`
Status int `json:"status" form:"status" gorm:"column:status;comment:生长状态"`
Placement string `json:"placement" form:"placement" gorm:"size:50;column:placement;comment:摆放位置"`
PotMaterial string `json:"potMaterial" form:"potMaterial" gorm:"column:pot_material;size:50;comment:花盆材质"`
PotSize string `json:"potSize" form:"potSize" gorm:"column:pot_size;size:50;comment:花盆大小"` // 花盆大小 如直径 20cm × 高度 18cm
Sunlight string `json:"sunlight" form:"sunlight" gorm:"column:sunlight;size:50;comment:光照条件"` // 如每日12小时
PlantingMaterial string `json:"plantingMaterial" form:"plantingMaterial" gorm:"column:planting_material;size:50;comment:植料"`
ImgList []*system.Oss `json:"imgList" form:"imgList" gorm:"many2many:my_plant_oss;comment:图片列表"`
CarePlans []*CarePlan `json:"carePlans" form:"carePlans" gorm:"foreignKey:PlantId;comment:养护计划"`
CareRecords []*CareRecord `json:"careRecords" form:"careRecords" gorm:"foreignKey:PlantId;comment:养护记录"`
}
// AfterCreate 钩子函数 创建plant时自动创建careTask
func (p *MyPlant) AfterCreate(tx *gorm.DB) (err error) {
today := timer.GetZeroTime()
for _, v := range p.CarePlans {
dueDate := today.AddDate(0, 0, v.Period)
task := CareTask{
UserId: p.UserId,
PlantId: p.Id,
PlanId: v.Id,
Name: v.Name,
Icon: v.Icon,
DueDate: dueDate,
Status: 1,
}
err = tx.Create(&task).Error
if err != nil {
return err
}
}
return
}
+15
View File
@@ -0,0 +1,15 @@
package plant
import (
"sundynix-go/global"
)
// CarePlan 养护计划
type CarePlan struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
PlantId string `json:"plantId" form:"plantId" gorm:"size:50;column:plant_id;comment:植物id"`
Icon string `json:"icon" form:"icon" gorm:"type:text;"`
Name string `json:"name"`
Period int `json:"period" form:"period" gorm:"column:period;comment:周期"`
}
+13
View File
@@ -0,0 +1,13 @@
package plant
import "sundynix-go/global"
type CareRecord struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
PlantId string `json:"plantId" form:"plantId" gorm:"index;size:50;column:plant_id;comment:植物id"`
PlanId string `json:"planId" form:"plantId" gorm:"index;column:plan_id;comment:计划id"`
Name string `json:"name" form:"name" gorm:"column:name"`
Remark string `json:"remark" form:"remark" gorm:"column:remark"`
Icon string `json:"icon" form:"icon" gorm:"type:text;column:icon"`
}
+18
View File
@@ -0,0 +1,18 @@
package plant
import (
"sundynix-go/global"
"time"
)
type CareTask struct {
global.BaseModel
PlantId string `json:"plantId" gorm:"index"`
PlanId string `json:"planId" gorm:"index"`
UserId string `json:"userId" gorm:"index"`
Name string `json:"name"`
Icon string `json:"icon" gorm:"type:text"`
DueDate time.Time `json:"dueDate"` // 应做时间(用于判断逾期)
CompletedAt *time.Time `json:"completedAt" gorm:"column:completed_at"` // 完成时间(为nil表示未完成)
Status int `json:"status"` // 1:待执行 2:已完成 3:已跳过
}
+36
View File
@@ -0,0 +1,36 @@
package request
type CarePlan struct {
Icon string `json:"icon"` // icon信息
Name string `json:"name"` // 农事名称
Period int `json:"period"` // 周期
}
// CreateMyPlant 创建植物
type CreateMyPlant struct {
Name string `json:"name"` // 植物名称
PlantTime string `json:"plantTime"` // 种植时间
PotMaterial string `json:"potMaterial"` //花盆材质
PotSize string `json:"potSize"` // 花盆大小 如直径 20cm × 高度 18cm
Placement string `json:"placement"` //摆放位置
Sunlight string `json:"sunlight"` //光照条件如每日12小时
PlantingMaterial string `json:"plantingMaterial"` //植料(即土的材质)
OssIds []string `json:"ossIds"` // 图片ids
CarePlans []*CarePlan `json:"carePlans"` // 养护计划
}
// UpdateMyPlant 修改植物
type UpdateMyPlant struct {
Id string `json:"id" binding:"required"`
Name string `json:"name"` // 植物名称
PotMaterial string `json:"potMaterial"` // 花盆材质
PotSize string `json:"potSize"` // 花盆大小 如直径 20cm × 高度 18cm
Placement string `json:"placement"` // 摆放位置
Sunlight string `json:"sunlight"` // 光照条件如每日12小时
PlantingMaterial string `json:"plantingMaterial"` // 植料(即土的材质)
}
type CompleteTask struct {
TaskId string `json:"taskId" binding:"required"`
Remark string `json:"remark"`
}
+6
View File
@@ -0,0 +1,6 @@
package response
//type BadgeGroup struct {
// CategoryName string `json:"categoryName" comment:"分类名称"`
// BadgeList []plant.Badge `json:"badgeList"`
//}
+12
View File
@@ -0,0 +1,12 @@
package response
import (
"sundynix-go/model/plant"
)
// PlantTaskVO 植物任务
type PlantTaskVO struct {
MyPlant *plant.MyPlant
HasExpired bool `json:"hasExpired"`
Tasks []*plant.CareTask `json:"tasks"`
}
+22
View File
@@ -0,0 +1,22 @@
package response
// BaikeInfo 植物百科信息(baike_info子对象)
type BaikeInfo struct {
BaikeUrl string `json:"baike_url"` // 百度百科链接
ImageUrl string `json:"image_url"` // 植物图片链接
Description string `json:"description"` // 植物百科描述文本
}
// ResultItem 识别结果项(result数组中的单个元素)
type ResultItem struct {
Score float64 `json:"score"` // 匹配相似度得分(0-1
Name string `json:"name"` // 植物名称
BaikeInfo *BaikeInfo `json:"baike_info"` // 植物百科信息(部分结果可能无此字段,用指针避免空值解析问题)
}
// PlantRecognitionResponse 植物识别接口的HTTP响应结构体
// 字段标签仅保留 json,严格匹配返回的JSON字段名
type PlantRecognitionResponse struct {
LogId uint64 `json:"log_id"` // 识别请求日志ID(唯一标识)
Result []ResultItem `json:"result"` // 植物识别结果列表
}