feat: 植物识别百科ai助手迁移

This commit is contained in:
Blizzard
2026-05-24 01:41:22 +08:00
parent ae6d03d351
commit 076ed1509b
29 changed files with 1121 additions and 372 deletions
@@ -51,14 +51,24 @@ func (l *CompleteTaskLogic) CompleteTask(in *plant.CompleteTaskReq) (*plant.Task
today := time.Now()
todayZero := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
nextDue := todayZero.AddDate(0, 0, plan.Period)
newTask := plantModel.CareTask{
UserID: plan.UserID, PlantID: plan.PlantID, PlanID: plan.ID,
Name: plan.Name, Icon: plan.Icon, TargetAction: plan.TargetAction,
DueDate: nextDue, Status: 1,
}
if err := tx.Create(&newTask).Error; err != nil {
// 检查是否已经存在该计划的待办任务,避免重复生成相同事项的多个待办任务
var activeCount int64
if err := tx.Model(&plantModel.CareTask{}).
Where("plan_id = ? AND status = 1", plan.ID).
Count(&activeCount).Error; err != nil {
return err
}
if activeCount == 0 {
newTask := plantModel.CareTask{
UserID: plan.UserID, PlantID: plan.PlantID, PlanID: plan.ID,
Name: plan.Name, Icon: plan.Icon, TargetAction: plan.TargetAction,
DueDate: nextDue, Status: 1,
}
if err := tx.Create(&newTask).Error; err != nil {
return err
}
}
// 4. 保存养护记录
record := plantModel.CareRecord{
UserID: plan.UserID, PlantID: plan.PlantID, PlanID: plan.ID,