| | |
| | | package com.yeshi.buwan.service.imp.ad; |
| | | |
| | | 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.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 org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Resource |
| | | private VIPService vipService; |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | 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; |
| | | } |
| | |
| | | return new VideoDetailVO.VideoAdInfo(strategy.getDetailPVAExpireTime() < now, strategy.getDetailFSAExpireTime() < now); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取小视频广告展示策略 |
| | | * |
| | | * @param deviceId |
| | | * @param detailSystemId |
| | | * @return |
| | | */ |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailShortVideoAdStrategy(String deviceId, String detailSystemId) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return new VideoDetailVO.VideoAdInfo(true, true); |
| | | } |
| | | 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 new VideoDetailVO.VideoAdInfo(strategy.getDetailShortVideoPVAExpireTime() < now, strategy.getDetailShortVideoFSAExpireTime() < now); |
| | | } |
| | | |
| | | @Override |
| | | public void setVideoDetailAdStrategy(String deviceId, String detailSystemId, long fsaExpireTime, long pvaExpireTime) { |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, String loginUid, String videoId, String from) { |
| | | |
| | | VideoDetailVO.VideoAdInfo videoAdInfo = getVideoDetailAdStrategy(deviceId, detailSystemId, 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); |
| | | videoAdInfo.setFullVideo(videoAdInfo.isFullVideo() && shortVideo.isFullVideo()); |
| | | } |
| | | } |
| | | return videoAdInfo; |
| | | } |
| | | |
| | | @Override |
| | | public void setVideoDetailAdStrategy(String deviceId, String detailSystemId, Long fsaExpireTime, Long pvaExpireTime) { |
| | | if (StringUtil.isNullOrEmpty(deviceId) || StringUtil.isNullOrEmpty(detailSystemId)) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | DeviceAdStrategy update = new DeviceAdStrategy(); |
| | | update.setId(id); |
| | | update.setDetailFSAExpireTime(fsaExpireTime); |
| | | update.setDetailPVAExpireTime(pvaExpireTime); |
| | | if (fsaExpireTime != null) |
| | | update.setDetailFSAExpireTime(fsaExpireTime); |
| | | if (pvaExpireTime != null) |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |