Merge branch 'jng-supplier-0105'
This commit is contained in:
commit
a62549e503
2209
api/supplier/supplier.pb.go
Normal file
2209
api/supplier/supplier.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
208
api/supplier/supplier.proto
Normal file
208
api/supplier/supplier.proto
Normal file
@ -0,0 +1,208 @@
|
||||
syntax = "proto3";
|
||||
package supplier;
|
||||
|
||||
option go_package = "./;supplier";
|
||||
|
||||
// FiEE供应商微服务
|
||||
service Supplier {
|
||||
//供应商curd
|
||||
rpc GetSupplier(GetSupplierRequest) returns (UpdateSupplierRequest) {}
|
||||
rpc CreateSupplier(CreateSupplierRequest) returns (CreateSupplierResponse) {}
|
||||
rpc UpdateSupplier(UpdateSupplierRequest) returns (CreateSupplierResponse) {}
|
||||
rpc GetSupplierList(GetSupplierListRequest) returns (GetSupplierListResponse) {}
|
||||
//组织字典
|
||||
rpc CreateOrganizeDictionary(CreateOrganizeDictionaryRequest) returns (CreateOrganizeDictionaryResponse) {}
|
||||
rpc GetOrganizeDictionaryList(GetOrganizeDictionaryListRequest) returns (GetOrganizeDictionaryListResponse) {}
|
||||
rpc GetOrganizeDictionaryInfo(CreateOrganizeDictionaryRequest) returns (OrganizeDictionary) {}
|
||||
//国家组织
|
||||
rpc GetCountryRegionList(GetCountryRegionListRequest) returns (GetCountryRegionListResponse) {}
|
||||
rpc GetCountryRegionInfo(GetCountryRegionInfoRequest) returns (CountryRegion) {}
|
||||
//导入
|
||||
rpc CreateImportRecord(CreateImportRecordRequest) returns (CreateImportRecordResponse) {}
|
||||
rpc GetImportRecordInfo(GetImportRecordRequest) returns (GetImportRecordResponse) {}
|
||||
}
|
||||
message GetImportRecordRequest{
|
||||
string uuid = 1;
|
||||
}
|
||||
message GetImportRecordResponse{
|
||||
uint64 successNum = 1;
|
||||
uint64 failNum = 2;
|
||||
string deriveUrl = 3;
|
||||
}
|
||||
message CreateImportRecordRequest{
|
||||
repeated string supplierCodes = 1;
|
||||
uint64 status = 2;
|
||||
uint64 userId = 3;
|
||||
string toLeadUrl = 4;
|
||||
string deriveUrl = 5;
|
||||
string uuid = 6;
|
||||
uint64 successNum = 7;
|
||||
uint64 failNum = 8;
|
||||
}
|
||||
message CreateImportRecordResponse{
|
||||
uint64 id = 1;
|
||||
}
|
||||
message GetCountryRegionListResponse{
|
||||
repeated CountryRegion data = 1;
|
||||
uint64 page = 2;
|
||||
uint64 pageSize = 3;
|
||||
uint64 total = 4;
|
||||
}
|
||||
message CountryRegion{
|
||||
uint64 id = 1;
|
||||
string nameEN = 2;
|
||||
string nameCN = 3;
|
||||
string code = 4;
|
||||
}
|
||||
message GetCountryRegionInfoRequest{
|
||||
string zhAndCode = 1;
|
||||
}
|
||||
message GetCountryRegionListRequest{
|
||||
uint64 page = 1;
|
||||
uint64 pageSize = 2;
|
||||
string nameEN = 3;
|
||||
string nameCN = 4;
|
||||
string code = 5;
|
||||
}
|
||||
message OrganizeDictionary{
|
||||
uint64 id = 1;
|
||||
string name = 2;
|
||||
}
|
||||
message GetOrganizeDictionaryListResponse{
|
||||
repeated OrganizeDictionary data = 1;
|
||||
uint64 page = 2;
|
||||
uint64 pageSize = 3;
|
||||
uint64 total = 4;
|
||||
}
|
||||
message CreateOrganizeDictionaryRequest{
|
||||
string name = 1;
|
||||
}
|
||||
message CreateOrganizeDictionaryResponse{
|
||||
uint64 id = 1;
|
||||
}
|
||||
message GetOrganizeDictionaryListRequest{
|
||||
uint64 page = 1;
|
||||
uint64 pageSize = 2;
|
||||
string name = 3;
|
||||
}
|
||||
message GetSupplierListRequest{
|
||||
uint64 page = 1;
|
||||
uint64 pageSize = 2;
|
||||
uint64 owningEntityId = 3;
|
||||
string supplierUniqueCode = 4;
|
||||
string legalName =5;
|
||||
string localName = 6;
|
||||
string abbreviationName =7;
|
||||
uint64 countryOrRegionId = 8;
|
||||
string companyRegistrationNumber =9;
|
||||
string supplierType =10;
|
||||
string approvalStatus = 11;
|
||||
string approvalDateStart = 12;
|
||||
string approvalDateEnd = 13;
|
||||
string lastReviewDateStart = 14;
|
||||
string lastReviewDateEnd = 15;
|
||||
string legalEntityType = 16;
|
||||
string sanctionsCountryScreeningResult = 17;
|
||||
string keyFinancial = 18;
|
||||
string companyAddress = 19;
|
||||
string primaryContact = 20;
|
||||
string dataOwnerDepartment = 21;
|
||||
string basicCompanyInformation = 22;
|
||||
uint64 status = 23;
|
||||
string updateStart = 24;
|
||||
string updateEnd = 25;
|
||||
}
|
||||
message GetSupplierListResponse{
|
||||
uint64 total = 1;
|
||||
repeated SupplierInfo data = 2;
|
||||
uint64 page = 3;
|
||||
uint64 pageSize = 4;
|
||||
}
|
||||
message SupplierInfo{
|
||||
uint64 id = 1;
|
||||
uint64 owningEntityId = 2;
|
||||
string legalName = 3;
|
||||
string localName = 4;
|
||||
string abbreviationName = 5;
|
||||
uint64 countryOrRegionId = 6;
|
||||
string companyRegistrationNumber = 7;
|
||||
string supplierType = 8;
|
||||
string approvalStatus = 9;
|
||||
string approvalDate = 10;
|
||||
string lastReviewDate = 11;
|
||||
string legalEntityType = 12;
|
||||
string sanctionsCountryScreeningResult = 13;
|
||||
string keyFinancial = 14;
|
||||
string companyAddress = 15;
|
||||
string primaryContact = 16;
|
||||
string dataOwnerDepartment = 17;
|
||||
string basicCompanyInformation = 18;
|
||||
string linkAddress = 19;
|
||||
string supplementaryText = 20;
|
||||
repeated attachment attachments = 21;
|
||||
uint64 status = 22;
|
||||
string createdAt = 23;
|
||||
string updatedAt = 24;
|
||||
string supplierUniqueCode = 25;
|
||||
string owningEntityName = 26;
|
||||
string countryOrRegionCode = 27;
|
||||
}
|
||||
message UpdateSupplierRequest{
|
||||
uint64 id = 1;
|
||||
uint64 owningEntityId = 2;
|
||||
string legalName = 3;
|
||||
string localName = 4;
|
||||
string abbreviationName = 5;
|
||||
uint64 countryOrRegionId = 6;
|
||||
string companyRegistrationNumber = 7;
|
||||
string supplierType = 8;
|
||||
string approvalStatus = 9;
|
||||
string approvalDate = 10;
|
||||
string lastReviewDate = 11;
|
||||
string legalEntityType = 12;
|
||||
string sanctionsCountryScreeningResult = 13;
|
||||
string keyFinancial = 14;
|
||||
string companyAddress = 15;
|
||||
string primaryContact = 16;
|
||||
string dataOwnerDepartment = 17;
|
||||
string basicCompanyInformation = 18;
|
||||
string linkAddress = 19;
|
||||
string supplementaryText = 20;
|
||||
repeated attachment attachments = 21;
|
||||
uint64 status = 22;
|
||||
}
|
||||
message CreateSupplierRequest{
|
||||
uint64 owningEntityId = 1;
|
||||
string legalName = 2;
|
||||
string localName = 3;
|
||||
string abbreviationName = 4;
|
||||
uint64 countryOrRegionId = 5;
|
||||
string companyRegistrationNumber = 6;
|
||||
string supplierType = 7;
|
||||
string approvalStatus = 8;
|
||||
string approvalDate = 9;
|
||||
string lastReviewDate = 10;
|
||||
string legalEntityType = 11;
|
||||
string sanctionsCountryScreeningResult = 12;
|
||||
string keyFinancial = 13;
|
||||
string companyAddress = 14;
|
||||
string primaryContact = 15;
|
||||
string dataOwnerDepartment = 16;
|
||||
string basicCompanyInformation = 17;
|
||||
string linkAddress = 18;
|
||||
string supplementaryText = 19;
|
||||
repeated attachment attachments = 20;
|
||||
uint64 status = 21;
|
||||
}
|
||||
message attachment{
|
||||
string url = 1;
|
||||
string type = 2;
|
||||
string name = 3;
|
||||
}
|
||||
message CreateSupplierResponse{
|
||||
uint64 id = 1;
|
||||
string supplierCode = 2;
|
||||
}
|
||||
message GetSupplierRequest{
|
||||
uint64 id = 1;
|
||||
}
|
||||
122
api/supplier/supplier.validator.pb.go
Normal file
122
api/supplier/supplier.validator.pb.go
Normal file
@ -0,0 +1,122 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: api/supplier/supplier.proto
|
||||
|
||||
package supplier
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
math "math"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
func (this *GetImportRecordRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetImportRecordResponse) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *CreateImportRecordRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *CreateImportRecordResponse) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetCountryRegionListResponse) Validate() error {
|
||||
for _, item := range this.Data {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *CountryRegion) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetCountryRegionInfoRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetCountryRegionListRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *OrganizeDictionary) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetOrganizeDictionaryListResponse) Validate() error {
|
||||
for _, item := range this.Data {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *CreateOrganizeDictionaryRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *CreateOrganizeDictionaryResponse) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetOrganizeDictionaryListRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetSupplierListRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetSupplierListResponse) Validate() error {
|
||||
for _, item := range this.Data {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *SupplierInfo) Validate() error {
|
||||
for _, item := range this.Attachments {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Attachments", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *UpdateSupplierRequest) Validate() error {
|
||||
for _, item := range this.Attachments {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Attachments", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *CreateSupplierRequest) Validate() error {
|
||||
for _, item := range this.Attachments {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("Attachments", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *Attachment) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *CreateSupplierResponse) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *GetSupplierRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
605
api/supplier/supplier_triple.pb.go
Normal file
605
api/supplier/supplier_triple.pb.go
Normal file
@ -0,0 +1,605 @@
|
||||
// Code generated by protoc-gen-go-triple. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-triple v1.0.5
|
||||
// - protoc v6.32.0
|
||||
// source: api/supplier/supplier.proto
|
||||
|
||||
package supplier
|
||||
|
||||
import (
|
||||
context "context"
|
||||
protocol "dubbo.apache.org/dubbo-go/v3/protocol"
|
||||
dubbo3 "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3"
|
||||
invocation "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
|
||||
grpc_go "github.com/dubbogo/grpc-go"
|
||||
codes "github.com/dubbogo/grpc-go/codes"
|
||||
metadata "github.com/dubbogo/grpc-go/metadata"
|
||||
status "github.com/dubbogo/grpc-go/status"
|
||||
common "github.com/dubbogo/triple/pkg/common"
|
||||
constant "github.com/dubbogo/triple/pkg/common/constant"
|
||||
triple "github.com/dubbogo/triple/pkg/triple"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc_go.SupportPackageIsVersion7
|
||||
|
||||
// SupplierClient is the client API for Supplier 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 SupplierClient interface {
|
||||
// 供应商curd
|
||||
GetSupplier(ctx context.Context, in *GetSupplierRequest, opts ...grpc_go.CallOption) (*UpdateSupplierRequest, common.ErrorWithAttachment)
|
||||
CreateSupplier(ctx context.Context, in *CreateSupplierRequest, opts ...grpc_go.CallOption) (*CreateSupplierResponse, common.ErrorWithAttachment)
|
||||
UpdateSupplier(ctx context.Context, in *UpdateSupplierRequest, opts ...grpc_go.CallOption) (*CreateSupplierResponse, common.ErrorWithAttachment)
|
||||
GetSupplierList(ctx context.Context, in *GetSupplierListRequest, opts ...grpc_go.CallOption) (*GetSupplierListResponse, common.ErrorWithAttachment)
|
||||
// 组织字典
|
||||
CreateOrganizeDictionary(ctx context.Context, in *CreateOrganizeDictionaryRequest, opts ...grpc_go.CallOption) (*CreateOrganizeDictionaryResponse, common.ErrorWithAttachment)
|
||||
GetOrganizeDictionaryList(ctx context.Context, in *GetOrganizeDictionaryListRequest, opts ...grpc_go.CallOption) (*GetOrganizeDictionaryListResponse, common.ErrorWithAttachment)
|
||||
GetOrganizeDictionaryInfo(ctx context.Context, in *CreateOrganizeDictionaryRequest, opts ...grpc_go.CallOption) (*OrganizeDictionary, common.ErrorWithAttachment)
|
||||
// 国家组织
|
||||
GetCountryRegionList(ctx context.Context, in *GetCountryRegionListRequest, opts ...grpc_go.CallOption) (*GetCountryRegionListResponse, common.ErrorWithAttachment)
|
||||
GetCountryRegionInfo(ctx context.Context, in *GetCountryRegionInfoRequest, opts ...grpc_go.CallOption) (*CountryRegion, common.ErrorWithAttachment)
|
||||
// 导入
|
||||
CreateImportRecord(ctx context.Context, in *CreateImportRecordRequest, opts ...grpc_go.CallOption) (*CreateImportRecordResponse, common.ErrorWithAttachment)
|
||||
GetImportRecordInfo(ctx context.Context, in *GetImportRecordRequest, opts ...grpc_go.CallOption) (*GetImportRecordResponse, common.ErrorWithAttachment)
|
||||
}
|
||||
|
||||
type supplierClient struct {
|
||||
cc *triple.TripleConn
|
||||
}
|
||||
|
||||
type SupplierClientImpl struct {
|
||||
GetSupplier func(ctx context.Context, in *GetSupplierRequest) (*UpdateSupplierRequest, error)
|
||||
CreateSupplier func(ctx context.Context, in *CreateSupplierRequest) (*CreateSupplierResponse, error)
|
||||
UpdateSupplier func(ctx context.Context, in *UpdateSupplierRequest) (*CreateSupplierResponse, error)
|
||||
GetSupplierList func(ctx context.Context, in *GetSupplierListRequest) (*GetSupplierListResponse, error)
|
||||
CreateOrganizeDictionary func(ctx context.Context, in *CreateOrganizeDictionaryRequest) (*CreateOrganizeDictionaryResponse, error)
|
||||
GetOrganizeDictionaryList func(ctx context.Context, in *GetOrganizeDictionaryListRequest) (*GetOrganizeDictionaryListResponse, error)
|
||||
GetOrganizeDictionaryInfo func(ctx context.Context, in *CreateOrganizeDictionaryRequest) (*OrganizeDictionary, error)
|
||||
GetCountryRegionList func(ctx context.Context, in *GetCountryRegionListRequest) (*GetCountryRegionListResponse, error)
|
||||
GetCountryRegionInfo func(ctx context.Context, in *GetCountryRegionInfoRequest) (*CountryRegion, error)
|
||||
CreateImportRecord func(ctx context.Context, in *CreateImportRecordRequest) (*CreateImportRecordResponse, error)
|
||||
GetImportRecordInfo func(ctx context.Context, in *GetImportRecordRequest) (*GetImportRecordResponse, error)
|
||||
}
|
||||
|
||||
func (c *SupplierClientImpl) GetDubboStub(cc *triple.TripleConn) SupplierClient {
|
||||
return NewSupplierClient(cc)
|
||||
}
|
||||
|
||||
func (c *SupplierClientImpl) XXX_InterfaceName() string {
|
||||
return "supplier.Supplier"
|
||||
}
|
||||
|
||||
func NewSupplierClient(cc *triple.TripleConn) SupplierClient {
|
||||
return &supplierClient{cc}
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetSupplier(ctx context.Context, in *GetSupplierRequest, opts ...grpc_go.CallOption) (*UpdateSupplierRequest, common.ErrorWithAttachment) {
|
||||
out := new(UpdateSupplierRequest)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetSupplier", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) CreateSupplier(ctx context.Context, in *CreateSupplierRequest, opts ...grpc_go.CallOption) (*CreateSupplierResponse, common.ErrorWithAttachment) {
|
||||
out := new(CreateSupplierResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CreateSupplier", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) UpdateSupplier(ctx context.Context, in *UpdateSupplierRequest, opts ...grpc_go.CallOption) (*CreateSupplierResponse, common.ErrorWithAttachment) {
|
||||
out := new(CreateSupplierResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/UpdateSupplier", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetSupplierList(ctx context.Context, in *GetSupplierListRequest, opts ...grpc_go.CallOption) (*GetSupplierListResponse, common.ErrorWithAttachment) {
|
||||
out := new(GetSupplierListResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetSupplierList", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) CreateOrganizeDictionary(ctx context.Context, in *CreateOrganizeDictionaryRequest, opts ...grpc_go.CallOption) (*CreateOrganizeDictionaryResponse, common.ErrorWithAttachment) {
|
||||
out := new(CreateOrganizeDictionaryResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CreateOrganizeDictionary", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetOrganizeDictionaryList(ctx context.Context, in *GetOrganizeDictionaryListRequest, opts ...grpc_go.CallOption) (*GetOrganizeDictionaryListResponse, common.ErrorWithAttachment) {
|
||||
out := new(GetOrganizeDictionaryListResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetOrganizeDictionaryList", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetOrganizeDictionaryInfo(ctx context.Context, in *CreateOrganizeDictionaryRequest, opts ...grpc_go.CallOption) (*OrganizeDictionary, common.ErrorWithAttachment) {
|
||||
out := new(OrganizeDictionary)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetOrganizeDictionaryInfo", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetCountryRegionList(ctx context.Context, in *GetCountryRegionListRequest, opts ...grpc_go.CallOption) (*GetCountryRegionListResponse, common.ErrorWithAttachment) {
|
||||
out := new(GetCountryRegionListResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetCountryRegionList", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetCountryRegionInfo(ctx context.Context, in *GetCountryRegionInfoRequest, opts ...grpc_go.CallOption) (*CountryRegion, common.ErrorWithAttachment) {
|
||||
out := new(CountryRegion)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetCountryRegionInfo", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) CreateImportRecord(ctx context.Context, in *CreateImportRecordRequest, opts ...grpc_go.CallOption) (*CreateImportRecordResponse, common.ErrorWithAttachment) {
|
||||
out := new(CreateImportRecordResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CreateImportRecord", in, out)
|
||||
}
|
||||
|
||||
func (c *supplierClient) GetImportRecordInfo(ctx context.Context, in *GetImportRecordRequest, opts ...grpc_go.CallOption) (*GetImportRecordResponse, common.ErrorWithAttachment) {
|
||||
out := new(GetImportRecordResponse)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetImportRecordInfo", in, out)
|
||||
}
|
||||
|
||||
// SupplierServer is the server API for Supplier service.
|
||||
// All implementations must embed UnimplementedSupplierServer
|
||||
// for forward compatibility
|
||||
type SupplierServer interface {
|
||||
// 供应商curd
|
||||
GetSupplier(context.Context, *GetSupplierRequest) (*UpdateSupplierRequest, error)
|
||||
CreateSupplier(context.Context, *CreateSupplierRequest) (*CreateSupplierResponse, error)
|
||||
UpdateSupplier(context.Context, *UpdateSupplierRequest) (*CreateSupplierResponse, error)
|
||||
GetSupplierList(context.Context, *GetSupplierListRequest) (*GetSupplierListResponse, error)
|
||||
// 组织字典
|
||||
CreateOrganizeDictionary(context.Context, *CreateOrganizeDictionaryRequest) (*CreateOrganizeDictionaryResponse, error)
|
||||
GetOrganizeDictionaryList(context.Context, *GetOrganizeDictionaryListRequest) (*GetOrganizeDictionaryListResponse, error)
|
||||
GetOrganizeDictionaryInfo(context.Context, *CreateOrganizeDictionaryRequest) (*OrganizeDictionary, error)
|
||||
// 国家组织
|
||||
GetCountryRegionList(context.Context, *GetCountryRegionListRequest) (*GetCountryRegionListResponse, error)
|
||||
GetCountryRegionInfo(context.Context, *GetCountryRegionInfoRequest) (*CountryRegion, error)
|
||||
// 导入
|
||||
CreateImportRecord(context.Context, *CreateImportRecordRequest) (*CreateImportRecordResponse, error)
|
||||
GetImportRecordInfo(context.Context, *GetImportRecordRequest) (*GetImportRecordResponse, error)
|
||||
mustEmbedUnimplementedSupplierServer()
|
||||
}
|
||||
|
||||
// UnimplementedSupplierServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedSupplierServer struct {
|
||||
proxyImpl protocol.Invoker
|
||||
}
|
||||
|
||||
func (UnimplementedSupplierServer) GetSupplier(context.Context, *GetSupplierRequest) (*UpdateSupplierRequest, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSupplier not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) CreateSupplier(context.Context, *CreateSupplierRequest) (*CreateSupplierResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateSupplier not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) UpdateSupplier(context.Context, *UpdateSupplierRequest) (*CreateSupplierResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateSupplier not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetSupplierList(context.Context, *GetSupplierListRequest) (*GetSupplierListResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSupplierList not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) CreateOrganizeDictionary(context.Context, *CreateOrganizeDictionaryRequest) (*CreateOrganizeDictionaryResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateOrganizeDictionary not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetOrganizeDictionaryList(context.Context, *GetOrganizeDictionaryListRequest) (*GetOrganizeDictionaryListResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetOrganizeDictionaryList not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetOrganizeDictionaryInfo(context.Context, *CreateOrganizeDictionaryRequest) (*OrganizeDictionary, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetOrganizeDictionaryInfo not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetCountryRegionList(context.Context, *GetCountryRegionListRequest) (*GetCountryRegionListResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetCountryRegionList not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetCountryRegionInfo(context.Context, *GetCountryRegionInfoRequest) (*CountryRegion, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetCountryRegionInfo not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) CreateImportRecord(context.Context, *CreateImportRecordRequest) (*CreateImportRecordResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateImportRecord not implemented")
|
||||
}
|
||||
func (UnimplementedSupplierServer) GetImportRecordInfo(context.Context, *GetImportRecordRequest) (*GetImportRecordResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetImportRecordInfo not implemented")
|
||||
}
|
||||
func (s *UnimplementedSupplierServer) XXX_SetProxyImpl(impl protocol.Invoker) {
|
||||
s.proxyImpl = impl
|
||||
}
|
||||
|
||||
func (s *UnimplementedSupplierServer) XXX_GetProxyImpl() protocol.Invoker {
|
||||
return s.proxyImpl
|
||||
}
|
||||
|
||||
func (s *UnimplementedSupplierServer) XXX_ServiceDesc() *grpc_go.ServiceDesc {
|
||||
return &Supplier_ServiceDesc
|
||||
}
|
||||
func (s *UnimplementedSupplierServer) XXX_InterfaceName() string {
|
||||
return "supplier.Supplier"
|
||||
}
|
||||
|
||||
func (UnimplementedSupplierServer) mustEmbedUnimplementedSupplierServer() {}
|
||||
|
||||
// UnsafeSupplierServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to SupplierServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeSupplierServer interface {
|
||||
mustEmbedUnimplementedSupplierServer()
|
||||
}
|
||||
|
||||
func RegisterSupplierServer(s grpc_go.ServiceRegistrar, srv SupplierServer) {
|
||||
s.RegisterService(&Supplier_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Supplier_GetSupplier_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSupplierRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetSupplier", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_CreateSupplier_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateSupplierRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("CreateSupplier", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_UpdateSupplier_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateSupplierRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("UpdateSupplier", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetSupplierList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSupplierListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetSupplierList", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_CreateOrganizeDictionary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateOrganizeDictionaryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("CreateOrganizeDictionary", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetOrganizeDictionaryList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetOrganizeDictionaryListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetOrganizeDictionaryList", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetOrganizeDictionaryInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateOrganizeDictionaryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetOrganizeDictionaryInfo", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetCountryRegionList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetCountryRegionListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetCountryRegionList", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetCountryRegionInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetCountryRegionInfoRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetCountryRegionInfo", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_CreateImportRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateImportRecordRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("CreateImportRecord", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Supplier_GetImportRecordInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetImportRecordRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("GetImportRecordInfo", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Supplier_ServiceDesc is the grpc_go.ServiceDesc for Supplier service.
|
||||
// It's only intended for direct use with grpc_go.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Supplier_ServiceDesc = grpc_go.ServiceDesc{
|
||||
ServiceName: "supplier.Supplier",
|
||||
HandlerType: (*SupplierServer)(nil),
|
||||
Methods: []grpc_go.MethodDesc{
|
||||
{
|
||||
MethodName: "GetSupplier",
|
||||
Handler: _Supplier_GetSupplier_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateSupplier",
|
||||
Handler: _Supplier_CreateSupplier_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateSupplier",
|
||||
Handler: _Supplier_UpdateSupplier_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSupplierList",
|
||||
Handler: _Supplier_GetSupplierList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateOrganizeDictionary",
|
||||
Handler: _Supplier_CreateOrganizeDictionary_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetOrganizeDictionaryList",
|
||||
Handler: _Supplier_GetOrganizeDictionaryList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetOrganizeDictionaryInfo",
|
||||
Handler: _Supplier_GetOrganizeDictionaryInfo_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetCountryRegionList",
|
||||
Handler: _Supplier_GetCountryRegionList_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetCountryRegionInfo",
|
||||
Handler: _Supplier_GetCountryRegionInfo_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateImportRecord",
|
||||
Handler: _Supplier_CreateImportRecord_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetImportRecordInfo",
|
||||
Handler: _Supplier_GetImportRecordInfo_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc_go.StreamDesc{},
|
||||
Metadata: "api/supplier/supplier.proto",
|
||||
}
|
||||
15
cmd/app.go
15
cmd/app.go
@ -20,7 +20,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"fonchain-fiee/cmd/config"
|
||||
"fonchain-fiee/pkg/cache"
|
||||
"fonchain-fiee/pkg/common"
|
||||
cronpkg "fonchain-fiee/pkg/cron"
|
||||
"fonchain-fiee/pkg/logger"
|
||||
@ -50,14 +49,14 @@ func bootstrap() (err error) {
|
||||
|
||||
logger.LogInit(config.AppConfig)
|
||||
////redis
|
||||
redisConfig := cache.RedisConfig{
|
||||
RedisDB: configEnv.Redis.RedisDB,
|
||||
RedisAddr: configEnv.Redis.RedisAddr,
|
||||
RedisPw: configEnv.Redis.RedisPW,
|
||||
RedisDbName: configEnv.Redis.RedisDBNAme,
|
||||
}
|
||||
//redisConfig := cache.RedisConfig{
|
||||
// RedisDB: configEnv.Redis.RedisDB,
|
||||
// RedisAddr: configEnv.Redis.RedisAddr,
|
||||
// RedisPw: configEnv.Redis.RedisPW,
|
||||
// RedisDbName: configEnv.Redis.RedisDBNAme,
|
||||
//}
|
||||
|
||||
cache.LoadRedis(redisConfig)
|
||||
//cache.LoadRedis(redisConfig)
|
||||
common.Init()
|
||||
if configEnv.System.CronOpen {
|
||||
fmt.Println("启动定时任务管理器...")
|
||||
|
||||
@ -54,6 +54,9 @@ dubbo:
|
||||
FieeCronClientImpl:
|
||||
protocol: tri
|
||||
interface: com.fontree.microservices.fiee.cron
|
||||
SupplierClientImpl:
|
||||
protocol: tri
|
||||
interface: com.fontree.microservices.common.supplier
|
||||
logger:
|
||||
zap-config:
|
||||
level: error # 日志级别
|
||||
|
||||
@ -61,6 +61,9 @@ dubbo:
|
||||
methods:
|
||||
- name: SecurityScan
|
||||
timeout: 120000
|
||||
SupplierClientImpl:
|
||||
protocol: tri
|
||||
interface: com.fontree.microservices.common.supplier
|
||||
logger:
|
||||
zap-config:
|
||||
level: error # 日志级别
|
||||
|
||||
@ -63,6 +63,9 @@ dubbo:
|
||||
methods:
|
||||
- name: SecurityScan
|
||||
timeout: 120000
|
||||
SupplierClientImpl:
|
||||
protocol: tri
|
||||
interface: com.fontree.microservices.common.supplier
|
||||
logger:
|
||||
zap-config:
|
||||
level: error # 日志级别
|
||||
|
||||
@ -61,6 +61,9 @@ dubbo:
|
||||
methods:
|
||||
- name: SecurityScan
|
||||
timeout: 120000
|
||||
SupplierClientImpl:
|
||||
protocol: tri
|
||||
interface: com.fontree.microservices.common.supplier
|
||||
logger:
|
||||
zap-config:
|
||||
level: error # 日志级别
|
||||
|
||||
178
pkg/logic/supplier.go
Normal file
178
pkg/logic/supplier.go
Normal file
@ -0,0 +1,178 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tealeg/xlsx"
|
||||
)
|
||||
|
||||
type SupplierLogic struct {
|
||||
OwningEntityName string `json:"owningEntityName"`
|
||||
LegalName string `json:"legalName"`
|
||||
LocalName string `json:"localName"`
|
||||
AbbreviationName string `json:"abbreviationName"`
|
||||
CountryOrRegionName string `json:"countryOrRegionName"`
|
||||
CompanyRegistrationNumber string `json:"companyRegistrationNumber"`
|
||||
SupplierType string `json:"supplierType"`
|
||||
ApprovalStatus string `json:"approvalStatus"`
|
||||
ApprovalDate string `json:"approvalDate"`
|
||||
LastReviewDate string `json:"lastReviewDate"`
|
||||
LegalEntityType string `json:"legalEntityType"`
|
||||
SanctionsCountryScreeningResult string `json:"sanctionsCountryScreeningResult"`
|
||||
KeyFinancial string `json:"keyFinancial"`
|
||||
CompanyAddress string `json:"companyAddress"`
|
||||
PrimaryContact string `json:"primaryContact"`
|
||||
DataOwnerDepartment string `json:"dataOwnerDepartment"`
|
||||
BasicCompanyInformation string `json:"basicCompanyInformation"`
|
||||
SupplementaryText string `json:"supplementaryText"`
|
||||
}
|
||||
type ErrSupplierRes struct {
|
||||
ID int `json:"id"`
|
||||
LegalName string `json:"legalName"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func ImportSupplier(filePath string) ([]*SupplierLogic, error) {
|
||||
xlFile, err := xlsx.OpenFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//开辟除表头外的行数的数组内存
|
||||
//遍历sheet
|
||||
for sheetIndex, sheet := range xlFile.Sheets {
|
||||
var resourceArr []map[int]string
|
||||
//遍历每一行
|
||||
//for rowIndex, row := range sheet.Rows {
|
||||
for _, row := range sheet.Rows {
|
||||
//开辟除表头外的行数的数组内存
|
||||
objMap := make(map[int]string)
|
||||
|
||||
//if len(row.Cells) <= 0 || row.Cells[0].String() == "" {
|
||||
// continue
|
||||
//}
|
||||
for cellIndex, cell := range row.Cells {
|
||||
text := cell.String()
|
||||
//如果是每一行的第一个单元格
|
||||
objMap[cellIndex] = text
|
||||
}
|
||||
resourceArr = append(resourceArr, objMap)
|
||||
}
|
||||
if len(resourceArr) >= 2 {
|
||||
suppliers, err := getListFromRaw(resourceArr)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("页码:%d,文件读取错误信息%s", sheetIndex+1, err.Error()))
|
||||
}
|
||||
if len(suppliers) > 0 {
|
||||
return suppliers, nil
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
func getListFromRaw(list []map[int]string) ([]*SupplierLogic, error) {
|
||||
var entrusts []*SupplierLogic
|
||||
kkMap := map[string]string{
|
||||
"*使用组织/Owning Entity": "owningEntityName",
|
||||
"*供应商法定全称/Legal Name": "legalName",
|
||||
"供应商本地名称(如有)/Local Name (if applicable)": "localName",
|
||||
"供应商简称(如有)/Abbreviation/Trade Name (if applicable)": "abbreviationName",
|
||||
"*所在国家或地区/Country or Region": "countryOrRegionName",
|
||||
"*公司注册编号/Company Registration Number": "companyRegistrationNumber",
|
||||
"*供应商类型/Supplier Type": "supplierType",
|
||||
"*准入状态/Approval Status": "approvalStatus",
|
||||
"准入日期/Approval Date": "approvalDate",
|
||||
"法律实体形式/Legal Entity Type": "legalEntityType",
|
||||
"制裁与高风险国家筛查结果/Sanctions & High-Risk Country Screening Result": "sanctionsCountryScreeningResult",
|
||||
"关键财务与付款信息/Key Financial & Payment Information": "keyFinancial",
|
||||
"公司地址/Company Address": "companyAddress",
|
||||
"主要联系人、职位及联系方式/Primary Contact, Position&Details": "primaryContact",
|
||||
"数据维护部门&人员/Data Owner Department/Personnel": "dataOwnerDepartment",
|
||||
"公司信息概要/Summary of Basic Company Information": "basicCompanyInformation",
|
||||
"其他补充信息/Other Supplementary Information": "supplementaryText",
|
||||
}
|
||||
keyMap := list[0]
|
||||
for index, tt := range list {
|
||||
if index == 0 {
|
||||
continue
|
||||
}
|
||||
temp := &SupplierLogic{}
|
||||
for i, r := range tt {
|
||||
t := strings.TrimSpace(r)
|
||||
if _, ok := keyMap[i]; !ok {
|
||||
continue
|
||||
}
|
||||
keyString := strings.TrimSpace(keyMap[i])
|
||||
if _, ok := kkMap[keyString]; !ok {
|
||||
fmt.Println(fmt.Sprintf("行数:%d字段信息(%s)没有匹配,请以模版为准", i, keyString))
|
||||
continue
|
||||
}
|
||||
switch kkMap[keyString] {
|
||||
case "owningEntityName":
|
||||
temp.OwningEntityName = t
|
||||
case "legalName":
|
||||
temp.LegalName = t
|
||||
case "localName":
|
||||
temp.LocalName = t
|
||||
case "abbreviationName":
|
||||
temp.AbbreviationName = t
|
||||
case "countryOrRegionName":
|
||||
temp.CountryOrRegionName = t
|
||||
case "companyRegistrationNumber":
|
||||
temp.CompanyRegistrationNumber = t
|
||||
case "supplierType":
|
||||
temp.SupplierType = t
|
||||
case "approvalStatus":
|
||||
temp.ApprovalStatus = t
|
||||
case "approvalDate":
|
||||
temp.ApprovalDate = ParseExcelDate(t)
|
||||
//temp.ApprovalDate = t
|
||||
case "legalEntityType":
|
||||
temp.LegalEntityType = t
|
||||
case "sanctionsCountryScreeningResult":
|
||||
temp.SanctionsCountryScreeningResult = t
|
||||
case "keyFinancial":
|
||||
temp.KeyFinancial = t
|
||||
case "companyAddress":
|
||||
temp.CompanyAddress = t
|
||||
case "primaryContact":
|
||||
temp.PrimaryContact = t
|
||||
case "dataOwnerDepartment":
|
||||
temp.DataOwnerDepartment = t
|
||||
case "basicCompanyInformation":
|
||||
temp.BasicCompanyInformation = t
|
||||
case "supplementaryText":
|
||||
temp.SupplementaryText = t
|
||||
|
||||
}
|
||||
}
|
||||
entrusts = append(entrusts, temp)
|
||||
}
|
||||
sha256.New()
|
||||
return entrusts, nil
|
||||
}
|
||||
func ParseExcelDate(v string) string {
|
||||
if v == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 非数字,直接认为是 yyyy-mm-dd
|
||||
if _, err := strconv.ParseFloat(v, 64); err != nil {
|
||||
t, err := time.Parse("2006-01-02", v)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return t.Format("2006-01-02")
|
||||
}
|
||||
|
||||
// Excel 序列号
|
||||
f, _ := strconv.ParseFloat(v, 64)
|
||||
base := time.Date(1899, 12, 30, 0, 0, 0, 0, time.Local)
|
||||
return base.AddDate(0, 0, int(f)).Format("2006-01-02")
|
||||
}
|
||||
@ -58,6 +58,7 @@ func NewRouter() *gin.Engine {
|
||||
SecFilingRouter(privateGroup)
|
||||
app.MediaAppRouter(privateGroup)
|
||||
cronRouter(privateGroup)
|
||||
SupplierRouter(privateGroup)
|
||||
{
|
||||
v1.POST("version", version.Version) //版本号公共
|
||||
}
|
||||
|
||||
35
pkg/router/supplier.go
Normal file
35
pkg/router/supplier.go
Normal file
@ -0,0 +1,35 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fonchain-fiee/pkg/middleware"
|
||||
"fonchain-fiee/pkg/service"
|
||||
"fonchain-fiee/pkg/service/supplier"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func SupplierRouter(r *gin.RouterGroup) {
|
||||
|
||||
supplierRoute := r.Group("supplier/web")
|
||||
|
||||
supplierRoute.Use(middleware.CheckWebLogin(service.AccountProvider))
|
||||
{
|
||||
supplierRoute.POST("info", supplier.GetSupplier)
|
||||
supplierRoute.POST("create", supplier.CreateSupplier)
|
||||
supplierRoute.POST("update", supplier.UpdateSupplier)
|
||||
supplierRoute.POST("list", supplier.GetSupplierList)
|
||||
}
|
||||
{
|
||||
supplierRoute.POST("dictionary/create", supplier.CreateOrganizeDictionary)
|
||||
supplierRoute.POST("dictionary/list", supplier.GetOrganizeDictionaryList)
|
||||
}
|
||||
{
|
||||
supplierRoute.POST("country-region/list", supplier.GetCountryRegionList)
|
||||
}
|
||||
{
|
||||
supplierRoute.POST("import/record", supplier.CreateImportRecord)
|
||||
supplierRoute.POST("import/info", supplier.GetImportRecordInfo)
|
||||
supplierRoute.POST("export/list", supplier.GetExportList)
|
||||
}
|
||||
|
||||
}
|
||||
@ -47,7 +47,7 @@ func NewChatHandler() ChatHandler {
|
||||
c := ChatHandler{
|
||||
cache: chatCache.ChatCache{NewMessageStatExpireAfter: 10 * time.Minute},
|
||||
}
|
||||
c.robot = robot.NewRobot(&c.cache)
|
||||
//c.robot = robot.NewRobot(&c.cache)
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"fonchain-fiee/api/payment"
|
||||
"fonchain-fiee/api/pressreleases"
|
||||
"fonchain-fiee/api/secFilings"
|
||||
"fonchain-fiee/api/supplier"
|
||||
pkConfig "fonchain-fiee/pkg/config"
|
||||
"os"
|
||||
|
||||
@ -35,20 +36,22 @@ var PressReleasesProvider = new(pressreleases.PressReleasesClientImpl)
|
||||
var SecFilingProvider = new(secFilings.SecFilingsClientImpl)
|
||||
var AyrshareProvider = new(aryshare.AyrshareClientImpl)
|
||||
var CronProvider = new(cron.CronClientImpl)
|
||||
var SupplierProvider = new(supplier.SupplierClientImpl)
|
||||
|
||||
func init() {
|
||||
config.SetConsumerService(BundleProvider)
|
||||
config.SetConsumerService(OrderProvider)
|
||||
//config.SetConsumerService(BundleProvider)
|
||||
//config.SetConsumerService(OrderProvider)
|
||||
config.SetConsumerService(AccountProvider)
|
||||
config.SetConsumerService(PaymentProvider)
|
||||
config.SetConsumerService(AccountFieeProvider)
|
||||
config.SetConsumerService(CastProvider)
|
||||
config.SetConsumerService(FilesProvider)
|
||||
config.SetConsumerService(GovernanceProvider)
|
||||
config.SetConsumerService(PressReleasesProvider)
|
||||
config.SetConsumerService(SecFilingProvider)
|
||||
config.SetConsumerService(AyrshareProvider)
|
||||
config.SetConsumerService(CronProvider)
|
||||
//config.SetConsumerService(PaymentProvider)
|
||||
//config.SetConsumerService(AccountFieeProvider)
|
||||
//config.SetConsumerService(CastProvider)
|
||||
//config.SetConsumerService(FilesProvider)
|
||||
//config.SetConsumerService(GovernanceProvider)
|
||||
//config.SetConsumerService(PressReleasesProvider)
|
||||
//config.SetConsumerService(SecFilingProvider)
|
||||
//config.SetConsumerService(AyrshareProvider)
|
||||
//config.SetConsumerService(CronProvider)
|
||||
config.SetConsumerService(SupplierProvider)
|
||||
|
||||
if err := config.Load(); err != nil {
|
||||
panic(err)
|
||||
|
||||
391
pkg/service/supplier/supplier.go
Normal file
391
pkg/service/supplier/supplier.go
Normal file
@ -0,0 +1,391 @@
|
||||
package supplier
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fonchain-fiee/api/supplier"
|
||||
"fonchain-fiee/pkg/logic"
|
||||
"fonchain-fiee/pkg/model/login"
|
||||
"fonchain-fiee/pkg/service"
|
||||
"fonchain-fiee/pkg/service/upload"
|
||||
"fonchain-fiee/pkg/utils"
|
||||
"fonchain-fiee/pkg/utils/excel"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func GetSupplier(c *gin.Context) {
|
||||
req := &supplier.GetSupplierRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.GetSupplier(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
func CreateSupplier(c *gin.Context) {
|
||||
req := &supplier.CreateSupplierRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.CreateSupplier(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateSupplier(c *gin.Context) {
|
||||
req := &supplier.UpdateSupplierRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
info, err := service.SupplierProvider.GetSupplier(c, &supplier.GetSupplierRequest{Id: req.Id})
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
if info.Status == 3 {
|
||||
service.Error(c, errors.New("审核中不可修改")) //todo 修改:审核中并且存在审核人 不可修改
|
||||
return
|
||||
}
|
||||
if req.Status != 1 && req.Status != 2 {
|
||||
service.Error(c, errors.New("审批状态错误")) //todo 只允许前端暂存或提交审核申请
|
||||
}
|
||||
res, err := service.SupplierProvider.UpdateSupplier(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func GetSupplierList(c *gin.Context) {
|
||||
req := &supplier.GetSupplierListRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.GetSupplierList(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func CreateOrganizeDictionary(c *gin.Context) {
|
||||
req := &supplier.CreateOrganizeDictionaryRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.CreateOrganizeDictionary(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func GetOrganizeDictionaryList(c *gin.Context) {
|
||||
req := &supplier.GetOrganizeDictionaryListRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.GetOrganizeDictionaryList(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func GetCountryRegionList(c *gin.Context) {
|
||||
req := &supplier.GetCountryRegionListRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.GetCountryRegionList(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func CreateImportRecord(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
}
|
||||
safeFilename := fmt.Sprintf("%d", time.Now().Unix()) + "_" + file.Filename
|
||||
userInfo := login.GetUserInfoFromC(c)
|
||||
fileDir := fmt.Sprintf("/fiee/supplier/%s/%s_%s", time.Now().Format("2006-01-02"), userInfo.Name, safeFilename)
|
||||
// 保存上传的文件到本地
|
||||
if err = c.SaveUploadedFile(file, safeFilename); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err := os.Remove(safeFilename); err != nil {
|
||||
// 处理删除文件失败的情况
|
||||
fmt.Println("Failed to delete file:", err)
|
||||
}
|
||||
}()
|
||||
inputUrl, err := upload.PutBosWithName(safeFilename, false, fileDir)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
supplierList, err := logic.ImportSupplier(safeFilename)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
if len(supplierList) == 0 {
|
||||
service.Error(c, errors.New("导入数据为空"))
|
||||
return
|
||||
}
|
||||
uuid, _ := uuid.NewUUID()
|
||||
var SuccessNum uint64
|
||||
var SupplierCodes []string
|
||||
var ErrSupplierRes []*logic.ErrSupplierRes
|
||||
for idx, i := range supplierList {
|
||||
rowNum := idx + 1
|
||||
if i.OwningEntityName == "" || i.LegalName == "" || i.CountryOrRegionName == "" || i.CompanyRegistrationNumber == "" || i.SupplierType == "" || i.ApprovalStatus == "" {
|
||||
ErrSupplierRes = append(ErrSupplierRes, &logic.ErrSupplierRes{
|
||||
ID: rowNum,
|
||||
LegalName: i.LegalName,
|
||||
Remark: "必填项存在空值",
|
||||
})
|
||||
continue
|
||||
}
|
||||
OwningEntityRes, _ := service.SupplierProvider.GetOrganizeDictionaryInfo(c, &supplier.CreateOrganizeDictionaryRequest{Name: i.OwningEntityName})
|
||||
if OwningEntityRes == nil || OwningEntityRes.Id == 0 {
|
||||
ErrSupplierRes = append(ErrSupplierRes, &logic.ErrSupplierRes{
|
||||
ID: rowNum,
|
||||
LegalName: i.LegalName,
|
||||
Remark: "所属组织不存在",
|
||||
})
|
||||
continue
|
||||
}
|
||||
countryRegionRes, _ := service.SupplierProvider.GetCountryRegionInfo(c, &supplier.GetCountryRegionInfoRequest{ZhAndCode: i.CountryOrRegionName})
|
||||
if countryRegionRes == nil || countryRegionRes.Id == 0 {
|
||||
ErrSupplierRes = append(ErrSupplierRes, &logic.ErrSupplierRes{
|
||||
ID: rowNum,
|
||||
LegalName: i.LegalName,
|
||||
Remark: "所属国家或地区不存在",
|
||||
})
|
||||
continue
|
||||
}
|
||||
var LastReviewDate string
|
||||
if i.ApprovalDate != "" {
|
||||
t, err := time.Parse("2006-01-02", i.ApprovalDate)
|
||||
if err != nil {
|
||||
LastReviewDate = ""
|
||||
i.ApprovalDate = ""
|
||||
} else {
|
||||
LastReviewDate = t.AddDate(1, 0, 0).Format("2006-01-02")
|
||||
}
|
||||
}
|
||||
createRes, err := service.SupplierProvider.CreateSupplier(c, &supplier.CreateSupplierRequest{
|
||||
OwningEntityId: OwningEntityRes.Id,
|
||||
LegalName: i.LegalName,
|
||||
LocalName: i.LocalName,
|
||||
AbbreviationName: i.AbbreviationName,
|
||||
CountryOrRegionId: countryRegionRes.Id,
|
||||
CompanyRegistrationNumber: i.CompanyRegistrationNumber,
|
||||
SupplierType: i.SupplierType,
|
||||
ApprovalStatus: i.ApprovalStatus,
|
||||
ApprovalDate: i.ApprovalDate,
|
||||
LastReviewDate: LastReviewDate,
|
||||
LegalEntityType: i.LegalEntityType,
|
||||
SanctionsCountryScreeningResult: i.SanctionsCountryScreeningResult,
|
||||
KeyFinancial: i.KeyFinancial,
|
||||
CompanyAddress: i.CompanyAddress,
|
||||
PrimaryContact: i.PrimaryContact,
|
||||
DataOwnerDepartment: i.DataOwnerDepartment,
|
||||
BasicCompanyInformation: i.BasicCompanyInformation,
|
||||
SupplementaryText: i.SupplementaryText,
|
||||
Status: 1,
|
||||
})
|
||||
if err != nil {
|
||||
ErrSupplierRes = append(ErrSupplierRes, &logic.ErrSupplierRes{
|
||||
ID: rowNum,
|
||||
LegalName: i.LegalName,
|
||||
Remark: err.Error(),
|
||||
})
|
||||
continue
|
||||
} else {
|
||||
SupplierCodes = append(SupplierCodes, createRes.SupplierCode)
|
||||
SuccessNum++
|
||||
}
|
||||
|
||||
}
|
||||
status := 2
|
||||
outUrl := ""
|
||||
if len(ErrSupplierRes) == 0 {
|
||||
status = 1
|
||||
} else {
|
||||
var sheet1Columns = []string{"行数", "供应商法定全称", "错误信息"}
|
||||
var sheet1 = excel.NewSheet("Sheet1", ErrSupplierRes, sheet1Columns)
|
||||
ex, err := excel.NewExcelCreatorFromTemplate("./mistake.xlsx", "./supplier/excel/", "", sheet1)
|
||||
ex.UseOption(excel.OptionFileNameSuffixWithUnixTime)
|
||||
path, _, err := ex.WriteToFile()
|
||||
outUrl, err = upload.PutBos(path, "", false)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
os.RemoveAll("./supplier")
|
||||
}()
|
||||
}
|
||||
req := &supplier.CreateImportRecordRequest{
|
||||
SupplierCodes: SupplierCodes,
|
||||
Status: uint64(status),
|
||||
UserId: userInfo.ID,
|
||||
ToLeadUrl: inputUrl,
|
||||
DeriveUrl: outUrl,
|
||||
Uuid: uuid.String(),
|
||||
SuccessNum: SuccessNum,
|
||||
FailNum: uint64(len(ErrSupplierRes)),
|
||||
}
|
||||
_, err = service.SupplierProvider.CreateImportRecord(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, req)
|
||||
return
|
||||
}
|
||||
|
||||
func GetImportRecordInfo(c *gin.Context) {
|
||||
req := &supplier.GetImportRecordRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
res, err := service.SupplierProvider.GetImportRecordInfo(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
service.Success(c, res)
|
||||
return
|
||||
}
|
||||
|
||||
func GetExportList(c *gin.Context) {
|
||||
req := &supplier.GetSupplierListRequest{}
|
||||
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
infoRes, err := service.SupplierProvider.GetSupplierList(c, req)
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
// 定义标题列表
|
||||
titleList := []string{
|
||||
"状态/State", "使用组织/Owning Entity", "供应商唯一编码/SupplierUnique Code", "供应商法定全称(英文)/LegalName (English)", "供应商本地名称(如有)/LocalName (if applicable)",
|
||||
"所在国家或地区/Country or Region", "公司注册编号/Company RegistrationNumber", "供应商类型/Supplier Type", "准入状态/Approval Status", "准入日期/ApprovalDate",
|
||||
"法律实体形式/Legal Entity Type", "制裁与高风险国家筛查结果/Sanctions & High-RiskCountry Screening Result", "关键财务与付款信息/Key Financial & Payment Information",
|
||||
"公司地址/Company Address", "主要联系人、职位及联系方式/Primary Contact,Position&Details", "数据维护部门&人员/Data Owner Department/Personnel", "最后更新日期/Last Updated Date",
|
||||
"公司信息概要/Summary of Basic Company Information",
|
||||
}
|
||||
// 定义数据结构
|
||||
type DataInfo struct {
|
||||
Status string
|
||||
OwningEntity string
|
||||
SupplierUniqueCode string
|
||||
LegalName string
|
||||
LocalName string
|
||||
CountryOrRegion string
|
||||
CompanyRegistrationNumber string
|
||||
SupplierType string
|
||||
ApprovalStatus string
|
||||
ApprovalDate string
|
||||
LegalEntityType string
|
||||
SanctionsCountryScreeningResult string
|
||||
KeyFinancial string
|
||||
CompanyAddress string
|
||||
PrimaryContact string
|
||||
DataOwnerDepartment string
|
||||
UpdatedAt string
|
||||
BasicCompanyInformation string
|
||||
}
|
||||
// 创建员工ID到DataInfo的映射
|
||||
dataMap := make(map[string]*DataInfo)
|
||||
statusMap := map[uint64]string{
|
||||
1: "草稿",
|
||||
2: "审核中",
|
||||
3: "已驳回",
|
||||
4: "已成功",
|
||||
}
|
||||
for _, info := range infoRes.Data {
|
||||
dataMap[info.SupplierUniqueCode] = &DataInfo{
|
||||
Status: statusMap[info.Status],
|
||||
OwningEntity: info.OwningEntityName,
|
||||
SupplierUniqueCode: info.SupplierUniqueCode,
|
||||
LegalName: info.LegalName,
|
||||
LocalName: info.LocalName,
|
||||
CountryOrRegion: info.CountryOrRegionCode,
|
||||
CompanyRegistrationNumber: info.CompanyRegistrationNumber,
|
||||
SupplierType: info.SupplierType,
|
||||
ApprovalStatus: info.ApprovalStatus,
|
||||
ApprovalDate: info.ApprovalDate,
|
||||
LegalEntityType: info.LegalEntityType,
|
||||
SanctionsCountryScreeningResult: info.SanctionsCountryScreeningResult,
|
||||
KeyFinancial: info.KeyFinancial,
|
||||
CompanyAddress: info.CompanyAddress,
|
||||
PrimaryContact: info.PrimaryContact,
|
||||
DataOwnerDepartment: info.DataOwnerDepartment,
|
||||
UpdatedAt: info.UpdatedAt,
|
||||
BasicCompanyInformation: info.BasicCompanyInformation,
|
||||
}
|
||||
}
|
||||
// 生成最终数据列表
|
||||
var dataList []interface{}
|
||||
for _, data := range dataMap {
|
||||
dataList = append(dataList, &[]any{
|
||||
data.Status, data.OwningEntity, data.SupplierUniqueCode, data.LegalName, data.LocalName,
|
||||
data.CountryOrRegion, data.CompanyRegistrationNumber, data.SupplierType, data.ApprovalStatus, data.ApprovalDate,
|
||||
data.LegalEntityType, data.SanctionsCountryScreeningResult, data.KeyFinancial, data.CompanyAddress, data.PrimaryContact,
|
||||
data.DataOwnerDepartment, data.UpdatedAt, data.BasicCompanyInformation,
|
||||
})
|
||||
}
|
||||
|
||||
// 生成Excel文件
|
||||
content, err := utils.ToExcelByType(titleList, dataList, "slice", "")
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 返回Excel文件
|
||||
utils.ResponseXls(c, content, "供应商库")
|
||||
return
|
||||
}
|
||||
@ -12,14 +12,14 @@ import (
|
||||
"fonchain-fiee/pkg/model"
|
||||
"fonchain-fiee/pkg/service"
|
||||
"fonchain-fiee/pkg/utils"
|
||||
"io"
|
||||
|
||||
cmdConf "fonchain-fiee/cmd/config"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/fonchain_enterprise/utils/objstorage"
|
||||
"github.com/gin-gonic/gin"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"io"
|
||||
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/url"
|
||||
@ -28,6 +28,9 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -216,7 +219,7 @@ func quickBos(file *multipart.FileHeader, mediaType string, mask string, source
|
||||
return
|
||||
}
|
||||
}
|
||||
var objectName string = fmt.Sprintf("%s/%s/%s", config.ConfigData.Oss.BaseDir, config.Env, filePath)
|
||||
var objectName string = fmt.Sprintf("%s/%s/%s", config.ConfigData.Oss.BaseDir, cmdConf.AppConfig.System.AppMode, filePath)
|
||||
BOSClient, _ := objstorage.NewOSS(os.Getenv(config.ConfigData.Oss.AccessKeyId), os.Getenv(config.ConfigData.Oss.AccessKeySecret), os.Getenv(config.ConfigData.Oss.Endpoint))
|
||||
_, err = BOSClient.PutObjectFromBytes(os.Getenv(config.ConfigData.Oss.BucketName), objectName, fileBytes)
|
||||
if err != nil {
|
||||
@ -266,7 +269,8 @@ func BaiduCheckImage(imageByte []byte) (err error) {
|
||||
return nil
|
||||
}
|
||||
func PutBos(filePath string, mediaType string, needRemove bool) (url string, err error) {
|
||||
BOSClient, err := objstorage.NewOSS(os.Getenv(config.ConfigData.Oss.AccessKeyId), os.Getenv(config.ConfigData.Oss.AccessKeySecret), os.Getenv(config.ConfigData.Oss.Endpoint))
|
||||
//BOSClient, err := objstorage.NewOSS(os.Getenv(config.ConfigData.Oss.AccessKeyId), os.Getenv(config.ConfigData.Oss.AccessKeySecret), os.Getenv(config.ConfigData.Oss.Endpoint))
|
||||
BOSClient, err := objstorage.NewOSS(config.ConfigData.Oss.AccessKeyId, config.ConfigData.Oss.AccessKeySecret, config.ConfigData.Oss.Endpoint)
|
||||
if err != nil {
|
||||
fmt.Println("=== PutBos NewOss err ", err)
|
||||
//logger.Errorf("PutBos NewOss err ", err)
|
||||
@ -290,8 +294,9 @@ func PutBos(filePath string, mediaType string, needRemove bool) (url string, err
|
||||
}
|
||||
}
|
||||
filePath = strings.Replace(filePath, model.MediaPath, "", 1)
|
||||
var objectName string = fmt.Sprintf("%s/%s%s", config.ConfigData.Oss.BaseDir, config.Env, filePath)
|
||||
_, err = BOSClient.PutObjectFromBytes(os.Getenv(config.ConfigData.Oss.BucketName), objectName, fileBytes)
|
||||
var objectName string = fmt.Sprintf("%s/%s%s", config.ConfigData.Oss.BaseDir, cmdConf.AppConfig.System.AppMode, filePath)
|
||||
//_, err = BOSClient.PutObjectFromBytes(os.Getenv(config.ConfigData.Oss.BucketName), objectName, fileBytes)
|
||||
_, err = BOSClient.PutObjectFromBytes(config.ConfigData.Oss.BucketName, objectName, fileBytes)
|
||||
if err != nil {
|
||||
fmt.Println("=== PutBos PutObject err ", err)
|
||||
//logger.Errorf("PutBos PutObject err %+v", err.Error())
|
||||
@ -299,7 +304,8 @@ func PutBos(filePath string, mediaType string, needRemove bool) (url string, err
|
||||
return
|
||||
}
|
||||
//url = fmt.Sprintf("%s%s%s/%s", config.BosHttp, config.BosBucketName, config.BosUrl, objectName)
|
||||
url = fmt.Sprintf("%s/%s", os.Getenv(config.ConfigData.Oss.CdnHost), objectName)
|
||||
//url = fmt.Sprintf("%s/%s", os.Getenv(config.ConfigData.Oss.CdnHost), objectName)
|
||||
url = fmt.Sprintf("%s/%s", config.ConfigData.Oss.CdnHost, objectName)
|
||||
return
|
||||
}
|
||||
func GetSnapshot(videoPath, snapshotPath string, frameNum int) (snapshotName string, err error) {
|
||||
@ -347,3 +353,30 @@ func getEnvDir(cloudStoreSubPath string) (ep string) {
|
||||
ep, _ = url.JoinPath("fiee", cloudStoreSubPath)
|
||||
return ep
|
||||
}
|
||||
func PutBosWithName(filePath string, needRemove bool, ossPath string) (url string, err error) {
|
||||
//BOSClient, err := objstorage.NewOSS(os.Getenv(config.ConfigData.Oss.AccessKeyId), os.Getenv(config.ConfigData.Oss.AccessKeySecret), os.Getenv(config.ConfigData.Oss.Endpoint))
|
||||
BOSClient, err := objstorage.NewOSS(config.ConfigData.Oss.AccessKeyId, config.ConfigData.Oss.AccessKeySecret, config.ConfigData.Oss.Endpoint)
|
||||
if err != nil {
|
||||
//logger.Errorf("PutBosWithName err1 ", err)
|
||||
err = errors.New(e.GetMsg(e.ErrorUploadBos))
|
||||
return
|
||||
}
|
||||
if ossPath == "" {
|
||||
ossPath = filePath[1:]
|
||||
}
|
||||
var objectName string = fmt.Sprintf("%s/%s%s", config.ConfigData.Oss.BaseDir, cmdConf.AppConfig.System.AppMode, ossPath)
|
||||
//_, err = BOSClient.PutObject(os.Getenv(config.ConfigData.Oss.BucketName), objectName, filePath)
|
||||
_, err = BOSClient.PutObject(config.ConfigData.Oss.BucketName, objectName, filePath)
|
||||
if err != nil {
|
||||
//logger.Errorf("PutBosWithName err2 ", err)
|
||||
err = errors.New(e.GetMsg(e.ErrorUploadBos))
|
||||
return
|
||||
}
|
||||
//删除本地文件
|
||||
if needRemove {
|
||||
_ = os.Remove(filePath)
|
||||
}
|
||||
//url = fmt.Sprintf("%s/%s", os.Getenv(config.ConfigData.Oss.CdnHost), objectName)
|
||||
url = fmt.Sprintf("%s/%s", config.ConfigData.Oss.CdnHost, objectName)
|
||||
return
|
||||
}
|
||||
|
||||
381
pkg/utils/excel/excelInter.go
Normal file
381
pkg/utils/excel/excelInter.go
Normal file
@ -0,0 +1,381 @@
|
||||
// Package excel -----------------------------
|
||||
// @file : templateInter.go
|
||||
// @author : JJXu
|
||||
// @contact : wavingbear@163.com
|
||||
// @time : 2022/7/23 15:34
|
||||
// -------------------------------------------
|
||||
package excel
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/tealeg/xlsx"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrSheetNotExist = errors.New("sheet does not exist")
|
||||
ErrSheetDataFormatNotSupport = errors.New("sheet data format not support")
|
||||
//ErrSheetNameNotInTemplate = errors.New("sheet name not in emailTemplate")
|
||||
)
|
||||
|
||||
// ======================================================================================================================
|
||||
//
|
||||
// Sheet define
|
||||
type HeaderRow struct {
|
||||
RowNum int //行号
|
||||
Values []string
|
||||
}
|
||||
|
||||
// 抽象工作簿
|
||||
type Sheet interface {
|
||||
GetData() any //数据,支持struct、[]struct、[]*struct三种类型
|
||||
SheetName() string //表名称
|
||||
SheetHeaders() []string //表头名称,没有则跳过插入表头的步骤
|
||||
GetJsonFiledList() []string //指定字段的排列顺序,默认按照结构体中的顺序排列(表头与数据没有关联,使用这个指定字段插入顺序)
|
||||
}
|
||||
|
||||
// 实例化工作簿,使用模板生成excel的话用这个
|
||||
func NewTemplateSheet(sheetName string, datas any) Sheet {
|
||||
return &newSheetDefine{
|
||||
Datas: datas,
|
||||
Name: sheetName,
|
||||
}
|
||||
}
|
||||
|
||||
// 实例化工作簿,不通过模板生成excel的话用这个
|
||||
func NewSheet(sheetName string, datas any, headers []string, jsonFiledList ...[]string) Sheet {
|
||||
st := &newSheetDefine{
|
||||
Datas: datas,
|
||||
Name: sheetName,
|
||||
Headers: headers,
|
||||
}
|
||||
if jsonFiledList != nil {
|
||||
st.JsonFiledList = jsonFiledList[0]
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
// 定义一个能够通用的工作簿结构,此结构必须遵循Sheet接口规范
|
||||
type newSheetDefine struct {
|
||||
Datas any
|
||||
Name string
|
||||
Headers []string
|
||||
JsonFiledList []string
|
||||
}
|
||||
|
||||
func (s *newSheetDefine) GetData() any {
|
||||
return s.Datas
|
||||
}
|
||||
func (s *newSheetDefine) SheetName() string {
|
||||
return s.Name
|
||||
}
|
||||
func (s *newSheetDefine) SheetHeaders() []string {
|
||||
return s.Headers
|
||||
}
|
||||
func (s *newSheetDefine) GetJsonFiledList() []string {
|
||||
return s.JsonFiledList
|
||||
}
|
||||
|
||||
//======================================================================================================================
|
||||
// Sheet define
|
||||
|
||||
// WriteToExcel 通过模板文件写入数据并另存为
|
||||
// param fileName : 文件名
|
||||
// param filesSuffix : 文件后缀名生成函数
|
||||
// param fileRoot : 导出目录
|
||||
// param templatePath : 模板文件路径
|
||||
// param sheets : Sheet类型的数据,类型为[]Sheet
|
||||
// return path : 文件路径
|
||||
// return exfileName : 导出后的文件名
|
||||
// return err
|
||||
func WriteToExcel(fileName string, fileRoot string, templatePath string, sheets ...Sheet) (path string, exFileName string, err error) {
|
||||
var exc *Excel
|
||||
exc, err = NewExcelCreatorFromTemplate(fileName, fileRoot, templatePath, sheets...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
exc.UseOption(OptionFileNameSuffixWithUnixTime)
|
||||
return exc.WriteToFile()
|
||||
}
|
||||
|
||||
// ReadDataFromExcel 从excel文件读取数据
|
||||
func ReadDataFromExcel(filepath string, sheetName string, handler func(rowIndex int, rows []string)) error {
|
||||
ex := Excel{OriginFilePath: filepath}
|
||||
return ex.ReadSheetData(sheetName, handler)
|
||||
}
|
||||
|
||||
// ReadDataFromBytes 从io口读取数据,用户http上传的附件
|
||||
func ReadDataFromBytes(file io.Reader, sheetName string, handler func(rowIndex int, row []string)) error {
|
||||
exce, err := excelize.OpenReader(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var ex = Excel{ex: exce}
|
||||
return ex.ReadSheetData(sheetName, handler)
|
||||
}
|
||||
|
||||
// 读取模板并创建工作表生成器
|
||||
func NewExcelCreatorFromTemplate(fileName string, fileRoot string, templatePath string, sheets ...Sheet) (exc *Excel, err error) {
|
||||
exc = &Excel{
|
||||
SaveRoot: fileRoot,
|
||||
SaveName: fileName,
|
||||
OriginFilePath: templatePath,
|
||||
rwLock: sync.RWMutex{},
|
||||
}
|
||||
if sheets != nil {
|
||||
err = exc.AddSheets(sheets...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return exc, nil
|
||||
}
|
||||
|
||||
// 新建文件并创建工作表生成器
|
||||
func NewExcelCreatorWithNewFile(fileName string, fileRoot string, sheets ...Sheet) (exc *Excel, err error) {
|
||||
return NewExcelCreatorFromTemplate(fileName, fileRoot, "", sheets...)
|
||||
}
|
||||
|
||||
type Excel struct {
|
||||
ex *excelize.File
|
||||
SaveRoot string
|
||||
SaveName string
|
||||
OriginFilePath string
|
||||
Sheets map[string]Sheet
|
||||
rwLock sync.RWMutex
|
||||
Opts []Option
|
||||
After []Option
|
||||
}
|
||||
|
||||
// UseOption 使用可选项
|
||||
func (s *Excel) UseOption(opts ...Option) {
|
||||
if opts != nil {
|
||||
s.Opts = append(s.Opts, opts...)
|
||||
}
|
||||
}
|
||||
func (s *Excel) AfterAddData(after ...Option) {
|
||||
if after != nil {
|
||||
s.After = append(s.After, after...)
|
||||
}
|
||||
}
|
||||
|
||||
// 添加工作簿
|
||||
// 注意如果添加相同的工作簿,之前的会被覆盖
|
||||
func (s *Excel) AddSheets(sheets ...Sheet) (err error) {
|
||||
if s.Sheets == nil {
|
||||
s.Sheets = make(map[string]Sheet, 0)
|
||||
}
|
||||
for _, sheet := range sheets {
|
||||
var sheetName = sheet.SheetName()
|
||||
s.Sheets[sheetName] = sheet
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除工作簿
|
||||
func (s *Excel) DeleteSheets(sheetName string) error {
|
||||
if s.Sheets == nil {
|
||||
return nil
|
||||
} else if s.Sheets[sheetName] != nil {
|
||||
delete(s.Sheets, sheetName)
|
||||
} else {
|
||||
return ErrSheetNotExist
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 读取工作簿
|
||||
func (s *Excel) ReadSheetData(sheetName string, handler func(rowIndex int, row []string)) (err error) {
|
||||
if s.ex == nil {
|
||||
s.ex, err = excelize.OpenFile(s.OriginFilePath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
datas, err := s.ex.GetRows(sheetName)
|
||||
for i, row := range datas {
|
||||
handler(i, row)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 写入到文件
|
||||
func (s *Excel) WriteToFile() (path string, fileName string, err error) {
|
||||
if s.ex == nil {
|
||||
if s.OriginFilePath == "" {
|
||||
s.ex = excelize.NewFile()
|
||||
} else {
|
||||
s.ex, err = excelize.OpenFile(s.OriginFilePath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if s.Opts != nil {
|
||||
for _, opt := range s.Opts {
|
||||
opt(s)
|
||||
}
|
||||
}
|
||||
//插入数据
|
||||
for sheetName, st := range s.Sheets {
|
||||
//添加表头,没有定义则不插入
|
||||
if st.SheetHeaders() != nil {
|
||||
for i, c := range st.SheetHeaders() {
|
||||
err = s.ex.SetCellValue(sheetName, GetCellIndex(1, i+1), c)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
headerStyleID, errs := s.ex.NewStyle(NewDefaultHeaderStyle())
|
||||
if errs != nil {
|
||||
fmt.Println(errs)
|
||||
err = errs
|
||||
return
|
||||
}
|
||||
//表头设置为默认样式,边框加粗、字体加粗
|
||||
if err = s.ex.SetCellStyle(st.SheetName(), "A1", GetCellIndex(1, len(st.SheetHeaders())), headerStyleID); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
//添加数据
|
||||
var firstRow = s.getFirstEmptyRowIndex(s.ex, sheetName)
|
||||
var SheetData = reflect.ValueOf(st.GetData())
|
||||
var SheetType = reflect.TypeOf(st.GetData())
|
||||
writerFunc, exists := writerMap[SheetData.Kind()]
|
||||
if exists {
|
||||
err = writerFunc(s, st, SheetData, SheetType, firstRow)
|
||||
} else {
|
||||
return "", "", ErrSheetDataFormatNotSupport
|
||||
}
|
||||
}
|
||||
if s.After != nil {
|
||||
for _, after := range s.After {
|
||||
after(s)
|
||||
}
|
||||
}
|
||||
//检测并生成目录
|
||||
_ = os.MkdirAll(s.SaveRoot, os.ModePerm)
|
||||
//保存
|
||||
path = filepath.ToSlash(filepath.Join(s.SaveRoot, s.SaveName))
|
||||
fileName = s.SaveName
|
||||
s.rwLock.Lock()
|
||||
if err = s.ex.SaveAs(path); err != nil {
|
||||
log.Println(fmt.Sprintf("save file error :%v", err))
|
||||
s.rwLock.Unlock()
|
||||
return
|
||||
}
|
||||
s.rwLock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
// getJsonFieldList 获取json字段列表
|
||||
func (s *Excel) getJsonFieldList(sheetType reflect.Type) (tagList []string) {
|
||||
t := sheetType.Elem()
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
if t.Kind() != reflect.Struct {
|
||||
return
|
||||
}
|
||||
}
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
var tag = t.Field(i).Tag.Get("json")
|
||||
if tag != "" {
|
||||
tagList = append(tagList, tag)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// dataToMap 数据转字典
|
||||
func (s *Excel) dataToMap(sheet reflect.Value, sheetType reflect.Type) (dataMap map[string]any) {
|
||||
dataMap = make(map[string]any)
|
||||
t := sheetType.Elem()
|
||||
//指针类型结构体拿真实的对象
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
sheet = sheet.Elem()
|
||||
}
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
var tag = t.Field(i).Tag.Get("json")
|
||||
if tag != "" {
|
||||
dataMap[t.Field(i).Tag.Get("json")] = sheet.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
return dataMap
|
||||
}
|
||||
|
||||
// getFirstEmptyRowIndex 获取首个空行的索引位置
|
||||
func (s *Excel) getFirstEmptyRowIndex(ex *excelize.File, sheetName string) (index int) {
|
||||
rows, err := ex.GetRows(sheetName)
|
||||
if err != nil {
|
||||
return 1
|
||||
}
|
||||
return len(rows)
|
||||
}
|
||||
|
||||
func ToExcel(titleList []string, dataList []interface{}) (content io.ReadSeeker) {
|
||||
// 生成一个新的文件
|
||||
file := xlsx.NewFile()
|
||||
// 添加sheet页
|
||||
sheet, _ := file.AddSheet("Sheet1")
|
||||
// 插入表头
|
||||
titleRow := sheet.AddRow()
|
||||
for _, v := range titleList {
|
||||
cell := titleRow.AddCell()
|
||||
cell.Value = v
|
||||
}
|
||||
// 插入内容
|
||||
for _, v := range dataList {
|
||||
row := sheet.AddRow()
|
||||
row.WriteStruct(v, -1)
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
_ = file.Write(&buffer)
|
||||
file.Save("1.xlsx")
|
||||
content = bytes.NewReader(buffer.Bytes())
|
||||
return
|
||||
}
|
||||
|
||||
// 自动设置单元格宽度
|
||||
func (s *Excel) autoResetCellWidth(sheetObj Sheet) {
|
||||
// 获取最大字符宽度
|
||||
maxWidths := make(map[int]int)
|
||||
var sheetData = reflect.ValueOf(sheetObj.GetData())
|
||||
var rowLen = 1
|
||||
var columnLen = len(sheetObj.GetJsonFiledList())
|
||||
if sheetData.Kind() == reflect.Slice {
|
||||
rowLen = sheetData.Len()
|
||||
}
|
||||
limitWidth := 90
|
||||
for col := 1; col <= columnLen; col++ {
|
||||
var maxWidth int
|
||||
for row := 0; row < rowLen; row++ {
|
||||
value, _ := s.ex.GetCellValue(sheetObj.SheetName(), GetCellIndex(row+1, col))
|
||||
width := len(value)
|
||||
if width > limitWidth {
|
||||
width = limitWidth
|
||||
}
|
||||
if width > maxWidth {
|
||||
maxWidth = width
|
||||
}
|
||||
}
|
||||
maxWidths[col] = maxWidth
|
||||
}
|
||||
|
||||
// 设置列宽度
|
||||
for col, width := range maxWidths {
|
||||
colChar := GetColumnIndex(col)
|
||||
s.ex.SetColWidth(sheetObj.SheetName(), colChar, colChar, float64(width+2))
|
||||
}
|
||||
}
|
||||
52
pkg/utils/excel/options.go
Normal file
52
pkg/utils/excel/options.go
Normal file
@ -0,0 +1,52 @@
|
||||
// Package excel -----------------------------
|
||||
// @file : options.go
|
||||
// @author : JJXu
|
||||
// @contact : wavingBear@163.com
|
||||
// @time : 2022/12/19 12:41:40
|
||||
// -------------------------------------------
|
||||
package excel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Option func(excel *Excel)
|
||||
|
||||
// func AddSaveFileSuffixWithUnixTime(excel *Excel) {
|
||||
// excel.SaveName
|
||||
// fmt.Sprintf("%v", time.Now().Unix())
|
||||
// }
|
||||
//
|
||||
// 时间戳作为文件后缀
|
||||
func OptionFileNameSuffixWithUnixTime(excel *Excel) {
|
||||
ext := filepath.Ext(excel.SaveName)
|
||||
name := strings.Split(excel.SaveName, ext)[0]
|
||||
excel.SaveName = fmt.Sprintf("%s_%v%s", name, time.Now().Unix(), ext)
|
||||
}
|
||||
|
||||
// 为第一行添加表头
|
||||
func AfterAddHeader1(sheet Sheet, text string) func(excel *Excel) {
|
||||
return func(excel *Excel) {
|
||||
err := excel.ex.InsertRows(sheet.SheetName(), 1, 1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = excel.ex.SetCellValue(sheet.SheetName(), GetCellIndex(1, 1), text)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
headerStyleID, errs := excel.ex.NewStyle(NewHeaderOneStyle())
|
||||
if errs != nil {
|
||||
fmt.Println(errs)
|
||||
err = errs
|
||||
return
|
||||
}
|
||||
//表头设置为默认样式,边框加粗、字体加粗
|
||||
_ = excel.ex.SetCellStyle(sheet.SheetName(), "A1", GetCellIndex(1, len(sheet.SheetHeaders())), headerStyleID)
|
||||
_ = excel.ex.MergeCell(sheet.SheetName(), "A1", GetCellIndex(1, len(sheet.SheetHeaders())))
|
||||
|
||||
}
|
||||
}
|
||||
54
pkg/utils/excel/style.go
Normal file
54
pkg/utils/excel/style.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Package excel -----------------------------
|
||||
// @file : style.go
|
||||
// @author : JJXu
|
||||
// @contact : wavingbear@163.com
|
||||
// @time : 2023/9/1 13:50
|
||||
// -------------------------------------------
|
||||
package excel
|
||||
|
||||
import (
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
func NewDefaultHeaderStyle() *excelize.Style {
|
||||
return &excelize.Style{
|
||||
Border: []excelize.Border{
|
||||
{Type: "left", Color: "000000", Style: 2},
|
||||
{Type: "top", Color: "000000", Style: 2},
|
||||
{Type: "bottom", Color: "000000", Style: 2},
|
||||
{Type: "right", Color: "000000", Style: 2},
|
||||
},
|
||||
Font: &excelize.Font{Bold: true, Size: 12},
|
||||
Alignment: &excelize.Alignment{
|
||||
Horizontal: "center",
|
||||
},
|
||||
}
|
||||
}
|
||||
func NewDefaultDataStyle() *excelize.Style {
|
||||
return &excelize.Style{
|
||||
Border: []excelize.Border{
|
||||
{Type: "left", Color: "000000", Style: 1},
|
||||
{Type: "bottom", Color: "000000", Style: 1},
|
||||
{Type: "right", Color: "000000", Style: 1},
|
||||
},
|
||||
Font: &excelize.Font{Size: 12},
|
||||
Alignment: &excelize.Alignment{
|
||||
Horizontal: "left",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewHeaderOneStyle() *excelize.Style {
|
||||
return &excelize.Style{
|
||||
Border: []excelize.Border{
|
||||
{Type: "left", Color: "000000", Style: 2},
|
||||
{Type: "top", Color: "000000", Style: 2},
|
||||
{Type: "bottom", Color: "000000", Style: 2},
|
||||
{Type: "right", Color: "000000", Style: 2},
|
||||
},
|
||||
Font: &excelize.Font{Bold: true, Size: 14},
|
||||
Alignment: &excelize.Alignment{
|
||||
Horizontal: "center",
|
||||
},
|
||||
}
|
||||
}
|
||||
41
pkg/utils/excel/utils.go
Normal file
41
pkg/utils/excel/utils.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package utils -----------------------------
|
||||
// @file : excelHelper.go
|
||||
// @author : JJXu
|
||||
// @contact : wavingbear@163.com
|
||||
// @time : 2022/6/9 13:41
|
||||
// -------------------------------------------
|
||||
package excel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 行列坐标值转换为excel的坐标。注意row和columnCount的初始值都是1
|
||||
func GetCellIndex(row int, columnCount int) string {
|
||||
var column = GetColumnIndex(columnCount)
|
||||
return fmt.Sprintf("%s%d", column, row)
|
||||
}
|
||||
|
||||
// 获取excel的列索引
|
||||
var columnIndices = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
|
||||
|
||||
func GetColumnIndex(num int) string {
|
||||
num--
|
||||
var column = columnIndices[num%26]
|
||||
for num = num / 26; num > 0; num = num / 26 {
|
||||
column = columnIndices[(num-1)%26] + column
|
||||
num--
|
||||
}
|
||||
return column
|
||||
}
|
||||
|
||||
func Int[T int | uint | uint8 | uint32 | uint64 | int32 | int64](value string) T {
|
||||
v, _ := strconv.Atoi(value)
|
||||
return T(v)
|
||||
}
|
||||
|
||||
func Float[T float64 | float32](value string) T {
|
||||
v, _ := strconv.ParseFloat(value, 64)
|
||||
return T(v)
|
||||
}
|
||||
81
pkg/utils/excel/writer.go
Normal file
81
pkg/utils/excel/writer.go
Normal file
@ -0,0 +1,81 @@
|
||||
// Package excel -----------------------------
|
||||
// @file : writer.go
|
||||
// @author : JJXu
|
||||
// @contact : wavingbear@163.com
|
||||
// @time : 2023/9/1 14:11
|
||||
// -------------------------------------------
|
||||
package excel
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var writerMap = map[reflect.Kind]func(exc *Excel, sheetObj Sheet, SheetData reflect.Value, SheetType reflect.Type, firstRow int) error{
|
||||
reflect.Slice: sliceWriter,
|
||||
reflect.Struct: structWriter,
|
||||
}
|
||||
|
||||
func RegisterWriter(dataKind reflect.Kind, function func(exc *Excel, sheetObj Sheet, SheetData reflect.Value, SheetType reflect.Type, firstRow int) error) error {
|
||||
if _, exists := writerMap[dataKind]; exists {
|
||||
return errors.New(fmt.Sprintf("dataKind: %v has existed", dataKind))
|
||||
}
|
||||
writerMap[dataKind] = function
|
||||
return nil
|
||||
}
|
||||
|
||||
func sliceWriter(exc *Excel, sheetObj Sheet, SheetData reflect.Value, SheetDataType reflect.Type, firstRow int) error {
|
||||
var cellNameList = sheetObj.GetJsonFiledList()
|
||||
if cellNameList == nil {
|
||||
cellNameList = exc.getJsonFieldList(SheetDataType)
|
||||
}
|
||||
var rowLen = SheetData.Len()
|
||||
for i := 0; i < rowLen; i++ {
|
||||
var dataMap = exc.dataToMap(SheetData.Index(i), SheetDataType)
|
||||
for column, v := range cellNameList {
|
||||
var axis = GetCellIndex(i+firstRow+1, column+1)
|
||||
err := exc.ex.SetCellValue(sheetObj.SheetName(), axis, dataMap[v])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
//设置数据格式
|
||||
dataStyleID, errs := exc.ex.NewStyle(NewDefaultDataStyle())
|
||||
if errs != nil {
|
||||
return errs
|
||||
}
|
||||
if err := exc.ex.SetCellStyle(sheetObj.SheetName(), GetCellIndex(firstRow+1, 1), GetCellIndex(rowLen+1, len(sheetObj.SheetHeaders())), dataStyleID); err != nil {
|
||||
return err
|
||||
}
|
||||
//设置默认列宽
|
||||
//exc.ex.SetColWidth(sheetObj.SheetName(), GetColumnIndex(1), GetColumnIndex(len(sheetObj.SheetHeaders())), 12.0)
|
||||
exc.autoResetCellWidth(sheetObj)
|
||||
return nil
|
||||
}
|
||||
|
||||
func structWriter(exc *Excel, sheetObj Sheet, SheetData reflect.Value, SheetType reflect.Type, firstRow int) error {
|
||||
var cellNameList = exc.getJsonFieldList(SheetType)
|
||||
var dataMap = exc.dataToMap(SheetData, SheetType)
|
||||
for column, v := range cellNameList {
|
||||
var axis = GetCellIndex(firstRow+1, column+1)
|
||||
err := exc.ex.SetCellValue(sheetObj.SheetName(), axis, dataMap[v])
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
//设置数据格式
|
||||
dataStyleID, err := exc.ex.NewStyle(NewDefaultDataStyle())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = exc.ex.SetCellStyle(sheetObj.SheetName(), GetCellIndex(firstRow, 1), GetCellIndex(firstRow+1, len(sheetObj.SheetHeaders())), dataStyleID); err != nil {
|
||||
return err
|
||||
}
|
||||
//设置默认列宽
|
||||
//exc.ex.SetColWidth(sheetObj.SheetName(), GetColumnIndex(1), GetColumnIndex(len(sheetObj.SheetHeaders())), 12.0)
|
||||
exc.autoResetCellWidth(sheetObj)
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user