maven
2025-09-22 b525e2433bf5a4bb28848d4426c0ca07ec949cc2
src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java
@@ -1,6 +1,8 @@
package com.ruoyi.device.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
@@ -22,6 +24,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -44,6 +47,11 @@
    @Override
    public AjaxResult saveDeviceLedger(DeviceLedger deviceLedger) {
        LambdaQueryWrapper<DeviceLedger> deviceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
        deviceLedgerLambdaQueryWrapper.eq(DeviceLedger::getDeviceModel,deviceLedger.getDeviceModel());
        if (this.count(deviceLedgerLambdaQueryWrapper) > 0) {
            return AjaxResult.error("设备型号已存在");
        }
        boolean save = this.save(deviceLedger);
        if (save){
            return AjaxResult.success();
@@ -53,6 +61,14 @@
    @Override
    public AjaxResult updateDeviceLedger(DeviceLedger deviceLedger) {
        if (ObjectUtils.isNotNull(deviceLedger.getStartRuntimeTime()) && ObjectUtils.isNotNull(deviceLedger.getEndRuntimeTime())){
            //计算运行时长
            long start = deviceLedger.getStartRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000;
            long end = deviceLedger.getEndRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000;
            long diffMillis = Math.abs(end - start);
            double time = diffMillis / (1000.0 * 60 * 60);// 毫秒 -> 秒 -> 分钟 -> 小时
            deviceLedger.setRuntimeDuration(time+"h");
        }
        if (this.updateById(deviceLedger)) {
            return AjaxResult.success();
        }