| | |
| | | package com.yeshi.buwan.controller.admin.api; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.google.common.base.Function; |
| | | import com.google.common.collect.Maps; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.domain.solr.SolrAlbumVideo; |
| | | import com.yeshi.buwan.domain.video.VideoInfoExtra; |
| | | import com.yeshi.buwan.dto.search.SolrResultDTO; |
| | | import com.yeshi.buwan.dto.search.SolrVideoSearchFilter; |
| | | import com.yeshi.buwan.iqiyi.IqiYiNewAPI; |
| | | import com.yeshi.buwan.service.imp.VideoResourceService; |
| | | import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; |
| | | import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import com.yeshi.buwan.vo.video.VideoAdminInfoVO; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | 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; |
| | |
| | | @RequestMapping("admin/new/api/video") |
| | | public class VideoAdminController { |
| | | |
| | | @Resource |
| | | private VideoManager videoManager; |
| | | @Resource |
| | | private VideoManager videoManager; |
| | | |
| | | @Resource |
| | | private ClassService classService; |
| | | @Resource |
| | | private ClassService classService; |
| | | |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | |
| | | @Resource |
| | | private IqiyiUtil iqiyiUtil; |
| | | @Resource |
| | | private VideoResourceService videoResourceService; |
| | | |
| | | @Resource |
| | | private AcFunUtil acFunUtil; |
| | | @Resource |
| | | private IqiyiUtil iqiyiUtil; |
| | | |
| | | @Resource |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | @Resource |
| | | private AcFunUtil acFunUtil; |
| | | |
| | | @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); |
| | | } |
| | | @Resource |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | @RequestMapping(value = "/deletevideo", method = RequestMethod.POST) |
| | | public void deleteVideo(String id, PrintWriter out) { |
| | | String[] ids = id.split(","); |
| | | for (String idStr : ids) |
| | | videoManager.deleteVideo(idStr); |
| | | @Resource |
| | | private SolrAlbumVideoDataManager solrAlbumDataManager; |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | object.put("code", 0); |
| | | object.put("msg", "删除成功"); |
| | | out.print(object); |
| | | } |
| | | @Resource |
| | | private VideoInfoExtraService videoInfoExtraService; |
| | | |
| | | @RequestMapping(value = "/videolist", method = RequestMethod.POST) |
| | | public void videoList(int videotype, int page, String key, int contenttype, PrintWriter out) { |
| | | List<VideoInfo> 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); |
| | | @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); |
| | | } |
| | | |
| | | data.put("pageEntity", new GsonBuilder().create().toJson(entity)); |
| | | data.put("data", array); |
| | | object.put("data", data); |
| | | out.println(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); |
| | | |
| | | @RequestMapping("updateVideos") |
| | | public void updateVideos(PrintWriter out) { |
| | | iqiyiUtil.updateAll(""); |
| | | out.print(JsonUtil.loadTrueAdmin("执行成功")); |
| | | } |
| | | JSONObject object = new JSONObject(); |
| | | object.put("code", 0); |
| | | object.put("msg", "删除成功"); |
| | | out.print(object); |
| | | } |
| | | |
| | | @RequestMapping("updateIqiyiAlbum") |
| | | public void updateIqiyiAlbum(String url, PrintWriter out) { |
| | | String aid = IqiyiUtil.getAlbumIdFromPlayUrl(url); |
| | | if (StringUtil.isNullOrEmpty(aid)) { |
| | | out.print(JsonUtil.loadFalseAdmin("未能获取到专辑")); |
| | | } else { |
| | | iqiyiUtil.updateAlbum(aid); |
| | | out.print(JsonUtil.loadTrueAdmin("专辑更新成功")); |
| | | } |
| | | } |
| | | @RequestMapping(value = "/videolist", method = RequestMethod.POST) |
| | | public void videoList(int videotype, int page, String key, String type, String resourceIds, int contenttype, String freeType, String area, PrintWriter out) { |
| | | |
| | | @RequestMapping("addIqiyiShortVideo") |
| | | public void addIqiyiShortVideo(String urlJson, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(type)) { |
| | | type = "name"; |
| | | } |
| | | |
| | | Integer freeTypeInt = null; |
| | | if (!StringUtil.isNullOrEmpty(freeType)) { |
| | | freeTypeInt = Integer.parseInt(freeType); |
| | | } |
| | | |
| | | |
| | | List<VideoInfo> list = null; |
| | | long count = 0; |
| | | List<VideoAdminInfoVO> voList = new ArrayList<>(); |
| | | //正片搜索 |
| | | if (contenttype == 1) { |
| | | SolrVideoSearchFilter filter = new SolrVideoSearchFilter(); |
| | | |
| | | switch (type) { |
| | | case "name": |
| | | filter.setKey(key); |
| | | break; |
| | | case "actor": |
| | | filter.setActor(key); |
| | | break; |
| | | case "director": |
| | | filter.setDirector(key); |
| | | break; |
| | | } |
| | | |
| | | |
| | | filter.setVideoType(videotype == 0 ? null : videotype); |
| | | filter.setContentType(1); |
| | | if (!StringUtil.isNullOrEmpty(resourceIds)) { |
| | | JSONArray array = JSONArray.fromObject(resourceIds); |
| | | String[] rids = new String[array.size()]; |
| | | for (int i = 0; i < array.size(); i++) { |
| | | rids[i] = array.optString(i); |
| | | } |
| | | filter.setResourceIds(Arrays.asList(rids)); |
| | | } |
| | | |
| | | filter.setSortKey("updateTime"); |
| | | |
| | | filter.setFreeType(freeTypeInt); |
| | | |
| | | filter.setArea(StringUtil.isNullOrEmpty(area) ? null : area.trim()); |
| | | |
| | | List<VideoResource> resourceList = videoResourceService.getResourceList(); |
| | | Map<Long, String> resourceMap = new HashMap<>(); |
| | | for (VideoResource vr : resourceList) { |
| | | resourceMap.put(Long.parseLong(vr.getId()), vr.getName()); |
| | | } |
| | | |
| | | SolrResultDTO dto = solrAlbumDataManager.find(filter, page, Constant.pageCount); |
| | | if (dto.getVideoList() != null) |
| | | for (SolrAlbumVideo videoInfo : (List<SolrAlbumVideo>) dto.getVideoList()) |
| | | voList.add(VideoAdminInfoVO.create(videoInfo,resourceMap)); |
| | | count = dto.getTotalCount(); |
| | | } else { |
| | | list = classService.getTypeVideoListAdmin(videotype == 0 ? "" : videotype + "", page, key, |
| | | contenttype); |
| | | count = classService.getTypeVideoListAdminCount(videotype == 0 ? "" : videotype + "", key, contenttype); |
| | | if (list != null) |
| | | for (VideoInfo videoInfo : list) |
| | | voList.add(VideoAdminInfoVO.create(videoInfo)); |
| | | } |
| | | |
| | | List<String> ids = new ArrayList<>(); |
| | | for (VideoAdminInfoVO a : voList) { |
| | | ids.add(a.getId()); |
| | | } |
| | | |
| | | List<VideoInfoExtra> extraList = videoInfoExtraService.listByIds(ids); |
| | | |
| | | Map<String, VideoInfoExtra> maps = Maps.uniqueIndex(extraList.iterator(), new Function<VideoInfoExtra, String>() { |
| | | @Override |
| | | public String apply(VideoInfoExtra extra) { |
| | | return extra.getId(); |
| | | } |
| | | }); |
| | | //过滤图片 |
| | | for (VideoAdminInfoVO a : voList) { |
| | | VideoInfoExtra extra = maps.get(a.getId()); |
| | | if (extra != null) { |
| | | |
| | | if (a.getHpicture() != null) { |
| | | if (!StringUtil.isNullOrEmpty(extra.gethPosterPicture())) |
| | | a.setHpicture(extra.gethPosterPicture()); |
| | | } |
| | | |
| | | if (a.getVpicture() != null) { |
| | | if (!StringUtil.isNullOrEmpty(extra.getvPosterPicture())) |
| | | a.setVpicture(extra.getvPosterPicture()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | object.put("code", 0); |
| | | JSONObject data = new JSONObject(); |
| | | JSONArray array = new JSONArray(); |
| | | |
| | | 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", new Gson().toJson(voList)); |
| | | 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++) { |
| | |
| | | // 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); |
| | | } |
| | | @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); |
| | | } |
| | | |
| | | @RequestMapping("getVideoInfoExtra") |
| | | public void getVideoInfoExtra(String id, PrintWriter out) { |
| | | VideoInfoExtra extra = videoInfoExtraService.getById(id); |
| | | JSONObject object = new JSONObject(); |
| | | if (extra != null) { |
| | | object.put("code", 0); |
| | | object.put("data", new Gson().toJson(extra)); |
| | | } else { |
| | | object.put("code", 1); |
| | | object.put("msg", "无附加信息"); |
| | | } |
| | | out.print(object); |
| | | } |
| | | |
| | | @RequestMapping("updateVideoInfoExtra") |
| | | public void updateVideoInfoExtra(String id, String vPicture, String hPicture, PrintWriter out) { |
| | | VideoInfoExtra extra = new VideoInfoExtra(); |
| | | extra.setId(id); |
| | | if (StringUtil.isNullOrEmpty(vPicture)) { |
| | | vPicture = ""; |
| | | } |
| | | |
| | | extra.setvPosterPicture(vPicture); |
| | | |
| | | if (StringUtil.isNullOrEmpty(hPicture)) { |
| | | hPicture = ""; |
| | | } |
| | | |
| | | extra.sethPosterPicture(hPicture); |
| | | |
| | | videoInfoExtraService.save(extra); |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | object.put("code", 0); |
| | | out.print(object); |
| | | } |
| | | |
| | | |
| | | } |