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;
|
}
|
|
}
|