init: init refactor

This commit is contained in:
Blizzard
2026-04-27 00:02:18 +08:00
commit e515f6a287
360 changed files with 30713 additions and 0 deletions
@@ -0,0 +1,52 @@
// 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
}