考勤接口
This commit is contained in:
@ -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编码过的数据)
|
||||
|
||||
@ -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<String, Object> healthCodeInfo;
|
||||
}
|
||||
Reference in New Issue
Block a user