增加攝像頭鏈接狀態

taiwan-lingli-new
yiming 4 years ago
parent 451193fab6
commit 7f7e2cf6e8

@ -34,6 +34,7 @@ import java.io.IOException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@Service
@Slf4j
@ -103,20 +104,48 @@ public class CameraService {
cameraMapper.deleteById(id);
}
public PageInfo<Camera> cameras(StreetSearch streetSearch) {
public PageInfo<Camera> cameras(StreetSearch streetSearch){
PageHelper.startPage(streetSearch.getPageNum(), streetSearch.getPageSize());
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
cameras.forEach(camera -> {
Boolean ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
if(ok){
camera.setStatus("連接正常");
}else {
camera.setStatus("未連接");
if(cameras.size() > 0){
CountDownLatch latch = new CountDownLatch(cameras.size());
cameras.forEach(camera -> {
StatusThread statusThread = new StatusThread(camera,latch);
statusThread.start();
});
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
return new PageInfo<>(cameras);
}
public class StatusThread extends Thread{
private Camera camera;
private CountDownLatch latch;
public StatusThread(Camera camera,CountDownLatch latch){
this.camera = camera;
this.latch = latch;
}
@Override
public void run() {
try {
Boolean ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
if(ok){
camera.setStatus("連接正常");
}else {
camera.setStatus("未連接");
}
}catch (Exception e){
camera.setStatus("未連接");
}finally {
latch.countDown();
}
}
}
public Camera detail(Integer id){
return cameraMapper.selectById(id);
}

Loading…
Cancel
Save