package com.ruoyi.ss.device.utils;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author wjh
 * 2025/1/3
 */
public class DeviceUtils {


    public static long getSyncSeconds(LocalDateTime expireTime, LocalDateTime now) {
        if (expireTime == null) {
            return 0L;
        }
        if (now == null) {
            now = LocalDateTime.now();
        }
        return Duration.between(now, expireTime).getSeconds();
    }

    public static BigDecimal getSyncEle(BigDecimal expireEle, BigDecimal totalEle) {
        if (expireEle == null) {
            return BigDecimal.ZERO;
        }
        if (totalEle == null) {
            return expireEle;
        }
        if (totalEle.compareTo(expireEle) >= 0) {
            return BigDecimal.ZERO;
        }
        return expireEle.subtract(totalEle);
    }
}
