Compare commits
10 Commits
f65ff27434
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f73e40f791 | ||
|
|
525385a6c3 | ||
|
|
ffb7d8c584 | ||
|
|
589b558924 | ||
|
|
f1cc281b2f | ||
|
|
99e5beb69a | ||
|
|
820b713c95 | ||
|
|
e4fa58310c | ||
|
|
a8e90216e8 | ||
|
|
f86cc6ad74 |
1
pom.xml
1
pom.xml
@@ -33,6 +33,7 @@
|
|||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
<guava.version>16.0.1</guava.version>
|
<guava.version>16.0.1</guava.version>
|
||||||
<mybatis-spring-boot.version>2.3.1</mybatis-spring-boot.version>
|
<mybatis-spring-boot.version>2.3.1</mybatis-spring-boot.version>
|
||||||
|
<mybatis-plus-spring-boot.version>3.5.14</mybatis-plus-spring-boot.version>
|
||||||
<mysql.version>8.0.33</mysql.version>
|
<mysql.version>8.0.33</mysql.version>
|
||||||
<lombok.version>1.18.30</lombok.version>
|
<lombok.version>1.18.30</lombok.version>
|
||||||
<spring-data-redis.version>3.23.6</spring-data-redis.version>
|
<spring-data-redis.version>3.23.6</spring-data-redis.version>
|
||||||
|
|||||||
@@ -73,6 +73,15 @@ public interface IRedisService {
|
|||||||
*/
|
*/
|
||||||
Boolean hasKey(String group, String key);
|
Boolean hasKey(String group, String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置过期时间
|
||||||
|
* @param key key
|
||||||
|
* @param timeout 过期时间
|
||||||
|
* @param unit 时间单位
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
Boolean expire(String key, long timeout, TimeUnit unit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置过期时间
|
* 设置过期时间
|
||||||
* @param group 项目名称
|
* @param group 项目名称
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public class RedisServiceImpl implements IRedisService {
|
|||||||
return redisTemplate.hasKey(buildKey(group, key));
|
return redisTemplate.hasKey(buildKey(group, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean expire(String key, long timeout, TimeUnit unit) {
|
||||||
|
return expire(group, key, timeout, unit);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean expire(String group, String key, long timeout, TimeUnit unit) {
|
public Boolean expire(String group, String key, long timeout, TimeUnit unit) {
|
||||||
return redisTemplate.expire(buildKey(group, key), timeout, unit);
|
return redisTemplate.expire(buildKey(group, key), timeout, unit);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.xiang.xservice.basic.utils;
|
package com.xiang.xservice.basic.utils;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -84,4 +85,31 @@ public class DateUtils {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验是否节假日
|
||||||
|
* @param date 当前日期
|
||||||
|
* @param statusDesc 状态描述,节假日/工作日/周末。1.当status为1时,表示节假日;2.当status为2时,表示工作日;3.当status为null时,如果week为周六或者周日,表示周末,否则表示工作日
|
||||||
|
* @param week 表示星期几
|
||||||
|
* @param status 当天状态标识,1:节假日,2:工作日,null:周末或工作日(可根据week进行判断,也可以直接根据statusDesc进行判断)
|
||||||
|
*
|
||||||
|
* @return 是否是节假日
|
||||||
|
*/
|
||||||
|
public static Boolean validHolidayTime(String date, String statusDesc, String week, String status) {
|
||||||
|
if (StringUtils.equals(status, "1")) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(status, "2")) {
|
||||||
|
log.info("当前日期:{}, {}, 是工作日", date, week);
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(status)) {
|
||||||
|
if (StringUtils.equals(week, "周六") || StringUtils.equals(week, "周日")) {
|
||||||
|
log.info("当前日期:{}, {}, 是周末", date, week);
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiang.xservice.basic.utils;
|
package com.xiang.xservice.basic.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@@ -25,11 +26,15 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
private static final int socketTimeOut = 5000;
|
private static final int socketTimeOut = 10000;
|
||||||
private static final int connectTimeout = 10000;
|
private static final int connectTimeout = 10000;
|
||||||
private static final int connectionRequestTimeout = 3000;
|
private static final int connectionRequestTimeout = 3000;
|
||||||
private static final int defaultMaxPerRoute = 20;
|
private static final int defaultMaxPerRoute = 100;
|
||||||
private static final int maxTotal = 100;
|
private static final int maxTotal = 200;
|
||||||
|
|
||||||
|
private static final int LIVE_TIME = 5000;
|
||||||
|
|
||||||
|
private static final int ALIVE_STRATEGY = 30000;
|
||||||
|
|
||||||
private static final RequestConfig requestConfig = RequestConfig.custom()
|
private static final RequestConfig requestConfig = RequestConfig.custom()
|
||||||
.setConnectTimeout(connectTimeout)
|
.setConnectTimeout(connectTimeout)
|
||||||
@@ -47,12 +52,15 @@ public class HttpUtils {
|
|||||||
connectionManager.setMaxTotal(maxTotal);
|
connectionManager.setMaxTotal(maxTotal);
|
||||||
// 每个主机的最大连接数
|
// 每个主机的最大连接数
|
||||||
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
|
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
|
||||||
|
connectionManager.setValidateAfterInactivity(LIVE_TIME);
|
||||||
|
|
||||||
|
|
||||||
httpClient = HttpClients.custom()
|
httpClient = HttpClients.custom()
|
||||||
.setConnectionManager(connectionManager)
|
.setConnectionManager(connectionManager)
|
||||||
.setDefaultRequestConfig(requestConfig)
|
.setDefaultRequestConfig(requestConfig)
|
||||||
// 清理空闲连接
|
// 清理空闲连接
|
||||||
.evictIdleConnections(30, TimeUnit.SECONDS)
|
.evictIdleConnections(30, TimeUnit.SECONDS)
|
||||||
|
.setKeepAliveStrategy((response, context) -> ALIVE_STRATEGY)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +68,7 @@ public class HttpUtils {
|
|||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
log.info("HTTP请求,请求地址===>{}, 请求参数===>{}", url, jsonParams);
|
log.info("HTTP请求,请求地址===>{}, 请求头===>{}, 请求参数===>{}", url, JSON.toJSONString(header), jsonParams);
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
httpPost.addHeader("Content-Type", "application/json");
|
httpPost.addHeader("Content-Type", "application/json");
|
||||||
// 创建请求内容
|
// 创建请求内容
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.rholder</groupId>
|
<groupId>com.github.rholder</groupId>
|
||||||
<artifactId>guava-retrying</artifactId>
|
<artifactId>guava-retrying</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>1.0.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang</groupId>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>xservice-parent-starter</artifactId>
|
<artifactId>xservice-parent-starter</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -50,12 +51,11 @@
|
|||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>${mysql.version}</version>
|
<version>${mysql.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- MyBatis-Plus 核心依赖 -->
|
||||||
<!-- MyBatis -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
<version>${mybatis-spring-boot.version}</version>
|
<version>${mybatis-plus-spring-boot.version}</version> <!-- 建议使用最新版 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Redis -->
|
<!-- Redis -->
|
||||||
@@ -88,8 +88,8 @@
|
|||||||
<!-- 分页插件 -->
|
<!-- 分页插件 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
<artifactId>pagehelper</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
<version>5.3.3</version>
|
<version>1.4.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 对象转换 -->
|
<!-- 对象转换 -->
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>xservice-web-starter</artifactId>
|
<artifactId>xservice-web-starter</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -21,8 +20,12 @@ public class DynamicTaskScheduler {
|
|||||||
|
|
||||||
|
|
||||||
public void schedule(TaskConfig config, Runnable task) {
|
public void schedule(TaskConfig config, Runnable task) {
|
||||||
|
schedule(config, task, LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void schedule(TaskConfig config, Runnable task, LocalDateTime serverTime) {
|
||||||
LocalDateTime time = config.getExecutionTime();
|
LocalDateTime time = config.getExecutionTime();
|
||||||
if (time.isBefore(LocalDateTime.now())) return;
|
if (time.isBefore(serverTime)) return;
|
||||||
|
|
||||||
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user