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 org.springframework.stereotype.Service; 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业务层处理 * * @author ard * @date 2023-08-19 */ @Service public class ArdChannelServiceImpl implements IArdChannelService { @Resource private ArdChannelMapper ardChannelMapper; /** * 查询通道管理 * * @param id 通道管理主键 * @return 通道管理 */ @Override public ArdChannel selectArdChannelById(String id) { return ardChannelMapper.selectArdChannelById(id); } /** * 查询通道管理列表 * * @param ardChannel 通道管理 * @return 通道管理 */ @Override public List selectArdChannelList(ArdChannel ardChannel) { return ardChannelMapper.selectArdChannelList(ardChannel); } /** * 新增通道管理 * * @param ardChannel 通道管理 * @return 结果 */ @Override public int insertArdChannel(ArdChannel ardChannel) { ardChannel.setId(IdUtils.simpleUUID()); return ardChannelMapper.insertArdChannel(ardChannel); } /** * 修改通道管理 * * @param ardChannel 通道管理 * @return 结果 */ @Override public int updateArdChannel(ArdChannel ardChannel) { return ardChannelMapper.updateArdChannel(ardChannel); } /** * 批量删除通道管理 * * @param ids 需要删除的通道管理主键 * @return 结果 */ @Override public int deleteArdChannelByIds(String[] ids) { return ardChannelMapper.deleteArdChannelByIds(ids); } /** * 删除通道管理信息 * * @param id 通道管理主键 * @return 结果 */ @Override public int deleteArdChannelById(String id) { return ardChannelMapper.deleteArdChannelById(id); } /** * 删除通道管理信息 * * @param deviceId 所属设备ID * @return 结果 */ @Override public int deleteArdChannelByDeviceId(String deviceId) { return ardChannelMapper.deleteArdChannelByDeviceId(deviceId); } //求两个对象List的交集 @Override public List sameList(List oldArrayList, List newArrayList) { List 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 diffList(List firstArrayList, List secondArrayList) { List 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 oldArrayList, List 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); }); } }