不要阻塞程序启动!!!

This commit is contained in:
wangliwen 2022-06-03 16:36:30 +08:00
parent cd082d34d2
commit ddc3417007
2 changed files with 200 additions and 188 deletions

View File

@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutionException;
@RestController @RestController
@RequestMapping("api/project") @RequestMapping("api/project")
@ -21,6 +22,7 @@ public class FileController {
/** /**
* 根据摄像头标识获取视频流 * 根据摄像头标识获取视频流
*
* @param channelCode * @param channelCode
* @return * @return
* @throws IOException * @throws IOException
@ -34,8 +36,8 @@ public class FileController {
} }
@GetMapping("token") @GetMapping("token")
public Result token( ) { public Result token() throws ExecutionException, InterruptedException {
String s = monitorService.init(); String s = monitorService.init().get();
Result success = Result.success(s); Result success = Result.success(s);
return success; return success;
} }

View File

@ -36,6 +36,7 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
@Service @Service
@ -86,16 +87,16 @@ public class MonitorService {
static int keepaliveCount = 16; static int keepaliveCount = 16;
@PostConstruct @PostConstruct
public String init(){ public CompletableFuture<String> init() {
// 不要阻塞程序启动
return CompletableFuture.supplyAsync(() -> {
try { try {
return monitorLogin(); return monitorLogin();
} catch (Exception e) { } catch (Exception e) {
log.warn("摄像头登录异常,跳过", e); log.warn("摄像头登录异常,跳过", e);
} }
return null; return null;
});
} }
public String monitorLogin() { public String monitorLogin() {
@ -181,7 +182,6 @@ public class MonitorService {
} }
} }
}, 0, duration * 1000); }, 0, duration * 1000);
} }
@ -262,6 +262,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点8:50抓图 * 特定摊点8:50抓图
*/ */
@ -304,6 +305,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点9:50抓图 * 特定摊点9:50抓图
*/ */
@ -346,6 +348,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点9:20抓图 * 特定摊点9:20抓图
*/ */
@ -388,6 +391,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点11:20抓图 * 特定摊点11:20抓图
*/ */
@ -430,6 +434,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点12:20抓图 * 特定摊点12:20抓图
*/ */
@ -472,6 +477,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/** /**
* 特定摊点19:20抓图 * 特定摊点19:20抓图
*/ */
@ -696,8 +702,7 @@ public class MonitorService {
} }
} } catch (Exception e) {
catch (Exception e){
log.info("[monitor-capture] " + cameraCode + " 人流识别失败 " + e.getMessage()); log.info("[monitor-capture] " + cameraCode + " 人流识别失败 " + e.getMessage());
} }
@ -708,6 +713,7 @@ public class MonitorService {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private BufferedImage capturecreenshot(String code) throws IOException { private BufferedImage capturecreenshot(String code) throws IOException {
String url = monitorDomain + "/videoService/realmonitor/uri?scheme=HLS&channelId=" + code; String url = monitorDomain + "/videoService/realmonitor/uri?scheme=HLS&channelId=" + code;
@ -752,6 +758,7 @@ public class MonitorService {
} }
} }
public String fileCode(String code) throws IOException { public String fileCode(String code) throws IOException {
String url = monitorDomain + "/videoService/realmonitor/uri?scheme=HLS&channelId=" + code; String url = monitorDomain + "/videoService/realmonitor/uri?scheme=HLS&channelId=" + code;
@ -1142,6 +1149,7 @@ public class MonitorService {
return maps; return maps;
} }
//环卫道路明细数据 //环卫道路明细数据
public List<Map> resCatalogApplyHJWSRoad() { public List<Map> resCatalogApplyHJWSRoad() {
String token = this.qidiToken(); String token = this.qidiToken();
@ -1173,6 +1181,7 @@ public class MonitorService {
return new ArrayList<>(); return new ArrayList<>();
} }
} }
//获取当前日期的时间串2022-05-08 00:00:00 //获取当前日期的时间串2022-05-08 00:00:00
private String dateTimeStr() { private String dateTimeStr() {
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();
@ -1181,6 +1190,7 @@ public class MonitorService {
LocalDateTime dateTime = LocalDateTime.of(yestDay.getYear(), yestDay.getMonth(), yestDay.getDayOfMonth(), 0, 0, 0); LocalDateTime dateTime = LocalDateTime.of(yestDay.getYear(), yestDay.getMonth(), yestDay.getDayOfMonth(), 0, 0, 0);
return dateTime.format(formatter); return dateTime.format(formatter);
} }
//获取当前日期的时间串2022-05-08 //获取当前日期的时间串2022-05-08
private String dateStr() { private String dateStr() {
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();