From 1d583729f100bd446b0647534c766b8aafabe291 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期一, 27 十月 2025 11:11:32 +0800
Subject: [PATCH] app附近人员接口

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java |   67 ++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
index a3d24ca..0549ffe 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
@@ -4,7 +4,9 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.UpdateDetailTeamDto;
 import com.ruoyi.system.dto.UserIdDto;
@@ -14,12 +16,17 @@
 import com.ruoyi.system.service.TAppUserEquipmentService;
 import com.ruoyi.system.service.TAppUserLocationService;
 import com.ruoyi.system.service.TAppUserService;
+import com.ruoyi.system.utils.GDMapGeocodingUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.LocalDate;
+
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -40,13 +47,15 @@
     private final PasswordEncoder passwordEncoder;
     private final TAppUserEquipmentService appUserEquipmentService;
     private final TAppUserLocationService appUserLocationService;
+    private final RedisCache redisCache;
     @Autowired
-    public TAppUserController(TAppUserService appUserService, TokenService tokenService, PasswordEncoder passwordEncoder, TAppUserEquipmentService appUserEquipmentService, TAppUserLocationService appUserLocationService) {
+    public TAppUserController(TAppUserService appUserService, TokenService tokenService, PasswordEncoder passwordEncoder, TAppUserEquipmentService appUserEquipmentService, TAppUserLocationService appUserLocationService, RedisCache redisCache) {
         this.appUserService = appUserService;
         this.tokenService = tokenService;
         this.passwordEncoder = passwordEncoder;
         this.appUserEquipmentService = appUserEquipmentService;
         this.appUserLocationService = appUserLocationService;
+        this.redisCache = redisCache;
     }
 
     /**
@@ -95,7 +104,7 @@
      * 查看人员管理详情--修改队伍情况
      */
     @ApiOperation(value = "查看人员管理详情--修改队伍情况",response = UpdateDetailTeamDto.class)
-    @PostMapping(value = "/open/t-app-user/updateDetailTeam")
+    @PostMapping(value = "/api/t-app-user/updateDetailTeam")
     public R<?> updateDetailTeam(@RequestBody String param) {
         String userId = tokenService.getLoginUserApplet().getUserId();
         UpdateDetailTeamDto dto = JSON.parseObject(param, UpdateDetailTeamDto.class);
@@ -112,12 +121,31 @@
      * 用户打点
      */
     @ApiOperation(value = "用户打点",response = TAppUserLocation.class)
-    @PostMapping(value = "/open/t-app-user/appUserLocation")
+    @PostMapping(value = "/api/t-app-user/appUserLocation")
     public R<?> appUserLocation(@RequestBody String param) {
         TAppUserLocation location = JSON.parseObject(param,TAppUserLocation.class);
         String userId = tokenService.getLoginUserApplet().getUserId();
         location.setAppUserId(userId);
         appUserLocationService.save(location);
+        return R.ok();
+    }
+
+    /**
+     * 用户实时定位上传
+     */
+    @ApiOperation(value = "用户实时定位上传")
+    @PostMapping(value = "/open/t-app-user/positioningUpload")
+    public R<String> positioningUpload(@RequestParam(value = "lon") String lon ,
+                                       @RequestParam(value = "lat") String lat ) {
+        String userId = tokenService.getLoginUserApplet().getUserId();
+        String location = redisCache.getCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now());
+        if(StringUtils.hasLength(location)){
+            redisCache.setCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now(), location + ";" +lon + "," + lat);
+        }else {
+            redisCache.setCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now(), lon + "," + lat);
+        }
+        // 实时定位点
+        redisCache.setCacheObject(Constants.LOCATION + userId, lon + "," + lat);
         return R.ok();
     }
 
@@ -143,6 +171,39 @@
         return R.ok(location);
     }
 
+    /**
+     * 用户附近人员定位
+     */
+    @ApiOperation(value = "用户附近人员定位")
+    @PostMapping(value = "/open/t-app-user/nearUserLocation")
+    public R<List<TAppUser>> nearUserLocation(@RequestParam(value = "lon") String lon ,
+                                       @RequestParam(value = "lat") String lat ) {
+        List<TAppUser> list = appUserService.list(Wrappers.lambdaQuery(TAppUser.class)
+                .eq(TAppUser::getStatus, 1)
+                .eq(TAppUser::getState, 1));
+
+        Iterator<TAppUser> iterator = list.iterator();
+        while (iterator.hasNext()) {
+            TAppUser appUser = iterator.next();
+            String location = redisCache.getCacheObject(Constants.LOCATION + appUser.getId());
+            if(!StringUtils.hasLength(location)){
+                iterator.remove();
+            }else {
+                // 计算距离
+                double startLon = Double.parseDouble(location.split(",")[0]);
+                double startLat = Double.parseDouble(location.split(",")[1]);
+                double distance = GDMapGeocodingUtil.getDistance(Double.parseDouble(lon), Double.parseDouble(lat), startLon, startLat);
+                distance = distance / 1000;
+                if(distance>50){
+                    iterator.remove();
+                }else {
+                    appUser.setLon(String.valueOf(startLon));
+                    appUser.setLat(String.valueOf(startLat));
+                }
+            }
+        }
+        return R.ok(list);
+    }
 
 }
 

--
Gitblit v1.7.1