This commit is contained in:
2024-11-28 15:10:09 +08:00
commit 901691aaea
90 changed files with 4919 additions and 0 deletions

View File

@ -0,0 +1,176 @@
//package com.ycwl.basic.task;
//
//
//import cn.hutool.core.util.StrUtil;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.tu.common.redis.RedisUtils;
//import com.tu.common.utils.ChinaMobileUtil;
//import com.tu.common.utils.DateUtils;
//import com.tu.dao.TuSpaceManageDao;
//import com.tu.dto.GetLiveSteamUrlDTO;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.core.annotation.Order;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.*;
//
//import static com.tu.common.utils.ChinaMobileUtil.getTokenBySend;
//import static com.tu.common.utils.ChinaMobileUtil.sendPost;
//
//@Slf4j
//@Component
//@EnableScheduling
//public class GetSpaceChinaMobileLiveSteamJob {
//
// @Autowired
// TuSpaceManageDao tuSpaceManageDao;
// @Autowired
// RedisUtils redisUtils;
// @Autowired
// ChinaMobileUtil chinaMobileUtil;
// @Value("${spring.profiles.active}")
// private String springProfile;
//
// //public static String token = null;
// private static Queue failMsgSubQueue = new LinkedList(); // 保存订阅失败的数据
//
// /**
// * 订阅消息
// */
// @PostConstruct
// public void msgSubscription() {
// new Thread(() -> {
// if (springProfile.equals("prod")) {
// List<GetLiveSteamUrlDTO> liveSteamUrl = tuSpaceManageDao.getLiveSteamUrl(null, 2);
// List<String> deviceIdList = new ArrayList<>();
// for (GetLiveSteamUrlDTO item : liveSteamUrl) {
// String deviceSn = item.getDeviceSn();
// if (deviceSn != null && !deviceSn.equals("")) {
// deviceIdList.add(deviceSn);
//
// if (deviceIdList.size() == 29) {
// // 30条数据为一组分开订阅
// String msg = doMsgSubscription(deviceIdList);
// if (StrUtil.isBlank(msg)) {
// // 消息订阅失败,过一会儿再试试
// List<String> failDeviceIdList = new ArrayList<>();
// Collections.copy(failDeviceIdList, deviceIdList);
// failMsgSubQueue.offer(failDeviceIdList);
// }
// deviceIdList = new ArrayList<>();
// }
//
// }
// }
// doMsgSubscription(deviceIdList);
// }
// }).start();
//
// }
//
//
// /**
// * 每小时扫描订阅失败的消息
// */
// @PostConstruct
// @Scheduled(cron = "0 0 * * * *")
// public void scanQueue() {
// if (failMsgSubQueue.size() > 0) {
// Object poll = failMsgSubQueue.poll();
// if (poll != null) {
// List<String> pollList = (List<String>) poll;
// String msg = doMsgSubscription(pollList);
// if (StrUtil.isBlank(msg)) {
// // 消息订阅失败,过一会儿再试试
// List<String> failDeviceIdList = new ArrayList<>();
// Collections.copy(failDeviceIdList, pollList);
// failMsgSubQueue.offer(failDeviceIdList);
// }
// }
// }
// }
//
//
// @PostConstruct
// @Scheduled(fixedRate = 1000 * 60 * 60 * 2)
// @Order(1)
// public void getToken() {
// if (springProfile.equals("prod")) {
// String tokenBySend = getTokenBySend();
// redisUtils.set("CHINA_MOBILE_TOKEN_KEY_NEW", tokenBySend, RedisUtils.HOUR_TOW_EXPIRE);
// }
// }
//
// @Scheduled(cron = "0 */19 * * * *")
// @PostConstruct
// @Order(2)
// public void setLiveSteam() {
// new Thread(() -> {
// if (springProfile.equals("prod")) {
// List<GetLiveSteamUrlDTO> liveSteamUrl = tuSpaceManageDao.getLiveSteamUrl(null, 2);
// for (GetLiveSteamUrlDTO item : liveSteamUrl) {
// String url = getLiveSteam(item.getDeviceSn());
// if (url != null && !url.equals("")) {
// tuSpaceManageDao.updateLiveSteamUrl(item.getId(), url);
// }
// }
// }
// }).start();
// }
//
// public String getLiveSteam(String deviceId) {
// log.info("【移动】开始获取视频流" + deviceId);
// String url_hls = "https://open.andmu.cn/v3/open/api/device/hls";
// JSONObject bodyParam = new JSONObject();
// bodyParam.put("deviceId", deviceId);
// bodyParam.put("endTime", DateUtils.addDateDays(new Date(), 2).getTime());
// log.info("【移动】bodyParam->{}", bodyParam);
// String res = sendPost(url_hls, bodyParam, chinaMobileUtil.getTempToken());
// log.info("【移动】开始获取视频流结果:-》{}" + res);
// JSONObject jsonObject = JSONObject.parseObject(res);
// String m3u8Url = null;
// if (jsonObject.get("resultCode").toString().equals("000000")) {
// String data = jsonObject.get("data").toString();
// JSONObject jsonData = JSONObject.parseObject(data);
// m3u8Url = jsonData.get("m3u8Url").toString();
// }
// // token已过期
// if (jsonObject.get("resultCode").toString().equals("11504")) {
// // 删除redis的token会重新获取
// redisUtils.delete("CHINA_MOBILE_TOKEN_KEY_NEW");
// getLiveSteam(deviceId);
// }
// return m3u8Url;
// }
//
//
// public static void main(String[] args) {
//
// //List<String> deviceIdList =new ArrayList<>(30);
// //deviceIdList.add("2");
// //deviceIdList.add("1");
// //
// //List<String> failDeviceIdList = new ArrayList<>(deviceIdList);
// //failMsgSubQueue.offer(failDeviceIdList);
// //deviceIdList = new ArrayList<>();
// //List<String> pollList = ( List<String>) failMsgSubQueue.poll();
// //for (String s : pollList) {
// // System.out.println(s);
// //}
// //System.out.println(failMsgSubQueue.poll());
// //System.out.println(failMsgSubQueue.size());
//
//
// //String s = doMsgSubscription(Arrays.asList("040312e7fc9f", "743fc2dae410"));
// //System.out.println(s);
// }
//
//
//
//}