| | |
| | | import com.yeshi.buwan.dao.ad.DeviceAdStrategyDao; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.ad.DeviceAdStrategy; |
| | | import com.yeshi.buwan.service.imp.DetailSystemConfigService; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | import com.yeshi.buwan.service.inter.ad.DeviceAdStrategyService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.RedisManager; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import com.yeshi.buwan.util.video.VideoConstant; |
| | | import com.yeshi.buwan.vo.video.VideoDetailVO; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private DetailSystemConfigService detailSystemConfigService; |
| | | |
| | | private DeviceAdStrategy init(String id, String deviceId, String detailSystemId) { |
| | | DeviceAdStrategy strategy = new DeviceAdStrategy(); |
| | | strategy.setId(id); |
| | |
| | | return strategy; |
| | | } |
| | | |
| | | /** |
| | | * 加载广告权重 |
| | | * |
| | | * @param videoAdInfo |
| | | * @param detailSystemId |
| | | * @param version |
| | | * @param channel |
| | | */ |
| | | private VideoDetailVO.VideoAdInfo loadAdWeight(VideoDetailVO.VideoAdInfo videoAdInfo, String detailSystemId, int version, String channel) { |
| | | String value = detailSystemConfigService.getConfigValueByKey("video_detail_full_video_version_channel_type", detailSystemId, version); |
| | | if (StringUtil.isNullOrEmpty(value)) { |
| | | return videoAdInfo; |
| | | } |
| | | |
| | | JSONObject json = JSONObject.fromObject(value); |
| | | if (json.optJSONObject(channel) == null) { |
| | | json = json.optJSONObject("qq"); |
| | | } else { |
| | | json = json.optJSONObject(channel); |
| | | } |
| | | if (json != null) { |
| | | videoAdInfo.setFullVideoWeight(json.optInt("fullvideo")); |
| | | videoAdInfo.setInterstitialWeight(json.optInt("interstitial")); |
| | | } |
| | | return videoAdInfo; |
| | | } |
| | | |
| | | @Override |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, String loginUid) { |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, int version, String channel, String loginUid) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return new VideoDetailVO.VideoAdInfo(true, true); |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(true, true), detailSystemId, version, channel); |
| | | } |
| | | //走VIP判定逻辑 |
| | | if (!StringUtil.isNullOrEmpty(loginUid)) { |
| | | if (vipService.isVIP(loginUid)) { |
| | | //VIP不展示视频前贴和全屏 |
| | | return new VideoDetailVO.VideoAdInfo(false, false); |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(false, false), detailSystemId, version, channel); |
| | | } |
| | | } |
| | | |
| | |
| | | strategy = init(id, deviceId, detailSystemId); |
| | | } |
| | | long now = System.currentTimeMillis(); |
| | | return new VideoDetailVO.VideoAdInfo(strategy.getDetailPVAExpireTime() < now, strategy.getDetailFSAExpireTime() < now); |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(strategy.getDetailPVAExpireTime() < now, strategy.getDetailFSAExpireTime() < now), detailSystemId, version, channel); |
| | | } |
| | | |
| | | |
| | |
| | | * @param detailSystemId |
| | | * @return |
| | | */ |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailShortVideoAdStrategy(String deviceId, String detailSystemId) { |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailShortVideoAdStrategy(String deviceId, String detailSystemId, int version, String channel) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return new VideoDetailVO.VideoAdInfo(true, true); |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(true, true), detailSystemId, version, channel); |
| | | } |
| | | String id = DeviceAdStrategy.createId(deviceId, detailSystemId); |
| | | DeviceAdStrategy strategy = deviceAdStrategyDao.get(id); |
| | |
| | | } |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | return new VideoDetailVO.VideoAdInfo(strategy.getDetailShortVideoPVAExpireTime() < now, strategy.getDetailShortVideoFSAExpireTime() < now); |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(strategy.getDetailShortVideoPVAExpireTime() < now, strategy.getDetailShortVideoFSAExpireTime() < now), detailSystemId, version, channel); |
| | | } |
| | | |
| | | @Override |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, String loginUid, String videoId, String from) { |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, int version, String channel, String loginUid, String videoId, String from) { |
| | | |
| | | VideoDetailVO.VideoAdInfo videoAdInfo = getVideoDetailAdStrategy(deviceId, detailSystemId, loginUid); |
| | | VideoDetailVO.VideoAdInfo videoAdInfo = getVideoDetailAdStrategy(deviceId, detailSystemId, version, channel, loginUid); |
| | | //从APP首页推荐而来,并且有全屏視頻廣告 |
| | | if (videoAdInfo.isFullVideo() && "recommend".equalsIgnoreCase(from)) { |
| | | //是否为4大分类 |
| | | VideoInfo videoInfo = videoInfoService.getVideoInfoCache(videoId); |
| | | //除正片外不展示全屏视频广告 |
| | | if (videoInfo != null && videoInfo.getContentType() != null && videoInfo.getContentType() != 1) { |
| | | VideoDetailVO.VideoAdInfo shortVideo = getVideoDetailShortVideoAdStrategy(deviceId, detailSystemId); |
| | | VideoDetailVO.VideoAdInfo shortVideo = getVideoDetailShortVideoAdStrategy(deviceId, detailSystemId, version, channel); |
| | | videoAdInfo.setFullVideo(videoAdInfo.isFullVideo() && shortVideo.isFullVideo()); |
| | | } |
| | | } |
| | |
| | | //记录当前看PP的次数 |
| | | String id = DeviceAdStrategy.createId(deviceId, detailSystemId); |
| | | String ppDayCount = "pptv-watch-count-" + id; |
| | | int timeS = (int) ((TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd")-System.currentTimeMillis()) / 1000); |
| | | int timeS = (int) ((TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd") - System.currentTimeMillis()) / 1000); |
| | | redisManager.increase(ppDayCount, 1); |
| | | redisManager.expire(ppDayCount, timeS); |
| | | String countStr = redisManager.getCommonString(ppDayCount); |