當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。