type OnlyCastOnXSGService struct {
	getCastLimitConfigByAwemeLoader   loader.IGetCastLimitConfigByAwemeLoader
	getCastLimitConfigByToutiaoLoader loader.IGetCastLimitConfigByToutiaoLoader
}

func NewOnlyCastOnXSGService(
	getCastLimitConfigByAwemeLoader loader.IGetCastLimitConfigByAwemeLoader,
	getCastLimitConfigByToutiaoLoader loader.IGetCastLimitConfigByToutiaoLoader,
) *OnlyCastOnXSGService {
	return &OnlyCastOnXSGService{
		getCastLimitConfigByAwemeLoader:   getCastLimitConfigByAwemeLoader,
		getCastLimitConfigByToutiaoLoader: getCastLimitConfigByToutiaoLoader,
	}
}

func (s *OnlyCastOnXSGService) ItemIsOnlyCastOnXSG(
	ctx context.Context, req *tv_cast_server.ItemIsOnlyCastOnXSGRequest,
) *tv_cast_server.ItemIsOnlyCastOnXSGResponse {
	// 参数检验
	if err := s.checkParams(req); err != nil {
		logs.CtxError(ctx, "[ItemIsOnlyCastOnXSG] checkParams err=%v", err)
		return s.genResp(nil, consts.ErrParamsErr, err.Error())
	}

	appType := consts.APPID2APPType[req.AppID]
	castItemInfoList := make([]*model.CastItemInfo, 0, len(req.GetItemList()))
	for _, item := range req.GetItemList() {
		castItemM := new(model.CastItemInfo)
		castItemM.ReConvertModelFromThriftModel(item)
		castItemInfoList = append(castItemInfoList, castItemM)
	}
	loaderParams := &loader.GetCastLimitConfigLoaderParams{}
	loaderParams.SetItemList(castItemInfoList)
	var loaderResult *loader.GetCastLimitConfigLoaderResult
	var err error
	if appType == consts.AppTypeToutiao {
		loaderResult, err = s.getCastLimitConfigByToutiaoLoader.Load(ctx, loaderParams)
	} else {
		loaderResult, err = s.getCastLimitConfigByAwemeLoader.Load(ctx, loaderParams)
	}
	if err != nil {
		logs.CtxError(ctx, "[ItemIsOnlyCastOnXSG] load err=%v, appType=%v", err, appType)
		return s.genResp(nil, consts.ErrServerInternalErr, "")
	}
	onlyCastOnXSGConfigInfoList := s.packItemOnlyCastOnXSGConfigInfo(req.AppID, req.SceneID, castItemInfoList,
		loaderResult.UniqueID2SpecialItemCastLimitConfigListMap(), loaderResult.UniqueID2SelectedCastLimitConfigListMap())

	return s.genResp(onlyCastOnXSGConfigInfoList, consts.ErrSuccess, "")
}

func (s *OnlyCastOnXSGService) checkParams(req *tv_cast_server.ItemIsOnlyCastOnXSGRequest) error {
	if req.SceneID <= 0 {
		return fmt.Errorf("sceneID:%v is invalid", req.SceneID)
	}
	if _, ok := consts.APPID2APPType[req.AppID]; !ok {
		return fmt.Errorf("appID:%v is unsupported", req.AppID)
	}
	if len(req.ItemList) == 0 {
		return fmt.Errorf("ItemList is empty")
	}
	return nil
}

func (s *OnlyCastOnXSGService) packItemOnlyCastOnXSGConfigInfo(
	appID, sceneID int32, castItemList []*model.CastItemInfo,
	uniqueID2SpecialItemCastLimitConfigListMap map[string][]*tv_cast_model.CastLimitConfigInfo,
	uniqueID2SelectedCastLimitConfigListMap map[string][]*tv_data_model.SelectedProjectInfo,
) []*tv_cast_model.OnlyCastOnXSGConfigInfo {
	ret := make([]*tv_cast_model.OnlyCastOnXSGConfigInfo, 0, len(castItemList))
	for _, item := range castItemList {
		if item == nil {
			continue
		}
		onlyCastOnXSGConfigInfo := &tv_cast_model.OnlyCastOnXSGConfigInfo{CastItemInfo: item.ConvertToThriftModel()}
		onlyCastOnXSGConfigInfo.IsOnlyCastOnXSG = s.hasEfficientConfig(appID, sceneID,
			uniqueID2SpecialItemCastLimitConfigListMap[item.UniqueID],
			uniqueID2SelectedCastLimitConfigListMap[item.UniqueID])
		ret = append(ret, onlyCastOnXSGConfigInfo)
	}
	return ret
}

func (s *OnlyCastOnXSGService) hasEfficientConfig(
	appID, sceneID int32, specialItemCastLimitConfigList []*tv_cast_model.CastLimitConfigInfo,
	selectedCastLimitConfigList []*tv_data_model.SelectedProjectInfo,
) bool {
	currentTime := time.Now().Unix()
	for _, config := range specialItemCastLimitConfigList {
		if config.BeginTime > currentTime || (config.EndTime != 0 && config.EndTime < currentTime) {
			continue
		}
		if !misc.Contains(config.APPIDList, appID) {
			continue
		}
		if !misc.Contains(config.SceneIDList, sceneID) {
			continue
		}
		return true
	}

	platformID := appID*1000 + sceneID
	for _, config := range selectedCastLimitConfigList {
		if config.BeginTime > currentTime || config.EndTime < currentTime {
			continue
		}
		if config.ProjectExclusiveType == tv_model.ProjectExclusiveType_Undefined {
			continue
		}
		if misc.Contains(config.ValidProjectPlatformList, int64(platformID)) {
			return true
		}
	}

	return false
}

func (s *OnlyCastOnXSGService) genResp(
	onlyCastOnXSGConfigInfoList []*tv_cast_model.OnlyCastOnXSGConfigInfo, bizErr consts.BizError, errMsg string,
) *tv_cast_server.ItemIsOnlyCastOnXSGResponse {
	resp := tv_cast_server.NewItemIsOnlyCastOnXSGResponse()
	resp.OnlyCastOnXSGConfigInfoList = onlyCastOnXSGConfigInfoList
	resp.BaseResp = util.GetBaseRespByBizErr(bizErr, errMsg)
	return resp
}解释下上面代码，并分析代码问题