admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
src/main/java/com/yeshi/buwan/controller/admin/api/TVLiveChannelAdminController.java
@@ -1,16 +1,16 @@
package com.yeshi.buwan.controller.admin.api;
import com.google.gson.*;
import com.yeshi.buwan.domain.live.SuperTVLiveCategory;
import com.yeshi.buwan.domain.live.TVLiveCategory;
import com.yeshi.buwan.domain.live.TVLiveCategoryChannelMap;
import com.yeshi.buwan.domain.live.TVLiveChannel;
import com.google.gson.reflect.TypeToken;
import com.yeshi.buwan.domain.live.*;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.exception.live.TVLiveCategoryException;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.inter.live.TVLiveCategoryChannelService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelResourceService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelService;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.vo.tvlive.TVLiveChannelResourceMapAdminVO;
import com.yeshi.buwan.web.tag.PageEntity;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
@@ -39,6 +39,9 @@
    @Resource
    private SystemService systemService;
    @Resource
    private TVLiveChannelResourceService tvLiveChannelResourceService;
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
        @Override
@@ -63,6 +66,24 @@
        data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
        data.put("data", gson.toJson(channelList));
        out.print(JsonUtil.loadTrueAdmin(data.toString()));
    }
    @RequestMapping(value = "/addChannel", method = RequestMethod.POST)
    public void addChannel(TVLiveChannel channel, HttpSession session, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(channel.getName()) || StringUtil.isNullOrEmpty(channel.gethPicture())) {
            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
            return;
        }
        channel.setState(TVLiveChannel.STATE_NORMAL);
        try {
            tvLiveChannelService.addChannel(channel);
            out.print(JsonUtil.loadTrueAdmin(""));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
            return;
        }
    }
@@ -119,92 +140,100 @@
        out.print(JsonUtil.loadTrueAdmin(""));
    }
    //获取频道资源
//    @RequestMapping(value = "/addCategory", method = RequestMethod.POST)
//    public void addCategory(TVLiveCategory category, String detailsystemids, HttpSession session, PrintWriter out) {
//
//        if (StringUtil.isNullOrEmpty(category.getName())) {
//            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
//            return;
//        }
//
//        category.setSystemId(SystemUtil.getAdminSelectedSystem(session).getId());
//
//        List<String> detailSystemList = new ArrayList<>();
//        if (!StringUtil.isNullOrEmpty(detailsystemids)) {
//            String[] sps = detailsystemids.split(",");
//            for (String sp : sps) {
//                detailSystemList.add(sp);
//            }
//        }
//
//        try {
//            tvLiveCategoryService.addCategory(category, detailSystemList);
//            out.print(JsonUtil.loadTrueAdmin(""));
//        } catch (TVLiveCategoryException e) {
//            out.print(JsonUtil.loadFalseAdmin(e.getMsg()));
//        }
//    }
//
//
//    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
//    public void updateCategory(TVLiveCategory category, PrintWriter out) {
//
//        if (StringUtil.isNullOrEmpty(category.getName())) {
//            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
//            return;
//        }
//        tvLiveCategoryService.updateCategory(category);
//        out.print(JsonUtil.loadTrueAdmin(""));
//    }
//
//
//    @RequestMapping(value = "/getCategory", method = RequestMethod.POST)
//    public void getCategory(String id, PrintWriter out) {
//        TVLiveCategory category = tvLiveCategoryService.selectCategoryBuPrimaryKey(id);
//        out.print(JsonUtil.loadTrueAdmin(new Gson().toJson(category)));
//    }
//
//
//    /**
//     * 删除分类
//     *
//     * @param ids
//     * @param out
//     */
//    @RequestMapping(value = "/deleteCategory", method = RequestMethod.POST)
//    public void deleteCategory(String ids, PrintWriter out) {
//        if (StringUtil.isNullOrEmpty(ids)) {
//            out.print(JsonUtil.loadFalseAdmin("ids不能为空"));
//            return;
//        }
//        tvLiveCategoryService.deleteCateogry(Arrays.asList(ids.split(",")));
//        out.print(JsonUtil.loadTrueAdmin(""));
//    }
//
//
//    @RequestMapping(value = "/deleteSuperCategory", method = RequestMethod.POST)
//    public void deleteSuperCategory(String cid, String detailSystemId, PrintWriter out) {
//        if (StringUtil.isNullOrEmpty(cid) || StringUtil.isNullOrEmpty(detailSystemId)) {
//            out.print(JsonUtil.loadFalseAdmin("信息不完整"));
//            return;
//        }
//        tvLiveCategoryService.deleteSuperCategory(cid, detailSystemId);
//        out.print(JsonUtil.loadTrueAdmin(""));
//    }
//
//
//    @RequestMapping(value = "/addSuperCategory", method = RequestMethod.POST)
//    public void addSuperCategory(String cid, String detailSystemId, Integer weight, String icon, PrintWriter out) {
//
//        SuperTVLiveCategory superTVLiveCategory = new SuperTVLiveCategory();
//        superTVLiveCategory.setCid(cid);
//        superTVLiveCategory.setDetailSystemId(detailSystemId);
//        superTVLiveCategory.setWeight(weight);
//        superTVLiveCategory.setIcon(icon);
//        tvLiveCategoryService.addSuperCategory(superTVLiveCategory);
//        out.print(JsonUtil.loadTrueAdmin(""));
//    }
    /**
     * 获取频道的播放资源
     *
     * @param session
     * @param id
     * @param out
     */
    @RequestMapping(value = "/getChannelResourceList", method = RequestMethod.POST)
    public void getChannelResourceList(HttpSession session, String id, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseAdmin("频道ID不能为空"));
            return;
        }
        List<TVLiveChannelResourceMap> mapList = tvLiveChannelResourceService.listByChannelId(id);
        List<TVLiveChannelResourceMapAdminVO> voList = new ArrayList<>();
        if (mapList != null)
            for (TVLiveChannelResourceMap map : mapList) {
                voList.add(TVLiveChannelResourceMapAdminVO.create(map));
            }
        JSONObject data = new JSONObject();
        data.put("data", gson.toJson(voList));
        data.put("channelId", id);
        out.print(JsonUtil.loadTrueAdmin(data.toString()));
    }
    /**
     * 更新频道播放资源
     *
     * @param session
     * @param id
     * @param resources
     * @param out
     */
    @RequestMapping(value = "/updateChannelResources", method = RequestMethod.POST)
    public void updateChannelResources(HttpSession session, String id, String resources, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseAdmin("频道ID不能为空"));
            return;
        }
        Type type = new TypeToken<List<TVLiveChannelResourceMapAdminVO>>() {
        }.getType();
        List<TVLiveChannelResourceMapAdminVO> voList = gson.fromJson(resources, type);
        List<TVLiveChannelResourceMap> list = new ArrayList<>();
        for (TVLiveChannelResourceMapAdminVO vo : voList) {
            TVLiveChannelResourceMap map = new TVLiveChannelResourceMap();
            map.setId(vo.getId());
            map.setWeight(vo.getWeight());
            map.setChannelId(id);
            map.setPlayUrl(vo.getPlayUrl());
            map.setSubResourceName(vo.getName());
            list.add(map);
        }
        List<TVLiveChannelResourceMap> originMapList = tvLiveChannelResourceService.listByChannelId(id);
        if (originMapList == null)
            originMapList = new ArrayList<>();
        List<String> originMapIds = new ArrayList<>();
        for (TVLiveChannelResourceMap map : originMapList) {
            originMapIds.add(map.getId());
        }
        //更新需要更新的
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId() != null && originMapIds.contains(list.get(i).getId())) {
                originMapIds.remove(list.get(i).getId());
                tvLiveChannelResourceService.update(list.get(i));
                list.remove(i--);
            }
        }
        //删除不需要更新的
        for (String mid : originMapIds) {
            tvLiveChannelResourceService.delete(mid);
        }
        //添加新的
        for (TVLiveChannelResourceMap map : list) {
            //咪咕不能手动添加
            map.setResource(TVLiveResource.other);
            tvLiveChannelResourceService.add(map);
        }
        out.print(JsonUtil.loadTrueAdmin(""));
    }
}