feat: 植物识别百科ai助手迁移
This commit is contained in:
@@ -57,19 +57,29 @@ func (l *AddCareRecordLogic) AddCareRecord(in *plant.AddCareRecordReq) (*plant.C
|
||||
|
||||
// 4. 生成下一期任务(以今天为基准,+period 天)
|
||||
nextDue := time.Now().Truncate(24*time.Hour).AddDate(0, 0, plan.Period)
|
||||
nextTask := plantModel.CareTask{
|
||||
UserID: in.UserId,
|
||||
PlantID: in.PlantId,
|
||||
PlanID: in.PlanId,
|
||||
Name: plan.Name,
|
||||
Icon: plan.Icon,
|
||||
TargetAction: plan.TargetAction,
|
||||
DueDate: nextDue,
|
||||
Status: 1,
|
||||
}
|
||||
if err := tx.Create(&nextTask).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 {
|
||||
nextTask := plantModel.CareTask{
|
||||
UserID: in.UserId,
|
||||
PlantID: in.PlantId,
|
||||
PlanID: in.PlanId,
|
||||
Name: plan.Name,
|
||||
Icon: plan.Icon,
|
||||
TargetAction: plan.TargetAction,
|
||||
DueDate: nextDue,
|
||||
Status: 1,
|
||||
}
|
||||
if err := tx.Create(&nextTask).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 更新用户 care_count 统计
|
||||
actionMap := map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user