xuhy
19 小时以前 1d583729f100bd446b0647534c766b8aafabe291
app附近人员接口
3个文件已修改
47 ■■■■■ 已修改文件
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/webSocket/WebSocketServer.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/test/java/com/ruoyi/web/controller/webSocket/WebSocketClientTest.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
@@ -16,6 +16,7 @@
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;
@@ -25,6 +26,7 @@
import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;
/**
@@ -169,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);
    }
}
ruoyi-applet/src/main/java/com/ruoyi/web/controller/webSocket/WebSocketServer.java
@@ -64,7 +64,7 @@
                             * 浏览器请求时: ws://localhost:7000/xxx 请求的url
                             * 核心功能是将http协议升级为ws协议 保持长链接
                             */
                            pipeline.addLast(new WebSocketServerProtocolHandler("/hello"));
                            pipeline.addLast(new WebSocketServerProtocolHandler("/websocket"));
                            // 自定义Handler, 处理业务逻辑
                            // 使用@Sharable注解的Handler,可以被多个连接共享
                            pipeline.addLast(webSocketTextFrameHandler);
ruoyi-applet/src/test/java/com/ruoyi/web/controller/webSocket/WebSocketClientTest.java
@@ -202,7 +202,13 @@
        // 发送心跳消息: {"type":"ping","timestamp":1761294280878}
        // 发送业务消息: {"type":"business","content":"这是一条测试业务消息","timestamp":1761294280878}
        JSONObject businessMessage = new JSONObject();
        businessMessage.put("type", "mission_push");
        businessMessage.put("content", "{\"missionId\":\"1976542839650725890\"}");
        businessMessage.put("timestamp", System.currentTimeMillis());
        String message = businessMessage.toJSONString();
        log.info("发送业务消息: {}", message);
    }
    /**
@@ -222,8 +228,8 @@
     */
    private void sendBusinessMessage() {
        JSONObject businessMessage = new JSONObject();
        businessMessage.put("type", "business");
        businessMessage.put("content", "这是一条测试业务消息");
        businessMessage.put("type", "mission_push");
        businessMessage.put("content", "{\"missionId\":\"1976542839650725890\"}");
        businessMessage.put("timestamp", System.currentTimeMillis());
        
        String message = businessMessage.toJSONString();