package com.ruoyi.dataInterchange.controller;
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.dataInterchange.dao.UPPlaybackMsgControlAckDao;
|
import com.ruoyi.dataInterchange.dao.UPPlaybackMsgStartupAckDao;
|
import com.ruoyi.dataInterchange.model.UPPlaybackMsgControlAck;
|
import com.ruoyi.dataInterchange.model.UPPlaybackMsgStartupAck;
|
import com.ruoyi.dataInterchange.server.DOWNPlaybackMsgControlService;
|
import com.ruoyi.dataInterchange.server.DOWNPlaybackMsgStartupService;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2025/3/24 9:45
|
*/
|
@RestController
|
@RequestMapping("/playbackMsg")
|
public class PlaybackMsgController {
|
|
@Resource
|
private DOWNPlaybackMsgStartupService downPlaybackMsgStartupService;
|
|
@Resource
|
private UPPlaybackMsgStartupAckDao upPlaybackMsgStartupAckDao;
|
|
@Resource
|
private UPPlaybackMsgControlAckDao upPlaybackMsgControlAckDao;
|
|
@Resource
|
private DOWNPlaybackMsgControlService downPlaybackMsgControlService;
|
|
|
/**
|
* 远程录像回放请求
|
*
|
* @param inferiorPlatformId
|
* @param vehicleNo
|
* @return
|
*/
|
@PostMapping("/playbackMsgStartup")
|
public R<UPPlaybackMsgStartupAck> playbackMsgStartup(@RequestParam("inferiorPlatformId") Integer inferiorPlatformId, @RequestParam("vehicleNo") String vehicleNo,
|
@RequestParam("startTime") LocalDateTime startTime, @RequestParam("endTime") LocalDateTime endTime) {
|
R r = downPlaybackMsgStartupService.playbackMsgStartup(inferiorPlatformId, vehicleNo, startTime, endTime);
|
if (200 != r.getCode()) {
|
return r;
|
}
|
//发送成功,定时任务获取响应结果
|
int num = 0;
|
LocalDateTime now = LocalDateTime.now();
|
while (true) {
|
UPPlaybackMsgStartupAck upPlaybackMsgStartupAck = upPlaybackMsgStartupAckDao.findByInferiorPlatformIdAndVehicleNoAndCreateTimeAfter(inferiorPlatformId, vehicleNo, now);
|
if (null == upPlaybackMsgStartupAck) {
|
try {
|
Thread.sleep(1000L);
|
} catch (InterruptedException e) {
|
throw new RuntimeException(e);
|
}
|
num++;
|
continue;
|
}
|
if (null != upPlaybackMsgStartupAck || num >= 30) {
|
return R.ok(upPlaybackMsgStartupAck);
|
}
|
}
|
}
|
|
|
/**
|
* 远程录像回放控制
|
*
|
* @param inferiorPlatformId 平台唯一码
|
* @param vehicleNo 车牌号
|
* @param controlType 控制类型
|
* @param fastTime 快进快退倍数
|
* @return
|
*/
|
@PostMapping("/playbackMsgControl")
|
public R<Integer> playbackMsgControl(@RequestParam("inferiorPlatformId") Integer inferiorPlatformId, @RequestParam("vehicleNo") String vehicleNo,
|
@RequestParam("controlType") Integer controlType, @RequestParam("fastTime") Integer fastTime) {
|
R r = downPlaybackMsgControlService.playbackMsgControl(inferiorPlatformId, vehicleNo, controlType, fastTime);
|
if (200 != r.getCode()) {
|
return r;
|
}
|
//发送成功,定时任务获取响应结果
|
int num = 0;
|
LocalDateTime now = LocalDateTime.now();
|
while (true) {
|
UPPlaybackMsgControlAck upPlaybackMsgControlAck = upPlaybackMsgControlAckDao.findByInferiorPlatformIdAndVehicleNoAndCreateTimeAfter(inferiorPlatformId, vehicleNo, now);
|
if (null == upPlaybackMsgControlAck) {
|
try {
|
Thread.sleep(1000L);
|
} catch (InterruptedException e) {
|
throw new RuntimeException(e);
|
}
|
num++;
|
continue;
|
}
|
if (null != upPlaybackMsgControlAck) {
|
return R.ok(upPlaybackMsgControlAck.getResult());
|
}
|
if (num >= 30) {
|
return R.fail("远程响应失败");
|
}
|
}
|
}
|
}
|