DeviceLocationService.java 2.68 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.com.glsx.stdinterface.modules.model.LocationCheckBO;
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
 */

@Slf4j
@Service
public class DeviceLocationService {

    @Autowired
    private DeviceLocationMapper deviceLocationMapper;

    /**
     * 插入或者更新设备上点数据
     *
     * @param deviceLocationDtoList
     */
    public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) {
        for (DeviceLocationDto deviceLocationDto : deviceLocationDtoList) {
            try {
                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);
                }
            } catch (Exception e) {
                log.error("设备号:" + deviceLocationDto.getSn() + "查询异常===" + e.getMessage());
                e.printStackTrace();
            }
        }
    }

    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();
    }

    /**
     * 位置验证
     *
     * @param checkBO
     */
    public void locationCheck(LocationCheckBO checkBO) {

    }
}