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