package com.yeshi.buwan.controller.admin.api;
|
|
import com.google.gson.*;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.live.SuperTVLiveCategory;
|
import com.yeshi.buwan.domain.live.TVLiveCategory;
|
import com.yeshi.buwan.domain.special.Special;
|
import com.yeshi.buwan.domain.special.SpecialVideo;
|
import com.yeshi.buwan.domain.special.SuperSpecial;
|
import com.yeshi.buwan.domain.system.DetailSystem;
|
import com.yeshi.buwan.domain.system.SystemInfo;
|
import com.yeshi.buwan.domain.web.DetailSystemSelect;
|
import com.yeshi.buwan.domain.web.SpecialAdmin;
|
import com.yeshi.buwan.exception.live.TVLiveCategoryException;
|
import com.yeshi.buwan.service.imp.SpecialService;
|
import com.yeshi.buwan.service.imp.SystemService;
|
import com.yeshi.buwan.service.inter.live.TVLiveCategoryService;
|
import com.yeshi.buwan.util.*;
|
import com.yeshi.buwan.web.tag.PageEntity;
|
import net.sf.json.JSONArray;
|
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.*;
|
|
@Controller
|
@RequestMapping("admin/new/api/tvlive/category")
|
public class TVLiveCategoryAdminController {
|
|
@Resource
|
private TVLiveCategoryService tvLiveCategoryService;
|
|
@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 = "/getCategoryList", method = RequestMethod.POST)
|
public void getCategoryList(HttpSession session, String detailSystemId, String key, int page, PrintWriter out) {
|
SystemInfo systemInfo = SystemUtil.getAdminSelectedSystem(session);
|
detailSystemId = StringUtil.isNullOrEmpty(detailSystemId) ? null : detailSystemId;
|
List<TVLiveCategory> list = tvLiveCategoryService.list(detailSystemId, systemInfo.getId(), key, page, Constant.pageCount);
|
List<DetailSystem> detailSystemList = systemService.getDetailSystemList(systemInfo.getId());
|
List<TVLiveCategoryAdmin> resultList = new ArrayList<>();
|
if (list != null)
|
for (TVLiveCategory category : list) {
|
Set<String> selectedDetailSystemSet = new HashSet<>();
|
List<SuperTVLiveCategory> superList = tvLiveCategoryService.listSuper(category.getId());
|
for (SuperTVLiveCategory cy : superList) {
|
selectedDetailSystemSet.add(cy.getDetailSystemId());
|
}
|
List<DetailSystemSelect> selectList = new ArrayList<>();
|
for (DetailSystem detailSystem : detailSystemList) {
|
detailSystem.setSystem(null);
|
detailSystem.setInfo(null);
|
DetailSystemSelect select = new DetailSystemSelect();
|
select.setDetailSystem(detailSystem);
|
select.setSelected(selectedDetailSystemSet.contains(detailSystem.getId()));
|
selectList.add(select);
|
}
|
resultList.add(new TVLiveCategoryAdmin(category, selectList));
|
}
|
|
long count = tvLiveCategoryService.count(detailSystemId, systemInfo.getId(), key);
|
JSONObject data = new JSONObject();
|
data.put("pageEntity", new PageEntity(page, Constant.pageCount, (int) count));
|
data.put("data", gson.toJson(resultList));
|
out.print(JsonUtil.loadTrueAdmin(data.toString()));
|
}
|
|
@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(""));
|
}
|
|
|
class TVLiveCategoryAdmin {
|
private TVLiveCategory category;
|
private List<DetailSystemSelect> detailSystemSelectList;
|
|
public TVLiveCategoryAdmin(TVLiveCategory category, List<DetailSystemSelect> detailSystemSelectList) {
|
this.category = category;
|
this.detailSystemSelectList = detailSystemSelectList;
|
}
|
|
public TVLiveCategory getCategory() {
|
return category;
|
}
|
|
public void setCategory(TVLiveCategory category) {
|
this.category = category;
|
}
|
|
public List<DetailSystemSelect> getDetailSystemSelectList() {
|
return detailSystemSelectList;
|
}
|
|
public void setDetailSystemSelectList(List<DetailSystemSelect> detailSystemSelectList) {
|
this.detailSystemSelectList = detailSystemSelectList;
|
}
|
}
|
|
}
|