考勤机
This commit is contained in:
@ -280,6 +280,13 @@
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.15</version> <!-- 最新版本可自行调整 -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -3,10 +3,12 @@ package org.dromara.project.controller;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
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.*;
|
||||
import org.dromara.project.domain.vo.attendance.DeviceResult;
|
||||
import org.dromara.project.service.IBusAttendanceMachineService;
|
||||
import org.dromara.project.service.IBusAttendanceService;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@ -17,7 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
|
||||
|
||||
/**
|
||||
* 考勤
|
||||
@ -38,11 +40,11 @@ public class BusAttendanceDeviceController extends BaseController {
|
||||
|
||||
@PostMapping("/api/v1/record/face")
|
||||
@SaIgnore
|
||||
public R<Boolean> punchCardByFace(@RequestBody DeviceDto dto) {
|
||||
public DeviceResult punchCardByFace(@RequestBody DeviceDto dto) {
|
||||
//打印接收数据
|
||||
log.info("接收数据:{}", dto);
|
||||
if (dto.getLogs().isEmpty()) {
|
||||
return R.fail("没有数据");
|
||||
return new DeviceResult(500, "没有数据");
|
||||
}
|
||||
Log first = dto.getLogs().getFirst();
|
||||
|
||||
@ -53,7 +55,7 @@ public class BusAttendanceDeviceController extends BaseController {
|
||||
.last("limit 1")
|
||||
.one();
|
||||
if (one == null || one.getProjectId() == null) {
|
||||
return R.fail("考勤机不存在或未关联项目");
|
||||
return new DeviceResult(500, "考勤机不存在或未关联项目");
|
||||
}
|
||||
|
||||
String recogTime = first.getRecog_time();
|
||||
@ -74,14 +76,14 @@ public class BusAttendanceDeviceController extends BaseController {
|
||||
// 假设first.getImage()返回base64字符串,且你有一个文件名
|
||||
MultipartFile file = convert(first.getPhoto(), "face.jpg");
|
||||
log.info("开始打卡");
|
||||
return R.ok(busAttendanceService.punchCardByFace(file, req));
|
||||
busAttendanceService.punchCardByFace(file, req);
|
||||
return new DeviceResult(0, "打卡成功");
|
||||
} catch (IOException e) {
|
||||
return R.fail("文件转换失败");
|
||||
return new DeviceResult(500, "文件转换失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static MultipartFile convert(String base64String, String fileName) throws IOException {
|
||||
// 先进行URL解码(如果是URL编码过的数据)
|
||||
try {
|
||||
@ -96,23 +98,11 @@ public class BusAttendanceDeviceController extends BaseController {
|
||||
}
|
||||
|
||||
// 解码base64字符串
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(base64String);
|
||||
byte[] decodedBytes = Base64.decodeBase64(base64String);
|
||||
|
||||
// 创建MultipartFile对象
|
||||
return new MockMultipartFile(fileName, fileName, "image/jpeg", decodedBytes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package org.dromara.project.domain.vo.attendance;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeviceResult {
|
||||
|
||||
private Integer Result;
|
||||
|
||||
private String Msg;
|
||||
}
|
||||
Reference in New Issue
Block a user