admin
2021-09-03 b41a6efe17ba61d150c5a9b7309651cebae54e0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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.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.TVLiveChannelService;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.web.tag.PageEntity;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
@Controller
@RequestMapping("admin/new/api/tvlive/channel")
public class TVLiveChannelAdminController {
 
    @Resource
    private TVLiveChannelService tvLiveChannelService;
 
    @Resource
    private TVLiveCategoryChannelService tvLiveCategoryChannelService;
 
    @Resource
    private SystemService systemService;
 
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
 
        @Override
        public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
            return src == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(src.getTime(), "yyyy.MM.dd HH:mm"));
        }
    }).create();
 
    @RequestMapping(value = "/getChannelList", method = RequestMethod.POST)
    public void getChannelList(HttpSession session, String categoryId, String key, Integer state, int page, PrintWriter out) {
 
        List<TVLiveChannel> channelList;
        long count;
        if (StringUtil.isNullOrEmpty(categoryId)) {
            channelList = tvLiveChannelService.list(key, state, page, Constant.pageCount);
            count = tvLiveChannelService.count(key, state);
        } else {
            channelList = tvLiveCategoryChannelService.listChannelByCid(categoryId, key, page, Constant.pageCount);
            count = tvLiveCategoryChannelService.countChannelByCid(categoryId, key);
        }
        JSONObject data = new JSONObject();
        data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
        data.put("data", gson.toJson(channelList));
        out.print(JsonUtil.loadTrueAdmin(data.toString()));
    }
 
 
    @RequestMapping(value = "/addCategoryChannel", method = RequestMethod.POST)
    public void addCategoryChannel(String categoryId, String channelIds, Integer weight, HttpSession session, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(categoryId) || StringUtil.isNullOrEmpty(channelIds)) {
            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
            return;
        }
 
        String[] channelIdArray = channelIds.split(",");
        for (String channelId : channelIdArray) {
            TVLiveCategoryChannelMap map = new TVLiveCategoryChannelMap();
            map.setWeight(weight);
            map.setCategoryId(categoryId);
            map.setChannelId(channelId);
            tvLiveCategoryChannelService.addMap(map);
        }
 
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
    @RequestMapping(value = "/deleteCategoryChannel", method = RequestMethod.POST)
    public void deleteCategoryChannel(String categoryId, String channelIds, HttpSession session, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(categoryId) || StringUtil.isNullOrEmpty(channelIds)) {
            out.print(JsonUtil.loadFalseAdmin("数据不完整"));
            return;
        }
 
        String[] channelIdArray = channelIds.split(",");
        for (String channelId : channelIdArray) {
            TVLiveCategoryChannelMap map = tvLiveCategoryChannelService.selectByCategoryIdAndChannelId(categoryId, channelId);
            if (map != null)
                tvLiveCategoryChannelService.deleteByPrimaryKey(map.getId());
        }
        out.print(JsonUtil.loadTrueAdmin(""));
    }
 
 
    @RequestMapping(value = "/updateCategoryChannelWeight", method = RequestMethod.POST)
    public void updateCategoryChannelWeight(String categoryId, String channelId, Integer weight, HttpSession session, PrintWriter out) {
        TVLiveCategoryChannelMap oldMap = tvLiveCategoryChannelService.selectByCategoryIdAndChannelId(categoryId, channelId);
        if (oldMap == null) {
            out.print(JsonUtil.loadFalseAdmin("分类的频道不存在"));
            return;
        }
 
        TVLiveCategoryChannelMap map = new TVLiveCategoryChannelMap();
        map.setId(oldMap.getId());
        map.setWeight(weight);
        tvLiveCategoryChannelService.update(map);
        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(""));
//    }
 
 
}