package com.yeshi.buwan.controller.admin.api;
|
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpSession;
|
|
|
import com.yeshi.buwan.service.inter.recommend.HomeVideoService;
|
import com.yeshi.buwan.util.*;
|
import com.yeshi.buwan.util.video.VideoUtil;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.buwan.domain.CategoryContry;
|
import com.yeshi.buwan.domain.system.DetailSystem;
|
import com.yeshi.buwan.domain.HomeType;
|
import com.yeshi.buwan.domain.HomeVideo;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoType;
|
import com.yeshi.buwan.domain.recommend.CategoryRecommendVideo;
|
import com.yeshi.buwan.domain.recommend.SuperCategoryRecommendVideo;
|
import com.yeshi.buwan.domain.web.CategoryRecommendVideoAdmin;
|
import com.yeshi.buwan.service.imp.CategoryAreaService;
|
import com.yeshi.buwan.service.imp.ClassService;
|
import com.yeshi.buwan.service.imp.HomeTypeService;
|
import com.yeshi.buwan.service.imp.SystemService;
|
import com.yeshi.buwan.service.imp.recommend.CategoryRecommendVideoService;
|
import com.yeshi.buwan.web.tag.PageEntity;
|
|
@Controller
|
@RequestMapping("admin/new/api/class")
|
public class ClassController {
|
|
@Resource
|
private ClassService classService;
|
|
@Resource
|
private HomeTypeService homeTypeService;
|
|
@Resource
|
private HomeVideoService homeVideoService;
|
|
@Resource
|
private CategoryRecommendVideoService categoryRecommendVideoService;
|
|
@Resource
|
private SystemService systemService;
|
|
@Resource
|
private CategoryAreaService categoryAreaService;
|
|
@RequestMapping(value = "/getnextclass", method = RequestMethod.POST)
|
public void getNextClass(int pid, PrintWriter out) {
|
System.out.println("pid--" + pid);
|
List<VideoType> list;
|
if (pid <= 0)
|
list = classService.getNextTypeList("");
|
else
|
list = classService.getNextTypeList(pid + "");
|
|
JSONArray array = new JSONArray();
|
if (list != null)
|
for (VideoType type : list) {
|
JSONObject obj = new JSONObject();
|
obj.put("id", type.getId());
|
obj.put("name", type.getName());
|
array.add(obj);
|
}
|
JSONObject object = new JSONObject();
|
object.put("code", 0);
|
object.put("data", array);
|
out.print(object);
|
}
|
|
@RequestMapping("getAllFirstClass")
|
public void getAllFirstClass(PrintWriter out) {
|
List<VideoType> list = classService.getAllVideoType();
|
JSONArray array = new JSONArray();
|
if (list != null)
|
for (VideoType type : list) {
|
JSONObject obj = new JSONObject();
|
obj.put("id", type.getId());
|
obj.put("name", type.getName());
|
array.add(obj);
|
}
|
JSONObject object = new JSONObject();
|
object.put("code", 0);
|
object.put("data", array);
|
out.print(object);
|
}
|
|
@RequestMapping(value = "/gethometypelist", method = RequestMethod.POST)
|
public void getHomeTypeList(int pid, HttpSession session, PrintWriter out) {
|
List<HomeType> list = homeTypeService.getHomeTypeList(SystemUtil.getAdminSelectedSystemId(session));
|
|
JSONArray array = new JSONArray();
|
if (list != null)
|
for (HomeType type : list) {
|
JSONObject obj = new JSONObject();
|
obj.put("id", type.getId());
|
obj.put("name", type.getName());
|
array.add(obj);
|
}
|
JSONObject object = new JSONObject();
|
object.put("code", 0);
|
object.put("data", array);
|
out.print(object);
|
}
|
|
@RequestMapping(value = "/addhomevideos", method = RequestMethod.POST)
|
public void addHomeVideos(int hometypeid, String videos, String pictures,
|
String tags, PrintWriter out) {
|
String[] videoStr = videos.split(",");
|
String[] pictureStr = pictures.split(",");
|
String[] tagStr = tags.split(",");
|
|
List<HomeVideo> list = new ArrayList<HomeVideo>();
|
for (int i = 0; i < videoStr.length; i++) {
|
HomeVideo hv = new HomeVideo();
|
hv.setCreatetime(System.currentTimeMillis() + "");
|
hv.setTag(tagStr[i]);
|
hv.setPicture(pictureStr[i]);
|
hv.setType(new HomeType(hometypeid + ""));
|
hv.setVideoId(videoStr[i]);
|
hv.setFromType(VideoUtil.getVideoFromType(hv.getVideoId()));
|
hv.setBigPicture(false);
|
}
|
|
homeVideoService.addHomeVideo(list);
|
JSONObject object = new JSONObject();
|
object.put("code", 0);
|
object.put("msg", "添加成功");
|
out.print(object);
|
}
|
|
/**
|
* 搜索
|
*
|
* @param key
|
* @param detailsystem
|
* @param videotype
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "/getseachList", method = RequestMethod.POST)
|
public void categoryRecommendVideoList(String key, String detailsystem,
|
String videotype, String page, HttpSession session, PrintWriter out) {
|
|
if (detailsystem == null || "".equals(detailsystem.trim())) {
|
detailsystem = "0";
|
}
|
|
if (page == null || "".equals(page.trim())) {
|
page = "1";
|
}
|
|
int pageIndex = Integer.parseInt(page);
|
if (pageIndex == 0)
|
pageIndex = 1;
|
|
videotype = StringUtil.isNullOrEmpty(videotype) ? "150" : videotype;
|
|
List<CategoryRecommendVideoAdmin> list = categoryRecommendVideoService
|
.getCategoryRecommendVideoAdmin(key,
|
Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem), pageIndex);
|
long count = categoryRecommendVideoService
|
.getCategoryRecommendVideoAdminCount(key,
|
Integer.parseInt(videotype), SystemUtil.getAdminSelectedSystemId(session), Integer.parseInt(detailsystem));
|
PageEntity pe = new PageEntity();
|
pe.setPageIndex(pageIndex);
|
pe.setPageSize(Constant.pageCount);
|
Map<String, String> map = new HashMap<String, String>();
|
map.put("key", key);
|
map.put("detailsystem", detailsystem + "");
|
map.put("videotype", videotype + "");
|
pe.setParams(map);
|
pe.setTotalCount((int) count);
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
|
.create();
|
JSONObject root = new JSONObject();
|
root.put("code", "0");
|
root.put("pageEntity", pe);
|
String json = gson.toJson(list);
|
root.put("crv", json);
|
System.out.println(root.toString());
|
out.print(root);
|
}
|
|
@RequestMapping(value = "/deleteCategoryRecommendVideo", method = RequestMethod.POST)
|
public void deleteCategoryRecommendVideo(String ids, PrintWriter out) {
|
|
if (ids == null || ids.trim().length() == 0) {
|
return;
|
}
|
String[] idArr = ids.split(",");
|
for (String id : idArr) {
|
System.out.println(id);
|
categoryRecommendVideoService.deleteCategoryRecommendVideo(new CategoryRecommendVideo(id));
|
}
|
out.print("yes");
|
}
|
|
@RequestMapping(value = "/getCategoryRecommendVideo", method = RequestMethod.POST)
|
public void getCategoryRecommendVideo(String id, PrintWriter out) {
|
|
// id = StringUtil.isNullOrEmpty(id) ? request.getAttribute("id").toString() : id;
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
|
.create();
|
JSONObject root = new JSONObject();
|
CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id);
|
if (categoryRecommendVideo != null) {
|
String json = gson.toJson(categoryRecommendVideo);
|
root.put("code", "0");
|
root.put("crv", json);
|
} else {
|
root.put("code", "1");
|
root.put("crv", null);
|
}
|
out.print(root);
|
|
//request.setAttribute("videoTypeList", classService.getFirstTypeList(""));
|
// request.setAttribute("systemList", systemService.getSystemList());
|
// request.setAttribute("categoryRecommendVideo", categoryRecommendVideo);
|
return;
|
}
|
|
@RequestMapping(value = "/setCategoryRecommendVideo", method = RequestMethod.POST)
|
public void updateCategoryRecommendVideo(String id, String beizhu, String desc, int orderby, String picture, String videoid, String videotype, HttpSession session, PrintWriter out) {
|
|
//id为空则新加
|
if (id == null || "".equals(id.trim())) {
|
CategoryRecommendVideo newCategoryRecommendVideo = new CategoryRecommendVideo();
|
newCategoryRecommendVideo.setBeizhu(beizhu);
|
newCategoryRecommendVideo.setCreatetime(System.currentTimeMillis() + "");
|
newCategoryRecommendVideo.setDesc(desc);
|
newCategoryRecommendVideo.setOrderby(orderby);
|
newCategoryRecommendVideo.setPicture(picture);
|
newCategoryRecommendVideo.setVideoInfo(new VideoInfo(videoid));
|
newCategoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype)));
|
newCategoryRecommendVideo.setSystem(SystemUtil.getAdminSelectedSystem(session));
|
|
categoryRecommendVideoService.addCategoryRecommendVideo(newCategoryRecommendVideo);
|
|
SuperCategoryRecommendVideo sz = null;
|
List<DetailSystem> list = systemService.getDetailSystemList(SystemUtil.getAdminSelectedSystem(session).getId());
|
for (DetailSystem ds : list) {
|
sz = new SuperCategoryRecommendVideo();
|
sz.setDetailSystem(new DetailSystem(ds.getId()));
|
sz.setCategoryRecommendVideo(newCategoryRecommendVideo);
|
categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz);
|
}
|
|
out.print("yes");
|
return;
|
}
|
CategoryRecommendVideo categoryRecommendVideo = categoryRecommendVideoService.getCategoryRecommendVideoById(id);
|
categoryRecommendVideo.setBeizhu(beizhu);
|
categoryRecommendVideo.setCreatetime(System.currentTimeMillis() + "");
|
categoryRecommendVideo.setDesc(desc);
|
// categoryRecommendVideo.setJpos(jpos);
|
categoryRecommendVideo.setOrderby(orderby);
|
categoryRecommendVideo.setPicture(picture);
|
categoryRecommendVideo.setVideoInfo(new VideoInfo(videoid));
|
categoryRecommendVideo.setVideoType(new VideoType(Long.parseLong(videotype)));
|
categoryRecommendVideoService.updateCategoryRecommendVideo(categoryRecommendVideo);
|
out.print("yes");
|
return;
|
}
|
|
|
@RequestMapping(value = "/CategoryRecommendVideoAdminServlet", method = RequestMethod.POST)
|
public void set(String type, String id, String systemid, PrintWriter out) {
|
|
System.out.println("type--" + type);
|
System.out.println("id--" + id);
|
System.out.println("systemid--" + systemid);
|
|
if ("add".equalsIgnoreCase(type)) {// 获取来源列表
|
if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) {
|
SuperCategoryRecommendVideo sz = new SuperCategoryRecommendVideo();
|
sz.setDetailSystem(new DetailSystem(systemid));
|
sz.setCategoryRecommendVideo(new CategoryRecommendVideo(id));
|
categoryRecommendVideoService.addSuperCategoryRecommendVideo(sz);
|
}
|
out.print("yes");
|
} else if ("delete".equalsIgnoreCase(type)) {
|
if (!StringUtil.isNullOrEmpty(systemid) && !StringUtil.isNullOrEmpty(id)) {
|
categoryRecommendVideoService.deleteCategoryRecommendVideoAdmin(id, systemid);
|
}
|
out.print("yes");
|
}
|
}
|
|
@RequestMapping("getAreaList")
|
public void getAreaList(long cid, PrintWriter out) {
|
List<CategoryContry> list = categoryAreaService.getCategoryContryListByCid(cid + "");
|
if (list.size() == 0) {
|
out.print(JsonUtil.loadFalseAdmin("加载错误"));
|
return;
|
}
|
List<CategoryContry> categoryContryList = categoryAreaService.categoryContryList(list.get(0).getId() + "");
|
PageEntity pe = new PageEntity();
|
pe.setPageIndex(1);
|
pe.setPageSize(categoryContryList.size());
|
pe.setTotalCount(categoryContryList.size());
|
JSONObject data = new JSONObject();
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
data.put("pe", pe);
|
data.put("list", gson.toJson(categoryContryList));
|
String json = JsonUtil.loadTrueAdmin(data);
|
out.print(json);
|
}
|
|
@RequestMapping("getArea")
|
public void getArea(long id, PrintWriter out) {
|
CategoryContry area = categoryAreaService.getCategoryArea(id + "");
|
if (area == null) {
|
out.print(JsonUtil.loadFalseAdmin(""));
|
return;
|
}
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
out.print(JsonUtil.loadTrueAdmin(gson.toJson(area)));
|
}
|
|
@RequestMapping("updateArea")
|
public void updateArea(long id, int orderBy, PrintWriter out) {
|
CategoryContry area = categoryAreaService.getCategoryArea(id + "");
|
if (area == null) {
|
out.print(JsonUtil.loadFalseAdmin(""));
|
return;
|
}
|
area.setOrderby(orderBy);
|
categoryAreaService.updateArea(area);
|
out.print(JsonUtil.loadTrueAdmin(""));
|
}
|
|
|
}
|