2022-08-26 10:15:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2022-11-08 06:53:52 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
2022-08-26 10:15:49 +00:00
|
|
|
|
2022-10-10 04:11:39 +00:00
|
|
|
"git.selly.red/Selly-Modules/natsio"
|
|
|
|
"git.selly.red/Selly-Modules/natsio/model"
|
|
|
|
"git.selly.red/Selly-Modules/natsio/subject"
|
2022-08-26 10:15:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Supplier ...
|
|
|
|
type Supplier struct{}
|
|
|
|
|
2022-08-26 16:37:01 +00:00
|
|
|
// GetSupplier ...
|
|
|
|
func GetSupplier() Supplier {
|
|
|
|
return Supplier{}
|
|
|
|
}
|
|
|
|
|
2022-08-29 07:37:45 +00:00
|
|
|
func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) {
|
2022-08-29 07:25:12 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p))
|
2022-08-26 10:15:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
2022-08-29 07:37:45 +00:00
|
|
|
Data []*model.ResponseSupplierInfo `json:"data"`
|
|
|
|
Error string `json:"error"`
|
2022-08-26 10:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-08-29 07:25:12 +00:00
|
|
|
|
|
|
|
func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractRequest) (*model.ResponseSupplierContract, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierContractBySupplierID, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.ResponseSupplierContract `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
|
|
|
|
}
|
2022-08-31 07:48:24 +00:00
|
|
|
|
|
|
|
func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.SupplierAll `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
|
|
|
|
}
|
2022-09-14 07:09:48 +00:00
|
|
|
|
|
|
|
func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.SupplierAll `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
|
|
|
|
}
|
2022-09-14 10:33:18 +00:00
|
|
|
|
2022-11-08 06:53:52 +00:00
|
|
|
// SyncWarehouseIntoServiceSupplier ...
|
|
|
|
func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, toBytes(p))
|
2022-09-14 10:33:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-14 16:30:22 +00:00
|
|
|
|
2022-11-08 06:53:52 +00:00
|
|
|
// GetListWarehouseFreeShip ...
|
|
|
|
func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeShip, toBytes(bson.M{}))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.SupplierListWarehouseFreeShipResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFreeShipInfo ...
|
|
|
|
func (s Supplier) GetFreeShipInfo(p model.SupplierFreeShipInfoRequestPayload) ([]*model.SupplierFreeShipInfoResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.GetFreeShipInfo, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data []*model.SupplierFreeShipInfoResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateCashflow ...
|
|
|
|
func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
Data *model.SupplierCashflowCreateResponse `json:"data"`
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Supplier) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
Data *model.SupplierUpdateBalanceRes `json:"data"`
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Supplier) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
Data *model.SupplierGetCurrentBalanceRes `json:"data"`
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Supplier) DeleteCashflow(p model.SupplierDeleteCashflowReq) error {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, toBytes(p))
|
2022-09-14 16:30:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|