feat: 迁移plant

This commit is contained in:
Blizzard
2026-05-23 13:55:05 +08:00
parent a93477ea8e
commit ae6d03d351
228 changed files with 25296 additions and 917 deletions
@@ -2,11 +2,14 @@ package logic
import (
"context"
"time"
plantModel "sundynix-micro-go/app/plant/model"
"sundynix-micro-go/app/plant/rpc/internal/svc"
"sundynix-micro-go/app/plant/rpc/plant"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type AddCarePlanLogic struct {
@@ -23,9 +26,38 @@ func NewAddCarePlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCa
}
}
// 养护
// 添加魏护计划
func (l *AddCarePlanLogic) AddCarePlan(in *plant.AddCarePlanReq) (*plant.CommonResp, error) {
// todo: add your logic here and delete this line
return &plant.CommonResp{}, nil
txErr := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
// 1. 创建计划
carePlan := plantModel.CarePlan{
UserID: in.UserId,
PlantID: in.PlantId,
Name: in.Name,
Icon: in.Icon,
Period: int(in.Period),
TargetAction: in.TargetAction,
}
if err := tx.Create(&carePlan).Error; err != nil {
return err
}
// 2. 创建第一个魏护任务
today := time.Now().Truncate(24 * time.Hour)
dueDate := today.AddDate(0, 0, int(in.Period))
task := plantModel.CareTask{
UserID: in.UserId,
PlantID: in.PlantId,
PlanID: carePlan.ID,
Name: in.Name,
Icon: in.Icon,
TargetAction: in.TargetAction,
DueDate: dueDate,
Status: 1,
}
return tx.Create(&task).Error
})
if txErr != nil {
return nil, txErr
}
return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
}