2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-12 6fe040e3e2805c28442090221e9a4597381830d9
ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostSubService.java
@@ -1,9 +1,14 @@
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;
@@ -20,12 +25,20 @@
        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("子设备已绑定");
        }
        InterphoneHostSubPole pole = new InterphoneHostSubPole();
        pole.setHostId(hostId);
        pole.setSubId(subId);
        return save(pole);
@@ -38,10 +51,14 @@
        if (subId == null) {
            throw new BusinessException("子设备id不能为空");
        }
        InterphoneHostSubPole one = getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, subId));
        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 removeById(one);
        return remove(eq);
    }
}