package managecenterModel

import "goutil/stringUtil"

//大区页签对象
type AreaLabel struct {
	// 大区Id
	AreaId int32 `json:"AreaID"`
	//标签ID
	LabelID int32 `json:"LabelID"`
	//标签名字
	LabelName string `json:"LabelName"`
	//客户端显示名字
	ClientName string `json:"ClientName"`
	//标签区间字符串1-100,200-300
	LabelServerRange string `json:"LabelServerRange"`
	//渠道列表
	PartnerIdList []int64 `json:"PartnerIdList"`
}

//检测服务器是否在大区页签的区间范围
func (this *AreaLabel) CheckServerIdIsInLabelRange(serverId int32) (isVaild bool) {
	isVaild = false
	for _, serverRangeItem := range stringUtil.Split(this.LabelServerRange, []string{","}) {
		serverRange, _ := stringUtil.SplitToInt32Slice(serverRangeItem, "-")
		lower := serverRange[0]
		upper := serverRange[1]

		//如果范围大小顺序不对，则换位
		if lower > upper {
			temp := lower
			lower = upper
			upper = temp
		}

		//如果服务器在该大区的任意区服区间，则返回true
		if serverId >= lower && serverId <= upper {
			isVaild = true

			return
		}
	}

	return
}
