当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.TPDerivedChargers类代码示例

本文整理汇总了Golang中github.com/cgrates/cgrates/utils.TPDerivedChargers的典型用法代码示例。如果您正苦于以下问题:Golang TPDerivedChargers类的具体用法?Golang TPDerivedChargers怎么用?Golang TPDerivedChargers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TPDerivedChargers类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: importDerivedChargers

func (self *TPCSVImporter) importDerivedChargers(fn string) error {
	if self.Verbose {
		log.Printf("Processing file: <%s> ", fn)
	}
	fParser, err := NewTPCSVFileParser(self.DirPath, fn)
	if err != nil {
		return err
	}
	loadId := utils.CSV_LOAD //Autogenerate account actions profile id
	if self.ImportId != "" {
		loadId += "_" + self.ImportId
	}
	dcs := make(map[string][]*utils.TPDerivedCharger)
	lineNr := 0
	for {
		lineNr++
		record, err := fParser.ParseNextLine()
		if err == io.EOF { // Reached end of file
			break
		} else if err != nil {
			if self.Verbose {
				log.Printf("Ignoring line %d, warning: <%s> ", lineNr, err.Error())
			}
			continue
		}
		newDcs := utils.TPDerivedChargers{TPid: self.TPid,
			Loadid:    loadId,
			Direction: record[0],
			Tenant:    record[1],
			Category:  record[2],
			Account:   record[3],
			Subject:   record[4]}
		dcsId := newDcs.GetDerivedChargesId()

		if _, hasIt := dcs[dcsId]; !hasIt {
			dcs[dcsId] = make([]*utils.TPDerivedCharger, 0)
		}
		dcs[dcsId] = append(dcs[dcsId], &utils.TPDerivedCharger{
			RunId:            ValueOrDefault(record[5], "*default"),
			RunFilters:       record[6],
			ReqTypeField:     ValueOrDefault(record[7], "*default"),
			DirectionField:   ValueOrDefault(record[8], "*default"),
			TenantField:      ValueOrDefault(record[9], "*default"),
			CategoryField:    ValueOrDefault(record[10], "*default"),
			AccountField:     ValueOrDefault(record[11], "*default"),
			SubjectField:     ValueOrDefault(record[12], "*default"),
			DestinationField: ValueOrDefault(record[13], "*default"),
			SetupTimeField:   ValueOrDefault(record[14], "*default"),
			AnswerTimeField:  ValueOrDefault(record[15], "*default"),
			UsageField:       ValueOrDefault(record[16], "*default"),
		})
	}
	if err := self.StorDb.SetTPDerivedChargers(self.TPid, dcs); err != nil {
		if self.Verbose {
			log.Printf("Ignoring line %d, storDb operational error: <%s> ", lineNr, err.Error())
		}
	}
	return nil
}
开发者ID:intralanman,项目名称:cgrates,代码行数:59,代码来源:tpimporter_csv.go

示例2: LoadDerivedChargers

// Load derived chargers from storDb into dataDb.
func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
	if len(attrs.TPid) == 0 {
		return utils.NewErrMandatoryIeMissing("TPid")
	}
	dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid, self.Config.DefaultTimezone, self.Config.LoadHistorySize)
	dc := engine.APItoModelDerivedCharger(&attrs)
	if err := dbReader.LoadDerivedChargersFiltered(&dc[0], true); err != nil {
		return utils.NewErrServerError(err)
	}
	//Automatic cache of the newly inserted rating plan
	var derivedChargingKeys []string
	if len(attrs.Direction) != 0 && len(attrs.Tenant) != 0 && len(attrs.Category) != 0 && len(attrs.Account) != 0 && len(attrs.Subject) != 0 {
		derivedChargingKeys = []string{utils.DERIVEDCHARGERS_PREFIX + attrs.GetDerivedChargersKey()}
	}
	if err := self.RatingDb.CacheRatingPrefixValues(map[string][]string{utils.DERIVEDCHARGERS_PREFIX: derivedChargingKeys}); err != nil {
		return err
	}
	*reply = OK
	return nil
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:21,代码来源:apier.go

示例3: SetTPDerivedChargers

// Creates a new DerivedCharges profile within a tariff plan
func (self *ApierV1) SetTPDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
	if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Direction", "Tenant", "Category", "Account", "Subject"}); len(missing) != 0 {
		return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
	}
	/*for _, action := range attrs.DerivedCharges {
		requiredFields := []string{"Identifier", "Weight"}
		if action.BalanceType != "" { // Add some inter-dependent parameters - if balanceType then we are not talking about simply calling actions
			requiredFields = append(requiredFields, "Direction", "Units")
		}
		if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
			return fmt.Errorf("%s:DerivedCharge:%s:%v", utils.ERR_MANDATORY_IE_MISSING, action.Identifier, missing)
		}
	}*/
	if err := self.StorDb.SetTPDerivedChargers(attrs.TPid, map[string][]*utils.TPDerivedCharger{
		attrs.GetDerivedChargesId(): attrs.DerivedChargers,
	}); err != nil {
		return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
	}
	*reply = "OK"
	return nil
}
开发者ID:intralanman,项目名称:cgrates,代码行数:22,代码来源:tpderivedcharges.go

示例4: LoadDerivedChargers

// Load derived chargers from storDb into dataDb.
func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
	if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Category", "Direction", "Account", "Subject"}); len(missing) != 0 {
		return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
	}
	if attrs.Loadid == utils.EMPTY {
		attrs.Loadid = ""
	}
	if attrs.Tenant == utils.EMPTY {
		attrs.Tenant = ""
	}
	if attrs.Category == utils.EMPTY {
		attrs.Category = ""
	}
	if attrs.Direction == utils.EMPTY {
		attrs.Direction = ""
	}
	if attrs.Account == utils.EMPTY {
		attrs.Account = ""
	}
	if attrs.Subject == utils.EMPTY {
		attrs.Subject = ""
	}
	dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
	if err := dbReader.LoadDerivedChargersFiltered(&attrs); err != nil {
		return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
	}
	//Automatic cache of the newly inserted rating plan
	didNotChange := []string{}
	if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, didNotChange, nil); err != nil {
		return err
	}
	*reply = OK
	return nil
}
开发者ID:intralanman,项目名称:cgrates,代码行数:35,代码来源:apier.go


注:本文中的github.com/cgrates/cgrates/utils.TPDerivedChargers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。