34 changed files with 3261 additions and 12 deletions
@ -0,0 +1 @@ |
|||||
|
调度系统 |
||||
@ -0,0 +1,177 @@ |
|||||
|
<?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>common</artifactId> |
||||
|
<groupId>com.ccsens</groupId> |
||||
|
<version>1.0-SNAPSHOT</version> |
||||
|
</parent> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<artifactId>scheduler</artifactId> |
||||
|
|
||||
|
<dependencies> |
||||
|
<!--任务调度相关依赖--> |
||||
|
<dependency> |
||||
|
<groupId>org.quartz-scheduler</groupId> |
||||
|
<artifactId>quartz</artifactId> |
||||
|
<version>2.3.2</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.quartz-scheduler</groupId> |
||||
|
<artifactId>quartz-jobs</artifactId> |
||||
|
<version>2.3.2</version> |
||||
|
</dependency> |
||||
|
<!-- spring Redis--> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- spring RabbitMQ--> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-amqp</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- spring MongoDB--> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-data-mongodb</artifactId> |
||||
|
</dependency> |
||||
|
<!-- 自动重连--> |
||||
|
<dependency> |
||||
|
<groupId>com.spring4all</groupId> |
||||
|
<artifactId>mongodb-plus-spring-boot-starter</artifactId> |
||||
|
<version>1.0.0.RELEASE</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- spring MyBatis --> |
||||
|
<dependency> |
||||
|
<groupId>org.mybatis.spring.boot</groupId> |
||||
|
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||
|
<version>1.1.1</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--jfinal enjoy 模板引擎--> |
||||
|
<dependency> |
||||
|
<groupId>com.jfinal</groupId> |
||||
|
<artifactId>enjoy</artifactId> |
||||
|
<version>4.7</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- mybatis pagehelper包--> |
||||
|
<dependency> |
||||
|
<groupId>com.github.pagehelper</groupId> |
||||
|
<artifactId>pagehelper</artifactId> |
||||
|
<version>4.1.4</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--mybatis generator包--> |
||||
|
<dependency> |
||||
|
<groupId>org.mybatis.generator</groupId> |
||||
|
<artifactId>mybatis-generator-core</artifactId> |
||||
|
<version>1.3.7</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- MySQL数据库 --> |
||||
|
<dependency> |
||||
|
<groupId>mysql</groupId> |
||||
|
<artifactId>mysql-connector-java</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--Durid数据源--> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba</groupId> |
||||
|
<artifactId>druid</artifactId> |
||||
|
<version>1.1.10</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- hutool-all --> |
||||
|
<dependency> |
||||
|
<groupId>cn.hutool</groupId> |
||||
|
<artifactId>hutool-all</artifactId> |
||||
|
<version>4.1.21</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--jjwt--> |
||||
|
<dependency> |
||||
|
<groupId>io.jsonwebtoken</groupId> |
||||
|
<artifactId>jjwt</artifactId> |
||||
|
<version>0.7.0</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--Jackson Xml--> |
||||
|
<dependency> |
||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId> |
||||
|
<artifactId>jackson-dataformat-xml</artifactId> |
||||
|
<version>2.9.0</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<dependency> |
||||
|
<groupId>com.jayway.jsonpath</groupId> |
||||
|
<artifactId>json-path</artifactId> |
||||
|
<version>2.4.0</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--Shiro --> |
||||
|
<dependency> |
||||
|
<groupId>org.apache.shiro</groupId> |
||||
|
<artifactId>shiro-spring</artifactId> |
||||
|
<version>1.4.0</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--Swagger --> |
||||
|
<dependency> |
||||
|
<groupId>io.springfox</groupId> |
||||
|
<artifactId>springfox-swagger2</artifactId> |
||||
|
<version>2.9.2</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>io.springfox</groupId> |
||||
|
<artifactId>springfox-swagger-ui</artifactId> |
||||
|
<version>2.9.2</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> |
||||
|
<dependency> |
||||
|
<groupId>org.projectlombok</groupId> |
||||
|
<artifactId>lombok</artifactId> |
||||
|
<version>1.18.2</version> |
||||
|
<scope>provided</scope> |
||||
|
</dependency> |
||||
|
|
||||
|
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> |
||||
|
<dependency> |
||||
|
<groupId>org.apache.httpcomponents</groupId> |
||||
|
<artifactId>httpclient</artifactId> |
||||
|
<version>4.3.1</version> |
||||
|
</dependency> |
||||
|
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> |
||||
|
<dependency> |
||||
|
<groupId>org.apache.httpcomponents</groupId> |
||||
|
<artifactId>httpcore</artifactId> |
||||
|
<version>4.3.1</version> |
||||
|
</dependency> |
||||
|
<!-- https://mvnrepository.com/artifact/io.netty/netty-all --> |
||||
|
<dependency> |
||||
|
<groupId>io.netty</groupId> |
||||
|
<artifactId>netty-all</artifactId> |
||||
|
<version>4.1.32.Final</version> |
||||
|
</dependency> |
||||
|
|
||||
|
<!--Poi Excel --> |
||||
|
<dependency> |
||||
|
<groupId>org.apache.poi</groupId> |
||||
|
<artifactId>poi</artifactId> |
||||
|
<version>3.17</version> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>org.apache.poi</groupId> |
||||
|
<artifactId>poi-ooxml</artifactId> |
||||
|
<version>3.17</version> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
|
||||
|
</project> |
||||
@ -0,0 +1,9 @@ |
|||||
|
package com.ccsens.scheduler; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: whj |
||||
|
* @time: 2021/2/20 17:39 |
||||
|
*/ |
||||
|
public class SchedulerApplication { |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import com.ccsens.scheduler.intercept.MybatisInterceptor; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: wuHuiJuan |
||||
|
* @create: 2019/12/03 18:01 |
||||
|
*/ |
||||
|
@Configuration |
||||
|
public class BeanConfig { |
||||
|
|
||||
|
/** |
||||
|
* 注册拦截器 |
||||
|
*/ |
||||
|
@Bean |
||||
|
public MybatisInterceptor mybatisInterceptor() { |
||||
|
MybatisInterceptor interceptor = new MybatisInterceptor(); |
||||
|
return interceptor; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import com.ccsens.scheduler.exception.BaseException; |
||||
|
import com.ccsens.scheduler.util.CodeEnum; |
||||
|
import com.ccsens.scheduler.util.JsonResponse; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.http.converter.HttpMessageNotReadableException; |
||||
|
import org.springframework.validation.BindException; |
||||
|
import org.springframework.validation.BindingResult; |
||||
|
import org.springframework.validation.FieldError; |
||||
|
import org.springframework.web.bind.MethodArgumentNotValidException; |
||||
|
import org.springframework.web.bind.annotation.ControllerAdvice; |
||||
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
|
||||
|
/** |
||||
|
* @author wu |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@ControllerAdvice |
||||
|
public class ControllerExceptionHandler { |
||||
|
|
||||
|
|
||||
|
@ExceptionHandler(value = MethodArgumentNotValidException.class) |
||||
|
@ResponseBody |
||||
|
public JsonResponse validateExceptionHandler(MethodArgumentNotValidException e){ |
||||
|
BindingResult bindingResult = e.getBindingResult(); |
||||
|
log.error("MethodArgumentNotValidException",e); |
||||
|
return JsonResponse.newInstance().fail(CodeEnum.PARAM_NULL.getCode(),bindingResult.getFieldError().getDefaultMessage()); |
||||
|
} |
||||
|
|
||||
|
@ExceptionHandler(value = BindException.class) |
||||
|
@ResponseBody |
||||
|
public JsonResponse handleBindException(BindException e) { |
||||
|
// ex.getFieldError():随机返回一个对象属性的异常信息。如果要一次性返回所有对象属性异常信息,则调用ex.getAllErrors()
|
||||
|
FieldError fieldError = e.getFieldError(); |
||||
|
StringBuilder sb = new StringBuilder(); |
||||
|
sb.append(fieldError.getField()).append("=[").append(fieldError.getRejectedValue()).append("]") |
||||
|
.append(fieldError.getDefaultMessage()); |
||||
|
e.printStackTrace(); |
||||
|
log.error("BindException", e); |
||||
|
return JsonResponse.newInstance().fail(-11,sb.toString()); |
||||
|
} |
||||
|
|
||||
|
@ExceptionHandler(value = HttpMessageNotReadableException.class) |
||||
|
@ResponseBody |
||||
|
public JsonResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { |
||||
|
e.printStackTrace(); |
||||
|
log.error("HttpMessageNotReadableException", e); |
||||
|
return JsonResponse.newInstance().fail(-12,e.getMessage()); |
||||
|
} |
||||
|
|
||||
|
@ExceptionHandler(value = BaseException.class) |
||||
|
@ResponseBody |
||||
|
public JsonResponse jsonBaseExceptionHandler(HttpServletRequest req, BaseException e) { |
||||
|
e.printStackTrace(); |
||||
|
log.error("BaseException",e); |
||||
|
if (e.getCodeEnum() != null) { |
||||
|
return JsonResponse.newInstance().ok(e.getCodeEnum()); |
||||
|
} |
||||
|
return JsonResponse.newInstance().fail(e.getCode(),e.getMessage()); |
||||
|
} |
||||
|
|
||||
|
@ExceptionHandler(value = Exception.class) |
||||
|
@ResponseBody |
||||
|
public JsonResponse jsonExceptionHandler(HttpServletRequest req, Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
log.error("Exception",e); |
||||
|
return JsonResponse.newInstance().fail(-1,e.getMessage()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,382 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import cn.hutool.core.codec.Base64; |
||||
|
import cn.hutool.core.util.CharsetUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import cn.hutool.crypto.symmetric.SymmetricAlgorithm; |
||||
|
import cn.hutool.crypto.symmetric.SymmetricCrypto; |
||||
|
import com.alibaba.druid.pool.DruidDataSource; |
||||
|
import com.ccsens.scheduler.util.Constant; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.context.annotation.PropertySource; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.sql.SQLException; |
||||
|
|
||||
|
@Component |
||||
|
@ConfigurationProperties(prefix="spring.datasource.druid") |
||||
|
@PropertySource(value = {"classpath:druid-${spring.profiles.active}.yml"}, factory = MyPropertySourceFactory.class) |
||||
|
public class DruidProps { |
||||
|
private Logger logger = LoggerFactory.getLogger(DruidProps.class); |
||||
|
|
||||
|
private String dynamicUrl; |
||||
|
private String url; |
||||
|
private String username; |
||||
|
private String password; |
||||
|
private String driverClassName; |
||||
|
private int initialSize; |
||||
|
private int minIdle; |
||||
|
private int maxActive; |
||||
|
private int maxWait; |
||||
|
private int timeBetweenEvictionRunsMillis; |
||||
|
private int minEvictableIdleTimeMillis; |
||||
|
private String validationQuery; |
||||
|
private boolean testWhileIdle; |
||||
|
private boolean testOnBorrow; |
||||
|
private boolean testOnReturn; |
||||
|
private boolean poolPreparedStatements; |
||||
|
private int maxPoolPreparedStatementPerConnectionSize; |
||||
|
private String filters; |
||||
|
private String connectionProperties; |
||||
|
private String logSlowSql; |
||||
|
|
||||
|
private String servletName; |
||||
|
private String servletUrlMapping; |
||||
|
private String servletLoginUsername; |
||||
|
private String servletLoginPassword; |
||||
|
private String servletLogSlowSql; |
||||
|
private String servletResetEnable; |
||||
|
|
||||
|
private String filterName; |
||||
|
private String filterUrlPattern; |
||||
|
private String filterExclusions; |
||||
|
private String filterProfileEnable; |
||||
|
|
||||
|
private String env; |
||||
|
|
||||
|
public DataSource createDruidDataSource() { |
||||
|
DruidDataSource datasource = new DruidDataSource(); |
||||
|
|
||||
|
datasource.setUrl(url); |
||||
|
datasource.setUsername(username); |
||||
|
if (StrUtil.isNotEmpty(password)) { |
||||
|
String key = System.getenv(env); |
||||
|
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key)); |
||||
|
String decryptStr = aes.decryptStr(password, CharsetUtil.CHARSET_UTF_8); |
||||
|
datasource.setPassword(decryptStr); |
||||
|
} else { |
||||
|
datasource.setPassword(""); |
||||
|
} |
||||
|
|
||||
|
datasource.setDriverClassName(driverClassName); |
||||
|
|
||||
|
//configuration
|
||||
|
datasource.setInitialSize(initialSize); |
||||
|
datasource.setMinIdle(minIdle); |
||||
|
datasource.setMaxActive(maxActive); |
||||
|
datasource.setMaxWait(maxWait); |
||||
|
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
||||
|
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
||||
|
datasource.setValidationQuery(validationQuery); |
||||
|
datasource.setTestWhileIdle(testWhileIdle); |
||||
|
datasource.setTestOnBorrow(testOnBorrow); |
||||
|
datasource.setTestOnReturn(testOnReturn); |
||||
|
datasource.setPoolPreparedStatements(poolPreparedStatements); |
||||
|
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); |
||||
|
try { |
||||
|
datasource.setFilters(filters); |
||||
|
} catch (SQLException e) { |
||||
|
logger.error("druid configuration initialization filter : {0}", e); |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
datasource.setConnectionProperties(connectionProperties); |
||||
|
|
||||
|
return datasource; |
||||
|
} |
||||
|
|
||||
|
public DataSource createDynamicDruidDataSource(String schema) { |
||||
|
DruidDataSource datasource = new DruidDataSource(); |
||||
|
|
||||
|
String url = dynamicUrl.replace(Constant.DYNAMIC_DATASOURCE_SCHEMA_KEY,schema); |
||||
|
datasource.setUrl(url); |
||||
|
datasource.setUsername(username); |
||||
|
datasource.setPassword(password); |
||||
|
datasource.setDriverClassName(driverClassName); |
||||
|
|
||||
|
//configuration
|
||||
|
datasource.setInitialSize(initialSize); |
||||
|
datasource.setMinIdle(minIdle); |
||||
|
datasource.setMaxActive(maxActive); |
||||
|
datasource.setMaxWait(maxWait); |
||||
|
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); |
||||
|
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); |
||||
|
datasource.setValidationQuery(validationQuery); |
||||
|
datasource.setTestWhileIdle(testWhileIdle); |
||||
|
datasource.setTestOnBorrow(testOnBorrow); |
||||
|
datasource.setTestOnReturn(testOnReturn); |
||||
|
datasource.setPoolPreparedStatements(poolPreparedStatements); |
||||
|
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); |
||||
|
try { |
||||
|
datasource.setFilters(filters); |
||||
|
} catch (SQLException e) { |
||||
|
logger.error("druid configuration initialization filter : {0}", e); |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
datasource.setConnectionProperties(connectionProperties); |
||||
|
|
||||
|
return datasource; |
||||
|
} |
||||
|
|
||||
|
//----------------------------------------------------
|
||||
|
|
||||
|
public String getDynamicUrl() { |
||||
|
return dynamicUrl; |
||||
|
} |
||||
|
|
||||
|
public void setDynamicUrl(String dynamicUrl) { |
||||
|
this.dynamicUrl = dynamicUrl; |
||||
|
} |
||||
|
|
||||
|
public String getUrl() { |
||||
|
return url; |
||||
|
} |
||||
|
|
||||
|
public void setUrl(String url) { |
||||
|
this.url = url; |
||||
|
} |
||||
|
|
||||
|
public String getUsername() { |
||||
|
return username; |
||||
|
} |
||||
|
|
||||
|
public void setUsername(String username) { |
||||
|
this.username = username; |
||||
|
} |
||||
|
|
||||
|
public String getPassword() { |
||||
|
return password; |
||||
|
} |
||||
|
|
||||
|
public void setPassword(String password) { |
||||
|
this.password = password; |
||||
|
} |
||||
|
|
||||
|
public String getDriverClassName() { |
||||
|
return driverClassName; |
||||
|
} |
||||
|
|
||||
|
public void setDriverClassName(String driverClassName) { |
||||
|
this.driverClassName = driverClassName; |
||||
|
} |
||||
|
|
||||
|
public int getInitialSize() { |
||||
|
return initialSize; |
||||
|
} |
||||
|
|
||||
|
public void setInitialSize(int initialSize) { |
||||
|
this.initialSize = initialSize; |
||||
|
} |
||||
|
|
||||
|
public int getMinIdle() { |
||||
|
return minIdle; |
||||
|
} |
||||
|
|
||||
|
public void setMinIdle(int minIdle) { |
||||
|
this.minIdle = minIdle; |
||||
|
} |
||||
|
|
||||
|
public int getMaxActive() { |
||||
|
return maxActive; |
||||
|
} |
||||
|
|
||||
|
public void setMaxActive(int maxActive) { |
||||
|
this.maxActive = maxActive; |
||||
|
} |
||||
|
|
||||
|
public int getMaxWait() { |
||||
|
return maxWait; |
||||
|
} |
||||
|
|
||||
|
public void setMaxWait(int maxWait) { |
||||
|
this.maxWait = maxWait; |
||||
|
} |
||||
|
|
||||
|
public int getTimeBetweenEvictionRunsMillis() { |
||||
|
return timeBetweenEvictionRunsMillis; |
||||
|
} |
||||
|
|
||||
|
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { |
||||
|
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; |
||||
|
} |
||||
|
|
||||
|
public int getMinEvictableIdleTimeMillis() { |
||||
|
return minEvictableIdleTimeMillis; |
||||
|
} |
||||
|
|
||||
|
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) { |
||||
|
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; |
||||
|
} |
||||
|
|
||||
|
public String getValidationQuery() { |
||||
|
return validationQuery; |
||||
|
} |
||||
|
|
||||
|
public void setValidationQuery(String validationQuery) { |
||||
|
this.validationQuery = validationQuery; |
||||
|
} |
||||
|
|
||||
|
public boolean isTestWhileIdle() { |
||||
|
return testWhileIdle; |
||||
|
} |
||||
|
|
||||
|
public void setTestWhileIdle(boolean testWhileIdle) { |
||||
|
this.testWhileIdle = testWhileIdle; |
||||
|
} |
||||
|
|
||||
|
public boolean isTestOnBorrow() { |
||||
|
return testOnBorrow; |
||||
|
} |
||||
|
|
||||
|
public void setTestOnBorrow(boolean testOnBorrow) { |
||||
|
this.testOnBorrow = testOnBorrow; |
||||
|
} |
||||
|
|
||||
|
public boolean isTestOnReturn() { |
||||
|
return testOnReturn; |
||||
|
} |
||||
|
|
||||
|
public void setTestOnReturn(boolean testOnReturn) { |
||||
|
this.testOnReturn = testOnReturn; |
||||
|
} |
||||
|
|
||||
|
public boolean isPoolPreparedStatements() { |
||||
|
return poolPreparedStatements; |
||||
|
} |
||||
|
|
||||
|
public void setPoolPreparedStatements(boolean poolPreparedStatements) { |
||||
|
this.poolPreparedStatements = poolPreparedStatements; |
||||
|
} |
||||
|
|
||||
|
public int getMaxPoolPreparedStatementPerConnectionSize() { |
||||
|
return maxPoolPreparedStatementPerConnectionSize; |
||||
|
} |
||||
|
|
||||
|
public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) { |
||||
|
this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; |
||||
|
} |
||||
|
|
||||
|
public String getFilters() { |
||||
|
return filters; |
||||
|
} |
||||
|
|
||||
|
public void setFilters(String filters) { |
||||
|
this.filters = filters; |
||||
|
} |
||||
|
|
||||
|
public String getConnectionProperties() { |
||||
|
return connectionProperties; |
||||
|
} |
||||
|
|
||||
|
public void setConnectionProperties(String connectionProperties) { |
||||
|
this.connectionProperties = connectionProperties; |
||||
|
} |
||||
|
|
||||
|
public String getLogSlowSql() { |
||||
|
return logSlowSql; |
||||
|
} |
||||
|
|
||||
|
public void setLogSlowSql(String logSlowSql) { |
||||
|
this.logSlowSql = logSlowSql; |
||||
|
} |
||||
|
|
||||
|
public String getServletUrlMapping() { |
||||
|
return servletUrlMapping; |
||||
|
} |
||||
|
|
||||
|
public void setServletUrlMapping(String servletUrlMapping) { |
||||
|
this.servletUrlMapping = servletUrlMapping; |
||||
|
} |
||||
|
|
||||
|
public String getServletLoginUsername() { |
||||
|
return servletLoginUsername; |
||||
|
} |
||||
|
|
||||
|
public void setServletLoginUsername(String servletLoginUsername) { |
||||
|
this.servletLoginUsername = servletLoginUsername; |
||||
|
} |
||||
|
|
||||
|
public String getServletLoginPassword() { |
||||
|
return servletLoginPassword; |
||||
|
} |
||||
|
|
||||
|
public void setServletLoginPassword(String servletLoginPassword) { |
||||
|
this.servletLoginPassword = servletLoginPassword; |
||||
|
} |
||||
|
|
||||
|
public String getServletLogSlowSql() { |
||||
|
return servletLogSlowSql; |
||||
|
} |
||||
|
|
||||
|
public void setServletLogSlowSql(String servletLogSlowSql) { |
||||
|
this.servletLogSlowSql = servletLogSlowSql; |
||||
|
} |
||||
|
|
||||
|
public String getServletResetEnable() { |
||||
|
return servletResetEnable; |
||||
|
} |
||||
|
|
||||
|
public void setServletResetEnable(String servletResetEnable) { |
||||
|
this.servletResetEnable = servletResetEnable; |
||||
|
} |
||||
|
|
||||
|
public String getServletName() { |
||||
|
return servletName; |
||||
|
} |
||||
|
|
||||
|
public void setServletName(String servletName) { |
||||
|
this.servletName = servletName; |
||||
|
} |
||||
|
|
||||
|
public String getFilterName() { |
||||
|
return filterName; |
||||
|
} |
||||
|
|
||||
|
public void setFilterName(String filterName) { |
||||
|
this.filterName = filterName; |
||||
|
} |
||||
|
|
||||
|
public String getFilterUrlPattern() { |
||||
|
return filterUrlPattern; |
||||
|
} |
||||
|
|
||||
|
public void setFilterUrlPattern(String filterUrlPattern) { |
||||
|
this.filterUrlPattern = filterUrlPattern; |
||||
|
} |
||||
|
|
||||
|
public String getFilterExclusions() { |
||||
|
return filterExclusions; |
||||
|
} |
||||
|
|
||||
|
public void setFilterExclusions(String filterExclusions) { |
||||
|
this.filterExclusions = filterExclusions; |
||||
|
} |
||||
|
|
||||
|
public String getFilterProfileEnable() { |
||||
|
return filterProfileEnable; |
||||
|
} |
||||
|
|
||||
|
public void setFilterProfileEnable(String filterProfileEnable) { |
||||
|
this.filterProfileEnable = filterProfileEnable; |
||||
|
} |
||||
|
|
||||
|
public String getEnv() { |
||||
|
return env; |
||||
|
} |
||||
|
|
||||
|
public void setEnv(String env) { |
||||
|
this.env = env; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import org.springframework.boot.env.YamlPropertySourceLoader; |
||||
|
import org.springframework.core.env.PropertySource; |
||||
|
import org.springframework.core.io.support.EncodedResource; |
||||
|
import org.springframework.core.io.support.PropertySourceFactory; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: wuHuiJuan |
||||
|
* @create: 2019/12/02 10:35 |
||||
|
*/ |
||||
|
public class MyPropertySourceFactory implements PropertySourceFactory { |
||||
|
public MyPropertySourceFactory() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) throws IOException { |
||||
|
return new YamlPropertySourceLoader().load(name, encodedResource.getResource()).get(0); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
|
||||
|
@Configuration |
||||
|
public class RedisConfig { |
||||
|
|
||||
|
@Bean |
||||
|
@SuppressWarnings("all") |
||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { |
||||
|
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); |
||||
|
template.setConnectionFactory(factory); |
||||
|
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); |
||||
|
ObjectMapper om = new ObjectMapper(); |
||||
|
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); |
||||
|
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); |
||||
|
jackson2JsonRedisSerializer.setObjectMapper(om); |
||||
|
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); |
||||
|
// key采用String的序列化方式
|
||||
|
template.setKeySerializer(stringRedisSerializer); |
||||
|
// hash的key也采用String的序列化方式
|
||||
|
template.setHashKeySerializer(stringRedisSerializer); |
||||
|
// value序列化方式采用jackson
|
||||
|
template.setValueSerializer(jackson2JsonRedisSerializer); |
||||
|
// hash的value序列化方式采用jackson
|
||||
|
template.setHashValueSerializer(jackson2JsonRedisSerializer); |
||||
|
template.afterPropertiesSet(); |
||||
|
return template; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import com.alibaba.druid.support.http.StatViewServlet; |
||||
|
import com.alibaba.druid.support.http.WebStatFilter; |
||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
||||
|
import org.springframework.boot.web.servlet.ServletRegistrationBean; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* 在springboot添加过滤器有两种方式: |
||||
|
1、通过创建FilterRegistrationBean的方式 |
||||
|
1.1 建议使用此种方式,统一管理,且通过注解的方式若不是本地调试, |
||||
|
如果在filter中需要增加cookie可能会存在写不进前端情况 |
||||
|
1.2 有多个filter就创建多个FilterRegistrationBean ,若需注明filter的执行顺序, |
||||
|
可通过registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE - 1)配置, |
||||
|
值越大,执行顺序越靠后 |
||||
|
2、通过注解@WebFilter的方式 |
||||
|
2.1 在启动类上增加@ServletComponentScan注解,自动扫描带有过滤器注解的包 |
||||
|
2.2 在类上使用@WebFilter和@Order组合实现 |
||||
|
3、通过注解@WebFilter的方式 |
||||
|
3.1 在类上使用@WebFilter和@Order组合实现 |
||||
|
3.2 在类上添加@Component注解 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* 原生方案 |
||||
|
* @WebServlet 、@WebListener、@WebFilter |
||||
|
* 在启动类上增加@ServletComponentScan注解,自动扫描带有Servlet原生方案注解的包 |
||||
|
* |
||||
|
* SpringBoot方案 |
||||
|
* SpringBoot提供了三种Bean |
||||
|
* FilterRegistrationBean、 |
||||
|
* ServletRegistrationBean、 |
||||
|
* ServletListenerRegistrationBean |
||||
|
* 分别对应配置原生的Filter、Servlet、Listener |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* 注册系统过滤器 |
||||
|
*/ |
||||
|
@Configuration |
||||
|
public class ServletConfig { |
||||
|
@Resource |
||||
|
private DruidProps druidConfig; |
||||
|
|
||||
|
@Bean |
||||
|
public ServletRegistrationBean druidServlet() { |
||||
|
ServletRegistrationBean reg = new ServletRegistrationBean(); |
||||
|
reg.setServlet(new StatViewServlet()); |
||||
|
reg.setName(druidConfig.getFilterName()); |
||||
|
reg.addUrlMappings(druidConfig.getServletUrlMapping()); |
||||
|
//白名单:
|
||||
|
//reg.addInitParameter("allow","127.0.0.1");
|
||||
|
//IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
|
||||
|
//reg.addInitParameter("deny","192.168.1.73");
|
||||
|
reg.addInitParameter("loginUsername", druidConfig.getServletLoginUsername()); |
||||
|
reg.addInitParameter("loginPassword", druidConfig.getServletLoginPassword()); |
||||
|
reg.addInitParameter("logSlowSql", druidConfig.getServletLogSlowSql()); |
||||
|
//是否能够重置数据.
|
||||
|
reg.addInitParameter("resetEnable",druidConfig.getServletResetEnable()); |
||||
|
return reg; |
||||
|
} |
||||
|
|
||||
|
@Bean |
||||
|
public FilterRegistrationBean druidFilter() { |
||||
|
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); |
||||
|
filterRegistrationBean.setFilter(new WebStatFilter()); |
||||
|
filterRegistrationBean.setName(druidConfig.getFilterName()); |
||||
|
filterRegistrationBean.addUrlPatterns(druidConfig.getFilterUrlPattern()); |
||||
|
filterRegistrationBean.addInitParameter("exclusions", druidConfig.getFilterExclusions()); |
||||
|
filterRegistrationBean.addInitParameter("profileEnable", druidConfig.getFilterProfileEnable()); |
||||
|
return filterRegistrationBean; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,118 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
|
||||
|
import cn.hutool.core.lang.Snowflake; |
||||
|
import cn.hutool.core.util.IdUtil; |
||||
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.fasterxml.jackson.databind.module.SimpleModule; |
||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.http.converter.HttpMessageConverter; |
||||
|
import org.springframework.http.converter.StringHttpMessageConverter; |
||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
||||
|
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; |
||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.nio.charset.Charset; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Configuration |
||||
|
public class SpringConfig implements WebMvcConfigurer { |
||||
|
@Autowired |
||||
|
private DruidProps druidPropsUtil; |
||||
|
@Value("${spring.snowflake.workerId}") |
||||
|
private String workerId; |
||||
|
@Value("${spring.snowflake.datacenterId}") |
||||
|
private String datacenterId; |
||||
|
|
||||
|
/** |
||||
|
* 配置Converter |
||||
|
* @return |
||||
|
*/ |
||||
|
@Bean |
||||
|
public HttpMessageConverter<String> responseStringConverter() { |
||||
|
StringHttpMessageConverter converter = new StringHttpMessageConverter( |
||||
|
Charset.forName("UTF-8")); |
||||
|
return converter; |
||||
|
} |
||||
|
|
||||
|
@Bean |
||||
|
public HttpMessageConverter<Object> responseJsonConverter(){ |
||||
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
||||
|
List<MediaType> mediaTypeList = new ArrayList<>(); |
||||
|
mediaTypeList.add(MediaType.TEXT_HTML); |
||||
|
mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8); |
||||
|
converter.setSupportedMediaTypes(mediaTypeList); |
||||
|
|
||||
|
//converter.setObjectMapper();
|
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
SimpleModule simpleModule = new SimpleModule(); |
||||
|
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
||||
|
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
||||
|
objectMapper.registerModule(simpleModule); |
||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
||||
|
converter.setObjectMapper(objectMapper); |
||||
|
|
||||
|
return converter; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
||||
|
converters.add(responseStringConverter()); |
||||
|
converters.add(responseJsonConverter()); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { |
||||
|
configurer.favorPathExtension(false); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void addCorsMappings(CorsRegistry registry) { |
||||
|
registry.addMapping("/**") |
||||
|
.allowedOrigins("*") |
||||
|
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") |
||||
|
.allowCredentials(true) |
||||
|
.maxAge(3600) |
||||
|
.allowedHeaders("*"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 配置静态资源 |
||||
|
*/ |
||||
|
@Override |
||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
||||
|
registry.addResourceHandler("swagger-ui.html") |
||||
|
.addResourceLocations("classpath:/META-INF/resources/"); |
||||
|
registry.addResourceHandler("/webjars/**") |
||||
|
.addResourceLocations("classpath:/META-INF/resources/webjars/"); |
||||
|
|
||||
|
registry.addResourceHandler("/uploads/**") |
||||
|
.addResourceLocations("file:///home/filedeal/uploads/"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 配置数据源(单数据源) |
||||
|
*/ |
||||
|
@Bean |
||||
|
public DataSource dataSource(){ |
||||
|
return druidPropsUtil.createDruidDataSource(); |
||||
|
} |
||||
|
|
||||
|
@Bean |
||||
|
public Snowflake snowflake(){ |
||||
|
return IdUtil.createSnowflake(Long.valueOf(workerId),Long.valueOf(datacenterId)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
package com.ccsens.scheduler.config; |
||||
|
|
||||
|
import com.ccsens.scheduler.util.Constant; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import springfox.documentation.builders.ParameterBuilder; |
||||
|
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
|
import springfox.documentation.schema.ModelRef; |
||||
|
import springfox.documentation.service.ApiInfo; |
||||
|
import springfox.documentation.service.Parameter; |
||||
|
import springfox.documentation.spi.DocumentationType; |
||||
|
import springfox.documentation.spring.web.plugins.Docket; |
||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Configuration |
||||
|
@EnableSwagger2 |
||||
|
@ConditionalOnExpression("${swagger.enable}") |
||||
|
public class SwaggerConfigure { |
||||
|
@Bean |
||||
|
public Docket customDocket() { |
||||
|
//
|
||||
|
return new Docket(DocumentationType.SWAGGER_2) |
||||
|
.apiInfo(apiInfo()) |
||||
|
.select() |
||||
|
.apis(RequestHandlerSelectors |
||||
|
.basePackage("com.ccsens.scheduler.api")) |
||||
|
.build() |
||||
|
.globalOperationParameters(setHeaderToken()); |
||||
|
} |
||||
|
|
||||
|
private ApiInfo apiInfo() { |
||||
|
return new ApiInfo("Swagger scheduler", |
||||
|
"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", |
||||
|
"1.0.0", |
||||
|
"http://swagger.io/terms/", |
||||
|
"zhangsan", |
||||
|
"Apache 2.0", |
||||
|
"http://www.apache.org/licenses/LICENSE-2.0.html" |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private List<Parameter> setHeaderToken() { |
||||
|
ParameterBuilder tokenPar = new ParameterBuilder(); |
||||
|
List<Parameter> pars = new ArrayList<>(); |
||||
|
tokenPar.name(Constant.HEADER_KEY_TOKEN).description("token") |
||||
|
.defaultValue(Constant.HEADER_KEY_TOKEN_PREFIX) |
||||
|
.modelRef(new ModelRef("string")).parameterType("header").required(false).build(); |
||||
|
pars.add(tokenPar.build()); |
||||
|
return pars; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package com.ccsens.scheduler.exception; |
||||
|
|
||||
|
import com.ccsens.scheduler.util.CodeEnum; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
/** |
||||
|
* @author _zhangsan |
||||
|
*/ |
||||
|
@Getter |
||||
|
public class BaseException extends RuntimeException { |
||||
|
private Integer code; |
||||
|
private CodeEnum codeEnum; |
||||
|
private String operation; |
||||
|
|
||||
|
public BaseException(String message){ |
||||
|
super(message); |
||||
|
this.code = -1; |
||||
|
} |
||||
|
|
||||
|
public BaseException(Integer code, String message){ |
||||
|
super(message); |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public BaseException(CodeEnum codeEnum) { |
||||
|
super(codeEnum.getMsg()); |
||||
|
this.code = codeEnum.getCode(); |
||||
|
this.codeEnum = codeEnum; |
||||
|
} |
||||
|
|
||||
|
public BaseException(){ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,158 @@ |
|||||
|
package com.ccsens.scheduler.intercept; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import com.ccsens.scheduler.util.Constant; |
||||
|
import org.apache.ibatis.executor.Executor; |
||||
|
import org.apache.ibatis.mapping.BoundSql; |
||||
|
import org.apache.ibatis.mapping.MappedStatement; |
||||
|
import org.apache.ibatis.mapping.ResultMap; |
||||
|
import org.apache.ibatis.mapping.SqlSource; |
||||
|
import org.apache.ibatis.plugin.*; |
||||
|
import org.apache.ibatis.reflection.DefaultReflectorFactory; |
||||
|
import org.apache.ibatis.reflection.MetaObject; |
||||
|
import org.apache.ibatis.reflection.factory.DefaultObjectFactory; |
||||
|
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; |
||||
|
import org.apache.ibatis.session.ResultHandler; |
||||
|
import org.apache.ibatis.session.RowBounds; |
||||
|
|
||||
|
import java.lang.reflect.InvocationTargetException; |
||||
|
import java.lang.reflect.Method; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.Properties; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: wuHuiJuan |
||||
|
* @create: 2019/12/11 10:58 |
||||
|
*/ |
||||
|
@Intercepts({ |
||||
|
@Signature( |
||||
|
type = Executor.class, |
||||
|
method = "query", |
||||
|
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class} |
||||
|
) |
||||
|
}) |
||||
|
public class MybatisInterceptor implements Interceptor { |
||||
|
@Override |
||||
|
public Object intercept(Invocation invocation) throws Throwable { |
||||
|
|
||||
|
|
||||
|
String selectByExample = "selectByExample"; |
||||
|
String countByExample = "countByExample"; |
||||
|
String countByExample2 = "selectByExample_COUNT"; |
||||
|
String selectByPrimaryKey = "selectByPrimaryKey"; |
||||
|
|
||||
|
Object[] args = invocation.getArgs(); |
||||
|
MappedStatement statement = (MappedStatement) args[0]; |
||||
|
if (statement.getId().endsWith(selectByExample) |
||||
|
|| statement.getId().endsWith(countByExample) |
||||
|
|| statement.getId().endsWith(countByExample2)) { |
||||
|
//XXXExample
|
||||
|
Object example = args[1]; |
||||
|
|
||||
|
addCondition(statement, example); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} else if (statement.getId().endsWith(selectByPrimaryKey)) { |
||||
|
BoundSql boundSql = statement.getBoundSql(args[1]); |
||||
|
String sql = boundSql.getSql() + " and rec_status = 0"; |
||||
|
MappedStatement newStatement = newMappedStatement(statement, new BoundSqlSqlSource(boundSql)); |
||||
|
MetaObject msObject = MetaObject.forObject(newStatement, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(),new DefaultReflectorFactory()); |
||||
|
msObject.setValue("sqlSource.boundSql.sql", sql); |
||||
|
args[0] = newStatement; |
||||
|
} |
||||
|
|
||||
|
return invocation.proceed(); |
||||
|
} |
||||
|
|
||||
|
private void addCondition(MappedStatement statement, Object example) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException { |
||||
|
if (example instanceof Map) { |
||||
|
example = ((Map) example).get("_ORIGINAL_PARAMETER_OBJECT"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Method method = example.getClass().getMethod("getOredCriteria", null); |
||||
|
//获取到条件数组,第一个是Criteria
|
||||
|
List list = (List) method.invoke(example); |
||||
|
if (CollectionUtil.isEmpty(list)) { |
||||
|
Class clazz = ((ResultMap) statement.getResultMaps().get(0)).getType(); |
||||
|
String exampleName = clazz.getName() + "Example"; |
||||
|
Object paramExample = Class.forName(exampleName).newInstance(); |
||||
|
Method createCriteria = paramExample.getClass().getMethod("createCriteria"); |
||||
|
Object criteria = createCriteria.invoke(paramExample); |
||||
|
Method andIsDelEqualTo = criteria.getClass().getMethod("andRecStatusEqualTo", Byte.class); |
||||
|
andIsDelEqualTo.invoke(criteria, Constant.REC_STATUS.Normal.value); |
||||
|
list.add(criteria); |
||||
|
} else { |
||||
|
Object criteria = list.get(0); |
||||
|
Method getCriteria = criteria.getClass().getMethod("getCriteria"); |
||||
|
List params = (List) getCriteria.invoke(criteria); |
||||
|
boolean hasDel = false; |
||||
|
for (Object param : params) { |
||||
|
Method getCondition = param.getClass().getMethod("getCondition"); |
||||
|
Object condition = getCondition.invoke(param); |
||||
|
if ("rec_status =".equals(condition)) { |
||||
|
hasDel = true; |
||||
|
} |
||||
|
} |
||||
|
if (!hasDel) { |
||||
|
Method andIsDelEqualTo = criteria.getClass().getMethod("andRecStatusEqualTo", Byte.class); |
||||
|
andIsDelEqualTo.invoke(criteria, Constant.REC_STATUS.Normal.value); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Object plugin(Object target) { |
||||
|
return Plugin.wrap(target, this); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setProperties(Properties properties) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) { |
||||
|
MappedStatement.Builder builder = |
||||
|
new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType()); |
||||
|
builder.resource(ms.getResource()); |
||||
|
builder.fetchSize(ms.getFetchSize()); |
||||
|
builder.statementType(ms.getStatementType()); |
||||
|
builder.keyGenerator(ms.getKeyGenerator()); |
||||
|
if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) { |
||||
|
StringBuilder keyProperties = new StringBuilder(); |
||||
|
for (String keyProperty : ms.getKeyProperties()) { |
||||
|
keyProperties.append(keyProperty).append(","); |
||||
|
} |
||||
|
keyProperties.delete(keyProperties.length() - 1, keyProperties.length()); |
||||
|
builder.keyProperty(keyProperties.toString()); |
||||
|
} |
||||
|
builder.timeout(ms.getTimeout()); |
||||
|
builder.parameterMap(ms.getParameterMap()); |
||||
|
builder.resultMaps(ms.getResultMaps()); |
||||
|
builder.resultSetType(ms.getResultSetType()); |
||||
|
builder.cache(ms.getCache()); |
||||
|
builder.flushCacheRequired(ms.isFlushCacheRequired()); |
||||
|
builder.useCache(ms.isUseCache()); |
||||
|
|
||||
|
return builder.build(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
class BoundSqlSqlSource implements SqlSource { |
||||
|
private BoundSql boundSql; |
||||
|
public BoundSqlSqlSource(BoundSql boundSql) { |
||||
|
this.boundSql = boundSql; |
||||
|
} |
||||
|
@Override |
||||
|
public BoundSql getBoundSql(Object parameterObject) { |
||||
|
return boundSql; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
package com.ccsens.scheduler.util; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
|
||||
|
@Getter |
||||
|
public enum CodeEnum { |
||||
|
/** |
||||
|
* 异常 |
||||
|
*/ |
||||
|
SUCCESS(200, "ok", true), |
||||
|
SYS_ERROR(500, "网络繁忙,请您稍后重试", false), |
||||
|
FILE_FORMAT_ERROR(1, "文件格式错误", true), |
||||
|
PARAM_NULL(6, "请检查您的参数是否填写完整。", true), |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
; |
||||
|
|
||||
|
public CodeEnum addMsg(String msg){ |
||||
|
this.msg = msg+"行:"+this.msg; |
||||
|
return this; |
||||
|
} |
||||
|
public static CodeEnum getByCode(int code) { |
||||
|
for (CodeEnum codeEnum: CodeEnum.values()) { |
||||
|
if (codeEnum.getCode() == code) { |
||||
|
return codeEnum; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
private CodeEnum(Integer code, String msg, boolean success) { |
||||
|
this.code = code; |
||||
|
this.msg = msg; |
||||
|
this.success = success; |
||||
|
} |
||||
|
private Integer code; |
||||
|
private String msg; |
||||
|
private boolean success; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,594 @@ |
|||||
|
package com.ccsens.scheduler.util; |
||||
|
|
||||
|
|
||||
|
public class Constant { |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public static final String PARAMETER_KEY_TOKEN = "token"; |
||||
|
public static final String HEADER_KEY_TOKEN = "Authorization"; |
||||
|
public static final String HEADER_KEY_TOKEN_PREFIX = "Bearer "; |
||||
|
public static final String REQUEST_KEY_CLAIMS = "claims"; |
||||
|
public static final String REQUEST_KEY_TOKEN_USERS = "Token_User"; |
||||
|
public static final String RANDOM_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
||||
|
public static final String IMAGE_CODE = "image_code_"; |
||||
|
public static final String DYNAMIC_DATASOURCE_SCHEMA_KEY = "${schema}"; |
||||
|
|
||||
|
public enum REC_STATUS { |
||||
|
Normal((byte) 0,"正常"), Disabled((byte) 1,"已禁用"),Deleted((byte) 2,"已删除"); |
||||
|
|
||||
|
public byte value; |
||||
|
public String phase; |
||||
|
REC_STATUS(byte value,String thePhase){ |
||||
|
this.value =value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public enum PARTI_LOGIN_STATUS { |
||||
|
SUCCESS(0,"登陆成功"), ToStep2(1,"进入下一步"); |
||||
|
|
||||
|
public int value; |
||||
|
public String phase; |
||||
|
PARTI_LOGIN_STATUS(int value,String thePhase){ |
||||
|
this.value =value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Gender{ |
||||
|
Unknown(0,"未知"),Male(1,"男"),Female(2,"女"); |
||||
|
|
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Gender(int value,String thePhase){ |
||||
|
this.value =value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Parti_Verify_Type{ |
||||
|
Phone(0,"手机"),Email(1,"邮件"),Account(2,"账号"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Parti_Verify_Type(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Parti_Verify_Type valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Phone; |
||||
|
case 1: return Email; |
||||
|
case 2: return Account; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum PartiVerify{ |
||||
|
None(0,"无验证"),Verify(1,"验证"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
PartiVerify(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum TASK_Execute_Type { |
||||
|
Start(0,"开始"),Complete(1,"完成"); |
||||
|
|
||||
|
public int value; |
||||
|
public String phase; |
||||
|
TASK_Execute_Type(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public enum Message_Type{ |
||||
|
Heart(0x00,"Heart"),Ack(0x01,"Ack"),Auth(0x02,"Auth"),Channel(0x03,"Channel") |
||||
|
,Sync(0x04,"Sync") |
||||
|
,Node(0x05,"Node"),User(0x06,"User"), Timer(0x07,"Timer") |
||||
|
,Error(0x99,"Error") |
||||
|
,MasterStatus(0x10,"MasterStatus") |
||||
|
,BatchSetting(0x11,"BatchSetting") |
||||
|
,Admin(0x12,"Admin") |
||||
|
,Ring(0x13,"Ring") |
||||
|
,Deliver(0x14,"Deliver") |
||||
|
,Game(0x15,"Game") |
||||
|
,Chrome(0x15,"Chrome") |
||||
|
,PPTCtl(0x15,"PPTCtl") |
||||
|
,Count(0x16,"Count") |
||||
|
,ChangeStatus(0x17,"ChangeStatus") |
||||
|
,PROJECT_MESSAGE(0x18, "ProjectMessage"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Type(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Type valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0x00: return Heart; |
||||
|
case 0x01: return Ack; |
||||
|
case 0x02: return Auth; |
||||
|
case 0x03: return Channel; |
||||
|
case 0x04: return Sync; |
||||
|
case 0x05: return Node; |
||||
|
case 0x06: return User; |
||||
|
case 0x07: return Timer; |
||||
|
case 0x10: return MasterStatus; |
||||
|
case 0x11: return BatchSetting; |
||||
|
case 0x12: return Admin; |
||||
|
case 0x13: return Ring; |
||||
|
case 0x14: return Deliver; |
||||
|
case 0x15: return Game; |
||||
|
case 0x16: return Count; |
||||
|
case 0x17: return ChangeStatus; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static Message_Type phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if("Sync".equalsIgnoreCase(phase)) { |
||||
|
return Sync; |
||||
|
} |
||||
|
if("Ack".equalsIgnoreCase(phase)) { |
||||
|
return Ack; |
||||
|
} |
||||
|
if("Node".equalsIgnoreCase(phase)) { |
||||
|
return Node; |
||||
|
} |
||||
|
if("User".equalsIgnoreCase(phase)) { |
||||
|
return User; |
||||
|
} |
||||
|
if("Heart".equalsIgnoreCase(phase)) { |
||||
|
return Heart; |
||||
|
} |
||||
|
if("Auth".equalsIgnoreCase(phase)) { |
||||
|
return Auth; |
||||
|
} |
||||
|
if("Channel".equalsIgnoreCase(phase)) { |
||||
|
return Channel; |
||||
|
} |
||||
|
if("Timer".equalsIgnoreCase(phase)) { |
||||
|
return Timer; |
||||
|
} |
||||
|
if("MasterStatus".equalsIgnoreCase(phase)) { |
||||
|
return MasterStatus; |
||||
|
} |
||||
|
if("BatchSetting".equalsIgnoreCase(phase)) { |
||||
|
return BatchSetting; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Admin")) { |
||||
|
return Admin; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Ring")) { |
||||
|
return Ring; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Deliver")) { |
||||
|
return Deliver; |
||||
|
} |
||||
|
if("Game".equalsIgnoreCase(phase)) { |
||||
|
return Game; |
||||
|
} |
||||
|
if("Count".equalsIgnoreCase(phase)) { |
||||
|
return Count; |
||||
|
} |
||||
|
if("ChangeStatus".equalsIgnoreCase(phase)) { |
||||
|
return Count; |
||||
|
}else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
public enum Message_Ack_Event{ |
||||
|
Ack(0,"Ack"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Ack_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Ack_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Ack; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Ack_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Ack")) { |
||||
|
return Ack; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Sync_Event{ |
||||
|
ChangeDuration(0,"ChangeDuration"),Move(1,"Move"), |
||||
|
Remove(2,"Remove"),Add(3,"Add"),Start(4,"Start"),ChangeBeginTime(5,"ChangeBeginTime"),Show(6,"Show"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Sync_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Sync_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return ChangeDuration; |
||||
|
case 1: return Move; |
||||
|
case 2: return Remove; |
||||
|
case 3: return Add; |
||||
|
case 4: return Start; |
||||
|
case 5: return ChangeBeginTime; |
||||
|
case 6: return Show; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Sync_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Start")) { |
||||
|
return Start; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("ChangeDuration")) { |
||||
|
return ChangeDuration; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Move")) { |
||||
|
return Move; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Remove")) { |
||||
|
return Remove; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Add")) { |
||||
|
return Add; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("ChangeBeginTime")) { |
||||
|
return ChangeBeginTime; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Show")) { |
||||
|
return Show; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Node_Event{ |
||||
|
ChangeStatus(0,"ChangeStatus"),PostComment(1,"PostComment"),UploadDeliver(2,"UploadDeliver"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Node_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Node_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return ChangeStatus; |
||||
|
case 1: return PostComment; |
||||
|
case 2: return UploadDeliver; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Node_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("ChangeStatus")) { |
||||
|
return ChangeStatus; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("PostComment")) { |
||||
|
return PostComment; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("UploadDeliver")) { |
||||
|
return UploadDeliver; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_User_Event{ |
||||
|
HasRead(0,"HasRead"),User(1,"User"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_User_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_User_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return HasRead; |
||||
|
case 1: return User; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_User_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("HasRead")) { |
||||
|
return HasRead; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("User")) { |
||||
|
return User; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Heart_Event{ |
||||
|
Heart(0,"Heart"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Heart_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Heart_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Heart; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Heart_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Heart")) { |
||||
|
return Heart; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Auth_Event{ |
||||
|
Auth(0,"Auth"), |
||||
|
Answer(1,"Answer"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Auth_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Auth_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Auth; |
||||
|
case 1: return Answer; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Auth_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Auth")) { |
||||
|
return Auth; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Answer")) { |
||||
|
return Answer; |
||||
|
}else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Channel_Event{ |
||||
|
Channel(0,"Channel"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Channel_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Channel_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Channel; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Channel_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Channel")) { |
||||
|
return Channel; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_MasterStatus_Event{ |
||||
|
Report(0,"Report"),Query(1,"Query"),Answer(2,"Answer"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_MasterStatus_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_MasterStatus_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Report; |
||||
|
case 1: return Query; |
||||
|
case 2: return Answer; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_MasterStatus_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Report")) { |
||||
|
return Report; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Query")) { |
||||
|
return Query; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Answer")) { |
||||
|
return Answer; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@SuppressWarnings("all") |
||||
|
public enum Task_Check_Status{ |
||||
|
PENDING(0,"未审核"),FAILURE(1,"审核未通过"),SUCCESS(2,"审核已通过"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Task_Check_Status(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Task_Check_Status valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return PENDING; |
||||
|
case 1: return FAILURE; |
||||
|
case 2: return SUCCESS; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Task_Check_Status phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("PENDING")) { |
||||
|
return PENDING; |
||||
|
}else if(phase.equalsIgnoreCase("FAILURE")) { |
||||
|
return FAILURE; |
||||
|
} else if(phase.equalsIgnoreCase("SUCCESS")) { |
||||
|
return SUCCESS; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public enum Message_BatchSetting_Event{ |
||||
|
Apply(0,"Apply"),Answer(1,"Answer"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_BatchSetting_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_BatchSetting_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Apply; |
||||
|
case 1: return Answer; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_BatchSetting_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Apply")) { |
||||
|
return Apply; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Answer")) { |
||||
|
return Answer; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Admin_Event{ |
||||
|
FindAll(0,"FindAll"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Admin_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Admin_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return FindAll; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Admin_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("FindAll")) { |
||||
|
return FindAll; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum Message_Ring_Event{ |
||||
|
Send(0,"Send") |
||||
|
,Read(1,"Read"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Ring_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Ring_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Send; |
||||
|
case 1: return Read; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Ring_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Send")) { |
||||
|
return Send; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Read")) { |
||||
|
return Read; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
public enum Message_Deliver_Event{ |
||||
|
Upload(0,"Upload") |
||||
|
,Checker(1,"Checker") |
||||
|
,Delete(2,"Delete"); |
||||
|
public int value; |
||||
|
public String phase; |
||||
|
Message_Deliver_Event(int value,String thePhase){ |
||||
|
this.value = value; |
||||
|
this.phase = thePhase; |
||||
|
} |
||||
|
public static Message_Deliver_Event valueOf(int value) { // 手写的从int到enum的转换函数
|
||||
|
switch (value) { |
||||
|
case 0: return Upload; |
||||
|
case 1: return Checker; |
||||
|
case 2: return Delete; |
||||
|
default: return null; |
||||
|
} |
||||
|
} |
||||
|
public static Message_Deliver_Event phaseOf(String phase) { // 手写的从String到enum的转换函数
|
||||
|
if(phase.equalsIgnoreCase("Upload")) { |
||||
|
return Upload; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Checker")) { |
||||
|
return Checker; |
||||
|
} |
||||
|
if(phase.equalsIgnoreCase("Delete")) { |
||||
|
return Delete; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//wbs表时间类型==================================================================/
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* redis类型 |
||||
|
*/ |
||||
|
public enum RedisType{ |
||||
|
/**redis类型**/ |
||||
|
STRING(0,"字符串类型"), |
||||
|
LIST_INDEX(1,"列表-某一个"), |
||||
|
LIST_RANGE(2,"列表-范围"), |
||||
|
SET(3,"集合"), |
||||
|
SORT_SET_RANGE(4,"有序集合-index"), |
||||
|
SORT_SET_SCORE(5,"有序集合-分数"), |
||||
|
HASH_ITEM(6, "哈希-某一项"), |
||||
|
HASH(7, "哈希-全部"), |
||||
|
; |
||||
|
/**类型code*/ |
||||
|
public int type; |
||||
|
/**类型*/ |
||||
|
public String message; |
||||
|
RedisType(int type, String message) { |
||||
|
this.type = type; |
||||
|
this.message = message; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
package com.ccsens.scheduler.util; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel |
||||
|
public class JsonResponse<T> { |
||||
|
|
||||
|
/** |
||||
|
* Common Error Constant |
||||
|
*/ |
||||
|
public static class RegularError { |
||||
|
public static final int ERRCODE_SUCCESS = 200; |
||||
|
public static final String ERRCODE_SUCCESS_PHASE = "ok"; |
||||
|
public static final int ERRCODE_FAIL = -1; |
||||
|
public static final String ERRCODE_FAIL_PHASE = "error"; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
@ApiModelProperty(value="状态码") |
||||
|
private Integer code; |
||||
|
@ApiModelProperty(value="数据") |
||||
|
private T data; |
||||
|
@ApiModelProperty(value="消息") |
||||
|
private String msg; |
||||
|
@ApiModelProperty(value="成功与否") |
||||
|
private boolean success; |
||||
|
|
||||
|
private JsonResponse() { |
||||
|
} |
||||
|
|
||||
|
public static JsonResponse newInstance(){ |
||||
|
return new JsonResponse(); |
||||
|
} |
||||
|
|
||||
|
public JsonResponse ok(){ |
||||
|
this.code = CodeEnum.SUCCESS.getCode(); |
||||
|
this.msg = CodeEnum.SUCCESS.getMsg(); |
||||
|
this.success = CodeEnum.SUCCESS.isSuccess(); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse<T> ok(T data){ |
||||
|
ok(); |
||||
|
this.data = data; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse ok(CodeEnum codeEnum){ |
||||
|
this.code = codeEnum.getCode(); |
||||
|
this.msg = codeEnum.getMsg(); |
||||
|
this.success = codeEnum.isSuccess(); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse ok(CodeEnum codeEnum, T data){ |
||||
|
this.code = codeEnum.getCode(); |
||||
|
this.msg = codeEnum.getMsg(); |
||||
|
this.success = codeEnum.isSuccess(); |
||||
|
this.data = data; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse fail(){ |
||||
|
this.code = RegularError.ERRCODE_FAIL; |
||||
|
this.msg = RegularError.ERRCODE_FAIL_PHASE; |
||||
|
this.success = false; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse fail(String error){ |
||||
|
fail(); |
||||
|
this.msg = error; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse fail(int code){ |
||||
|
fail(); |
||||
|
this.code = code; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse fail(int code, String error){ |
||||
|
fail(); |
||||
|
this.code = code; |
||||
|
this.msg = error; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public JsonResponse fail(int code, String error, T obj){ |
||||
|
fail(); |
||||
|
this.code = code; |
||||
|
this.msg = error; |
||||
|
this.data = obj; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
package com.ccsens.scheduler.util; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @program: ptpro |
||||
|
* @description: |
||||
|
* @author: wu huijuan |
||||
|
* @create: 2019/10/21 10:37 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class PropUtil { |
||||
|
|
||||
|
public static String path; |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Value("${file.path:}") |
||||
|
public void setPath(String path) { |
||||
|
PropUtil.path = path; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,750 @@ |
|||||
|
package com.ccsens.scheduler.util; |
||||
|
|
||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
import org.springframework.data.redis.core.ZSetOperations; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.Set; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
@Component |
||||
|
public class RedisUtil { |
||||
|
@Resource |
||||
|
private RedisTemplate<String, Object> redisTemplate; |
||||
|
|
||||
|
/** |
||||
|
* 指定缓存失效时间 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param time 时间(秒) |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean expire(String key, long time) { |
||||
|
try { |
||||
|
if (time > 0) { |
||||
|
redisTemplate.expire(key, time, TimeUnit.SECONDS); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据key 获取过期时间 |
||||
|
* |
||||
|
* @param key 键 不能为null |
||||
|
* @return 时间(秒) 返回0代表为永久有效 |
||||
|
*/ |
||||
|
public long getExpire(String key) { |
||||
|
return redisTemplate.getExpire(key, TimeUnit.SECONDS); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 判断key是否存在 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return true 存在 false不存在 |
||||
|
*/ |
||||
|
public boolean hasKey(String key) { |
||||
|
try { |
||||
|
return redisTemplate.hasKey(key); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除缓存 |
||||
|
* |
||||
|
* @param key 可以传一个值 或多个 |
||||
|
*/ |
||||
|
@SuppressWarnings("unchecked") |
||||
|
public void del(String... key) { |
||||
|
if (key != null && key.length > 0) { |
||||
|
if (key.length == 1) { |
||||
|
redisTemplate.delete(key[0]); |
||||
|
} else { |
||||
|
redisTemplate.delete(CollectionUtils.arrayToList(key)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//============================String=============================
|
||||
|
|
||||
|
/** |
||||
|
* 普通缓存获取 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return 值 |
||||
|
*/ |
||||
|
public Object get(String key) { |
||||
|
return key == null ? null : redisTemplate.opsForValue().get(key); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 普通缓存放入 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @return true成功 false失败 |
||||
|
*/ |
||||
|
public boolean set(String key, Object value) { |
||||
|
try { |
||||
|
redisTemplate.opsForValue().set(key, value); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 普通缓存放入并设置时间 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @param seconds 时间(秒) time要大于0 如果time小于等于0 将设置无限期 |
||||
|
* @return true成功 false 失败 |
||||
|
*/ |
||||
|
public boolean set(String key, Object value, long seconds) { |
||||
|
try { |
||||
|
if (seconds > 0) { |
||||
|
redisTemplate.opsForValue().set(key, value, seconds, TimeUnit.SECONDS); |
||||
|
} else { |
||||
|
set(key, value); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 普通缓存放入 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @return true成功 false失败 |
||||
|
*/ |
||||
|
public boolean setNx(String key, Object value) { |
||||
|
try { |
||||
|
return redisTemplate.opsForValue().setIfAbsent(key, value); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 普通缓存放入并设置时间 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @param seconds 时间(秒) time要大于0 如果time小于等于0 将设置无限期 |
||||
|
* @return true成功 false 失败 |
||||
|
*/ |
||||
|
public boolean setNx(String key, Object value, long seconds) { |
||||
|
try { |
||||
|
if (seconds > 0) { |
||||
|
return redisTemplate.opsForValue().setIfAbsent(key, value, seconds, TimeUnit.SECONDS); |
||||
|
} else { |
||||
|
return setNx(key, value); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 递增 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param delta 要增加几(大于0) |
||||
|
* @return |
||||
|
*/ |
||||
|
public long incr(String key, long delta) { |
||||
|
if (delta < 0) { |
||||
|
throw new RuntimeException("递增因子必须大于0"); |
||||
|
} |
||||
|
return redisTemplate.opsForValue().increment(key, delta); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 递减 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param delta 要减少几(小于0) |
||||
|
* @return |
||||
|
*/ |
||||
|
public long decr(String key, long delta) { |
||||
|
if (delta < 0) { |
||||
|
throw new RuntimeException("递减因子必须大于0"); |
||||
|
} |
||||
|
return redisTemplate.opsForValue().increment(key, -delta); |
||||
|
} |
||||
|
|
||||
|
//================================Map=================================
|
||||
|
|
||||
|
/** |
||||
|
* HashGet |
||||
|
* |
||||
|
* @param key 键 不能为null |
||||
|
* @param item 项 不能为null |
||||
|
* @return 值 |
||||
|
*/ |
||||
|
public Object hget(String key, String item) { |
||||
|
return redisTemplate.opsForHash().get(key, item); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取hashKey对应的所有键值 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return 对应的多个键值 |
||||
|
*/ |
||||
|
public Map<Object, Object> hmget(String key) { |
||||
|
return redisTemplate.opsForHash().entries(key); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* HashSet |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param map 对应多个键值 |
||||
|
* @return true 成功 false 失败 |
||||
|
*/ |
||||
|
public boolean hmset(String key, Map<String, Object> map) { |
||||
|
try { |
||||
|
redisTemplate.opsForHash().putAll(key, map); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* HashSet 并设置时间 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param map 对应多个键值 |
||||
|
* @param time 时间(秒) |
||||
|
* @return true成功 false失败 |
||||
|
*/ |
||||
|
public boolean hmset(String key, Map<String, Object> map, long time) { |
||||
|
try { |
||||
|
redisTemplate.opsForHash().putAll(key, map); |
||||
|
if (time > 0) { |
||||
|
expire(key, time); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 向一张hash表中放入数据,如果不存在将创建 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param item 项 |
||||
|
* @param value 值 |
||||
|
* @return true 成功 false失败 |
||||
|
*/ |
||||
|
public boolean hset(String key, String item, Object value) { |
||||
|
try { |
||||
|
redisTemplate.opsForHash().put(key, item, value); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 向一张hash表中放入数据,如果不存在将创建 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param item 项 |
||||
|
* @param value 值 |
||||
|
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 |
||||
|
* @return true 成功 false失败 |
||||
|
*/ |
||||
|
public boolean hset(String key, String item, Object value, long time) { |
||||
|
try { |
||||
|
redisTemplate.opsForHash().put(key, item, value); |
||||
|
if (time > 0) { |
||||
|
expire(key, time); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除hash表中的值 |
||||
|
* |
||||
|
* @param key 键 不能为null |
||||
|
* @param item 项 可以使多个 不能为null |
||||
|
*/ |
||||
|
public void hdel(String key, Object... item) { |
||||
|
redisTemplate.opsForHash().delete(key, item); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 判断hash表中是否有该项的值 |
||||
|
* |
||||
|
* @param key 键 不能为null |
||||
|
* @param item 项 不能为null |
||||
|
* @return true 存在 false不存在 |
||||
|
*/ |
||||
|
public boolean hHasKey(String key, String item) { |
||||
|
return redisTemplate.opsForHash().hasKey(key, item); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* hash递增 如果不存在,就会创建一个 并把新增后的值返回 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param item 项 |
||||
|
* @param by 要增加几(大于0) |
||||
|
* @return |
||||
|
*/ |
||||
|
public double hincr(String key, String item, double by) { |
||||
|
return redisTemplate.opsForHash().increment(key, item, by); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* hash递减 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param item 项 |
||||
|
* @param by 要减少记(小于0) |
||||
|
* @return |
||||
|
*/ |
||||
|
public double hdecr(String key, String item, double by) { |
||||
|
return redisTemplate.opsForHash().increment(key, item, -by); |
||||
|
} |
||||
|
|
||||
|
//============================set=============================
|
||||
|
|
||||
|
/** |
||||
|
* 根据key获取Set中的所有值 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return |
||||
|
*/ |
||||
|
public Set<Object> sGet(String key) { |
||||
|
try { |
||||
|
return redisTemplate.opsForSet().members(key); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据value从一个set中查询,是否存在 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @return true 存在 false不存在 |
||||
|
*/ |
||||
|
public boolean sHasKey(String key, Object value) { |
||||
|
try { |
||||
|
return redisTemplate.opsForSet().isMember(key, value); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将数据放入set缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param values 值 可以是多个 |
||||
|
* @return 成功个数 |
||||
|
*/ |
||||
|
public long sSet(String key, Object... values) { |
||||
|
try { |
||||
|
return redisTemplate.opsForSet().add(key, values); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将set数据放入缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param time 时间(秒) |
||||
|
* @param values 值 可以是多个 |
||||
|
* @return 成功个数 |
||||
|
*/ |
||||
|
public long sSetAndTime(String key, long time, Object... values) { |
||||
|
try { |
||||
|
Long count = redisTemplate.opsForSet().add(key, values); |
||||
|
if (time > 0) expire(key, time); |
||||
|
return count; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取set缓存的长度 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return |
||||
|
*/ |
||||
|
public long sGetSetSize(String key) { |
||||
|
try { |
||||
|
return redisTemplate.opsForSet().size(key); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 移除值为value的 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param values 值 可以是多个 |
||||
|
* @return 移除的个数 |
||||
|
*/ |
||||
|
public long setRemove(String key, Object... values) { |
||||
|
try { |
||||
|
Long count = redisTemplate.opsForSet().remove(key, values); |
||||
|
return count; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
//===============================list=================================
|
||||
|
|
||||
|
/** |
||||
|
* 获取list缓存的内容 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param start 开始 |
||||
|
* @param end 结束 0 到 -1代表所有值 |
||||
|
* @return |
||||
|
*/ |
||||
|
public List<Object> lGet(String key, long start, long end) { |
||||
|
try { |
||||
|
return redisTemplate.opsForList().range(key, start, end); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取list缓存的长度 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @return |
||||
|
*/ |
||||
|
public long lGetListSize(String key) { |
||||
|
try { |
||||
|
return redisTemplate.opsForList().size(key); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 通过索引 获取list中的值 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 |
||||
|
* @return |
||||
|
*/ |
||||
|
public Object lGetIndex(String key, long index) { |
||||
|
try { |
||||
|
return redisTemplate.opsForList().index(key, index); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将list放入缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean lSet(String key, Object value) { |
||||
|
try { |
||||
|
redisTemplate.opsForList().rightPush(key, value); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将list放入缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @param time 时间(秒) |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean lSet(String key, Object value, long time) { |
||||
|
try { |
||||
|
redisTemplate.opsForList().rightPush(key, value); |
||||
|
if (time > 0) { |
||||
|
expire(key, time); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将list放入缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean lSet(String key, List<Object> value) { |
||||
|
try { |
||||
|
redisTemplate.opsForList().rightPushAll(key, value); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将list放入缓存 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param value 值 |
||||
|
* @param time 时间(秒) |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean lSet(String key, List<? extends Object> value, long time) { |
||||
|
try { |
||||
|
redisTemplate.opsForList().rightPushAll(key, value); |
||||
|
if (time > 0) { |
||||
|
expire(key, time); |
||||
|
} |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据索引修改list中的某条数据 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param index 索引 |
||||
|
* @param value 值 |
||||
|
* @return |
||||
|
*/ |
||||
|
public boolean lUpdateIndex(String key, long index, Object value) { |
||||
|
try { |
||||
|
redisTemplate.opsForList().set(key, index, value); |
||||
|
return true; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 移除N个值为value |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @param count 移除多少个 |
||||
|
* @param value 值 |
||||
|
* @return 移除的个数 |
||||
|
*/ |
||||
|
public long lRemove(String key, long count, Object value) { |
||||
|
try { |
||||
|
Long remove = redisTemplate.opsForList().remove(key, count, value); |
||||
|
return remove; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
//===============================zset=================================
|
||||
|
/** |
||||
|
* 获取sort set缓存的内容 |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param small 起始分数 |
||||
|
* @param max 结束分数 |
||||
|
* @return java.util.Set<java.lang.Object> |
||||
|
*/ |
||||
|
public Set<Object> zsGetByScore(String key, double small, double max) { |
||||
|
return redisTemplate.opsForZSet().rangeByScore(key, small, max); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取sort set缓存的内容 |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param start 开始 0:第一个元素 |
||||
|
* @param end 结束 -1:代表所有 |
||||
|
* @return java.util.Set<java.lang.Object> |
||||
|
*/ |
||||
|
public Set<Object> zsGet(String key, long start, long end) { |
||||
|
return redisTemplate.opsForZSet().range(key, start, end); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取sort set缓存的内容(包含分数) |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param start 开始 0:第一个元素 |
||||
|
* @param end 结束 -1:代表所有 |
||||
|
* @return java.util.Set<ZSetOperations.TypedTuple<Object>> |
||||
|
*/ |
||||
|
public Set<ZSetOperations.TypedTuple<Object>> zsGetWithScore(String key, long start, long end) { |
||||
|
return redisTemplate.opsForZSet().rangeWithScores(key, start, end); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 分数由高到低 获取sort set缓存的内容 |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param start 开始 0:第一个元素 |
||||
|
* @param end 结束 -1:代表所有 |
||||
|
* @return java.util.Set<java.lang.Object> |
||||
|
*/ |
||||
|
public Set<Object> zsRevGet(String key, long start, long end) { |
||||
|
return redisTemplate.opsForZSet().reverseRange(key, start, end); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 分数由高到低 获取sort set缓存的内容(包含分数) |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param start 开始 0:第一个元素 |
||||
|
* @param end 结束 -1:代表所有 |
||||
|
* @return java.util.Set<ZSetOperations.TypedTuple<Object>> |
||||
|
*/ |
||||
|
public Set<ZSetOperations.TypedTuple<Object>> zsRevGetWithScore(String key, long start, long end) { |
||||
|
return redisTemplate.opsForZSet().reverseRangeWithScores(key, start, end); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加zset |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param value |
||||
|
* @param score |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public boolean zsSet(String key, Object value, double score) { |
||||
|
return redisTemplate.opsForZSet().add(key, value, score); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加zset |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @param value |
||||
|
* @param score |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public boolean zsSet(String key, Object value, double score, long time) { |
||||
|
redisTemplate.opsForZSet().add(key, value, score); |
||||
|
if (time > 0) { |
||||
|
expire(key, time); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取zset长度 |
||||
|
* @author whj |
||||
|
* @date 2019/8/1 |
||||
|
* @param key |
||||
|
* @return |
||||
|
*/ |
||||
|
public Long zsGetSize(String key) { |
||||
|
return redisTemplate.opsForZSet().size(key); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除元素 |
||||
|
* @param key |
||||
|
* @param values |
||||
|
* @return |
||||
|
*/ |
||||
|
public Long zsDel(String key, Object... values) { |
||||
|
return redisTemplate.opsForZSet().remove(key, values); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取对应分数 |
||||
|
* @param key |
||||
|
* @param value |
||||
|
* @return |
||||
|
*/ |
||||
|
public Object zsGetScore(String key, Object value) { |
||||
|
return redisTemplate.opsForZSet().score(key, value); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询排第几 |
||||
|
* @param key |
||||
|
* @param value |
||||
|
* @return |
||||
|
*/ |
||||
|
public Long zsRank(String key, Object value) { |
||||
|
return redisTemplate.opsForZSet().rank(key, value); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询倒叙排第几 |
||||
|
* @param key |
||||
|
* @param value |
||||
|
* @return |
||||
|
*/ |
||||
|
public Long zsReverseRank(String key, Object value) { |
||||
|
return redisTemplate.opsForZSet().reverseRank(key, value); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
logging: |
||||
|
level: |
||||
|
com: |
||||
|
favorites: DEBUG |
||||
|
org: |
||||
|
hibernate: ERROR |
||||
|
springframework: |
||||
|
web: DEBUG |
||||
|
mybatis: |
||||
|
config-location: classpath:mybatis/mybatis-config.xml |
||||
|
mapper-locations: classpath*:mapper_*/*.xml |
||||
|
type-aliases-package: com.ccsens.ht.bean |
||||
|
server: |
||||
|
servlet: |
||||
|
encoding: |
||||
|
charset: UTF-8 |
||||
|
enabled: true |
||||
|
force: true |
||||
|
spring: |
||||
|
servlet: |
||||
|
multipart: |
||||
|
max-file-size: 10GB |
||||
|
max-request-size: 100GB |
||||
|
mvc: |
||||
|
log-request-details: true |
||||
|
|
||||
|
|
||||
@ -0,0 +1,22 @@ |
|||||
|
server: |
||||
|
port: 8001 |
||||
|
spring: |
||||
|
snowflake: |
||||
|
datacenterId: 1 |
||||
|
workerId: 1 |
||||
|
datasource: |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
redis: |
||||
|
database: 0 |
||||
|
host: 127.0.0.1 |
||||
|
jedis: |
||||
|
pool: |
||||
|
max-active: 200 |
||||
|
max-idle: 10 |
||||
|
max-wait: -1ms |
||||
|
min-idle: 0 |
||||
|
password: '' |
||||
|
port: 6379 |
||||
|
timeout: 1000ms |
||||
|
swagger: |
||||
|
enable: true |
||||
@ -0,0 +1,22 @@ |
|||||
|
server: |
||||
|
port: 8000 |
||||
|
spring: |
||||
|
snowflake: |
||||
|
datacenterId: 1 |
||||
|
workerId: 1 |
||||
|
datasource: |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
redis: |
||||
|
database: 0 |
||||
|
host: 127.0.0.1 |
||||
|
jedis: |
||||
|
pool: |
||||
|
max-active: 200 |
||||
|
max-idle: 10 |
||||
|
max-wait: -1ms |
||||
|
min-idle: 0 |
||||
|
password: |
||||
|
port: 6379 |
||||
|
timeout: 1000ms |
||||
|
swagger: |
||||
|
enable: false |
||||
@ -0,0 +1,24 @@ |
|||||
|
server: |
||||
|
port: 8000 |
||||
|
spring: |
||||
|
snowflake: |
||||
|
datacenterId: 1 |
||||
|
workerId: 1 |
||||
|
datasource: |
||||
|
type: com.alibaba.druid.pool.DruidDataSource |
||||
|
redis: |
||||
|
database: 0 |
||||
|
host: 127.0.0.1 |
||||
|
jedis: |
||||
|
pool: |
||||
|
max-active: 200 |
||||
|
max-idle: 10 |
||||
|
max-wait: -1ms |
||||
|
min-idle: 0 |
||||
|
password: '' |
||||
|
port: 6379 |
||||
|
timeout: 1000ms |
||||
|
swagger: |
||||
|
enable: true |
||||
|
|
||||
|
|
||||
@ -0,0 +1,4 @@ |
|||||
|
spring: |
||||
|
profiles: |
||||
|
active: dev |
||||
|
include: common |
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* _ooOoo_ |
||||
|
* o8888888o |
||||
|
* 88" . "88 |
||||
|
* (| -_- |) |
||||
|
* O\ = /O |
||||
|
* ___/`---'\____ |
||||
|
* . ' \\| |// `. |
||||
|
* / \\||| : |||// \ |
||||
|
* / _||||| -:- |||||- \ |
||||
|
* | | \\\ - /// | | |
||||
|
* | \_| ''\---/'' | | |
||||
|
* \ .-\__ `-` ___/-. / |
||||
|
* ___`. .' /--.--\ `. . __ |
||||
|
* ."" '< `.___\_<|>_/___.' >'"". |
||||
|
* | | : `- \`.;`\ _ /`;.`/ - ` : | | |
||||
|
* \ \ `-. \_ __\ /__ _/ .-` / / |
||||
|
* ======`-.____`-.___\_____/___.-`____.-'====== |
||||
|
* `=---=' |
||||
|
* ............................................. |
||||
|
* 佛曰:bug泛滥,我已瘫痪! |
||||
|
*/ |
||||
@ -0,0 +1,33 @@ |
|||||
|
spring: |
||||
|
datasource: |
||||
|
druid: |
||||
|
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
||||
|
driverClassName: com.mysql.cj.jdbc.Driver |
||||
|
dynamicUrl: jdbc:mysql://localhost:3306/${schema} |
||||
|
filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' |
||||
|
filterName: druidFilter |
||||
|
filterProfileEnable: true |
||||
|
filterUrlPattern: /* |
||||
|
filters: stat,wall |
||||
|
initialSize: 5 |
||||
|
maxActive: 20 |
||||
|
maxPoolPreparedStatementPerConnectionSize: 20 |
||||
|
maxWait: 60000 |
||||
|
minEvictableIdleTimeMillis: 300000 |
||||
|
minIdle: 5 |
||||
|
password: 68073a279b399baa1fa12cf39bfbb65bfc1480ffee7b659ccc81cf19be8c4473 |
||||
|
poolPreparedStatements: true |
||||
|
servletLogSlowSql: true |
||||
|
servletLoginPassword: 111111 |
||||
|
servletLoginUsername: druid |
||||
|
servletName: druidServlet |
||||
|
servletResetEnable: true |
||||
|
servletUrlMapping: /druid/* |
||||
|
testOnBorrow: false |
||||
|
testOnReturn: false |
||||
|
testWhileIdle: true |
||||
|
timeBetweenEvictionRunsMillis: 60000 |
||||
|
url: jdbc:mysql://49.233.89.188:3306/scheduler?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai |
||||
|
username: root |
||||
|
validationQuery: SELECT 1 FROM DUAL |
||||
|
env: CCSENS_TALL |
||||
@ -0,0 +1,34 @@ |
|||||
|
spring: |
||||
|
datasource: |
||||
|
druid: |
||||
|
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
||||
|
driverClassName: com.mysql.cj.jdbc.Driver |
||||
|
dynamicUrl: jdbc:mysql://127.0.0.1:3306/${schema} |
||||
|
filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' |
||||
|
filterName: druidFilter |
||||
|
filterProfileEnable: true |
||||
|
filterUrlPattern: /* |
||||
|
filters: stat,wall |
||||
|
initialSize: 5 |
||||
|
maxActive: 20 |
||||
|
maxPoolPreparedStatementPerConnectionSize: 20 |
||||
|
maxWait: 60000 |
||||
|
minEvictableIdleTimeMillis: 300000 |
||||
|
minIdle: 5 |
||||
|
# password: 7cdefb88e0b8c8a401b66a83ee0cf80387461268074d1c3dcb146ab485318633 |
||||
|
password: |
||||
|
poolPreparedStatements: true |
||||
|
servletLogSlowSql: true |
||||
|
servletLoginPassword: 111111 |
||||
|
servletLoginUsername: druid |
||||
|
servletName: druidServlet |
||||
|
servletResetEnable: true |
||||
|
servletUrlMapping: /druid/* |
||||
|
testOnBorrow: false |
||||
|
testOnReturn: false |
||||
|
testWhileIdle: true |
||||
|
timeBetweenEvictionRunsMillis: 60000 |
||||
|
url: jdbc:mysql://127.0.0.1/scheduler?useUnicode=true&characterEncoding=UTF-8 |
||||
|
username: root |
||||
|
validationQuery: SELECT 1 FROM DUAL |
||||
|
env: CCSENS_HEALTH |
||||
@ -0,0 +1,34 @@ |
|||||
|
spring: |
||||
|
datasource: |
||||
|
druid: |
||||
|
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
||||
|
driverClassName: com.mysql.cj.jdbc.Driver |
||||
|
dynamicUrl: jdbc:mysql://localhost:3306/${schema} |
||||
|
filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' |
||||
|
filterName: druidFilter |
||||
|
filterProfileEnable: true |
||||
|
filterUrlPattern: /* |
||||
|
filters: stat,wall |
||||
|
initialSize: 5 |
||||
|
maxActive: 20 |
||||
|
maxPoolPreparedStatementPerConnectionSize: 20 |
||||
|
maxWait: 60000 |
||||
|
minEvictableIdleTimeMillis: 300000 |
||||
|
minIdle: 5 |
||||
|
# password: |
||||
|
password: 68073a279b399baa1fa12cf39bfbb65bfc1480ffee7b659ccc81cf19be8c4473 |
||||
|
poolPreparedStatements: true |
||||
|
servletLogSlowSql: true |
||||
|
servletLoginPassword: 111111 |
||||
|
servletLoginUsername: druid |
||||
|
servletName: druidServlet |
||||
|
servletResetEnable: true |
||||
|
servletUrlMapping: /druid/* |
||||
|
testOnBorrow: false |
||||
|
testOnReturn: false |
||||
|
testWhileIdle: true |
||||
|
timeBetweenEvictionRunsMillis: 60000 |
||||
|
url: jdbc:mysql://test.tall.wiki/scheduler?useUnicode=true&characterEncoding=UTF-8 |
||||
|
username: root |
||||
|
validationQuery: SELECT 1 FROM DUAL |
||||
|
env: CCSENS_TALL |
||||
@ -0,0 +1,196 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 --> |
||||
|
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true --> |
||||
|
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 --> |
||||
|
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --> |
||||
|
<configuration scan="true" scanPeriod="10 seconds"> |
||||
|
|
||||
|
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />--> |
||||
|
|
||||
|
<contextName>logback</contextName> |
||||
|
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 --> |
||||
|
<property name="log.path" value="/home/scheduler/log/" /> |
||||
|
|
||||
|
<!-- 彩色日志 --> |
||||
|
<!-- 彩色日志依赖的渲染类 --> |
||||
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> |
||||
|
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> |
||||
|
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> |
||||
|
<!-- 彩色日志格式 --> |
||||
|
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> |
||||
|
|
||||
|
|
||||
|
<!--输出到控制台--> |
||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> |
||||
|
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> |
||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
||||
|
<level>info</level> |
||||
|
</filter> |
||||
|
<encoder> |
||||
|
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern> |
||||
|
<!-- 设置字符集 --> |
||||
|
<charset>UTF-8</charset> |
||||
|
</encoder> |
||||
|
</appender> |
||||
|
|
||||
|
|
||||
|
<!--输出到文件--> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 DEBUG 日志 --> |
||||
|
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${log.path}/log_debug.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 日志归档 --> |
||||
|
<fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录debug级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>debug</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 INFO 日志 --> |
||||
|
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${log.path}/log_info.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<!-- 每天日志归档路径以及格式 --> |
||||
|
<fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录info级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>info</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- 时间滚动输出 level为 WARN 日志 --> |
||||
|
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${log.path}/log_warn.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录warn级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>warn</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
|
||||
|
<!-- 时间滚动输出 level为 ERROR 日志 --> |
||||
|
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<!-- 正在记录的日志文件的路径及文件名 --> |
||||
|
<file>${log.path}/log_error.log</file> |
||||
|
<!--日志文件输出格式--> |
||||
|
<encoder> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
|
</encoder> |
||||
|
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
|
<maxFileSize>100MB</maxFileSize> |
||||
|
</timeBasedFileNamingAndTriggeringPolicy> |
||||
|
<!--日志文件保留天数--> |
||||
|
<maxHistory>15</maxHistory> |
||||
|
</rollingPolicy> |
||||
|
<!-- 此日志文件只记录ERROR级别的 --> |
||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
||||
|
<level>ERROR</level> |
||||
|
<onMatch>ACCEPT</onMatch> |
||||
|
<onMismatch>DENY</onMismatch> |
||||
|
</filter> |
||||
|
</appender> |
||||
|
|
||||
|
<!-- |
||||
|
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、 |
||||
|
以及指定<appender>。<logger>仅有一个name属性, |
||||
|
一个可选的level和一个可选的addtivity属性。 |
||||
|
name:用来指定受此logger约束的某一个包或者具体的某一个类。 |
||||
|
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF, |
||||
|
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。 |
||||
|
如果未设置此属性,那么当前logger将会继承上级的级别。 |
||||
|
addtivity:是否向上级logger传递打印信息。默认是true。 |
||||
|
--> |
||||
|
<!--<logger name="org.springframework.web" level="info"/>--> |
||||
|
<!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>--> |
||||
|
<!-- |
||||
|
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作: |
||||
|
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息 |
||||
|
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别: |
||||
|
--> |
||||
|
|
||||
|
|
||||
|
<!-- |
||||
|
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性 |
||||
|
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF, |
||||
|
不能设置为INHERITED或者同义词NULL。默认是DEBUG |
||||
|
可以包含零个或多个元素,标识这个appender将会添加到这个logger。 |
||||
|
--> |
||||
|
|
||||
|
<!--开发环境:打印控制台--> |
||||
|
<springProfile name="dev"> |
||||
|
<logger name="com.ccsens.ptpro.persist.*" level="debug"/> |
||||
|
</springProfile> |
||||
|
|
||||
|
<root level="info"> |
||||
|
<appender-ref ref="CONSOLE" /> |
||||
|
<appender-ref ref="DEBUG_FILE" /> |
||||
|
<appender-ref ref="INFO_FILE" /> |
||||
|
<appender-ref ref="WARN_FILE" /> |
||||
|
<appender-ref ref="ERROR_FILE" /> |
||||
|
</root> |
||||
|
|
||||
|
<!--生产环境:输出到文件--> |
||||
|
<!--<springProfile name="pro">--> |
||||
|
<!--<root level="info">--> |
||||
|
<!--<appender-ref ref="CONSOLE" />--> |
||||
|
<!--<appender-ref ref="DEBUG_FILE" />--> |
||||
|
<!--<appender-ref ref="INFO_FILE" />--> |
||||
|
<!--<appender-ref ref="ERROR_FILE" />--> |
||||
|
<!--<appender-ref ref="WARN_FILE" />--> |
||||
|
<!--</root>--> |
||||
|
<!--</springProfile>--> |
||||
|
|
||||
|
</configuration> |
||||
@ -0,0 +1,68 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE generatorConfiguration |
||||
|
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" |
||||
|
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> |
||||
|
|
||||
|
<generatorConfiguration> |
||||
|
<context id="MySQL" targetRuntime="MyBatis3"> |
||||
|
<!-- 为生成的Java模型创建一个toString方法 --> |
||||
|
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin> |
||||
|
|
||||
|
<!-- 自定义的序列化 类文件 插件 --> |
||||
|
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> |
||||
|
|
||||
|
<!-- 重新生成xml文件,而不是追加 --> |
||||
|
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" /> |
||||
|
|
||||
|
<commentGenerator> |
||||
|
<!-- 是否去除自动生成的注释 true:是 : false:否 --> |
||||
|
<property name="suppressAllComments" value="true" /> |
||||
|
</commentGenerator> |
||||
|
|
||||
|
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> |
||||
|
<jdbcConnection driverClass="com.mysql.jdbc.Driver" |
||||
|
connectionURL="jdbc:mysql://49.233.89.188:3306/scheduler?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false" |
||||
|
userId="root" |
||||
|
password="po3OynBO[M3579p6L7)o"> |
||||
|
</jdbcConnection> |
||||
|
|
||||
|
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 |
||||
|
NUMERIC 类型解析为java.math.BigDecimal --> |
||||
|
<javaTypeResolver> |
||||
|
<property name="forceBigDecimals" value="true" /> |
||||
|
</javaTypeResolver> |
||||
|
|
||||
|
<!-- targetProject:生成PO类的位置 --> |
||||
|
<javaModelGenerator targetPackage="com.ccsens.scheduler.bean.po" |
||||
|
targetProject=".\src\main\java"> |
||||
|
<!-- enableSubPackages:是否让schema作为包的后缀 --> |
||||
|
<property name="enableSubPackages" value="false" /> |
||||
|
<!-- 从数据库返回的值被清理前后的空格 --> |
||||
|
<property name="trimStrings" value="true" /> |
||||
|
</javaModelGenerator> |
||||
|
|
||||
|
<!-- targetProject:mapper映射文件生成的位置 --> |
||||
|
<sqlMapGenerator targetPackage="mapper_raw" |
||||
|
targetProject=".\src\main\resources"> |
||||
|
<!-- enableSubPackages:是否让schema作为包的后缀 --> |
||||
|
<property name="enableSubPackages" value="false" /> |
||||
|
</sqlMapGenerator> |
||||
|
|
||||
|
<!-- targetPackage:mapper接口生成的位置 --> |
||||
|
<javaClientGenerator type="XMLMAPPER" |
||||
|
targetPackage="com.ccsens.scheduler.persist.mapper" |
||||
|
targetProject=".\src\main\java"> |
||||
|
<!-- enableSubPackages:是否让schema作为包的后缀 --> |
||||
|
<property name="enableSubPackages" value="false" /> |
||||
|
</javaClientGenerator> |
||||
|
|
||||
|
<table tableName="t_file_commit" domainObjectName="FileCommit"/> |
||||
|
|
||||
|
|
||||
|
|
||||
|
<!-- 有些表的字段需要指定java类型 |
||||
|
<table schema="" tableName=""> |
||||
|
<columnOverride column="" javaType="" /> |
||||
|
</table> --> |
||||
|
</context> |
||||
|
</generatorConfiguration> |
||||
@ -0,0 +1,64 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<!DOCTYPE configuration |
||||
|
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" |
||||
|
"http://mybatis.org/dtd/mybatis-3-config.dtd"> |
||||
|
|
||||
|
<configuration> |
||||
|
<!-- 全局参数 --> |
||||
|
<settings> |
||||
|
<!-- 打印SQL语句 --> |
||||
|
<setting name="logImpl" value="STDOUT_LOGGING" /> |
||||
|
<!-- 使全局的映射器启用或禁用缓存。 --> |
||||
|
<setting name="cacheEnabled" value="true"/> |
||||
|
<!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 --> |
||||
|
<setting name="lazyLoadingEnabled" value="true"/> |
||||
|
<!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 --> |
||||
|
<setting name="aggressiveLazyLoading" value="true"/> |
||||
|
<!-- 是否允许单条sql 返回多个数据集 (取决于驱动的兼容性) default:true --> |
||||
|
<setting name="multipleResultSetsEnabled" value="true"/> |
||||
|
<!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true --> |
||||
|
<setting name="useColumnLabel" value="true"/> |
||||
|
<!-- 允许JDBC 生成主键。需要驱动器支持。如果设为了true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。 default:false --> |
||||
|
<setting name="useGeneratedKeys" value="true"/> |
||||
|
<!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE:不隐射 PARTIAL:部分 FULL:全部 --> |
||||
|
<setting name="autoMappingBehavior" value="PARTIAL"/> |
||||
|
<!-- 这是默认的执行类型 (SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句;BATCH: 执行器可以重复执行语句和批量更新) --> |
||||
|
<setting name="defaultExecutorType" value="SIMPLE"/> |
||||
|
<!-- 使用驼峰命名法转换字段。 --> |
||||
|
<setting name="mapUnderscoreToCamelCase" value="true"/> |
||||
|
<!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session --> |
||||
|
<setting name="localCacheScope" value="SESSION"/> |
||||
|
<!-- 设置但JDBC类型为空时,某些驱动程序 要指定值,default:OTHER,插入空值时不需要指定类型 --> |
||||
|
<setting name="jdbcTypeForNull" value="NULL"/> |
||||
|
</settings> |
||||
|
|
||||
|
<typeAliases> |
||||
|
<typeAlias alias="Integer" type="java.lang.Integer" /> |
||||
|
<typeAlias alias="Long" type="java.lang.Long" /> |
||||
|
<typeAlias alias="Map" type="java.util.Map" /> |
||||
|
<typeAlias alias="HashMap" type="java.util.HashMap" /> |
||||
|
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" /> |
||||
|
<typeAlias alias="ArrayList" type="java.util.ArrayList" /> |
||||
|
<typeAlias alias="LinkedList" type="java.util.LinkedList" /> |
||||
|
<typeAlias alias="List" type="java.util.List" /> |
||||
|
<typeAlias alias="String" type="java.lang.String" /> |
||||
|
</typeAliases> |
||||
|
|
||||
|
<plugins> |
||||
|
<!-- com.github.pagehelper为PageHelper类所在包名 --> |
||||
|
<plugin interceptor="com.github.pagehelper.PageHelper"> |
||||
|
<property name="dialect" value="mysql"/> |
||||
|
<!-- 该参数默认为false --> |
||||
|
<!-- 设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用 --> |
||||
|
<!-- 和startPage中的pageNum效果一样--> |
||||
|
<property name="offsetAsPageNum" value="false"/> |
||||
|
<!-- 该参数默认为false --> |
||||
|
<!-- 设置为true时,使用RowBounds分页会进行count查询 --> |
||||
|
<property name="rowBoundsWithCount" value="false"/> |
||||
|
<property name="pageSizeZero" value="true"/> |
||||
|
<property name="reasonable" value="false"/> |
||||
|
<property name="supportMethodsArguments" value="false"/> |
||||
|
<property name="returnPageInfo" value="none"/> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
</configuration> |
||||
Loading…
Reference in new issue