|
|
|
|
@ -33,9 +33,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@ -114,30 +115,58 @@ public class CameraService {
|
|
|
|
|
Assert.isTrue(count == null || count == 0, "球机已被绑定");
|
|
|
|
|
cameraMapper.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(20);
|
|
|
|
|
public PageInfo<Camera> cameras(StreetSearch streetSearch) {
|
|
|
|
|
PageHelper.startPage(streetSearch.getPageNum(), streetSearch.getPageSize());
|
|
|
|
|
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
|
|
|
|
|
List<Camera> collect = cameras.parallelStream().peek(camera -> {
|
|
|
|
|
|
|
|
|
|
Boolean ok = false;
|
|
|
|
|
if(CameraConnMap.getConnId(camera.getId())!=null){
|
|
|
|
|
if (configProperties.getCameraConfig().getCameraType() == ConfigProperties.HIK_CAMERA) {
|
|
|
|
|
|
|
|
|
|
ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
|
|
|
|
|
} else {
|
|
|
|
|
ok = JoywareLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok) {
|
|
|
|
|
camera.setStatus("连接正常");
|
|
|
|
|
} else {
|
|
|
|
|
//CameraConnMap.disConn(camera.getId());
|
|
|
|
|
camera.setStatus("未连接");
|
|
|
|
|
cameraLogin(camera);
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
return new PageInfo<>(collect);
|
|
|
|
|
}
|
|
|
|
|
// List<Future<Boolean>> futureTasks = new ArrayList<>();
|
|
|
|
|
// for(Camera camera : cameras){
|
|
|
|
|
//
|
|
|
|
|
// FutureTask<Boolean> futureTask = new FutureTask<>(() -> {
|
|
|
|
|
// Boolean ok = false;
|
|
|
|
|
// if(CameraConnMap.getConnId(camera.getId())!=null){
|
|
|
|
|
// if (configProperties.getCameraConfig().getCameraType() == ConfigProperties.HIK_CAMERA) {
|
|
|
|
|
//
|
|
|
|
|
// ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
|
|
|
|
|
// } else {
|
|
|
|
|
// ok = JoywareLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (ok) {
|
|
|
|
|
// camera.setStatus("连接正常");
|
|
|
|
|
// } else {
|
|
|
|
|
// //CameraConnMap.disConn(camera.getId());
|
|
|
|
|
// camera.setStatus("未连接");
|
|
|
|
|
// cameraLogin(camera);
|
|
|
|
|
// }
|
|
|
|
|
// return ok;
|
|
|
|
|
// });
|
|
|
|
|
// futureTasks.add(futureTask);
|
|
|
|
|
// executor.execute(futureTask);
|
|
|
|
|
// }
|
|
|
|
|
// for (Future<Boolean> f :futureTasks){
|
|
|
|
|
// try {
|
|
|
|
|
// f.get();
|
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
// } catch (ExecutionException e) {
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return new PageInfo<>(cameras);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StatusThread extends Thread {
|
|
|
|
|
@ -154,7 +183,7 @@ public class CameraService {
|
|
|
|
|
try {
|
|
|
|
|
Boolean ok = false;
|
|
|
|
|
if (configProperties.getCameraConfig().getCameraType() == ConfigProperties.HIK_CAMERA) {
|
|
|
|
|
if(CameraConnMap.getConnId(camera.getId()) ==null){
|
|
|
|
|
if(CameraConnMap.getConnId(camera.getId()) == null){
|
|
|
|
|
cameraLogin(camera);
|
|
|
|
|
}
|
|
|
|
|
ok = HikLoginModuleImpl.connectStatus(CameraConnMap.getConnId(camera.getId()).intValue());
|
|
|
|
|
|