Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderStateLogsLogic {
|
||||
return &AddOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
func (l *AddOrderStateLogsLogic) AddOrderStateLogs(in *pb.AddOrderStateLogsReq) (*pb.AddOrderStateLogsResp, error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("order state log is required")
|
||||
}
|
||||
|
||||
builder := l.svcCtx.OrderModelsRW.OrderStateLogs.Create().
|
||||
SetID(in.Id).
|
||||
SetOrderID(in.OrderId).
|
||||
SetToStatus(in.ToStatus).
|
||||
SetAction(in.Action).
|
||||
SetActorID(in.ActorId).
|
||||
SetActorRole(in.ActorRole)
|
||||
|
||||
if in.FromStatus != nil {
|
||||
builder = builder.SetFromStatus(*in.FromStatus)
|
||||
}
|
||||
if in.Metadata != nil {
|
||||
metadata, err := parseJSONMap(*in.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder = builder.SetMetadata(metadata)
|
||||
}
|
||||
if in.CreatedAt != nil {
|
||||
builder = builder.SetCreatedAt(time.Unix(*in.CreatedAt, 0))
|
||||
}
|
||||
|
||||
if _, err := builder.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrdersLogic {
|
||||
return &AddOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orders-----------------------
|
||||
func (l *AddOrdersLogic) AddOrders(in *pb.AddOrdersReq) (*pb.AddOrdersResp, error) {
|
||||
orderID := in.Id
|
||||
if orderID <= 0 {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderID = idResp.Id
|
||||
}
|
||||
|
||||
totalPrice, err := parseDecimal(in.GetTotalPrice())
|
||||
if err != nil || totalPrice.Cmp(decimal.Zero) <= 0 {
|
||||
return nil, errors.New("invalid total price")
|
||||
}
|
||||
|
||||
serviceSnapshot, err := parseJSONMap(in.GetServiceSnapshot())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
creator := l.svcCtx.OrderModelsRW.Orders.Create().
|
||||
SetID(orderID).
|
||||
SetConsumerID(in.ConsumerId).
|
||||
SetConsumerName(in.ConsumerName).
|
||||
SetPlayerID(in.PlayerId).
|
||||
SetPlayerName(in.PlayerName).
|
||||
SetServiceSnapshot(serviceSnapshot).
|
||||
SetTotalPrice(totalPrice)
|
||||
|
||||
if in.ShopId != nil {
|
||||
creator = creator.SetShopID(*in.ShopId)
|
||||
}
|
||||
if in.ShopName != nil {
|
||||
creator = creator.SetShopName(*in.ShopName)
|
||||
}
|
||||
if in.Status != nil && *in.Status != "" {
|
||||
creator = creator.SetStatus(*in.Status)
|
||||
}
|
||||
if in.Note != nil {
|
||||
creator = creator.SetNote(*in.Note)
|
||||
}
|
||||
if in.Version != nil {
|
||||
creator = creator.SetVersion(int(*in.Version))
|
||||
}
|
||||
if in.TimeoutJobId != nil {
|
||||
creator = creator.SetTimeoutJobID(*in.TimeoutJobId)
|
||||
}
|
||||
if in.SearchText != nil {
|
||||
creator = creator.SetSearchText(*in.SearchText)
|
||||
}
|
||||
if createdAt := unixPtr(in.CreatedAt); createdAt != nil {
|
||||
creator = creator.SetCreatedAt(*createdAt)
|
||||
}
|
||||
if acceptedAt := unixPtr(in.AcceptedAt); acceptedAt != nil {
|
||||
creator = creator.SetAcceptedAt(*acceptedAt)
|
||||
}
|
||||
if closedAt := unixPtr(in.ClosedAt); closedAt != nil {
|
||||
creator = creator.SetClosedAt(*closedAt)
|
||||
}
|
||||
if completedAt := unixPtr(in.CompletedAt); completedAt != nil {
|
||||
creator = creator.SetCompletedAt(*completedAt)
|
||||
}
|
||||
if cancelledAt := unixPtr(in.CancelledAt); cancelledAt != nil {
|
||||
creator = creator.SetCancelledAt(*cancelledAt)
|
||||
}
|
||||
if updatedAt := unixPtr(in.UpdatedAt); updatedAt != nil {
|
||||
creator = creator.SetUpdatedAt(*updatedAt)
|
||||
} else {
|
||||
creator = creator.SetUpdatedAt(time.Now())
|
||||
}
|
||||
|
||||
if _, err := creator.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddOrdersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
)
|
||||
|
||||
func parseDecimal(v string) (decimal.Decimal, error) {
|
||||
if v == "" {
|
||||
return decimal.Zero, nil
|
||||
}
|
||||
d, err := decimal.NewFromString(v)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.New("invalid decimal value")
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func parseJSONMap(v string) (map[string]any, error) {
|
||||
if v == "" {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
var result map[string]any
|
||||
if err := json.Unmarshal([]byte(v), &result); err != nil {
|
||||
return nil, errors.New("invalid json value")
|
||||
}
|
||||
if result == nil {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func unixPtr(v *int64) *time.Time {
|
||||
if v == nil || *v <= 0 {
|
||||
return nil
|
||||
}
|
||||
t := time.Unix(*v, 0)
|
||||
return &t
|
||||
}
|
||||
|
||||
func toPBOrder(item *models.Orders) *pb.Orders {
|
||||
serviceSnapshot := "{}"
|
||||
if b, err := json.Marshal(item.ServiceSnapshot); err == nil {
|
||||
serviceSnapshot = string(b)
|
||||
}
|
||||
|
||||
result := &pb.Orders{
|
||||
Id: item.ID,
|
||||
ConsumerId: item.ConsumerID,
|
||||
ConsumerName: item.ConsumerName,
|
||||
PlayerId: item.PlayerID,
|
||||
PlayerName: item.PlayerName,
|
||||
ServiceSnapshot: serviceSnapshot,
|
||||
Status: item.Status,
|
||||
TotalPrice: item.TotalPrice.String(),
|
||||
Version: int64(item.Version),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
}
|
||||
|
||||
if item.ShopID != nil {
|
||||
result.ShopId = item.ShopID
|
||||
}
|
||||
if item.ShopName != nil {
|
||||
result.ShopName = item.ShopName
|
||||
}
|
||||
if item.Note != nil {
|
||||
result.Note = item.Note
|
||||
}
|
||||
if item.TimeoutJobID != nil {
|
||||
result.TimeoutJobId = item.TimeoutJobID
|
||||
}
|
||||
if item.SearchText != nil {
|
||||
result.SearchText = *item.SearchText
|
||||
}
|
||||
if item.AcceptedAt != nil {
|
||||
t := item.AcceptedAt.Unix()
|
||||
result.AcceptedAt = &t
|
||||
}
|
||||
if item.ClosedAt != nil {
|
||||
t := item.ClosedAt.Unix()
|
||||
result.ClosedAt = &t
|
||||
}
|
||||
if item.CompletedAt != nil {
|
||||
t := item.CompletedAt.Unix()
|
||||
result.CompletedAt = &t
|
||||
}
|
||||
if item.CancelledAt != nil {
|
||||
t := item.CancelledAt.Unix()
|
||||
result.CancelledAt = &t
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func toPBOrderStateLog(item *models.OrderStateLogs) *pb.OrderStateLogs {
|
||||
result := &pb.OrderStateLogs{
|
||||
Id: item.ID,
|
||||
OrderId: item.OrderID,
|
||||
ToStatus: item.ToStatus,
|
||||
Action: item.Action,
|
||||
ActorId: item.ActorID,
|
||||
ActorRole: item.ActorRole,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
}
|
||||
|
||||
if item.FromStatus != nil {
|
||||
result.FromStatus = item.FromStatus
|
||||
}
|
||||
if item.Metadata != nil {
|
||||
if b, err := json.Marshal(item.Metadata); err == nil {
|
||||
metadata := string(b)
|
||||
result.Metadata = &metadata
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelOrderStateLogsLogic {
|
||||
return &DelOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelOrderStateLogsLogic) DelOrderStateLogs(in *pb.DelOrderStateLogsReq) (*pb.DelOrderStateLogsResp, error) {
|
||||
if err := l.svcCtx.OrderModelsRW.OrderStateLogs.DeleteOneID(in.Id).Exec(l.ctx); err != nil {
|
||||
if models.IsNotFound(err) {
|
||||
return nil, errors.New("order state log not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DelOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelOrdersLogic {
|
||||
return &DelOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelOrdersLogic) DelOrders(in *pb.DelOrdersReq) (*pb.DelOrdersResp, error) {
|
||||
if err := l.svcCtx.OrderModelsRW.Orders.DeleteOneID(in.Id).Exec(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DelOrdersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrderStateLogsByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetOrderStateLogsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderStateLogsByIdLogic {
|
||||
return &GetOrderStateLogsByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrderStateLogsByIdLogic) GetOrderStateLogsById(in *pb.GetOrderStateLogsByIdReq) (*pb.GetOrderStateLogsByIdResp, error) {
|
||||
item, err := l.svcCtx.OrderModelsRO.OrderStateLogs.Query().
|
||||
Where(orderstatelogs.IDEQ(in.Id)).
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetOrderStateLogsByIdResp{OrderStateLogs: toPBOrderStateLog(item)}, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrdersByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetOrdersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrdersByIdLogic {
|
||||
return &GetOrdersByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrdersByIdLogic) GetOrdersById(in *pb.GetOrdersByIdReq) (*pb.GetOrdersByIdResp, error) {
|
||||
item, err := l.svcCtx.OrderModelsRO.Orders.Query().Where(orders.IDEQ(in.Id)).First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetOrdersByIdResp{Orders: toPBOrder(item)}, nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchOrderStateLogsLogic {
|
||||
return &SearchOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchOrderStateLogsLogic) SearchOrderStateLogs(in *pb.SearchOrderStateLogsReq) (*pb.SearchOrderStateLogsResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.OrderStateLogs, 0, 8)
|
||||
if in.Id != nil {
|
||||
preds = append(preds, orderstatelogs.IDEQ(*in.Id))
|
||||
}
|
||||
if in.OrderId != nil {
|
||||
preds = append(preds, orderstatelogs.OrderIDEQ(*in.OrderId))
|
||||
}
|
||||
if in.FromStatus != nil && *in.FromStatus != "" {
|
||||
preds = append(preds, orderstatelogs.FromStatusEQ(*in.FromStatus))
|
||||
}
|
||||
if in.ToStatus != nil && *in.ToStatus != "" {
|
||||
preds = append(preds, orderstatelogs.ToStatusEQ(*in.ToStatus))
|
||||
}
|
||||
if in.Action != nil && *in.Action != "" {
|
||||
preds = append(preds, orderstatelogs.ActionContainsFold(*in.Action))
|
||||
}
|
||||
if in.ActorId != nil {
|
||||
preds = append(preds, orderstatelogs.ActorIDEQ(*in.ActorId))
|
||||
}
|
||||
if in.ActorRole != nil && *in.ActorRole != "" {
|
||||
preds = append(preds, orderstatelogs.ActorRoleContainsFold(*in.ActorRole))
|
||||
}
|
||||
if in.CreatedAt != nil && *in.CreatedAt > 0 {
|
||||
preds = append(preds, orderstatelogs.CreatedAtGTE(time.Unix(*in.CreatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.OrderModelsRO.OrderStateLogs.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(orderstatelogs.And(preds...))
|
||||
}
|
||||
|
||||
items, err := query.Offset(int(in.Page * in.Limit)).Limit(int(in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*pb.OrderStateLogs, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, toPBOrderStateLog(item))
|
||||
}
|
||||
|
||||
return &pb.SearchOrderStateLogsResp{OrderStateLogs: result}, nil
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchOrdersLogic {
|
||||
return &SearchOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchOrdersLogic) SearchOrders(in *pb.SearchOrdersReq) (*pb.SearchOrdersResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.Orders, 0, 20)
|
||||
if in.Id != nil {
|
||||
preds = append(preds, orders.IDEQ(*in.Id))
|
||||
}
|
||||
if in.ConsumerId != nil {
|
||||
preds = append(preds, orders.ConsumerIDEQ(*in.ConsumerId))
|
||||
}
|
||||
if in.ConsumerName != nil && *in.ConsumerName != "" {
|
||||
preds = append(preds, orders.ConsumerNameContainsFold(*in.ConsumerName))
|
||||
}
|
||||
if in.PlayerId != nil {
|
||||
preds = append(preds, orders.PlayerIDEQ(*in.PlayerId))
|
||||
}
|
||||
if in.PlayerName != nil && *in.PlayerName != "" {
|
||||
preds = append(preds, orders.PlayerNameContainsFold(*in.PlayerName))
|
||||
}
|
||||
if in.ShopId != nil {
|
||||
preds = append(preds, orders.ShopIDEQ(*in.ShopId))
|
||||
}
|
||||
if in.ShopName != nil && *in.ShopName != "" {
|
||||
preds = append(preds, orders.ShopNameContainsFold(*in.ShopName))
|
||||
}
|
||||
if in.Status != nil && *in.Status != "" {
|
||||
preds = append(preds, orders.StatusEQ(*in.Status))
|
||||
}
|
||||
if in.TotalPrice != nil && *in.TotalPrice != "" {
|
||||
price, err := parseDecimal(*in.TotalPrice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
preds = append(preds, orders.TotalPriceEQ(price))
|
||||
}
|
||||
if in.Note != nil && *in.Note != "" {
|
||||
preds = append(preds, orders.NoteContainsFold(*in.Note))
|
||||
}
|
||||
if in.Version != nil {
|
||||
preds = append(preds, orders.VersionEQ(int(*in.Version)))
|
||||
}
|
||||
if in.TimeoutJobId != nil && *in.TimeoutJobId != "" {
|
||||
preds = append(preds, orders.TimeoutJobIDEQ(*in.TimeoutJobId))
|
||||
}
|
||||
if in.SearchText != nil && *in.SearchText != "" {
|
||||
preds = append(preds, orders.SearchTextContainsFold(*in.SearchText))
|
||||
}
|
||||
if in.CreatedAt != nil && *in.CreatedAt > 0 {
|
||||
preds = append(preds, orders.CreatedAtGTE(time.Unix(*in.CreatedAt, 0)))
|
||||
}
|
||||
if in.AcceptedAt != nil && *in.AcceptedAt > 0 {
|
||||
preds = append(preds, orders.AcceptedAtGTE(time.Unix(*in.AcceptedAt, 0)))
|
||||
}
|
||||
if in.ClosedAt != nil && *in.ClosedAt > 0 {
|
||||
preds = append(preds, orders.ClosedAtGTE(time.Unix(*in.ClosedAt, 0)))
|
||||
}
|
||||
if in.CompletedAt != nil && *in.CompletedAt > 0 {
|
||||
preds = append(preds, orders.CompletedAtGTE(time.Unix(*in.CompletedAt, 0)))
|
||||
}
|
||||
if in.CancelledAt != nil && *in.CancelledAt > 0 {
|
||||
preds = append(preds, orders.CancelledAtGTE(time.Unix(*in.CancelledAt, 0)))
|
||||
}
|
||||
if in.UpdatedAt != nil && *in.UpdatedAt > 0 {
|
||||
preds = append(preds, orders.UpdatedAtGTE(time.Unix(*in.UpdatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.OrderModelsRO.Orders.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(orders.And(preds...))
|
||||
}
|
||||
|
||||
items, err := query.Offset(int(in.Page * in.Limit)).Limit(int(in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*pb.Orders, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, toPBOrder(item))
|
||||
}
|
||||
|
||||
return &pb.SearchOrdersResp{Orders: result}, nil
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderStateLogsLogic {
|
||||
return &UpdateOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateOrderStateLogsLogic) UpdateOrderStateLogs(in *pb.UpdateOrderStateLogsReq) (*pb.UpdateOrderStateLogsResp, error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("order state log is required")
|
||||
}
|
||||
|
||||
builder := l.svcCtx.OrderModelsRW.OrderStateLogs.UpdateOneID(in.Id)
|
||||
|
||||
if in.OrderId != nil {
|
||||
builder = builder.SetOrderID(*in.OrderId)
|
||||
}
|
||||
if in.FromStatus != nil {
|
||||
builder = builder.SetFromStatus(*in.FromStatus)
|
||||
}
|
||||
if in.ToStatus != nil {
|
||||
builder = builder.SetToStatus(*in.ToStatus)
|
||||
}
|
||||
if in.Action != nil {
|
||||
builder = builder.SetAction(*in.Action)
|
||||
}
|
||||
if in.ActorId != nil {
|
||||
builder = builder.SetActorID(*in.ActorId)
|
||||
}
|
||||
if in.ActorRole != nil {
|
||||
builder = builder.SetActorRole(*in.ActorRole)
|
||||
}
|
||||
if in.Metadata != nil {
|
||||
metadata, err := parseJSONMap(*in.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder = builder.SetMetadata(metadata)
|
||||
}
|
||||
if _, err := builder.Save(l.ctx); err != nil {
|
||||
if models.IsNotFound(err) {
|
||||
return nil, errors.New("order state log not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrdersLogic {
|
||||
return &UpdateOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateOrdersLogic) UpdateOrders(in *pb.UpdateOrdersReq) (*pb.UpdateOrdersResp, error) {
|
||||
updater := l.svcCtx.OrderModelsRW.Orders.UpdateOneID(in.Id)
|
||||
|
||||
if in.ConsumerId != nil {
|
||||
updater = updater.SetConsumerID(*in.ConsumerId)
|
||||
}
|
||||
if in.ConsumerName != nil {
|
||||
updater = updater.SetConsumerName(*in.ConsumerName)
|
||||
}
|
||||
if in.PlayerId != nil {
|
||||
updater = updater.SetPlayerID(*in.PlayerId)
|
||||
}
|
||||
if in.PlayerName != nil {
|
||||
updater = updater.SetPlayerName(*in.PlayerName)
|
||||
}
|
||||
if in.ShopId != nil {
|
||||
updater = updater.SetShopID(*in.ShopId)
|
||||
}
|
||||
if in.ShopName != nil {
|
||||
updater = updater.SetShopName(*in.ShopName)
|
||||
}
|
||||
if in.ServiceSnapshot != nil {
|
||||
snapshot, err := parseJSONMap(*in.ServiceSnapshot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updater = updater.SetServiceSnapshot(snapshot)
|
||||
}
|
||||
if in.Status != nil {
|
||||
updater = updater.SetStatus(*in.Status)
|
||||
}
|
||||
if in.TotalPrice != nil {
|
||||
price, err := parseDecimal(*in.TotalPrice)
|
||||
if err != nil || price.Cmp(decimal.Zero) <= 0 {
|
||||
return nil, errors.New("invalid total price")
|
||||
}
|
||||
updater = updater.SetTotalPrice(price)
|
||||
}
|
||||
if in.Note != nil {
|
||||
updater = updater.SetNote(*in.Note)
|
||||
}
|
||||
if in.Version != nil {
|
||||
updater = updater.SetVersion(int(*in.Version))
|
||||
}
|
||||
if in.TimeoutJobId != nil {
|
||||
updater = updater.SetTimeoutJobID(*in.TimeoutJobId)
|
||||
}
|
||||
if in.SearchText != nil {
|
||||
updater = updater.SetSearchText(*in.SearchText)
|
||||
}
|
||||
if acceptedAt := unixPtr(in.AcceptedAt); acceptedAt != nil {
|
||||
updater = updater.SetAcceptedAt(*acceptedAt)
|
||||
}
|
||||
if closedAt := unixPtr(in.ClosedAt); closedAt != nil {
|
||||
updater = updater.SetClosedAt(*closedAt)
|
||||
}
|
||||
if completedAt := unixPtr(in.CompletedAt); completedAt != nil {
|
||||
updater = updater.SetCompletedAt(*completedAt)
|
||||
}
|
||||
if cancelledAt := unixPtr(in.CancelledAt); cancelledAt != nil {
|
||||
updater = updater.SetCancelledAt(*cancelledAt)
|
||||
}
|
||||
if updatedAt := unixPtr(in.UpdatedAt); updatedAt != nil {
|
||||
updater = updater.SetUpdatedAt(*updatedAt)
|
||||
}
|
||||
|
||||
if _, err := updater.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateOrdersResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user