弹幕下载

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

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

@ -23,10 +23,8 @@ import web.html.data.OtherDataResult;
import web.model.DataModelForm;
import web.service.DataService;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.ArrayList;
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"));
public DataController() throws IOException {
}
private static final String key="regionJson";
@RequestMapping
public String find(HttpSession session, Model model) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
session.setAttribute("regionJson", regionJson);
return super.find(model, new DataModelForm(), new DataTable<>(0, 10));
public DataController() throws IOException, InstantiationException, IllegalAccessException {
super();
}
@RequestMapping("start/{size}")
public void start(@PathVariable Integer size) {
stop();
@ -57,11 +52,11 @@ public class DataController extends TableController<DataModel, DataModelForm, Da
@ResponseBody
@RequestMapping(value = "count/{cid}")
public Integer count(@PathVariable int cid) {
// try {
// return ThriftClientDemo.commentSum(cid);
// }catch (Exception e){
// log.error(e);
// }
try {
return ThriftClientDemo.commentSum(cid);
}catch (Exception e){
log.error(e);
}
return null;
}
@ -118,4 +113,9 @@ public class DataController extends TableController<DataModel, DataModelForm, Da
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.service.BaseService;
import java.lang.reflect.InvocationTargetException;
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> {
@ -20,35 +19,51 @@ public abstract class TableController<T extends AbstractModel,A extends T,E exte
private static final int typeIndex=4;
@RequestMapping("table")
public String find(Model model,@ModelAttribute("command") A command,B pageResult) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
protected final B result = (B) getResolvableType(typeIndex).newInstance();
protected TableController() throws IllegalAccessException, InstantiationException {
}
@RequestMapping("table")
public String find(Model model,@ModelAttribute("command") A command,B pageResult) {
DBAction action=DBAction.R;
log.info(tableName+ "进行批量" + action.getCh() + "操作请求");
B result;
if(checkAction(action)) {
try {
Long rowCount=rowCount(command);
if(rowCount>0) {
List list = find(command, pageResult.getCurrentPage()*pageResult.getPageSize(), pageResult.getPageSize());
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{
result= (B) getResolvableType(typeIndex).getConstructor(Type.class,String.class).newInstance(Type.fail,"没有记录");
result.setType(Type.fail);
result.setErrorMsg("没有记录");
}
} catch (DataAccessException e) {
log.error(e);
result= (B) getResolvableType(typeIndex).getConstructor(Type.class,String.class).newInstance(Type.fail,"非法操作");
result.setType(Type.fail);
result.setErrorMsg("非法操作");
}
}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);
setModel(model);
return "table";
}
protected void setModel(Model model){
}
@Override
protected boolean checkAction(DBAction action) {
return false;

@ -1,7 +1,6 @@
package web.html;
import db.form.PageResult;
import db.form.Type;
import db.model.AbstractModel;
import java.util.List;
@ -19,21 +18,6 @@ public abstract class Table<E extends OtherResult,T extends AbstractModel> exten
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() {
if(importJspPath==null){
@ -66,4 +50,10 @@ public abstract class Table<E extends OtherResult,T extends AbstractModel> exten
public List<E> getOtherData() {
return otherData;
}
public void setOtherData(List<E> otherData) {
this.otherData = otherData;
}
}

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

@ -170,7 +170,7 @@ public class DataService extends BaseService {
sql.append(" where title like '%").append(form.getTitle()).append("%'");
}
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) {
$("td[cid=" + cid + "]").find("span").text("获取中");
$.get("/data/count/" + cid, function (result) {
if (result>=0) {
if (result!='') {
if(result > 0){
$("#cid_" + cid).removeAttr("disabled");
}

@ -63,7 +63,7 @@ public class SpringTest {
@Test
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();
}

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

Loading…
Cancel
Save