|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|