admin
2021-07-30 a66b556036c2b3936a51fd7b7e54a204eb31dc14
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
package com.yeshi.buwan.controller.parser;
 
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.video.VideoWatchHistory;
import com.yeshi.buwan.service.imp.VideoService;
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.StringUtil;
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;
 
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;
 
@Component
public class UserVideoParser {
 
    @Resource
    private VideoWatchHistoryService videoWatchHistoryService;
 
    @Resource
    private VideoService videoService;
 
    public void getWatchHistory(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        int page = Integer.parseInt(request.getParameter("Page"));
        page = page == 0 ? 1 : page;
        List<VideoWatchHistory> list = videoWatchHistoryService.listHistory(acceptData.getDevice(), page, Constant.pageCount);
        long count = videoWatchHistoryService.countHistory(acceptData.getDevice());
 
        List<String> videoIds = new ArrayList<>();
        if (list != null)
            for (VideoWatchHistory wh : list) {
                videoIds.add(wh.getVideoId());
            }
 
        List<VideoInfo> videoInfoList = videoService.getVideoInfoList(videoIds);
        Map<String, VideoInfo> videoInfoMap = new HashMap<>();
        if (videoInfoList != null)
            for (VideoInfo vi : videoInfoList) {
                if (vi != null)
                    videoInfoMap.put(vi.getId(), vi);
            }
        for (VideoWatchHistory wh : list) {
            wh.setVideo(videoInfoMap.get(wh.getVideoId()));
        }
 
 
        JSONObject root = new JSONObject();
        root.put("count", count);
        root.put("list", StringUtil.outPutResultJson(list));
        out.print(JsonUtil.loadTrueJson(root.toString()));
    }
 
    public void deleteWatchHistory(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String ids = (request.getParameter("Ids"));
        List<String> idList = new ArrayList<>();
        JSONArray array = JSONArray.fromObject(ids);
        if (array != null)
            for (int i = 0; i < array.size(); i++) {
                idList.add(array.optString(i));
            }
        videoWatchHistoryService.delete(idList);
 
        out.print(JsonUtil.loadTrueJson(""));
    }
 
}