admin
2021-01-23 0a18a8cb0a7a57bf1f82df425251334c57f8c39a
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
package com.yeshi.buwan.web.action;
 
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.stereotype.Controller;
 
import com.opensymphony.xwork2.ActionSupport;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.VideoUrl;
import com.yeshi.buwan.service.imp.VideoManager;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.service.imp.VideoService;
import com.yeshi.buwan.util.StringUtil;
 
@Controller
public class VideoDetailAction extends ActionSupport implements ServletRequestAware {
    @Resource
    private VideoManager videoManager;
    @Resource
    private VideoService videoService;
    @Resource
    private VideoResourceService videoResourceService;
 
    public VideoResourceService getVideoResourceService() {
        return videoResourceService;
    }
 
    public void setVideoResourceService(VideoResourceService videoResourceService) {
        this.videoResourceService = videoResourceService;
    }
 
    public VideoManager getVideoManager() {
        return videoManager;
    }
 
    public void setVideoManager(VideoManager videoManager) {
        this.videoManager = videoManager;
    }
 
    public VideoService getVideoService() {
        return videoService;
    }
 
    public void setVideoService(VideoService videoService) {
        this.videoService = videoService;
    }
 
    HttpServletRequest request;
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    /**
     * 获取详情列表
     * 
     * @return
     */
    public String getVideoDetailList() {
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            videoId = (String) request.getAttribute("videoId");
        }
 
        List<VideoDetailInfo> detailList = videoManager.getVideoDetail(videoId);
        request.setAttribute("videoDetailList", detailList);
 
        List<VideoResource> list = videoResourceService.getResourceList();
        request.setAttribute("resourceList", list);
        request.setAttribute("videoId", videoId);
        return SUCCESS;
    }
 
    /**
     * 修改详情
     * 
     * @return
     */
    public String updateVideoDetail() {
 
        if (Long.parseLong(id) > 0) {
            VideoDetailInfo detail = videoManager.getVideoDetailById(Long.parseLong(id));
            detail.setIntroduction(introduction);
            try {
                if (!StringUtil.isNullOrEmpty(introduction))
                    detail.setIntroduction(new String(introduction.getBytes("iso-8859-1"), "UTF-8"));
                detail.setName(new String(name.getBytes("iso-8859-1"), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            detail.setTag(tag);
            invalids = request.getParameterValues("invalids");
            List<VideoUrl> urlList = new ArrayList<VideoUrl>();
            if (urls != null)
                for (int i = 0; i < urls.length; i++) {
                    VideoUrl vu = new VideoUrl();
                    vu.setVideoDetail(new VideoDetailInfo(detail.getId()));
                    vu.setUrl(urls[i]);
                    if (StringUtil.isNullOrEmpty(invalids[i]))
                        vu.setInvalid("1");// 链接无效
                    else
                        vu.setInvalid("0");// 链接有效
                    vu.setResource(new VideoResource(resources[i]));
                    vu.setVideoDetail(detail);
                    urlList.add(vu);
                }
            detail.setUrls(urlList);
            request.setAttribute("videoId", detail.getVideo().getId());
            videoManager.updateVideoDetail(detail);
        } else {
            VideoDetailInfo detail = new VideoDetailInfo();
            detail.setIntroduction(introduction);
            try {
                if (!StringUtil.isNullOrEmpty(introduction))
                    detail.setIntroduction(new String(introduction.getBytes("iso-8859-1"), "UTF-8"));
                detail.setName(new String(name.getBytes("iso-8859-1"), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            detail.setTag(tag);
            detail.setVideo(new VideoInfo(videoId));
            List<VideoUrl> urlList = new ArrayList<VideoUrl>();
            if (urls != null)
                for (int i = 0; i < urls.length; i++) {
                    VideoUrl vu = new VideoUrl();
                    vu.setUrl(urls[i]);
                    if (StringUtil.isNullOrEmpty(invalids[i]))
                        vu.setInvalid("1");// 链接无效
                    else
                        vu.setInvalid("0");// 链接有效
                    vu.setResource(new VideoResource(resources[i]));
                    urlList.add(vu);
                }
            detail.setUrls(urlList);
            request.setAttribute("videoId", videoId);
            videoManager.addVideoDetail(detail);
        }
        return SUCCESS;
    }
 
    /**
     * 添加详情
     * 
     * @return
     */
    public String addVideoDetail() {
 
        VideoDetailInfo detail = new VideoDetailInfo();
        detail.setIntroduction(introduction);
        detail.setName(name);
        detail.setTag(tag);
        detail.setVideo(new VideoInfo(videoId));
        List<VideoUrl> urlList = new ArrayList<VideoUrl>();
        for (int i = 0; i < urls.length; i++) {
            VideoUrl vu = new VideoUrl();
            vu.setUrl(urls[i]);
            if (StringUtil.isNullOrEmpty(invalids[i]))
                vu.setInvalid("1");// 链接无效
            else
                vu.setInvalid("0");// 链接有效
            vu.setResource(new VideoResource(resources[i]));
            urlList.add(vu);
        }
        detail.setUrls(urlList);
        videoManager.addVideoDetail(detail);
        return SUCCESS;
    }
 
    /**
     * 删除详情
     * 
     * @return
     */
    public String deleteVideoDetail() {
 
        videoManager.deleteVideoDetail(new VideoDetailInfo(Long.parseLong(id)));
        return SUCCESS;
    }
 
    public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }
 
    private String videoId;
    private String id;
    private String tag;
    private String name;
    private String introduction;
    private String beizhu;
 
    public String getVideoId() {
        return videoId;
    }
 
    public void setVideoId(String videoId) {
        this.videoId = videoId;
    }
 
    public String getId() {
        return id;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    public String getTag() {
        return tag;
    }
 
    public void setTag(String tag) {
        this.tag = tag;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getIntroduction() {
        return introduction;
    }
 
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }
 
    public String getBeizhu() {
        return beizhu;
    }
 
    public void setBeizhu(String beizhu) {
        this.beizhu = beizhu;
    }
 
    private String[] resources;
    private String[] urls;
    private String[] invalids;
 
    public String[] getInvalids() {
        return invalids;
    }
 
    public void setInvalids(String[] invalids) {
        this.invalids = invalids;
    }
 
    public String[] getResources() {
        return resources;
    }
 
    public void setResources(String[] resources) {
        this.resources = resources;
    }
 
    public String[] getUrls() {
        return urls;
    }
 
    public void setUrls(String[] urls) {
        this.urls = urls;
    }
 
}