From b67a7d5370c40dd959e4d740be775264bf1a8863 Mon Sep 17 00:00:00 2001 From: lcj <2331845269@qq.com> Date: Tue, 28 Oct 2025 20:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusAttendanceDeviceController.java | 49 +++++++++++- .../domain/dto/attendance/DeviceUserInfo.java | 77 +++++++++++++++++++ 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/domain/dto/attendance/DeviceUserInfo.java diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/controller/BusAttendanceDeviceController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/controller/BusAttendanceDeviceController.java index d7c45f25..640f11c5 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/controller/BusAttendanceDeviceController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/controller/BusAttendanceDeviceController.java @@ -1,10 +1,13 @@ package org.dromara.project.controller; import cn.dev33.satoken.annotation.SaIgnore; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; -import org.dromara.common.core.domain.R; import org.dromara.common.web.core.BaseController; import org.dromara.project.domain.BusAttendanceMachine; import org.dromara.project.domain.dto.attendance.*; @@ -13,10 +16,15 @@ import org.dromara.project.service.IBusAttendanceMachineService; import org.dromara.project.service.IBusAttendanceService; import org.springframework.mock.web.MockMultipartFile; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -84,6 +92,43 @@ public class BusAttendanceDeviceController extends BaseController { } } + @PostMapping("/api/v1/recordvisit") + @SaIgnore + public DeviceResult recordvisit(@RequestBody DeviceUserInfo dto) { + try { + log.info("设备上报数据:{}", dto); + // 1. 将对象转为 JSON 字符串(带格式) + String json = JSONUtil.toJsonPrettyStr(dto); + log.info("JSON数据:{}", json); + // 2. 构建保存路径(按日期区分文件) + String dateStr = DateUtil.format(DateUtil.date(), "yyyyMMdd"); + String fileName = StrUtil.format("device_record_{}.txt", dateStr); + + // 3. 路径:项目根目录 /logs/device-data/ + File dir = FileUtil.mkdir("logs/device-data"); + File file = FileUtil.file(dir, fileName); + + // 4. 生成时间戳+分隔符 + String timePrefix = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss"); + String data = StrUtil.format( + "[{}]\n{}\n{}\n", + timePrefix, + json, + StrUtil.repeat("-", 80) + ); + + // 5. 追加到文件中 + FileUtil.appendString(data, file, StandardCharsets.UTF_8); + + log.info("✅ 设备上报数据已保存: {}", file.getAbsolutePath()); + return new DeviceResult(0, "保存成功"); + + } catch (Exception e) { + log.error("❌ 保存设备数据失败", e); + return new DeviceResult(-2, "保存失败:" + e.getMessage()); + } + } + public static MultipartFile convert(String base64String, String fileName) throws IOException { // 先进行URL解码(如果是URL编码过的数据) diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/domain/dto/attendance/DeviceUserInfo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/domain/dto/attendance/DeviceUserInfo.java new file mode 100644 index 00000000..ca4940f3 --- /dev/null +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/domain/dto/attendance/DeviceUserInfo.java @@ -0,0 +1,77 @@ +package org.dromara.project.domain.dto.attendance; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Map; + +@Data +public class DeviceUserInfo { + + /** + * 设备序列号 + */ + @JsonProperty("dev_sn") + private String devSn; + + /** + * 用户编号 + */ + @JsonProperty("user_number") + private String userNumber; + + /** + * 用户姓名 + */ + @JsonProperty("user_name") + private String userName; + + @JsonProperty("user_photo") + private String userPhoto; + + @JsonProperty("photo") + private String photo; + + @JsonProperty("recog_time") + private Long recogTime; + + @JsonProperty("user_birthday") + private Long userBirthday; + + @JsonProperty("user_gender") + private String userGender; + + @JsonProperty("user_ethnic") + private String userEthnic; + + @JsonProperty("user_address") + private String userAddress; + + @JsonProperty("user_issue") + private String userIssue; + + @JsonProperty("user_valid_start") + private Long userValidStart; + + @JsonProperty("user_valid_end") + private Long userValidEnd; + + @JsonProperty("confidence") + private String confidence; + + @JsonProperty("body_temperature") + private BigDecimal bodyTemperature; + + @JsonProperty("reflectivity") + private Integer reflectivity; + + @JsonProperty("room_temperature") + private BigDecimal roomTemperature; + + @JsonProperty("health_code_color") + private String healthCodeColor; + + @JsonProperty("health_code_info") + private Map healthCodeInfo; +}