|
@@ -8,19 +8,26 @@ import com.qmth.sop.business.bean.dto.SopCrmInfo;
|
|
|
import com.qmth.sop.business.bean.params.DingSaveParam;
|
|
|
import com.qmth.sop.business.bean.result.*;
|
|
|
import com.qmth.sop.business.entity.TBDing;
|
|
|
+import com.qmth.sop.business.entity.TBDingHistory;
|
|
|
import com.qmth.sop.business.entity.TBUserArchives;
|
|
|
import com.qmth.sop.business.entity.TFFlowApprove;
|
|
|
import com.qmth.sop.business.mapper.TBDingMapper;
|
|
|
import com.qmth.sop.business.service.*;
|
|
|
+import com.qmth.sop.business.sync.FaceApiUtils;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.*;
|
|
|
import com.qmth.sop.common.util.DateDisposeUtils;
|
|
|
+import com.qmth.sop.common.util.FileStoreUtil;
|
|
|
+import com.qmth.sop.common.util.FileUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -49,9 +56,18 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
|
|
|
private SysDingDateService sysDingDateService;
|
|
|
@Resource
|
|
|
private TBSopInfoService tbSopInfoService;
|
|
|
+ @Resource
|
|
|
+ private FileStoreUtil fileStoreUtil;
|
|
|
+ @Resource
|
|
|
+ private FaceApiUtils faceApiUtils;
|
|
|
+ @Resource
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+ @Resource
|
|
|
+ private TBDingHistoryService tbDingHistoryService;
|
|
|
|
|
|
@Override
|
|
|
public DingElementResult findDingElements(String sopNo, Long userId) {
|
|
|
+
|
|
|
SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
|
|
|
Long serviceUnitId = sopCrmInfo.getServiceUnitId();
|
|
|
|
|
@@ -213,21 +229,52 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void dingSave(DingSaveParam dingSaveParam, Long userId) {
|
|
|
+ public void dingSave(DingSaveParam dingSaveParam, Long userId) throws IOException {
|
|
|
String sopNo = dingSaveParam.getSopNo();
|
|
|
+ SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
|
|
|
+ Long serviceUnitId = sopCrmInfo.getServiceUnitId();
|
|
|
+ DingElementResult dingElementResult = this.baseMapper.findDingResultByUserId(userId, serviceUnitId);
|
|
|
+
|
|
|
Long signTime = dingSaveParam.getSignTime();
|
|
|
DingDateTypeEnum dateType = sysDingDateService.getDingDateType(DateDisposeUtils.timestampToLocalDate(signTime));
|
|
|
|
|
|
InOutTypeEnum signType = dingSaveParam.getSignType();
|
|
|
String signAddress = dingSaveParam.getSignAddress();
|
|
|
- Boolean facePass = dingSaveParam.getFacePass();
|
|
|
+ String facePhotoPath = dingSaveParam.getFacePhotoPath();
|
|
|
String axisX = dingSaveParam.getAxisX();
|
|
|
String axisY = dingSaveParam.getAxisY();
|
|
|
|
|
|
TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
|
|
|
Long userArchivesId = tbUserArchives.getId();
|
|
|
+ // 人脸识别
|
|
|
+ Boolean faceOpen = dingElementResult.getFaceOpen();
|
|
|
+ BigDecimal score = null;
|
|
|
+ Boolean facePass = null;
|
|
|
+ if (faceOpen) {
|
|
|
+ // 开启人脸识别
|
|
|
+ if (facePhotoPath == null || facePhotoPath.length() == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("缺少人脸识别照片");
|
|
|
+ }
|
|
|
+ String basePhotoPath = tbUserArchives.getBasePhotoPath();
|
|
|
+ String basePhotoSuffix = basePhotoPath.substring(basePhotoPath.lastIndexOf(".")).toLowerCase();
|
|
|
+ File basePhotoTemp = SystemConstant.getFileTempVar(basePhotoSuffix);
|
|
|
+ String facePhotoSuffix = facePhotoPath.substring(facePhotoPath.lastIndexOf(".")).toLowerCase();
|
|
|
+ File facePhotoTemp = SystemConstant.getFileTempVar(facePhotoSuffix);
|
|
|
+ try {
|
|
|
+ basePhotoTemp = fileStoreUtil.ossDownload(basePhotoPath, basePhotoTemp, UploadFileEnum.FILE.getFssType());
|
|
|
+ facePhotoTemp = fileStoreUtil.ossDownload(facePhotoPath, facePhotoTemp, UploadFileEnum.FILE.getFssType());
|
|
|
+ score = faceApiUtils.faceMatch(basePhotoTemp, facePhotoTemp);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ FileUtil.deleteFile(basePhotoTemp);
|
|
|
+ FileUtil.deleteFile(facePhotoTemp);
|
|
|
+ }
|
|
|
+ String limitStr = sysConfigService.findByConfigKey(SystemConstant.BAIDU_FACE_COMPARE_SCORE).getConfigValue();
|
|
|
+ BigDecimal limit = new BigDecimal(limitStr);
|
|
|
+ facePass = score.compareTo(limit) > -1;
|
|
|
+ }
|
|
|
|
|
|
- SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
|
|
|
String crmNo = sopCrmInfo.getCrmNo();
|
|
|
Long serviceId = sopCrmInfo.getServiceUnitId();
|
|
|
Long flowId = sopCrmInfo.getFlowId();
|
|
@@ -295,26 +342,41 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
|
|
|
|
|
|
switch (signType) {
|
|
|
case IN: // 签到打卡
|
|
|
- recordList = recordList.stream().peek(e -> {
|
|
|
+ for (TBDing e : recordList) {
|
|
|
e.setSignInTime(signTime);
|
|
|
e.setSignInAddress(signAddress);
|
|
|
e.setAxisInX(axisX);
|
|
|
e.setAxisInY(axisY);
|
|
|
e.setFaceInPass(facePass);
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
break;
|
|
|
case OUT: // 签退打卡
|
|
|
- recordList = recordList.stream().peek(e -> {
|
|
|
+ for (TBDing e : recordList) {
|
|
|
e.setSignOutTime(signTime);
|
|
|
e.setSignOutAddress(signAddress);
|
|
|
e.setAxisOutX(axisX);
|
|
|
e.setAxisOutY(axisY);
|
|
|
e.setFaceOutPass(facePass);
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
this.updateBatchById(recordList);
|
|
|
}
|
|
|
+
|
|
|
+ // 新增打卡历史记录
|
|
|
+ TBDingHistory history = new TBDingHistory();
|
|
|
+ history.setSopNo(sopNo);
|
|
|
+ history.setSignDate(signDate);
|
|
|
+ history.setDateType(dateType);
|
|
|
+ history.setSignTime(signTime);
|
|
|
+ history.setAxisX(axisX);
|
|
|
+ history.setAxisY(axisY);
|
|
|
+ history.setFaceOpen(faceOpen);
|
|
|
+ history.setFacePass(facePass);
|
|
|
+ history.setFacePhotoPath(facePhotoPath);
|
|
|
+ history.setMatchScore(score);
|
|
|
+ history.setCreateId(userId);
|
|
|
+ tbDingHistoryService.save(history);
|
|
|
}
|
|
|
|
|
|
/**
|