Browse Source

新增人脸识别接口,打卡时间接口

master
HY 4 months ago
parent
commit
bbe1c38ade
5 changed files with 123 additions and 15 deletions
  1. +15
    -3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/controller/ClockinController.java
  2. +20
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/req/ClockInTimeReq.java
  3. +19
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/req/VerifyFaceReq.java
  4. +18
    -3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/service/IClockinService.java
  5. +51
    -9
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/service/impl/ClockinServiceImpl.java

+ 15
- 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/controller/ClockinController.java View File

@ -5,9 +5,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.xcx.clockin.req.ClockInLogReq;
import org.jeecg.modules.xcx.clockin.req.ClockInReq;
import org.jeecg.modules.xcx.clockin.req.ClockInTotalReq;
import org.jeecg.modules.xcx.clockin.req.*;
import org.jeecg.modules.xcx.clockin.service.IClockinService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -47,4 +45,18 @@ public class ClockinController {
return clockinService.clockInTotal(clockInTotalReq);
}
@ApiOperation(value = "人脸识别")
@PostMapping("/verify/face")
public Result<?> verifyFace(HttpServletRequest request , VerifyFaceReq verifyFaceReq){
verifyFaceReq.setToken(TokenUtils.getTokenByRequest(request));
return clockinService.verifyFace(verifyFaceReq);
}
@ApiOperation("是否在打卡时间段")
@PostMapping("/time")
public Result<?> clockInTime(HttpServletRequest request, ClockInTimeReq clockInTimeReq){
clockInTimeReq.setToken(TokenUtils.getTokenByRequest(request));
return clockinService.clockInTime(clockInTimeReq);
}
}

+ 20
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/req/ClockInTimeReq.java View File

@ -0,0 +1,20 @@
package org.jeecg.modules.xcx.clockin.req;
import lombok.Data;
/**
* @author java996.icu
* @title: ClockInTimeReq
* @projectName clockin-api
* @description: TODO
* @date 2024/11/28 15:42
* @Version V1.0
*/
@Data
public class ClockInTimeReq {
private String token;
private String lon;
private String lat;
}

+ 19
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/req/VerifyFaceReq.java View File

@ -0,0 +1,19 @@
package org.jeecg.modules.xcx.clockin.req;
import lombok.Data;
/**
* @author java996.icu
* @title: VerifyFaceReq
* @projectName clockin-api
* @description: TODO
* @date 2024/11/28 14:32
* @Version V1.0
*/
@Data
public class VerifyFaceReq {
private String token;
private String image;
}

+ 18
- 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/service/IClockinService.java View File

@ -1,12 +1,13 @@
package org.jeecg.modules.xcx.clockin.service;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xcx.clockin.req.ClockInLogReq;
import org.jeecg.modules.xcx.clockin.req.ClockInReq;
import org.jeecg.modules.xcx.clockin.req.ClockInTotalReq;
import org.jeecg.modules.xcx.clockin.req.*;
public interface IClockinService {
/**
* 打卡
* @param clockInReq
@ -28,4 +29,18 @@ public interface IClockinService {
*/
Result<?> clockInTotal(ClockInTotalReq clockInTotalReq);
/**
* 人脸识别
* @param verifyFaceReq
* @return
*/
Result<?> verifyFace(VerifyFaceReq verifyFaceReq);
/**
* 是否在打卡时间段
* @param token
* @return
*/
Result<?> clockInTime(ClockInTimeReq clockInTimeReq);
}

+ 51
- 9
jeecg-boot-module-system/src/main/java/org/jeecg/modules/xcx/clockin/service/impl/ClockinServiceImpl.java View File

@ -21,9 +21,7 @@ import org.jeecg.modules.clockinteam.service.IClockinTeamService;
import org.jeecg.modules.clockinteamlog.entity.ClockinTeamLog;
import org.jeecg.modules.clockinteamlog.service.IClockinTeamLogService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.xcx.clockin.req.ClockInLogReq;
import org.jeecg.modules.xcx.clockin.req.ClockInReq;
import org.jeecg.modules.xcx.clockin.req.ClockInTotalReq;
import org.jeecg.modules.xcx.clockin.req.*;
import org.jeecg.modules.xcx.clockin.resp.ClockInTotalResp;
import org.jeecg.modules.xcx.clockin.service.IClockinService;
import org.springframework.stereotype.Service;
@ -73,9 +71,9 @@ public class ClockinServiceImpl implements IClockinService {
if(clockInProject == null){
throw new JeecgBootException("当前团队未配置项目,无需打卡");
}
Integer distance = clockInProjectService.getDistance(clockInReq.getLon(), clockInProject.getLat(), clockInProject.getId());
Integer distance = clockInProjectService.getDistance(clockInReq.getLon(), clockInReq.getLat(), clockInProject.getId());
if(distance > clockInProject.getDistance()){
log.info("用户经度:"+clockInReq.getLon()+"纬度:"+clockInProject.getLat());
log.info("用户经度:"+clockInReq.getLon()+"纬度:"+clockInReq.getLat());
log.info("距离:"+distance);
throw new JeecgBootException("不在有效打卡距离内");
}
@ -84,10 +82,7 @@ public class ClockinServiceImpl implements IClockinService {
throw new JeecgBootException("当前未到打卡时间");
}
VerifyFaceResponse verifyFaceResponse = TencentUtils.VerifyFace(hanHaiMember.getId(), clockInReq.getImage(),Long.parseLong(clockInConfService.getConf("qualityControl")));
if(!verifyFaceResponse.getIsMatch()){
throw new JeecgBootException("人脸识别错误");
}
ClockinLog clockinLog1 = clockinLogService.lambdaQuery()
.eq(ClockinLog::getDelFlag, 0)
@ -210,4 +205,51 @@ public class ClockinServiceImpl implements IClockinService {
map.put("abnormal",abnormal);
return Result.OK(map);
}
@Override
public Result<?> verifyFace(VerifyFaceReq verifyFaceReq) {
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(verifyFaceReq.getToken());
VerifyFaceResponse verifyFaceResponse = TencentUtils.VerifyFace(hanHaiMember.getId(), verifyFaceReq.getImage(),Long.parseLong(clockInConfService.getConf("qualityControl")));
if(!verifyFaceResponse.getIsMatch()){
throw new JeecgBootException("人脸识别错误");
}
return Result.OK();
}
@Override
public Result<?> clockInTime(ClockInTimeReq clockInTimeReq) {
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(clockInTimeReq.getToken());
ClockinTeamLog clockinTeamLog = clockinTeamLogService.lambdaQuery()
.eq(ClockinTeamLog::getDelFlag, 0)
.eq(ClockinTeamLog::getUserId, hanHaiMember.getId())
.one();
if(clockinTeamLog == null){
throw new JeecgBootException("未绑定团队,请先绑定团队");
}
ClockInProject clockInProject = clockInProjectService.lambdaQuery()
.eq(ClockInProject::getDelFlag, 0)
.eq(ClockInProject::getTeamId, clockinTeamLog.getTeamId())
.one();
if(clockInProject == null){
throw new JeecgBootException("当前团队未配置项目");
}
ClockInProjectItem validClockInTime = clockInProjectItemService.getValidClockInTime(DateUtils2.getNowDateTimeStrings(), clockInProject.getId());
if(validClockInTime == null){
throw new JeecgBootException("当前未到打卡时间");
}
Integer distance = clockInProjectService.getDistance(clockInTimeReq.getLon(), clockInTimeReq.getLat(), clockInProject.getId());
log.info("用户经度:"+clockInTimeReq.getLon()+"纬度:"+clockInTimeReq.getLat());
log.info("距离:"+distance);
if(distance > clockInProject.getDistance()){
throw new JeecgBootException("不在有效打卡距离内");
}
return Result.OK();
}
}

Loading…
Cancel
Save