| | |
| | | import com.yeshi.buwan.domain.video.InternetSearchVideo; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.dto.log.BaseLog; |
| | | import com.yeshi.buwan.dto.statistic.video.VideoDetailStatisticData; |
| | | import com.yeshi.buwan.mogotv.MogoTVUtil; |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.service.imp.*; |
| | | import com.yeshi.buwan.service.inter.ad.DeviceAdStrategyService; |
| | | import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.inter.juhe.YouKuService; |
| | | import com.yeshi.buwan.service.inter.recommend.HomeRecommendSpecialService; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import com.yeshi.buwan.service.manager.VideoPlayStatisticManager; |
| | | import com.yeshi.buwan.tencent.TencentVideoUtil; |
| | | import com.yeshi.buwan.util.*; |
| | | import com.yeshi.buwan.util.annotation.RequireUid; |
| | |
| | | |
| | | @Resource |
| | | private HomeRecommendSpecialService homeRecommendSpecialService; |
| | | |
| | | @Resource |
| | | private DeviceAdStrategyService deviceAdStrategyService; |
| | | |
| | | private final Logger userPlayLogger = LoggerFactory.getLogger("videoPlayUser"); |
| | | |
| | |
| | | @Resource |
| | | private TencentVideoUtil tencentVideoUtil; |
| | | |
| | | @Resource |
| | | private VideoPlayStatisticManager videoPlayStatisticManager; |
| | | |
| | | |
| | | private String createVideoDetailSessionId(AcceptData acceptData, String uid, String videoName, String videoId, String resourceId) { |
| | | |
| | | try { |
| | | VideoDetailStatisticData data = new VideoDetailStatisticData(); |
| | | data.setDetailSystemId(acceptData.getDetailSystem().getId()); |
| | | data.setLoginUid(uid); |
| | | data.setResourceId(Integer.parseInt(resourceId)); |
| | | data.setUtdId(acceptData.getUtdId()); |
| | | data.setVersion(acceptData.getVersion()); |
| | | data.setVideoId(videoId); |
| | | data.setVideoName(videoName); |
| | | |
| | | return videoPlayStatisticManager.createVideoDetailSessionId(data); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public void getVideoDetailForInternetSearch(AcceptData acceptData, String videoId, HttpServletRequest request, PrintWriter out) { |
| | | String loginUid = request.getParameter("LoginUid"); |
| | |
| | | JSONObject obj = new JSONObject(); |
| | | |
| | | if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion())) { |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), new VideoDetailVO.VideoAdInfo(true, false), null)), array.toString(), |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), deviceAdStrategyService.getVideoDetailAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), loginUid), null, createVideoDetailSessionId(acceptData, loginUid, info.getName(), videoId, resourceId))), array.toString(), |
| | | obj.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(), |
| | |
| | | |
| | | p = p >= series.getSeries().size() ? 0 : p; |
| | | |
| | | String sessionId = createVideoDetailSessionId(acceptData, loginUid, series.getName(), videoId, resourceId); |
| | | String playUrl = PPTVUtil.getPlayUrl(series, series.getSeries().get(p)); |
| | | data.put("videoId", videoId); |
| | | data.put("playUrl", playUrl); |
| | | data.put("name", series.getName()); |
| | | data.put("pptv", true); |
| | | data.put("sessionId", sessionId); |
| | | out.print(JsonUtil.loadTrueJson(data.toString())); |
| | | LoggerUtil.getUserActiveLogger().info(UserActiveLogFactory.createVideoDetail(new BaseLog(acceptData, loginUid), videoId, series.getName(), from)); |
| | | return; |
| | |
| | | } |
| | | UserInfo user = userService.getUserInfo(acceptData.getUid()); |
| | | if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion())) { |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), new VideoDetailVO.VideoAdInfo(true, true), attention)), array.toString(), |
| | | String sessionId = createVideoDetailSessionId(acceptData, loginUid, info.getName(), videoId, resourceId); |
| | | |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), deviceAdStrategyService.getVideoDetailAdStrategy(acceptData.getUtdId(), acceptData.getDetailSystem().getId(), loginUid), attention, sessionId)), array.toString(), |
| | | obj.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(), |
New file |
| | |
| | | package com.yeshi.buwan.dao.ad; |
| | | |
| | | import com.yeshi.buwan.domain.ad.DeviceAdStrategy; |
| | | import com.yeshi.buwan.dao.base.MongodbBaseDao; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Repository |
| | | public class DeviceAdStrategyDao extends MongodbBaseDao<DeviceAdStrategy> { |
| | | |
| | | public void updateSelective(DeviceAdStrategy bean) { |
| | | Query query = new Query(); |
| | | Update update = new Update(); |
| | | query.addCriteria(Criteria.where("id").is(bean.getId())); |
| | | if (bean.getDetailSystemId() != null) { |
| | | update.set("detailSystemId", bean.getDetailSystemId()); |
| | | } |
| | | if (bean.getDeviceId() != null) { |
| | | update.set("deviceId", bean.getDeviceId()); |
| | | } |
| | | if (bean.getDetailFSAExpireTime() != null) { |
| | | update.set("detailFSAExpireTime", bean.getDetailFSAExpireTime()); |
| | | } |
| | | if (bean.getDetailPVAExpireTime() != null) { |
| | | update.set("detailPVAExpireTime", bean.getDetailPVAExpireTime()); |
| | | } |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | } |
| | | } |
| | |
| | | package com.yeshi.buwan.domain.ad; |
| | | |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.index.Indexed; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 设置广告策略 |
| | | */ |
| | | @Document(collection = "deviceAdStrategy") |
| | | public class DeviceAdStrategy { |
| | | public final static long ALWAYS_DISPLAY = -1L; |
| | | |
| | | |
| | | @Id |
| | | //设备ID |
| | | private String deviceId; |
| | | private String id; |
| | | @Indexed |
| | | //设备平台 |
| | | private String platform; |
| | | private String detailSystemId; |
| | | |
| | | @Indexed |
| | | private String deviceId; |
| | | |
| | | |
| | | //下次详情页 全屏视频广告的展示时间 |
| | | private Long detailFSAExpireTime; |
| | | |
| | | //下次详情页视频前贴展示的时间 |
| | | private Long detailPVAExpireTime; |
| | | |
| | | private Date createTime; |
| | | private Date updateTime; |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public Date getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Date updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getDetailSystemId() { |
| | | return detailSystemId; |
| | | } |
| | | |
| | | public void setDetailSystemId(String detailSystemId) { |
| | | this.detailSystemId = detailSystemId; |
| | | } |
| | | |
| | | public String getDeviceId() { |
| | | return deviceId; |
| | | } |
| | | |
| | | public void setDeviceId(String deviceId) { |
| | | this.deviceId = deviceId; |
| | | } |
| | | |
| | | public Long getDetailFSAExpireTime() { |
| | | return detailFSAExpireTime; |
| | | } |
| | | |
| | | public void setDetailFSAExpireTime(Long detailFSAExpireTime) { |
| | | this.detailFSAExpireTime = detailFSAExpireTime; |
| | | } |
| | | |
| | | public Long getDetailPVAExpireTime() { |
| | | return detailPVAExpireTime; |
| | | } |
| | | |
| | | public void setDetailPVAExpireTime(Long detailPVAExpireTime) { |
| | | this.detailPVAExpireTime = detailPVAExpireTime; |
| | | } |
| | | |
| | | public static String createId(String deviceId, String detailSystemId) { |
| | | return StringUtil.Md5(deviceId + "#" + detailSystemId); |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.dto.statistic.video; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * 详情页统计数据 |
| | | */ |
| | | public class VideoDetailStatisticData implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | |
| | | private String utdId; |
| | | private String detailSystemId; |
| | | private String loginUid; |
| | | private int version; |
| | | private String videoId; |
| | | private String videoName; |
| | | private int resourceId; |
| | | private long createTime; |
| | | |
| | | |
| | | public String getUtdId() { |
| | | return utdId; |
| | | } |
| | | |
| | | public void setUtdId(String utdId) { |
| | | this.utdId = utdId; |
| | | } |
| | | |
| | | public String getDetailSystemId() { |
| | | return detailSystemId; |
| | | } |
| | | |
| | | public void setDetailSystemId(String detailSystemId) { |
| | | this.detailSystemId = detailSystemId; |
| | | } |
| | | |
| | | public String getLoginUid() { |
| | | return loginUid; |
| | | } |
| | | |
| | | public void setLoginUid(String loginUid) { |
| | | this.loginUid = loginUid; |
| | | } |
| | | |
| | | public int getVersion() { |
| | | return version; |
| | | } |
| | | |
| | | public void setVersion(int version) { |
| | | this.version = version; |
| | | } |
| | | |
| | | public String getVideoId() { |
| | | return videoId; |
| | | } |
| | | |
| | | public void setVideoId(String videoId) { |
| | | this.videoId = videoId; |
| | | } |
| | | |
| | | public String getVideoName() { |
| | | return videoName; |
| | | } |
| | | |
| | | public void setVideoName(String videoName) { |
| | | this.videoName = videoName; |
| | | } |
| | | |
| | | public int getResourceId() { |
| | | return resourceId; |
| | | } |
| | | |
| | | public void setResourceId(int resourceId) { |
| | | this.resourceId = resourceId; |
| | | } |
| | | |
| | | public long getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(long createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.service.imp.ad; |
| | | |
| | | import com.yeshi.buwan.dao.ad.DeviceAdStrategyDao; |
| | | import com.yeshi.buwan.domain.ad.DeviceAdStrategy; |
| | | import com.yeshi.buwan.service.inter.ad.DeviceAdStrategyService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.vo.video.VideoDetailVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | |
| | | @Service |
| | | public class DeviceAdStrategyServiceImpl implements DeviceAdStrategyService { |
| | | |
| | | @Resource |
| | | private DeviceAdStrategyDao deviceAdStrategyDao; |
| | | |
| | | @Resource |
| | | private VIPService vipService; |
| | | |
| | | private DeviceAdStrategy init(String id, String deviceId, String detailSystemId) { |
| | | DeviceAdStrategy strategy = new DeviceAdStrategy(); |
| | | strategy.setId(id); |
| | | strategy.setDeviceId(deviceId); |
| | | strategy.setDetailSystemId(detailSystemId); |
| | | strategy.setCreateTime(new Date()); |
| | | strategy.setDetailFSAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | strategy.setDetailPVAExpireTime(DeviceAdStrategy.ALWAYS_DISPLAY); |
| | | deviceAdStrategyDao.save(strategy); |
| | | return strategy; |
| | | } |
| | | |
| | | @Override |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, String loginUid) { |
| | | |
| | | //走VIP判定逻辑 |
| | | if (!StringUtil.isNullOrEmpty(loginUid)) { |
| | | if (vipService.isVIP(loginUid)) { |
| | | //VIP不展示视频前贴和全屏 |
| | | return new VideoDetailVO.VideoAdInfo(false, false); |
| | | } |
| | | } |
| | | |
| | | String id = DeviceAdStrategy.createId(deviceId, detailSystemId); |
| | | DeviceAdStrategy strategy = deviceAdStrategyDao.get(id); |
| | | if (strategy == null) { |
| | | strategy = init(id, deviceId, detailSystemId); |
| | | } |
| | | long now = System.currentTimeMillis(); |
| | | return new VideoDetailVO.VideoAdInfo(strategy.getDetailPVAExpireTime() < now, strategy.getDetailFSAExpireTime() < now); |
| | | } |
| | | |
| | | @Override |
| | | public void setVideoDetailAdStrategy(String deviceId, String detailSystemId, long fsaExpireTime, long pvaExpireTime) { |
| | | 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); |
| | | update.setDetailFSAExpireTime(fsaExpireTime); |
| | | update.setDetailPVAExpireTime(pvaExpireTime); |
| | | deviceAdStrategyDao.updateSelective(update); |
| | | } |
| | | } |
| | |
| | | list.toArray(params); |
| | | return userVIPInfoDao.getCount(hql, params); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isVIP(String loginUid) { |
| | | UserVIPInfo userVIPInfo = userVIPInfoDao.find(UserVIPInfo.class, loginUid); |
| | | if (userVIPInfo == null) |
| | | return false; |
| | | if (userVIPInfo.getExpireDate() == null) |
| | | return false; |
| | | |
| | | if (userVIPInfo.getExpireDate().getTime() < System.currentTimeMillis()) |
| | | return false; |
| | | return true; |
| | | } |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.service.inter.ad; |
| | | |
| | | import com.yeshi.buwan.vo.video.VideoDetailVO; |
| | | |
| | | public interface DeviceAdStrategyService { |
| | | |
| | | /** |
| | | * 获取视频详情页的广告展示策略 |
| | | * |
| | | * @param deviceId |
| | | * @param detailSystemId |
| | | * @return |
| | | */ |
| | | public VideoDetailVO.VideoAdInfo getVideoDetailAdStrategy(String deviceId, String detailSystemId, String loginUid); |
| | | |
| | | |
| | | /** |
| | | * 设置详情页广告展示策略 |
| | | * @param deviceId |
| | | * @param detailSystemId |
| | | * @param fsaExpireTime |
| | | * @param pvaExpireTime |
| | | */ |
| | | public void setVideoDetailAdStrategy(String deviceId, String detailSystemId,long fsaExpireTime,long pvaExpireTime); |
| | | |
| | | } |
| | |
| | | public long countVIPUser(Date minVIPExpireDate,Date maxVIPExpireDate); |
| | | |
| | | |
| | | public boolean isVIP(String loginUid); |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.service.manager; |
| | | |
| | | import com.yeshi.buwan.dto.statistic.video.VideoDetailStatisticData; |
| | | import com.yeshi.buwan.util.RedisManager; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * 播放统计管理 |
| | | */ |
| | | @Component |
| | | public class VideoPlayStatisticManager { |
| | | |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | /** |
| | | * 创建会话 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public String createVideoDetailSessionId(VideoDetailStatisticData data) { |
| | | if (data.getCreateTime() == 0L) { |
| | | data.setCreateTime(System.currentTimeMillis()); |
| | | } |
| | | String sessionId = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis() + "#" + data.getUtdId()); |
| | | //缓存8小时 |
| | | redisManager.setDataToRedis("session-" + sessionId, data, 60 * 60 * 8); |
| | | return sessionId; |
| | | } |
| | | |
| | | |
| | | public void consumeVideoDetailSession(String sessionId) { |
| | | String key = "session-" + sessionId; |
| | | VideoDetailStatisticData data = (VideoDetailStatisticData) redisManager.getDataFromRedis(key); |
| | | redisManager.remove(key); |
| | | //TODO 做日志记录 |
| | | if (data != null) { |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.vo.video.VideoListResultVO; |
| | | |
| | | import org.yeshi.utils.SerializeUtil; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | import redis.clients.jedis.params.SetParams; |
| | |
| | | removeKey(key); |
| | | } |
| | | |
| | | public void remove(String key) { |
| | | removeKey(key); |
| | | } |
| | | |
| | | /** |
| | | * 保存视频数据 |
| | | * |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 从redis缓存中查询,反序列化 |
| | | * |
| | | * @param redisKey |
| | | * @return |
| | | */ |
| | | public Object getDataFromRedis(String redisKey) { |
| | | //查询 |
| | | Jedis jedis = jedisPool.getResource(); |
| | | try { |
| | | byte[] result = jedis.get(redisKey.getBytes()); |
| | | |
| | | //如果查询没有为空 |
| | | if (null == result) { |
| | | return null; |
| | | } |
| | | |
| | | //查询到了,反序列化 |
| | | return SerializeUtil.unSerialize(result); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将数据库中查询到的数据放入redis |
| | | * |
| | | * @param redisKey |
| | | * @param obj |
| | | */ |
| | | public void setDataToRedis(String redisKey, Object obj, Integer seconds) { |
| | | |
| | | //序列化 |
| | | byte[] bytes = SerializeUtil.serialize(obj); |
| | | |
| | | SetParams params = null; |
| | | if (seconds != null) { |
| | | params = new SetParams().nx().ex(seconds); |
| | | } |
| | | //存入redis |
| | | Jedis jedis = jedisPool.getResource(); |
| | | try { |
| | | jedis.set(redisKey.getBytes(), bytes, params); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | @Expose |
| | | private AttentionInfo attention; |
| | | |
| | | @Expose |
| | | private String sessionId; |
| | | |
| | | public VideoDetailVO(VideoInfoDetail video, VideoAdInfo adInfo, AttentionInfo attention) { |
| | | |
| | | public VideoDetailVO(VideoInfoDetail video, VideoAdInfo adInfo, AttentionInfo attention, String sessionId) { |
| | | this.video = video; |
| | | this.adInfo = adInfo; |
| | | this.attention = attention; |
| | | this.sessionId = sessionId; |
| | | } |
| | | |
| | | public VideoInfoDetail getVideo() { |