Align origin/main with upstream/main (GitHub). The two branches diverged due to pre-rebase vs post-rebase merge commits for the k8s-amd64-dockerfiles feature. Includes: multi-stage Go compilation Dockerfiles, pan-bolt inventory features, CRM relations, Excel import tooling, proto/gRPC updates, migration scripts, and tools/ directory. Excludes deploy/bin/ pre-compiled binaries (arm64, not needed for amd64 K3s cluster; builds use multi-stage Dockerfiles now).
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"muyu-apiserver/model"
|
|
"muyu-apiserver/pkg/metrics"
|
|
"muyu-apiserver/pkg/tenantctx"
|
|
"muyu-apiserver/pkg/uid"
|
|
"muyu-apiserver/rpc/inventory/internal/svc"
|
|
"muyu-apiserver/rpc/inventory/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type SaveBoltsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewSaveBoltsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveBoltsLogic {
|
|
return &SaveBoltsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *SaveBoltsLogic) SaveBolts(in *pb.SaveBoltsReq) (*pb.Empty, error) {
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
|
|
var totalLengthM float64
|
|
bolts := make([]*model.InvProductBolt, 0, len(in.Lengths))
|
|
for i, lengthStr := range in.Lengths {
|
|
lengthM, _ := strconv.ParseFloat(lengthStr, 64)
|
|
totalLengthM += lengthM
|
|
bolts = append(bolts, &model.InvProductBolt{
|
|
BoltId: uid.Generate(),
|
|
PanId: in.PanId,
|
|
LengthM: lengthM,
|
|
SortOrder: int64(i + 1),
|
|
})
|
|
}
|
|
|
|
if err := l.svcCtx.BoltModel.BulkReplace(l.ctx, in.PanId, tenantId, bolts); err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
metrics.InboundBoltsTotal.WithLabelValues(tenantId, "save_bolts").Add(float64(len(in.Lengths)))
|
|
if totalLengthM > 0 {
|
|
metrics.InboundLengthMetersTotal.WithLabelValues(tenantId, "", "", "save_bolts").Add(totalLengthM)
|
|
}
|
|
|
|
return &pb.Empty{}, nil
|
|
}
|