admin
2021-04-02 d551bef5e2b09bd98681cf97807988c9863e66fc
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
package com.yeshi.buwan.controller.parser;
 
import com.yeshi.buwan.domain.Attention;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.service.imp.AttentionService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.Utils;
import com.yeshi.buwan.util.VideoPictureUtil;
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
 
@Controller
public class AttentionParser {
 
    @Resource
    private AttentionService attentionService;
 
 
 
 
    public void addAttention(AcceptData acceptData,  HttpServletRequest request, PrintWriter out) {
 
        String videoId = request.getParameter("VideoId");
        String loginUid = request.getParameter("LoginUid");
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传videoId"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(loginUid)) {
            out.print(JsonUtil.loadFalseJson("请上传loginUid"));
            return;
        }
 
        Attention at = new Attention();
        at.setCreatetime(System.currentTimeMillis() + "");
        at.setLoginUser(new LoginUser(loginUid));
        at.setShow(true);
        at.setVideoInfo(new VideoInfo(videoId));
 
        boolean isS = attentionService.addAttention(at);
        if (isS)
            out.print(JsonUtil.loadTrueJson(""));
        else
            out.print(JsonUtil.loadFalseJson(""));
    }
 
    public void cancelAttention(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String videoId = request.getParameter("VideoId");
        String loginUid = request.getParameter("LoginUid");
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传videoId"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(loginUid)) {
            out.print(JsonUtil.loadFalseJson("请上传loginUid"));
            return;
        }
 
        List<Long> videosList = new ArrayList<Long>();
 
        if (videoId.contains(",")) {
            String[] sts = videoId.split(",");
            for (String st : sts)
                if (!StringUtil.isNullOrEmpty(st))
                    videosList.add(Long.parseLong(st.trim()));
        } else
            videosList.add(Long.parseLong(videoId));
        boolean isS = attentionService.deleteAttentions(videosList, Long.parseLong(loginUid));
        if (isS)
            out.print(JsonUtil.loadTrueJson(""));
        else
            out.print(JsonUtil.loadFalseJson(""));
    }
 
    public void getAttentionList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String loginUid = request.getParameter("LoginUid");
        String page = request.getParameter("Page");
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(loginUid)) {
            out.print(JsonUtil.loadFalseJson("请上传loginUid"));
            return;
        }
 
        int pageIndex = 1;
        if (!StringUtil.isNullOrEmpty(page))
            pageIndex = Integer.parseInt(page);
 
        List<Attention> list = attentionService.getAttentionListByLoginUid(Long.parseLong(loginUid), pageIndex);
        JSONObject object = new JSONObject();
        object.put("count", (new StringBuilder(String.valueOf(list.size()))).toString());
        JSONArray array = new JSONArray();
        for (int i = 0; i < list.size(); i++)
            array.add(StringUtil.outPutResultJson(list.get(i)));
        object.put("data", array);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    public void getAttentionUpdateList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String loginUid = request.getParameter("LoginUid");
        String page = request.getParameter("Page");
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(loginUid)) {
            out.print(JsonUtil.loadFalseJson("请上传loginUid"));
            return;
        }
 
        int pageIndex = 1;
        if (!StringUtil.isNullOrEmpty(page))
            pageIndex = Integer.parseInt(page);
 
        List<Attention> list = attentionService.getAttentionVideoListByLoginUid(Long.parseLong(loginUid), pageIndex);
        JSONObject object = new JSONObject();
        object.put("count", (new StringBuilder(String.valueOf(list.size()))).toString());
        JSONArray array = new JSONArray();
        for (int i = 0; i < list.size(); i++) {
            JSONObject ob = new JSONObject();
            ob.put("Id", list.get(i).getId());
//            if (!StringUtil.isNullOrEmpty(list.get(i).getVideoInfo().getHpicture()))
//                list.get(i).getVideoInfo().setPicture(list.get(i).getVideoInfo().getHpicture());
 
            if (list.get(i).getVideoInfo().getVideoDetailList() != null
                    && list.get(i).getVideoInfo().getVideoDetailList().size() > 0)
                list.get(i).getVideoInfo().getVideoDetailList().get(0)
                        .setPicture(VideoPictureUtil.getShowPicture(list.get(i).getVideoInfo(), acceptData.getPlatform(), acceptData.getVersion()+""));
            ob.put("VideoInfo", StringUtil.outPutResultJson(Utils.convertVideo(list.get(i).getVideoInfo())));
            array.add(ob);
        }
        object.put("data", array);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
}