Pu Zhibing
2025-04-25 4bff66cbe2f53d97766e190bdb0fbe131cadd900
DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverOnlineServiceImpl.java
@@ -156,7 +156,7 @@
        }
        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)"));
        //生成每个活动从开始上班到当前时间的时长记录
        for (DriverActivityHistory driverActivityHistory : driverActivityHistories) {
            String value = redisUtil.getValue("driverActivity_" + driverId + "_" + driverActivityHistory.getId());
@@ -164,10 +164,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);
            }
        }
    }
@@ -257,14 +257,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 /home/igotechgh/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 +287,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){
@@ -334,14 +341,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 /home/igotechgh/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);
@@ -361,7 +375,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);
            }
        }
    }