admin
2021-07-30 a66b556036c2b3936a51fd7b7e54a204eb31dc14
src/main/java/com/yeshi/buwan/controller/admin/api/VideoAdminController.java
@@ -2,16 +2,24 @@
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 com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.yeshi.buwan.domain.SolrVideo;
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.manager.SolrAlbumDataManager;
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;
@@ -28,7 +36,6 @@
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;
@@ -48,6 +55,9 @@
    private ResourceVideoService resourceVideoService;
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private IqiyiUtil iqiyiUtil;
    @Resource
@@ -57,7 +67,10 @@
    private ThreadPoolTaskExecutor taskExecutor;
    @Resource
    private SolrAlbumDataManager solrAlbumDataManager;
    private SolrAlbumVideoDataManager solrAlbumDataManager;
    @Resource
    private VideoInfoExtraService videoInfoExtraService;
    @RequestMapping(value = "/changevideoshow", method = RequestMethod.POST)
    public void changeVideoShow(String id, int show, PrintWriter out) {
@@ -85,10 +98,15 @@
    }
    @RequestMapping(value = "/videolist", method = RequestMethod.POST)
    public void videoList(int videotype, int page, String key, String type, String resourceIds, int contenttype, PrintWriter out) {
    public void videoList(int videotype, int page, String key, String type, String resourceIds, int contenttype, String freeType, String area, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(type)) {
            type = "name";
        }
        Integer freeTypeInt = null;
        if (!StringUtil.isNullOrEmpty(freeType)) {
            freeTypeInt = Integer.parseInt(freeType);
        }
@@ -125,10 +143,20 @@
            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 (SolrVideo videoInfo : dto.getVideoList())
                    voList.add(VideoAdminInfoVO.create(videoInfo));
                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,
@@ -138,6 +166,38 @@
                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();
@@ -206,5 +266,42 @@
        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);
    }
}