package com.newvideo.controller.admin.api; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.google.gson.GsonBuilder; import com.newvideo.domain.ResourceVideo; import com.newvideo.domain.VideoInfo; import com.newvideo.iqiyi.util.IqiyiUtil; import com.newvideo.service.imp.ClassService; import com.newvideo.service.imp.ResourceVideoService; import com.newvideo.service.imp.VideoManager; import com.newvideo.util.JsonUtil; import com.newvideo.util.SolrUtil; import com.newvideo.util.StringUtil; import com.newvideo.util.TimeUtil; import com.newvideo.web.tag.PageEntity; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @Controller @RequestMapping("admin/new/api/video") public class VideoAdminController { @Resource private VideoManager videoManager; @Resource private ClassService classService; @Resource private ResourceVideoService resourceVideoService; @Resource private IqiyiUtil iqiyiUtil; @RequestMapping(value = "/changevideoshow", method = RequestMethod.POST) public void changeVideoShow(String id, int show, PrintWriter out) { VideoInfo vi = videoManager.getVideoInfo(id); if (vi != null) { vi.setShow(show + ""); videoManager.changeVideoShow(vi); } JSONObject object = new JSONObject(); object.put("code", 0); object.put("msg", "修改成功"); out.print(object); } @RequestMapping(value = "/deletevideo", method = RequestMethod.POST) public void deleteVideo(String id, PrintWriter out) { String[] ids = id.split(","); for (String idStr : ids) videoManager.deleteVideo(idStr); JSONObject object = new JSONObject(); object.put("code", 0); object.put("msg", "删除成功"); out.print(object); } @RequestMapping(value = "/videolist", method = RequestMethod.POST) public void videoList(int videotype, int page, String key, int contenttype, PrintWriter out) { List list = classService.getTypeVideoListAdmin(videotype == 0 ? "" : videotype + "", page, key, contenttype); long count = classService.getTypeVideoListAdminCount(videotype == 0 ? "" : videotype + "", key, contenttype); JSONObject object = new JSONObject(); object.put("code", 0); JSONObject data = new JSONObject(); JSONArray array = new JSONArray(); for (VideoInfo vi : list) { JSONObject item = new JSONObject(); item.put("id", vi.getId()); item.put("name", vi.getName()); item.put("picture", vi.getHpicture()); item.put("updatetime", TimeUtil.getGernalTime( Long.parseLong( StringUtil.isNullOrEmpty(vi.getCreatetime() + "") ? "0" : vi.getCreatetime() + ""), "yyyy-MM-dd")); item.put("show", vi.getShow()); array.add(item); } PageEntity entity = new PageEntity(); entity.setPageIndex(page); entity.setPageSize(20); entity.setTotalCount((int) count); data.put("pageEntity", new GsonBuilder().create().toJson(entity)); data.put("data", array); object.put("data", data); out.println(object); } @RequestMapping("updateVideos") public void updateVideos(PrintWriter out) { iqiyiUtil.updateAll(""); out.print(JsonUtil.loadTrueJson("执行成功")); } @RequestMapping("updateIqiyiAlbum") public void updateIqiyiAlbum(String url, PrintWriter out) { String aid = IqiyiUtil.getAlbumIdFromPlayUrl(url); if (StringUtil.isNullOrEmpty(aid)) { JSONObject data = new JSONObject(); data.put("code", 1); data.put("msg", "未能获取到专辑"); out.print(data); } else { iqiyiUtil.updateAlbum(aid); JSONObject data = new JSONObject(); data.put("code", 0); data.put("data", "专辑更新成功"); out.print(data); } } }