服务器下载路径修改

This commit is contained in:
liyj 2025-09-08 17:48:27 +08:00
parent 235dfa19a8
commit a4e174385a
4 changed files with 66 additions and 10 deletions

View File

@ -36,6 +36,11 @@ public class DynamicTaskScheduler {
@PostConstruct @PostConstruct
public void initTasks() { public void initTasks() {
//初始化 start
CommentModel commentModel =sxDataService.getCommentModel();
DataBaseInfo enabledTask = sxDataService.getDataBaseInfo(commentModel);
executeTask(enabledTask.getDataBaseName(),commentModel);
//初始化 end
refreshTasks(); refreshTasks();
// 每5分钟检查一次数据库更新 // 每5分钟检查一次数据库更新
taskScheduler.scheduleAtFixedRate(this::refreshTasks, Duration.ofHours(1)); taskScheduler.scheduleAtFixedRate(this::refreshTasks, Duration.ofHours(1));

View File

@ -30,7 +30,7 @@ public class HttpUtils {
public static final String URL_SYNC_GET_APPSIGN="/shop/sync/third/getAppSign";//获取密文 public static final String URL_SYNC_GET_APPSIGN="/shop/sync/third/getAppSign";//获取密文
public static final String URL_SYNC_GET_DOWNCLIENTJAR="/shop/sync/app/downClientJar";//文件下载 public static final String URL_SYNC_GET_DOWNCLIENTJAR="/shop/sync/third/app/downClientJar";//文件下载
public static final String URL_SYNC_GET_STOREdBCONFIG="/shop/sync/third/getStoreDbConfig";//获取数据库配置 public static final String URL_SYNC_GET_STOREdBCONFIG="/shop/sync/third/getStoreDbConfig";//获取数据库配置

View File

@ -52,7 +52,7 @@ public class SxDataDao extends BaseDao{
public final static String DEFALTWHERE="where 1=1"; public final static String DEFALTWHERE="where 1=1";
public final static String DEFAULT_IMG="https://digitalassets.tesla.com/tesla-contents/image/upload/f_auto,q_auto/Homepage-Model-Y-2-Promo-Hero-Tablet-CN.png"; public final static String DEFAULT_IMG="https://media-mall-prod-1259811287.cos.ap-guangzhou.myqcloud.com/media/media/plantform/20250906/b93a9751b35a49fca6cf979829230868.png";
private final static String T_PUB_PLAN_MASTER="t_pub_plan_master";//活动方案表 private final static String T_PUB_PLAN_MASTER="t_pub_plan_master";//活动方案表

View File

@ -22,24 +22,31 @@ import com.small.client.service.WebClientService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity; import org.springframework.http.*;
import org.springframework.http.HttpHeaders; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import javax.net.ssl.SSLContext;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.time.Duration; import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -591,12 +598,24 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
} }
log.info("文件下载目录: {}", downloadDirectory); log.info("文件下载目录: {}", downloadDirectory);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<>(headers); // headers.set("User-Agent", "Apifox/1.0.0 (https://apifox.com)");
headers.setAccept(Collections.singletonList(MediaType.ALL)); // 对应 */*
headers.set("Accept-Encoding", "gzip, deflate, br");
// 可以添加其他Apifox可能发送的头部
headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
headers.set("Connection", "keep-alive");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
String encryptedData = getPrimaryKey(); String encryptedData = getPrimaryKey();
String url = UriComponentsBuilder.fromHttpUrl(remoteIp + HttpUtils.URL_SYNC_GET_DOWNCLIENTJAR)
.queryParam("primaryKey", encryptedData)
.queryParam("clienVersionName", versionName)
.toUriString();
log.info("url:{}",url);
// RestTemplate myRestTemplate = createUnsafeRestTemplate();
ResponseEntity<Resource> response = restTemplate.exchange( ResponseEntity<Resource> response = restTemplate.exchange(
remoteIp+HttpUtils.URL_SYNC_GET_DOWNCLIENTJAR+"?primaryKey="+encryptedData url,
+"&clienVersionName="+versionName,
HttpMethod.GET, HttpMethod.GET,
requestEntity, requestEntity,
Resource.class); Resource.class);
@ -649,6 +668,8 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
return downloadDirectory+originalFileName; return downloadDirectory+originalFileName;
} }
@Override @Override
public void checkForUpdates() { public void checkForUpdates() {
log.info("curentPath:{}",JarPathUtil.getRuntimePath()); log.info("curentPath:{}",JarPathUtil.getRuntimePath());
@ -818,5 +839,35 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
return map; return map;
} }
/**
* 创建跳过SSL验证的RestTemplate
* 仅用于测试环境生产环境不安全
*/
private RestTemplate createUnsafeRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
// 配置请求参数
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(30000)
.setSocketTimeout(30000)
.setRedirectsEnabled(true)
.setMaxRedirects(10)
.build();
// 创建SSL上下文信任所有证书 - 仅测试环境使用
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial((chain, authType) -> true)
.build();
// 创建HttpClient配置SSL和重定向
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(config)
.setSSLContext(sslContext)
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
// 创建请求工厂
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(factory);
}
} }