package com.fastbee.iot.service.impl;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.iot.domain.DeviceReportInfo;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
import com.fastbee.iot.service.IDeviceActivationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 设备激活Service业务层处理
 */
@Service
public class DeviceActivationServiceImpl implements IDeviceActivationService
{
   @Autowired
   private DeviceMapper deviceMapper;

   @Autowired
   private DeviceReportInfoMapper deviceReportInfoMapper;

   @Override
   public int selectDevice(String serialNumber,Long tenantId,String tenantName,double longitude,double latitude,String imgUrl,String name)
   {
      //获取激活时间/更新时间
      DateTime activationTime=DateTime.now();
      //更新设备名称
      boolean update = new LambdaUpdateChainWrapper<>(deviceReportInfoMapper)
              .set(DeviceReportInfo::getName, name)
              .set(DeviceReportInfo::getLatitude,latitude)
              .set(DeviceReportInfo::getLongitude,longitude)
              .eq(DeviceReportInfo::getSerialNumber, serialNumber)
              .update();
      return deviceMapper.updateDeviceActivationStatus(serialNumber,activationTime,tenantId,tenantName,longitude,latitude,imgUrl);
   }
}
