mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Apier.AddTriggeredAction receiving now BalanceWeight and ExpiryTime
This commit is contained in:
@@ -419,36 +419,43 @@ func (self *ApierV1) SetActionPlan(attrs AttrSetActionPlan, reply *string) error
|
||||
}
|
||||
|
||||
type AttrAddActionTrigger struct {
|
||||
Tenant string
|
||||
Account string
|
||||
Direction string
|
||||
BalanceType string
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
DestinationId string
|
||||
Weight float64
|
||||
ActionsId string
|
||||
Tenant string
|
||||
Account string
|
||||
Direction string
|
||||
BalanceType string
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceExpiryTime string
|
||||
Weight float64
|
||||
ActionsId string
|
||||
}
|
||||
|
||||
func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error {
|
||||
if attr.Direction == "" {
|
||||
attr.Direction = engine.OUTBOUND
|
||||
}
|
||||
|
||||
balExpiryTime, err := utils.ParseTimeDetectLayout(attr.BalanceExpiryTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
at := &engine.ActionTrigger{
|
||||
Id: utils.GenUUID(),
|
||||
BalanceType: attr.BalanceType,
|
||||
Direction: attr.Direction,
|
||||
ThresholdType: attr.ThresholdType,
|
||||
ThresholdValue: attr.ThresholdValue,
|
||||
DestinationId: attr.DestinationId,
|
||||
Weight: attr.Weight,
|
||||
ActionsId: attr.ActionsId,
|
||||
Executed: false,
|
||||
Id: utils.GenUUID(),
|
||||
BalanceType: attr.BalanceType,
|
||||
Direction: attr.Direction,
|
||||
ThresholdType: attr.ThresholdType,
|
||||
ThresholdValue: attr.ThresholdValue,
|
||||
DestinationId: attr.DestinationId,
|
||||
BalanceWeight: attr.BalanceWeight,
|
||||
BalanceExpiryTime: balExpiryTime,
|
||||
Weight: attr.Weight,
|
||||
ActionsId: attr.ActionsId,
|
||||
Executed: false,
|
||||
}
|
||||
|
||||
tag := utils.BalanceKey(attr.Tenant, attr.Account, attr.Direction)
|
||||
_, err := engine.AccLock.Guard(tag, func() (float64, error) {
|
||||
_, err = engine.AccLock.Guard(tag, func() (float64, error) {
|
||||
userBalance, err := self.AccountDb.GetAccount(tag)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -28,18 +28,18 @@ import (
|
||||
)
|
||||
|
||||
type ActionTrigger struct {
|
||||
Id string // uniquely identify the trigger
|
||||
BalanceType string
|
||||
Direction string
|
||||
ThresholdType string //*min_counter, *max_counter, *min_balance, *max_balance
|
||||
ThresholdValue float64
|
||||
Recurrent bool // reset eexcuted flag each run
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceExpirationDate time.Time
|
||||
Weight float64
|
||||
ActionsId string
|
||||
Executed bool
|
||||
Id string // uniquely identify the trigger
|
||||
BalanceType string
|
||||
Direction string
|
||||
ThresholdType string //*min_counter, *max_counter, *min_balance, *max_balance
|
||||
ThresholdValue float64
|
||||
Recurrent bool // reset eexcuted flag each run
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceExpiryTime time.Time
|
||||
Weight float64
|
||||
ActionsId string
|
||||
Executed bool
|
||||
}
|
||||
|
||||
func (at *ActionTrigger) Execute(ub *Account) (err error) {
|
||||
|
||||
@@ -76,8 +76,8 @@ func (b *Balance) MatchDestination(destinationId string) bool {
|
||||
|
||||
func (b *Balance) MatchActionTrigger(at *ActionTrigger) bool {
|
||||
matchesExpirationDate := true
|
||||
if !at.BalanceExpirationDate.IsZero() {
|
||||
matchesExpirationDate = (at.BalanceExpirationDate.Equal(b.ExpirationDate))
|
||||
if !at.BalanceExpiryTime.IsZero() {
|
||||
matchesExpirationDate = (at.BalanceExpiryTime.Equal(b.ExpirationDate))
|
||||
}
|
||||
matchesWeight := true
|
||||
if at.BalanceWeight > 0 {
|
||||
|
||||
Reference in New Issue
Block a user