package com.ard.work.carousel.service.impl;
|
|
import com.ard.common.core.constant.SecurityConstants;
|
import com.ard.common.core.domain.R;
|
import com.ard.common.core.utils.DateUtils;
|
import com.ard.common.core.utils.uuid.IdUtils;
|
import com.ard.common.datascope.annotation.DataScope;
|
import com.ard.vtdu.api.RemoteArdVtduService;
|
import com.ard.vtdu.api.domian.ArdVtdu;
|
import com.ard.work.api.domian.ArdChannel;
|
import com.ard.work.carousel.domain.ArdCarouselPlans;
|
import com.ard.work.carousel.domain.ArdCarouselWindow;
|
import com.ard.work.carousel.domain.ArdCarouselWindowChannel;
|
import com.ard.work.carousel.mapper.ArdCarouselPlansMapper;
|
import com.ard.work.carousel.mapper.ArdCarouselWindowChannelMapper;
|
import com.ard.work.carousel.mapper.ArdCarouselWindowMapper;
|
import com.ard.work.carousel.service.IArdCarouselPlansService;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* 视频轮播方案Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2024-09-03
|
*/
|
@Service
|
public class ArdCarouselPlansServiceImpl implements IArdCarouselPlansService {
|
@Resource
|
private ArdCarouselPlansMapper ardCarouselPlansMapper;
|
@Resource
|
private ArdCarouselWindowMapper ardCarouselWindowMapper;
|
@Resource
|
private ArdCarouselWindowChannelMapper ardCarouselWindowChannelMapper;
|
@Resource
|
private RemoteArdVtduService remoteArdVtduService;
|
|
/**
|
* 查询视频轮播方案
|
*
|
* @param id 视频轮播方案主键
|
* @return 视频轮播方案
|
*/
|
@Override
|
public ArdCarouselPlans selectArdCarouselPlansById(String id) {
|
ArdCarouselPlans ardCarouselPlans = ardCarouselPlansMapper.selectArdCarouselPlansById(id);
|
if (ardCarouselPlans == null) {
|
return new ArdCarouselPlans();
|
}
|
ArdCarouselWindow ardCarouselWindow = new ArdCarouselWindow();
|
ardCarouselWindow.setPlanId(id);
|
List<ArdCarouselWindow> ardCarouselWindows = ardCarouselWindowMapper.selectArdCarouselWindowList(ardCarouselWindow);
|
ardCarouselWindows.stream().forEach(ardCarouselWindow1 -> {
|
//获取窗口关联的通道
|
List<ArdChannel> ardChannels = ardCarouselWindowChannelMapper.selectChannelIdsByWindowId(ardCarouselWindow1.getId());
|
ardCarouselWindow1.setArdChannels(ardChannels);
|
|
//获取通道关联的流媒体
|
List<ArdVtdu> ardVtduList = ardChannels.stream().map(channel -> {
|
// 拼接名称
|
String name = channel.getDeviceId() + "_" + channel.getChanNo();
|
// 从 流媒体微服务 中获取对应的 ArdVtdu 对象
|
R<ArdVtdu> ArdVtduR = remoteArdVtduService.getInfo(name, SecurityConstants.INNER);
|
if (ArdVtduR.getCode() != R.SUCCESS) {
|
return null; // 如果不成功,返回 null
|
}
|
return ArdVtduR.getData();
|
}).filter(vtdu -> vtdu != null) // 过滤掉 null 值
|
.collect(Collectors.toList());
|
ardCarouselWindow1.setArdVtdus(ardVtduList);
|
});
|
ardCarouselPlans.setArdCarouselWindows(ardCarouselWindows);
|
return ardCarouselPlans;
|
}
|
|
/**
|
* 查询视频轮播方案列表
|
*
|
* @param ardCarouselPlans 视频轮播方案
|
* @return 视频轮播方案
|
*/
|
@Override
|
@DataScope(deptAlias = "d", userAlias = "u")
|
public List<ArdCarouselPlans> selectArdCarouselPlansList(ArdCarouselPlans ardCarouselPlans) {
|
return ardCarouselPlansMapper.selectArdCarouselPlansList(ardCarouselPlans);
|
}
|
|
/**
|
* 新增视频轮播方案
|
*
|
* @param ardCarouselPlans 视频轮播方案
|
* @return 结果
|
*/
|
@Override
|
@Transactional
|
public int insertArdCarouselPlans(ArdCarouselPlans ardCarouselPlans) {
|
ardCarouselPlans.setId(IdUtils.fastSimpleUUID());
|
insertWindowChannel(ardCarouselPlans);
|
ardCarouselPlans.setCreateTime(DateUtils.getNowDate());
|
return ardCarouselPlansMapper.insertArdCarouselPlans(ardCarouselPlans);
|
}
|
|
/**
|
* 修改视频轮播方案
|
*
|
* @param ardCarouselPlans 视频轮播方案
|
* @return 结果
|
*/
|
@Override
|
@Transactional
|
public int updateArdCarouselPlans(ArdCarouselPlans ardCarouselPlans) {
|
ardCarouselPlans.setUpdateTime(DateUtils.getNowDate());
|
//先删除当前计划ID关联的所有窗口和通道数据
|
deleteWindowChannel(ardCarouselPlans.getId());
|
//后插入ID关联的所有窗口和通道数据
|
insertWindowChannel(ardCarouselPlans);
|
return ardCarouselPlansMapper.updateArdCarouselPlans(ardCarouselPlans);
|
}
|
|
/**
|
* 批量删除视频轮播方案
|
*
|
* @param ids 需要删除的视频轮播方案主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdCarouselPlansByIds(String[] ids) {
|
Arrays.stream(ids).forEach(id -> {
|
//先删除当前计划ID关联的所有窗口和通道数据
|
deleteWindowChannel(id);
|
});
|
return ardCarouselPlansMapper.deleteArdCarouselPlansByIds(ids);
|
}
|
|
/**
|
* 删除视频轮播方案信息
|
*
|
* @param id 视频轮播方案主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteArdCarouselPlansById(String id) {
|
//先删除当前计划ID关联的所有窗口和通道数据
|
deleteWindowChannel(id);
|
return ardCarouselPlansMapper.deleteArdCarouselPlansById(id);
|
}
|
|
/**
|
* 添加轮播方案和窗口和通道的关系
|
*
|
* @param ardCarouselPlans 巡检方案
|
* @return
|
* @author 刘苏义
|
* @date 2024/9/4 10:57
|
*/
|
public void insertWindowChannel(ArdCarouselPlans ardCarouselPlans) {
|
ardCarouselPlans.getArdCarouselWindows().forEach(ardCarouselWindow -> {
|
ardCarouselWindow.setId(IdUtils.fastSimpleUUID());
|
List<ArdCarouselWindowChannel> windowChannelList = ardCarouselWindow.getArdChannels().stream()
|
.map(ardChannel -> {
|
ArdCarouselWindowChannel ardCarouselWindowChannel = new ArdCarouselWindowChannel();
|
ardCarouselWindowChannel.setCameraId(ardChannel.getDeviceId());
|
ardCarouselWindowChannel.setChanNo(ardChannel.getChanNo());
|
ardCarouselWindowChannel.setWindowId(ardCarouselWindow.getId());
|
return ardCarouselWindowChannel;
|
})
|
.collect(Collectors.toList());
|
|
ardCarouselWindow.setCreateTime(DateUtils.getNowDate());
|
ardCarouselWindow.setPlanId(ardCarouselPlans.getId());
|
ardCarouselWindowMapper.insertArdCarouselWindow(ardCarouselWindow);
|
if (!windowChannelList.isEmpty()) {
|
ardCarouselWindowChannelMapper.batchWindowChannel(windowChannelList);
|
}
|
});
|
}
|
|
/**
|
* 删除轮播方案和窗口和通道的关系
|
*
|
* @param id 巡检方案ID
|
* @return
|
* @author 刘苏义
|
* @date 2024/9/4 10:57
|
*/
|
public void deleteWindowChannel(String id) {
|
//先删除当前计划ID关联的所有窗口和通道数据
|
ArdCarouselWindow ardCarouselWindow = new ArdCarouselWindow();
|
ardCarouselWindow.setPlanId(id);
|
List<ArdCarouselWindow> windows = ardCarouselWindowMapper.selectArdCarouselWindowList(ardCarouselWindow);
|
if (!windows.isEmpty()) {
|
List<String> windowIds = windows.stream().map(ArdCarouselWindow::getId).collect(Collectors.toList());
|
ardCarouselWindowChannelMapper.deleteWindowChannel(windowIds.toArray(new String[0]));
|
ardCarouselWindowMapper.deleteArdCarouselWindowByIds(windowIds.toArray(new String[0]));
|
}
|
}
|
}
|