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).
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"muyu-apiserver/model"
|
|
"muyu-apiserver/pkg/tenantctx"
|
|
"muyu-apiserver/pkg/uid"
|
|
"muyu-apiserver/rpc/purchase/internal/svc"
|
|
"muyu-apiserver/rpc/purchase/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateSupplierLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCreateSupplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSupplierLogic {
|
|
return &CreateSupplierLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *CreateSupplierLogic) CreateSupplier(in *pb.CreateSupplierReq) (*pb.IdResp, error) {
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
|
|
existing, err := l.svcCtx.SupplierModel.FindOneByNameAndTenant(l.ctx, tenantId, in.SupplierName)
|
|
if err == nil && existing != nil {
|
|
return nil, ErrSupplierNameExists
|
|
}
|
|
|
|
supplierId := uid.Generate()
|
|
_, err = l.svcCtx.SupplierModel.Insert(l.ctx, &model.PurSupplier{
|
|
SupplierId: supplierId,
|
|
TenantId: tenantId,
|
|
SupplierName: in.SupplierName,
|
|
Phone: in.Phone,
|
|
Status: 1,
|
|
Remark: sql.NullString{String: in.Remark, Valid: in.Remark != ""},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &pb.IdResp{Id: supplierId}, nil
|
|
}
|