| | |
| | | import com.yeshi.buwan.dao.ad.DeviceAdStrategyDao; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.ad.DeviceAdStrategy; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | 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.user.UserDPContentWatchStatisticService; |
| | | 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.video.VideoConstant; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import com.yeshi.buwan.vo.video.VideoDetailVO; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private DetailSystemConfigService detailSystemConfigService; |
| | | |
| | | @Resource |
| | | private UserDPContentWatchStatisticService userDPContentWatchStatisticService; |
| | | |
| | | private DeviceAdStrategy init(String id, String deviceId, String detailSystemId) { |
| | | DeviceAdStrategy strategy = new DeviceAdStrategy(); |
| | | strategy.setId(id); |
| | |
| | | strategy.setCreateTime(new Date()); |
| | | strategy.setDetailFSAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | strategy.setDetailPVAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | |
| | | strategy.setDetailShortVideoFSAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | strategy.setDetailShortVideoPVAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | deviceAdStrategyDao.save(strategy); |
| | | 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 filterData(loadAdWeight(new VideoDetailVO.VideoAdInfo(strategy.getDetailPVAExpireTime() < now, strategy.getDetailFSAExpireTime() < now), detailSystemId, version, channel), detailSystemId, deviceId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取小视频广告展示策略 |
| | | * |
| | | * @param deviceId |
| | | * @param detailSystemId |
| | | * @return |
| | | */ |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailShortVideoAdStrategy(String deviceId, String detailSystemId, int version, String channel) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return loadAdWeight(new VideoDetailVO.VideoAdInfo(true, true), detailSystemId, version, channel); |
| | | } |
| | | String id = DeviceAdStrategy.createId(deviceId, detailSystemId); |
| | | DeviceAdStrategy strategy = deviceAdStrategyDao.get(id); |
| | | if (strategy == null) { |
| | | strategy = init(id, deviceId, detailSystemId); |
| | | } |
| | | |
| | | if (strategy.getDetailShortVideoPVAExpireTime() == null) { |
| | | strategy.setDetailShortVideoPVAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | } |
| | | |
| | | if (strategy.getDetailShortVideoFSAExpireTime() == null) { |
| | | strategy.setDetailShortVideoFSAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | } |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | return filterData(loadAdWeight(new VideoDetailVO.VideoAdInfo(strategy.getDetailShortVideoPVAExpireTime() < now, strategy.getDetailShortVideoFSAExpireTime() < now), detailSystemId, version, channel), detailSystemId, deviceId); |
| | | } |
| | | |
| | | @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, version, channel); |
| | | videoAdInfo.setFullVideo(videoAdInfo.isFullVideo() && shortVideo.isFullVideo()); |
| | | } |
| | | } |
| | | |
| | | |
| | | return filterData(videoAdInfo, detailSystemId, deviceId); |
| | | } |
| | | |
| | | |
| | | private VideoDetailVO.VideoAdInfo filterData(VideoDetailVO.VideoAdInfo videoAdInfo, String detailSystemId, String deviceId) { |
| | | DetailSystem ds = new DetailSystem(); |
| | | ds.setId(detailSystemId); |
| | | if (videoAdInfo != null) { |
| | | AcceptData acceptData = new AcceptData(); |
| | | acceptData.setUtdId(deviceId); |
| | | acceptData.setDetailSystem(ds); |
| | | boolean isDPUser = userDPContentWatchStatisticService.isDPUser(acceptData); |
| | | if (isDPUser) { |
| | | videoAdInfo.setFullVideo(false); |
| | | videoAdInfo.setPlayVideo(false); |
| | | } |
| | | } |
| | | return videoAdInfo; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void setVideoDetailAdStrategy(String deviceId, String detailSystemId, Long fsaExpireTime, Long pvaExpireTime) { |
| | |
| | | update.setDetailPVAExpireTime(pvaExpireTime); |
| | | deviceAdStrategyDao.updateSelective(update); |
| | | } |
| | | |
| | | @Override |
| | | public void setShortVideoAdStrategy(String deviceId, String detailSystemId, String videoId, String from, Long fsaExpireTime, Long pvaExpireTime) { |
| | | //只有首页推荐小视频才设置 |
| | | if (!"recommend".equalsIgnoreCase(from)) |
| | | return; |
| | | |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | VideoInfo videoInfo = videoInfoService.getVideoInfoCache(videoId); |
| | | //除正片外不展示全屏视频广告 |
| | | if (videoInfo != null && videoInfo.getContentType() != null && videoInfo.getContentType() != 1) { |
| | | |
| | | String id = DeviceAdStrategy.createId(deviceId, detailSystemId); |
| | | DeviceAdStrategy strategy = deviceAdStrategyDao.get(id); |
| | | if (strategy == null) { |
| | | init(id, deviceId, detailSystemId); |
| | | } |
| | | DeviceAdStrategy update = new DeviceAdStrategy(); |
| | | update.setId(id); |
| | | if (fsaExpireTime != null) |
| | | update.setDetailShortVideoFSAExpireTime(fsaExpireTime); |
| | | if (pvaExpireTime != null) |
| | | update.setDetailShortVideoPVAExpireTime(pvaExpireTime); |
| | | deviceAdStrategyDao.updateSelective(update); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void watchPPTVVideo(String deviceId, String detailSystemId) { |
| | | //记录当前看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); |
| | | redisManager.increase(ppDayCount, 1); |
| | | redisManager.expire(ppDayCount, timeS); |
| | | String countStr = redisManager.getCommonString(ppDayCount); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(countStr) && Integer.parseInt(countStr) >= 2) { |
| | | long showTime = TimeUtil.convertGernalTime(TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd"); |
| | | setVideoDetailAdStrategy(deviceId, detailSystemId, showTime, null); |
| | | } |
| | | |
| | | } |
| | | } |