mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Adding remove method on tptimings, modified SetTPTiming to update on exists
This commit is contained in:
@@ -189,9 +189,9 @@ func (dbr *DbReader) LoadRatingPlans() error {
|
||||
return errors.New(fmt.Sprintf("Could not get timing for tag %v", drt.TimingId))
|
||||
}
|
||||
drt.Timing = t
|
||||
drs, exists := dbr.destinationRates[drt.DestRatesId]
|
||||
drs, exists := dbr.destinationRates[drt.DestinationRatesId]
|
||||
if !exists {
|
||||
return errors.New(fmt.Sprintf("Could not find destination rate for tag %v", drt.DestRatesId))
|
||||
return errors.New(fmt.Sprintf("Could not find destination rate for tag %v", drt.DestinationRatesId))
|
||||
}
|
||||
|
||||
plan, exists := dbr.ratingPlans[drts.RatingPlanId]
|
||||
@@ -250,11 +250,11 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
|
||||
return fmt.Errorf("No Timings profile with id %s: %v", rp.TimingId, err)
|
||||
}
|
||||
rp.Timing = tm[rp.TimingId]
|
||||
drm, err := dbr.storDb.GetTpDestinationRates(dbr.tpid, rp.DestRatesId)
|
||||
drm, err := dbr.storDb.GetTpDestinationRates(dbr.tpid, rp.DestinationRatesId)
|
||||
if err != nil || len(drm) == 0 {
|
||||
return fmt.Errorf("No DestinationRates profile with id %s: %v", rp.DestRatesId, err)
|
||||
return fmt.Errorf("No DestinationRates profile with id %s: %v", rp.DestinationRatesId, err)
|
||||
}
|
||||
for _, drate := range drm[rp.DestRatesId].DestinationRates {
|
||||
for _, drate := range drm[rp.DestinationRatesId].DestinationRates {
|
||||
Logger.Debug(fmt.Sprintf("Destination rate: %v", drate))
|
||||
rt, err := dbr.storDb.GetTpRates(dbr.tpid, drate.RateId)
|
||||
if err != nil || len(rt) == 0 {
|
||||
|
||||
@@ -105,6 +105,7 @@ type LoadStorage interface {
|
||||
ExistsTPTiming(string, string) (bool, error)
|
||||
GetTPTiming(string, string) (*utils.TPTiming, error)
|
||||
GetTPTimingIds(string) ([]string, error)
|
||||
RemTPTiming(string, string) error
|
||||
SetTPDestination(string, *Destination) error
|
||||
ExistsTPDestination(string, string) (bool, error)
|
||||
GetTPDestination(string, string) (*Destination, error)
|
||||
|
||||
@@ -65,7 +65,7 @@ func (self *SQLStorage) GetTPIds() ([]string, error) {
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetTPTiming(tpid string, tm *utils.TPTiming) error {
|
||||
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s')",
|
||||
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s') ON DUPLICATE KEY UPDATE years=values(years), months=values(months), month_days=values(month_days), week_days=values(week_days), time=values(time)",
|
||||
utils.TBL_TP_TIMINGS, tpid, tm.Id, tm.Years.Serialize(";"), tm.Months.Serialize(";"), tm.MonthDays.Serialize(";"),
|
||||
tm.WeekDays.Serialize(";"), tm.StartTime)); err != nil {
|
||||
return err
|
||||
@@ -118,6 +118,16 @@ func (self *SQLStorage) GetTPTimingIds(tpid string) ([]string, error) {
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (self *SQLStorage) RemTPTiming(tpid, tag string) error {
|
||||
q := fmt.Sprintf("DELETE FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_TIMINGS, tpid, tag)
|
||||
if _, err := self.Db.Exec(q); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Extracts destinations from StorDB on specific tariffplan id
|
||||
func (self *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) {
|
||||
rows, err := self.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_DESTINATIONS, tpid))
|
||||
@@ -363,7 +373,7 @@ func (self *SQLStorage) SetTPRatingPlans(tpid string, drts map[string][]*utils.R
|
||||
qry += ","
|
||||
}
|
||||
qry += fmt.Sprintf("('%s','%s','%s','%s',%f)",
|
||||
tpid, drtId, drt.DestRatesId, drt.TimingId, drt.Weight)
|
||||
tpid, drtId, drt.DestinationRatesId, drt.TimingId, drt.Weight)
|
||||
i++
|
||||
}
|
||||
}
|
||||
@@ -1084,7 +1094,7 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string) (*utils.TPRatingPlan,
|
||||
return nil, err
|
||||
}
|
||||
rt := &utils.RatingPlan{
|
||||
DestRatesId: destination_rates_tag,
|
||||
DestinationRatesId: destination_rates_tag,
|
||||
Weight: weight,
|
||||
TimingId: timings_tag,
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ func (self *TPCSVImporter) importRatingPlans(fn string) error {
|
||||
}
|
||||
drt := []*utils.RatingPlan{
|
||||
&utils.RatingPlan{
|
||||
DestRatesId: record[1],
|
||||
DestinationRatesId: record[1],
|
||||
Weight: weight,
|
||||
TimingId: record[2],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user