From 244228feba355b4df8e160fd4c7c353f674044f1 Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期六, 14 二月 2026 17:08:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpClockInServiceImpl.java |  130 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpClockInServiceImpl.java b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpClockInServiceImpl.java
index 10cc8dc..f0f37b9 100644
--- a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpClockInServiceImpl.java
+++ b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpClockInServiceImpl.java
@@ -1,11 +1,30 @@
 package com.xiaopeng.maintenance.service.impl;
 
-import com.xiaopeng.api.model.maintenance.XpClockIn;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xiaopeng.api.model.maintenance.XpCheckLocation;
+import com.xiaopeng.api.model.maintenance.XpClockIn;
+import com.xiaopeng.api.model.maintenance.XpShift;
+import com.xiaopeng.common.core.domain.R;
+import com.xiaopeng.common.core.utils.DateUtils;
+import com.xiaopeng.common.core.utils.GeodesyUtil;
+import com.xiaopeng.maintenance.dto.ClockDTO;
+import com.xiaopeng.maintenance.dto.VerifyRangeDTO;
+import com.xiaopeng.maintenance.mapper.XpCheckLocationMapper;
 import com.xiaopeng.maintenance.mapper.XpClockInMapper;
+import com.xiaopeng.maintenance.mapper.XpShiftMapper;
 import com.xiaopeng.maintenance.service.IXpClockInService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import java.util.Objects;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -24,6 +43,115 @@
 @Service
 public class XpClockInServiceImpl extends ServiceImpl<XpClockInMapper, XpClockIn> implements IXpClockInService {
 
+    @Autowired
+    private XpCheckLocationMapper xpCheckLocationMapper;
+    @Autowired
+    private XpShiftMapper xpShiftMapper;
+    @Autowired
+    private XpClockInMapper xpClockInMapper;
+
+    @Override
+    public Boolean verifyRange(VerifyRangeDTO dto) {
+
+        XpCheckLocation xpCheckLocation = xpCheckLocationMapper.selectById(dto.getLocationId());
+
+        Map<String, Double> distance = GeodesyUtil.getDistance(dto.getUserLon()+","+dto.getUserLat(), xpCheckLocation.getLocationLon()+","+xpCheckLocation.getLocationLat());
+        if (null != distance) {
+            Double distance1 = distance.get("WGS84");
+            if (BigDecimal.valueOf(distance1).compareTo(xpCheckLocation.getLocationRange())>0) {
+                return false;
+            }else {
+                return true;
+            }
+        } else {
+            log.error("调用高德计算距离出错");
+            return false;
+        }
+    }
+
+    @Override
+    public R<String> clockIn(ClockDTO dto) {
+
+        XpCheckLocation xpCheckLocation = xpCheckLocationMapper.selectById(dto.getLocationId());
+
+        Map<String, Double> distance = GeodesyUtil.getDistance(dto.getUserLon()+","+dto.getUserLat(), xpCheckLocation.getLocationLon()+","+xpCheckLocation.getLocationLat());
+        if (null != distance) {
+            Double distance1 = distance.get("WGS84");
+            if (BigDecimal.valueOf(distance1).compareTo(xpCheckLocation.getLocationRange()) > 0) {
+                return R.fail("不在打卡范围内");
+            }
+        }else {
+            return R.fail("打卡失败");
+        }
+
+        // 查询班次
+        XpShift xpShift = xpShiftMapper.selectById(dto.getShiftId());
+        if (null == xpShift) {
+            return R.fail("班次不存在");
+        }
+        // 开始打卡时间
+        String startTime = xpShift.getStartTime();
+        LocalDateTime startLocalDateTime = DateUtils.stringToLocalDateTime(LocalDate.now() + " " + startTime + ":00");
+
+        XpClockIn xpClockIn = new XpClockIn();
+        xpClockIn.setAppUserId(dto.getOperationsUserId());
+        xpClockIn.setClockInTime(LocalDateTime.now());
+        xpClockIn.setClockInLon(dto.getUserLon());
+        xpClockIn.setClockInLat(dto.getUserLat());
+        xpClockIn.setShiftId(dto.getShiftId());
+        if (xpClockIn.getClockInTime().isAfter(startLocalDateTime)) {
+            xpClockIn.setClockInResult(2);
+        }else {
+            xpClockIn.setClockInResult(1);
+        }
+        this.save(xpClockIn);
+        return R.ok();
+    }
+
+    @Override
+    public R<String> clockOut(ClockDTO dto) {
+
+        XpCheckLocation xpCheckLocation = xpCheckLocationMapper.selectById(dto.getLocationId());
+        Map<String, Double> distance = GeodesyUtil.getDistance(dto.getUserLon()+","+dto.getUserLat(), xpCheckLocation.getLocationLon()+","+xpCheckLocation.getLocationLat());
+        if (null != distance) {
+            Double distance1 = distance.get("WGS84");
+            if (BigDecimal.valueOf(distance1).compareTo(xpCheckLocation.getLocationRange()) > 0) {
+                return R.fail("不在打卡范围内");
+            }
+        }else {
+            return R.fail("打卡失败");
+        }
+
+        // 查询上班打卡信息
+        XpClockIn xpClockIn = xpClockInMapper.selectOne(Wrappers.lambdaQuery(XpClockIn.class)
+                .eq(XpClockIn::getAppUserId, dto.getOperationsUserId())
+                .likeRight(XpClockIn::getClockInTime, LocalDate.now())
+                .last("LIMIT 1"));
+        if(Objects.isNull(xpClockIn)){
+            return R.fail("请先上班打卡");
+        }
+
+        // 查询班次
+        XpShift xpShift = xpShiftMapper.selectById(xpClockIn.getShiftId());
+        if (null == xpShift) {
+            return R.fail("班次不存在");
+        }
+        // 开始打卡时间
+        String endTime = xpShift.getEndTime();
+        LocalDateTime endLocalDateTime = DateUtils.stringToLocalDateTime(LocalDate.now() + " " + endTime + ":00");
+
+        xpClockIn.setClockOutTime(LocalDateTime.now());
+        xpClockIn.setClockOutLon(dto.getUserLon());
+        xpClockIn.setClockOutLat(dto.getUserLat());
+
+        if (xpClockIn.getClockOutTime().isBefore(endLocalDateTime)) {
+            xpClockIn.setClockInResult(2);
+        }else {
+            xpClockIn.setClockInResult(1);
+        }
+        this.updateById(xpClockIn);
+        return R.ok();
+    }
     @Override
     public Boolean checkWorkStatus(Long appUserId) {
         if (appUserId == null) {

--
Gitblit v1.7.1