package com.sandu.ximon.admin.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.sandu.common.execption.BusinessException;
|
import com.sandu.common.service.impl.BaseServiceImpl;
|
import com.sandu.common.util.SpringContextHolder;
|
import com.sandu.ximon.admin.security.SecurityUtils;
|
import com.sandu.ximon.dao.domain.InterphoneHost;
|
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
|
import com.sandu.ximon.dao.domain.InterphoneSub;
|
import com.sandu.ximon.dao.mapper.InterphoneHostSubPoleMapper;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
@AllArgsConstructor
|
public class InterphoneHostSubService extends BaseServiceImpl<InterphoneHostSubPoleMapper, InterphoneHostSubPole> {
|
private InterphoneHostSubPoleMapper interphoneHostSubPoleMapper;
|
|
/**
|
* 子设备绑定主设备
|
*/
|
public boolean bindHostSub(Integer hostId, Integer subId) {
|
if (hostId == null || subId == null) {
|
throw new BusinessException("主设备id或子设备id不能为空");
|
}
|
if (SecurityUtils.getClientId() != null) {
|
throw new BusinessException("只有管理员才能进行此操作");
|
}
|
InterphoneHostSubPole pole = new InterphoneHostSubPole();
|
InterphoneHost host = SpringContextHolder.getBean(InterphoneHostService.class).getById(hostId);
|
InterphoneSub sub = SpringContextHolder.getBean(InterphoneSubService.class).getById(subId);
|
if (host == null || sub == null) {
|
throw new BusinessException("主设备或子设备不存在");
|
}
|
InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId));
|
if (one != null) {
|
throw new BusinessException("子设备已绑定");
|
}
|
|
pole.setHostId(hostId);
|
pole.setSubId(subId);
|
return save(pole);
|
}
|
|
/**
|
* 子设备解绑主设备
|
*/
|
public boolean unbindHostSub(Integer subId) {
|
if (subId == null) {
|
throw new BusinessException("子设备id不能为空");
|
}
|
if (SecurityUtils.getClientId() != null) {
|
throw new BusinessException("只有管理员才能进行此操作");
|
}
|
LambdaQueryWrapper<InterphoneHostSubPole> eq = Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId);
|
InterphoneHostSubPole one = getOne(eq);
|
if (one == null) {
|
throw new BusinessException("绑定关系不存在");
|
}
|
return remove(eq);
|
}
|
}
|