mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
working on duration expire time
This commit is contained in:
@@ -117,7 +117,7 @@ CREATE TABLE `tp_actions` (
|
||||
`balance_tag` varchar(24) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
`units` DECIMAL(5,2) NOT NULL,
|
||||
`expiration_time` int(11) NOT NULL,
|
||||
`expiration_time` varchar(24) NOT NULL,
|
||||
`destination_tag` varchar(24) NOT NULL,
|
||||
`rate_type` varchar(8) NOT NULL,
|
||||
`rate` DECIMAL(5,4) NOT NULL,
|
||||
|
||||
@@ -28,14 +28,15 @@ import (
|
||||
Structure to be filled for each tariff plan with the bonus value for received calls minutes.
|
||||
*/
|
||||
type Action struct {
|
||||
Id string
|
||||
ActionType string
|
||||
BalanceId string
|
||||
Direction string
|
||||
ExpirationDate time.Time
|
||||
Units float64
|
||||
Weight float64
|
||||
MinuteBucket *MinuteBucket
|
||||
Id string
|
||||
ActionType string
|
||||
BalanceId string
|
||||
Direction string
|
||||
ExpirationString string
|
||||
ExpirationDate time.Time
|
||||
Units float64
|
||||
Weight float64
|
||||
MinuteBucket *MinuteBucket
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -379,19 +379,17 @@ func (csvr *CSVReader) LoadActions() (err error) {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Could not parse action units: %v", err))
|
||||
}
|
||||
unix, err := strconv.ParseInt(record[5], 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Could not parse expiration date: %v", err))
|
||||
}
|
||||
expDate := time.Unix(unix, 0)
|
||||
var a *Action
|
||||
if record[2] != MINUTES {
|
||||
a = &Action{
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
Direction: record[3],
|
||||
Units: units,
|
||||
ExpirationDate: expDate,
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
Direction: record[3],
|
||||
Units: units,
|
||||
ExpirationString: record[5],
|
||||
}
|
||||
if _, err := utils.ParseDate(a.ExpirationString); err != nil {
|
||||
return errors.New(fmt.Sprintf("Could not parse expiration time: %v", err))
|
||||
}
|
||||
} else {
|
||||
value, err := strconv.ParseFloat(record[8], 64)
|
||||
@@ -407,21 +405,25 @@ func (csvr *CSVReader) LoadActions() (err error) {
|
||||
return errors.New(fmt.Sprintf("Could not parse action weight: %v", err))
|
||||
}
|
||||
a = &Action{
|
||||
Id: utils.GenUUID(),
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
Direction: record[3],
|
||||
Weight: weight,
|
||||
ExpirationDate: expDate,
|
||||
Id: utils.GenUUID(),
|
||||
ActionType: record[1],
|
||||
BalanceId: record[2],
|
||||
Direction: record[3],
|
||||
Weight: weight,
|
||||
ExpirationString: record[5],
|
||||
MinuteBucket: &MinuteBucket{
|
||||
Seconds: units,
|
||||
Weight: minutesWeight,
|
||||
Price: value,
|
||||
PriceType: record[7],
|
||||
DestinationId: record[6],
|
||||
ExpirationDate: expDate,
|
||||
Seconds: units,
|
||||
Weight: minutesWeight,
|
||||
Price: value,
|
||||
PriceType: record[7],
|
||||
DestinationId: record[6],
|
||||
ExpirationString: record[5],
|
||||
},
|
||||
}
|
||||
if _, err := utils.ParseDate(a.ExpirationString); err != nil {
|
||||
return errors.New(fmt.Sprintf("Could not parse expiration time: %v", err))
|
||||
}
|
||||
|
||||
}
|
||||
csvr.actions[tag] = append(csvr.actions[tag], a)
|
||||
}
|
||||
|
||||
@@ -25,13 +25,14 @@ import (
|
||||
)
|
||||
|
||||
type MinuteBucket struct {
|
||||
Seconds float64
|
||||
Weight float64
|
||||
Price float64 // percentage from standard price or absolute value depending on Type
|
||||
PriceType string
|
||||
DestinationId string
|
||||
ExpirationDate time.Time
|
||||
precision int
|
||||
Seconds float64
|
||||
Weight float64
|
||||
Price float64 // percentage from standard price or absolute value depending on Type
|
||||
PriceType string
|
||||
DestinationId string
|
||||
ExpirationString string
|
||||
ExpirationDate time.Time
|
||||
precision int
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -23,8 +23,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SQLStorage struct {
|
||||
@@ -552,8 +550,7 @@ func (self *SQLStorage) GetTPActions(tpid, actsId string) (*utils.TPActions, err
|
||||
i := 0
|
||||
for rows.Next() {
|
||||
i++ //Keep here a reference so we know we got at least one result
|
||||
var action, balanceId, dir, destId, rateType string
|
||||
var expTime int64
|
||||
var action, balanceId, dir, destId, rateType, expTime string
|
||||
var units, rate, minutesWeight, weight float64
|
||||
if err = rows.Scan(&action, &balanceId, &dir, &units, &expTime, &destId, &rateType, &rate, &minutesWeight, &weight); err != nil {
|
||||
return nil, err
|
||||
@@ -1081,36 +1078,31 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*Action, er
|
||||
if err := rows.Scan(&id, &tpid, &tag, &action, &balance_tag, &direction, &units, &expirationDate, &destinations_tag, &rate_type, &rate, &minutes_weight, &weight); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unix, err := strconv.ParseInt(expirationDate, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expDate := time.Unix(unix, 0)
|
||||
var a *Action
|
||||
if balance_tag != MINUTES {
|
||||
a = &Action{
|
||||
ActionType: action,
|
||||
BalanceId: balance_tag,
|
||||
Direction: direction,
|
||||
Units: units,
|
||||
ExpirationDate: expDate,
|
||||
ActionType: action,
|
||||
BalanceId: balance_tag,
|
||||
Direction: direction,
|
||||
Units: units,
|
||||
ExpirationString: expirationDate,
|
||||
}
|
||||
} else {
|
||||
var price float64
|
||||
a = &Action{
|
||||
Id: utils.GenUUID(),
|
||||
ActionType: action,
|
||||
BalanceId: balance_tag,
|
||||
Direction: direction,
|
||||
Weight: weight,
|
||||
ExpirationDate: expDate,
|
||||
Id: utils.GenUUID(),
|
||||
ActionType: action,
|
||||
BalanceId: balance_tag,
|
||||
Direction: direction,
|
||||
Weight: weight,
|
||||
ExpirationString: expirationDate,
|
||||
MinuteBucket: &MinuteBucket{
|
||||
Seconds: units,
|
||||
Weight: minutes_weight,
|
||||
Price: price,
|
||||
PriceType: rate_type,
|
||||
DestinationId: destinations_tag,
|
||||
ExpirationDate: expDate,
|
||||
Seconds: units,
|
||||
Weight: minutes_weight,
|
||||
Price: price,
|
||||
PriceType: rate_type,
|
||||
DestinationId: destinations_tag,
|
||||
ExpirationString: expirationDate,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ type Action struct {
|
||||
BalanceId string // Type of balance the action will operate on
|
||||
Direction string // Balance direction
|
||||
Units float64 // Number of units to add/deduct
|
||||
ExpirationTime int64 // Time when the units will expire
|
||||
ExpirationTime string // Time when the units will expire
|
||||
DestinationId string // Destination profile id
|
||||
RateType string // Type of price <ABSOLUTE|PERCENT>
|
||||
Rate float64 // Price value
|
||||
|
||||
@@ -94,3 +94,27 @@ func Round(x float64, prec int, method string) float64 {
|
||||
|
||||
return rounder / pow
|
||||
}
|
||||
|
||||
func ParseDate(date string) (expDate time.Time, err error) {
|
||||
if date == "" {
|
||||
return // zero values are fine
|
||||
}
|
||||
expirationTime := []byte(date)
|
||||
switch {
|
||||
case string(expirationTime) == "*unlimited":
|
||||
// leave it at zero
|
||||
case string(expirationTime[0]) == "+":
|
||||
d, err := time.ParseDuration(string(expirationTime[1:]))
|
||||
if err != nil {
|
||||
return expDate, err
|
||||
}
|
||||
expDate = time.Now().Add(d)
|
||||
default:
|
||||
unix, err := strconv.ParseInt(string(expirationTime), 10, 64)
|
||||
if err != nil {
|
||||
return expDate, err
|
||||
}
|
||||
expDate = time.Unix(unix, 0)
|
||||
}
|
||||
return expDate, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user