| | |
| | | package com.yeshi.buwan.controller.parser; |
| | | |
| | | import com.ks.lib.common.exception.ParamsException; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.uservideo.CollectionVideoV2; |
| | | import com.yeshi.buwan.domain.video.InternetSearchVideo; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.service.imp.AttentionService; |
| | | import com.yeshi.buwan.service.imp.CollectionService; |
| | | import com.yeshi.buwan.service.imp.VideoService; |
| | | import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService; |
| | | import com.yeshi.buwan.service.inter.uservideo.CollectionVideoV2Service; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import com.yeshi.buwan.util.JsonUtil; |
| | | import com.yeshi.buwan.util.NumberUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.factory.VideoInfoFactory; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class UserVideoParser { |
| | |
| | | |
| | | @Resource |
| | | private AttentionService attentionService; |
| | | |
| | | @Resource |
| | | private CollectionVideoV2Service collectionVideoV2Service; |
| | | |
| | | @Resource |
| | | private InternetSearchVideoService internetSearchVideoService; |
| | | |
| | | |
| | | public void getWatchHistory(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | |
| | |
| | | if (vi != null) |
| | | videoInfoMap.put(vi.getId(), vi); |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | VideoWatchHistory wh = list.get(i); |
| | | if (videoInfoMap.get(list.get(i).getVideoId()) == null) { |
| | | list.remove(i--); |
| | | videoWatchHistoryService.delete(Arrays.asList(new String[]{wh.getId()})); |
| | | } else { |
| | | wh.setVideo(videoInfoMap.get(wh.getVideoId())); |
| | | } |
| | | } |
| | | |
| | | for (VideoWatchHistory wh : list) { |
| | | wh.setVideo(videoInfoMap.get(wh.getVideoId())); |
| | | } |
| | |
| | | } |
| | | |
| | | long collectionCount = collectionService.getCollectVideoCount(acceptData.getUid()); |
| | | long collectionCountNew = collectionVideoV2Service.countByUid(loginUid); |
| | | long attentionCount = attentionService.getAttentionCountByLoginUid(Long.parseLong(loginUid)); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("collectionCount", collectionCount); |
| | | data.put("collectionCount", collectionCount == 0 ? collectionCountNew : collectionCount); |
| | | data.put("attentionCount", attentionCount); |
| | | out.print(JsonUtil.loadTrueJson(data.toString())); |
| | | } |
| | | |
| | | public void collectVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | |
| | | String loginUid = request.getParameter("LoginUid"); |
| | | String videoId = request.getParameter("VideoId"); |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | out.print(JsonUtil.loadFalseJson("用户未登录")); |
| | | return; |
| | | } |
| | | CollectionVideoV2 v2 = new CollectionVideoV2(); |
| | | v2.setVideoId(videoId); |
| | | v2.setLoginUid(loginUid); |
| | | try { |
| | | collectionVideoV2Service.add(v2); |
| | | } catch (ParamsException e) { |
| | | if (e.getCode() == ParamsException.CODE_EXIST) { |
| | | out.print(JsonUtil.loadFalseJson("已收藏")); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadFalseJson("收藏出错")); |
| | | return; |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | |
| | | out.print(JsonUtil.loadTrueJson(data.toString())); |
| | | } |
| | | |
| | | public void cancelCollectVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | String loginUid = request.getParameter("LoginUid"); |
| | | String videoIds = request.getParameter("VideoId"); |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | out.print(JsonUtil.loadFalseJson("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(videoIds)) { |
| | | out.print(JsonUtil.loadFalseJson("未上传视频ID")); |
| | | return; |
| | | } |
| | | |
| | | String[] videoIdArray = videoIds.split(","); |
| | | |
| | | List<String> ids = new ArrayList<>(); |
| | | for (String id : videoIdArray) { |
| | | ids.add(CollectionVideoV2.createId(loginUid, id)); |
| | | } |
| | | collectionVideoV2Service.delete(ids); |
| | | JSONObject data = new JSONObject(); |
| | | out.print(JsonUtil.loadTrueJson(data.toString())); |
| | | } |
| | | |
| | | |
| | | public void getCollectVideoList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | String loginUid = request.getParameter("LoginUid"); |
| | | String page = request.getParameter("Page"); |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | out.print(JsonUtil.loadFalseJson("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | long count = collectionVideoV2Service.countByUid(loginUid); |
| | | List<CollectionVideoV2> list = collectionVideoV2Service.listByUid(loginUid, Integer.parseInt(page), Constant.pageCount); |
| | | //获取视频详情 |
| | | List<String> localIds = new ArrayList<>(); |
| | | List<String> internetIds = new ArrayList<>(); |
| | | Map<String, Integer> pmap = new HashMap<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | pmap.put(list.get(i).getVideoId(), i); |
| | | if (NumberUtil.isNumeric(list.get(i).getVideoId())) { |
| | | localIds.add(list.get(i).getVideoId()); |
| | | } else { |
| | | internetIds.add(list.get(i).getVideoId()); |
| | | } |
| | | } |
| | | |
| | | VideoInfo[] videoInfos = new VideoInfo[list.size()]; |
| | | //填充本地视频 |
| | | List<VideoInfo> localVideoInfoList = videoService.getVideoInfoList(localIds); |
| | | if (localVideoInfoList != null) { |
| | | for (VideoInfo video : localVideoInfoList) { |
| | | videoInfos[pmap.get(video.getId())] = video; |
| | | } |
| | | } |
| | | //填充全网搜视频 |
| | | List<InternetSearchVideo> internetSearchVideoList = internetSearchVideoService.listByIds(internetIds); |
| | | for (InternetSearchVideo video : internetSearchVideoList) { |
| | | videoInfos[pmap.get(video.getId())] = VideoInfoFactory.create(video); |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count + ""); |
| | | JSONArray array = new JSONArray(); |
| | | for (int i = 0; i < videoInfos.length; i++) { |
| | | videoInfos[i].setIntroduction(""); |
| | | array.add(StringUtil.outPutResultJson(videoInfos[i])); |
| | | } |
| | | data.put("data", array); |
| | | out.print(JsonUtil.loadTrueJson(data.toString())); |
| | | } |
| | | |
| | | |
| | | } |