| | |
| | | package com.yeshi.buwan.controller.api; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.domain.jump.JumpDetail; |
| | | import com.yeshi.buwan.domain.jump.JumpTypeEnum; |
| | | import com.yeshi.buwan.domain.pptv.PPTVPlayProcessRecord; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.pptv.entity.PPTVProgram; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeriesProgramMap; |
| | | import com.yeshi.buwan.pptv.entity.VideoPPTVMap; |
| | | import com.yeshi.buwan.domain.vip.VideoBuyRecord; |
| | | import com.yeshi.buwan.exception.ParamsException; |
| | | import com.yeshi.buwan.service.imp.DetailSystemConfigService; |
| | | import com.yeshi.buwan.videos.pptv.PPTVApiUtil; |
| | | import com.yeshi.buwan.videos.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.videos.pptv.entity.PPTVProgram; |
| | | import com.yeshi.buwan.videos.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.videos.pptv.entity.PPTVSeriesProgramMap; |
| | | import com.yeshi.buwan.videos.pptv.entity.VideoPPTVMap; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVPlayProcessRecordService; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.inter.push.PushDeviceTokenService; |
| | | import com.yeshi.buwan.service.inter.system.SystemConfigService; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.service.inter.vip.VideoBuyRecordService; |
| | | import com.yeshi.buwan.util.*; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import com.yeshi.buwan.vo.video.PPTVVideoActivityInfoVO; |
| | | import com.yeshi.buwan.vo.video.PPTVWatchVIPVideoActivityWay; |
| | | import org.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Controller; |
| | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v2/video/play") |
| | |
| | | |
| | | @Resource |
| | | private VideoWatchHistoryService videoWatchHistoryService; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Resource |
| | | private DetailSystemConfigService detailSystemConfigService; |
| | | |
| | | @Resource |
| | | private VIPService vipService; |
| | | |
| | | @Resource |
| | | private VideoBuyRecordService videoBuyRecordService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private PPTVPlayProcessRecordService pptvPlayProcessRecordService; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | logger.info("播放PPTV:loginUid-{},cid-{},vid-{}", loginUid, Cid, Vid); |
| | | |
| | | PPTVSeriesProgramMap map = pptvService.selectMapByCode(Cid, Vid); |
| | | PPTVSeriesProgramMap map = pptvService.selectMapByCode(Cid, StringUtil.isNullOrEmpty(Vid) ? null : Vid); |
| | | if (map != null) { |
| | | String infoId = map.getInfoId(); |
| | | VideoPPTVMap videoPPTVMap = pptvService.selectVideoPPTVMapByInfoId(infoId); |
| | | PPTVSeries series = pptvService.selectSeriesBySeriesCode(Cid); |
| | | if (series == null) { |
| | | return ""; |
| | | } |
| | | |
| | | VideoPPTVMap videoPPTVMap = pptvService.selectVideoPPTVMapByPPInfo(infoId, (series.getProgramType().contains("电影") || series.getProgramType2().contains("电影")) ? Vid : null); |
| | | |
| | | if (videoPPTVMap != null) { |
| | | PPTVProgram program = pptvService.selectProgramById(Vid); |
| | | PPTVProgram program = pptvService.selectProgramById(StringUtil.isNullOrEmpty(Vid) ? Cid : Vid); |
| | | if (program != null && program.getSeriesNum() != null) { |
| | | //当前播放的集数 program.getSeriesNum(); |
| | | VideoWatchHistory history = new VideoWatchHistory(); |
| | | history.setDevice(acceptData.getDevice()); |
| | | history.setVideoId(videoPPTVMap.getVideoId()); |
| | | history.setUid(loginUid); |
| | | history.setPosition(Integer.parseInt(program.getSeriesNum()) - 1); |
| | | history.setPosition(StringUtil.isNullOrEmpty(program.getSeriesNum()) ? 0 : Integer.parseInt(program.getSeriesNum()) - 1); |
| | | videoWatchHistoryService.add(history); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | @RequestMapping("pptvFinishPlay") |
| | | @ResponseBody |
| | | public String pptvFinishPlay(AcceptData acceptData, String loginUid, String cid, String vid, Integer currentTime) { |
| | | ///记录结束播放 |
| | | PPTVPlayProcessRecord record = new PPTVPlayProcessRecord(); |
| | | record.setCid(cid); |
| | | record.setDetailSystemId(acceptData.getDetailSystem().getId()); |
| | | record.setDeviceId(StringUtil.isNullOrEmpty(acceptData.getUtdId()) ? acceptData.getDevice() : acceptData.getUtdId()); |
| | | record.setVid(vid); |
| | | record.setLoginUid(loginUid); |
| | | record.setCurrentTime(currentTime); |
| | | try { |
| | | pptvPlayProcessRecordService.addRecord(record); |
| | | } catch (ParamsException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return JsonUtil.loadTrueJson(""); |
| | | } |
| | | |
| | | /** |
| | | * 获取pptv的活动 |
| | | * |
| | | * @param acceptData |
| | | * @param loginUid |
| | | * @param cid |
| | | * @param vid |
| | | * @return |
| | | */ |
| | | @RequestMapping("getPPTVVIPVideoActivity") |
| | | @ResponseBody |
| | | public String getPPTVVIPVideoActivity(AcceptData acceptData, String loginUid, String cid, String vid) { |
| | | //查询cid与vid的名字 |
| | | PPTVSeries pptvSeries = pptvService.selectSeriesBySeriesCode(cid); |
| | | if (pptvSeries == null) { |
| | | // PPTVProgram program = pptvService.selectProgramById(cid); |
| | | try { |
| | | pptvSeries = PPTVApiUtil.getDetail(cid); |
| | | ThreadUtil.run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pptvService.syncSeries(cid); |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(vid)) { |
| | | vid = cid; |
| | | } |
| | | |
| | | PPTVVideoActivityInfoVO vo = new PPTVVideoActivityInfoVO(); |
| | | if (pptvSeries != null) { |
| | | vo.setVideoName("《" + pptvSeries.getName() + "》"); |
| | | } else { |
| | | vo.setVideoName("《未知视频》"); |
| | | } |
| | | |
| | | List<PPTVWatchVIPVideoActivityWay> wayList = new ArrayList<>(); |
| | | PPTVWatchVIPVideoActivityWay way = null; |
| | | |
| | | if (!vipService.isVIP(loginUid)) { |
| | | way = new PPTVWatchVIPVideoActivityWay(); |
| | | way.setEndBgColor("#E9CE93"); |
| | | way.setStartBgColor("#F7EDD7"); |
| | | way.setEndPrice(new BigDecimal("77.8")); |
| | | way.setIcon("https://buwan-1255749512.cos.ap-guangzhou.myqcloud.com/resource/icon_vip.png"); |
| | | way.setStartPrice(new BigDecimal("8.8")); |
| | | way.setSubTitle("包月、季、年卡"); |
| | | way.setTitle("VIP看高清 免广告"); |
| | | way.setTextColor("#885E24"); |
| | | way.setType("vip"); |
| | | wayList.add(way); |
| | | } |
| | | |
| | | |
| | | //3.9.2后返回单片购买 |
| | | if (VersionUtil.isGraterThan392(acceptData.getPlatform(), acceptData.getVersion())) { |
| | | String buyVideoUrl = systemConfigService.getConfigValueByKeyCache("buyVideoUrl"); |
| | | if (buyVideoUrl != null && pptvSeries != null && PPTVUtil.isVIPVideo(pptvSeries.getFree()) && PPTVUtil.getAvaiableStates().contains(pptvSeries.getStatus())) { |
| | | boolean canBuy = pptvSeries.getGoodsInfo() != null && !StringUtil.isNullOrEmpty(pptvSeries.getGoodsInfo().getGoodsNo()); |
| | | if (canBuy) { |
| | | way = new PPTVWatchVIPVideoActivityWay(); |
| | | way.setEndBgColor("#DCE8FF"); |
| | | way.setStartBgColor("#DCE8FF"); |
| | | // way.setEndPrice(new BigDecimal("77.8")); |
| | | way.setIcon("http://img.ysdq.yeshitv.com/resource/icon_free_money.png"); |
| | | way.setStartPrice(new BigDecimal("0")); |
| | | way.setSubTitle("畅享海量高清"); |
| | | way.setTitle("0元看单片(影视豆抵扣)"); |
| | | way.setTextColor("#0052F6"); |
| | | way.setType("video"); |
| | | JumpDetail jumpDetail = new JumpDetail(); |
| | | jumpDetail.setNeedLogin(true); |
| | | jumpDetail.setType(JumpTypeEnum.web); |
| | | way.setJumpDetail(jumpDetail); |
| | | JSONObject params = new JSONObject(); |
| | | params.put("url", buyVideoUrl.replace("{cid}", cid).replace("{vid}", vid)); |
| | | params.put("close", false); |
| | | way.setParams(params.toString().replace("\"", "\\" + "\"")); |
| | | wayList.add(way); |
| | | } |
| | | } |
| | | } |
| | | |
| | | vo.setWayList(wayList); |
| | | return JsonUtil.loadTrueJson(new Gson().toJson(vo)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取PPTV的播放状态 |
| | | * |
| | | * @param acceptData |
| | | * @param loginUid |
| | | * @param cid |
| | | * @param vid |
| | | * @return |
| | | */ |
| | | @RequestMapping("getPPTVVideoPlayState") |
| | | @ResponseBody |
| | | public String getPPTVVideoPlayState(AcceptData acceptData, String loginUid, String cid, String vid) { |
| | | |
| | | vid = StringUtil.isNullOrEmpty(vid) ? cid : vid; |
| | | |
| | | //获取当前用户是否为vip |
| | | boolean vip = StringUtil.isNullOrEmpty(loginUid) ? false : vipService.isVIP(loginUid); |
| | | |
| | | boolean isVIPVideo = false; |
| | | boolean isBought = false; |
| | | boolean canBuy = false; |
| | | //获取是否为vip视频 |
| | | PPTVSeries pptvSeries = pptvService.selectSeriesBySeriesCode(cid); |
| | | |
| | | if (pptvSeries != null) { |
| | | if (StringUtil.isNullOrEmpty(vid) || vid.trim().equalsIgnoreCase("0")) { |
| | | if (pptvSeries != null) { |
| | | isVIPVideo = PPTVUtil.isVIPVideo(pptvSeries.getFree()); |
| | | } |
| | | } else { |
| | | PPTVProgram program = pptvService.selectProgramById(vid); |
| | | if (program != null) |
| | | isVIPVideo = PPTVUtil.isVIPVideo(program.getFree()); |
| | | } |
| | | |
| | | canBuy = pptvSeries.getGoodsInfo() != null && !StringUtil.isNullOrEmpty(pptvSeries.getGoodsInfo().getGoodsNo()); |
| | | //是否已经购买单片 |
| | | if (pptvSeries != null && canBuy) { |
| | | isBought = !StringUtil.isNullOrEmpty(redisManager.getCommonString(PPTVUtil.getBuyGoodsCacheKey(loginUid, pptvSeries.getGoodsInfo().getGoodsNo()))); |
| | | } |
| | | } |
| | | |
| | | if (!isBought) |
| | | isBought = videoBuyRecordService.isBought(loginUid, cid, vid, new Date()); |
| | | |
| | | //获取播放进度 |
| | | PPTVPlayProcessRecord record = new PPTVPlayProcessRecord(); |
| | | record.setCid(cid); |
| | | record.setDetailSystemId(acceptData.getDetailSystem().getId()); |
| | | record.setDeviceId(StringUtil.isNullOrEmpty(acceptData.getUtdId()) ? acceptData.getDevice() : acceptData.getUtdId()); |
| | | String id = PPTVPlayProcessRecord.createId(record.getDetailSystemId(), record.getDeviceId(), cid); |
| | | record = pptvPlayProcessRecordService.selectByPrimaryKey(id); |
| | | |
| | | |
| | | net.sf.json.JSONObject data = new net.sf.json.JSONObject(); |
| | | data.put("vipUser", vip); |
| | | data.put("vipVideo", isVIPVideo); |
| | | data.put("bought", isBought); |
| | | data.put("canBuy", canBuy); |
| | | |
| | | |
| | | //华为是否在上线,在上线就不展示 |
| | | String onLiningVersionInfo = detailSystemConfigService.getConfigValueByKey("ad_hw_online_version_info", acceptData.getDetailSystem().getId(), acceptData.getVersion()); |
| | | net.sf.json.JSONObject onLiningVersionInfoJson = net.sf.json.JSONObject.fromObject(onLiningVersionInfo); |
| | | int onLiningVersionCode = onLiningVersionInfoJson.optInt("versionCode"); |
| | | |
| | | if ("huawei".equalsIgnoreCase(acceptData.getChannel()) && onLiningVersionCode <= acceptData.getVersion()) { |
| | | data.put("showInterstitialAd", false); |
| | | } else |
| | | data.put("showInterstitialAd", true); |
| | | data.put("showPreVideoAd", false); |
| | | if (pptvSeries != null) |
| | | data.put("title", pptvSeries.getName()); |
| | | if (record != null) { |
| | | data.put("playPosition", record.getCurrentTime()); |
| | | } |
| | | return JsonUtil.loadTrueJson(data.toString()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取订单的视频信息 |
| | | * |
| | | * @param acceptData |
| | | * @return |
| | | */ |
| | | @RequestMapping("getOrderVideoInfo") |
| | | @ResponseBody |
| | | public String getOrderVideoInfo(AcceptData acceptData, String loginUid, String cid, String vid) { |
| | | VideoBuyRecord record = videoBuyRecordService.getLatestRecord(loginUid, cid, vid); |
| | | if (record == null) { |
| | | return JsonUtil.loadFalseJson("购买记录不存在"); |
| | | } |
| | | JumpDetail jumpDetail = new JumpDetail(); |
| | | jumpDetail.setType(JumpTypeEnum.clazz); |
| | | jumpDetail.setActivity("com.weikou.beibeivideo.ui.media.VideoDetailActivity2"); |
| | | net.sf.json.JSONObject params = new net.sf.json.JSONObject(); |
| | | params.put("Id", PPTVUtil.getVisualVideoId(record.getCid(), record.getVid())); |
| | | params.put("from", "order"); |
| | | |
| | | net.sf.json.JSONObject data = new net.sf.json.JSONObject(); |
| | | data.put("jumpDetail", new Gson().toJson(jumpDetail)); |
| | | data.put("params", params); |
| | | return JsonUtil.loadTrueJson(data.toString()); |
| | | } |
| | | |
| | | |
| | | } |