feat(study): 添加学生签到执行器日志记录功能

dev
zhaokai 2026-03-07 10:13:37 +08:00
parent 42740c78ae
commit a9a61e3e62
1 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.zcloud.edu.command.study; package com.zcloud.edu.command.study;
import cn.hutool.json.JSONUtil;
import com.alibaba.cola.exception.BizException; import com.alibaba.cola.exception.BizException;
import com.zcloud.edu.config.FileUrlConfig; import com.zcloud.edu.config.FileUrlConfig;
import com.zcloud.edu.domain.gateway.study.StudentSignGateway; import com.zcloud.edu.domain.gateway.study.StudentSignGateway;
@ -12,6 +13,7 @@ import com.zcloud.gbscommon.utils.Base64Util;
import com.zcloud.gbscommon.utils.Tools; import com.zcloud.gbscommon.utils.Tools;
import com.zcloud.gbscommon.zcloudimgfiles.facade.ZcloudImgFilesFacade; import com.zcloud.gbscommon.zcloudimgfiles.facade.ZcloudImgFilesFacade;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -30,6 +32,7 @@ import java.io.IOException;
*/ */
@Component @Component
@AllArgsConstructor @AllArgsConstructor
@Slf4j
public class StudentSignAddExe { public class StudentSignAddExe {
private final StudentSignGateway studentSignGateway; private final StudentSignGateway studentSignGateway;
private final StudentRepository studentRepository; private final StudentRepository studentRepository;
@ -40,41 +43,38 @@ public class StudentSignAddExe {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public StudentSignCO execute(StudentSignAddCmd cmd) { public StudentSignCO execute(StudentSignAddCmd cmd) {
System.out.println("第一步-----------------------------"+ System.currentTimeMillis()); log.info("StudentSignAddExe-execute,开始进行人脸识别接口,开始,请求参数{}",JSONUtil.toJsonStr( cmd));
long startTime = System.currentTimeMillis();
StudentDO stu = studentRepository.findInfoByStudentId(cmd.getStudentId()); StudentDO stu = studentRepository.findInfoByStudentId(cmd.getStudentId());
System.out.println("第2步-----------------------------"+ System.currentTimeMillis());
StudentSignE studentSignE = new StudentSignE(); StudentSignE studentSignE = new StudentSignE();
BeanUtils.copyProperties(cmd, studentSignE); BeanUtils.copyProperties(cmd, studentSignE);
System.out.println("第3步-----------------------------"+ System.currentTimeMillis());
StudentDO student = studentRepository.findFaceUrlByPhone(stu.getPhone()); StudentDO student = studentRepository.findFaceUrlByPhone(stu.getPhone());
System.out.println("第4步-----------------------------"+ System.currentTimeMillis());
if (student == null || ObjectUtils.isEmpty(student.getUserAvatarUrl())) { if (student == null || ObjectUtils.isEmpty(student.getUserAvatarUrl())) {
throw new BizException("您还没有录入人脸"); throw new BizException("您还没有录入人脸");
} }
String faceUrl = null; String faceUrl = null;
try { try {
System.out.println("第5步-----------------------------"+ System.currentTimeMillis());
faceUrl = Base64Util.getBase64String(studentSignE.getFiles()[0]); faceUrl = Base64Util.getBase64String(studentSignE.getFiles()[0]);
System.out.println("第6步-----------------------------"+ System.currentTimeMillis()); log.info("StudentSignAddExe-execute,调用阿里进行人脸识别开始");
long startAliTime = System.currentTimeMillis();
studentSignE.compareFace(student.getUserAvatarUrl(), faceUrl, fileUrlConfig.getPrefixUrl()); studentSignE.compareFace(student.getUserAvatarUrl(), faceUrl, fileUrlConfig.getPrefixUrl());
System.out.println("第10步-----------------------------"+ System.currentTimeMillis()); log.info("StudentSignAddExe-execute,调用阿里进行人脸识别结束,耗时:{}",System.currentTimeMillis() - startAliTime);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
String path = studentSignE.getType() == 1 ? "clockSign" : "examSign"; String path = studentSignE.getType() == 1 ? "clockSign" : "examSign";
System.out.println("第11步-----------------------------"+ System.currentTimeMillis());
String fileName = Tools.get32UUID() + studentSignE.getFiles()[0].getOriginalFilename().substring(studentSignE.getFiles()[0].getOriginalFilename().lastIndexOf(".")); String fileName = Tools.get32UUID() + studentSignE.getFiles()[0].getOriginalFilename().substring(studentSignE.getFiles()[0].getOriginalFilename().lastIndexOf("."));
System.out.println("第12步-----------------------------"+ System.currentTimeMillis()); log.info("StudentSignAddExe-execute,保存人脸图片开始");
long l = System.currentTimeMillis();
studentSignE.setFaceUrl(zcloudImgFilesFacade.saveFile( faceUrl,fileName, path)); studentSignE.setFaceUrl(zcloudImgFilesFacade.saveFile( faceUrl,fileName, path));
System.out.println("第13步-----------------------------"+ System.currentTimeMillis()); log.info("StudentSignAddExe-execute,保存人脸图片结束,耗时:{}",System.currentTimeMillis() - l);
studentSignE.init(stu.getStudentId(), stu.getClassId(), stu.getClassCorpinfoId()); studentSignE.init(stu.getStudentId(), stu.getClassId(), stu.getClassCorpinfoId());
boolean res = false; boolean res = false;
StudentSignCO studentSignCO = new StudentSignCO(); StudentSignCO studentSignCO = new StudentSignCO();
try { try {
System.out.println("第14步-----------------------------"+ System.currentTimeMillis());
res = studentSignGateway.add(studentSignE); res = studentSignGateway.add(studentSignE);
System.out.println("第15步-----------------------------"+ System.currentTimeMillis());
BeanUtils.copyProperties(studentSignE, studentSignCO); BeanUtils.copyProperties(studentSignE, studentSignCO);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -82,6 +82,9 @@ public class StudentSignAddExe {
if (!res) { if (!res) {
throw new BizException("保存失败"); throw new BizException("保存失败");
} }
long totalTime = System.currentTimeMillis() - startTime;
log.info("StudentSignAddExe-execute,开始进行人脸识别接口,结束,耗时:{}",totalTime);
return studentSignCO; return studentSignCO;
} }
} }