master
WuXianChaoPin 7 years ago
parent 7a28ff4209
commit 51e82d7d90
  1. 11
      core/pom.xml
  2. 4
      core/src/main/java/core/aop/Advisor.java
  3. 79
      core/src/main/java/core/config/HibernateConfig.java
  4. 9
      core/src/main/java/core/dao/BaseDao1.java
  5. 26
      core/src/main/java/core/dao/BaseDao2.java
  6. 6
      core/src/main/java/core/service/BaseService.java
  7. 63
      db/pom.xml
  8. 117
      db/src/main/java/db/config/HibernateConfig.java
  9. 30
      db/src/main/java/db/config/MyEmptyInterceptor.java
  10. 2
      db/src/main/java/db/model/AbstractModel.java
  11. 4
      db/src/main/java/db/model/CidEntity.java
  12. 373
      db/src/main/java/db/model/DataModel.java
  13. 4
      db/src/main/java/db/model/ScheduledTaskEntity.java
  14. 4
      db/src/main/java/db/model/TaskEntity.java
  15. 8
      pom.xml
  16. 5
      web/pom.xml
  17. 5
      web/src/main/java/web/config/AbstractWebConfig.java
  18. 14
      web/src/main/java/web/config/AppConfig.java
  19. 13
      web/src/main/java/web/config/SpringConfig.java
  20. 2
      web/src/main/java/web/controller/BaseController.java
  21. 10
      web/src/main/java/web/controller/CommentController.java
  22. 8
      web/src/main/java/web/util/DynamicTimer.java
  23. 18
      web/src/main/resources/config.properties
  24. 5
      web/src/main/resources/log4j2.xml
  25. 144
      web/src/test/java/SpringTest.java

@ -80,6 +80,17 @@
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>db</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>core</finalName> <finalName>core</finalName>

@ -1,6 +1,6 @@
package core.aop; package core.aop;
import core.dao.BaseDao; import core.dao.BaseDao1;
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;
@ -19,7 +19,7 @@ public class Advisor extends StaticMethodMatcherPointcutAdvisor {
@Override @Override
public boolean matches(Method method, Class<?> aClass) { public boolean matches(Method method, Class<?> aClass) {
return BaseDao.class.isAssignableFrom(aClass); return BaseDao1.class.isAssignableFrom(aClass);
} }
@PostConstruct @PostConstruct

@ -1,79 +0,0 @@
package core.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.Properties;
/**
* Created by reborn on 2017/7/28.
*/
@Configuration
@EnableTransactionManagement
public class HibernateConfig{
private Logger log=LogManager.getLogger();
@Value("${hibernate.dialect}")
private String dialect;
@Value("${hibernate.connection.driver_class}")
private String driver;
@Value("${hibernate.connection.url}")
private String url;
@Value("${hibernate.connection.username}")
private String username;
@Value("${hibernate.connection.password}")
private String password;
@Value("${sessionFactory.scan:web.model}")
private String packagesToScan[];
public static LocalSessionFactoryBean sessionFactoryBean;
private DruidDataSource druidDataSource(){
DruidDataSource dataSource=new DruidDataSource();
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(driver);
return dataSource;
}
@PostConstruct
private void init() throws IOException {
log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password);
sessionFactoryBean=new LocalSessionFactoryBean();
Properties properties=new Properties();
properties.setProperty("hibernate.dialect",dialect);
sessionFactoryBean.setHibernateProperties(properties);
sessionFactoryBean.setDataSource(druidDataSource());
sessionFactoryBean.setPackagesToScan(packagesToScan);
sessionFactoryBean.afterPropertiesSet();
}
@Bean
public SessionFactory sessionFactory(){
return sessionFactoryBean.getObject();
}
@Bean("transactionManager")
public HibernateTransactionManager hibernateTransactionManager() {
HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
hibernateTransactionManager.setSessionFactory(sessionFactory());
return hibernateTransactionManager;
}
}

@ -1,11 +1,12 @@
package core.dao; package core.dao;
import core.model.AbstractModel; import db.model.AbstractModel;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable; import java.io.Serializable;
@ -14,11 +15,11 @@ import java.io.Serializable;
*/ */
@Repository @Repository
public class BaseDao extends HibernateTemplate{ public class BaseDao1 extends HibernateTemplate{
@Autowired @Autowired
public BaseDao(SessionFactory sessionFactory) { public BaseDao1(SessionFactory aliyun) {
super(sessionFactory); super(aliyun);
} }
public <T extends AbstractModel> void delete(Class<T> tClass, Serializable key) throws DataAccessException { public <T extends AbstractModel> void delete(Class<T> tClass, Serializable key) throws DataAccessException {

@ -0,0 +1,26 @@
package core.dao;
import db.model.AbstractModel;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
@Repository
public class BaseDao2 extends HibernateTemplate {
@Autowired
public BaseDao2(SessionFactory huaWeiCloud) {
super(huaWeiCloud);
}
public <T extends AbstractModel> void delete(Class<T> tClass, Serializable key) throws DataAccessException {
T model = load(tClass, key);
if (model != null) {
delete(model);
}
}
}

@ -1,8 +1,8 @@
package core.service; package core.service;
import core.dao.BaseDao; import core.dao.BaseDao1;
import core.model.AbstractModel;
import core.util.DBAction; import core.util.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.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -18,7 +18,7 @@ public class BaseService {
protected Logger log=LogManager.getLogger(); protected Logger log=LogManager.getLogger();
@Resource @Resource
private BaseDao baseDao; private BaseDao1 baseDao;
public<T extends AbstractModel> String curd(DBAction action, T command) { public<T extends AbstractModel> String curd(DBAction action, T command) {
Class<T> tClass = (Class<T>) command.getClass(); Class<T> tClass = (Class<T>) command.getClass();

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>Webcrawler</artifactId>
<groupId>org.pqh</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>db</artifactId>
<packaging>jar</packaging>
<name>core Maven Webapp</name>
<url>https://gitee.com/WuXianChaoPin/webCrawler</url>
<dependencies>
<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>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,117 @@
package db.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;
/**
* Created by reborn on 2017/7/28.
*/
public class HibernateConfig{
private Logger log=LogManager.getLogger();
@Value("${hibernate.dialect}")
private String dialect;
@Value("${hibernate.connection.driver_class}")
private String driver;
@Value("${hibernate.connection.url}")
private String url;
@Value("${hibernate.connection.username}")
private String username;
@Value("${hibernate.connection.password}")
private String password;
@Value("${hibernate.connection.url2}")
private String url2;
@Value("${hibernate.connection.username2}")
private String username2;
@Value("${hibernate.connection.password2}")
private String password2;
@Value("${sessionFactory.scan}")
private String packagesToScan[];
private LocalSessionFactoryBean aliyun = new LocalSessionFactoryBean();
private LocalSessionFactoryBean huaWeiCloud = new LocalSessionFactoryBean();
private MyEmptyInterceptor interceptor =new MyEmptyInterceptor();
private DruidDataSource dataSource(String url,String username,String password){
DruidDataSource dataSource=new DruidDataSource();
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(driver);
log.info("数据源初始化\nurl="+url+"\nusername="+username+"\npassword="+password);
return dataSource;
}
@PostConstruct
private void init() {
initSessionFactory(aliyun,dataSource(url,username,password));
initSessionFactory(huaWeiCloud,dataSource(url2,username2,password2));
}
private void initSessionFactory(LocalSessionFactoryBean bean, DataSource dataSource){
Properties properties=new Properties();
properties.setProperty("hibernate.dialect",dialect);
properties.setProperty("hibernate.format_sql","true");
bean.setHibernateProperties(properties);
bean.setDataSource(dataSource);
bean.setPackagesToScan(packagesToScan);
bean.setEntityInterceptor(interceptor);
try {
bean.afterPropertiesSet();
} catch (IOException e) {
e.printStackTrace();
}
}
@Bean("aliyun")
public SessionFactory aliyun(){
return aliyun.getObject();
}
@Bean("huaWeiCloud")
public SessionFactory huaWeiCloud(){
return huaWeiCloud.getObject();
}
@Bean("transactionManager1")
public HibernateTransactionManager aliyunTransaction() {
HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
hibernateTransactionManager.setSessionFactory(aliyun());
return hibernateTransactionManager;
}
@Bean("transactionManager2")
public HibernateTransactionManager huaweiTransaction() {
HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
hibernateTransactionManager.setSessionFactory(huaWeiCloud());
return hibernateTransactionManager;
}
}

@ -0,0 +1,30 @@
package db.config;
import db.model.DataModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
import java.io.Serializable;
public class MyEmptyInterceptor extends EmptyInterceptor {
private Logger log=LogManager.getLogger();
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
if(entity instanceof DataModel){
DataModel dataModel= (DataModel) entity;
log.info(dataModel);
}
return true;
}
@Override
public String onPrepareStatement(String sql) {
// log.info(sql);
return super.onPrepareStatement(sql);
}
}

@ -1,4 +1,4 @@
package core.model; package db.model;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;

@ -1,6 +1,4 @@
package web.model; package db.model;
import core.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;

@ -1,6 +1,4 @@
package web.model; package db.model;
import core.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -8,37 +6,37 @@ import java.util.Objects;
@Entity @Entity
@Table(name = "data", schema = "bilibili", catalog = "") @Table(name = "data", schema = "bilibili", catalog = "")
public class DataEntity extends AbstractModel { public class DataModel extends AbstractModel {
private int cid; private int cid;
private Integer aid; private Integer aid;
private Byte dpDoneMp4;
private String letvVu;
private Byte dpDoneFlv;
private Integer uploadMeta;
private String type;
private Integer vp;
private Integer upload;
private String author; private String author;
private String backupVid;
private String cache;
private String cover; private String cover;
private String title;
private Integer page;
private Integer dispatch; private Integer dispatch;
private String vid;
private String backupVid;
private Integer files;
private Integer dispatchServers; private Integer dispatchServers;
private String cache;
private Integer storageServer;
private Byte dpDone; private Byte dpDone;
private Double duration; private Byte dpDoneFlv;
private Integer mid;
private Byte dpDoneHdmp4; private Byte dpDoneHdmp4;
private Byte dpDoneMp4;
private Double duration;
private Integer files;
private String letvAddr;
private Integer letvVid; private Integer letvVid;
private String letvVu;
private Integer mid;
private Integer page;
private Integer storage; private Integer storage;
private String letvAddr; private Integer storageServer;
private String subtitle; private String subtitle;
private String title;
private String type;
private Integer upload;
private Integer uploadMeta;
private String vid;
private Integer vp;
private Integer typeId;
private CidEntity cidEntity;
@Id @Id
@Column(name = "cid") @Column(name = "cid")
public int getCid() { public int getCid() {
@ -60,173 +58,183 @@ public class DataEntity extends AbstractModel {
} }
@Basic @Basic
@Column(name = "dp_done_mp4") @Column(name = "author")
public Byte getDpDoneMp4() { public String getAuthor() {
return dpDoneMp4; return author;
} }
public void setDpDoneMp4(Byte dpDoneMp4) { public void setAuthor(String author) {
this.dpDoneMp4 = dpDoneMp4; this.author = author;
} }
@Basic @Basic
@Column(name = "letv_vu") @Column(name = "backup_vid")
public String getLetvVu() { public String getBackupVid() {
return letvVu; return backupVid;
} }
public void setLetvVu(String letvVu) { public void setBackupVid(String backupVid) {
this.letvVu = letvVu; this.backupVid = backupVid;
} }
@Basic @Basic
@Column(name = "dp_done_flv") @Column(name = "cache")
public Byte getDpDoneFlv() { public String getCache() {
return dpDoneFlv; return cache;
} }
public void setDpDoneFlv(Byte dpDoneFlv) { public void setCache(String cache) {
this.dpDoneFlv = dpDoneFlv; this.cache = cache;
} }
@Basic @Basic
@Column(name = "upload_meta") @Column(name = "cover")
public Integer getUploadMeta() { public String getCover() {
return uploadMeta; return cover;
} }
public void setUploadMeta(Integer uploadMeta) { public void setCover(String cover) {
this.uploadMeta = uploadMeta; this.cover = cover;
} }
@Basic @Basic
@Column(name = "type") @Column(name = "dispatch")
public String getType() { public Integer getDispatch() {
return type; return dispatch;
} }
public void setType(String type) { public void setDispatch(Integer dispatch) {
this.type = type; this.dispatch = dispatch;
} }
@Basic @Basic
@Column(name = "vp") @Column(name = "dispatch_servers")
public Integer getVp() { public Integer getDispatchServers() {
return vp; return dispatchServers;
} }
public void setVp(Integer vp) { public void setDispatchServers(Integer dispatchServers) {
this.vp = vp; this.dispatchServers = dispatchServers;
} }
@Basic @Basic
@Column(name = "upload") @Column(name = "dp_done")
public Integer getUpload() { public Byte getDpDone() {
return upload; return dpDone;
} }
public void setUpload(Integer upload) { public void setDpDone(Byte dpDone) {
this.upload = upload; this.dpDone = dpDone;
} }
@Basic @Basic
@Column(name = "author") @Column(name = "dp_done_flv")
public String getAuthor() { public Byte getDpDoneFlv() {
return author; return dpDoneFlv;
} }
public void setAuthor(String author) { public void setDpDoneFlv(Byte dpDoneFlv) {
this.author = author; this.dpDoneFlv = dpDoneFlv;
} }
@Basic @Basic
@Column(name = "cover") @Column(name = "dp_done_hdmp4")
public String getCover() { public Byte getDpDoneHdmp4() {
return cover; return dpDoneHdmp4;
} }
public void setCover(String cover) { public void setDpDoneHdmp4(Byte dpDoneHdmp4) {
this.cover = cover; this.dpDoneHdmp4 = dpDoneHdmp4;
} }
@Basic @Basic
@Column(name = "title") @Column(name = "dp_done_mp4")
public String getTitle() { public Byte getDpDoneMp4() {
return title; return dpDoneMp4;
} }
public void setTitle(String title) { public void setDpDoneMp4(Byte dpDoneMp4) {
this.title = title; this.dpDoneMp4 = dpDoneMp4;
} }
@Basic @Basic
@Column(name = "page") @Column(name = "duration")
public Integer getPage() { public Double getDuration() {
return page; return duration;
} }
public void setPage(Integer page) { public void setDuration(Double duration) {
this.page = page; this.duration = duration;
} }
@Basic @Basic
@Column(name = "dispatch") @Column(name = "files")
public Integer getDispatch() { public Integer getFiles() {
return dispatch; return files;
} }
public void setDispatch(Integer dispatch) { public void setFiles(Integer files) {
this.dispatch = dispatch; this.files = files;
} }
@Basic @Basic
@Column(name = "vid") @Column(name = "letv_addr")
public String getVid() { public String getLetvAddr() {
return vid; return letvAddr;
} }
public void setVid(String vid) { public void setLetvAddr(String letvAddr) {
this.vid = vid; this.letvAddr = letvAddr;
} }
@Basic @Basic
@Column(name = "backup_vid") @Column(name = "letv_vid")
public String getBackupVid() { public Integer getLetvVid() {
return backupVid; return letvVid;
} }
public void setBackupVid(String backupVid) { public void setLetvVid(Integer letvVid) {
this.backupVid = backupVid; this.letvVid = letvVid;
} }
@Basic @Basic
@Column(name = "files") @Column(name = "letv_vu")
public Integer getFiles() { public String getLetvVu() {
return files; return letvVu;
} }
public void setFiles(Integer files) { public void setLetvVu(String letvVu) {
this.files = files; this.letvVu = letvVu;
} }
@Basic @Basic
@Column(name = "dispatch_servers") @Column(name = "mid")
public Integer getDispatchServers() { public Integer getMid() {
return dispatchServers; return mid;
} }
public void setDispatchServers(Integer dispatchServers) { public void setMid(Integer mid) {
this.dispatchServers = dispatchServers; this.mid = mid;
} }
@Basic @Basic
@Column(name = "cache") @Column(name = "page")
public String getCache() { public Integer getPage() {
return cache; return page;
} }
public void setCache(String cache) { public void setPage(Integer page) {
this.cache = cache; this.page = page;
}
@Basic
@Column(name = "storage")
public Integer getStorage() {
return storage;
}
public void setStorage(Integer storage) {
this.storage = storage;
} }
@Basic @Basic
@ -240,134 +248,125 @@ public class DataEntity extends AbstractModel {
} }
@Basic @Basic
@Column(name = "dp_done") @Column(name = "subtitle")
public Byte getDpDone() { public String getSubtitle() {
return dpDone; return subtitle;
} }
public void setDpDone(Byte dpDone) { public void setSubtitle(String subtitle) {
this.dpDone = dpDone; this.subtitle = subtitle;
} }
@Basic @Basic
@Column(name = "duration") @Column(name = "title")
public Double getDuration() { public String getTitle() {
return duration; return title;
} }
public void setDuration(Double duration) { public void setTitle(String title) {
this.duration = duration; this.title = title;
} }
@Basic @Basic
@Column(name = "mid") @Column(name = "type")
public Integer getMid() { public String getType() {
return mid; return type;
} }
public void setMid(Integer mid) { public void setType(String type) {
this.mid = mid; this.type = type;
} }
@Basic @Basic
@Column(name = "dp_done_hdmp4") @Column(name = "upload")
public Byte getDpDoneHdmp4() { public Integer getUpload() {
return dpDoneHdmp4; return upload;
} }
public void setDpDoneHdmp4(Byte dpDoneHdmp4) { public void setUpload(Integer upload) {
this.dpDoneHdmp4 = dpDoneHdmp4; this.upload = upload;
} }
@Basic @Basic
@Column(name = "letv_vid") @Column(name = "upload_meta")
public Integer getLetvVid() { public Integer getUploadMeta() {
return letvVid; return uploadMeta;
} }
public void setLetvVid(Integer letvVid) { public void setUploadMeta(Integer uploadMeta) {
this.letvVid = letvVid; this.uploadMeta = uploadMeta;
} }
@Basic @Basic
@Column(name = "storage") @Column(name = "vid")
public Integer getStorage() { public String getVid() {
return storage; return vid;
} }
public void setStorage(Integer storage) { public void setVid(String vid) {
this.storage = storage; this.vid = vid;
} }
@Basic @Basic
@Column(name = "letv_addr") @Column(name = "vp")
public String getLetvAddr() { public Integer getVp() {
return letvAddr; return vp;
} }
public void setLetvAddr(String letvAddr) { public void setVp(Integer vp) {
this.letvAddr = letvAddr; this.vp = vp;
} }
@Basic @Basic
@Column(name = "subtitle") @Column(name = "type_id")
public String getSubtitle() { public Integer getTypeId() {
return subtitle; return typeId;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
@OneToOne
@JoinColumn(name = "cid")
public CidEntity getCidEntity() {
return cidEntity;
} }
public void setCidEntity(CidEntity cidEntity) { public void setTypeId(Integer typeId) {
this.cidEntity = cidEntity; this.typeId = typeId;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
DataEntity that = (DataEntity) o; DataModel dataModel = (DataModel) o;
return cid == that.cid && return cid == dataModel.cid &&
Objects.equals(aid, that.aid) && Objects.equals(aid, dataModel.aid) &&
Objects.equals(dpDoneMp4, that.dpDoneMp4) && Objects.equals(author, dataModel.author) &&
Objects.equals(letvVu, that.letvVu) && Objects.equals(backupVid, dataModel.backupVid) &&
Objects.equals(dpDoneFlv, that.dpDoneFlv) && Objects.equals(cache, dataModel.cache) &&
Objects.equals(uploadMeta, that.uploadMeta) && Objects.equals(cover, dataModel.cover) &&
Objects.equals(type, that.type) && Objects.equals(dispatch, dataModel.dispatch) &&
Objects.equals(vp, that.vp) && Objects.equals(dispatchServers, dataModel.dispatchServers) &&
Objects.equals(upload, that.upload) && Objects.equals(dpDone, dataModel.dpDone) &&
Objects.equals(author, that.author) && Objects.equals(dpDoneFlv, dataModel.dpDoneFlv) &&
Objects.equals(cover, that.cover) && Objects.equals(dpDoneHdmp4, dataModel.dpDoneHdmp4) &&
Objects.equals(title, that.title) && Objects.equals(dpDoneMp4, dataModel.dpDoneMp4) &&
Objects.equals(page, that.page) && Objects.equals(duration, dataModel.duration) &&
Objects.equals(dispatch, that.dispatch) && Objects.equals(files, dataModel.files) &&
Objects.equals(vid, that.vid) && Objects.equals(letvAddr, dataModel.letvAddr) &&
Objects.equals(backupVid, that.backupVid) && Objects.equals(letvVid, dataModel.letvVid) &&
Objects.equals(files, that.files) && Objects.equals(letvVu, dataModel.letvVu) &&
Objects.equals(dispatchServers, that.dispatchServers) && Objects.equals(mid, dataModel.mid) &&
Objects.equals(cache, that.cache) && Objects.equals(page, dataModel.page) &&
Objects.equals(storageServer, that.storageServer) && Objects.equals(storage, dataModel.storage) &&
Objects.equals(dpDone, that.dpDone) && Objects.equals(storageServer, dataModel.storageServer) &&
Objects.equals(duration, that.duration) && Objects.equals(subtitle, dataModel.subtitle) &&
Objects.equals(mid, that.mid) && Objects.equals(title, dataModel.title) &&
Objects.equals(dpDoneHdmp4, that.dpDoneHdmp4) && Objects.equals(type, dataModel.type) &&
Objects.equals(letvVid, that.letvVid) && Objects.equals(upload, dataModel.upload) &&
Objects.equals(storage, that.storage) && Objects.equals(uploadMeta, dataModel.uploadMeta) &&
Objects.equals(letvAddr, that.letvAddr) && Objects.equals(vid, dataModel.vid) &&
Objects.equals(subtitle, that.subtitle); Objects.equals(vp, dataModel.vp) &&
Objects.equals(typeId, dataModel.typeId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(cid, aid, dpDoneMp4, letvVu, dpDoneFlv, uploadMeta, type, vp, upload, author, cover, title, page, dispatch, vid, backupVid, files, dispatchServers, cache, storageServer, dpDone, duration, mid, dpDoneHdmp4, letvVid, storage, letvAddr, subtitle); return Objects.hash(cid, aid, author, backupVid, cache, cover, dispatch, dispatchServers, dpDone, dpDoneFlv, dpDoneHdmp4, dpDoneMp4, duration, files, letvAddr, letvVid, letvVu, mid, page, storage, storageServer, subtitle, title, type, upload, uploadMeta, vid, vp, typeId);
} }
@Override @Override

@ -1,6 +1,4 @@
package web.model; package db.model;
import core.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;

@ -1,6 +1,4 @@
package web.model; package db.model;
import core.model.AbstractModel;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;

@ -8,6 +8,7 @@
<modules> <modules>
<module>core</module> <module>core</module>
<module>web</module> <module>web</module>
<module>db</module>
</modules> </modules>
<name>Webcrawler Maven Webapp</name> <name>Webcrawler Maven Webapp</name>
<url>https://gitee.com/WuXianChaoPin/WebCrawler</url> <url>https://gitee.com/WuXianChaoPin/WebCrawler</url>
@ -26,6 +27,7 @@
<log4j.version>RELEASE</log4j.version> <log4j.version>RELEASE</log4j.version>
<commons-io.version>RELEASE</commons-io.version> <commons-io.version>RELEASE</commons-io.version>
<druid.version>RELEASE</druid.version> <druid.version>RELEASE</druid.version>
<lang3.version>RELEASE</lang3.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -108,6 +110,12 @@
<version>${druid.version}</version> <version>${druid.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${lang3.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

@ -87,11 +87,6 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>

@ -23,7 +23,7 @@ public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServlet
@Override @Override
protected Class<?>[] getRootConfigClasses() { protected Class<?>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class}; return new Class[]{AppConfig.class};
} }
@Override @Override
@ -39,9 +39,6 @@ public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServlet
FilterRegistration.Dynamic characterEncodingFilter=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding)); FilterRegistration.Dynamic characterEncodingFilter=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding));
characterEncodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*"); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
FilterRegistration.Dynamic openSessionInViewFilter=super.registerServletFilter(servletContext,new OpenSessionInViewFilter());
openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
ServletRegistration.Dynamic servlet=servletContext.addServlet("DruidStatView", StatViewServlet.class); ServletRegistration.Dynamic servlet=servletContext.addServlet("DruidStatView", StatViewServlet.class);
servlet.addMapping("/druid/*"); servlet.addMapping("/druid/*");

@ -0,0 +1,14 @@
package web.config;
import db.config.HibernateConfig;
import org.springframework.context.annotation.*;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement
@PropertySource("classpath:config.properties")
@ComponentScan({"core"})
@Import(HibernateConfig.class)
public class AppConfig {
}

@ -1,7 +1,8 @@
package web.config; package web.config;
import core.config.HibernateConfig; import core.dao.BaseDao1;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor; import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
@ -10,16 +11,20 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
/** /**
* Created by reborn on 2017/7/28. * Created by reborn on 2017/7/28.
*/ */
@Configuration
@EnableWebMvc @EnableWebMvc
@PropertySource("classpath:config.properties") @PropertySource("classpath:config.properties")
@ComponentScan({"${spring.scan}"}) @ComponentScan({"web.controller"})
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SpringConfig implements WebMvcConfigurer { public class SpringConfig implements WebMvcConfigurer {
@Resource
private BaseDao1 baseDao;
@Override @Override
public void configureViewResolvers(ViewResolverRegistry registry) { public void configureViewResolvers(ViewResolverRegistry registry) {
@ -30,7 +35,7 @@ public class SpringConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
OpenSessionInViewInterceptor interceptor=new OpenSessionInViewInterceptor(); OpenSessionInViewInterceptor interceptor=new OpenSessionInViewInterceptor();
interceptor.setSessionFactory(HibernateConfig.sessionFactoryBean.getObject()); interceptor.setSessionFactory(baseDao.getSessionFactory());
registry.addWebRequestInterceptor(interceptor); registry.addWebRequestInterceptor(interceptor);
} }
} }

@ -1,8 +1,8 @@
package web.controller; package web.controller;
import core.model.AbstractModel;
import core.service.BaseService; import core.service.BaseService;
import core.util.DBAction; import core.util.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.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;

@ -1,17 +1,11 @@
package web.controller; package web.controller;
import db.model.DataModel;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import web.model.DataEntity;
@Controller @Controller
@RequestMapping("/comment") @RequestMapping("/comment")
public class CommentController extends BaseController<DataEntity>{ public class CommentController extends BaseController<DataModel>{
@RequestMapping(value = "find",produces = "application/json;charset=UTF-8")
public String get(DataEntity dataEntity){
return "";
}
} }

@ -1,6 +1,8 @@
package web.util; package web.util;
import core.dao.BaseDao; import core.dao.BaseDao1;
import db.model.ScheduledTaskEntity;
import db.model.TaskEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@ -12,8 +14,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.TriggerTask; import org.springframework.scheduling.config.TriggerTask;
import org.springframework.scheduling.support.CronTrigger; import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import web.model.ScheduledTaskEntity;
import web.model.TaskEntity;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -30,7 +30,7 @@ public class DynamicTimer extends ScheduledTaskRegistrar {
private Logger log=LogManager.getLogger(); private Logger log=LogManager.getLogger();
@Resource @Resource
private BaseDao baseDao; private BaseDao1 baseDao;
@PostConstruct @PostConstruct
public void init(){ public void init(){

@ -1,16 +1,16 @@
#-----------------------hibernate配置----------------------------- #-----------------------hibernate\u914D\u7F6E-----------------------------
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.connection.url=jdbc:mysql://mikuhime.xyz:3306/bilibili?serverTimezone=UTC #\u6570\u636E\u6E901
hibernate.connection.url=jdbc:mysql://sukura.top:3306/bilibili?serverTimezone=UTC&useSSL=false
hibernate.connection.username=sukura hibernate.connection.username=sukura
hibernate.connection.password=@ hibernate.connection.password=@
#数据源2 #\u6570\u636E\u6E902
hibernate.dialect2=org.hibernate.dialect.MySQL57Dialect hibernate.connection.url2=jdbc:mysql://mysql.sukura.top:8635/bilibili?serverTimezone=UTC&useSSL=false
hibernate.connection.driver_class2=com.mysql.cj.jdbc.Driver
hibernate.connection.url2=jdbc:mysql://mikuhime.xyz:3306/bilibili?serverTimezone=UTC
hibernate.connection.username2=sukura hibernate.connection.username2=sukura
hibernate.connection.password2=@ hibernate.connection.password2=Luffy9412!
#-----------------------DruidDataSource配置----------------------- #-----------------------DruidDataSource\u914D\u7F6E-----------------------
druid.maxActive=20 druid.maxActive=20
spring.scan=core,web spring.scan=core,web,db
sessionFactory.scan=db.model

@ -16,9 +16,12 @@
</Appenders> </Appenders>
<Loggers> <Loggers>
<Logger name="test1" level="debug" additivity="false"> <Logger name="test1" level="TRACE" additivity="false">
<AppenderRef ref="STDOUT"/> <AppenderRef ref="STDOUT"/>
</Logger> </Logger>
<!--<Logger name="org.hibernate.SQL" level="debug" additivity="false">-->
<!--<AppenderRef ref="STDOUT"/>-->
<!--</Logger>-->
<Logger name="test2" level="debug" additivity="false"> <Logger name="test2" level="debug" additivity="false">
<AppenderRef ref="File_debug"/> <AppenderRef ref="File_debug"/>
</Logger> </Logger>

@ -0,0 +1,144 @@
import core.dao.BaseDao1;
import core.dao.BaseDao2;
import db.model.CidEntity;
import db.model.DataModel;
import db.model.TaskEntity;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import web.config.AppConfig;
import web.config.SpringConfig;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
//让测试运行于Spring环境
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig
@ContextConfiguration(classes = {AppConfig.class})
public class SpringTest {
private Logger log=LogManager.getLogger();
@Resource
private BaseDao1 baseDao1;
@Resource
private BaseDao2 baseDao2;
@Test
@Transactional("transactionManager2")
@Rollback(false)
public void test1(){
DataModel dataModel=new DataModel();
dataModel.setCid(333);
TaskEntity taskEntity=new TaskEntity();
taskEntity.setApi("fdsfsdf");
baseDao2.save(dataModel);
}
@Test
@Transactional("transactionManager2")
@Rollback(false)
public void test(){
// for (int id=1;id<10;id++){
int id=103;
DataModel dataModel=baseDao1.get(DataModel.class,id);
CidEntity cidEntity=baseDao1.get(CidEntity.class,id);
if(dataModel!=null&&cidEntity!=null){
dataModel.setTypeId(cidEntity.getTypeid());
try {
log.info(baseDao2.save(dataModel));
}catch (DataAccessException e){
log.error(e);
}
}
// }
}
// @Test
public void exportTableSql(){
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(baseDao1.getSessionFactory().getProperties()).build();
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(DataModel.class).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile("test.sql");
schemaExport.setFormat(true);
schemaExport.create(EnumSet.of(TargetType.SCRIPT), metadata);
List<Integer> typeid= (List<Integer>) baseDao1.findByCriteria(DetachedCriteria.forClass(CidEntity.class).setProjection(Projections.groupProperty("typeid")));
List<String> tableNames=new ArrayList<>();
StringBuffer sb=new StringBuffer();
for(Integer id:typeid){
String tableName="data_"+id;
sb.append("create table "+tableName+" like data_1;\n");
tableNames.add(tableName);
}
sb.append("create table data (\n" +
" cid integer not null,\n" +
" aid integer,\n" +
" author varchar(255),\n" +
" backup_vid varchar(255),\n" +
" cache varchar(255),\n" +
" cover varchar(255),\n" +
" dispatch integer,\n" +
" dispatch_servers integer,\n" +
" dp_done tinyint,\n" +
" dp_done_flv tinyint,\n" +
" dp_done_hdmp4 tinyint,\n" +
" dp_done_mp4 tinyint,\n" +
" duration double precision,\n" +
" files integer,\n" +
" letv_addr varchar(255),\n" +
" letv_vid integer,\n" +
" letv_vu varchar(255),\n" +
" mid integer,\n" +
" page integer,\n" +
" storage integer,\n" +
" storage_server integer,\n" +
" subtitle varchar(255),\n" +
" title varchar(255),\n" +
" type varchar(255),\n" +
" upload integer,\n" +
" upload_meta integer,\n" +
" vid varchar(255),\n" +
" vp integer,\n" +
" type_id integer,\n" +
" primary key (cid)\n" +
" ) engine=MERGE UNION=("+StringUtils.join(tableNames,",")+") insert_method=no;");
try {
FileUtils.writeStringToFile(new File("test.sql"),sb.toString(),"utf-8",true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save