liusuyi
2024-07-10 016aa105789fca71e86cdbb0d26a181812f200f9
ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.device.channel.service.impl;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,6 +9,8 @@
import com.ruoyi.device.channel.mapper.ArdChannelMapper;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.service.IArdChannelService;
import javax.annotation.Resource;
/**
 * 通道管理Service业务层处理
@@ -17,7 +20,7 @@
 */
@Service
public class ArdChannelServiceImpl implements IArdChannelService {
    @Autowired
    @Resource
    private ArdChannelMapper ardChannelMapper;
    /**
@@ -86,6 +89,7 @@
    public int deleteArdChannelById(String id) {
        return ardChannelMapper.deleteArdChannelById(id);
    }
    /**
     * 删除通道管理信息
     *
@@ -96,4 +100,39 @@
    public int deleteArdChannelByDeviceId(String deviceId) {
        return ardChannelMapper.deleteArdChannelByDeviceId(deviceId);
    }
    //求两个对象List的交集
    @Override
    public List<ArdChannel> sameList(List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) {
        List<ArdChannel> resultList = newArrayList.stream()
                .filter(item -> oldArrayList.stream().map(e -> e.getChanNo())
                        .collect(Collectors.toList()).contains(item.getChanNo()))
                .collect(Collectors.toList());
        return resultList;
    }
    //求两个对象List的差集
    @Override
    public List<ArdChannel> diffList(List<ArdChannel> firstArrayList, List<ArdChannel> secondArrayList) {
        List<ArdChannel> resultList = firstArrayList.stream()
                .filter(item -> !secondArrayList.stream().map(e -> e.getChanNo()).collect(Collectors.toList()).contains(item.getChanNo()))
                .collect(Collectors.toList());
        return resultList;
    }
    @Override
    public void asyncChannel(List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) {
        //需要更新的数据,参数顺序注意
        sameList(oldArrayList, newArrayList).stream().forEach(ardChannel -> {
            updateArdChannel(ardChannel);
        });
        //需要删除的数据
        diffList(oldArrayList, newArrayList).stream().forEach(ardChannel -> {
            deleteArdChannelById(ardChannel.getId());
        });
        //需要新增的数据
        diffList(newArrayList, oldArrayList).stream().forEach(ardChannel -> {
            insertArdChannel(ardChannel);
        });
    }
}