2021与蓝度共同重构项目,服务端
liuhaonan
2021-12-24 4965d8affe8ab2f3302bda6c62f45dc5fd455f93
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
210
211
212
213
214
215
216
217
218
package com.sandu.ximon.admin.utils;
 
import com.alibaba.fastjson.JSON;
import com.sandu.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.config.VnnoxUrl;
import com.sandu.ximon.admin.utils.request.*;
import com.sandu.ximon.admin.utils.response.*;
import com.sandu.ximon.dao.domain.LedPlayerEntity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
@Component("VnnoxAPIUtil")
@AllArgsConstructor
public class VnnoxAPIUtil {
 
    //@Autowired
    private RedisUtils redisUtils;
 
    public static VnnoxAPIUtil getBean() {
        return (VnnoxAPIUtil) SpringContextUtil.getBean("VnnoxAPIUtil");
    }
 
    /**
     * 获取token
     */
    public void getToken () {
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.GET_TOKEN),
                new VnnoxGetTokenRequest().toJson(),
                new CommonHeader(CommonHeader.FORM, false)
        );
 
        CommonResponse commonResponse = JSON.parseObject(result,CommonResponse.class);
        VnnoxGetTokenResponse response = new VnnoxGetTokenResponse().parse(commonResponse);
        //  将token保存到redis缓存中
        redisUtils.set(VnnoxConstant.REDIS_TOKEN_NAME,response.getToken(),(long)(response.getExpire()-30));
    }
 
 
    /**
     * 获取播放器列表
     *
     * @param count 每次读取数量,默认20,取值范围:1~100
     * @param start 从第几条记录开始读取,默认0
     * @return
     */
    public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start) {
 
        String result = VnnoxRequestUtil.GetWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.GET_PLAYER_LIST),
                new VnnoxGetPlayerListRequest(count, start).toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
        VnnoxPlayerListResponse response =
                new VnnoxPlayerListResponse().parse(JSON.parseObject(result, CommonResponse.class));
        return response;
    }
 
    /**
     * 获取当前屏幕信息-POST-JSON
     *
     * @param list
     * @return
     */
    public List<LedPlayerEntity> syncCurrentInfo(List<LedPlayerEntity> list) {
        List<String> playerIds = new ArrayList<>();
 
        for (LedPlayerEntity playerEntity : list) {
            playerIds.add(playerEntity.getPlayerId());
        }
 
        VnnoxSyncCurrentInfoRequest vnnoxSyncCurrentInfoRequest = new VnnoxSyncCurrentInfoRequest();
        vnnoxSyncCurrentInfoRequest.setPlayerIds(playerIds);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO),
                vnnoxSyncCurrentInfoRequest.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
 
        VnnoxSyncCurrentInfoResponse response = JSON.parseObject(result, VnnoxSyncCurrentInfoResponse.class);
 
        for (LedPlayerEntity playerEntity : list) {
            for (VnnoxPlayerInfoResponse res : response.getData()) {
                if (res.getPlayerId().equals(playerEntity.getPlayerId())) {
                    playerEntity.setPlayerType(res.getPlayerType());
                    playerEntity.setOnlineStatus(res.getOnlineStatus());
                    playerEntity.setVersion(res.getVersion());
                    playerEntity.setOsVersion(res.getOsVersion());
                    playerEntity.setLastOnlineTime(res.getLastOnlineTime());
                    playerEntity.setIp(res.getIp());
                    playerEntity.setWidth(res.getWidth());
                    playerEntity.setHeight(res.getHeight());
                    break;
                }
            }
        }
        return list;
    }
 
    /**
     * 调整屏幕状态(亮屏/黑屏)-POST-JSON
     *
     * @param playerIds
     * @param type
     * @return
     */
    public VnnoxResult screenStatus(List<String> playerIds, VnnoxScreenStatusType type) {
        VnnoxScreenStatusRequest vnnoxScreenStatusRequest = new VnnoxScreenStatusRequest();
        vnnoxScreenStatusRequest.setPlayerIds(playerIds);
        vnnoxScreenStatusRequest.setStatus(type);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.SCREEN_STATUS),
                vnnoxScreenStatusRequest.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
 
        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
        return response.getData();
    }
 
 
    /**
     * 音量调整-POST-JSON
     *
     * @param playerIds
     * @param vol
     * @return
     */
    public VnnoxResult volChange(List<String> playerIds, Integer vol) {
 
        VnnoxBaseRequest request = new VnnoxBaseRequest();
        request.setPlayerIds(playerIds);
        request.setValue(vol);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.CHANGE_VOL),
                request.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
        return response.getData();
 
    }
 
    /**
     * 屏幕亮度调整
     *
     * @param playerIds
     * @param brightness
     * @return
     */
    public VnnoxResult brightnessChange(List<String> playerIds, Integer brightness) {
        VnnoxBaseRequest request = new VnnoxBaseRequest();
        request.setPlayerIds(playerIds);
        request.setValue(brightness);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.CHANGE_BRIGHTNESS),
                request.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
        return response.getData();
    }
 
    /**
     * 屏幕截图
     *
     * @param playerId
     * @return
     */
    public VnnoxResult screenShot(String playerId) {
        List<String> players = new ArrayList<>();
        players.add(playerId);
        VnnoxBaseRequest request = new VnnoxBaseRequest();
        request.setPlayerIds(players);
        request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.SCREEN_SHOT),
                request.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
        return response.getData();
    }
 
    /**
     * 设备重启
     *
     * @param playerIdList
     * @return
     */
    public VnnoxResult reboot(List<String> playerIdList) {
        VnnoxBaseRequest request = new VnnoxBaseRequest();
        request.setPlayerIds(playerIdList);
        request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL);
 
        String result = VnnoxRequestUtil.PostWithHeader(
                VnnoxUrl.getUrl(VnnoxUrl.REBOOT),
                request.toJson(),
                new CommonHeader(CommonHeader.JSON, true)
        );
        VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class);
 
        return response.getData();
    }
 
}