package com.ruoyi.bst.locationLog.service.impl;

import org.springframework.stereotype.Service;

import com.ruoyi.bst.device.domain.DeviceVO;
import com.ruoyi.bst.locationLog.domain.LocationLog;
import com.ruoyi.bst.locationLog.service.LocationLogConverter;
import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus;
import com.ruoyi.common.utils.StringUtils;

@Service
public class LocationLogConverterImpl implements LocationLogConverter {

    @Override
    public LocationLog toPo(DeviceVO device) {
        if (device == null || StringUtils.isBlank(device.getMac())) {
            return null;
        }

        // 转为定位日志
        LocationLog po = new LocationLog();
        po.setMac(device.getMac());
        po.setSn(device.getSn());
        po.setStatus(device.getStatus());
        po.setLockStatus(device.getLockStatus());
        po.setIotStatus(device.getIotStatus());
        po.setQuality(device.getQuality());
        po.setVoltage(device.getVoltage());
        po.setSignal(device.getSignalStrength());
        po.setSatellites(device.getSatellites());
        po.setLongitude(device.getLongitude());
        po.setLatitude(device.getLatitude());
        po.setAt(device.getLastLocationTime());
        po.setDeviceId(device.getId());
        po.setType(device.getLocationType());
        if (OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus())) {
            po.setOrderId(device.getOrderId());
        }
        return po;
    }

}
