Compare commits
2 Commits
0ac0976ecf
...
80bda515df
| Author | SHA1 | Date | |
|---|---|---|---|
| 80bda515df | |||
| 2cf27154dc |
@ -48,7 +48,7 @@ public class EbikeCoreHandler {
|
||||
* @param ecuID 中控ID
|
||||
* @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<>();
|
||||
EbikeEcuInfoService ebikeEcuInfoService = SpringContextHolder.getBean(EbikeEcuInfoService.class);
|
||||
EbikeEcuInfo ebikeEcuInfo = ebikeEcuInfoService.getById(ecuID);
|
||||
@ -57,8 +57,10 @@ public class EbikeCoreHandler {
|
||||
cmdMsg.setGroup(ebikeEcuInfo.getOperatorCode());
|
||||
|
||||
String tid = UUID.randomUUID().toString().replace("-", "");
|
||||
ReqEbikeBikeComDto reqEbikeBikeComDto = new ReqEbikeBikeComDto(String.valueOf(bikeId),String.valueOf(staffId),cmdCode,"1","1");
|
||||
commandRecords.put(tid, reqEbikeBikeComDto);
|
||||
if (bikeId != null) {
|
||||
ReqEbikeBikeComDto reqEbikeBikeComDto = new ReqEbikeBikeComDto(String.valueOf(bikeId), String.valueOf(staffId), cmdCode, "1", "1");
|
||||
commandRecords.put(tid, reqEbikeBikeComDto);
|
||||
}
|
||||
String command = getCommand(cmdCode, tid);
|
||||
cmdMsg.setCommand(command);
|
||||
// 注册响应监听
|
||||
@ -70,11 +72,15 @@ public class EbikeCoreHandler {
|
||||
// 设置超时任务(30秒未响应则超时)
|
||||
timeoutScheduler.schedule(() -> {
|
||||
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) {
|
||||
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
|
||||
ReqEbikeBikeComDto log = commandRecords.get(tid);
|
||||
log.setOperateResult("0");
|
||||
comService.save(log);
|
||||
timedOutFuture.completeExceptionally(new TimeoutException("超时未响应"));
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
@ -98,9 +104,9 @@ public class EbikeCoreHandler {
|
||||
*/
|
||||
public void completeFuture(String tid, String response) {
|
||||
CompletableFuture<String> future = pendingRequests.remove(tid);
|
||||
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
|
||||
ReqEbikeBikeComDto log = commandRecords.remove(tid);
|
||||
if (log != null) {
|
||||
EbikeBikeComService comService = SpringContextHolder.getBean(EbikeBikeComService.class);
|
||||
log.setOperateResult("1");
|
||||
comService.save(log);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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 {
|
||||
EbikeEcuInfo ebikeEcuInfo = ecuInfoService.getById(ecuId);
|
||||
boolean online = EmqxApiClient.isClientOnline(ebikeEcuInfo.getEcuSn());
|
||||
@ -86,7 +86,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.VIDEO_5, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -116,7 +116,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -157,7 +157,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -186,7 +186,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.CLOSE_BATTERY_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -215,7 +215,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -244,7 +244,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.UNLOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -273,7 +273,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.OPEN_HEMET, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -302,7 +302,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.CAMERA_RETURN, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -331,7 +331,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.CANCEL_ANTI_THEFT, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -361,7 +361,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.GPS, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -391,7 +391,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.RESTART, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
@ -421,7 +421,7 @@ public class EbikeCoreController {
|
||||
* @return 执行结构
|
||||
*/
|
||||
@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秒超时
|
||||
ebikeCoreService.executeCommand(ecuId, CmdCode.TEMP_LOCK, bikeId,getStaffId() ).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
|
||||
@ -18,7 +18,6 @@ import com.cdzy.ebikeoperate.model.pojo.EbikeRegion;
|
||||
import com.cdzy.ebikeoperate.model.pojo.EbikeRegionoperation;
|
||||
import com.cdzy.ebikeoperate.service.EbikeAdministrationZoneService;
|
||||
import com.cdzy.ebikeoperate.service.EbikeRegionService;
|
||||
import com.cdzy.ebikeoperate.utils.RedisUtil;
|
||||
import com.ebike.feign.clients.StaffFeignClient;
|
||||
import com.ebike.feign.model.rsp.RspBikeInfo;
|
||||
import com.ebike.feign.model.rsp.StaffFeign;
|
||||
@ -53,9 +52,6 @@ public class EbikeRegionController {
|
||||
@Resource
|
||||
private EbikeAdministrationZoneService zoneService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private StaffFeignClient staffFeignClient;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user