|
@@ -1,6 +1,10 @@
|
|
|
package org.dromara.server.hik.controller;
|
|
package org.dromara.server.hik.controller;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.common.core.domain.R;
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.server.hik.domain.dto.DeviceDto;
|
|
import org.dromara.server.hik.domain.dto.DeviceDto;
|
|
@@ -9,6 +13,11 @@ import org.dromara.server.hik.domain.dto.UploadEmpDto;
|
|
|
import org.dromara.server.hik.service.ISendDeviceService;
|
|
import org.dromara.server.hik.service.ISendDeviceService;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 海康消费机
|
|
* 海康消费机
|
|
@@ -213,4 +222,63 @@ public class TestController {
|
|
|
return sendDeviceService.deleteAllCardByUserNo(device,userNo);
|
|
return sendDeviceService.deleteAllCardByUserNo(device,userNo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @PostMapping(("/info"))
|
|
|
|
|
+ public void receiveDevicePushData(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 判断请求类型
|
|
|
|
|
+ if (isMultipartRequest(request)) {
|
|
|
|
|
+ // 转换为 Multipart 请求对象
|
|
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
|
+
|
|
|
|
|
+ multipartRequest.getParameterMap().forEach((fieldName, values) -> {
|
|
|
|
|
+ System.out.println("字段 [" + fieldName + "] 值: " + String.join(", ", values));
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ multipartRequest.getFileMap().forEach((fieldName, file) -> {
|
|
|
|
|
+ if (!file.isEmpty()) {
|
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
|
+ try {
|
|
|
|
|
+ file.transferTo(Path.of("f:/uploads", fileName));
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException("文件保存失败: " + fileName, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 处理 JSON 请求
|
|
|
|
|
+ handleJsonRequest(request);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ response.getWriter().write("success");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ response.getWriter().write("false");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否是 multipart 请求
|
|
|
|
|
+ private boolean isMultipartRequest(HttpServletRequest request) {
|
|
|
|
|
+ return request.getContentType() != null
|
|
|
|
|
+ && request.getContentType().startsWith("multipart/form-data");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理 JSON 请求
|
|
|
|
|
+ private void handleJsonRequest(HttpServletRequest request) throws IOException {
|
|
|
|
|
+ if (request.getContentType() != null
|
|
|
|
|
+ && request.getContentType().contains("application/json")) {
|
|
|
|
|
+
|
|
|
|
|
+ try (BufferedReader reader = request.getReader()) {
|
|
|
|
|
+ StringBuilder requestData = new StringBuilder();
|
|
|
|
|
+ String line;
|
|
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
|
|
+ requestData.append(line);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 使用任意 JSON 库解析
|
|
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(requestData.toString());
|
|
|
|
|
+ System.out.println("收到 JSON 数据:");
|
|
|
|
|
+ System.out.println(jsonObject.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|