DeviceLocationService.java 2.44 KB
package cn.com.glsx.stdinterface.modules.service;

import cn.com.glsx.stdinterface.dto.DeviceLocationDto;
import cn.com.glsx.stdinterface.modules.mapper.DeviceLocationMapper;
import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 设备上点 serviceImpl
 *
 * @author yll
 */
import cn.com.glsx.stdinterface.modules.model.LocationCheckBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DeviceLocationService {

    @Autowired
    private DeviceLocationMapper deviceLocationMapper;

    /**
     * 插入或者更新设备上点数据
     *
     * @param deviceLocationDtoList
     */
    public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) {
        deviceLocationDtoList.forEach(deviceLocationDto -> {
            DeviceLocation locationBySn = deviceLocationMapper.getDeviceLocationBySn(deviceLocationDto.getSn());
            if (ObjectUtil.isNull(locationBySn)) {
                DeviceLocation deviceLocation = new DeviceLocation();
                BeanUtils.copyProperties(deviceLocationDto, deviceLocation);
                deviceLocation.setCreatedTime(new Date());
                deviceLocationMapper.insertSelective(deviceLocation);
            } else {
                mergeData(locationBySn, deviceLocationDto);
                deviceLocationMapper.updateByPrimaryKeySelective(locationBySn);
            }
        });
    }

    private void mergeData(DeviceLocation locationBySn, DeviceLocationDto deviceLocationDto) {
        if (ObjectUtil.isNotEmpty(deviceLocationDto.getLastGpsTime())) {
            locationBySn.setLastGpsTime(deviceLocationDto.getLastGpsTime());
        }

        if (ObjectUtil.isNotEmpty(deviceLocationDto.getLastBsTime())) {
            locationBySn.setLastBsTime(deviceLocationDto.getLastBsTime());
        }
        locationBySn.setUpdatedTime(new Date());
    }

    /**
     * 获取E盾中的所有设备号集合
     *
     * @return
     */
    public List<String> getAllSnInNewEshield() {
        return deviceLocationMapper.getAllSnInNewEshield();
    }
    public void locationCheck(LocationCheckBO checkBO) {

    }

}