From 977b2c8c8c0c15b5722e563c02f912106f1523aa Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 23 十一月 2023 19:07:19 +0800
Subject: [PATCH] 获取供应商grpc服务端

---
 proto/supplier/server.go           |   28 +++
 proto/supplier/supplier_grpc.pb.go |  109 +++++++++++++
 proto/supplier/supplier.pb.go      |  287 +++++++++++++++++++++++++++++++++++
 main.go                            |    2 
 proto/supplier.proto               |   20 ++
 5 files changed, 446 insertions(+), 0 deletions(-)

diff --git a/main.go b/main.go
index fe6d232..2b4c8d8 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@
 	"srm/api/v1/test"
 	"srm/proto/purchase_wms"
 	"srm/proto/qualityinspect"
+	"srm/proto/supplier"
 
 	"srm/core"
 	"srm/global"
@@ -48,6 +49,7 @@
 		s := grpc.NewServer()
 		//todo 娣诲姞鍏蜂綋鏈嶅姟
 		purchase_wms.RegisterPurchaseServiceServer(s, &purchase_wms.Server{})
+		supplier.RegisterSupplierServiceServer(s, &supplier.Server{})
 		err = s.Serve(ln)
 		if err != nil {
 			global.GVA_LOG.Error("grpc server init error: %v", zap.Error(err))
diff --git a/proto/supplier.proto b/proto/supplier.proto
new file mode 100644
index 0000000..ce9592e
--- /dev/null
+++ b/proto/supplier.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+option go_package = "./supplier";
+
+service SupplierService {
+  rpc GetSupplierList(SupplierListRequest) returns (SupplierListResponse);
+}
+
+message SupplierListRequest {
+  int32 Status=1;
+}
+
+message SupplierInfo {
+  int32 SupplierId =1 ;
+  string SupplierName =2;
+}
+
+message SupplierListResponse {
+  repeated SupplierInfo List =1;
+}
diff --git a/proto/supplier/server.go b/proto/supplier/server.go
new file mode 100644
index 0000000..90d45e4
--- /dev/null
+++ b/proto/supplier/server.go
@@ -0,0 +1,28 @@
+package supplier
+
+import (
+	"context"
+	"srm/global"
+	"srm/model/test"
+)
+
+type Server struct {
+	UnimplementedSupplierServiceServer
+}
+
+func (s *Server) GetSupplierList(c context.Context, req *SupplierListRequest) (*SupplierListResponse, error) {
+	var supplierList []*test.Supplier
+	resp := new(SupplierListResponse)
+
+	db := global.GVA_DB.Table("srm_supplier")
+	if req.Status != -1 {
+		db = db.Where("status=?", req.Status)
+	}
+	if err := db.Find(&supplierList).Error; err != nil {
+		return resp, err
+	}
+	for _, v := range supplierList {
+		resp.List = append(resp.List, &SupplierInfo{SupplierId: int32(v.ID), SupplierName: v.Name})
+	}
+	return resp, nil
+}
diff --git a/proto/supplier/supplier.pb.go b/proto/supplier/supplier.pb.go
new file mode 100644
index 0000000..9f82b20
--- /dev/null
+++ b/proto/supplier/supplier.pb.go
@@ -0,0 +1,287 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// 	protoc-gen-go v1.30.0
+// 	protoc        v3.8.0
+// source: supplier.proto
+
+package supplier
+
+import (
+	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+	reflect "reflect"
+	sync "sync"
+)
+
+const (
+	// Verify that this generated code is sufficiently up-to-date.
+	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+	// Verify that runtime/protoimpl is sufficiently up-to-date.
+	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type SupplierListRequest struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Status int32 `protobuf:"varint,1,opt,name=Status,proto3" json:"Status,omitempty"`
+}
+
+func (x *SupplierListRequest) Reset() {
+	*x = SupplierListRequest{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_supplier_proto_msgTypes[0]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *SupplierListRequest) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*SupplierListRequest) ProtoMessage() {}
+
+func (x *SupplierListRequest) ProtoReflect() protoreflect.Message {
+	mi := &file_supplier_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use SupplierListRequest.ProtoReflect.Descriptor instead.
+func (*SupplierListRequest) Descriptor() ([]byte, []int) {
+	return file_supplier_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *SupplierListRequest) GetStatus() int32 {
+	if x != nil {
+		return x.Status
+	}
+	return 0
+}
+
+type SupplierInfo struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	SupplierId   int32  `protobuf:"varint,1,opt,name=SupplierId,proto3" json:"SupplierId,omitempty"`
+	SupplierName string `protobuf:"bytes,2,opt,name=SupplierName,proto3" json:"SupplierName,omitempty"`
+}
+
+func (x *SupplierInfo) Reset() {
+	*x = SupplierInfo{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_supplier_proto_msgTypes[1]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *SupplierInfo) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*SupplierInfo) ProtoMessage() {}
+
+func (x *SupplierInfo) ProtoReflect() protoreflect.Message {
+	mi := &file_supplier_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use SupplierInfo.ProtoReflect.Descriptor instead.
+func (*SupplierInfo) Descriptor() ([]byte, []int) {
+	return file_supplier_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *SupplierInfo) GetSupplierId() int32 {
+	if x != nil {
+		return x.SupplierId
+	}
+	return 0
+}
+
+func (x *SupplierInfo) GetSupplierName() string {
+	if x != nil {
+		return x.SupplierName
+	}
+	return ""
+}
+
+type SupplierListResponse struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	List []*SupplierInfo `protobuf:"bytes,1,rep,name=List,proto3" json:"List,omitempty"`
+}
+
+func (x *SupplierListResponse) Reset() {
+	*x = SupplierListResponse{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_supplier_proto_msgTypes[2]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *SupplierListResponse) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*SupplierListResponse) ProtoMessage() {}
+
+func (x *SupplierListResponse) ProtoReflect() protoreflect.Message {
+	mi := &file_supplier_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use SupplierListResponse.ProtoReflect.Descriptor instead.
+func (*SupplierListResponse) Descriptor() ([]byte, []int) {
+	return file_supplier_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *SupplierListResponse) GetList() []*SupplierInfo {
+	if x != nil {
+		return x.List
+	}
+	return nil
+}
+
+var File_supplier_proto protoreflect.FileDescriptor
+
+var file_supplier_proto_rawDesc = []byte{
+	0x0a, 0x0e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
+	0x22, 0x2d, 0x0a, 0x13, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75,
+	0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22,
+	0x52, 0x0a, 0x0c, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12,
+	0x1e, 0x0a, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
+	0x01, 0x28, 0x05, 0x52, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x12,
+	0x22, 0x0a, 0x0c, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18,
+	0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4e,
+	0x61, 0x6d, 0x65, 0x22, 0x39, 0x0a, 0x14, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c,
+	0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x4c,
+	0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x53, 0x75, 0x70, 0x70,
+	0x6c, 0x69, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x32, 0x51,
+	0x0a, 0x0f, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
+	0x65, 0x12, 0x3e, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72,
+	0x4c, 0x69, 0x73, 0x74, 0x12, 0x14, 0x2e, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c,
+	0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x53, 0x75, 0x70,
+	0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
+	0x65, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x62,
+	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+	file_supplier_proto_rawDescOnce sync.Once
+	file_supplier_proto_rawDescData = file_supplier_proto_rawDesc
+)
+
+func file_supplier_proto_rawDescGZIP() []byte {
+	file_supplier_proto_rawDescOnce.Do(func() {
+		file_supplier_proto_rawDescData = protoimpl.X.CompressGZIP(file_supplier_proto_rawDescData)
+	})
+	return file_supplier_proto_rawDescData
+}
+
+var file_supplier_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
+var file_supplier_proto_goTypes = []interface{}{
+	(*SupplierListRequest)(nil),  // 0: SupplierListRequest
+	(*SupplierInfo)(nil),         // 1: SupplierInfo
+	(*SupplierListResponse)(nil), // 2: SupplierListResponse
+}
+var file_supplier_proto_depIdxs = []int32{
+	1, // 0: SupplierListResponse.List:type_name -> SupplierInfo
+	0, // 1: SupplierService.GetSupplierList:input_type -> SupplierListRequest
+	2, // 2: SupplierService.GetSupplierList:output_type -> SupplierListResponse
+	2, // [2:3] is the sub-list for method output_type
+	1, // [1:2] is the sub-list for method input_type
+	1, // [1:1] is the sub-list for extension type_name
+	1, // [1:1] is the sub-list for extension extendee
+	0, // [0:1] is the sub-list for field type_name
+}
+
+func init() { file_supplier_proto_init() }
+func file_supplier_proto_init() {
+	if File_supplier_proto != nil {
+		return
+	}
+	if !protoimpl.UnsafeEnabled {
+		file_supplier_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*SupplierListRequest); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_supplier_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*SupplierInfo); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_supplier_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*SupplierListResponse); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+	}
+	type x struct{}
+	out := protoimpl.TypeBuilder{
+		File: protoimpl.DescBuilder{
+			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+			RawDescriptor: file_supplier_proto_rawDesc,
+			NumEnums:      0,
+			NumMessages:   3,
+			NumExtensions: 0,
+			NumServices:   1,
+		},
+		GoTypes:           file_supplier_proto_goTypes,
+		DependencyIndexes: file_supplier_proto_depIdxs,
+		MessageInfos:      file_supplier_proto_msgTypes,
+	}.Build()
+	File_supplier_proto = out.File
+	file_supplier_proto_rawDesc = nil
+	file_supplier_proto_goTypes = nil
+	file_supplier_proto_depIdxs = nil
+}
diff --git a/proto/supplier/supplier_grpc.pb.go b/proto/supplier/supplier_grpc.pb.go
new file mode 100644
index 0000000..c03c768
--- /dev/null
+++ b/proto/supplier/supplier_grpc.pb.go
@@ -0,0 +1,109 @@
+// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.3.0
+// - protoc             v3.8.0
+// source: supplier.proto
+
+package supplier
+
+import (
+	context "context"
+	grpc "google.golang.org/grpc"
+	codes "google.golang.org/grpc/codes"
+	status "google.golang.org/grpc/status"
+)
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+// Requires gRPC-Go v1.32.0 or later.
+const _ = grpc.SupportPackageIsVersion7
+
+const (
+	SupplierService_GetSupplierList_FullMethodName = "/SupplierService/GetSupplierList"
+)
+
+// SupplierServiceClient is the client API for SupplierService service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
+type SupplierServiceClient interface {
+	GetSupplierList(ctx context.Context, in *SupplierListRequest, opts ...grpc.CallOption) (*SupplierListResponse, error)
+}
+
+type supplierServiceClient struct {
+	cc grpc.ClientConnInterface
+}
+
+func NewSupplierServiceClient(cc grpc.ClientConnInterface) SupplierServiceClient {
+	return &supplierServiceClient{cc}
+}
+
+func (c *supplierServiceClient) GetSupplierList(ctx context.Context, in *SupplierListRequest, opts ...grpc.CallOption) (*SupplierListResponse, error) {
+	out := new(SupplierListResponse)
+	err := c.cc.Invoke(ctx, SupplierService_GetSupplierList_FullMethodName, in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// SupplierServiceServer is the server API for SupplierService service.
+// All implementations must embed UnimplementedSupplierServiceServer
+// for forward compatibility
+type SupplierServiceServer interface {
+	GetSupplierList(context.Context, *SupplierListRequest) (*SupplierListResponse, error)
+	mustEmbedUnimplementedSupplierServiceServer()
+}
+
+// UnimplementedSupplierServiceServer must be embedded to have forward compatible implementations.
+type UnimplementedSupplierServiceServer struct {
+}
+
+func (UnimplementedSupplierServiceServer) GetSupplierList(context.Context, *SupplierListRequest) (*SupplierListResponse, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GetSupplierList not implemented")
+}
+func (UnimplementedSupplierServiceServer) mustEmbedUnimplementedSupplierServiceServer() {}
+
+// UnsafeSupplierServiceServer may be embedded to opt out of forward compatibility for this service.
+// Use of this interface is not recommended, as added methods to SupplierServiceServer will
+// result in compilation errors.
+type UnsafeSupplierServiceServer interface {
+	mustEmbedUnimplementedSupplierServiceServer()
+}
+
+func RegisterSupplierServiceServer(s grpc.ServiceRegistrar, srv SupplierServiceServer) {
+	s.RegisterService(&SupplierService_ServiceDesc, srv)
+}
+
+func _SupplierService_GetSupplierList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(SupplierListRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(SupplierServiceServer).GetSupplierList(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: SupplierService_GetSupplierList_FullMethodName,
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(SupplierServiceServer).GetSupplierList(ctx, req.(*SupplierListRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+// SupplierService_ServiceDesc is the grpc.ServiceDesc for SupplierService service.
+// It's only intended for direct use with grpc.RegisterService,
+// and not to be introspected or modified (even as a copy)
+var SupplierService_ServiceDesc = grpc.ServiceDesc{
+	ServiceName: "SupplierService",
+	HandlerType: (*SupplierServiceServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "GetSupplierList",
+			Handler:    _SupplierService_GetSupplierList_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "supplier.proto",
+}

--
Gitblit v1.8.0