From a0eae3ecda7b70468c60a0079db6c4609c29939d Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 17 四月 2025 09:36:22 +0800 Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/JiaDianHuiShou --- ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java index 0ac1fd6..3583d1e 100644 --- a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java +++ b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java @@ -1,6 +1,7 @@ package com.ruoyi.worker.controller; +import cn.afterturn.easypoi.cache.manager.IFileLoader; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.constant.Constants; @@ -41,8 +42,11 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.annotation.Resource; + +import lombok.Synchronized; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -297,6 +301,7 @@ @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true), @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true) }) + @Synchronized public R<Boolean> coordinate(@RequestParam Double longitude, @RequestParam Double latitude) { System.err.println("调用记录经纬度"+ LocalDateTime.now()); @@ -305,6 +310,13 @@ if (null == loginWorker) { return R.loginExpire("登录失效!"); } + Object cacheObject2 = redisService.getCacheObject("LOCK" + loginWorker.getUserid()); + if (cacheObject2!=null){ + return R.ok(); + }else { + redisService.setCacheObject("LOCK" + loginWorker.getUserid(),"1", 10L, TimeUnit.SECONDS); + } + // 获取当天时间 String today = DateUtils.dateTimeNow("yyyy-MM-dd"); Integer workerId = loginWorker.getUserid(); @@ -343,7 +355,6 @@ // 读取订单ID的JSON文件内容 try { String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath))); - System.out.println("JSON 文件内容:" + jsonContent); List<ServeCoordinate> coordinate = JSONObject.parseObject(jsonContent, List.class); // 订单轨迹信息 ServeCoordinate data = new ServeCoordinate(); @@ -368,7 +379,7 @@ LocalDateTime now = LocalDateTime.now(); // 减去三十分钟 - LocalDateTime thirtyMinutesAgo = now.minusMinutes(10); + LocalDateTime thirtyMinutesAgo = now.minusMinutes(5); // 定义日期时间格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); @@ -378,7 +389,7 @@ String nowStr = now.format(formatter); - redisService.setCacheObject("MARK:"+workerId+":"+nowStr,longitude + "," + latitude); + redisService.setCacheObject("MARK:"+workerId+":"+nowStr,longitude + "," + latitude, 10L, TimeUnit.MINUTES); String cacheObject = redisService.getCacheObject("MARK:" + workerId + ":" + formattedTime); if (cacheObject!=null){ @@ -418,14 +429,14 @@ System.err.println("-----当前距离"+distance); //如果超出一定范围,存入Mark文件 if (distance<50){ - redisService.setCacheObject("TIME:"+workerId,LocalDateTime.now()); + redisService.setCacheObject("TIME:"+workerId,LocalDateTime.now(), 10L, TimeUnit.MINUTES); marker(longitude,latitude); } } } - + redisService.deleteObject("LOCK" + loginWorker.getUserid()); return R.ok(); } @@ -435,7 +446,7 @@ // 检查差值是否小于等于2分钟 long minutes = Math.abs(duration.toMinutes()); - return minutes >= 10; + return minutes >= 5; } /** * 师傅端-定时调度记录师傅当天的轨迹标点 @@ -494,7 +505,6 @@ // 读取订单ID的JSON文件内容 try { String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath))); - System.out.println("JSON 文件内容:" + jsonContent); List<ServeCoordinate> coordinate = JSONObject.parseObject(jsonContent, List.class); // 订单轨迹信息 ServeCoordinate data = new ServeCoordinate(); @@ -525,7 +535,7 @@ // // } - @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页"}) + @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页[2.0]"}) @GetMapping(value = "/putLocation") @ApiImplicitParams({ @ApiImplicitParam(value = "workId", name = "workId", dataType = "int", required = true), @@ -535,10 +545,14 @@ public R<Object> orderNavigation(@RequestParam Integer workId, @RequestParam String longitude, @RequestParam String latitude) { Result<String> address = GaoDeMapUtil.getCityCode(longitude, latitude); - System.err.println(address.getDatas()); + String cityCode = address.getDatas(); + System.err.println("城市code"+cityCode); + String provinceCode = cityCode.substring(0, 2) + "0000"; + System.err.println("省份code"+provinceCode); Set<Integer> strings = new HashSet<>(); strings.add(workId); - redisService.setCacheSet("workerLocation:"+address.getDatas()+":", strings); + redisService.setCacheSet("workerLocation:"+cityCode+":", strings); + redisService.setCacheSet("workerLocation:"+provinceCode+":", strings); redisService.setCacheObject("work:"+workId+":", longitude+","+latitude); return R.ok(); -- Gitblit v1.7.1