2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-31 0e96c4a74c768405cdff478d26a294b1591526ec
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.InterphoneSubParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.dao.bo.InterphoneSubBo;
import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
import com.sandu.ximon.dao.domain.InterphoneSub;
import com.sandu.ximon.dao.enums.PoleBindingEnums;
import com.sandu.ximon.dao.mapper.InterphoneSubMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
@AllArgsConstructor
public class InterphoneSubService extends BaseServiceImpl<InterphoneSubMapper, InterphoneSub> {
 
    private final InterphoneSubMapper interphoneSubMapper;
    private final InterphoneHostSubService interphoneHostSubService;
 
    /**
     * 新增子设备
     */
    public boolean addSub(InterphoneSubParam interphoneSubParam) {
        InterphoneSub interphoneSub = new InterphoneSub();
        BeanUtils.copyProperties(interphoneSubParam, interphoneSub);
        boolean save = save(interphoneSub);
        /**
         * 添加一键求助子设备 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(interphoneSub.getSubMac());
        String content = "{ 设备id:" + interphoneSub.getSubId() + "设备code:" + interphoneSub.getSubMac() +
                "}";
 
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "添加一键求助子设备", content);
        /**
         * 添加一键求助子设备 日志记录结束
         */
        return save;
    }
 
    /**
     * 修改子设备
     */
    public boolean updateSub(Integer id, InterphoneSubParam interphoneSubParam) {
        InterphoneSub byId = getById(id);
        if (byId == null) {
            return false;
        }
        boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSubMac(), PoleBindingEnums.FOR_HELP);
        if (!belong) {
            throw new BusinessException("该设备不属于您,不能修改设备信息");
        }
        InterphoneSub interphoneSub = new InterphoneSub();
        BeanUtils.copyProperties(interphoneSubParam, interphoneSub);
        interphoneSub.setSubId(id);
 
        /**
         * 编辑一键求助子设备 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(interphoneSub.getSubMac());
        String content = "{ 设备id:" + interphoneSub.getSubId() + "设备code:" + interphoneSub.getSubMac() +
                "}";
 
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "编辑一键求助子设备", content);
        /**
         * 编辑一键求助子设备 日志记录结束
         */
 
        return updateById(interphoneSub);
    }
 
    /**
     * 删除子设备
     */
    public boolean deleteSub(Integer id) {
        InterphoneSub byId = getById(id);
        InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getSubId, id));
        if (one != null) {
            throw new BusinessException("该子设备存在绑定关系,不能删除");
        }
        if (byId == null) {
            return false;
        }
 
 
        /**
         * 删除一键求助子设备 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(byId.getSubMac());
        String content = "{ 设备id:" + byId.getSubId() + "设备code:" + byId.getSubMac() +
                "}";
 
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除一键求助子设备", content);
        /**
         * 删除一键求助子设备 日志记录结束
         */
 
        return removeById(id);
    }
 
    /**
     * 查询子设备
     */
    public InterphoneSub getSub(Integer id) {
        InterphoneSub byId = getById(id);
        if (byId == null) {
            return null;
        }
        return byId;
    }
 
    /**
     * 查询主机列表
     */
    public List<InterphoneSubBo> getInterphoneSubList(BaseConditionVO baseConditionVO, String keyword) {
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        }
        List<InterphoneSubBo> list;
        if (SecurityUtils.getClientId() == null) {
            list = interphoneSubMapper.getInterphoneSubList(keyword, null);
        } else {
            list = interphoneSubMapper.getInterphoneSubList(keyword, SecurityUtils.getUserId());
        }
        return list;
    }
}