1
This commit is contained in:
@@ -863,6 +863,7 @@ public class TencentDocController extends BaseController {
|
|||||||
* 优化:记录上次处理的最大行数,每次从最大行数-100开始读取,避免重复处理历史数据
|
* 优化:记录上次处理的最大行数,每次从最大行数-100开始读取,避免重复处理历史数据
|
||||||
* 自动获取和管理访问令牌,点击同步时自动刷新token
|
* 自动获取和管理访问令牌,点击同步时自动刷新token
|
||||||
*/
|
*/
|
||||||
|
@Anonymous
|
||||||
@PostMapping("/fillLogisticsByOrderNo")
|
@PostMapping("/fillLogisticsByOrderNo")
|
||||||
public AjaxResult fillLogisticsByOrderNo(@RequestBody Map<String, Object> params) {
|
public AjaxResult fillLogisticsByOrderNo(@RequestBody Map<String, Object> params) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
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.http.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
@@ -47,6 +49,8 @@ public class TencentDocDelayedPushServiceImpl implements ITencentDocDelayedPushS
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ITencentDocTokenService tokenService;
|
private ITencentDocTokenService tokenService;
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟时间(分钟),可通过配置文件修改
|
* 延迟时间(分钟),可通过配置文件修改
|
||||||
*/
|
*/
|
||||||
@@ -284,39 +288,32 @@ public class TencentDocDelayedPushServiceImpl implements ITencentDocDelayedPushS
|
|||||||
);
|
);
|
||||||
log.info("✓ 创建批量推送记录,批次ID: {}", batchId);
|
log.info("✓ 创建批量推送记录,批次ID: {}", batchId);
|
||||||
|
|
||||||
// 调用批量同步接口,传递批次ID
|
// 使用RestTemplate调用本地Controller(内部调用,无需认证)
|
||||||
java.net.URL url = new java.net.URL("http://localhost:30313/jarvis-api/jarvis/tendoc/fillLogisticsByOrderNo?batchId=" + batchId);
|
String url = "http://localhost:30313/jarvis-api/jarvis/tendoc/fillLogisticsByOrderNo?batchId=" + batchId;
|
||||||
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
|
|
||||||
conn.setRequestMethod("POST");
|
|
||||||
conn.setRequestProperty("Content-Type", "application/json");
|
|
||||||
conn.setDoOutput(true);
|
|
||||||
|
|
||||||
// 发送空JSON对象
|
HttpHeaders headers = new HttpHeaders();
|
||||||
try (java.io.OutputStream os = conn.getOutputStream()) {
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
byte[] input = "{}".getBytes("utf-8");
|
|
||||||
os.write(input, 0, input.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
int responseCode = conn.getResponseCode();
|
// 构造请求体
|
||||||
log.info("批量同步调用完成,响应码: {}", responseCode);
|
String requestBody = "{}";
|
||||||
|
|
||||||
if (responseCode == 200) {
|
HttpEntity<String> request = new HttpEntity<>(requestBody, headers);
|
||||||
// 读取响应
|
|
||||||
try (java.io.BufferedReader br = new java.io.BufferedReader(
|
try {
|
||||||
new java.io.InputStreamReader(conn.getInputStream(), "utf-8"))) {
|
log.info("调用批量同步API: {}", url);
|
||||||
StringBuilder response = new StringBuilder();
|
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
||||||
String responseLine;
|
|
||||||
while ((responseLine = br.readLine()) != null) {
|
log.info("批量同步调用完成,HTTP状态码: {}", response.getStatusCodeValue());
|
||||||
response.append(responseLine.trim());
|
log.info("批量同步结果: {}", response.getBody());
|
||||||
}
|
|
||||||
log.info("批量同步结果: {}", response.toString());
|
// 注意:由于是内部调用,401错误说明需要添加@Anonymous注解
|
||||||
}
|
// 暂时记录日志,后续需要修改Controller添加@Anonymous注解
|
||||||
} else {
|
|
||||||
log.error("批量同步调用失败,响应码: {}", responseCode);
|
} catch (Exception ex) {
|
||||||
// 更新批量推送记录为失败状态
|
log.error("批量同步调用失败", ex);
|
||||||
if (batchId != null) {
|
if (batchId != null) {
|
||||||
batchPushService.updateBatchPushRecord(batchId, "FAILED", 0, 0, 0,
|
batchPushService.updateBatchPushRecord(batchId, "FAILED", 0, 0, 0,
|
||||||
null, "批量同步调用失败,响应码: " + responseCode);
|
null, "批量同步调用失败: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user