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

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.bst.device.domain.Device;
import com.ruoyi.bst.device.service.DeviceIotService;
import com.ruoyi.bst.device.utils.DeviceUtil;
import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO;
import com.ruoyi.bst.orderDevice.service.OrderDeviceAssembler;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.collection.CollectionUtils;

@Service
public class OrderDeviceAssemblerImpl implements OrderDeviceAssembler {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private DeviceIotService deviceIotService;

    @Override
    public void assembleIot(List<OrderDeviceVO> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return;
        }

        for (OrderDeviceVO vo : list) {
            Device device = new Device();
            device.setMac(vo.getDeviceMac());
            Map<String, Object> info = deviceIotService.getIotInfo(device.getMac());
            if (info == null) {
                continue;
            }
            DeviceUtil.setIotInfo(device, info);

            vo.setDeviceVoltage(device.getVoltage());
            vo.setDeviceOnlineStatus(device.getOnlineStatus());
            vo.setDeviceLongitude(device.getLongitude());
            vo.setDeviceLatitude(device.getLatitude());
        }
    }
    
}
