| | |
| | | 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; |
| | |
| | | |
| | | import java.net.URISyntaxException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.CountDownLatch; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Component("VnnoxAPIUtil") |
| | | @AllArgsConstructor |
| | |
| | | //@Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | private CountDownLatchUtil countDownLatchUtil; |
| | | |
| | | 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) |
| | | ); |
| | | 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 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)); |
| | | // System.out.println("----------------------------------------"); |
| | | // System.out.println("----------------------------------------"); |
| | | // System.out.println("----------------------------------------"); |
| | | // System.out.println(response); |
| | | // return response; |
| | | // } |
| | | 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)); |
| | | 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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | 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()); |
| | |
| | | VnnoxSyncCurrentInfoRequest vnnoxSyncCurrentInfoRequest = new VnnoxSyncCurrentInfoRequest(); |
| | | vnnoxSyncCurrentInfoRequest.setPlayerIds(playerIds); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO), |
| | | vnnoxSyncCurrentInfoRequest.toJson(), |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SYNC_CURRENT_INFO), vnnoxSyncCurrentInfoRequest.toJson(), new CommonHeader(CommonHeader.JSON, true)); |
| | | |
| | | VnnoxSyncCurrentInfoResponse response = JSON.parseObject(result, VnnoxSyncCurrentInfoResponse.class); |
| | | |
| | |
| | | vnnoxScreenStatusRequest.setPlayerIds(playerIds); |
| | | vnnoxScreenStatusRequest.setStatus(type); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.SCREEN_STATUS), |
| | | vnnoxScreenStatusRequest.toJson(), |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SCREEN_STATUS), vnnoxScreenStatusRequest.toJson(), new CommonHeader(CommonHeader.JSON, true)); |
| | | |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | |
| | |
| | | request.setPlayerIds(playerIds); |
| | | request.setValue(vol); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.CHANGE_VOL), |
| | | request.toJson(), |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | 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(); |
| | |
| | | request.setPlayerIds(playerIds); |
| | | request.setValue(brightness); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.CHANGE_BRIGHTNESS), |
| | | request.toJson(), |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | 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(); |
| | |
| | | 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) |
| | | ); |
| | | 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 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | 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) |
| | | ); |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 同步播放 |
| | | */ |
| | | public VnnoxResult syncPlay(List<String> playerId, Integer option) { |
| | | VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | | request.setPlayerIds(playerId); |
| | | request.setOption(option); |
| | | request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.SIMU_LCAST), request.toJson(), new CommonHeader(CommonHeader.JSON, true)); |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | |
| | | return response.getData(); |
| | | } |
| | | |
| | | /** |
| | | * NTP_SYNC |
| | | */ |
| | | public VnnoxResult ntpSync(List<String> playerId, boolean enable) { |
| | | // VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | | // request.setPlayerIds(playerId); |
| | | // request.setEnable(enable); |
| | | // request.setServer("ntp1.aliyun.com"); |
| | | // request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | Map map = new HashMap(); |
| | | map.put("server", "ntp1.aliyun.com"); |
| | | map.put("enable", enable); |
| | | map.put("noticeUrl", VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | map.put("playerIds", playerId); |
| | | String s = JSON.toJSONString(map); |
| | | String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.NTP_SYNC), s, new CommonHeader(CommonHeader.JSON, true)); |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取音量,亮度 |
| | | */ |
| | | public VnnoxResultResponse asyncStatus(List<String> playerId) { |
| | | List<String> commands = new ArrayList<>(); |
| | | commands.add("volumeValue"); |
| | | commands.add("brightnessValue"); |
| | | VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | | request.setPlayerIds(playerId); |
| | | request.setCommands(commands); |
| | | request.setNoticeUrl(VnnoxConstant.STATUS_NOTIFY_URL); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader(VnnoxUrl.getUrl(VnnoxUrl.ASYNCURRENTSTATUS), request.toJson(), new CommonHeader(CommonHeader.JSON, true)); |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | System.out.println(response.toString()); |
| | | int size = response.getData().getSuccess().size(); |
| | | CountDownLatch countDownLatch = new CountDownLatch(size * 2); |
| | | countDownLatchUtil.push(response.getLogid(), countDownLatch); |
| | | try { |
| | | countDownLatch.await(20, TimeUnit.SECONDS); |
| | | countDownLatchUtil.remove(response.getLogid()); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | } |