feat(erp): 新增做账合同生成功能和数据归档接口

- 在 accounting 模块中新增 Gen 方法用于生成做账合同
- 在 shipment 模块中新增 ArchiveData 方法用于数据归档
- 调整 import 包顺序并优化 rpcx 客户端初始化逻辑
-为 erp服务添加本地调试用的 p2p discovery 配置
This commit is contained in:
守护自己的云 2025-10-29 17:28:34 +08:00
parent 308f6e93fe
commit d402297eb8
3 changed files with 54 additions and 15 deletions

View File

@ -4,14 +4,15 @@ import (
"context"
"errors"
"fmt"
"git.kumo.work/shama/service/config"
consulClient "git.kumo.work/shama/service/lib/consul"
"github.com/smallnest/rpcx/client"
"log"
"reflect"
"strings"
"sync"
"time"
"git.kumo.work/shama/service/config"
consulClient "git.kumo.work/shama/service/lib/consul"
"github.com/smallnest/rpcx/client"
)
var mClient = sync.Map{}
@ -60,17 +61,33 @@ func GetClient(s interface{}) (*RpcClient, error) {
mutex.Lock()
xClient, ok = mClient.Load(key)
if !ok {
d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
if err != nil {
return nil, errors.New("系统异常")
log.Println(11111111111111111, basePath, servicePath)
if basePath == "erp" {
//d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
d, err := client.NewPeer2PeerDiscovery("tcp@127.0.0.1:8082", "")
if err != nil {
return nil, errors.New("系统异常")
}
option := client.DefaultOption
option.Retries = 3
option.GenBreaker = func() client.Breaker {
return client.NewConsecCircuitBreaker(2, 30*time.Second)
}
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
mClient.Store(key, xClient)
} else {
d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
if err != nil {
return nil, errors.New("系统异常")
}
option := client.DefaultOption
option.Retries = 3
option.GenBreaker = func() client.Breaker {
return client.NewConsecCircuitBreaker(2, 30*time.Second)
}
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
mClient.Store(key, xClient)
}
option := client.DefaultOption
option.Retries = 3
option.GenBreaker = func() client.Breaker {
return client.NewConsecCircuitBreaker(2, 30*time.Second)
}
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
mClient.Store(key, xClient)
}
mutex.Unlock()
}

View File

@ -2,11 +2,12 @@ package erp
import (
"context"
"time"
"git.kumo.work/shama/service/client"
accounting2 "git.kumo.work/shama/service/erp/accounting"
"git.kumo.work/shama/service/lib/bean"
"github.com/shopspring/decimal"
"time"
)
type accounting struct {
@ -98,6 +99,16 @@ func (a *accounting) Add(ctx context.Context, args ArgsAccountingAdd) (accountId
return
}
// Gen @TITLE 生成做账合同
func (a *accounting) Gen(ctx context.Context, shipmentId int64) (err error) {
xClient, err := client.GetClient(a)
if err != nil {
return
}
reply := 0
return xClient.Call(ctx, "Gen", shipmentId, &reply)
}
type ReplyAccountingInfo struct {
Id int64 `json:"id"`
CustomId int64 `json:"customId"`

View File

@ -2,12 +2,13 @@ package erp
import (
"context"
"time"
"git.kumo.work/shama/service/client"
bean2 "git.kumo.work/shama/service/erp/bean"
shipment2 "git.kumo.work/shama/service/erp/shipment"
"git.kumo.work/shama/service/lib/bean"
"github.com/shopspring/decimal"
"time"
)
type shipment struct {
@ -261,3 +262,13 @@ func (s *shipment) Clone(ctx context.Context, args ArgsShipmentClone) (reply int
err = xClient.Call(ctx, "Clone", args, &reply)
return
}
// ArchiveData @TITLE 归档
func (s *shipment) ArchiveData(ctx context.Context, shipmentIds []int64) (reply int64, err error) {
xClient, err := client.GetClient(s)
if err != nil {
return
}
err = xClient.Call(ctx, "ArchiveData", shipmentIds, &reply)
return
}