弹幕下载

master
10295 7 years ago
parent a16702d659
commit 07cc873550
  1. 64
      core/pom.xml
  2. 2
      core/src/main/java/core/thrift/QryResult.java
  3. 2
      core/src/main/java/core/thrift/QueryImp.java
  4. 2
      core/src/main/java/core/thrift/TestQry.java
  5. 2
      core/src/main/java/core/thrift/ThriftClientDemo.java
  6. 2
      core/src/main/java/core/thrift/ThriftServerDemo.java
  7. 2
      core/src/main/java/core/util/ClassScaner.java
  8. 19
      core/src/main/java/core/util/ToJSON.java
  9. 12
      db/pom.xml
  10. 26
      db/src/main/java/db/AbstractModel.java
  11. 33
      db/src/main/java/db/ToJSON.java
  12. 4
      db/src/main/java/db/annotation/BiliBili.java
  13. 12
      db/src/main/java/db/annotation/TableInfo.java
  14. 42
      db/src/main/java/db/config/HibernateConfig.java
  15. 2
      db/src/main/java/db/form/DBAction.java
  16. 8
      db/src/main/java/db/form/JsonResult.java
  17. 11
      db/src/main/java/db/form/PageResult.java
  18. 2
      db/src/main/java/db/form/Type.java
  19. 34
      db/src/main/java/db/model/AbstractModel.java
  20. 6
      db/src/main/java/db/model/DataSourceModel.java
  21. 7
      db/src/main/java/db/model/bilibili/CidEntity.java
  22. 10
      db/src/main/java/db/model/bilibili/DataModel.java
  23. 7
      db/src/main/java/db/model/bilibili/MenuModel.java
  24. 6
      db/src/main/java/db/model/bilibili/ScheduledTaskEntity.java
  25. 7
      db/src/main/java/db/model/bilibili/TaskEntity.java
  26. 24
      pom-webjar.xml
  27. 29
      pom.xml
  28. 66
      web/pom.xml
  29. 2
      web/src/main/java/web/aop/Advice.java
  30. 17
      web/src/main/java/web/aop/Advisor.java
  31. 14
      web/src/main/java/web/config/SpringConfig.java
  32. 6
      web/src/main/java/web/controller/AdminController.java
  33. 66
      web/src/main/java/web/controller/BaseController.java
  34. 8
      web/src/main/java/web/controller/BiliController.java
  35. 52
      web/src/main/java/web/controller/DataController.java
  36. 15
      web/src/main/java/web/controller/MenuController.java
  37. 28
      web/src/main/java/web/controller/TableController.java
  38. 15
      web/src/main/java/web/model/DataModel.java
  39. 20
      web/src/main/java/web/service/BaseService.java
  40. 4
      web/src/main/java/web/service/BiliService.java
  41. 1
      web/src/main/java/web/service/DataService.java
  42. 23
      web/src/main/java/web/util/DynamicTimer.java
  43. 64
      web/src/main/webapp/WEB-INF/jsp/form.jsp
  44. 67
      web/src/main/webapp/WEB-INF/jsp/table.jsp
  45. 14
      web/src/test/java/SpringTest.java
  46. 5
      web/src/test/java/Test.java
  47. 6
      web/src/test/java/db/model/TaskModel.java
  48. 3
      web/src/test/java/web/controller/TestController.java

@ -11,6 +11,9 @@
<name>core</name> <name>core</name>
<url>https://gitee.com/WuXianChaoPin/webCrawler</url> <url>https://gitee.com/WuXianChaoPin/webCrawler</url>
<properties>
<thrift.version>RELEASE</thrift.version>
</properties>
<dependencies> <dependencies>
@ -24,71 +27,22 @@
<artifactId>spring-webmvc</artifactId> <artifactId>spring-webmvc</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId> <artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>fastjson</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.thrift</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>libthrift</artifactId>
</dependency> <version>${thrift.version}</version>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>db</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

@ -4,7 +4,7 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated * @generated
*/ */
package web.thrift; package core.thrift;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2018-04-28") @javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2018-04-28")

@ -1,4 +1,4 @@
package web.thrift; package core.thrift;
import org.apache.thrift.TException; import org.apache.thrift.TException;

@ -4,7 +4,7 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated * @generated
*/ */
package web.thrift; package core.thrift;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2018-04-28") @javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2018-04-28")

@ -1,4 +1,4 @@
package web.thrift; package core.thrift;
import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocol;

@ -1,4 +1,4 @@
package web.thrift; package core.thrift;
import org.apache.thrift.TProcessorFactory; import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol;

@ -1,4 +1,4 @@
package db.util; package core.util;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanDefinitionStoreException;

@ -0,0 +1,19 @@
package core.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import java.util.ArrayList;
import java.util.List;
public class ToJSON {
protected List<SerializerFeature> serializerFeatures(){
return new ArrayList<>();
}
@Override
public String toString() {
return JSON.toJSONString(this,serializerFeatures().toArray(new SerializerFeature[0]));
}
}

@ -30,11 +30,6 @@
<artifactId>log4j-web</artifactId> <artifactId>log4j-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
@ -64,5 +59,12 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -1,26 +0,0 @@
package db;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.criterion.DetachedCriteria;
import java.io.Serializable;
/**
* Created by reborn on 2017/8/3.
*/
public abstract class AbstractModel extends ToJSON{
public abstract Serializable primaryKey();
public abstract String tableNote();
@JsonIgnore
public DetachedCriteria getCriteria() {
return DetachedCriteria.forClass(this.getClass());
}
@SuppressWarnings("unchecked")
public <T extends AbstractModel> T cast() throws ClassCastException{
return (T) this;
}
}

@ -1,33 +0,0 @@
package db;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ToJSON {
private static ObjectMapper mapper=new ObjectMapper();
private static Logger log=LogManager.getLogger();
static {
init();
}
protected static void init(){
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
@Override
public String toString() {
try {
return mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
log.error(e);
return super.toString();
}
}
}

@ -1,4 +1,8 @@
package db.annotation; package db.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
public @interface BiliBili { public @interface BiliBili {
} }

@ -0,0 +1,12 @@
package db.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface TableInfo {
String comment();
}

@ -1,9 +1,9 @@
package db.config; package db.config;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import db.AbstractModel; import core.util.ClassScaner;
import db.annotation.TableInfo;
import db.model.DataSourceModel; import db.model.DataSourceModel;
import db.util.ClassScaner;
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 org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
@ -12,15 +12,12 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*; import java.util.*;
/** /**
@ -65,6 +62,12 @@ public class HibernateConfig {
return map; return map;
} }
private static final Map<Class,TableInfo> tableNotes=new HashMap<>();
public static TableInfo getTableNote(Class c){
return tableNotes.get(c);
}
private DruidDataSource dataSource(String url, String username, String password) { private DruidDataSource dataSource(String url, String username, String password) {
DruidDataSource dataSource = new DruidDataSource(); DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(url); dataSource.setUrl(url);
@ -100,10 +103,12 @@ public class HibernateConfig {
if (Annotation.class.isAssignableFrom(c)) { if (Annotation.class.isAssignableFrom(c)) {
classes = ClassScaner.scan(basePackage, (Class<? extends Annotation>) c); classes = ClassScaner.scan(basePackage, (Class<? extends Annotation>) c);
classes.forEach(this::checkClass);
bean.setAnnotatedClasses(classes.toArray(new Class[classes.size()])); bean.setAnnotatedClasses(classes.toArray(new Class[classes.size()]));
} else { } else {
log.error(c+"不是注解!!!"); log.error(c+"不是注解!!!");
} }
}); });
if (sessionFactory != null) { if (sessionFactory != null) {
@ -158,7 +163,6 @@ public class HibernateConfig {
try { try {
config.addConfig(bean); config.addConfig(bean);
bean.afterPropertiesSet(); bean.afterPropertiesSet();
checkClass(bean);
return bean.getObject(); return bean.getObject();
} catch (IOException e) { } catch (IOException e) {
log.error(e); log.error(e);
@ -166,27 +170,11 @@ public class HibernateConfig {
return null; return null;
} }
private void checkClass(LocalSessionFactoryBean bean) { private void checkClass(Class c) {
for (Class c : bean.getMetadataSources().getAnnotatedClasses()) { if(c.isAnnotationPresent(TableInfo.class)){
if (AbstractModel.class.isAssignableFrom(c)) { TableInfo info= (TableInfo) c.getAnnotation(TableInfo.class);
try { tableNotes.put(c,info);
Method method = ReflectionUtils.findMethod(c, tableNote); }
Object result = ReflectionUtils.invokeMethod(method, c.newInstance());
if (ObjectUtils.isEmpty(result)) {
throw new RuntimeException(method + "没有正确重写");
}else{
log.info("扫描实体类:"+c+",映射表:"+result);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
} else {
log.error(c + "没有继承" + AbstractModel.class);
}
}
} }

@ -1,4 +1,4 @@
package db; package db.form;
/** /**
* Created by reborn on 2017/8/2. * Created by reborn on 2017/8/2.

@ -1,6 +1,9 @@
package db; package db.form;
public class JsonResult<T> extends ToJSON{
import core.util.ToJSON;
public class JsonResult<T> extends ToJSON {
private T data; private T data;
@ -8,6 +11,7 @@ public class JsonResult<T> extends ToJSON{
private DBAction action; private DBAction action;
public JsonResult(T data, Type type, DBAction action) { public JsonResult(T data, Type type, DBAction action) {
this.data = data; this.data = data;
this.type = type; this.type = type;

@ -1,4 +1,6 @@
package db; package db.form;
import db.model.AbstractModel;
import java.util.List; import java.util.List;
@ -39,6 +41,9 @@ public class PageResult<T extends AbstractModel> {
this.errorMsg = errorMsg; this.errorMsg = errorMsg;
} }
public PageResult() {
}
public long getCount() { public long getCount() {
return count; return count;
} }
@ -66,4 +71,8 @@ public class PageResult<T extends AbstractModel> {
public String getErrorMsg() { public String getErrorMsg() {
return errorMsg; return errorMsg;
} }
public void setDatas(List<T> datas) {
this.datas = datas;
}
} }

@ -1,4 +1,4 @@
package db; package db.form;
import java.io.Serializable; import java.io.Serializable;

@ -0,0 +1,34 @@
package db.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import core.util.ToJSON;
import org.hibernate.criterion.DetachedCriteria;
import java.io.Serializable;
import java.util.List;
/**
* Created by reborn on 2017/8/3.
*/
public abstract class AbstractModel extends ToJSON {
public abstract Serializable primaryKey();
@Override
protected List<SerializerFeature> serializerFeatures() {
List list=super.serializerFeatures();
list.add(SerializerFeature.PrettyFormat);
return list;
}
@JSONField(serialize = false)
public DetachedCriteria getCriteria() {
return DetachedCriteria.forClass(this.getClass());
}
@SuppressWarnings("unchecked")
public <T extends AbstractModel> T cast() throws ClassCastException{
return (T) this;
}
}

@ -1,7 +1,5 @@
package db.model; package db.model;
import db.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@ -112,8 +110,4 @@ public class DataSourceModel extends AbstractModel {
return getDbDesc(); return getDbDesc();
} }
@Override
public String tableNote() {
return "数据源";
}
} }

@ -1,6 +1,6 @@
package db.model.bilibili; package db.model.bilibili;
import db.AbstractModel; import db.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -278,9 +278,4 @@ public class CidEntity extends AbstractModel {
public Serializable primaryKey() { public Serializable primaryKey() {
return getCid(); return getCid();
} }
@Override
public String tableNote() {
return "CID表";
}
} }

@ -1,7 +1,8 @@
package db.model.bilibili; package db.model.bilibili;
import db.AbstractModel;
import db.annotation.BiliBili; import db.annotation.BiliBili;
import db.annotation.TableInfo;
import db.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -10,6 +11,7 @@ import java.util.Objects;
@BiliBili @BiliBili
@Entity @Entity
@Table(name = "data", schema = "bilibili", catalog = "bilibili") @Table(name = "data", schema = "bilibili", catalog = "bilibili")
@TableInfo(comment = "历史接口")
public class DataModel extends AbstractModel { public class DataModel extends AbstractModel {
private int cid; private int cid;
private Integer aid; private Integer aid;
@ -41,6 +43,7 @@ public class DataModel extends AbstractModel {
private Integer vp; private Integer vp;
private Integer typeId; private Integer typeId;
@Id @Id
@Column(name = "cid") @Column(name = "cid")
public int getCid() { public int getCid() {
@ -377,9 +380,4 @@ public class DataModel extends AbstractModel {
public Serializable primaryKey() { public Serializable primaryKey() {
return getCid(); return getCid();
} }
@Override
public String tableNote() {
return "history接口数据表";
}
} }

@ -1,7 +1,7 @@
package db.model.bilibili; package db.model.bilibili;
import db.AbstractModel;
import db.annotation.BiliBili; import db.annotation.BiliBili;
import db.model.AbstractModel;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property; import org.hibernate.criterion.Property;
@ -87,11 +87,6 @@ public class MenuModel extends AbstractModel {
return getId(); return getId();
} }
@Override
public String tableNote() {
return "菜单表";
}
@Basic @Basic
@Column(name = "parent_id") @Column(name = "parent_id")
public int getParentId() { public int getParentId() {

@ -1,6 +1,6 @@
package db.model.bilibili; package db.model.bilibili;
import db.AbstractModel; import db.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -125,8 +125,4 @@ public class ScheduledTaskEntity extends AbstractModel {
return getId(); return getId();
} }
@Override
public String tableNote() {
return "定时任务";
}
} }

@ -1,6 +1,6 @@
package db.model.bilibili; package db.model.bilibili;
import db.AbstractModel; import db.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -39,11 +39,6 @@ public class TaskEntity extends AbstractModel {
return getId(); return getId();
} }
@Override
public String tableNote() {
return "脚本任务";
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.pqh</groupId> <groupId>org.pqh</groupId>
<artifactId>webjar</artifactId> <artifactId>webjar</artifactId>
<packaging>pom</packaging> <packaging>jar</packaging>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<name>webjar</name> <name>webjar</name>
@ -14,6 +14,9 @@
<bootstrap.version>RELEASE</bootstrap.version> <bootstrap.version>RELEASE</bootstrap.version>
<fontawesome.version>RELEASE</fontawesome.version> <fontawesome.version>RELEASE</fontawesome.version>
<jquery-tmpl.version>RELEASE</jquery-tmpl.version> <jquery-tmpl.version>RELEASE</jquery-tmpl.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
<dependencies> <dependencies>
@ -56,4 +59,23 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

@ -20,12 +20,9 @@
<spring.version>RELEASE</spring.version> <spring.version>RELEASE</spring.version>
<mysql.version>6.0.6</mysql.version> <mysql.version>6.0.6</mysql.version>
<commons-dbcp2.version>RELEASE</commons-dbcp2.version>
<hibernate-core.version>RELEASE</hibernate-core.version> <hibernate-core.version>RELEASE</hibernate-core.version>
<jackson-databind.version>RELEASE</jackson-databind.version> <fastjson.version>RELEASE</fastjson.version>
<aspectjweaver.version>RELEASE</aspectjweaver.version>
<log4j.version>RELEASE</log4j.version> <log4j.version>RELEASE</log4j.version>
<commons-io.version>RELEASE</commons-io.version>
<druid.version>RELEASE</druid.version> <druid.version>RELEASE</druid.version>
<lang3.version>RELEASE</lang3.version> <lang3.version>RELEASE</lang3.version>
</properties> </properties>
@ -51,11 +48,7 @@
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons-dbcp2.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
@ -69,15 +62,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.alibaba</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>fastjson</artifactId>
<version>${jackson-databind.version}</version> <version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -98,12 +85,6 @@
<version>${log4j.version}</version> <version>${log4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>

@ -17,7 +17,8 @@
<servlet-api.version>RELEASE</servlet-api.version> <servlet-api.version>RELEASE</servlet-api.version>
<jstl.version>1.2</jstl.version> <jstl.version>1.2</jstl.version>
<standard.version>1.1.2</standard.version> <standard.version>1.1.2</standard.version>
<thrift.version>RELEASE</thrift.version> <aspectjweaver.version>RELEASE</aspectjweaver.version>
<commons-io.version>RELEASE</commons-io.version>
</properties> </properties>
<dependencies> <dependencies>
@ -27,6 +28,12 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>db</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
@ -42,11 +49,6 @@
<artifactId>spring-orm</artifactId> <artifactId>spring-orm</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
@ -58,33 +60,40 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>log4j-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.aspectj</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>aspectjweaver</artifactId> <artifactId>log4j-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>com.alibaba</groupId>
<artifactId>log4j-core</artifactId> <artifactId>fastjson</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>com.alibaba</groupId>
<artifactId>log4j-web</artifactId> <artifactId>druid</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -94,18 +103,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>jstl</groupId> <groupId>jstl</groupId>
<artifactId>jstl</artifactId> <artifactId>jstl</artifactId>
@ -118,21 +115,6 @@
<version>${standard.version}</version> <version>${standard.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>${thrift.version}</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

@ -1,4 +1,4 @@
package core.aop; package web.aop;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

@ -1,12 +1,10 @@
package core.aop; package web.aop;
import core.service.BaseService;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import web.service.BaseService;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
@ -14,16 +12,13 @@ import java.lang.reflect.Method;
*/ */
@Component @Component
public class Advisor extends StaticMethodMatcherPointcutAdvisor { public class Advisor extends StaticMethodMatcherPointcutAdvisor {
@Resource
private Advice advice; public Advisor(Advice advice) {
super(advice);
}
@Override @Override
public boolean matches(Method method, Class<?> aClass) { public boolean matches(Method method, Class<?> aClass) {
return BaseService.class.isAssignableFrom(aClass); return BaseService.class.isAssignableFrom(aClass);
} }
@PostConstruct
public void init(){
this.setAdvice(advice);
}
} }

@ -1,15 +1,16 @@
package web.config; package web.config;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import db.config.HibernateConfig; import db.config.HibernateConfig;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor; import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.servlet.config.annotation.*;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -45,10 +46,13 @@ public class SpringConfig implements WebMvcConfigurer {
@Override @Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); FastJsonHttpMessageConverter fastJsonHttpMessageConverter=new FastJsonHttpMessageConverter();
builder.indentOutput(true); fastJsonHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
converters.add(new MappingJackson2HttpMessageConverter(builder.build())); converters.add(fastJsonHttpMessageConverter);
} }
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
}
} }

@ -1,6 +1,5 @@
package web.controller; package web.controller;
import db.DBAction;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -31,8 +30,5 @@ public class AdminController extends BiliController{
return "test2"; return "test2";
} }
@Override
public boolean checkAction(DBAction action) {
return true;
}
} }

@ -1,33 +1,53 @@
package web.controller; package web.controller;
import core.service.BaseService; import db.annotation.TableInfo;
import db.AbstractModel; import db.config.HibernateConfig;
import db.DBAction; import db.form.DBAction;
import db.JsonResult; import db.form.JsonResult;
import db.Type; import db.form.Type;
import db.model.AbstractModel;
import org.apache.commons.lang3.StringUtils;
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 org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import web.service.BaseService;
import java.lang.reflect.ParameterizedType;
/** /**
* Created by reborn on 2017/9/14. * Created by reborn on 2017/9/14.
*/ */
public abstract class BaseController<T extends AbstractModel,E extends BaseService>{ public abstract class BaseController<T extends AbstractModel,A extends T,E extends BaseService>{
protected static Logger log=LogManager.getLogger(); protected static Logger log=LogManager.getLogger();
protected E service; protected E service;
protected abstract void setService(E service); protected abstract void setService(E service);
private Class<T> tClass;
protected final String tableName;
public BaseController() {
TableInfo tableInfo=HibernateConfig.getTableNote(getCommandClass());
if(tableInfo!=null&&StringUtils.isNotEmpty(tableInfo.comment())){
tableName=tableInfo.comment();
}else {
tableName=getCommandClass().getName();
}
}
@ResponseBody @ResponseBody
@RequestMapping(value = "{action}", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "{action}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public <T extends AbstractModel> JsonResult curd(@PathVariable DBAction action, T model) { public JsonResult curd(@PathVariable DBAction action, T model) {
log.info(model.tableNote()+ "进行" + action.getCh() + "操作请求"); log.info(tableName+ "进行" + action.getCh() + "操作请求");
if(checkAction(action)) { if(checkAction(action)) {
try { try {
return new JsonResult<>(service.curd(action, model), Type.success, action); return new JsonResult<>(service.curd(action, model), Type.success, action);
@ -36,28 +56,44 @@ public abstract class BaseController<T extends AbstractModel,E extends BaseServi
return new JsonResult<>("非法操作", Type.fail, action); return new JsonResult<>("非法操作", Type.fail, action);
} }
}else{ }else{
return new JsonResult<>(model.tableNote() + "不允许" + action.getCh() + "操作", Type.fail,action); return new JsonResult<>(tableName + "不允许" + action.getCh() + "操作", Type.fail,action);
} }
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "batch/{action}", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "batch/{action}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public <T extends AbstractModel> JsonResult find(@PathVariable DBAction action, T queryCommand,@RequestParam Integer firstResult,@RequestParam Integer maxResults){ public JsonResult find(@PathVariable DBAction action, A queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){
log.info(queryCommand.tableNote()+ "进行批量" + action.getCh() + "操作请求"); log.info(tableName + "进行批量" + action.getCh() + "操作请求");
if(checkAction(action)) { if(checkAction(action)) {
try { try {
return new JsonResult<>(service.find(queryCommand, firstResult, maxResults), Type.success, action);
return new JsonResult<>(service.find(getDetachedCriteria(queryCommand), firstResult, maxResults), Type.success, action);
} catch (DataAccessException e) { } catch (DataAccessException e) {
log.error(e); log.error(e);
return new JsonResult<>("非法操作", Type.fail, action); return new JsonResult<>("非法操作", Type.fail, action);
} }
}else{ }else{
return new JsonResult<>(queryCommand.tableNote() + "不允许" + action.getCh() + "操作", Type.fail,action); return new JsonResult<>(tableName + "不允许" + action.getCh() + "操作", Type.fail,action);
} }
} }
public Class<T> getCommandClass(){
// log.info(ResolvableType.forField(ReflectionUtils.findField(this.getClass(),"service")));
if(tClass==null){
if(this.getClass().getGenericSuperclass() instanceof ParameterizedType){
tClass=(Class<T>) ((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}else{
tClass= (Class<T>) AbstractModel.class;
}
}
return tClass;
}
protected DetachedCriteria getDetachedCriteria(A queryCommand){
return DetachedCriteria.forClass(getCommandClass());
}
protected abstract boolean checkAction(DBAction action); protected abstract boolean checkAction(DBAction action);
} }

@ -1,11 +1,11 @@
package web.controller; package web.controller;
import db.AbstractModel; import db.form.DBAction;
import db.DBAction; import db.model.AbstractModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import web.service.BiliService; import web.service.BiliService;
public class BiliController<T extends AbstractModel> extends BaseController<T,BiliService>{ public abstract class BiliController<T extends AbstractModel> extends BaseController<T,T,BiliService>{
@Override @Override
@Autowired @Autowired
@ -17,4 +17,6 @@ public class BiliController<T extends AbstractModel> extends BaseController<T,Bi
protected boolean checkAction(DBAction action) { protected boolean checkAction(DBAction action) {
return false; return false;
} }
} }

@ -1,10 +1,12 @@
package web.controller; package web.controller;
import com.fasterxml.jackson.databind.JsonNode; import db.form.DBAction;
import com.fasterxml.jackson.databind.ObjectMapper;
import db.AbstractModel;
import db.DBAction;
import db.model.bilibili.DataModel; import db.model.bilibili.DataModel;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Property;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -12,44 +14,36 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import web.service.DataService; import web.service.DataService;
import javax.annotation.Resource; import javax.servlet.http.HttpSession;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.util.EnumSet; import java.util.EnumSet;
@Controller @Controller
@RequestMapping("/data") @RequestMapping("/data")
public class DataController extends TableController<DataModel,DataService> { public class DataController extends TableController<DataModel, web.model.DataModel,DataService> {
private final String regionJson=IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8"));
private static JsonNode jsonNode; public DataController() throws IOException {
static {
try {
jsonNode = new ObjectMapper().readTree(DataController.class.getResourceAsStream("/region.json"));
} catch (IOException e) {
e.printStackTrace();
}
} }
;
@Resource
private DataService dataService;
@RequestMapping @RequestMapping
public <T extends AbstractModel> String find(Model model, DataModel queryCommand){ public String find(HttpSession session,Model model) {
model.addAttribute("regionJson",jsonNode.toString()); session.setAttribute("regionJson",regionJson);
return super.find(model,queryCommand,0,10); return super.find(model,new web.model.DataModel(),0,10);
} }
@RequestMapping("start/{size}") @RequestMapping("start/{size}")
public void start(@PathVariable Integer size){ public void start(@PathVariable Integer size){
stop(); stop();
dataService.start(size); service.start(size);
} }
@RequestMapping("stop") @RequestMapping("stop")
public void stop(){ public void stop(){
dataService.stop(); service.stop();
} }
@Override @Override
@ -62,4 +56,18 @@ public class DataController extends TableController<DataModel,DataService> {
public boolean checkAction(DBAction action) { public boolean checkAction(DBAction action) {
return !EnumSet.of(DBAction.D).contains(action); return !EnumSet.of(DBAction.D).contains(action);
} }
@Override
protected DetachedCriteria getDetachedCriteria(web.model.DataModel queryCommand) {
DetachedCriteria criteria= super.getDetachedCriteria(queryCommand);
if(StringUtils.isNotEmpty(queryCommand.getTitle())){
criteria.add(Property.forName("title").like(queryCommand.getTitle(),MatchMode.ANYWHERE));
}
// if(queryCommand.getTypeIds()!=null){
// criteria.add(Property.forName("typeId").in(queryCommand.getTypeIds()));
// }
return criteria;
}
} }

@ -1,8 +1,10 @@
package web.controller; package web.controller;
import db.AbstractModel; import db.form.DBAction;
import db.DBAction;
import db.model.bilibili.MenuModel; import db.model.bilibili.MenuModel;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -13,8 +15,8 @@ import org.springframework.web.bind.annotation.RequestParam;
public class MenuController extends BiliController<MenuModel> { public class MenuController extends BiliController<MenuModel> {
@RequestMapping() @RequestMapping
public <T extends AbstractModel> String find(Model model, MenuModel queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){ public String find(Model model, MenuModel queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){
model.addAttribute("menus", super.find(DBAction.R, queryCommand, firstResult, maxResults).toString()); model.addAttribute("menus", super.find(DBAction.R, queryCommand, firstResult, maxResults).toString());
return "menu"; return "menu";
} }
@ -23,4 +25,9 @@ public class MenuController extends BiliController<MenuModel> {
public boolean checkAction(DBAction action) { public boolean checkAction(DBAction action) {
return DBAction.R.equals(action); return DBAction.R.equals(action);
} }
@Override
protected DetachedCriteria getDetachedCriteria(MenuModel queryCommand) {
return super.getDetachedCriteria(queryCommand).add(Property.forName("menuLevel").eq(0)).addOrder(Order.asc("sort"));
}
} }

@ -1,29 +1,32 @@
package web.controller; package web.controller;
import core.service.BaseService; import db.form.DBAction;
import db.AbstractModel; import db.form.PageResult;
import db.DBAction; import db.form.Type;
import db.PageResult; import db.model.AbstractModel;
import db.Type;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import web.service.BaseService;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
public abstract class TableController<T extends AbstractModel,E extends BaseService> extends BaseController<T,E> { public abstract class TableController<T extends AbstractModel,A extends T,E extends BaseService> extends BaseController<T,A,E> {
@RequestMapping("table") @RequestMapping("table")
public <T extends AbstractModel> String find(Model model, T queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){ public String find(Model model,@ModelAttribute("command") A command, @RequestParam Integer firstResult, @RequestParam Integer maxResults){
DBAction action=DBAction.R; DBAction action=DBAction.R;
log.info(queryCommand.tableNote()+ "进行批量" + action.getCh() + "操作请求"); log.info(tableName+ "进行批量" + action.getCh() + "操作请求");
PageResult result; PageResult result;
if(checkAction(action)) { if(checkAction(action)) {
try { try {
Long rowCount=service.rowCount(queryCommand.getClass()); Long rowCount=service.rowCount(getDetachedCriteria(command));
if(rowCount>0) { if(rowCount>0) {
List list = service.find(queryCommand, firstResult*maxResults, maxResults); List list = service.find(getDetachedCriteria(command), firstResult*maxResults, maxResults);
result=new PageResult<T>(rowCount, firstResult,list,maxResults , Type.success); result=new PageResult<T>(rowCount, firstResult,list,maxResults , Type.success);
}else{ }else{
result=new PageResult(Type.fail,"没有记录"); result=new PageResult(Type.fail,"没有记录");
@ -33,13 +36,16 @@ public abstract class TableController<T extends AbstractModel,E extends BaseServ
result=new PageResult(Type.fail,"非法操作"); result=new PageResult(Type.fail,"非法操作");
} }
}else{ }else{
result=new PageResult(Type.fail,queryCommand.tableNote() + "不允许" + action.getCh() + "操作"); result=new PageResult(Type.fail,tableName + "不允许" + action.getCh() + "操作");
} }
model.addAttribute("datas", result); model.addAttribute("datas", result);
return "table"; return "table";
} }
protected void setModel(HttpServletRequest request, Model model){
}
@Override @Override
protected boolean checkAction(DBAction action) { protected boolean checkAction(DBAction action) {

@ -0,0 +1,15 @@
package web.model;
import java.util.List;
public class DataModel extends db.model.bilibili.DataModel {
private List<Integer> typeIds;
public List<Integer> getTypeIds() {
return typeIds;
}
public void setTypeIds(List<Integer> typeIds) {
this.typeIds = typeIds;
}
}

@ -1,7 +1,7 @@
package core.service; package web.service;
import db.AbstractModel; import db.form.DBAction;
import db.DBAction; import db.model.AbstractModel;
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 org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
@ -20,14 +20,14 @@ public abstract class BaseService {
protected abstract HibernateTemplate getHibernateTemplate() ; protected abstract HibernateTemplate getHibernateTemplate() ;
public<T extends AbstractModel> T curd(DBAction action, T command) throws DataAccessException { public <T extends AbstractModel> T curd(DBAction action, T command) throws DataAccessException {
switch (action) { switch (action) {
case C: case C:
getHibernateTemplate().save(command);break; getHibernateTemplate().save(command);break;
case U: case U:
getHibernateTemplate().update(command);break; getHibernateTemplate().update(command);break;
case R: case R:
AbstractModel model=getHibernateTemplate().get(command.getClass(), command.primaryKey()); T model=(T)(getHibernateTemplate().get(command.getClass(), command.primaryKey()));
if(model!=null){ if(model!=null){
return model.cast(); return model.cast();
} }
@ -40,12 +40,14 @@ public abstract class BaseService {
} }
public <T extends AbstractModel> List find(T command, int firstResult, int maxResults){ public List find(DetachedCriteria criteria, int firstResult, int maxResults){
return getHibernateTemplate().findByCriteria(command.getCriteria(),firstResult,maxResults); return getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults);
} }
public <T extends AbstractModel> Long rowCount(Class<T> tClass){
return getHibernateTemplate().executeWithNativeSession(session -> (Long) DetachedCriteria.forClass(tClass).setProjection(Projections.rowCount()).getExecutableCriteria(session).uniqueResult());
public Long rowCount(DetachedCriteria criteria){
return getHibernateTemplate().executeWithNativeSession(session -> (Long) criteria.setProjection(Projections.rowCount()).getExecutableCriteria(session).uniqueResult());
} }
} }

@ -1,12 +1,12 @@
package web.service; package web.service;
import core.service.BaseService;
import db.config.HibernateConfig; import db.config.HibernateConfig;
import db.model.AbstractModel;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class BiliService extends BaseService { public class BiliService<T extends AbstractModel> extends BaseService {
@Override @Override
protected HibernateTemplate getHibernateTemplate() { protected HibernateTemplate getHibernateTemplate() {
return HibernateConfig.get("test2"); return HibernateConfig.get("test2");

@ -1,6 +1,5 @@
package web.service; package web.service;
import core.service.BaseService;
import db.config.HibernateConfig; import db.config.HibernateConfig;
import db.model.bilibili.CidEntity; import db.model.bilibili.CidEntity;
import db.model.bilibili.DataModel; import db.model.bilibili.DataModel;

@ -2,10 +2,6 @@ package web.util;
import db.model.bilibili.ScheduledTaskEntity; import db.model.bilibili.ScheduledTaskEntity;
import db.model.bilibili.TaskEntity; import db.model.bilibili.TaskEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
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 org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
@ -16,7 +12,6 @@ import org.springframework.scheduling.support.CronTrigger;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date; import java.util.Date;
/** /**
@ -41,7 +36,7 @@ public class DynamicTimer extends ScheduledTaskRegistrar {
super.scheduleTriggerTask(new TriggerTask(()->{ super.scheduleTriggerTask(new TriggerTask(()->{
TaskEntity taskEntity=scheduledTaskEntity.getTaskEntity(); TaskEntity taskEntity=scheduledTaskEntity.getTaskEntity();
if(taskEntity!=null&&taskEntity.getApi()!=null&&!taskEntity.getApi().isEmpty()) { if(taskEntity!=null&&taskEntity.getApi()!=null&&!taskEntity.getApi().isEmpty()) {
doGet(taskEntity.getApi()); // doGet(taskEntity.getApi());
} }
},(TriggerContext triggerContext)->{ },(TriggerContext triggerContext)->{
CronTrigger trigger = new CronTrigger(scheduledTaskEntity.getExpression()); CronTrigger trigger = new CronTrigger(scheduledTaskEntity.getExpression());
@ -52,21 +47,5 @@ public class DynamicTimer extends ScheduledTaskRegistrar {
} }
/**
* httpclient get请求封装
* @param href
* @return
*/
private CloseableHttpResponse doGet(String href){
log.debug("向地址:"+href+"发送get请求");
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(href);
try {
return closeableHttpClient.execute(httpGet);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
} }

@ -1,3 +1,4 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- <%--
Created by IntelliJ IDEA. Created by IntelliJ IDEA.
User: 10295 User: 10295
@ -8,15 +9,23 @@
<%@ page pageEncoding="utf-8" %> <%@ page pageEncoding="utf-8" %>
<html> <html>
<head> <head>
<style>
.gold {
background: gold;
color: black;
margin-right: 5px;
}
</style>
<script id="form_tmpl" type="text/x-jquery-tmpl"> <script id="form_tmpl" type="text/x-jquery-tmpl">
<div class="jumbotron text-center"> <div class="jumbotron text-center">
<div class="h1">{{= title}}</div> <div class="h1">{{= title}}</div>
<div class="row-fluid"> <div class="col-auto">
{{each data}} {{each data}}
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" <button type="button" class="btn btn-info dropdown-toggle gold" data-toggle="dropdown"
aria-haspopup="true" aria-haspopup="true"
aria-expanded="false"> aria-expanded="false">
{{= $value.name}} {{= $value.name}}
@ -37,40 +46,67 @@
<div class="input-group justify-content-center"> <div class="input-group justify-content-center">
<div class="h3">筛选条件:</div> <div class="h3">筛选条件:</div>
<div class="input-group-prepend"> <div id="typeButton" class="input-group-prepend">
</div> </div>
</div> </div>
</br>
<div class="form-row justify-content-center">
<div class="col-auto">
<label class="sr-only" for="inlineFormInputGroup">Username</label>
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text">关键词</div>
</div>
<input type="text" class="form-control" name="title" <c:if test="${!empty command}"> value="${command.title}"</c:if>>
</div>
</div>
<div class="col-auto">
<button type="button" class="btn btn-secondary">查询</button>
</div>
</div>
</div> </div>
</script> </script>
<script id="form_btn_tmpl" type="text/x-jquery-tmpl"> <script id="form_btn_tmpl" type="text/x-jquery-tmpl">
<button type="button" class="btn btn-outline-info" >{{= title}}<i class="fas fa-times"></i></button> <button type="button" class="btn btn-outline-info" >{{= title}}<i class="fas fa-times" data-type="{{= type}}"></i></button>
</script> </script>
<script id="form_input_tmpl" type="text/x-jquery-tmpl"> <script id="form_input_tmpl" type="text/x-jquery-tmpl">
<input type="hidden" name="typeId" id="type{{= value}}" value="{{= value}}"/> <input type="hidden" name="typeIds" id="type{{= value}}" value="{{= value}}"/>
</script> </script>
<script> <script>
$(function () { $(function () {
regionJson =${regionJson}; regionJson =${regionJson};
$("#form_tmpl").tmpl({'title': '弹幕查询', 'data': regionJson}).appendTo('#queryForm'); $("#form_tmpl").tmpl({'title': '弹幕查询', 'data': regionJson}).appendTo('#queryDiv');
$(".dropdown-item").click(function () { $(".dropdown-item").click(function () {
$("#form_btn_tmpl").tmpl({'title':$(this).text()}).appendTo(".input-group-prepend"); $("#form_btn_tmpl").tmpl({'title': $(this).text(),'type':$(this).data("type")}).appendTo("#typeButton");
$(this).hide(); $(this).hide();
$("#form_input_tmpl").tmpl({'value':$(this).data("type")}).prependTo("#queryForm"); $("#form_input_tmpl").tmpl({
'value': $(this).data("type"),
'index': $("input[id^=type]").length
}).prependTo("#queryDiv");
}); });
$('.input-group-prepend').on('click','i',function () { $('.input-group-prepend').on('click', 'i', function () {
a=$('.dropdown-item:contains('+$(this).parent().text()+')');
a.show();
$(this).parent().remove(); $(this).parent().remove();
$("#type"+a.data("type")).remove(); $("#type" + $(this).data("type")).remove();
});
$(".btn-secondary").click(function () {
$("#pageForm").attr("action","/data/table?firstResult="+($(this).val()==''?0:$(this).val())+"&maxResults=${datas.pageSize}").submit();
}); });
}); });
@ -78,9 +114,9 @@
</head> </head>
<body> <body>
<form id="queryForm" action="/data/table"> <div id="queryDiv">
</form> </div>
</body> </body>
</html> </html>

@ -5,18 +5,6 @@
<%@ page pageEncoding="utf-8" %> <%@ page pageEncoding="utf-8" %>
<head> <head>
<c:import url="head.jsp"/> <c:import url="head.jsp"/>
<script>
$(function () {
$("#pageButton button").click(function () {
$("[name=firstResult]").val($(this).val());
$('#pageForm').submit();
});
});
</script>
</head> </head>
@ -24,37 +12,36 @@
<c:choose> <c:choose>
<c:when test="${datas.type=='success'}"> <c:when test="${datas.type=='success'}">
<c:import url="form.jsp"/> <form:form id="pageForm">
<table class="table"> <c:import url="form.jsp"/>
<thead>
<tr>
<th scope="col">cid</th>
<th scope="col">aid</th>
<th scope="col">title</th>
<th scope="col">subtitle</th>
<th scope="col">author</th>
</tr> <table class="table">
</thead> <thead>
<tbody>
<c:forEach items="${datas.datas}" var="data">
<tr> <tr>
<td>${data.cid}</td> <th scope="col">cid</th>
<td>${data.aid}</td> <th scope="col">aid</th>
<td>${data.title}</td> <th scope="col">title</th>
<td>${data.subtitle}</td> <th scope="col">subtitle</th>
<td>${data.author}</td> <th scope="col">author</th>
</tr> </tr>
</thead>
<tbody>
<c:forEach items="${datas.datas}" var="data">
<tr>
<td>${data.cid}</td>
<td>${data.aid}</td>
<td>${data.title}</td>
<td>${data.subtitle}</td>
<td>${data.author}</td>
</tr>
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<form:form id="pageForm" action="/data/table">
<input type="hidden" name="firstResult" value="0"/>
<input type="hidden" name="maxResults" value="${datas.pageSize}"/>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<p class="text-justify font-weight-bold"> <p class="text-justify font-weight-bold">
@ -70,14 +57,16 @@
<button value="${datas.currentPage-2}" type="button" class="btn btn-secondary" <button value="${datas.currentPage-2}" type="button" class="btn btn-secondary"
<c:if test="${datas.currentPage-2==-1}">disabled</c:if>>上一页 <c:if test="${datas.currentPage-2==-1}">disabled</c:if>>上一页
</button> </button>
<button value="${datas.currentPage}" type="button" class="btn btn-secondary">下一页</button> <button value="${datas.currentPage}" type="button" class="btn btn-secondary"
<button value="${datas.pages}" type="button" class="btn btn-secondary">尾页</button> <c:if test="${datas.currentPage==datas.pages}">disabled</c:if>>下一页
</button>
<button value="${datas.pages-1}" type="button" class="btn btn-secondary">尾页</button>
</div> </div>
<div class="btn-group mr-2" role="group"> <div class="btn-group mr-2" role="group">
<c:forEach begin="${datas.currentPage+1}" <c:forEach begin="${datas.currentPage+1}"
end="${datas.currentPage+9}" var="i"> end="${datas.currentPage+9}" var="i">
<c:if test="${i<=datas.pages}"> <c:if test="${i<=datas.pages-1}">
<button value="${i}" type="button" class="btn btn-secondary">${i}</button> <button value="${i}" type="button" class="btn btn-secondary">${i}</button>
</c:if> </c:if>
</c:forEach> </c:forEach>

@ -43,9 +43,9 @@ import java.util.List;
//让测试运行于Spring环境 //让测试运行于Spring环境
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig @SpringJUnitWebConfig
@ContextConfiguration(classes = {AppConfig.class,SpringConfig.class}) @ContextConfiguration(classes = {AppConfig.class, SpringConfig.class})
public class SpringTest { public class SpringTest {
private static Logger log = LogManager.getLogger(); private static Logger log = LogManager.getLogger();
private MockMvc mockMvc; private MockMvc mockMvc;
@ -64,14 +64,20 @@ public class SpringTest {
private HibernateTemplate baseDao1; private HibernateTemplate baseDao1;
@Before @Before
public void setup(){ public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
} }
@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")); ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/table").param("firstResult", "0").param("maxResults", "10").param("typeIds","123").param("typeIds","456"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
public void test2() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/R").param("cid","9987062"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn(); resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
} }

@ -1,3 +1,4 @@
import db.model.bilibili.DataModel;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -5,6 +6,8 @@ public class Test {
private static Logger log = LogManager.getLogger(); private static Logger log = LogManager.getLogger();
public static void main(String[] args) { public static void main(String[] args) {
DataModel dataModel=new DataModel();
dataModel.setTypeId(123);
log.info("哈哈"+dataModel);
} }
} }

@ -1,7 +1,5 @@
package db.model; package db.model;
import db.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@ -52,8 +50,4 @@ public class TaskModel extends AbstractModel {
return getId(); return getId();
} }
@Override
public String tableNote() {
return "测试表";
}
} }

@ -1,6 +1,6 @@
package web.controller; package web.controller;
import db.DBAction; import db.form.DBAction;
import db.model.TaskModel; import db.model.TaskModel;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class TestController extends BiliController<TaskModel>{ public class TestController extends BiliController<TaskModel>{
@Override @Override
public boolean checkAction(DBAction action) { public boolean checkAction(DBAction action) {
return true; return true;

Loading…
Cancel
Save