34 changed files with 3058 additions and 0 deletions
@ -0,0 +1,165 @@ |
|||||
|
<?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>page</artifactId> |
||||
|
|
||||
|
<dependencies> |
||||
|
<!-- 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> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba</groupId> |
||||
|
<artifactId>fastjson</artifactId> |
||||
|
<version>1.2.62</version> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
|
||||
|
</project> |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.ccsens.page; |
||||
|
|
||||
|
import org.mybatis.spring.annotation.MapperScan; |
||||
|
import org.springframework.boot.SpringApplication; |
||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
import org.springframework.boot.web.servlet.ServletComponentScan; |
||||
|
import org.springframework.scheduling.annotation.EnableAsync; |
||||
|
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
|
|
||||
|
/** |
||||
|
* @description: 通用页面 |
||||
|
* @author: whj |
||||
|
* @time: 2021/9/14 20:51 |
||||
|
*/ |
||||
|
@EnableScheduling |
||||
|
@MapperScan(basePackages = {"com.ccsens.page.persist.*"}) |
||||
|
@ServletComponentScan |
||||
|
@EnableAsync |
||||
|
@SpringBootApplication(scanBasePackages = "com.ccsens") |
||||
|
public class PageApplication { |
||||
|
public static void main(String[] args) { |
||||
|
SpringApplication.run(PageApplication.class, args); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package com.ccsens.page.config; |
||||
|
|
||||
|
import com.ccsens.page.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; |
||||
|
} |
||||
|
|
||||
|
// @Bean
|
||||
|
// public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
||||
|
// return new RestTemplate(factory);
|
||||
|
// }
|
||||
|
//
|
||||
|
// @Bean
|
||||
|
// public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
|
||||
|
// SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
|
// factory.setReadTimeout(10000);
|
||||
|
// factory.setConnectTimeout(10000);
|
||||
|
// return factory;
|
||||
|
// }
|
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
package com.ccsens.page.config;//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.page.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.page.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,25 @@ |
|||||
|
package com.ccsens.page.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.page.config;//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,64 @@ |
|||||
|
package com.ccsens.page.config;//package com.ccsens.scheduler.config;
|
||||
|
//
|
||||
|
//import cn.hutool.core.io.resource.ClassPathResource;
|
||||
|
//import org.quartz.Scheduler;
|
||||
|
//import org.quartz.ee.servlet.QuartzInitializerListener;
|
||||
|
//import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
|
//import org.springframework.context.annotation.Bean;
|
||||
|
//import org.springframework.context.annotation.Configuration;
|
||||
|
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
//
|
||||
|
//import java.io.IOException;
|
||||
|
//import java.util.Properties;
|
||||
|
//
|
||||
|
///**
|
||||
|
// * @description:
|
||||
|
// * @author: whj
|
||||
|
// * @time: 2021/6/30 15:48
|
||||
|
// */
|
||||
|
//@Configuration
|
||||
|
//public class SchedulerConfig {
|
||||
|
// /**
|
||||
|
// * 读取quartz.properties 文件
|
||||
|
// * 将值初始化
|
||||
|
// * @return
|
||||
|
// */
|
||||
|
// @Bean
|
||||
|
// public Properties quartzProperties() throws IOException {
|
||||
|
// PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
|
||||
|
// propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
|
||||
|
// propertiesFactoryBean.afterPropertiesSet();
|
||||
|
// return propertiesFactoryBean.getObject();
|
||||
|
// }
|
||||
|
//
|
||||
|
// /**
|
||||
|
// * 将配置文件的数据加载到SchedulerFactoryBean中
|
||||
|
// * @return
|
||||
|
// * @throws IOException
|
||||
|
// */
|
||||
|
// @Bean
|
||||
|
// public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
|
||||
|
// SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
|
||||
|
// schedulerFactoryBean.setQuartzProperties();
|
||||
|
// return schedulerFactoryBean;
|
||||
|
// }
|
||||
|
//
|
||||
|
// /**
|
||||
|
// * 初始化监听器
|
||||
|
// * @return
|
||||
|
// */
|
||||
|
// @Bean
|
||||
|
// public QuartzInitializerListener executorListener(){
|
||||
|
// return new QuartzInitializerListener();
|
||||
|
// }
|
||||
|
//
|
||||
|
// /**
|
||||
|
// * 获得Scheduler 对象
|
||||
|
// * @return
|
||||
|
// * @throws IOException
|
||||
|
// */
|
||||
|
// @Bean
|
||||
|
// public Scheduler scheduler() throws IOException {
|
||||
|
// return schedulerFactoryBean().getScheduler();
|
||||
|
// }
|
||||
|
//}
|
||||
@ -0,0 +1,77 @@ |
|||||
|
package com.ccsens.page.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,120 @@ |
|||||
|
package com.ccsens.page.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/"); |
||||
|
registry.addResourceHandler("/static/**") |
||||
|
.addResourceLocations("classpath:/static/"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 配置数据源(单数据源) |
||||
|
*/ |
||||
|
@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.page.config;//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.page.exception; |
||||
|
|
||||
|
import com.ccsens.page.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,166 @@ |
|||||
|
package com.ccsens.page.intercept; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import com.ccsens.page.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.ArrayList; |
||||
|
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 in (0, 1)"; |
||||
|
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("andRecStatusIn", List.class); |
||||
|
List<Byte> params = new ArrayList<>(); |
||||
|
params.add(Constant.REC_STATUS.Normal.value); |
||||
|
params.add(Constant.REC_STATUS.Disabled.value); |
||||
|
andIsDelEqualTo.invoke(criteria, params); |
||||
|
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 (condition instanceof String && ((String) condition).contains("rec_status ")) { |
||||
|
hasDel = true; |
||||
|
} |
||||
|
} |
||||
|
if (!hasDel) { |
||||
|
|
||||
|
Method andIsDelEqualTo = criteria.getClass().getMethod("andRecStatusIn", List.class); |
||||
|
List<Byte> recParams = new ArrayList<>(); |
||||
|
recParams.add(Constant.REC_STATUS.Normal.value); |
||||
|
recParams.add(Constant.REC_STATUS.Disabled.value); |
||||
|
andIsDelEqualTo.invoke(criteria, recParams); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@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,9 @@ |
|||||
|
package com.ccsens.page.persist; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @author wei |
||||
|
*/ |
||||
|
public interface IMessageDao { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.ccsens.page.persist; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.data.mongodb.core.MongoTemplate; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
/** |
||||
|
* @author wei |
||||
|
*/ |
||||
|
@Repository |
||||
|
public class MessageDao implements IMessageDao { |
||||
|
private static final String COLLECTION_RAW_MESSAGE = "col_message_raw"; |
||||
|
private static final String COLLECTION_MESSAGE = "col_message"; |
||||
|
@Autowired |
||||
|
private MongoTemplate mongoTemplate; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
package com.ccsens.page.util; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
|
||||
|
@Getter |
||||
|
public enum CodeEnum { |
||||
|
/** |
||||
|
* 异常 |
||||
|
*/ |
||||
|
SUCCESS(200, "ok", true), |
||||
|
SYS_ERROR(500, "网络繁忙,请您稍后重试", false), |
||||
|
FILE_FORMAT_ERROR(1, "文件格式错误", true), |
||||
|
PARAM_NULL(2, "请检查您的参数是否填写完整。", true), |
||||
|
URL_ERROR(3, "请求路径转换异常", true), |
||||
|
JOB_EXISTED(4, "任务正在处理中,请不要重复添加或修改任务。", true), |
||||
|
JOB_ADD_FAIL(5, "任务添加失败,请检查参数后重试。", true), |
||||
|
JOB_NOT_EXISTED(6, "任务不存在。", true), |
||||
|
JOB_MODIFY_FAIL(7, "任务修改失败,请检查参数后重试。", true), |
||||
|
JOB_PAUSE_FAIL(8, "任务暂停失败。", true), |
||||
|
JOB_RESUME_FAIL(9, "任务重启失败。", true), |
||||
|
JOB_DEL_FAIL(10, "任务删除失败。", true), |
||||
|
; |
||||
|
|
||||
|
public static CodeEnum getByCode(int code) { |
||||
|
for (CodeEnum codeEnum: CodeEnum.values()) { |
||||
|
if (codeEnum.getCode() == code) { |
||||
|
return codeEnum; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
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,92 @@ |
|||||
|
package com.ccsens.page.util; |
||||
|
|
||||
|
|
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
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 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 static class Quartz { |
||||
|
public static final String QZ_JOB_GROUP_NAME = "JOB_GROUP_NAME"; |
||||
|
public static final String QZ_TRIGGER_GROUP_NAME = "TRIGGER_GROUP_NAME"; |
||||
|
public static final String QZ_JOB_NAME_PREFIX = "job_name_"; |
||||
|
public static final String QZ_TRIGGER_NAME_PREFIX = "trigger_name_"; |
||||
|
public static final String JOB_KEY_PREFIX = "scheduler:job:"; |
||||
|
public static final long JOB_KEY_EXPIRE_TIME = 60; |
||||
|
public static final String JOB_KEY_SPLIT = ":"; |
||||
|
public static final Map<Byte, String> JOB = new HashMap<>(); |
||||
|
static { |
||||
|
JOB.put((byte)0,"com.ccsens.scheduler.service.CoreJobService"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static class NotifyWay{ |
||||
|
public static final byte HTTP = 0; |
||||
|
public static final byte MQ = 1; |
||||
|
public static final byte EMAIL = 2; |
||||
|
public static final byte SMS = 3; |
||||
|
} |
||||
|
|
||||
|
public static class Split { |
||||
|
/** |
||||
|
* 多个通知路径分割符 |
||||
|
*/ |
||||
|
public static final String NOTIFY_URL = "[,;]"; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// @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;
|
||||
|
// }
|
||||
|
// }
|
||||
|
// }
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
package com.ccsens.page.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.page.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.page.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,155 @@ |
|||||
|
package com.ccsens.page.util; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.ccsens.page.exception.BaseException; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.http.HttpEntity; |
||||
|
import org.springframework.http.HttpHeaders; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.util.LinkedMultiValueMap; |
||||
|
import org.springframework.util.MultiValueMap; |
||||
|
import org.springframework.web.client.RestTemplate; |
||||
|
|
||||
|
import javax.annotation.PostConstruct; |
||||
|
import javax.annotation.Resource; |
||||
|
import java.net.URI; |
||||
|
import java.net.URISyntaxException; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class RestTemplateUtil { |
||||
|
|
||||
|
@Resource |
||||
|
private RestTemplate restTemplate; |
||||
|
|
||||
|
private static RestTemplateUtil util; |
||||
|
|
||||
|
@PostConstruct |
||||
|
public void init(){ |
||||
|
util = this; |
||||
|
util.restTemplate = this.restTemplate; |
||||
|
} |
||||
|
|
||||
|
public static Object getForEntity(String url, Map<String, Object> params, Class<?> returnClass) { |
||||
|
|
||||
|
if (params != null && !params.isEmpty()) { |
||||
|
String questionMark = "?"; |
||||
|
String assignMark = "="; |
||||
|
String andMark = "&"; |
||||
|
if (!url.contains(questionMark)) { |
||||
|
url += questionMark; |
||||
|
} |
||||
|
for (String key : params.keySet()) { |
||||
|
if (url.endsWith(questionMark)) { |
||||
|
url += key + assignMark +params.get(key); |
||||
|
} else { |
||||
|
url += andMark + key + assignMark +params.get(key); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
log.info("url:{}, params:{}", url, params); |
||||
|
ResponseEntity<String> entity = util.restTemplate.getForEntity(url, String.class); |
||||
|
log.info("entity:{}",entity); |
||||
|
return JSONObject.parseObject(entity.getBody(), returnClass); |
||||
|
} |
||||
|
|
||||
|
public static String postBody(String url, Object params) { |
||||
|
log.info("路径:{}, 参数:{}", url, params); |
||||
|
HttpHeaders httpHeaders = new HttpHeaders(); |
||||
|
MediaType type= MediaType.parseMediaType("application/json;charset=UTF-8"); |
||||
|
httpHeaders.setContentType(type); |
||||
|
|
||||
|
JSONObject json = JSON.parseObject(JSON.toJSONString(params)); |
||||
|
HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(json,httpHeaders); |
||||
|
URI uri; |
||||
|
try { |
||||
|
uri = new URI(url); |
||||
|
}catch (URISyntaxException e) { |
||||
|
log.error("转换路径异常", e); |
||||
|
throw new BaseException(CodeEnum.URL_ERROR); |
||||
|
} |
||||
|
|
||||
|
ResponseEntity<String> response = util.restTemplate.postForEntity(uri, objectHttpEntity, String.class); |
||||
|
log.info("返回:{}", response); |
||||
|
return response.getBody(); |
||||
|
} |
||||
|
|
||||
|
public static String postBody(String url, List<? extends Object> params) { |
||||
|
log.info("路径:{}, 参数:{}", url, params); |
||||
|
HttpHeaders httpHeaders = new HttpHeaders(); |
||||
|
MediaType type= MediaType.parseMediaType("application/json;charset=UTF-8"); |
||||
|
httpHeaders.setContentType(type); |
||||
|
|
||||
|
HttpEntity<List<? extends Object>> objectHttpEntity = new HttpEntity<>(params,httpHeaders); |
||||
|
URI uri; |
||||
|
try { |
||||
|
uri = new URI(url); |
||||
|
}catch (URISyntaxException e) { |
||||
|
log.error("转换路径异常:{}", e); |
||||
|
throw new BaseException(CodeEnum.URL_ERROR); |
||||
|
} |
||||
|
|
||||
|
ResponseEntity<String> response = util.restTemplate.postForEntity(uri, objectHttpEntity, String.class); |
||||
|
log.info("返回:{}", response); |
||||
|
return response.getBody(); |
||||
|
} |
||||
|
public static String postUrlEncode(String url, Object params) { |
||||
|
log.info("请求路径:{},请求参数:{}", url, params); |
||||
|
MultiValueMap<String, Object> paramMap; |
||||
|
if (params == null) { |
||||
|
paramMap = new LinkedMultiValueMap<>(); |
||||
|
} else { |
||||
|
JSONObject json = JSON.parseObject(JSON.toJSONString(params)); |
||||
|
paramMap = transMultiValueMap(json); |
||||
|
} |
||||
|
|
||||
|
HttpHeaders headers = new HttpHeaders(); |
||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
||||
|
HttpEntity<MultiValueMap> formEntity = new HttpEntity<>(paramMap, headers); |
||||
|
ResponseEntity<String> result = util.restTemplate.postForEntity(url, formEntity, String.class); |
||||
|
log.info("接口返回结果:{}", result); |
||||
|
return result.getBody(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 发送multipart/form-data |
||||
|
* @author whj |
||||
|
* @date 2019/8/20 |
||||
|
* @param url 路径 |
||||
|
* @param params 参数 |
||||
|
* @return com.alibaba.fastjson.JSONObject |
||||
|
*/ |
||||
|
public static JSONObject postImg(String url, JSONObject params) { |
||||
|
log.info("请求路径:{},请求参数:{}", url, params); |
||||
|
HttpHeaders headers = new HttpHeaders(); |
||||
|
headers.add("Accept", MediaType.APPLICATION_JSON.toString()); |
||||
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA); |
||||
|
MultiValueMap<String, Object> paramMap = transMultiValueMap(params); |
||||
|
HttpEntity<MultiValueMap> formEntity = new HttpEntity<>(paramMap, headers); |
||||
|
JSONObject result = util.restTemplate.postForObject(url, formEntity, JSONObject.class); |
||||
|
log.info("接口返回结果:{}", result); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将参数封装成MultiValueMap对象 |
||||
|
* @author whj |
||||
|
* @date 2019/8/20 |
||||
|
* @param params 参数 |
||||
|
* @return org.springframework.util.MultiValueMap<java.lang.String,java.lang.Object> |
||||
|
*/ |
||||
|
private static MultiValueMap<String, Object> transMultiValueMap(JSONObject params) { |
||||
|
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); |
||||
|
for (String key: params.keySet()) { |
||||
|
paramMap.add(key, params.get(key)); |
||||
|
} |
||||
|
return paramMap; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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,56 @@ |
|||||
|
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 |
||||
|
rabbitmq: |
||||
|
host: dd.tall.wiki |
||||
|
password: 111111 |
||||
|
port: 5672 |
||||
|
username: admin |
||||
|
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 |
||||
|
data: |
||||
|
mongodb: |
||||
|
uri: mongodb://wei:111111@dd.tall.wiki:27017/test |
||||
|
option: |
||||
|
max-connection-per-host: 100 |
||||
|
threads-allowed-to-block-for-connection-multiplier: 10 |
||||
|
min-connection-per-host: 1 |
||||
|
connect-timeout: 60000 |
||||
|
max-wait-time: 120000 |
||||
|
socket-timeout: 10000 |
||||
|
socket-keep-alive: true |
||||
|
max-connection-idle-time: 28800000 |
||||
|
max-connection-life-time: 0 |
||||
|
heartbeat-socket-timeout: 10000 |
||||
|
heartbeat-connect-timeout: 15000 |
||||
|
min-heartbeat-frequency: 5000 |
||||
|
heartbeat-frequency: 100000 |
||||
|
swagger: |
||||
|
enable: true |
||||
@ -0,0 +1,39 @@ |
|||||
|
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 |
||||
|
data: |
||||
|
mongodb: |
||||
|
uri: mongodb://wei:111111@127:0:0:1:27017/test |
||||
|
option: |
||||
|
max-connection-per-host: 100 |
||||
|
threads-allowed-to-block-for-connection-multiplier: 10 |
||||
|
min-connection-per-host: 1 |
||||
|
connect-timeout: 60000 |
||||
|
max-wait-time: 120000 |
||||
|
socket-timeout: 10000 |
||||
|
socket-keep-alive: true |
||||
|
max-connection-idle-time: 28800000 |
||||
|
max-connection-life-time: 0 |
||||
|
heartbeat-socket-timeout: 10000 |
||||
|
heartbeat-connect-timeout: 15000 |
||||
|
min-heartbeat-frequency: 5000 |
||||
|
heartbeat-frequency: 100000 |
||||
|
swagger: |
||||
|
enable: false |
||||
@ -0,0 +1,41 @@ |
|||||
|
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 |
||||
|
data: |
||||
|
mongodb: |
||||
|
uri: mongodb://wei:111111@127:0:0:1:27017/test |
||||
|
option: |
||||
|
max-connection-per-host: 100 |
||||
|
threads-allowed-to-block-for-connection-multiplier: 10 |
||||
|
min-connection-per-host: 1 |
||||
|
connect-timeout: 60000 |
||||
|
max-wait-time: 120000 |
||||
|
socket-timeout: 10000 |
||||
|
socket-keep-alive: true |
||||
|
max-connection-idle-time: 28800000 |
||||
|
max-connection-life-time: 0 |
||||
|
heartbeat-socket-timeout: 10000 |
||||
|
heartbeat-connect-timeout: 15000 |
||||
|
min-heartbeat-frequency: 5000 |
||||
|
heartbeat-frequency: 100000 |
||||
|
swagger: |
||||
|
enable: true |
||||
|
|
||||
|
|
||||
@ -0,0 +1,4 @@ |
|||||
|
spring: |
||||
|
profiles: |
||||
|
active: dev |
||||
|
include: common |
||||
@ -0,0 +1,10 @@ |
|||||
|
|
||||
|
|
||||
|
_ _ U _____ u _ _ U ___ u U ___ u ____ _ ____ |
||||
|
|'| |'| \| ___"|/ |"| |"| \/"_ \/ __ __ \/"_ \/U | _"\ u |"| | _"\ |
||||
|
/| |_| |\ | _|" U | | u U | | u | | | | \"\ /"/ | | | | \| |_) |/U | | u /| | | | |
||||
|
U| _ |u | |___ \| |/__ \| |/__.-,_| |_| | /\ \ /\ / /\.-,_| |_| | | _ < \| |/__U| |_| |\ |
||||
|
|_| |_| |_____| |_____| |_____|\_)-\___/ U \ V V / U\_)-\___/ |_| \_\ |_____||____/ u |
||||
|
// \\ << >> // \\ // \\ \\ .-,_\ /\ /_,-. \\ // \\_ // \\ |||_ |
||||
|
(_") ("_)(__) (__)(_")("_)(_")("_) (__) \_)-' '-(_/ (__) (__) (__)(_")("_)(__)_) |
||||
|
|
||||
@ -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_task" domainObjectName="Task"/> |
||||
|
|
||||
|
|
||||
|
|
||||
|
<!-- 有些表的字段需要指定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