测试中控:包含bikeId记录日志、不包含则不记录

This commit is contained in:
attiya 2025-04-29 09:08:12 +08:00
parent 2727b3ab7f
commit 2cf27154dc
3 changed files with 27 additions and 25 deletions

View File

@ -48,7 +48,7 @@ public class EbikeCoreHandler {
* @param ecuID 中控ID * @param ecuID 中控ID
* @return 一致性返回 * @return 一致性返回
*/ */
public CompletableFuture<String> executeCommand(Long ecuID, String cmdCode,Long bikeId,Long staffId) { public CompletableFuture<String> executeCommand(Long ecuID, String cmdCode, Long bikeId, Long staffId) {
CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> future = new CompletableFuture<>();
EbikeEcuInfoService ebikeEcuInfoService = SpringContextHolder.getBean(EbikeEcuInfoService.class); EbikeEcuInfoService ebikeEcuInfoService = SpringContextHolder.getBean(EbikeEcuInfoService.class);
EbikeEcuInfo ebikeEcuInfo = ebikeEcuInfoService.getById(ecuID); EbikeEcuInfo ebikeEcuInfo = ebikeEcuInfoService.getById(ecuID);
@ -57,8 +57,10 @@ public class EbikeCoreHandler {
cmdMsg.setGroup(ebikeEcuInfo.getOperatorCode()); cmdMsg.setGroup(ebikeEcuInfo.getOperatorCode());
String tid = UUID.randomUUID().toString().replace("-", ""); String tid = UUID.randomUUID().toString().replace("-", "");
ReqEbikeBikeComDto reqEbikeBikeComDto = new ReqEbikeBikeComDto(String.valueOf(bikeId),String.valueOf(staffId),cmdCode,"1","1"); if (bikeId != null) {
commandRecords.put(tid, reqEbikeBikeComDto); ReqEbikeBikeComDto reqEbikeBikeComDto = new ReqEbikeBikeComDto(String.valueOf(bikeId), String.valueOf(staffId), cmdCode, "1", "1");
commandRecords.put(tid, reqEbikeBikeComDto);
}
String command = getCommand(cmdCode, tid); String command = getCommand(cmdCode, tid);
cmdMsg.setCommand(command); cmdMsg.setCommand(command);
// 注册响应监听 // 注册响应监听
@ -70,11 +72,15 @@ public class EbikeCoreHandler {
// 设置超时任务30秒未响应则超时 // 设置超时任务30秒未响应则超时
timeoutScheduler.schedule(() -> { timeoutScheduler.schedule(() -> {
CompletableFuture<String> timedOutFuture = pendingRequests.remove(tid); CompletableFuture<String> timedOutFuture = pendingRequests.remove(tid);
if (bikeId != null) {
ReqEbikeBikeComDto log = commandRecords.remove(tid);
if (log != null) {
log.setOperateResult("0");
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
comService.save(log);
}
}
if (timedOutFuture != null) { if (timedOutFuture != null) {
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
ReqEbikeBikeComDto log = commandRecords.get(tid);
log.setOperateResult("0");
comService.save(log);
timedOutFuture.completeExceptionally(new TimeoutException("超时未响应")); timedOutFuture.completeExceptionally(new TimeoutException("超时未响应"));
} }
}, 5, TimeUnit.SECONDS); }, 5, TimeUnit.SECONDS);
@ -98,9 +104,9 @@ public class EbikeCoreHandler {
*/ */
public void completeFuture(String tid, String response) { public void completeFuture(String tid, String response) {
CompletableFuture<String> future = pendingRequests.remove(tid); CompletableFuture<String> future = pendingRequests.remove(tid);
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
ReqEbikeBikeComDto log = commandRecords.remove(tid); ReqEbikeBikeComDto log = commandRecords.remove(tid);
if (log != null) { if (log != null) {
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
log.setOperateResult("1"); log.setOperateResult("1");
comService.save(log); comService.save(log);
} }

View File

@ -67,7 +67,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("online") @GetMapping("online")
public JsonResult<?> online(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) throws IOException { public JsonResult<?> online(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) throws IOException {
try { try {
EbikeEcuInfo ebikeEcuInfo = ecuInfoService.getById(ecuId); EbikeEcuInfo ebikeEcuInfo = ecuInfoService.getById(ecuId);
boolean online = EmqxApiClient.isClientOnline(ebikeEcuInfo.getEcuSn()); boolean online = EmqxApiClient.isClientOnline(ebikeEcuInfo.getEcuSn());
@ -86,7 +86,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("findEbike") @GetMapping("findEbike")
public DeferredResult<JsonResult<?>> findEbike(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> findEbike(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.VIDEO_5, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.VIDEO_5, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -116,7 +116,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("gps") @GetMapping("gps")
public DeferredResult<JsonResult<?>> gps(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> gps(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -157,7 +157,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("openBatteryLock") @GetMapping("openBatteryLock")
public DeferredResult<JsonResult<?>> openBatteryLock(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> openBatteryLock(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -186,7 +186,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("closeBatteryLock") @GetMapping("closeBatteryLock")
public DeferredResult<JsonResult<?>> closeBatteryLock(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> closeBatteryLock(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.CLOSE_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.CLOSE_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -215,7 +215,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("lock") @GetMapping("lock")
public DeferredResult<JsonResult<?>> lock(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> lock(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -244,7 +244,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("unlock") @GetMapping("unlock")
public DeferredResult<JsonResult<?>> unlock(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> unlock(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.UNLOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.UNLOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -273,7 +273,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("openHelmet") @GetMapping("openHelmet")
public DeferredResult<JsonResult<?>> openHelmet(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> openHelmet(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_HEMET, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_HEMET, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -302,7 +302,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("cameraReturn") @GetMapping("cameraReturn")
public DeferredResult<JsonResult<?>> cameraReturn(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> cameraReturn(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.CAMERA_RETURN, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.CAMERA_RETURN, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -331,7 +331,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("cancelAntiTheft") @GetMapping("cancelAntiTheft")
public DeferredResult<JsonResult<?>> cancelAntiTheft(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> cancelAntiTheft(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.CANCEL_ANTI_THEFT, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.CANCEL_ANTI_THEFT, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -361,7 +361,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("powerOff") @GetMapping("powerOff")
public DeferredResult<JsonResult<?>> powerOff(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> powerOff(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -391,7 +391,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("restart") @GetMapping("restart")
public DeferredResult<JsonResult<?>> restart(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> restart(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.RESTART, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.RESTART, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {
@ -421,7 +421,7 @@ public class EbikeCoreController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("tempLock") @GetMapping("tempLock")
public DeferredResult<JsonResult<?>> tempLock(@RequestParam("ecuId") Long ecuId, @RequestParam("bikeId") Long bikeId) { public DeferredResult<JsonResult<?>> tempLock(@RequestParam("ecuId") Long ecuId, @RequestParam(value = "bikeId",required = false) Long bikeId) {
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时 DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
ebikeCoreService.executeCommand(ecuId, CmdCode.TEMP_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> { ebikeCoreService.executeCommand(ecuId, CmdCode.TEMP_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
if (ex != null) { if (ex != null) {

View File

@ -18,7 +18,6 @@ import com.cdzy.ebikeoperate.model.pojo.EbikeRegion;
import com.cdzy.ebikeoperate.model.pojo.EbikeRegionoperation; import com.cdzy.ebikeoperate.model.pojo.EbikeRegionoperation;
import com.cdzy.ebikeoperate.service.EbikeAdministrationZoneService; import com.cdzy.ebikeoperate.service.EbikeAdministrationZoneService;
import com.cdzy.ebikeoperate.service.EbikeRegionService; import com.cdzy.ebikeoperate.service.EbikeRegionService;
import com.cdzy.ebikeoperate.utils.RedisUtil;
import com.ebike.feign.clients.StaffFeignClient; import com.ebike.feign.clients.StaffFeignClient;
import com.ebike.feign.model.rsp.RspBikeInfo; import com.ebike.feign.model.rsp.RspBikeInfo;
import com.ebike.feign.model.rsp.StaffFeign; import com.ebike.feign.model.rsp.StaffFeign;
@ -53,9 +52,6 @@ public class EbikeRegionController {
@Resource @Resource
private EbikeAdministrationZoneService zoneService; private EbikeAdministrationZoneService zoneService;
@Resource
private RedisUtil redisUtil;
@Resource @Resource
private StaffFeignClient staffFeignClient; private StaffFeignClient staffFeignClient;