This commit is contained in:
anbuiselly 2022-11-23 10:29:50 +07:00
parent 8248069bb8
commit c47768308c
9 changed files with 151 additions and 0 deletions

41
client/segmnet.go Normal file
View File

@ -0,0 +1,41 @@
package client
import (
"encoding/json"
"errors"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
)
// Segment ...
type Segment struct{}
// GetSegment ...
func GetSegment() Segment {
return Segment{}
}
// GetListSegmentInfoByIds ...
func (s Segment) GetListSegmentInfoByIds(p model.GetListSegmentRequest) (*model.ResponseListSegmentInfo, error) {
msg, err := natsio.GetServer().Request(subject.Segment.GetListSegmentInfo, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListSegmentInfo `json:"data"`
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}

41
client/staff.go Normal file
View File

@ -0,0 +1,41 @@
package client
import (
"encoding/json"
"errors"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
)
// Staff ...
type Staff struct{}
func GetStaff() Staff {
return Staff{}
}
// GetListStaffInfoByIds ...
func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) {
msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListStaffInfo `json:"data"`
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}

6
model/segment_request.go Normal file
View File

@ -0,0 +1,6 @@
package model
// GetListSegmentRequest ...
type GetListSegmentRequest struct {
SegmentIds []string `json:"segmentIds"`
}

12
model/segment_response.go Normal file
View File

@ -0,0 +1,12 @@
package model
// ResponseSegmentInfo ...
type ResponseSegmentInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
}
// ResponseListSegmentInfo ...
type ResponseListSegmentInfo struct {
Segments []ResponseSegmentInfo `json:"segments"`
}

6
model/staff_request.go Normal file
View File

@ -0,0 +1,6 @@
package model
// GetListStaffRequest ...
type GetListStaffRequest struct {
StaffIds []string `json:"staffIds"`
}

12
model/staff_response.go Normal file
View File

@ -0,0 +1,12 @@
package model
// ResponseListStaffInfo ...
type ResponseListStaffInfo struct {
Staffs []ResponseStaffInfo `json:"staffs"`
}
// ResponseStaffInfo ...
type ResponseStaffInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
}

View File

@ -11,6 +11,8 @@ var prefixes = struct {
Seller string Seller string
SupplierUser string SupplierUser string
SupplierRole string SupplierRole string
Staff string
Segment string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -22,4 +24,6 @@ var prefixes = struct {
Seller: "seller", Seller: "seller",
SupplierUser: "supplier_user", SupplierUser: "supplier_user",
SupplierRole: "supplier_role", SupplierRole: "supplier_role",
Staff: "staff",
Segment: "segment",
} }

15
subject/segment.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
// getSegmentValue ...
func getSegmentValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Segment, val)
}
// Segment ...
var Segment = struct {
GetListSegmentInfo string
}{
GetListSegmentInfo: getSegmentValue("get_list_segment_info"),
}

14
subject/staff.go Normal file
View File

@ -0,0 +1,14 @@
package subject
import "fmt"
func getStaffValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Staff, val)
}
// Staff ...
var Staff = struct {
GetListStaffInfo string
}{
GetListStaffInfo: getStaffValue("get_list_staff_info"),
}