package com.ard.work.device.channel.service.impl; import com.ard.common.core.constant.CacheConstants; import com.ard.common.core.constant.Constants; import com.ard.common.core.constant.SecurityConstants; import com.ard.common.core.constant.UserConstants; import com.ard.common.core.domain.R; import com.ard.common.core.enums.LiveStreamType; import com.ard.common.core.utils.uuid.IdUtils; import com.ard.common.redis.service.RedisService; import com.ard.qs.api.RemoteQsDeviceService; import com.ard.qs.api.domain.QsDevice; import com.ard.work.api.domian.ArdCamera; import com.ard.work.api.domian.ArdCameraHepu; import com.ard.work.api.domian.ArdChannel; import com.ard.work.device.channel.mapper.ArdChannelMapper; import com.ard.work.device.channel.service.IArdChannelService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Objects; import java.util.Optional; /** * 通道管理Service业务层处理 * * @author ard * @date 2023-08-19 */ @Service @Slf4j public class ArdChannelServiceImpl implements IArdChannelService { @Resource private ArdChannelMapper ardChannelMapper; @Resource private RemoteQsDeviceService remoteQsDeviceService; @Resource private RedisService redisService; /** * 查询通道管理 * * @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 结果 */ @Transactional @Override public int updateArdChannel(ArdChannel ardChannel) { return ardChannelMapper.updateArdChannel(ardChannel); } /** * 批量删除通道管理 * * @param ids 需要删除的通道管理主键 * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) public int deleteArdChannelByIds(String[] ids) { int i = ardChannelMapper.deleteArdChannelByIds(ids); if (i > 0) { R delR = remoteQsDeviceService.removeQsDevice(ids, SecurityConstants.INNER); } return i; } /** * 删除通道管理信息 * * @param id 通道管理主键 * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) public int deleteArdChannelById(String id) { return ardChannelMapper.deleteArdChannelById(id); } /** * 清空通道 * * @author 刘苏义 * @date 2024/8/10 11:18 */ @Override public int clearArdChannel() { return ardChannelMapper.clearArdChannel(); } /** * 删除通道管理信息 * * @param deviceId 所属设备ID * @return 结果 */ @Override public int deleteArdChannelByDeviceId(String deviceId) { ArdChannel ardChannel = new ArdChannel(); ardChannel.setDeviceId(deviceId); List ardChannels = ardChannelMapper.selectArdChannelList(ardChannel); if (ardChannels != null && !ardChannels.isEmpty()) { String[] ids = ardChannels.stream() .map(ArdChannel::getId) // 提取id .toArray(String[]::new); // 转数组 deleteArdChannelByIds(ids); } return ardChannels != null ? ardChannels.size() : 0; } /** * 校验相机通道是否唯一 * * @param channel 通道信息 * @return 结果 */ @Override public boolean checkArdChannelUnique(ArdChannel channel) { ArdChannel info = ardChannelMapper.checkArdChannelUnique(channel); if (info != null && !Objects.equals(info.getId(), channel.getId())) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; } }