package com.xydl.cac.service.impl;

import com.xydl.cac.entity.N103Sensor;
import com.xydl.cac.repository.N103SensorRepository;
import com.xydl.cac.service.N103SensorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class N103SensorServiceImpl implements N103SensorService {
    @Resource
    N103SensorRepository repository;

    @Override
    public void importOne(N103Sensor item) {
        List<N103Sensor> list = repository.findByNsensorId(item.getNsensorId());
        if (!CollectionUtils.isEmpty(list)) {
            item.setId(list.get(0).getId());
        }
        repository.save(item);
    }
}
