2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-10 a3acc88a203d505957cd57ce2f508a428d36306b
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.InterphoneHostParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.InterphoneHostBo;
import com.sandu.ximon.dao.domain.InterphoneHost;
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
import com.sandu.ximon.dao.mapper.InterphoneHostMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
@AllArgsConstructor
public class InterphoneHostService extends BaseServiceImpl<InterphoneHostMapper, InterphoneHost> {
 
    private final InterphoneHostMapper interphoneHostMapper;
 
    private final InterphoneHostSubService interphoneHostSubService;
 
 
    /**
     * 添加主机
     */
    public boolean addHost(InterphoneHostParam interphoneHostParam) {
        InterphoneHost interphoneHost = new InterphoneHost();
        BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
        return save(interphoneHost);
    }
 
    /**
     * 修改主机
     */
    public boolean updateHost(Integer id, InterphoneHostParam interphoneHostParam) {
        InterphoneHost byId = getById(id);
        if (byId == null) {
            return false;
        }
        InterphoneHost interphoneHost = new InterphoneHost();
        interphoneHost.setHostId(id);
        BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
        return updateById(interphoneHost);
    }
 
    /**
     * 删除主机
     *
     * @param id
     * @return
     */
    public boolean deleteHost(Integer id) {
        InterphoneHost byId = getById(id);
 
        InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getHostId, id));
        if(one!=null){
            throw new RuntimeException("该主机存在绑定关系,不能删除");
        }
        if (byId == null) {
            return false;
        }
        return removeById(id);
    }
 
    /**
     * 查询主机
     *
     * @param id
     * @return
     */
    public InterphoneHost getHost(Integer id) {
        InterphoneHost byId = getById(id);
        if (byId == null) {
            return null;
        }
        return byId;
    }
 
    /**
     * 查询主机列表
     */
    public List<InterphoneHostBo> getInterphoneHostList(String keyword) {
        List<InterphoneHostBo> list;
        if (SecurityUtils.getClientId() == null) {
            list = interphoneHostMapper.getInterphoneHostList(keyword, null);
        } else {
            list = interphoneHostMapper.getInterphoneHostList(keyword, SecurityUtils.getUserId());
        }
        return list;
    }
}