admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
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
package com.newvideo.web.action;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.stereotype.Controller;
 
import com.newvideo.domain.AdminInfo;
import com.newvideo.domain.HomeType;
import com.newvideo.domain.HomeVideo;
import com.newvideo.domain.VideoInfo;
import com.newvideo.domain.VideoType;
import com.newvideo.service.imp.ClassService;
import com.newvideo.service.imp.HomeTypeService;
import com.newvideo.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;
 
@Controller
public class VideoTypeAction extends ActionSupport implements ServletRequestAware {
    @Resource
    private HomeTypeService homeTypeService;
    @Resource
    private ClassService classService;
 
    public HomeTypeService getHomeTypeService() {
        return homeTypeService;
    }
 
    public void setHomeTypeService(HomeTypeService homeTypeService) {
        this.homeTypeService = homeTypeService;
    }
 
    public ClassService getClassService() {
        return classService;
    }
 
    public void setClassService(ClassService classService) {
        this.classService = classService;
    }
 
    HttpServletRequest request;
 
    public String addHomeVideo() {
        String videoIds = request.getParameter("videoIds");
        String homeTypes = request.getParameter("homeTypes");
        List<String> videoList = new ArrayList<String>();
        List<String> homeTypeList = new ArrayList<String>();
        String[] videoIdSts = videoIds.split(",");
        String[] homeTypeSts = homeTypes.split(",");
        for (String vi : videoIdSts) {
            if (!StringUtil.isNullOrEmpty(vi))
                videoList.add(vi);
        }
 
        for (String ht : homeTypeSts) {
            if (!StringUtil.isNullOrEmpty(ht))
                homeTypeList.add(ht);
        }
 
        AdminInfo admin = (AdminInfo) request.getSession().getAttribute("ADMIN_USER");
 
        for (String video : videoList) {
            for (String homeType : homeTypeList) {
                HomeVideo hv = new HomeVideo();
                hv.setAdmin(admin);
                hv.setCreatetime(System.currentTimeMillis() + "");
                hv.setPicture("");
                hv.setTag("");
                hv.setType(new HomeType(homeType));
                hv.setVideo(new VideoInfo(video));
                homeTypeService.addHomeTypeVideo(hv);
            }
        }
 
        return SUCCESS;
    }
 
    /**
     * ��ȡ�����б�
     * 
     * @return
     */
    public String videoTypeList() {
 
        String pid = request.getParameter("pid");
        if (StringUtil.isNullOrEmpty(pid))
            pid = 0 + "";
        List<VideoType> typeList = classService.getNextTypeList(pid);
        request.setAttribute("typeList", typeList);
        request.setAttribute("pid", pid);
        return SUCCESS;
    }
 
    /**
     * ��ȡ��Ƶ��������
     * 
     * @return
     */
    public String getVideoType() {
 
        String id = request.getParameter("id");
        VideoType vt = classService.getType(Long.parseLong(id));
        request.setAttribute("videoType", vt);
        return SUCCESS;
    }
 
    /**
     * �޸���Ƶ����
     * 
     * @return
     */
    public String updateVideoType() {
 
        String id = request.getParameter("id");
 
        VideoType vt = classService.getType(Long.parseLong(id));
        vt.setOrderby(Integer.parseInt(request.getParameter("orderby")));
        if (iconFile != null) {// ����ͼƬ
            try {
                String root = ServletActionContext.getServletContext().getRealPath("/upload/class");
                if (!new File(root).exists())
                    new File(root).mkdirs();
                InputStream is = new FileInputStream(iconFile);
                OutputStream os = new FileOutputStream(new File(root, System.currentTimeMillis() + ".jpg"));
                System.out.println("file: " + iconFile.getPath());
 
                byte[] buffer = new byte[500];
                int length = 0;
                while (-1 != (length = is.read(buffer, 0, buffer.length))) {
                    os.write(buffer);
                }
                os.close();
                is.close();
                root = root.replace("\\", "/");
                vt.setIcon("/upload/" + root.split("/upload/")[1]);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (!StringUtil.isNullOrEmpty(iconUrl))
                vt.setIcon(iconUrl);
        }
        vt.setName(name);
        vt.setBeizhu(beizhu);
        classService.updateType(vt);
        request.setAttribute("videoType", vt);
        return SUCCESS;
    }
 
    /**
     * �����Ƶ����
     */
 
    public String addVideoType() {
 
        VideoType vt = new VideoType();
        if (iconFile != null) {// ����ͼƬ
            try {
                String root = ServletActionContext.getServletContext().getRealPath("/upload/class");
                if (!new File(root).exists())
                    new File(root).mkdirs();
                InputStream is = new FileInputStream(iconFile);
                OutputStream os = new FileOutputStream(new File(root, System.currentTimeMillis() + ".jpg"));
                System.out.println("file: " + iconFile.getPath());
 
                byte[] buffer = new byte[500];
                int length = 0;
                while (-1 != (length = is.read(buffer, 0, buffer.length))) {
                    os.write(buffer);
                }
                os.close();
                is.close();
                root = root.replace("\\", "/");
                vt.setIcon("/upload/" + root.split("/upload/")[1]);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            vt.setIcon(iconUrl);
        }
        vt.setName(name);
        vt.setBeizhu(beizhu);
        if (!StringUtil.isNullOrEmpty(pid) && !pid.equalsIgnoreCase("0")) {
            vt.setParent(new VideoType(Long.parseLong(pid)));
        }
        classService.createType(vt);
        request.setAttribute("pid", pid);
        return SUCCESS;
    }
 
    /**
     * ɾ����Ƶ����
     * 
     * @return
     */
    public String deleteVideoType() {
 
        String id = request.getParameter("id");
        classService.deleteVideoType(id);
        return SUCCESS;
    }
 
    public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }
 
    private File iconFile;
    private String iconFileFileName;
    private String iconFileContentType;
    private String name;
    private String beizhu;
    private String iconUrl;
    private String pid;
 
    public String getPid() {
        return pid;
    }
 
    public void setPid(String pid) {
        this.pid = pid;
    }
 
    public String getIconUrl() {
        return iconUrl;
    }
 
    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }
 
    public File getIconFile() {
        return iconFile;
    }
 
    public void setIconFile(File iconFile) {
        this.iconFile = iconFile;
    }
 
    public String getIconFileFileName() {
        return iconFileFileName;
    }
 
    public void setIconFileFileName(String iconFileFileName) {
        this.iconFileFileName = iconFileFileName;
    }
 
    public String getIconFileContentType() {
        return iconFileContentType;
    }
 
    public void setIconFileContentType(String iconFileContentType) {
        this.iconFileContentType = iconFileContentType;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getBeizhu() {
        return beizhu;
    }
 
    public void setBeizhu(String beizhu) {
        this.beizhu = beizhu;
    }
 
}