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


Golang TPDerivedChargers.GetDerivedChargesId方法代码示例

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


在下文中一共展示了TPDerivedChargers.GetDerivedChargesId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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


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