Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
afcb0abc6a
86
pom.xml
86
pom.xml
|
|
@ -35,12 +35,14 @@
|
|||
<qiniu.version>7.2.23</qiniu.version>
|
||||
<aliyun.oss.version>3.4.0</aliyun.oss.version>
|
||||
<qcloud.cos.version>4.4</qcloud.cos.version>
|
||||
<swagger.version>2.7.0</swagger.version>
|
||||
<!-- <swagger.version>2.7.0</swagger.version>-->
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
<joda.time.version>2.9.9</joda.time.version>
|
||||
<gson.version>2.8.5</gson.version>
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<hutool.version>4.6.10</hutool.version>
|
||||
<lombok.version>1.18.4</lombok.version>
|
||||
<shardingsphere.version>4.1.1</shardingsphere.version>
|
||||
|
||||
<!--wagon plugin 配置-->
|
||||
<!--<service-path>/work/sz</service-path>
|
||||
|
|
@ -67,6 +69,12 @@
|
|||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk</artifactId>
|
||||
<version>1.11.274</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>aws-java-sdk-simpleworkflow</artifactId>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
|
|
@ -97,13 +105,6 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--云购os支付-->
|
||||
<dependency>
|
||||
<groupId>com.yungouos.pay</groupId>
|
||||
<artifactId>yungouos-pay-sdk</artifactId>
|
||||
<version>2.0.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
|
|
@ -129,11 +130,11 @@
|
|||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>druid</artifactId>-->
|
||||
<!-- <version>1.1.10</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 苹果工具类 -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
|
|
@ -183,6 +184,12 @@
|
|||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<groupId>com.aliyun</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
|
|
@ -247,16 +254,40 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--动态数据库切换-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>dynamic-datasource-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>4.1.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<!--oracle驱动-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.oracle</groupId>-->
|
||||
<!-- <artifactId>ojdbc6</artifactId>-->
|
||||
<!-- <version>${oracle.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 用于定义sharding-jdbc 分片规则 -->
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>${oracle.version}</version>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>sharding-core-api</artifactId>
|
||||
<version>${shardingsphere.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${shardingsphere.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!--mssql驱动-->
|
||||
<dependency>
|
||||
|
|
@ -265,10 +296,10 @@
|
|||
<version>${mssql.version}</version>
|
||||
</dependency>
|
||||
<!--postgresql驱动-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.postgresql</groupId>-->
|
||||
<!-- <artifactId>postgresql</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
|
|
@ -327,14 +358,25 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
<version>1.5.22</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package com.sqx;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.sqx.common.aspect;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.sqx.common.utils.HttpContextUtils;
|
||||
import com.sqx.common.utils.IPUtils;
|
||||
|
|
@ -44,22 +45,27 @@ public class AppApiMethodAspect {
|
|||
|
||||
// 执行被拦截的方法
|
||||
Object result = pjp.proceed();
|
||||
|
||||
//请求的参数
|
||||
String resultJson = new Gson().toJson(result);
|
||||
try{
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
long end = System.currentTimeMillis();
|
||||
if(StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)){
|
||||
log.info("\n>>>>>> {} {}\n>>>>>> IP: {} \n>>>>>> execute time:{}ms \n>>>>>> Request: {}\n>>>>>> Response: {}",
|
||||
request.getMethod(), request.getRequestURL(), IPUtils.getIpAddr(request),end-start,
|
||||
params,
|
||||
resultJson
|
||||
);
|
||||
long end = System.currentTimeMillis();
|
||||
ThreadUtil.execAsync(() -> {
|
||||
//请求的参数
|
||||
String resultJson = new Gson().toJson(result);
|
||||
try {
|
||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
|
||||
log.info("\n>>>>>> {} {}" +
|
||||
"\n>>>>>> IP: {} " +
|
||||
"\n>>>>>> execute time:{}ms " +
|
||||
"\n>>>>>> Request: {}" +
|
||||
"\n>>>>>> Response: {}",
|
||||
request.getMethod(), request.getRequestURL(), IPUtils.getIpAddr(request), end - start,
|
||||
params,
|
||||
resultJson
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Request 为空" + e.getMessage());
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("Request 为空"+e.getMessage());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.sqx.common.utils;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.sqx.config;
|
||||
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -70,4 +71,10 @@ public class RedisConfig {
|
|||
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||
return redisTemplate.opsForZSet();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisUtils redisUtils() {
|
||||
// 根据实际情况初始化RedisUtils实例,可能需要传入相关配置参数,如Redis连接信息等
|
||||
return new RedisUtils();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,150 @@
|
|||
package com.sqx.config;
|
||||
|
||||
import com.sqx.sharding.MasterSlaveRules;
|
||||
import com.sqx.sharding.ShardingDataBase;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
|
||||
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
|
||||
import org.apache.shardingsphere.api.config.sharding.TableRuleConfiguration;
|
||||
import org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* sharding-jdbc 配置文件
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "spring.shardingsphere")
|
||||
public class ShardingConfig {
|
||||
|
||||
/**
|
||||
* 读取数据源信息
|
||||
*/
|
||||
private Map<String, ShardingDataBase> datasource;
|
||||
/**
|
||||
* 读写分离的配置
|
||||
*/
|
||||
private Map<String, MasterSlaveRules> masterSlaveRules;
|
||||
/**
|
||||
* 显示sharding-jdbc的sql
|
||||
*/
|
||||
private String showSql;
|
||||
|
||||
/**
|
||||
* 中心库的节点
|
||||
*/
|
||||
private String centerTablesDataNode;
|
||||
|
||||
@Value("${center-tables}")
|
||||
private String tableNamesAsString;
|
||||
|
||||
/**
|
||||
* 中心表,不进行分库操作
|
||||
*/
|
||||
// @Value("${center-tables}")
|
||||
private Set<String> centerTables;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 使用换行符进行分割,然后去除空白字符,收集到Set集合中
|
||||
centerTables = Arrays.stream(tableNamesAsString.split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置sharding-jdbc数据源
|
||||
*/
|
||||
@Bean
|
||||
public DataSource dataSource() throws SQLException {
|
||||
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
|
||||
|
||||
// 配置数据库主从
|
||||
shardingRuleConfig.setMasterSlaveRuleConfigs(masterSlaveRuleConfigs());
|
||||
|
||||
// 配置表的切分策略
|
||||
shardingRuleConfig.setTableRuleConfigs(addTableRuleConfigs());
|
||||
|
||||
// 配置是否显示sql
|
||||
Properties props = new Properties();
|
||||
props.put("sql.show", showSql);
|
||||
|
||||
// 配置数据源
|
||||
Map<String, DataSource> dataSourceMap = getShardingDataBase();
|
||||
return ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
private Set<TableRuleConfiguration> addTableRuleConfigs() {
|
||||
Set<TableRuleConfiguration> sets = new HashSet<>();
|
||||
for (String centerTable : centerTables) {
|
||||
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration(centerTable,
|
||||
String.format(centerTablesDataNode, centerTable));
|
||||
sets.add(tableRuleConfig);
|
||||
}
|
||||
|
||||
// // 定义区域表的分库规则
|
||||
// InlineShardingStrategyConfiguration databaseShardingStrategyConfig = new InlineShardingStrategyConfiguration(
|
||||
// regionTablesShardingDatabaseColumn, regionTablesShardingDatabaseAlgorithm);
|
||||
// for (String regionTable : regionTables) {
|
||||
// TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration(regionTable, String.format(regionTablesDataNode, regionTable));
|
||||
// tableRuleConfig.setDatabaseShardingStrategyConfig(databaseShardingStrategyConfig);
|
||||
// sets.add(tableRuleConfig);
|
||||
// }
|
||||
return sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置数据源
|
||||
*/
|
||||
private Map<String, DataSource> getShardingDataBase() {
|
||||
String testQuery = "SELECT 1";
|
||||
Map<String, DataSource> map = new HashMap<>();
|
||||
datasource.forEach((datasourceName, shardingDataBase) -> {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDriverClassName(shardingDataBase.getDriverClassName());
|
||||
config.setJdbcUrl(shardingDataBase.getJdbcUrl());
|
||||
config.setUsername(shardingDataBase.getUsername());
|
||||
config.setPassword(shardingDataBase.getPassword());
|
||||
config.setPoolName(datasourceName);
|
||||
config.setMinimumIdle(shardingDataBase.getMinimumIdle());
|
||||
config.setMaximumPoolSize(shardingDataBase.getMaximumPoolSize());
|
||||
config.setIdleTimeout(shardingDataBase.getIdleTimeout());
|
||||
config.setMaxLifetime(shardingDataBase.getMaxLifetime());
|
||||
config.setConnectionTimeout(shardingDataBase.getConnectionTimeout());
|
||||
config.setConnectionTestQuery(testQuery);
|
||||
map.put(datasourceName, new HikariDataSource(config));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置读写分离
|
||||
*/
|
||||
private Set<MasterSlaveRuleConfiguration> masterSlaveRuleConfigs() {
|
||||
Set<MasterSlaveRuleConfiguration> sets = new HashSet<>();
|
||||
masterSlaveRules.forEach((databaseName, masterSlaveRules) -> {
|
||||
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration(databaseName,
|
||||
masterSlaveRules.getMasterDataSourceName(), masterSlaveRules.getSlaveDataSourceNames());
|
||||
sets.add(masterSlaveRuleConfig);
|
||||
});
|
||||
return sets;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +1,85 @@
|
|||
package com.sqx.config;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.ApiKey;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${swagger.enabled}")
|
||||
private boolean enabled;
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.enable(enabled)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
//加了ApiOperation注解的类,才生成接口文档
|
||||
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
||||
//包下的类,才生成接口文档
|
||||
//.apis(RequestHandlerSelectors.basePackage("com.sqx.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.securitySchemes(security());
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("")
|
||||
.description("sqx-fast文档")
|
||||
.termsOfServiceUrl("")
|
||||
.version("3.0.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<ApiKey> security() {
|
||||
return newArrayList(
|
||||
new ApiKey("token", "token", "header")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.sqx.config;
|
||||
//
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.context.annotation.Profile;
|
||||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
//import springfox.documentation.builders.ApiInfoBuilder;
|
||||
//import springfox.documentation.builders.PathSelectors;
|
||||
//import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
//import springfox.documentation.service.ApiInfo;
|
||||
//import springfox.documentation.service.ApiKey;
|
||||
//import springfox.documentation.spi.DocumentationType;
|
||||
//import springfox.documentation.spring.web.plugins.Docket;
|
||||
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static com.google.common.collect.Lists.newArrayList;
|
||||
//
|
||||
////@Configuration
|
||||
////@EnableSwagger2
|
||||
////public class SwaggerConfig implements WebMvcConfigurer {
|
||||
////
|
||||
//// @Value("${swagger.enabled}")
|
||||
//// private boolean enabled;
|
||||
////
|
||||
//// @Bean
|
||||
//// public Docket createRestApi() {
|
||||
//// return new Docket(DocumentationType.SWAGGER_2)
|
||||
//// .enable(enabled)
|
||||
//// .apiInfo(apiInfo())
|
||||
//// .select()
|
||||
//// //加了ApiOperation注解的类,才生成接口文档
|
||||
//// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
||||
//// //包下的类,才生成接口文档
|
||||
//// //.apis(RequestHandlerSelectors.basePackage("com.sqx.controller"))
|
||||
//// .paths(PathSelectors.any())
|
||||
//// .build()
|
||||
//// .securitySchemes(security());
|
||||
//// }
|
||||
////
|
||||
//// private ApiInfo apiInfo() {
|
||||
//// return new ApiInfoBuilder()
|
||||
//// .title("")
|
||||
//// .description("sqx-fast文档")
|
||||
//// .termsOfServiceUrl("")
|
||||
//// .version("3.0.0")
|
||||
//// .build();
|
||||
//// }
|
||||
////
|
||||
//// private List<ApiKey> security() {
|
||||
//// return newArrayList(
|
||||
//// new ApiKey("token", "token", "header")
|
||||
//// );
|
||||
//// }
|
||||
////
|
||||
////}
|
||||
//
|
||||
//@Configuration
|
||||
//@EnableSwagger2
|
||||
//@Profile({"local", "dev"})
|
||||
//public class SwaggerConfig {
|
||||
//
|
||||
// @Bean
|
||||
// public Docket api() {
|
||||
// return new Docket(DocumentationType.SWAGGER_2)
|
||||
// .apiInfo(apiInfo())
|
||||
// .select()
|
||||
// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
|
||||
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
||||
// .paths(PathSelectors.any())
|
||||
// .build();
|
||||
// }
|
||||
//
|
||||
// private ApiInfo apiInfo() {
|
||||
// return new ApiInfoBuilder()
|
||||
// .title("悠车位后台API接口文档")
|
||||
// .description("悠车位服务端后台API接口文档")
|
||||
// .version("1.0")
|
||||
// .build();
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package com.sqx.datasource.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 多数据源注解
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
public @interface DataSource {
|
||||
String value() default "";
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package com.sqx.datasource.aspect;
|
||||
|
||||
|
||||
import com.sqx.datasource.annotation.DataSource;
|
||||
import com.sqx.datasource.config.DynamicContextHolder;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 多数据源,切面处理类
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class DataSourceAspect {
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Pointcut("@annotation(com.sqx.datasource.annotation.DataSource) " +
|
||||
"|| @within(com.sqx.datasource.annotation.DataSource)")
|
||||
public void dataSourcePointCut() {
|
||||
|
||||
}
|
||||
|
||||
@Around("dataSourcePointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Class targetClass = point.getTarget().getClass();
|
||||
Method method = signature.getMethod();
|
||||
|
||||
DataSource targetDataSource = (DataSource)targetClass.getAnnotation(DataSource.class);
|
||||
DataSource methodDataSource = method.getAnnotation(DataSource.class);
|
||||
if(targetDataSource != null || methodDataSource != null){
|
||||
String value;
|
||||
if(methodDataSource != null){
|
||||
value = methodDataSource.value();
|
||||
}else {
|
||||
value = targetDataSource.value();
|
||||
}
|
||||
|
||||
DynamicContextHolder.push(value);
|
||||
logger.debug("set datasource is {}", value);
|
||||
}
|
||||
|
||||
try {
|
||||
return point.proceed();
|
||||
} finally {
|
||||
DynamicContextHolder.poll();
|
||||
logger.debug("clean datasource");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package com.sqx.datasource.config;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
/**
|
||||
* 多数据源上下文
|
||||
*/
|
||||
public class DynamicContextHolder {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final ThreadLocal<Deque<String>> CONTEXT_HOLDER = new ThreadLocal() {
|
||||
@Override
|
||||
protected Object initialValue() {
|
||||
return new ArrayDeque();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获得当前线程数据源
|
||||
*
|
||||
* @return 数据源名称
|
||||
*/
|
||||
public static String peek() {
|
||||
return CONTEXT_HOLDER.get().peek();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前线程数据源
|
||||
*
|
||||
* @param dataSource 数据源名称
|
||||
*/
|
||||
public static void push(String dataSource) {
|
||||
CONTEXT_HOLDER.get().push(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前线程数据源
|
||||
*/
|
||||
public static void poll() {
|
||||
Deque<String> deque = CONTEXT_HOLDER.get();
|
||||
deque.poll();
|
||||
if (deque.isEmpty()) {
|
||||
CONTEXT_HOLDER.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.sqx.datasource.config;
|
||||
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
/**
|
||||
* 多数据源
|
||||
*/
|
||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DynamicContextHolder.peek();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package com.sqx.datasource.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.sqx.datasource.properties.DataSourceProperties;
|
||||
import com.sqx.datasource.properties.DynamicDataSourceProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 配置多数据源
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
|
||||
public class DynamicDataSourceConfig {
|
||||
@Autowired
|
||||
private DynamicDataSourceProperties properties;
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "spring.datasource.druid")
|
||||
public DataSourceProperties dataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DynamicDataSource dynamicDataSource(DataSourceProperties dataSourceProperties) {
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
dynamicDataSource.setTargetDataSources(getDynamicDataSource());
|
||||
|
||||
//默认数据源
|
||||
DruidDataSource defaultDataSource = DynamicDataSourceFactory.buildDruidDataSource(dataSourceProperties);
|
||||
dynamicDataSource.setDefaultTargetDataSource(defaultDataSource);
|
||||
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
private Map<Object, Object> getDynamicDataSource(){
|
||||
Map<String, DataSourceProperties> dataSourcePropertiesMap = properties.getDatasource();
|
||||
Map<Object, Object> targetDataSources = new HashMap<>(dataSourcePropertiesMap.size());
|
||||
dataSourcePropertiesMap.forEach((k, v) -> {
|
||||
DruidDataSource druidDataSource = DynamicDataSourceFactory.buildDruidDataSource(v);
|
||||
targetDataSources.put(k, druidDataSource);
|
||||
});
|
||||
|
||||
return targetDataSources;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package com.sqx.datasource.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.sqx.datasource.properties.DataSourceProperties;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* DruidDataSource
|
||||
*
|
||||
*/
|
||||
public class DynamicDataSourceFactory {
|
||||
|
||||
public static DruidDataSource buildDruidDataSource(DataSourceProperties properties) {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setDriverClassName(properties.getDriverClassName());
|
||||
druidDataSource.setUrl(properties.getUrl());
|
||||
druidDataSource.setUsername(properties.getUsername());
|
||||
druidDataSource.setPassword(properties.getPassword());
|
||||
|
||||
druidDataSource.setInitialSize(properties.getInitialSize());
|
||||
druidDataSource.setMaxActive(properties.getMaxActive());
|
||||
druidDataSource.setMinIdle(properties.getMinIdle());
|
||||
druidDataSource.setMaxWait(properties.getMaxWait());
|
||||
druidDataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis());
|
||||
druidDataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis());
|
||||
druidDataSource.setMaxEvictableIdleTimeMillis(properties.getMaxEvictableIdleTimeMillis());
|
||||
druidDataSource.setValidationQuery(properties.getValidationQuery());
|
||||
druidDataSource.setValidationQueryTimeout(properties.getValidationQueryTimeout());
|
||||
druidDataSource.setTestOnBorrow(properties.isTestOnBorrow());
|
||||
druidDataSource.setTestOnReturn(properties.isTestOnReturn());
|
||||
druidDataSource.setPoolPreparedStatements(properties.isPoolPreparedStatements());
|
||||
druidDataSource.setMaxOpenPreparedStatements(properties.getMaxOpenPreparedStatements());
|
||||
druidDataSource.setSharePreparedStatements(properties.isSharePreparedStatements());
|
||||
|
||||
try {
|
||||
druidDataSource.setFilters(properties.getFilters());
|
||||
druidDataSource.init();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return druidDataSource;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
package com.sqx.datasource.properties;
|
||||
|
||||
/**
|
||||
* 多数据源属性
|
||||
*
|
||||
*/
|
||||
public class DataSourceProperties {
|
||||
private String driverClassName;
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Druid默认参数
|
||||
*/
|
||||
private int initialSize = 2;
|
||||
private int maxActive = 10;
|
||||
private int minIdle = -1;
|
||||
private long maxWait = 60 * 1000L;
|
||||
private long timeBetweenEvictionRunsMillis = 60 * 1000L;
|
||||
private long minEvictableIdleTimeMillis = 1000L * 60L * 30L;
|
||||
private long maxEvictableIdleTimeMillis = 1000L * 60L * 60L * 7;
|
||||
private String validationQuery = "select 1";
|
||||
private int validationQueryTimeout = -1;
|
||||
private boolean testOnBorrow = false;
|
||||
private boolean testOnReturn = false;
|
||||
private boolean testWhileIdle = true;
|
||||
private boolean poolPreparedStatements = false;
|
||||
private int maxOpenPreparedStatements = -1;
|
||||
private boolean sharePreparedStatements = false;
|
||||
private String filters = "stat,wall";
|
||||
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
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 int getInitialSize() {
|
||||
return initialSize;
|
||||
}
|
||||
|
||||
public void setInitialSize(int initialSize) {
|
||||
this.initialSize = initialSize;
|
||||
}
|
||||
|
||||
public int getMaxActive() {
|
||||
return maxActive;
|
||||
}
|
||||
|
||||
public void setMaxActive(int maxActive) {
|
||||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public int getMinIdle() {
|
||||
return minIdle;
|
||||
}
|
||||
|
||||
public void setMinIdle(int minIdle) {
|
||||
this.minIdle = minIdle;
|
||||
}
|
||||
|
||||
public long getMaxWait() {
|
||||
return maxWait;
|
||||
}
|
||||
|
||||
public void setMaxWait(long maxWait) {
|
||||
this.maxWait = maxWait;
|
||||
}
|
||||
|
||||
public long getTimeBetweenEvictionRunsMillis() {
|
||||
return timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
|
||||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public long getMinEvictableIdleTimeMillis() {
|
||||
return minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
|
||||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public long getMaxEvictableIdleTimeMillis() {
|
||||
return maxEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public void setMaxEvictableIdleTimeMillis(long maxEvictableIdleTimeMillis) {
|
||||
this.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis;
|
||||
}
|
||||
|
||||
public String getValidationQuery() {
|
||||
return validationQuery;
|
||||
}
|
||||
|
||||
public void setValidationQuery(String validationQuery) {
|
||||
this.validationQuery = validationQuery;
|
||||
}
|
||||
|
||||
public int getValidationQueryTimeout() {
|
||||
return validationQueryTimeout;
|
||||
}
|
||||
|
||||
public void setValidationQueryTimeout(int validationQueryTimeout) {
|
||||
this.validationQueryTimeout = validationQueryTimeout;
|
||||
}
|
||||
|
||||
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 isTestWhileIdle() {
|
||||
return testWhileIdle;
|
||||
}
|
||||
|
||||
public void setTestWhileIdle(boolean testWhileIdle) {
|
||||
this.testWhileIdle = testWhileIdle;
|
||||
}
|
||||
|
||||
public boolean isPoolPreparedStatements() {
|
||||
return poolPreparedStatements;
|
||||
}
|
||||
|
||||
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
|
||||
this.poolPreparedStatements = poolPreparedStatements;
|
||||
}
|
||||
|
||||
public int getMaxOpenPreparedStatements() {
|
||||
return maxOpenPreparedStatements;
|
||||
}
|
||||
|
||||
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||
this.maxOpenPreparedStatements = maxOpenPreparedStatements;
|
||||
}
|
||||
|
||||
public boolean isSharePreparedStatements() {
|
||||
return sharePreparedStatements;
|
||||
}
|
||||
|
||||
public void setSharePreparedStatements(boolean sharePreparedStatements) {
|
||||
this.sharePreparedStatements = sharePreparedStatements;
|
||||
}
|
||||
|
||||
public String getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public void setFilters(String filters) {
|
||||
this.filters = filters;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package com.sqx.datasource.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 多数据源属性
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "dynamic")
|
||||
public class DynamicDataSourceProperties {
|
||||
private Map<String, DataSourceProperties> datasource = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, DataSourceProperties> getDatasource() {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
public void setDatasource(Map<String, DataSourceProperties> datasource) {
|
||||
this.datasource = datasource;
|
||||
}
|
||||
}
|
||||
|
|
@ -107,8 +107,8 @@ public class AppController {
|
|||
userEntity.setUserId(userId);
|
||||
old.setZhiFuBao(userEntity.getZhiFuBao());
|
||||
old.setZhiFuBaoName(userEntity.getZhiFuBaoName());
|
||||
boolean bool = userService.updateById(userEntity);
|
||||
// 去除首绑支付宝奖励
|
||||
// boolean bool = userService.updateById(userEntity);
|
||||
// if (bool && isFirstBind) {
|
||||
// userService.firstBindAwardsMoney(old);
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.math.BigDecimal;
|
|||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -17,6 +18,7 @@ import lombok.EqualsAndHashCode;
|
|||
@TableName(value ="invite_achievement")
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class InviteAchievement implements Serializable {
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ public interface InviteAchievementMapper extends BaseMapper<InviteAchievement> {
|
|||
@Update("update invite_achievement set count = count + #{i}, update_time=now() where id = #{id}")
|
||||
int incrCount(Integer id, int i);
|
||||
|
||||
@Insert("INSERT INTO invite_achievement (user_id, by_user_id, count, is_first, create_time)\n" +
|
||||
"SELECT #{userId}, #{byUserId}, #{count}, #{isFirst}, #{createTime} " +
|
||||
@Insert("INSERT INTO invite_achievement (user_id, source_user_id, count, state, create_time)\n" +
|
||||
"SELECT #{userId}, #{sourceUserId}, #{count}, #{state}, #{createTime} " +
|
||||
"WHERE NOT EXISTS ( " +
|
||||
" SELECT 1 FROM invite_achievement WHERE user_id = #{userId} " +
|
||||
");")
|
||||
|
|
|
|||
|
|
@ -1498,7 +1498,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
if (ret) {
|
||||
ThreadUtil.execAsync(()->{
|
||||
discSpinningService.withdrawAsync(entity, money.doubleValue(), "[提现]");
|
||||
},true);
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("首绑支付宝发放奖励异常,用户信息:{}", JSONUtil.toJsonStr(entity));
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
package com.sqx.modules.job.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 定时任务配置
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class ScheduleConfig {
|
||||
|
||||
@Bean
|
||||
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
|
||||
SchedulerFactoryBean factory = new SchedulerFactoryBean();
|
||||
factory.setDataSource(dataSource);
|
||||
|
||||
//quartz参数
|
||||
Properties prop = new Properties();
|
||||
prop.put("org.quartz.scheduler.instanceName", "sqxScheduler");
|
||||
prop.put("org.quartz.scheduler.instanceId", "AUTO");
|
||||
//线程池配置
|
||||
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
|
||||
prop.put("org.quartz.threadPool.threadCount", "20");
|
||||
prop.put("org.quartz.threadPool.threadPriority", "5");
|
||||
//JobStore配置
|
||||
prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
|
||||
//集群配置
|
||||
prop.put("org.quartz.jobStore.isClustered", "true");
|
||||
prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
|
||||
prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
|
||||
|
||||
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
|
||||
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
|
||||
prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
|
||||
|
||||
//PostgreSQL数据库,需要打开此注释
|
||||
//prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");
|
||||
|
||||
factory.setQuartzProperties(prop);
|
||||
|
||||
factory.setSchedulerName("sqxScheduler");
|
||||
//延时启动
|
||||
factory.setStartupDelay(30);
|
||||
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
|
||||
//可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
|
||||
factory.setOverwriteExistingJobs(true);
|
||||
//设置自动启动,默认为true
|
||||
factory.setAutoStartup(true);
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
|
@ -81,34 +81,34 @@ public class ScheduleJobController {
|
|||
/**
|
||||
* 立即执行任务
|
||||
*/
|
||||
@SysLog("立即执行任务")
|
||||
@RequestMapping("/run")
|
||||
public Result run(@RequestBody Long[] jobIds){
|
||||
scheduleJobService.run(jobIds);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停定时任务
|
||||
*/
|
||||
@SysLog("暂停定时任务")
|
||||
@RequestMapping("/pause")
|
||||
public Result pause(@RequestBody Long[] jobIds){
|
||||
scheduleJobService.pause(jobIds);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复定时任务
|
||||
*/
|
||||
@SysLog("恢复定时任务")
|
||||
@RequestMapping("/resume")
|
||||
public Result resume(@RequestBody Long[] jobIds){
|
||||
scheduleJobService.resume(jobIds);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
// @SysLog("立即执行任务")
|
||||
// @RequestMapping("/run")
|
||||
// public Result run(@RequestBody Long[] jobIds){
|
||||
// scheduleJobService.run(jobIds);
|
||||
//
|
||||
// return Result.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 暂停定时任务
|
||||
// */
|
||||
// @SysLog("暂停定时任务")
|
||||
// @RequestMapping("/pause")
|
||||
// public Result pause(@RequestBody Long[] jobIds){
|
||||
// scheduleJobService.pause(jobIds);
|
||||
//
|
||||
// return Result.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 恢复定时任务
|
||||
// */
|
||||
// @SysLog("恢复定时任务")
|
||||
// @RequestMapping("/resume")
|
||||
// public Result resume(@RequestBody Long[] jobIds){
|
||||
// scheduleJobService.resume(jobIds);
|
||||
//
|
||||
// return Result.success();
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,18 +34,18 @@ public interface ScheduleJobService extends IService<ScheduleJobEntity> {
|
|||
*/
|
||||
int updateBatch(Long[] jobIds, int status);
|
||||
|
||||
/**
|
||||
* 立即执行
|
||||
*/
|
||||
void run(Long[] jobIds);
|
||||
|
||||
/**
|
||||
* 暂停运行
|
||||
*/
|
||||
void pause(Long[] jobIds);
|
||||
|
||||
/**
|
||||
* 恢复运行
|
||||
*/
|
||||
void resume(Long[] jobIds);
|
||||
// /**
|
||||
// * 立即执行
|
||||
// */
|
||||
// void run(Long[] jobIds);
|
||||
//
|
||||
// /**
|
||||
// * 暂停运行
|
||||
// */
|
||||
// void pause(Long[] jobIds);
|
||||
//
|
||||
// /**
|
||||
// * 恢复运行
|
||||
// */
|
||||
// void resume(Long[] jobIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,38 +9,22 @@ import com.sqx.common.utils.Query;
|
|||
import com.sqx.modules.job.dao.ScheduleJobDao;
|
||||
import com.sqx.modules.job.entity.ScheduleJobEntity;
|
||||
import com.sqx.modules.job.service.ScheduleJobService;
|
||||
import com.sqx.modules.job.utils.ScheduleUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("scheduleJobService")
|
||||
public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化定时器
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
List<ScheduleJobEntity> scheduleJobList = this.list();
|
||||
for(ScheduleJobEntity scheduleJob : scheduleJobList){
|
||||
CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getJobId());
|
||||
//如果不存在,则创建
|
||||
if(cronTrigger == null) {
|
||||
ScheduleUtils.createScheduleJob(scheduler, scheduleJob);
|
||||
}else {
|
||||
ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
|
|
@ -61,25 +45,18 @@ public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, Schedule
|
|||
scheduleJob.setCreateTime(new Date());
|
||||
scheduleJob.setStatus(Constant.ScheduleStatus.NORMAL.getValue());
|
||||
this.save(scheduleJob);
|
||||
|
||||
ScheduleUtils.createScheduleJob(scheduler, scheduleJob);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(ScheduleJobEntity scheduleJob) {
|
||||
ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
|
||||
|
||||
|
||||
this.updateById(scheduleJob);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatch(Long[] jobIds) {
|
||||
for(Long jobId : jobIds){
|
||||
ScheduleUtils.deleteScheduleJob(scheduler, jobId);
|
||||
}
|
||||
|
||||
//删除数据
|
||||
this.removeByIds(Arrays.asList(jobIds));
|
||||
}
|
||||
|
|
@ -92,32 +69,32 @@ public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, Schedule
|
|||
return baseMapper.updateBatch(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void run(Long[] jobIds) {
|
||||
for(Long jobId : jobIds){
|
||||
ScheduleUtils.run(scheduler, this.getById(jobId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void pause(Long[] jobIds) {
|
||||
for(Long jobId : jobIds){
|
||||
ScheduleUtils.pauseJob(scheduler, jobId);
|
||||
}
|
||||
|
||||
updateBatch(jobIds, Constant.ScheduleStatus.PAUSE.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void resume(Long[] jobIds) {
|
||||
for(Long jobId : jobIds){
|
||||
ScheduleUtils.resumeJob(scheduler, jobId);
|
||||
}
|
||||
|
||||
updateBatch(jobIds, Constant.ScheduleStatus.NORMAL.getValue());
|
||||
}
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void run(Long[] jobIds) {
|
||||
// for(Long jobId : jobIds){
|
||||
// ScheduleUtils.run(scheduler, this.getById(jobId));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void pause(Long[] jobIds) {
|
||||
// for(Long jobId : jobIds){
|
||||
// ScheduleUtils.pauseJob(scheduler, jobId);
|
||||
// }
|
||||
//
|
||||
// updateBatch(jobIds, Constant.ScheduleStatus.PAUSE.getValue());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void resume(Long[] jobIds) {
|
||||
// for(Long jobId : jobIds){
|
||||
// ScheduleUtils.resumeJob(scheduler, jobId);
|
||||
// }
|
||||
//
|
||||
// updateBatch(jobIds, Constant.ScheduleStatus.NORMAL.getValue());
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ import javax.annotation.Resource;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Component("CashOutTask")
|
||||
public class CashOutTask implements ITask {
|
||||
@Component
|
||||
public class CashOutTask{
|
||||
|
||||
@Resource
|
||||
private CashOutDao cashOutDao;
|
||||
|
|
@ -32,7 +32,6 @@ public class CashOutTask implements ITask {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
logger.info("提现开始");
|
||||
List<CashOut> cashOuts = cashOutDao.selectYesterday();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.sqx.modules.utils.AliPayOrderUtil;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -23,8 +24,8 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component("CashOutTask2")
|
||||
public class CashOutTask2 implements ITask {
|
||||
@Component
|
||||
public class CashOutTask2{
|
||||
|
||||
@Resource
|
||||
private CashOutDao cashOutDao;
|
||||
|
|
@ -37,7 +38,6 @@ public class CashOutTask2 implements ITask {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
logger.info("提现开始");
|
||||
if (StringUtils.isBlank(params) || isValidDate(params)) {
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
package com.sqx.modules.job.task;
|
||||
|
||||
/**
|
||||
* 定时任务接口,所有定时任务都要实现该接口
|
||||
*
|
||||
*/
|
||||
public interface ITask {
|
||||
|
||||
/**
|
||||
* 执行定时任务接口
|
||||
*
|
||||
* @param params 参数,多参数使用JSON数据
|
||||
*/
|
||||
void run(String params);
|
||||
}
|
||||
|
|
@ -9,14 +9,17 @@ import com.sqx.modules.discSpinning.service.DiscSpinningService;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component("SpinningTask3")
|
||||
public class SpinningTask3 implements ITask {
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class SpinningTask3 {
|
||||
|
||||
@Resource
|
||||
private DiscSpinningService spinningController;
|
||||
|
|
@ -25,8 +28,12 @@ public class SpinningTask3 implements ITask {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
@Scheduled(cron = "0 0/2 * * * ? ")
|
||||
public void record() {
|
||||
record("1");
|
||||
}
|
||||
|
||||
public void record(String params) {
|
||||
logger.info("大转盘到账补偿机制");
|
||||
// 获取当前时间
|
||||
Date now = DateUtil.date();
|
||||
|
|
@ -48,6 +55,7 @@ public class SpinningTask3 implements ITask {
|
|||
recordQueryWrapper.lt("create_time", fiveMinutesAgoStr);
|
||||
//小于
|
||||
recordQueryWrapper.gt("create_time", tenMinutesAgoStr);
|
||||
logger.info("大转盘到账补偿时间范围:{}-----{}", tenMinutesAgoStr, fiveMinutesAgoStr);
|
||||
List<DiscSpinningRecord> list = recordService.list(recordQueryWrapper);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
for (DiscSpinningRecord record : list) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import java.util.List;
|
|||
* @author GYJoker
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("SupplyAgainSignRewardTask")
|
||||
public class SupplyAgainSignRewardTask implements ITask {
|
||||
@Component
|
||||
public class SupplyAgainSignRewardTask{
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
|
@ -35,7 +35,6 @@ public class SupplyAgainSignRewardTask implements ITask {
|
|||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
if (StringUtils.isBlank(params)) {
|
||||
log.error("参数为空");
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import org.springframework.stereotype.Component;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component("TempCashOutTask")
|
||||
public class TempCashOutTask implements ITask {
|
||||
@Component
|
||||
public class TempCashOutTask{
|
||||
|
||||
@Resource
|
||||
private CashOutDao cashOutDao;
|
||||
|
|
@ -23,7 +23,6 @@ public class TempCashOutTask implements ITask {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
logger.info("提现开始");
|
||||
List<CashOut> cashOuts = cashOutDao.selectTemp();
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("TempOrdersTask")
|
||||
public class TempOrdersTask implements ITask {
|
||||
@Component
|
||||
public class TempOrdersTask {
|
||||
|
||||
@Resource
|
||||
private OrdersDao ordersDao;
|
||||
|
|
@ -71,7 +71,6 @@ public class TempOrdersTask implements ITask {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
logger.info("订单表数据处理开始");
|
||||
List<Orders> orders = ordersDao.selectList(Wrappers.<Orders>lambdaQuery()
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
package com.sqx.modules.job.task;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 测试定时任务(演示Demo,可删除)
|
||||
*
|
||||
* testTask为spring bean的名称
|
||||
*
|
||||
*/
|
||||
@Component("testTask")
|
||||
public class TestTask implements ITask {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void run(String params){
|
||||
|
||||
logger.debug("TestTask定时任务正在执行,参数为:{}", params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
package com.sqx.modules.job.utils;
|
||||
|
||||
import com.sqx.common.utils.SpringContextUtils;
|
||||
import com.sqx.modules.job.entity.ScheduleJobEntity;
|
||||
import com.sqx.modules.job.entity.ScheduleJobLogEntity;
|
||||
import com.sqx.modules.job.service.ScheduleJobLogService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
*
|
||||
*/
|
||||
public class ScheduleJob extends QuartzJobBean {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
ScheduleJobEntity scheduleJob = (ScheduleJobEntity) context.getMergedJobDataMap()
|
||||
.get(ScheduleJobEntity.JOB_PARAM_KEY);
|
||||
|
||||
//获取spring bean
|
||||
ScheduleJobLogService scheduleJobLogService = (ScheduleJobLogService) SpringContextUtils.getBean("scheduleJobLogService");
|
||||
|
||||
//数据库保存执行记录
|
||||
ScheduleJobLogEntity log = new ScheduleJobLogEntity();
|
||||
log.setJobId(scheduleJob.getJobId());
|
||||
log.setBeanName(scheduleJob.getBeanName());
|
||||
log.setParams(scheduleJob.getParams());
|
||||
log.setCreateTime(new Date());
|
||||
|
||||
//任务开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
//执行任务
|
||||
logger.debug("任务准备执行,任务ID:" + scheduleJob.getJobId());
|
||||
|
||||
Object target = SpringContextUtils.getBean(scheduleJob.getBeanName());
|
||||
Method method = target.getClass().getDeclaredMethod("run", String.class);
|
||||
method.invoke(target, scheduleJob.getParams());
|
||||
|
||||
//任务执行总时长
|
||||
long times = System.currentTimeMillis() - startTime;
|
||||
log.setTimes((int)times);
|
||||
//任务状态 0:成功 1:失败
|
||||
log.setStatus(0);
|
||||
|
||||
logger.debug("任务执行完毕,任务ID:" + scheduleJob.getJobId() + " 总共耗时:" + times + "毫秒");
|
||||
} catch (Exception e) {
|
||||
logger.error("任务执行失败,任务ID:" + scheduleJob.getJobId(), e);
|
||||
|
||||
//任务执行总时长
|
||||
long times = System.currentTimeMillis() - startTime;
|
||||
log.setTimes((int)times);
|
||||
|
||||
//任务状态 0:成功 1:失败
|
||||
log.setStatus(1);
|
||||
log.setError(StringUtils.substring(e.toString(), 0, 2000));
|
||||
}finally {
|
||||
scheduleJobLogService.save(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
package com.sqx.modules.job.utils;
|
||||
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Constant;
|
||||
import com.sqx.modules.job.entity.ScheduleJobEntity;
|
||||
import org.quartz.*;
|
||||
|
||||
/**
|
||||
* 定时任务工具类
|
||||
*
|
||||
*/
|
||||
public class ScheduleUtils {
|
||||
private final static String JOB_NAME = "TASK_";
|
||||
|
||||
/**
|
||||
* 获取触发器key
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long jobId) {
|
||||
return TriggerKey.triggerKey(JOB_NAME + jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jobKey
|
||||
*/
|
||||
public static JobKey getJobKey(Long jobId) {
|
||||
return JobKey.jobKey(JOB_NAME + jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表达式触发器
|
||||
*/
|
||||
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) {
|
||||
try {
|
||||
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("获取定时任务CronTrigger出现异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*/
|
||||
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
|
||||
try {
|
||||
//构建job信息
|
||||
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId())).build();
|
||||
|
||||
//表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
|
||||
.withMisfireHandlingInstructionDoNothing();
|
||||
|
||||
//按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();
|
||||
|
||||
//放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
|
||||
//暂停任务
|
||||
if(scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()){
|
||||
pauseJob(scheduler, scheduleJob.getJobId());
|
||||
}
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("创建定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*/
|
||||
public static void updateScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
|
||||
try {
|
||||
TriggerKey triggerKey = getTriggerKey(scheduleJob.getJobId());
|
||||
|
||||
//表达式调度构建器
|
||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
|
||||
.withMisfireHandlingInstructionDoNothing();
|
||||
|
||||
CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId());
|
||||
|
||||
//按新的cronExpression表达式重新构建trigger
|
||||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||
|
||||
//参数
|
||||
trigger.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
scheduler.rescheduleJob(triggerKey, trigger);
|
||||
|
||||
//暂停任务
|
||||
if(scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()){
|
||||
pauseJob(scheduler, scheduleJob.getJobId());
|
||||
}
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("更新定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即执行任务
|
||||
*/
|
||||
public static void run(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
|
||||
try {
|
||||
//参数
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap);
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("立即执行定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*/
|
||||
public static void pauseJob(Scheduler scheduler, Long jobId) {
|
||||
try {
|
||||
scheduler.pauseJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("暂停定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*/
|
||||
public static void resumeJob(Scheduler scheduler, Long jobId) {
|
||||
try {
|
||||
scheduler.resumeJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("暂停定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*/
|
||||
public static void deleteScheduleJob(Scheduler scheduler, Long jobId) {
|
||||
try {
|
||||
scheduler.deleteJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new SqxException("删除定时任务失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,9 +32,6 @@ import com.sqx.modules.pay.dao.PayDetailsDao;
|
|||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.yungouos.pay.alipay.AliPay;
|
||||
import com.yungouos.pay.entity.AliPayH5Biz;
|
||||
import com.yungouos.pay.util.PaySignUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -109,16 +106,16 @@ public class AliPayController {
|
|||
log.info(flag + "回调验证信息");
|
||||
if (flag) {
|
||||
String tradeStatus = params.get("trade_status");
|
||||
if("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)){
|
||||
if ("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) {
|
||||
//支付宝返回的订单编号
|
||||
String outTradeNo = params.get("out_trade_no");
|
||||
//支付宝支付单号
|
||||
String tradeNo = params.get("trade_no");
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(outTradeNo);
|
||||
if(payDetails.getState()==0){
|
||||
if (payDetails.getState() == 0) {
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,tradeNo);
|
||||
if(payDetails.getType()==1){
|
||||
payDetailsDao.updateState(payDetails.getId(), 1, format, tradeNo);
|
||||
if (payDetails.getType() == 1) {
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(4);
|
||||
orders.setStatus(1);
|
||||
|
|
@ -128,34 +125,34 @@ public class AliPayController {
|
|||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
if (oneUserId != null) {
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
if (twoUserId != null) {
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
if (sysUserId != null) {
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.updateById(orders);
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
} else {
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyService.updateMoney(1, payDetails.getUserId(), add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
// ✅
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("支付宝充值金币");
|
||||
userMoneyDetails.setTitle("支付宝充值金币:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setTitle("支付宝充值金币:" + payClassify.getMoney() + ",赠送:" + payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
|
|
@ -179,92 +176,15 @@ public class AliPayController {
|
|||
@ApiOperation("支付宝回调")
|
||||
@RequestMapping("/notifyAppYunOS")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String notifyAppYunOS(HttpServletRequest request, HttpServletResponse response){
|
||||
//获取支付宝POST过来反馈信息
|
||||
Map<String,String> params = new HashMap<String,String>();
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用。
|
||||
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
String outTradeNo = params.get("outTradeNo");
|
||||
String code = params.get("code");
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
try {
|
||||
boolean flag = PaySignUtil.checkNotifySign(request, key);
|
||||
if(flag){
|
||||
if("1".equals(code)){
|
||||
PayDetails payDetails=payDetailsDao.selectByOrderId(outTradeNo);
|
||||
if(payDetails.getState()==0) {
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,null);
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(4);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
ordersService.updateById(orders);
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
// ✅
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("支付宝充值金币");
|
||||
userMoneyDetails.setTitle("支付宝充值金币:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetails.setMoneyType(2);
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("云购os支付报错!"+e.getMessage());
|
||||
}
|
||||
return null;
|
||||
public String notifyAppYunOS(HttpServletRequest request, HttpServletResponse response) {
|
||||
return "SUCCESS";
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("支付宝支付订单")
|
||||
@RequestMapping(value = "/payOrder", method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payOrder(Long orderId,Integer classify) {
|
||||
public Result payOrder(Long orderId, Integer classify) {
|
||||
//通知页面地址
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String returnUrl = one.getValue() + "/#/pages/task/recharge";
|
||||
|
|
@ -274,17 +194,17 @@ public class AliPayController {
|
|||
log.info("回调地址:" + url);
|
||||
Orders orders = ordersDao.selectById(orderId);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(orders.getOrdersNo());
|
||||
if(payDetails==null){
|
||||
payDetails=new PayDetails();
|
||||
if (payDetails == null) {
|
||||
payDetails = new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(orders.getOrdersNo());
|
||||
payDetails.setUserId(orders.getUserId());
|
||||
payDetails.setMoney(orders.getPayMoney().doubleValue());
|
||||
payDetails.setType(1);
|
||||
if(classify==1){
|
||||
if (classify == 1) {
|
||||
payDetails.setClassify(4);
|
||||
}else{
|
||||
} else {
|
||||
payDetails.setClassify(5);
|
||||
}
|
||||
payDetailsDao.insert(payDetails);
|
||||
|
|
@ -300,7 +220,7 @@ public class AliPayController {
|
|||
@ApiOperation("支付宝支付订单")
|
||||
@RequestMapping(value = "/payMoney", method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payMoney(Long payClassifyId, Integer classify,@RequestAttribute Long userId) {
|
||||
public Result payMoney(Long payClassifyId, Integer classify, @RequestAttribute Long userId) {
|
||||
//通知页面地址
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String returnUrl = one.getValue() + "/#/pages/task/recharge";
|
||||
|
|
@ -310,15 +230,15 @@ public class AliPayController {
|
|||
log.info("回调地址:" + url);
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
PayDetails payDetails=new PayDetails();
|
||||
PayDetails payDetails = new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(payClassify.getPrice().doubleValue());
|
||||
if(classify==1){
|
||||
if (classify == 1) {
|
||||
payDetails.setClassify(4);
|
||||
}else{
|
||||
} else {
|
||||
payDetails.setClassify(5);
|
||||
}
|
||||
payDetails.setType(2);
|
||||
|
|
@ -368,7 +288,6 @@ public class AliPayController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public Result payApp(String name, String generalOrder, Double money) {
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String url = one.getValue() + "/sqx_fast/app/aliPay/notifyApp";
|
||||
|
|
@ -405,7 +324,7 @@ public class AliPayController {
|
|||
model.setSubject(name);
|
||||
model.setOutTradeNo(generalOrder);
|
||||
model.setTimeoutExpress("30m");
|
||||
model.setTotalAmount(money +"");
|
||||
model.setTotalAmount(money + "");
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(url);
|
||||
|
|
@ -417,7 +336,7 @@ public class AliPayController {
|
|||
return Result.error("获取订单失败!");
|
||||
}
|
||||
return Result.success().put("data", result);
|
||||
} else if("2".equals(payWay.getValue())){
|
||||
} else if ("2".equals(payWay.getValue())) {
|
||||
//实例化客户端
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), "json", AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), "RSA2");
|
||||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
|
|
@ -439,13 +358,6 @@ public class AliPayController {
|
|||
return Result.error("获取订单失败!");
|
||||
}
|
||||
return Result.success().put("data", result);
|
||||
}else{
|
||||
url=one.getValue()+"/sqx_fast/app/aliPay/notifyAppYunOS";
|
||||
log.info("回调地址:"+url);
|
||||
String mchId = commonInfoService.findOne(168).getValue();
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
result = AliPay.appPay(generalOrder, String.valueOf(money), mchId, name ,null, url, null, null, null, null,key);
|
||||
return Result.success().put("data", result);
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -491,7 +403,7 @@ public class AliPayController {
|
|||
alipayRequest.setReturnUrl(returnUrl); //线上通知页面地址
|
||||
String result = alipayClient.pageExecute(alipayRequest).getBody();
|
||||
return Result.success().put("data", result);
|
||||
} else if ("2".equals(payWay.getValue())){
|
||||
} else if ("2".equals(payWay.getValue())) {
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), "json", AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), "RSA2");
|
||||
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
|
||||
JSONObject order = new JSONObject();
|
||||
|
|
@ -507,13 +419,6 @@ public class AliPayController {
|
|||
alipayRequest.setReturnUrl(returnUrl);
|
||||
String form = alipayClient.pageExecute(alipayRequest).getBody();
|
||||
return Result.success().put("data", form);
|
||||
}else{
|
||||
url=one.getValue()+"/sqx_fast/app/aliPay/notifyAppYunOS";
|
||||
log.info("回调地址:"+url);
|
||||
String mchId = commonInfoService.findOne(168).getValue();
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
AliPayH5Biz aliPayH5Biz = AliPay.h5Pay(generalOrder, String.valueOf(money), mchId, name, null, url, returnUrl, null, null, null,null,key);
|
||||
return Result.success().put("data", aliPayH5Biz.getForm());
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
log.error("CreatPayOrderForH5", e);
|
||||
|
|
@ -522,5 +427,4 @@ public class AliPayController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -361,18 +361,22 @@ public class WuyouController {
|
|||
}
|
||||
ordersService.updateById(order);
|
||||
ordersService.insertOrders(order);
|
||||
InviteAchievement inviteAchievement = inviteAchievementService.getByUserId(user.getUserId());
|
||||
if (inviteAchievement == null) {
|
||||
inviteAchievement = new InviteAchievement();
|
||||
inviteAchievement.setState(0);
|
||||
inviteAchievement.setCount(1);
|
||||
inviteAchievement.setCreateTime(DateUtil.date());
|
||||
inviteAchievement.setUserId(user.getUserId());
|
||||
inviteAchievement.setSourceUserId(byUser.getUserId());
|
||||
inviteAchievementService.insertNotExists(inviteAchievement);
|
||||
} else {
|
||||
inviteAchievementService.incrCount(inviteAchievement.getId(), 1);
|
||||
|
||||
if (byUser != null) {
|
||||
InviteAchievement inviteAchievement = inviteAchievementService.getByUserId(user.getUserId());
|
||||
if (inviteAchievement == null) {
|
||||
inviteAchievement = new InviteAchievement();
|
||||
inviteAchievement.setState(0);
|
||||
inviteAchievement.setCount(1);
|
||||
inviteAchievement.setCreateTime(DateUtil.date());
|
||||
inviteAchievement.setUserId(user.getUserId());
|
||||
inviteAchievement.setSourceUserId(byUser.getUserId());
|
||||
inviteAchievementService.insertNotExists(inviteAchievement);
|
||||
} else {
|
||||
inviteAchievementService.incrCount(inviteAchievement.getId(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
ThreadUtil.execAsync(() -> {
|
||||
activities(user, byUser);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.sqx.modules.pay.wuyou;
|
||||
|
||||
import com.alibaba.druid.util.Utils;
|
||||
import com.sqx.modules.utils.MD5Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -23,7 +23,7 @@ public class Encrypt {
|
|||
sb.append("key=").append(APP_SECRET);
|
||||
String signStr = sb.toString();
|
||||
System.out.println("signStr: " + signStr);
|
||||
return Utils.md5(signStr).toUpperCase();
|
||||
return MD5Util.encodeByMD5(signStr).toUpperCase();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class RedisServiceImpl implements RedisService {
|
|||
expireTime = jsonObject.getLong("expireTime");
|
||||
}
|
||||
|
||||
if ((StrUtil.isNotBlank(permanentlyFreeWatch) && redisUtils.isExpiredSet(freeWatchKey)) || (StrUtil.isNotBlank(permanentlyFreeWatch) && DateUtil.current() >= expireTime)) {
|
||||
if ((StrUtil.isNotBlank(permanentlyFreeWatch) && redisUtils.isExpiredSet(freeWatchKey)) || (StrUtil.isNotBlank(permanentlyFreeWatch) && DateUtil.current(false) >= expireTime)) {
|
||||
if (StrUtil.isBlank(permanentlyFreeWatch)) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ public class RedisServiceImpl implements RedisService {
|
|||
redisUtils.set(watchKey, jsonObject.toJSONString(), expire);
|
||||
return false;
|
||||
}else {
|
||||
return DateUtil.current() > expireTime;
|
||||
return DateUtil.current(false) > expireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ public class RedisServiceImpl implements RedisService {
|
|||
Integer expireTime = jsonObject.getInteger("expireTime");
|
||||
Long second = jsonObject.getLong("second");
|
||||
|
||||
return expireTime == -1 ? second : expireTime > DateUtil.current() ? expireTime - DateUtil.current() : 0L;
|
||||
return expireTime == -1 ? second : expireTime > DateUtil.current(false) ? expireTime - DateUtil.current(false) : 0L;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* oauth2过滤器
|
||||
*
|
||||
*/
|
||||
public class OAuth2Filter extends AuthenticatingFilter {
|
||||
|
||||
|
|
@ -32,7 +31,7 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|||
//获取请求token
|
||||
String token = getRequestToken((HttpServletRequest) request);
|
||||
|
||||
if(StringUtils.isBlank(token)){
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
|
||||
if(((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())){
|
||||
if (((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +51,7 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||
//获取请求token,如果token不存在,直接返回401
|
||||
String token = getRequestToken((HttpServletRequest) request);
|
||||
if(StringUtils.isBlank(token)){
|
||||
if (StringUtils.isBlank(token)) {
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
||||
|
|
@ -63,17 +62,8 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|||
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
return executeLogin(request, response);
|
||||
}catch (AbstractMethodError e){
|
||||
if (e.getMessage().contains("sessionCreated")) {
|
||||
logger.error(e.getMessage());
|
||||
return false;
|
||||
}else {
|
||||
logger.error(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return executeLogin(request, response);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -99,12 +89,12 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|||
/**
|
||||
* 获取请求的token
|
||||
*/
|
||||
private String getRequestToken(HttpServletRequest httpRequest){
|
||||
private String getRequestToken(HttpServletRequest httpRequest) {
|
||||
//从header中获取token
|
||||
String token = httpRequest.getHeader("token");
|
||||
|
||||
//如果header中不存在token,则从参数中获取token
|
||||
if(StringUtils.isBlank(token)){
|
||||
if (StringUtils.isBlank(token)) {
|
||||
token = httpRequest.getParameter("token");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.sqx.sharding;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 读写分离配置
|
||||
*/
|
||||
@Data
|
||||
public class MasterSlaveRules {
|
||||
|
||||
/**
|
||||
* 写库
|
||||
*/
|
||||
private String masterDataSourceName;
|
||||
|
||||
/**
|
||||
* 读库
|
||||
*/
|
||||
private List<String> slaveDataSourceNames;
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.sqx.sharding;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用于注入sharding-jdbc的值
|
||||
*/
|
||||
@Data
|
||||
public class ShardingDataBase {
|
||||
|
||||
/**
|
||||
* 连接池
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 驱动名称
|
||||
*/
|
||||
private String driverClassName;
|
||||
|
||||
/**
|
||||
* 数据库地址
|
||||
*/
|
||||
private String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 数据库用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 数据库密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 最小空闲连接,默认值10,小于0或大于maximum-pool-size,都会重置为maximum-pool-size
|
||||
*/
|
||||
private int minimumIdle;
|
||||
|
||||
/**
|
||||
* 最大连接数,小于等于0会被重置为默认值10;大于零小于1会被重置为minimum-idle的值
|
||||
*/
|
||||
private int maximumPoolSize;
|
||||
|
||||
/**
|
||||
* 空闲连接超时时间,默认值600000(10分钟),大于等于max-lifetime且max-lifetime>0,会被重置为0;不等于0且小于10秒,会被重置为10秒。
|
||||
*/
|
||||
private int idleTimeout;
|
||||
|
||||
/**
|
||||
* 连接最大存活时间.不等于0且小于30秒,会被重置为默认值30分钟.设置应该比mysql设置的超时时间短
|
||||
*/
|
||||
private int maxLifetime;
|
||||
|
||||
/**
|
||||
* 连接超时时间:毫秒,小于250毫秒,否则被重置为默认值30秒
|
||||
*/
|
||||
private int connectionTimeout;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.sqx.sharding;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.DataSourceUnwrapper;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author wxkj0012
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AutoConfigureAfter({MetricsAutoConfiguration.class, DataSourceAutoConfiguration.class,
|
||||
SimpleMetricsExportAutoConfiguration.class})
|
||||
@ConditionalOnClass({DataSource.class, MeterRegistry.class})
|
||||
@ConditionalOnBean({DataSource.class, MeterRegistry.class})
|
||||
@Slf4j
|
||||
public class ShardingDataSourcePoolMetricsAutoConfiguration {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({ShardingDataSource.class, HikariDataSource.class})
|
||||
static class ShardingDataSourceMetricsConfiguration {
|
||||
|
||||
private final MeterRegistry registry;
|
||||
|
||||
ShardingDataSourceMetricsConfiguration(MeterRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
void bindMetricsRegistryToHikariDataSources(Collection<DataSource> dataSources) {
|
||||
for (DataSource dataSource : dataSources) {
|
||||
ShardingDataSource shardingDataSource = DataSourceUnwrapper.unwrap(dataSource, ShardingDataSource.class);
|
||||
Collection<DataSource> shardDataSources = shardingDataSource.getDataSourceMap().values();
|
||||
for (DataSource ds : shardDataSources) {
|
||||
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(ds, HikariDataSource.class);
|
||||
if (hikariDataSource != null) {
|
||||
bindMetricsRegistryToHikariDataSource(hikariDataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void bindMetricsRegistryToHikariDataSource(HikariDataSource hikari) {
|
||||
if (hikari.getMetricRegistry() == null && hikari.getMetricsTrackerFactory() == null) {
|
||||
try {
|
||||
hikari.setMetricsTrackerFactory(new MicrometerMetricsTrackerFactory(this.registry));
|
||||
} catch (Exception ex) {
|
||||
log.warn("Failed to bind Hikari metrics: {}}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,55 @@
|
|||
# 数据源的一些配置
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 最小空闲连接,默认值10,小于0或大于maximum-pool-size,都会重置为maximum-pool-size
|
||||
minimum-idle: 5
|
||||
# 最大连接数,小于等于0会被重置为默认值10;大于零小于1会被重置为minimum-idle的值
|
||||
maximum-pool-size: 15
|
||||
# 空闲连接超时时间,默认值600000(10分钟),大于等于max-lifetime且max-lifetime>0,会被重置为0;不等于0且小于10秒,会被重置为10秒。
|
||||
idle-timeout: 30000
|
||||
# 连接最大存活时间.不等于0且小于30秒,会被重置为默认值30分钟.设置应该比mysql设置的超时时间短
|
||||
max-lifetime: 30000
|
||||
# 连接超时时间:毫秒,小于250毫秒,否则被重置为默认值30秒
|
||||
connection-timeout: 30000
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: video_user
|
||||
password: VideoUser@1
|
||||
initial-size: 10
|
||||
max-active: 50
|
||||
min-idle: 10
|
||||
max-wait: 60000
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
#Oracle需要打开注释
|
||||
#validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
#login-username: admin
|
||||
#login-password: admin
|
||||
filter:
|
||||
stat:
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 1000
|
||||
merge-sql: false
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
# sharding-jdbc 配置
|
||||
shardingsphere:
|
||||
center-tables-data-node: duanju.%s
|
||||
# 显示sharding-jdbc改写的sql语句
|
||||
show-sql: false
|
||||
# 数据源名称
|
||||
datasource:
|
||||
# 数据源配置begin
|
||||
master-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: video_user
|
||||
password: VideoUser@1
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://47.122.26.160:3306/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: 0fd6497c308ccfa8
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置end
|
||||
|
||||
# 读写分离配置begin
|
||||
master-slave-rules:
|
||||
#数据源
|
||||
duanju:
|
||||
master-data-source-name: master-0
|
||||
slave-data-source-names: slave-0
|
||||
# - master-0
|
||||
# - slave-0
|
||||
|
||||
swagger:
|
||||
enabled: true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
# 数据源的一些配置
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 最小空闲连接,默认值10,小于0或大于maximum-pool-size,都会重置为maximum-pool-size
|
||||
minimum-idle: 5
|
||||
# 最大连接数,小于等于0会被重置为默认值10;大于零小于1会被重置为minimum-idle的值
|
||||
maximum-pool-size: 15
|
||||
# 空闲连接超时时间,默认值600000(10分钟),大于等于max-lifetime且max-lifetime>0,会被重置为0;不等于0且小于10秒,会被重置为10秒。
|
||||
idle-timeout: 30000
|
||||
# 连接最大存活时间.不等于0且小于30秒,会被重置为默认值30分钟.设置应该比mysql设置的超时时间短
|
||||
max-lifetime: 30000
|
||||
# 连接超时时间:毫秒,小于250毫秒,否则被重置为默认值30秒
|
||||
connection-timeout: 30000
|
||||
|
||||
spring:
|
||||
# sharding-jdbc 配置
|
||||
shardingsphere:
|
||||
center-tables-data-node: duanju.%s
|
||||
# 显示sharding-jdbc改写的sql语句
|
||||
show-sql: false
|
||||
# 数据源名称
|
||||
datasource:
|
||||
# 数据源配置begin
|
||||
master-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: video_user
|
||||
password: VideoUser@1
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://47.122.26.160:3306/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: 0fd6497c308ccfa8
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置end
|
||||
|
||||
# 读写分离配置begin
|
||||
master-slave-rules:
|
||||
#数据源
|
||||
duanju:
|
||||
master-data-source-name: master-0
|
||||
slave-data-source-names: slave-0
|
||||
# - master-0
|
||||
# - slave-0
|
||||
|
||||
swagger:
|
||||
enabled: true
|
||||
pay:
|
||||
h5BaseUrl: https://video-h5.hnsiyao.cn/me/detail/detail?allId=
|
||||
orderNotifyUrl: https://video.hnsiyao.cn/czg/app/wuyou/notify
|
||||
extractNotifyUrl: https://video.hnsiyao.cn/czg/app/wuyou/extractNotify
|
||||
|
|
@ -0,0 +1 @@
|
|||
center-tables=activity,app,banner,cash_out,comment_good,common_info,complet_award,coupon,coupon_user,course,course_classification,course_collect,course_comment,course_details,course_user,disc_spinning,disc_spinning_amount,disc_spinning_record,help_classify,help_word,invite,invite_award,invite_money,message_info,msg,orders,pay_classify,pay_details,qrtz_blob_triggers,qrtz_calendars,qrtz_cron_triggers,qrtz_fired_triggers,qrtz_job_details,qrtz_locks,qrtz_paused_trigger_grps,qrtz_scheduler_state,qrtz_simple_triggers,qrtz_simprop_triggers,qrtz_triggers,schedule_job,schedule_job_log,sdk_info,sdk_type,search,sys_captcha,sys_config,sys_dict,sys_log,sys_menu,sys_oss,sys_role,sys_role_menu,sys_user,sys_user_role,sys_user_token,task_center,task_center_record,task_center_reward,tb_user,uni_ad_callback_record,url_address,user_integral,user_integral_details,user_money,user_money_details,user_prize_exchange,user_sign_record,user_vip,vip_details,invite_achievement
|
||||
|
|
@ -45,10 +45,14 @@ spring:
|
|||
min-idle: 5 # 连接池中的最小空闲连接
|
||||
mvc:
|
||||
throw-exception-if-no-handler-found: true
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
# pathmatch:
|
||||
# matching-strategy: ant_path_matcher
|
||||
|
||||
|
||||
management:
|
||||
health:
|
||||
db:
|
||||
enabled: false #关闭数据库健康检查isV
|
||||
#mybatis
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:/mapper/**/*.xml
|
||||
|
|
|
|||
|
|
@ -168,9 +168,7 @@
|
|||
(select sum(o.pay_money) from orders o where o.course_id=c.course_id and o.status=1) as payMoney,
|
||||
(select sum(good_num) from course_details d where d.course_id=c.course_id ) as goodNum,
|
||||
(select count(*) from course_details d where d.course_id=c.course_id ) as courseDetailsCount,
|
||||
(select count(*) from course_collect d where d.course_id=c.course_id
|
||||
and date_format(create_time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d') and
|
||||
date_format(create_time,'%Y-%m-%d')<=date_format(#{endTime},'%Y-%m-%d') ) as weekGoodNum,
|
||||
0 as weekGoodNum,
|
||||
(select count(*) from course_details cd where c.course_id=cd.course_id and cd.good=1 ) as isRecommend
|
||||
FROM
|
||||
course AS c
|
||||
|
|
@ -200,7 +198,7 @@
|
|||
<if test='null!= bannerId and bannerId!=0'>
|
||||
and c.banner_id = #{bannerId}
|
||||
</if>
|
||||
<if test="classifyId==0">
|
||||
<if test="classifyId!=null and classifyId==0">
|
||||
and c.is_recommend=1
|
||||
</if>
|
||||
<if test="over!=null and over==1">
|
||||
|
|
|
|||
Loading…
Reference in New Issue