diff --git a/config/config.xlsx b/config/config.xlsx index 99ab82e..b0e5735 100644 --- a/config/config.xlsx +++ b/config/config.xlsx @@ -1,2 +1,2 @@ 编号 门磁设备IMEI 对应摄像头IP -1 866674056947364 192.168.0.68 +1 866674056947364 192.168.0.68 diff --git a/pom.xml b/pom.xml index f8b723f..d359853 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,17 @@ jsch 0.1.49 + + + + + + + org.apache.httpcomponents + httpclient + 4.5.13 + + @@ -118,7 +129,7 @@ - fileHandle + doorMagnet diff --git a/src/main/java/com/doormagnet/controller/DoorMagnetController.java b/src/main/java/com/doormagnet/controller/DoorMagnetController.java index 2c06955..f7d332e 100644 --- a/src/main/java/com/doormagnet/controller/DoorMagnetController.java +++ b/src/main/java/com/doormagnet/controller/DoorMagnetController.java @@ -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 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; + } + + } diff --git a/src/main/java/com/doormagnet/ftp/service/FtpService.java b/src/main/java/com/doormagnet/ftp/service/FtpService.java index 339e487..66c685a 100644 --- a/src/main/java/com/doormagnet/ftp/service/FtpService.java +++ b/src/main/java/com/doormagnet/ftp/service/FtpService.java @@ -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(); diff --git a/src/main/java/com/doormagnet/service/DoorMagnetService.java b/src/main/java/com/doormagnet/service/DoorMagnetService.java index 6953f17..846ddf6 100644 --- a/src/main/java/com/doormagnet/service/DoorMagnetService.java +++ b/src/main/java/com/doormagnet/service/DoorMagnetService.java @@ -64,10 +64,10 @@ public class DoorMagnetService { writer.print(sb.toString()); writer.flush(); writer.close(); - //灏嗙敓鎴愮殑bcp鏂囦欢涓婁紶鍒癴tp - File file = new File(path); - //ftp杞彂 - ftpService.downloadFile(destPath,fileName, file); +// //灏嗙敓鎴愮殑bcp鏂囦欢涓婁紶鍒癴tp +// File file = new File(path); +// //ftp杞彂 +// ftpService.downloadFile(destPath,fileName, file); } catch (Exception e) { e.printStackTrace(); @@ -79,4 +79,8 @@ public class DoorMagnetService { } + + + + } diff --git a/src/main/java/com/doormagnet/service/GddService.java b/src/main/java/com/doormagnet/service/GddService.java new file mode 100644 index 0000000..94cda46 --- /dev/null +++ b/src/main/java/com/doormagnet/service/GddService.java @@ -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 { + //灏嗚幏鍙栧埌鐨則oken鍊煎啓涓洪潤鎬佸彉閲忥紝渚涘叾浠栨柟娉曡皟鐢紝鐢眑ogin鏂规硶璧嬪 + 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" + * }' + * 鑾峰彇鐧诲綍鐨則okne + */ + 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瑙f瀽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; + } + + + +} diff --git a/src/main/java/com/doormagnet/task/ExcelReader.java b/src/main/java/com/doormagnet/task/ExcelReader.java index e8e13a0..4a15238 100644 --- a/src/main/java/com/doormagnet/task/ExcelReader.java +++ b/src/main/java/com/doormagnet/task/ExcelReader.java @@ -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 鏂囦欢骞舵槧灏勫埌瀵硅薄