弹幕下载

master
10295 7 years ago
parent d621854a4c
commit 341f0f7c2f
  1. 11
      core/src/main/java/core/thrift/ThriftClientDemo.java
  2. 55
      db/src/main/java/db/form/PageResult.java
  3. 28
      web/src/main/java/web/controller/DataController.java
  4. 31
      web/src/main/java/web/controller/TableController.java
  5. 22
      web/src/main/java/web/html/Table.java
  6. 24
      web/src/main/java/web/html/data/DataTable.java
  7. 2
      web/src/main/java/web/service/DataService.java
  8. 2
      web/src/main/webapp/WEB-INF/jsp/data/otherData.jsp
  9. 2
      web/src/test/java/SpringTest.java
  10. 9
      web/src/test/java/Test.java

@ -9,7 +9,6 @@ import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransport;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ThriftClientDemo { public class ThriftClientDemo {
@ -17,12 +16,7 @@ public class ThriftClientDemo {
private static final String host="127.0.0.1"; private static final String host="127.0.0.1";
private static final int port=2233; private static final int port=2233;
private static Logger log=LogManager.getLogger(); private static Logger log=LogManager.getLogger();
private static final TTransport tTransport = getTTransport(host, port, 5000);
public static void main(String[] args) throws Exception {
downloadXml(new ArrayList<Integer>(){{
add(12026697);
}},"测试弹幕");
}
public static List<Integer> commentSumList(List<Integer> cids) throws Exception { public static List<Integer> commentSumList(List<Integer> cids) throws Exception {
List<Integer> result= client().commentSumList(cids); List<Integer> result= client().commentSumList(cids);
@ -48,9 +42,8 @@ public class ThriftClientDemo {
return new QueryComment.Client(protocol); return new QueryComment.Client(protocol);
} }
private static TTransport getTTransport() throws Exception{ public static TTransport getTTransport() throws Exception{
try{ try{
TTransport tTransport = getTTransport(host, port, 5000);
if(!tTransport.isOpen()){ if(!tTransport.isOpen()){
tTransport.open(); tTransport.open();
} }

@ -9,49 +9,40 @@ import java.util.List;
* @param <T> * @param <T>
*/ */
public class PageResult<T extends AbstractModel> { public class PageResult<T extends AbstractModel> {
/**
* 总记录数
*/
private long count; private long count;
/**
* 当前页数
*/
private int currentPage; private int currentPage;
/**
* 数据实体集合
*/
private List<T> datas; private List<T> datas;
/**
* 分页大小
*/
private int pageSize; private int pageSize;
/**
* 分页数
*/
private long pages; private long pages;
/**
* 返回结果
*/
private Type type; private Type type;
private String errorMsg;
public PageResult() {
}
/** /**
* * 错误信息
* @param count 总行数
* @param currentPage 当前分页数
* @param datas 数据
* @param pageSize 分页大小
* @param type 操作结果
*/ */
public PageResult(long count, int currentPage, List<T> datas, int pageSize, Type type) { private String errorMsg;
this.count = count;
this.currentPage = currentPage+1;
this.datas = datas;
this.pageSize = pageSize;
this.pages=count%pageSize==0?count/pageSize:count/pageSize+1;
this.type = type;
}
public PageResult(Type type, String errorMsg) {
this.type = type;
this.errorMsg = errorMsg;
}
public PageResult(int currentPage, int pageSize) {
this.currentPage = currentPage;
this.pageSize = pageSize;
}
public long getCount() { public long getCount() {
return count; return count;
@ -89,8 +80,8 @@ public class PageResult<T extends AbstractModel> {
return pages; return pages;
} }
public void setPages(long pages) { public void setPages() {
this.pages = pages; this.pages = count%pageSize==0?count/pageSize:count/pageSize+1;
} }
public Type getType() { public Type getType() {
@ -101,6 +92,8 @@ public class PageResult<T extends AbstractModel> {
this.type = type; this.type = type;
} }
public String getErrorMsg() { public String getErrorMsg() {
return errorMsg; return errorMsg;
} }

@ -23,10 +23,8 @@ import web.html.data.OtherDataResult;
import web.model.DataModelForm; import web.model.DataModelForm;
import web.service.DataService; import web.service.DataService;
import javax.servlet.http.HttpSession;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
@ -38,16 +36,13 @@ public class DataController extends TableController<DataModel, DataModelForm, Da
private final String regionJson = IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8")); private final String regionJson = IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8"));
public DataController() throws IOException { private static final String key="regionJson";
}
@RequestMapping public DataController() throws IOException, InstantiationException, IllegalAccessException {
public String find(HttpSession session, Model model) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { super();
session.setAttribute("regionJson", regionJson);
return super.find(model, new DataModelForm(), new DataTable<>(0, 10));
} }
@RequestMapping("start/{size}") @RequestMapping("start/{size}")
public void start(@PathVariable Integer size) { public void start(@PathVariable Integer size) {
stop(); stop();
@ -57,11 +52,11 @@ public class DataController extends TableController<DataModel, DataModelForm, Da
@ResponseBody @ResponseBody
@RequestMapping(value = "count/{cid}") @RequestMapping(value = "count/{cid}")
public Integer count(@PathVariable int cid) { public Integer count(@PathVariable int cid) {
// try { try {
// return ThriftClientDemo.commentSum(cid); return ThriftClientDemo.commentSum(cid);
// }catch (Exception e){ }catch (Exception e){
// log.error(e); log.error(e);
// } }
return null; return null;
} }
@ -118,4 +113,9 @@ public class DataController extends TableController<DataModel, DataModelForm, Da
add(new OtherDataResult()); add(new OtherDataResult());
}}; }};
} }
@Override
protected void setModel(Model model) {
model.addAttribute(key,regionJson);
}
} }

@ -11,7 +11,6 @@ import web.html.OtherResult;
import web.html.Table; import web.html.Table;
import web.service.BaseService; import web.service.BaseService;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
public abstract class TableController<T extends AbstractModel,A extends T,E extends BaseService,D extends OtherResult,B extends Table<D,T>> extends BaseController<T,A,E> { public abstract class TableController<T extends AbstractModel,A extends T,E extends BaseService,D extends OtherResult,B extends Table<D,T>> extends BaseController<T,A,E> {
@ -20,35 +19,51 @@ public abstract class TableController<T extends AbstractModel,A extends T,E exte
private static final int typeIndex=4; private static final int typeIndex=4;
@RequestMapping("table") protected final B result = (B) getResolvableType(typeIndex).newInstance();
public String find(Model model,@ModelAttribute("command") A command,B pageResult) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
protected TableController() throws IllegalAccessException, InstantiationException {
}
@RequestMapping("table")
public String find(Model model,@ModelAttribute("command") A command,B pageResult) {
DBAction action=DBAction.R; DBAction action=DBAction.R;
log.info(tableName+ "进行批量" + action.getCh() + "操作请求"); log.info(tableName+ "进行批量" + action.getCh() + "操作请求");
B result;
if(checkAction(action)) { if(checkAction(action)) {
try { try {
Long rowCount=rowCount(command); Long rowCount=rowCount(command);
if(rowCount>0) { if(rowCount>0) {
List list = find(command, pageResult.getCurrentPage()*pageResult.getPageSize(), pageResult.getPageSize()); List list = find(command, pageResult.getCurrentPage()*pageResult.getPageSize(), pageResult.getPageSize());
List<D> otherDatas= otherDatas(command); List<D> otherDatas= otherDatas(command);
result= (B) getResolvableType(typeIndex).getConstructor(long.class,int.class,List.class,int.class,Type.class,List.class).newInstance(rowCount, pageResult.getCurrentPage(),list,pageResult.getPageSize() , Type.success,otherDatas); result.setCount(rowCount);
result.setCurrentPage(pageResult.getCurrentPage()+1);
result.setDatas(list);
result.setPageSize(pageResult.getPageSize());
result.setType(Type.success);
result.setOtherData(otherDatas);
result.setPages();
}else{ }else{
result= (B) getResolvableType(typeIndex).getConstructor(Type.class,String.class).newInstance(Type.fail,"没有记录"); result.setType(Type.fail);
result.setErrorMsg("没有记录");
} }
} catch (DataAccessException e) { } catch (DataAccessException e) {
log.error(e); log.error(e);
result= (B) getResolvableType(typeIndex).getConstructor(Type.class,String.class).newInstance(Type.fail,"非法操作"); result.setType(Type.fail);
result.setErrorMsg("非法操作");
} }
}else{ }else{
result= (B) getResolvableType(typeIndex).getConstructor(Type.class,String.class).newInstance(Type.fail,tableName + "不允许" + action.getCh() + "操作"); result.setType(Type.fail);
result.setErrorMsg(tableName + "不允许" + action.getCh() + "操作");
} }
model.addAttribute("datas", result); model.addAttribute("datas", result);
setModel(model);
return "table"; return "table";
} }
protected void setModel(Model model){
}
@Override @Override
protected boolean checkAction(DBAction action) { protected boolean checkAction(DBAction action) {
return false; return false;

@ -1,7 +1,6 @@
package web.html; package web.html;
import db.form.PageResult; import db.form.PageResult;
import db.form.Type;
import db.model.AbstractModel; import db.model.AbstractModel;
import java.util.List; import java.util.List;
@ -19,21 +18,6 @@ public abstract class Table<E extends OtherResult,T extends AbstractModel> exten
private List<E> otherData; private List<E> otherData;
public Table() {
}
public Table(int currentPage, int pageSize) {
super(currentPage, pageSize);
}
public Table(long count, int currentPage, List<T> datas, int pageSize, Type type,List<E> otherData) {
super(count, currentPage, datas, pageSize, type);
this.otherData = otherData;
}
public Table(Type type, String errorMsg) {
super(type, errorMsg);
}
public String getImportJspPath() { public String getImportJspPath() {
if(importJspPath==null){ if(importJspPath==null){
@ -66,4 +50,10 @@ public abstract class Table<E extends OtherResult,T extends AbstractModel> exten
public List<E> getOtherData() { public List<E> getOtherData() {
return otherData; return otherData;
} }
public void setOtherData(List<E> otherData) {
this.otherData = otherData;
}
} }

@ -1,6 +1,5 @@
package web.html.data; package web.html.data;
import db.form.Type;
import db.model.bilibili.DataModel; import db.model.bilibili.DataModel;
import web.html.Table; import web.html.Table;
@ -9,22 +8,13 @@ import java.util.List;
public class DataTable<T extends DataModel> extends Table<OtherDataResult,T> { public class DataTable<T extends DataModel> extends Table<OtherDataResult,T> {
@Override
public int getPageSize() {
public DataTable(int currentPage, int pageSize) { if(super.getPageSize()==0){
super(currentPage, pageSize); return 10;
} }else{
return super.getPageSize();
public DataTable(long count, int currentPage, List<T> datas, int pageSize, Type type, List<OtherDataResult> otherData) { }
super(count, currentPage, datas, pageSize, type, otherData);
}
public DataTable(Type type, String errorMsg) {
super(type, errorMsg);
}
public DataTable(){
} }
@Override @Override

@ -170,7 +170,7 @@ public class DataService extends BaseService {
sql.append(" where title like '%").append(form.getTitle()).append("%'"); sql.append(" where title like '%").append(form.getTitle()).append("%'");
} }
log.info(sql); log.info(sql);
return getHibernateTemplate().execute(session -> session.createNativeQuery(sql.toString(),DataModel.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList()); return getHibernateTemplate().execute(session -> session.createNativeQuery(sql.toString(),DataModel.class).setFirstResult(firstResult).setMaxResults(maxResults>getMaxResults()?getMaxResults():maxResults).getResultList());
} }
} }

@ -15,7 +15,7 @@
function get(cid, i) { function get(cid, i) {
$("td[cid=" + cid + "]").find("span").text("获取中"); $("td[cid=" + cid + "]").find("span").text("获取中");
$.get("/data/count/" + cid, function (result) { $.get("/data/count/" + cid, function (result) {
if (result>=0) { if (result!='') {
if(result > 0){ if(result > 0){
$("#cid_" + cid).removeAttr("disabled"); $("#cid_" + cid).removeAttr("disabled");
} }

@ -63,7 +63,7 @@ public class SpringTest {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/table").param("firstResult", "0").param("maxResults", "10").param("cids","49052").param("typeIds","33")); ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/table").param("currentPage", "0").param("pageSize", "10").param("typeIds","33"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn(); resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
} }

@ -1,14 +1,11 @@
import core.thrift.ThriftClientDemo;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import web.service.BaseService;
import web.service.BiliService;
import java.io.IOException;
public class Test { public class Test {
private static Logger log = LogManager.getLogger(); private static Logger log = LogManager.getLogger();
public static void main(String[] args) throws IOException { public static void main(String[] args) throws Exception {
log.info(org.springframework.util.ClassUtils.isAssignable(BiliService.class,BaseService.class)); ThriftClientDemo.getTTransport();
} }
} }

Loading…
Cancel
Save