package com.yeshi.buwan.controller.parser;
|
|
import com.google.gson.FieldNamingPolicy;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.buwan.domain.system.DetailSystemConfig;
|
import com.yeshi.buwan.domain.system.DetailSystem;
|
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
|
import com.yeshi.buwan.service.imp.SystemService;
|
import com.yeshi.buwan.service.imp.zhibo.ZhiBoServcie;
|
import com.yeshi.buwan.util.JsonUtil;
|
import com.yeshi.buwan.util.NumberUtil;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.zhibo.ZhiBoUtil;
|
import com.yeshi.buwan.vo.AcceptData;
|
import com.yeshi.buwan.zhibo.entity.Live;
|
import com.yeshi.buwan.zhibo.entity.LiveType;
|
import com.yeshi.buwan.zhibo.entity.ZhiBoContent;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Controller
|
public class ZhiBoParser {
|
@Resource
|
private ZhiBoServcie zhiBoServcie;
|
|
@Resource
|
private SystemService systemService;
|
|
@Resource
|
private DetailSystemConfigService configService;
|
|
|
public void getTop(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
|
|
List<ZhiBoContent> list = new ArrayList<>();
|
JSONObject data = new JSONObject();
|
JSONArray array = new JSONArray();
|
for (ZhiBoContent zc : list) {
|
array.add(StringUtil.outPutResultJson(zc));
|
}
|
data.put("data", array);
|
data.put("count", list.size());
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
public void getNewList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
String page = request.getParameter("Page");
|
|
if (StringUtil.isNullOrEmpty(page)) {
|
out.print(JsonUtil.loadFalseJson("请上传page"));
|
return;
|
}
|
List<ZhiBoContent> list = new ArrayList<>();
|
long count = zhiBoServcie.getNewListCount();
|
JSONObject data = new JSONObject();
|
JSONArray array = new JSONArray();
|
for (ZhiBoContent zc : list) {
|
array.add(StringUtil.outPutResultJson(zc));
|
}
|
data.put("data", array);
|
data.put("count", count);
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
public void addStatistics(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
|
|
String type = request.getParameter("Type");
|
String roomId = request.getParameter("RoomId");
|
|
if (StringUtil.isNullOrEmpty(type)) {
|
out.print(JsonUtil.loadFalseJson("请上传Type"));
|
return;
|
}
|
|
if (StringUtil.isNullOrEmpty(roomId)) {
|
out.print(JsonUtil.loadFalseJson("请上传RoomId"));
|
return;
|
}
|
zhiBoServcie.addStatistics(roomId, Integer.parseInt(type));
|
out.print(JsonUtil.loadTrueJson(""));
|
}
|
|
public void getHotLive(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
boolean b = basicVerify(request, out);
|
if (!b) {
|
return;
|
}
|
|
List<Live> list = new ArrayList<>();
|
JSONObject data = new JSONObject();
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
data.put("data", gson.toJson(list));
|
data.put("PageSize", list.size());
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
public void getAllLiveType(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
boolean b = basicVerify(request, out);
|
if (!b) {
|
return;
|
}
|
|
DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
|
List<LiveType> typelist = new ArrayList<LiveType>();
|
String value = "";
|
if ("IOS".equalsIgnoreCase(acceptData.getPlatform())) {
|
DetailSystemConfig config = configService.getConfigByKey("open_huajiao_IOS", acceptData.getDetailSystem(), acceptData.getVersion());
|
value = config.getValue();
|
} else {
|
|
DetailSystemConfig config = configService.getConfigByKey("open_huajiao_Android", acceptData.getDetailSystem(), acceptData.getVersion());
|
value = config.getValue();
|
}
|
if ("是".equals(value)) {
|
typelist = zhiBoServcie.getAllLiveType(detailSystem.getId());
|
}
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
JSONObject data = new JSONObject();
|
data.put("data", gson.toJson(typelist));
|
data.put("PageSize", typelist.size());
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
public void getLiveList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
boolean bv = basicVerify(request, out);
|
if (!bv) {
|
return;
|
}
|
|
String page = request.getParameter("Page");
|
boolean b = NumberUtil.isNumeric(page);
|
if (!b) {
|
out.print(JsonUtil.loadFalseJson("page必须为正整数"));
|
return;
|
}
|
List<Live> list = new ArrayList<>();
|
if (list.size() > 0 && list.size() % 2 != 0) {
|
list.remove(list.size() - 1);
|
}
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
JSONObject data = new JSONObject();
|
data.put("PageSize", list.size());
|
data.put("data", gson.toJson(list));
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
public void getLiveListByType(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
boolean bb = basicVerify(request, out);
|
if (!bb) {
|
return;
|
}
|
String typeid = request.getParameter("Type");
|
String page = request.getParameter("Page");
|
boolean b = NumberUtil.isNumeric(typeid);
|
if (!b) {
|
out.print(JsonUtil.loadFalseJson("type必须为正整数"));
|
return;
|
}
|
b = NumberUtil.isNumeric(page);
|
if (!b) {
|
out.print(JsonUtil.loadFalseJson("page必须为正整数"));
|
return;
|
}
|
LiveType liveType = zhiBoServcie.getLiveType(typeid);
|
if (liveType == null) {
|
out.print(JsonUtil.loadFalseJson("不存在该类型"));
|
return;
|
}
|
String tag = liveType.getTag();
|
List<Live> list = ZhiBoUtil.getHuaJiaoList(Integer.parseInt(page), tag);
|
if (list.size() > 0 && (list.size() % 2 != 0)) {
|
list.remove(list.size() - 1);
|
}
|
JSONObject data = new JSONObject();
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
data.put("PageSize", list.size());
|
data.put("data", gson.toJson(list));
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
|
private boolean basicVerify(HttpServletRequest request, PrintWriter out) {
|
|
return true;
|
|
}
|
|
}
|