门磁对接

master
Bbt 6 months ago
parent 1b75633bd6
commit 164ca0a22f

@ -1,2 +1,2 @@
编号 门磁设备IMEI 对应摄像头IP
1 866674056947364 192.168.0.68
1 866674056947364 192.168.0.68

@ -101,6 +101,17 @@
<artifactId>jsch</artifactId>
<version>0.1.49</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.bytedeco</groupId>-->
<!-- <artifactId>javacv-platform</artifactId>-->
<!-- <version>1.4.4</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version> <!-- 使用时请检查最新版本 -->
</dependency>
</dependencies>
<build>
@ -118,7 +129,7 @@
</configuration>
</plugin>
</plugins>
<finalName>fileHandle</finalName>
<finalName>doorMagnet</finalName>
</build>

@ -5,11 +5,26 @@ import cn.hutool.json.ObjectMapper;
import com.alibaba.fastjson.JSON;
import com.doormagnet.pojo.EventReport;
import com.doormagnet.service.DoorMagnetService;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.support.BindingAwareModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @Author
@ -32,6 +47,82 @@ public class DoorMagnetController {
}
@PostMapping("/test2")
public ResponseEntity<?> handleUpload(@RequestParam("file") MultipartFile file) throws IOException {
if (file.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
switch (getFileExtension(file.getOriginalFilename())) {
case "json":
// JSON文件处理逻辑
Map<String, Object> retJson = new HashMap<>();
// TODO: JSON文件处理逻辑
//打印文件内容不转类型
String jsonStr = new String(file.getBytes());
System.out.println(jsonStr);
return ResponseEntity.ok(retJson);
case "jpeg":
// 带框图片处理逻辑
// TODO: 带框图片处理逻辑
//存储图片
System.out.println("jpeg");
try {
String path = "F:\\home\\wt\\";
File dest = new File(path + file.getOriginalFilename());
if (!dest.exists()) {
dest.mkdirs();
}
file.transferTo(dest);
System.out.println("文件生成成功");
} catch (IOException e) {
e.printStackTrace();
}
return ResponseEntity.ok().build();
case "jpg":
// 原始图片处理逻辑
// TODO: 原始图片处理逻辑
System.out.println("jpg");
//存储图片
try {
String path = "F:\\home\\wt\\";
File dest = new File(path + file.getOriginalFilename());
if (!dest.exists()) {
dest.mkdirs();
}
file.transferTo(dest);
System.out.println("文件生成成功");
} catch (IOException e) {
e.printStackTrace();
}
return ResponseEntity.ok().build();
case "mp4":
// 带框视频处理逻辑
// TODO: 带框视频处理逻辑
System.out.println("mp4");
return ResponseEntity.ok().build();
default:
System.out.println("失败");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported file type");
}
}
private String getFileExtension(String filename) {
int lastDotIndex = filename.lastIndexOf(".");
if (lastDotIndex == -1) {
return "";
}
return filename.substring(lastDotIndex + 1);
}
@GetMapping("/test3")
public String test3() {
return null;
}
}

@ -64,9 +64,11 @@ public class FtpService {
ftpClient.enterLocalPassiveMode();
ftpClient.setControlEncoding("UTF-8");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
//切换到指定目录
ftpClient.changeWorkingDirectory(srcpath);
ftpClient.storeFile(filename, new FileInputStream(file));
//打印转发路径
System.out.println(srcpath + "/" + filename + " 传输成功!");
} finally {
if (ftpClient.isConnected()) {
ftpClient.logout();

@ -64,10 +64,10 @@ public class DoorMagnetService {
writer.print(sb.toString());
writer.flush();
writer.close();
//将生成的bcp文件上传到ftp
File file = new File(path);
//ftp转发
ftpService.downloadFile(destPath,fileName, file);
// //将生成的bcp文件上传到ftp
// File file = new File(path);
// //ftp转发
// ftpService.downloadFile(destPath,fileName, file);
} catch (Exception e) {
e.printStackTrace();
@ -79,4 +79,8 @@ public class DoorMagnetService {
}
}

@ -0,0 +1,83 @@
package com.doormagnet.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* @Author
* @Date 2024/5/14 14:29
* @Version 1.0
*/
@Slf4j
@Service
public class GddService {
//将获取到的token值写为静态变量供其他方法调用由login方法赋值
public static String Token = null;
/**
* @description
* @author
* @param[1] null
* @throws
* @time 2024/5/14 14:32
*
*
* curl -X 'POST' \
* 'http://192.168.0.81:9090/api/inflet/v1/user/login' \
* -H 'accept: application/json' \
* -H 'Content-Type: application/json' \
* -d '{
* "password": "admin",
* "username": "123456"
* }'
* tokne
*/
public String login() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://192.168.0.81:9090/api/inflet/v1/user/login");
StringEntity params = new StringEntity("{\"password\":\"123456\",\"username\":\"admin\"}", StandardCharsets.UTF_8);
params.setContentType("application/json");
httpPost.setEntity(params);
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity != null) {
String responseBody = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println(responseBody);
// 使用Jackson解析JSON
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(responseBody);
// 获取data节点
JsonNode dataNode = rootNode.get("data");
// 获取token值
String token = dataNode.get("token").asText();
// 输出token
System.out.println("Token: " + token);
//为静态变量赋值
Token = token;
return token;
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
response.close();
httpClient.close();
}
return null;
}
}

@ -22,6 +22,7 @@ public class ExcelReader {
@PostConstruct
public static void readExcel() {
// String filePath = "/home/project/doormagnet/config/config.xlsx";
String filePath = "F:\\WT\\config.xlsx";
// 读取 Excel 文件并映射到对象

Loading…
Cancel
Save