| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.config.VnnoxConstant; |
| | | import com.sandu.ximon.admin.config.VnnoxUrl; |
| | | import com.sandu.ximon.admin.service.LedPlayerEntityService; |
| | | import com.sandu.ximon.admin.utils.request.*; |
| | | import com.sandu.ximon.admin.utils.response.*; |
| | | import com.sandu.ximon.dao.domain.LedPlayerEntity; |
| | |
| | | /** |
| | | * 获取token |
| | | */ |
| | | public void getToken () { |
| | | 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); |
| | | 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)); |
| | | 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 name) throws URISyntaxException { |
| | | public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start, String name) throws URISyntaxException { |
| | | |
| | | List<NameValuePair> urlParameters = new ArrayList<>(); |
| | | urlParameters.add(new BasicNameValuePair("count",count.toString())); |
| | | urlParameters.add(new BasicNameValuePair("start",start.toString())); |
| | | urlParameters.add(new BasicNameValuePair("name",name)); |
| | | urlParameters.add(new BasicNameValuePair("count", count.toString())); |
| | | urlParameters.add(new BasicNameValuePair("start", start.toString())); |
| | | urlParameters.add(new BasicNameValuePair("name", name)); |
| | | |
| | | String result = VnnoxRequestUtil.GetWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.GET_PLAYER_LIST), |
| | | urlParameters, |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | return new VnnoxPlayerListResponse().parse(JSON.parseObject(result,CommonResponse.class)); |
| | | return new VnnoxPlayerListResponse().parse(JSON.parseObject(result, CommonResponse.class)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public List<LedPlayerEntity> syncCurrentInfo(List<LedPlayerEntity> list) { |
| | | List<String> playerIds = new ArrayList<>(); |
| | | if (list.isEmpty()) { |
| | | return list; |
| | | } |
| | | |
| | | for (LedPlayerEntity playerEntity : list) { |
| | | playerIds.add(playerEntity.getPlayerId()); |
| | |
| | | return response.getData(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量屏幕截图 |
| | | * |
| | | * @param players |
| | | * @return |
| | | */ |
| | | public VnnoxResult screenShot(List<String> players) { |
| | | 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) |
| | | ); |
| | | |
| | | if (result.startsWith("{") && result.endsWith("}")) { |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | if (response.getStatus() == 0) { |
| | | return response.getData(); |
| | | } else { |
| | | System.out.println(response.getErrmsg()); |
| | | VnnoxResult vnnoxResult = new VnnoxResult(); |
| | | vnnoxResult.getFail().addAll(players); |
| | | return vnnoxResult; |
| | | } |
| | | } else { |
| | | System.out.println("数据解析异常!"); |
| | | VnnoxResult vnnoxResult = new VnnoxResult(); |
| | | vnnoxResult.getFail().addAll(players); |
| | | return vnnoxResult; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设备重启 |
| | | * |
| | |
| | | |
| | | /** |
| | | * 同步播放 |
| | | * |
| | | */ |
| | | public VnnoxResult syncPlay(List<String> playerId, Integer option) { |
| | | VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | |
| | | return response.getData(); |
| | | } |
| | | |
| | | |
| | | public List<LedPlayerEntity> saveCurrentInfo(List<LedPlayerEntity> list) { |
| | | List<String> playerIds = new ArrayList<>(); |
| | | if (list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | 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.setResolution(res.getWidth() + " * " + res.getHeight()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | } |