相机配置,增加easeai测试增加sse连接
parent
6e12cb63e2
commit
a4d385c98b
@ -0,0 +1,38 @@
|
||||
package com.zhehekeji.web.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.easyai.yolo.FastYolo;
|
||||
import org.dromara.easyai.yolo.YoloConfig;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties
|
||||
@Data
|
||||
public class EaseAiConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public YoloConfig yoloConfig(){
|
||||
YoloConfig yoloConfig = new YoloConfig();//创建配置参数类
|
||||
yoloConfig.setWindowHeight(300);
|
||||
yoloConfig.setWindowWidth(600);
|
||||
yoloConfig.setTypeNub(5);
|
||||
yoloConfig.setEnhance(40);
|
||||
yoloConfig.setContainIouTh(0.1);
|
||||
yoloConfig.setPth(0.7);
|
||||
return yoloConfig;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FastYolo fastYolo(YoloConfig yoloConfig){
|
||||
try {
|
||||
return new FastYolo(yoloConfig);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,128 @@
|
||||
package com.zhehekeji.web.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhehekeji.core.pojo.Result;
|
||||
import com.zhehekeji.web.entity.*;
|
||||
import com.zhehekeji.web.mapper.CameraIOMapper;
|
||||
import com.zhehekeji.web.pojo.camera.CameraConfigSearchReq;
|
||||
import com.zhehekeji.web.service.CameraService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Api(value = "cameraIo",tags = "球机预置点")
|
||||
@RestController
|
||||
@RequestMapping("/cameraIo")
|
||||
@Slf4j
|
||||
public class CameraIoController {
|
||||
@Resource
|
||||
private CameraIOMapper cameraIOMapper;
|
||||
|
||||
@Resource
|
||||
private CameraService cameraService;
|
||||
@PostMapping("/config")
|
||||
@ApiOperation(value = "球机IO配置新增 ")
|
||||
public Result addConfig (@RequestBody CameraIO config) {
|
||||
|
||||
cameraService.ptz(null, config.getCameraId(), config.getName(),0,config.getCode());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/realTimeCamera")
|
||||
@ApiOperation(value = "球机IO配置分页列表")
|
||||
public Result<List<Camera>> configPage () {
|
||||
List<Camera> cameras = cameraService.allCameras();
|
||||
List<CameraIO> cameraIOs = cameraIOMapper.selectList(new QueryWrapper<CameraIO>());
|
||||
Map<Integer, List<CameraIO>> map = cameraIOs.stream().collect(Collectors.groupingBy(CameraIO::getCameraId));
|
||||
for (Camera camera : cameras) {
|
||||
camera.setStatus(cameraService.getPtzIdByCodeAndCameraId(camera.getRtsp(),camera.getId())!=null?"在线":"离线");
|
||||
camera.setCameraIOs(map.get(camera.getId()));
|
||||
}
|
||||
|
||||
return Result.success(cameras);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/config/page")
|
||||
@ApiOperation(value = "球机IO配置分页列表")
|
||||
public Result<List<CameraIO>> configPage (@RequestBody CameraIO cameraIO) {
|
||||
return Result.success(cameraIOMapper.selectList(new QueryWrapper<CameraIO>().eq(cameraIO.getCameraId()!=null,"camera_id",cameraIO.getCameraId())));
|
||||
}
|
||||
|
||||
@PutMapping("/config")
|
||||
@ApiOperation(value = "球机IO配置修改 ")
|
||||
public Result editConfig (@RequestBody CameraIO config) {
|
||||
cameraIOMapper.updateById(config);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/getDeviceTree")
|
||||
@ApiOperation(value = "获取设备树")
|
||||
public Result<List<DeviceResp>> getDeviceTree () {
|
||||
List<DeviceResp> deviceResps = cameraService.getDeviceTree();
|
||||
return Result.success(deviceResps);
|
||||
}
|
||||
|
||||
@DeleteMapping("/config")
|
||||
@ApiOperation(value = "球机IO配置删除 ")
|
||||
public Result delConfig (@RequestBody CameraIO config) {
|
||||
cameraIOMapper.deleteById(config.getId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Path sourceDirectory = Paths.get("E:\\玉溪\\mysql");
|
||||
Path targetFile = Paths.get("E:\\玉溪\\mysql1.txt");
|
||||
|
||||
try {
|
||||
mergeFiles(sourceDirectory, targetFile);
|
||||
System.out.println("文件合并完成!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void mergeFiles(Path sourceDirectory, Path targetFile) throws IOException {
|
||||
List<Path> files = new ArrayList<>();
|
||||
Files.walkFileTree(sourceDirectory, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (Files.isRegularFile(file)) {
|
||||
files.add(file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(targetFile)) {
|
||||
for (Path file : files) {
|
||||
//writer.write("开始文件: " + file.getFileName() + "\n");
|
||||
Files.lines(file).forEach(line -> {
|
||||
try {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
// writer.write("结束文件: " + file.getFileName() + "\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.zhehekeji.web.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zhehekeji.core.pojo.Result;
|
||||
import com.zhehekeji.core.util.Assert;
|
||||
import com.zhehekeji.web.entity.Camera;
|
||||
import com.zhehekeji.web.entity.CameraIO;
|
||||
import com.zhehekeji.web.entity.SseMsgEntity;
|
||||
import com.zhehekeji.web.entity.Street;
|
||||
import com.zhehekeji.web.lib.CameraControlModule;
|
||||
import com.zhehekeji.web.mapper.CameraIOMapper;
|
||||
import com.zhehekeji.web.service.CameraService;
|
||||
import com.zhehekeji.web.service.StreetConn;
|
||||
import com.zhehekeji.web.util.SseClient;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Api(value = "sseConfig",tags = "sse设置")
|
||||
@RestController
|
||||
@RequestMapping("/sse")
|
||||
@Slf4j
|
||||
public class SseClientController {
|
||||
@Resource
|
||||
private SseClient sseClient;
|
||||
@Resource
|
||||
private CameraIOMapper cameraIOMapper;
|
||||
@Resource
|
||||
private CameraService cameraService;
|
||||
|
||||
@Resource
|
||||
private CameraControlModule cameraControlModule;
|
||||
@GetMapping("/index")
|
||||
@ResponseBody
|
||||
public Result<String> index() {
|
||||
String uid = UUID.randomUUID().toString();
|
||||
|
||||
return Result.success(uid);
|
||||
}
|
||||
|
||||
@GetMapping("/cameraIo/{type}")
|
||||
@ApiOperation(value = "门禁警告上传")
|
||||
public Result cameraIoType(@PathVariable String type){
|
||||
List<CameraIO> cameraIOs = cameraIOMapper.selectList(new QueryWrapper<CameraIO>().eq("code",type));
|
||||
for (CameraIO cameraIO: cameraIOs){
|
||||
try {
|
||||
|
||||
cameraControlModule.toPtz(cameraIO.getPtzId(),cameraIO.getCameraId());
|
||||
}catch (Exception e){
|
||||
log.error("ptz失败",e);
|
||||
}
|
||||
Camera camera = cameraService.detail(cameraIO.getCameraId());
|
||||
camera.setCameraIOs(new ArrayList<>());
|
||||
camera.getCameraIOs().add(cameraIO);
|
||||
SseMsgEntity sseMsgEntity = new SseMsgEntity();
|
||||
sseMsgEntity.setCameraId(camera.getId());
|
||||
sseMsgEntity.setDevice(camera.getType());
|
||||
sseMsgEntity.setCode(type);
|
||||
sseMsgEntity.setCameraIO(cameraIO);
|
||||
sseMsgEntity.setCamera(camera);
|
||||
sseClient.sendAll(JSON.toJSONString(sseMsgEntity));
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
@CrossOrigin
|
||||
@GetMapping("/createSse/{uid}")
|
||||
public SseEmitter createConnect(@PathVariable String uid) {
|
||||
return sseClient.createSse(uid);
|
||||
}
|
||||
@CrossOrigin
|
||||
@GetMapping("/sendMsg")
|
||||
@ResponseBody
|
||||
public String sseChat(@RequestBody SseMsgEntity sseMsgEntity) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sseClient.sendMessage(sseMsgEntity.getUid(), "no"+i,sseMsgEntity.getMessage());
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭连接
|
||||
*/
|
||||
@CrossOrigin
|
||||
@PostMapping("/closeSse")
|
||||
public Result closeConnect(@RequestBody SseMsgEntity sseMsgEntity ){
|
||||
|
||||
sseClient.closeSse(sseMsgEntity.getUid());
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.zhehekeji.web.easeAi;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Image {
|
||||
private String url;
|
||||
private int x;
|
||||
private int y;
|
||||
private int width;
|
||||
private int height;
|
||||
private String text;
|
||||
private String type;
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package com.zhehekeji.web.easeAi;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.dromara.easyai.entity.ThreeChannelMatrix;
|
||||
import org.dromara.easyai.yolo.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestPic {
|
||||
@Resource
|
||||
private YoloConfig yoloConfig;
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
static public void writeModel(String json, String path) {
|
||||
// 目标文件夹路径
|
||||
Path folderPath = Paths.get(path);
|
||||
|
||||
try {
|
||||
// 创建文件夹及所有上级文件夹
|
||||
Files.createDirectories(folderPath.getParent());
|
||||
System.out.println("文件夹已创建:" + folderPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("创建文件夹失败!");
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(path))) {
|
||||
// 写入字符到文件
|
||||
writer.write(json);
|
||||
writer.newLine(); // 写入换行符
|
||||
System.out.println("内容已成功写入文件。");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static YoloModel readModelParameter(String s) {
|
||||
YoloModel yoloModel = null;
|
||||
try (FileReader reader = new FileReader(s)) {
|
||||
// 读取JSON文件内容
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int i;
|
||||
while ((i = reader.read()) != -1) {
|
||||
stringBuilder.append((char) i);
|
||||
}
|
||||
String jsonString = stringBuilder.toString();
|
||||
|
||||
// 将 JSON 字符串转换为 Person 对象
|
||||
yoloModel = JSON.parseObject(jsonString, YoloModel.class);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return yoloModel;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.zhehekeji.web.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DeviceResp {
|
||||
private String title;
|
||||
private String key;
|
||||
private List<DeviceResp> children;
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Camera camera;
|
||||
private CameraIO cameraIO;
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.zhehekeji.web.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SseMsgEntity {
|
||||
private String messageId;
|
||||
private String message;
|
||||
private String uid;
|
||||
private String device;
|
||||
private Integer cameraId;
|
||||
private CameraIO cameraIO;
|
||||
private Camera camera;
|
||||
private String code;
|
||||
}
|
||||
Loading…
Reference in New Issue