| | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.CountDownLatch; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | |
| | | //获取当前任务中的车船信息 |
| | | List<TaskDetailVehicles> taskDetailVehicles = taskDetailVehiclesService.selectList(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id)); |
| | | int errNum = 0; |
| | | for (TaskDetailVehicles taskDetailVehicle : taskDetailVehicles) { |
| | | //根据企业id分组用于定义多线上处理 |
| | | Set<String> collect = taskDetailVehicles.stream().map(TaskDetailVehicles::getCompanyId).collect(Collectors.toSet()); |
| | | //定义线程池 |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(collect.size(), collect.size(), 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | //定义多线程阻塞 |
| | | CountDownLatch countDownLatch = new CountDownLatch(collect.size()); |
| | | for (String companyId : collect) { |
| | | List<TaskDetailVehicles> vehicles = taskDetailVehicles.stream().filter(s -> s.getCompanyId().equals(companyId)).collect(Collectors.toList()); |
| | | threadPoolExecutor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | for (TaskDetailVehicles taskDetailVehicle : vehicles) { |
| | | try { |
| | | taskDetailVehicle.setStartExecutionTime(LocalDateTime.now()); |
| | | Integer taskDetailVehicleId = taskDetailVehicle.getId(); |
| | |
| | | String fileId = VideoGateway.cameraShot2018(terminalId, videoChannel, 0); |
| | | if(null == fileId){ |
| | | log.error("2018年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); |
| | | throw new RuntimeException(); |
| | | throw new RuntimeException("2018年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); |
| | | }else{ |
| | | //等待15秒 |
| | | Thread.sleep(30000); |
| | |
| | | fileId = VideoGateway.cameraShot2018(terminalId, videoChannel, 0); |
| | | if(null == fileId){ |
| | | log.error("2018年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); |
| | | throw new Exception(); |
| | | throw new RuntimeException("2018年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); |
| | | }else{ |
| | | //等待15秒 |
| | | Thread.sleep(30000); |
| | |
| | | fileUrl = VideoGateway.getCameraShotByFileId2018(terminalId, fileId, 0); |
| | | if(null == fileUrl){ |
| | | log.error("2018年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); |
| | | throw new Exception(); |
| | | throw new RuntimeException("2018年协议车辆获取拍摄图片失败:terminalId-->" + terminalId + ",fileId-->" + fileId); |
| | | }else{ |
| | | taskDetailVehiclesChannel.setImageUrl(fileUrl); |
| | | taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); |
| | |
| | | String fileId = VideoGateway.cameraShot2023(vehicleId, vehicleType, terminalId, videoChannel, 0); |
| | | if(null == fileId){ |
| | | log.error("2023年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); |
| | | throw new Exception(); |
| | | throw new RuntimeException("2023年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); |
| | | }else{ |
| | | //等待15秒 |
| | | Thread.sleep(30000); |
| | |
| | | fileId = VideoGateway.cameraShot2023(vehicleId, vehicleType, terminalId, videoChannel, 0); |
| | | if(null == fileId){ |
| | | log.error("2023年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); |
| | | throw new Exception(); |
| | | throw new RuntimeException("2023年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); |
| | | }else{ |
| | | //等待15秒 |
| | | Thread.sleep(30000); |
| | |
| | | fileUrl = VideoGateway.getCameraShotByFileId2023(fileId, 0); |
| | | if(null == fileUrl){ |
| | | log.error("2023年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); |
| | | throw new Exception(); |
| | | throw new RuntimeException("2023年协议车辆获取拍摄图片失败:terminalId-->" + terminalId + ",fileId-->" + fileId); |
| | | }else{ |
| | | taskDetailVehiclesChannel.setImageUrl(fileUrl); |
| | | taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); |
| | |
| | | taskDetailVehicle.setEndExecutionTime(LocalDateTime.now()); |
| | | taskDetailVehicle.setStatus(5); |
| | | taskDetailVehiclesService.updateById(taskDetailVehicle); |
| | | errNum++; |
| | | } |
| | | } |
| | | |
| | | taskDetail.setStatus(0 == errNum ? 3 : 4); |
| | | |
| | | //当前线程执行完成后减少等待数 |
| | | countDownLatch.countDown(); |
| | | } |
| | | }); |
| | | } |
| | | try { |
| | | countDownLatch.await(); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | int count = taskDetailVehiclesService.selectCount(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id).eq("status", 5)); |
| | | taskDetail.setStatus(count > 0 ? 4 : 3); |
| | | taskDetailService.updateById(taskDetail); |
| | | } |
| | | |