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(""));
|
// }
|
|
|
}
|