53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
package myPlant
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"sundynix-micro-go/app/plant/api/internal/svc"
|
|
"sundynix-micro-go/app/plant/api/internal/types"
|
|
plantModel "sundynix-micro-go/app/plant/model"
|
|
)
|
|
|
|
type UpdatePlantLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdatePlantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlantLogic {
|
|
return &UpdatePlantLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
|
}
|
|
|
|
func (l *UpdatePlantLogic) UpdatePlant(req *types.UpdatePlantReq) error {
|
|
updates := map[string]interface{}{}
|
|
if req.Name != "" {
|
|
updates["name"] = req.Name
|
|
}
|
|
if req.Status > 0 {
|
|
updates["status"] = req.Status
|
|
}
|
|
if req.Placement != "" {
|
|
updates["placement"] = req.Placement
|
|
}
|
|
if req.PotMaterial != "" {
|
|
updates["pot_material"] = req.PotMaterial
|
|
}
|
|
if req.PotSize != "" {
|
|
updates["pot_size"] = req.PotSize
|
|
}
|
|
if req.Sunlight != "" {
|
|
updates["sunlight"] = req.Sunlight
|
|
}
|
|
if req.PlantingMaterial != "" {
|
|
updates["planting_material"] = req.PlantingMaterial
|
|
}
|
|
if len(updates) > 0 {
|
|
if err := l.svcCtx.DB.Model(&plantModel.SundynixMyPlant{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
|
return fmt.Errorf("更新植物失败")
|
|
}
|
|
}
|
|
return nil
|
|
}
|