2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-07-22 77edfb324184d304ae7763aae3ab609f2b495da4
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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.security.SecurityUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.admin.utils.VnnoxAPIUtil;
import com.sandu.ximon.admin.vo.EquipmentInfomation;
import com.sandu.ximon.dao.domain.LedPlayerEntity;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LedPlayerEntityMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @Author liuhaonan
 * @Date 2021/12/22 15:27
 * @Version 1.0
 * 诺瓦设备
 */
@Service
@AllArgsConstructor
public class LedPlayerEntityService extends BaseServiceImpl<LedPlayerEntityMapper, LedPlayerEntity> {
    private final LedPlayerEntityMapper ledPlayerEntityMapper;
    private VnnoxAPIUtil vnnoxAPIUtil;
 
    public LedPlayerEntity getBySn(String sn) {
        return getOne(Wrappers.lambdaQuery(LedPlayerEntity.class).eq(LedPlayerEntity::getSn, sn));
    }
 
    public LedPlayerEntity getByPlayerId(String playerId) {
        return getOne(Wrappers.lambdaQuery(LedPlayerEntity.class).eq(LedPlayerEntity::getPlayerId, playerId));
    }
 
    /**
     * 诺瓦设备新增
     *
     * @param ledPlayerEntity
     * @return
     */
    public boolean saveLed(LedPlayerEntity ledPlayerEntity) {
        boolean b = ledPlayerEntityMapper.saveLed(ledPlayerEntity);
        /**
         * 诺瓦设备新增 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(ledPlayerEntity.getSn());
        String content = "{ 设备id:" + ledPlayerEntity.getId() + "设备code:" + ledPlayerEntity.getSn()
                + "诺瓦playId:" + ledPlayerEntity.getPlayerId()
                + "诺瓦设备名称:" + ledPlayerEntity.getName() +
                "}";
 
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦设备新增", content);
        /**
         * 诺瓦设备新增 日志记录结束
         */
        return b;
    }
 
 
    /**
     * 诺瓦硬件设备
     */
    public LedPlayerEntity getBySnAndPlayerSn(String sn) {
        LedPlayerEntity one = getOne(Wrappers.lambdaQuery(LedPlayerEntity.class).eq(LedPlayerEntity::getSn, sn));
        if (one == null) {
            throw new BusinessException("诺瓦设备不存在");
        }
        List list = new ArrayList();
        list.add(one);
        List<LedPlayerEntity> led = vnnoxAPIUtil.syncCurrentInfo(list);
        Map<String, String> screenShotUrl = SpringContextHolder.getBean(VnnoxService.class).getScreenShotUrl(one.getId().intValue());
        if (screenShotUrl.get("code").equals("200")) {
            one.setScreenShotUrl(screenShotUrl.get("url"));
        } else {
            one.setScreenShotUrl("缩略图获取失败");
        }
        return one;
    }
 
    /**
     * 首页灯杆绑定信息
     */
    public EquipmentInfomation getBySnAndPlayerSnInfo(String sn) {
        EquipmentInfomation equipmentInfo = new EquipmentInfomation();
        equipmentInfo.setEquipmentType("诺瓦LED");
        if (sn == null || sn.trim().length() == 0) {
            return equipmentInfo;
        }
 
        LedPlayerEntity one = getOne(Wrappers.lambdaQuery(LedPlayerEntity.class).eq(LedPlayerEntity::getSn, sn));
        if (one == null) {
            return equipmentInfo;
        }
        List<LedPlayerEntity> list = new ArrayList<>();
        list.add(one);
        List<LedPlayerEntity> ledPlayerEntities = vnnoxAPIUtil.syncCurrentInfo(list);
        Integer onlineStatus = ledPlayerEntities.get(0).getOnlineStatus();
        if (one != null) {
            equipmentInfo.setEquipmentMac(one.getSn());
            equipmentInfo.setEquipmentName(one.getName());
            if (onlineStatus == 0) {
                equipmentInfo.setEquipmentState("在线");
            } else {
                equipmentInfo.setEquipmentState("离线");
            }
        }
 
        return equipmentInfo;
    }
 
 
    /**
     * 诺瓦列表
     *
     * @param baseConditionVO
     * @param keyword
     * @param order
     * @param seq
     * @return
     */
    public List<LedPlayerEntity> ledPlayerEntityList(BaseConditionVO baseConditionVO, String keyword, Integer order, Integer seq) {
        //排序字段
        String orderByResult = OrderByEnums.VNNOX_ID.getCode();
        //正序、倒叙
        String orderBySeq = OrderByEnums.ASC.getCode();
        if (order != null) {
            switch (order) {
                case 1:
                    orderByResult = OrderByEnums.VNNOX_POLE_NAME.getCode();
                    break;
                case 2:
                    orderByResult = OrderByEnums.VNNOX_CREATE_TIMESTAMP.getCode();
                    break;
                default:
            }
        }
        if (seq != null) {
            switch (seq) {
                case 1:
                    orderBySeq = OrderByEnums.ASC.getCode();
                    break;
                case 2:
                    orderBySeq = OrderByEnums.DESC.getCode();
                    break;
                default:
                    break;
            }
        }
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
 
 
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
        }
        List<LedPlayerEntity> list;
        //超管
        if (SecurityUtils.getClientId() == null) {
            list = ledPlayerEntityMapper.ledPlayerEntityList(keyword, null);
        } else {
            list = ledPlayerEntityMapper.ledPlayerEntityList(keyword, SecurityUtils.getUserId());
        }
        return SpringContextHolder.getBean(VnnoxService.class).setCacheInfo(vnnoxAPIUtil.syncCurrentInfo(list));
    }
 
    /**
     * 诺瓦列表(用于首页数据统计)
     *
     * @return
     */
    public List<LedPlayerEntity> ledPlayerEntityListOnHome() {
        List<LedPlayerEntity> list;
        //超管
        if (SecurityUtils.getClientId() == null) {
            list = ledPlayerEntityMapper.ledPlayerEntityList(null, null);
        } else {
            list = ledPlayerEntityMapper.ledPlayerEntityList(null, SecurityUtils.getUserId());
        }
        return list == null ? new ArrayList<>() : list;
    }
 
    /**
     * 诺瓦列表(用于绑定)
     *
     * @param keyword
     * @return
     */
    public List<LedPlayerEntity> ledPlayerEntityListOnBinding(String keyword) {
 
        List<LedPlayerEntity> list;
        //超管
        if (SecurityUtils.getClientId() == null) {
            list = ledPlayerEntityMapper.ledPlayerEntityListOnBinding(keyword, null);
        } else {
            list = ledPlayerEntityMapper.ledPlayerEntityListOnBinding(keyword, SecurityUtils.getUserId());
        }
        return SpringContextHolder.getBean(VnnoxService.class).setCacheInfo(vnnoxAPIUtil.syncCurrentInfo(list));
    }
 
}