no message

This commit is contained in:
2025-09-29 13:52:55 +08:00
parent 58462e5cb2
commit c8d32a77a2

View File

@ -12,11 +12,17 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
/** /**
@ -33,6 +39,11 @@ public class SendDataController {
@Autowired @Autowired
private SendDataService sendDataService; private SendDataService sendDataService;
@Autowired
@Lazy
@Qualifier("taskExecutor")
private Executor taskExecutor;
@ApiOperation(value = "接收需同步数据接口") @ApiOperation(value = "接收需同步数据接口")
@PostMapping("/dataToBattery") @PostMapping("/dataToBattery")
public Result sendDataToBattery(@RequestBody DataRceiveReq dataRceiveReq){ public Result sendDataToBattery(@RequestBody DataRceiveReq dataRceiveReq){
@ -62,12 +73,43 @@ public class SendDataController {
return sendDataService.sendStoreInfoToBattery(Long.parseLong(id)); return sendDataService.sendStoreInfoToBattery(Long.parseLong(id));
} }
@ApiOperation(value = "接收充电同步数据接口") // @ApiOperation(value = "接收充电同步数据接口")
// @GetMapping("/subOrder/{id}")
// public Map<String,String> sendSubOrderToBattery(@PathVariable String id){
// log.info("/subOrder 接收充电数据:{}",id);
// return sendDataService.sendSubOrderToBattery(Long.parseLong(id));
// }
@ApiOperation(value = "异步接收充电同步数据接口")
@GetMapping("/subOrder/{id}") @GetMapping("/subOrder/{id}")
public Map<String,String> sendSubOrderToBattery(@PathVariable String id){ public CompletableFuture<ResponseEntity<Map<String, String>>> sendSubOrderToBattery(@PathVariable String id){
log.info("/subOrder 接收充电数据:{}",id); log.info("/subOrder 接收充电数据:{}",id);
return CompletableFuture
.supplyAsync(() -> {
try {
return sendDataService.sendSubOrderToBattery(Long.parseLong(id)); return sendDataService.sendSubOrderToBattery(Long.parseLong(id));
} catch (Exception e) {
log.error("处理用户数据时发生异常", e);
Map<String, String> errorResponse = new HashMap<>();
errorResponse.put("code", "9999");
errorResponse.put("msg", "处理失败: " + e.getMessage());
return errorResponse;
} }
}, taskExecutor)
.thenApply(result -> {
log.info("用户数据处理完成,返回结果: {}", result);
return ResponseEntity.ok(result);
})
.exceptionally(throwable -> {
log.error("异步处理用户数据时发生异常", throwable);
Map<String, String> errorResponse = new HashMap<>();
errorResponse.put("code", "9999");
errorResponse.put("msg", "系统异常");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
});
}
// //