增加攝像頭鏈接狀態

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.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
@Service @Service
@Slf4j @Slf4j
@ -103,18 +104,46 @@ public class CameraService {
cameraMapper.deleteById(id); cameraMapper.deleteById(id);
} }
public PageInfo<Camera> cameras(StreetSearch streetSearch) { public PageInfo<Camera> cameras(StreetSearch streetSearch){
PageHelper.startPage(streetSearch.getPageNum(), streetSearch.getPageSize()); PageHelper.startPage(streetSearch.getPageNum(), streetSearch.getPageSize());
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0)); List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
if(cameras.size() > 0){
CountDownLatch latch = new CountDownLatch(cameras.size());
cameras.forEach(camera -> { 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()); Boolean ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
if(ok){ if(ok){
camera.setStatus("連接正常"); camera.setStatus("連接正常");
}else { }else {
camera.setStatus("未連接"); camera.setStatus("未連接");
} }
}); }catch (Exception e){
return new PageInfo<>(cameras); camera.setStatus("未連接");
}finally {
latch.countDown();
}
}
} }
public Camera detail(Integer id){ public Camera detail(Integer id){

Loading…
Cancel
Save