44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
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:"index;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:周期"`
|
|
TargetAction string `gorm:"type:varchar(32);index;not null;column:target_action;comment:触发动作代码" json:"targetAction"`
|
|
}
|
|
|
|
// AfterUpdate 钩子函数 修改计划后重新生成任务
|
|
// func (p *CarePlan) AfterUpdate(tx *gorm.DB) error {
|
|
// //1.删除旧任务
|
|
// err := tx.Where("plan_id = ?", p.Id).Unscoped().Delete(&CareTask{}).Error
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// //2.创建新任务
|
|
// today := timer.GetZeroTime()
|
|
// dueDate := today.AddDate(0, 0, p.Period)
|
|
// task := CareTask{
|
|
// UserId: p.UserId,
|
|
// PlantId: p.Id,
|
|
// PlanId: p.Id,
|
|
// Name: p.Name,
|
|
// Icon: p.Icon,
|
|
// DueDate: dueDate,
|
|
// Status: 1,
|
|
// }
|
|
// err = tx.Create(&task).Error
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// return nil
|
|
|
|
// }
|