muyu-apiserver/rpc/purchase/internal/logic/listinventoryloglogic.go
Chever John a25acdc5e4 chore: sync codebase with upstream
Pull latest changes from upstream/main (GitHub) including:
- Purchase RPC service (proto, server, logic, models)
- Gateway route updates for purchase endpoints
- SQL migration and config updates

Excludes deploy/bin/ pre-compiled arm64 binaries (builds use
multi-stage Dockerfiles targeting amd64).
2026-06-15 09:20:56 +08:00

49 lines
1.5 KiB
Go

package logic
import (
"context"
"fmt"
"muyu-apiserver/pkg/tenantctx"
"muyu-apiserver/rpc/purchase/internal/svc"
"muyu-apiserver/rpc/purchase/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListInventoryLogLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListInventoryLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListInventoryLogLogic {
return &ListInventoryLogLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *ListInventoryLogLogic) ListInventoryLog(in *pb.ListInventoryLogReq) (*pb.ListInventoryLogResp, error) {
tenantId := tenantctx.ExtractTenantId(l.ctx)
list, total, err := l.svcCtx.InventoryLogModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.ProductId, in.RefType, in.ChangeType, in.StartDate, in.EndDate)
if err != nil {
return nil, err
}
items := make([]*pb.InventoryLogInfo, 0, len(list))
for _, lg := range list {
items = append(items, &pb.InventoryLogInfo{
LogId: lg.LogId,
ProductId: lg.ProductId,
ChangeQty: fmt.Sprintf("%.2f", lg.ChangeQty),
BalanceAfter: fmt.Sprintf("%.2f", lg.BalanceAfter),
ChangeType: lg.ChangeType,
RefType: lg.RefType,
RefId: lg.RefId,
ContactId: lg.ContactId,
LogDate: lg.LogDate.Format("2006-01-02"),
Operator: lg.Operator,
Remark: lg.Remark.String,
CreatedAt: lg.CreatedAt.Format("2006-01-02 15:04:05"),
})
}
return &pb.ListInventoryLogResp{Total: total, List: items}, nil
}