2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-27 f04802851ffecf0e85b30f4ea7b73da5fbdbf188
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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<InterphoneHostSubPoleMapper, InterphoneHostSubPole> {
    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);
    }
}