package com.sandu.ximon.admin.service; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.sandu.common.execption.BusinessException; import com.sandu.common.service.impl.BaseServiceImpl; import com.sandu.ximon.dao.domain.InterphoneHostSubPole; import com.sandu.ximon.dao.mapper.InterphoneHostSubPoleMapper; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @Service @AllArgsConstructor public class InterphoneHostSubService extends BaseServiceImpl { private InterphoneHostSubPoleMapper interphoneHostSubPoleMapper; /** * 子设备绑定主设备 */ public boolean bindHostSub(Integer hostId, Integer subId) { if (hostId == null || subId == null) { throw new BusinessException("主设备id或子设备id不能为空"); } InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId)); if (one != null) { throw new BusinessException("子设备已绑定"); } InterphoneHostSubPole pole = new InterphoneHostSubPole(); pole.setHostId(hostId); pole.setSubId(subId); return save(pole); } /** * 子设备解绑主设备 */ public boolean unbindHostSub(Integer subId) { if (subId == null) { throw new BusinessException("子设备id不能为空"); } InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId)); if (one == null) { throw new BusinessException("绑定关系不存在"); } return removeById(one); } }