From f788607ff771a47bc60d6a86e00b3433c40f3d2c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 24 九月 2021 15:22:03 +0800
Subject: [PATCH] 接入视频直播

---
 src/main/java/com/yeshi/buwan/controller/admin/api/TVLiveChannelAdminController.java |  207 +++++++++++++++++++++++++++++----------------------
 1 files changed, 118 insertions(+), 89 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/admin/api/TVLiveChannelAdminController.java b/src/main/java/com/yeshi/buwan/controller/admin/api/TVLiveChannelAdminController.java
index bcb966e..c1fa332 100644
--- a/src/main/java/com/yeshi/buwan/controller/admin/api/TVLiveChannelAdminController.java
+++ b/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(""));
+    }
 
 
 }

--
Gitblit v1.8.0