feat: Add callback and exchange features, refactor care plan task generation logic, and update wiki ordering to prioritize hot items.
This commit is contained in:
@@ -2,9 +2,6 @@ package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/utils/timer"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CarePlan 养护计划
|
||||
@@ -19,28 +16,28 @@ type CarePlan struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user