package com.yeshi.buwan.controller.admin.api; import java.io.PrintWriter; import java.util.List; import javax.annotation.Resource; import com.yeshi.buwan.iqiyi.IqiYiNewAPI; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 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.yeshi.buwan.acFun.AcFunUtil; import com.yeshi.buwan.domain.VideoInfo; import com.yeshi.buwan.iqiyi.util.IqiyiUtil; import com.yeshi.buwan.service.imp.ClassService; import com.yeshi.buwan.service.imp.ResourceVideoService; import com.yeshi.buwan.service.imp.VideoManager; import com.yeshi.buwan.util.JsonUtil; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.util.TimeUtil; import com.yeshi.buwan.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; @Resource private AcFunUtil acFunUtil; @Resource private ThreadPoolTaskExecutor taskExecutor; @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.loadTrueAdmin("执行成功")); } @RequestMapping("updateIqiyiAlbum") public void updateIqiyiAlbum(String url, PrintWriter out) { String aid = IqiYiNewAPI.getAidByUrl(url); if (StringUtil.isNullOrEmpty(aid)) { out.print(JsonUtil.loadFalseAdmin("未能获取到专辑")); } else { iqiyiUtil.updateAlbum(aid); out.print(JsonUtil.loadTrueAdmin("专辑更新成功")); } } @RequestMapping("addIqiyiShortVideo") public void addIqiyiShortVideo(String urlJson, PrintWriter out) { // JSONArray array = JSONArray.fromObject(urlJson); // int count = 0; // for (int i = 0; i < array.size(); i++) { // String aid = IqiyiUtil.getAlbumIdFromPlayUrl(array.optString(i)); // if (!StringUtil.isNullOrEmpty(aid)) // count++; // // // 添加小视频 // // } // // String aid = IqiyiUtil.getAlbumIdFromPlayUrl(""); // if (StringUtil.isNullOrEmpty(aid)) { // out.print(JsonUtil.loadFalseAdmin("未能获取到专辑")); // } else { // iqiyiUtil.updateAlbum(aid); // out.print(JsonUtil.loadTrueAdmin("专辑更新成功")); // } } @RequestMapping("iqiyiUpdate") public void iqiyiUpdate(PrintWriter out) { taskExecutor.execute(new Runnable() { @Override public void run() { iqiyiUtil.updateAll(""); } }); JSONObject data = new JSONObject(); data.put("msg", "正在后台更新中"); out.print(data); } }