admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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.domain.vip.VideoBuyRecord;
import com.yeshi.buwan.exception.ParamsException;
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.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.RequestMapping;
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")
public class VideoPlayController {
 
    Logger logger = LoggerFactory.getLogger(VideoPlayController.class);
 
    @Resource
    private PPTVService pptvService;
 
    @Resource
    private VideoWatchHistoryService videoWatchHistoryService;
 
    @Resource
    private SystemConfigService systemConfigService;
 
    @Resource
    private VIPService vipService;
 
    @Resource
    private VideoBuyRecordService videoBuyRecordService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private PPTVPlayProcessRecordService pptvPlayProcessRecordService;
 
 
    /**
     * PPTV播放
     *
     * @param acceptData
     * @param loginUid
     * @param Cid
     * @param Vid
     * @return
     */
    @RequestMapping("pptvPlay")
    @ResponseBody
    public String pptvPlay(AcceptData acceptData, String loginUid, String Cid, String Vid) {
 
        logger.info("播放PPTV:loginUid-{},cid-{},vid-{}", loginUid, Cid, Vid);
 
        PPTVSeriesProgramMap map = pptvService.selectMapByCode(Cid, StringUtil.isNullOrEmpty(Vid) ? null : Vid);
        if (map != null) {
            String infoId = map.getInfoId();
            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(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(StringUtil.isNullOrEmpty(program.getSeriesNum()) ? 0 : Integer.parseInt(program.getSeriesNum()) - 1);
                    videoWatchHistoryService.add(history);
                }
            }
        }
        return "";
    }
 
 
    @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);
        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());
    }
 
 
}