From 821fc2f632f8b974a2c0fc37630e13c5fbe6086c Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 26 九月 2025 17:26:16 +0800 Subject: [PATCH] 修改bug --- DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java | 71 ++++++++++++++++++++++------------- 1 files changed, 45 insertions(+), 26 deletions(-) diff --git a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java index d86ae0c..6821759 100644 --- a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java +++ b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java @@ -156,7 +156,14 @@ } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List<DriverActivityHistory> driverActivityHistories = driverActivityHistoryMapper.selectList(new EntityWrapper<DriverActivityHistory>().eq("driverId", driverId) - .eq("type", 3).eq("carryOut", 1).last(" and day = '" + sdf.format(new Date()) + "'")); + .eq("type", 3).eq("carryOut", 1).last(" and day = '" + sdf.format(new Date()) + "' and driverActivityId in (select id from t_driver_activity where status = 3 and now() between startTime and endTime)")); + if(!driverActivityHistories.isEmpty()){ + //如果一直属于上班中,则需要从任务开始时间计算时间 + Date insertTime = driverActivityHistories.get(0).getInsertTime(); + if(driverWork.getStartTime().getTime() < insertTime.getTime()){ + driverWork.setStartTime(insertTime); + } + } //生成每个活动从开始上班到当前时间的时长记录 for (DriverActivityHistory driverActivityHistory : driverActivityHistories) { String value = redisUtil.getValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId()); @@ -164,10 +171,10 @@ JSONObject jsonObject = JSON.parseObject(value); Long startTime = jsonObject.getLong("startTime"); long time = System.currentTimeMillis() - startTime; - redisUtil.setStrValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId(), "{\"startTime\":" + startTime + ", \"time\":" + time + "}"); + redisUtil.setStrValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId(), "{\"startTime\":" + startTime + ", \"time\":" + time + "}", 172800); }else{ long time = System.currentTimeMillis() - driverWork.getStartTime().getTime(); - redisUtil.setStrValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId(), "{\"startTime\":" + driverWork.getStartTime().getTime() + ", \"time\":" + time + "}"); + redisUtil.setStrValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId(), "{\"startTime\":" + driverWork.getStartTime().getTime() + ", \"time\":" + time + "}", 172800); } } } @@ -210,7 +217,6 @@ continue; } Integer driverId = driverOnline.getDriverId(); - Driver driver1 = driverService.selectById(driverId); long m = Double.valueOf(driverActivityOnline.getOfflineTime() * 3600000L).longValue(); //找出最后一次接单的时间 @@ -257,14 +263,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /data/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } } }, 30000); @@ -280,7 +293,7 @@ public void deductionDuration1() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List<DriverActivityHistory> driverActivityHistories = driverActivityHistoryMapper.selectList(new EntityWrapper<DriverActivityHistory>() - .eq("type", 3).eq("carryOut", 1).last(" and day = '" + sdf.format(new Date()) + "'")); + .eq("type", 3).eq("carryOut", 1).last(" and day = '" + sdf.format(new Date()) + "' and driverActivityId in (select id from t_driver_activity where status = 3 and now() between startTime and endTime)")); for (DriverActivityHistory driverActivityHistory : driverActivityHistories) { DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driverActivityHistory.getDriverId()).eq("state", 1)); if(null == driverWork){ @@ -299,13 +312,13 @@ //在线时长累计 Long time = jsonObject.getLong("time") / 60000; int count1 = orderPrivateCarService.selectCount(new EntityWrapper<OrderPrivateCar>().eq("driverId", driverActivityHistory.getDriverId()) - .eq("isDelete", 1).ne("state", 10).last(" and UNIX_TIMESTAMP(snatchOrderTime) > " + (startTime) / 1000)); + .eq("isDelete", 1).ne("state", 10).last(" and UNIX_TIMESTAMP(snatchOrderTime) > " + (startTime / 1000))); int count2 = orderLogisticsService.selectCount(new EntityWrapper<OrderLogistics>().eq("driverId", driverActivityHistory.getDriverId()) - .eq("isDelete", 1).ne("state", 10).last(" and UNIX_TIMESTAMP(snatchOrderTime) > " + (startTime) / 1000)); + .eq("isDelete", 1).ne("state", 10).last(" and UNIX_TIMESTAMP(snatchOrderTime) > " + (startTime / 1000))); Driver driver = driverService.selectById(driverWork.getDriverId()); //阶段时间累计时长超过设定时长且没有接单,不计入累计总时长(司机服务中不下班) - if(m <= time && count1 + count2 == 0 && driver.getState() != 3){ + if(m <= time && (count1 + count2) == 0){ //司机下班,清空当前阶段的累计时长 driverWork.setState(2); driverWork.setEndTime(new Date()); @@ -334,20 +347,26 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用Runtime执行命令 + Process process = Runtime.getRuntime().exec("sudo rm -rf /data/nginx/html/files/audio/" + fileName); + // 读取命令的输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + // 等待命令执行完成 + process.waitFor(); + // 关闭流 + reader.close(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } } }, 30000); - } - //阶段时间累计有新的订单,计入累计总时长,重置新的开始统计时间戳 - if(m <= time && count1 + count2 > 0){ + } else if(m <= time && (count1 + count2) > 0){ + //阶段时间累计有新的订单,计入累计总时长,重置新的开始统计时间戳 DriverOnline driverOnline = this.selectOne(new EntityWrapper<DriverOnline>().eq("DATE_FORMAT(date, '%Y-%m-%d')", sdf.format(new Date())) .eq("driverId", driverActivityHistory.getDriverId())); if(null == driverOnline){ @@ -361,7 +380,7 @@ driverOnline.setDuration(driverOnline.getDuration() + (time * 60)); this.updateById(driverOnline); } - redisUtil.setStrValue("driverActivity_" + driverActivityHistory.getDriverId() + "_" + driverActivityHistory.getId(), "{\"startTime\":" + System.currentTimeMillis() + ", \"time\":" + 0 + "}"); + redisUtil.setStrValue("driverActivity_" + driverActivityHistory.getDriverId() + "_" + driverActivityHistory.getId(), "{\"startTime\":" + System.currentTimeMillis() + ", \"time\":" + 0 + "}", 172800); } } } -- Gitblit v1.7.1