| | |
| | | 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; |
| | |
| | | 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业务层处理 |
| | |
| | | */ |
| | | @Service |
| | | public class ArdChannelServiceImpl implements IArdChannelService { |
| | | @Autowired |
| | | @Resource |
| | | private ArdChannelMapper ardChannelMapper; |
| | | |
| | | /** |
| | |
| | | public int deleteArdChannelById(String id) { |
| | | return ardChannelMapper.deleteArdChannelById(id); |
| | | } |
| | | |
| | | /** |
| | | * 删除通道管理信息 |
| | | * |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | } |