From 4e76b9737e036c18e8a9e840dc443615ffcec348 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期四, 20 十月 2022 12:20:18 +0800
Subject: [PATCH] 大气农耕
---
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java | 179 +++++++++++++++++++++++++++++++++--------------------------
1 files changed, 99 insertions(+), 80 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java
index b01c089..e3c0de7 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java
@@ -1,11 +1,13 @@
package com.sandu.ximon.admin.utils;
+import cn.hutool.core.lang.Snowflake;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
-import com.sandu.ximon.admin.config.NginxConfigBean;
+import com.sandu.common.file.FileUploadDto;
import com.sandu.ximon.admin.config.RealtimeServerBean;
import com.sandu.ximon.admin.service.PoleLightemitService;
import com.sandu.ximon.admin.utils.request.*;
+import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.squareup.okhttp.*;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
@@ -14,6 +16,10 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
+
+/**
+ * 鐔欒灞忓箷鎺у埗
+ */
@Component
public class LightemitUtils {
@@ -24,15 +30,16 @@
PoleLightemitService poleLightemitService;
@Autowired
ApplicationContext applicationContext;
- @Autowired
- NginxConfigBean nginxConfigBean;
//body灏佽缂栫爜
private final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private OkHttpClient client = new OkHttpClient();
+ @Autowired
+ private Snowflake snowflake;
- public void init(){
+
+ public void init() {
//閲嶆柊鑾峰彇鍗曚緥
poleLightemitService = applicationContext.getBean(PoleLightemitService.class);
}
@@ -110,14 +117,14 @@
*
* @param ledCode
*/
- public void clear(String ledCode) {
+ public String clear(String ledCode) {
String postBody = new Gson().toJson(new Clear());
//璇锋眰鍦板潃
String url = realtimeServerBean.getCommand() + ledCode;
//璇锋眰
-// poleLightemitService.updateRequestBody(ledCode, "");
String result = post(url, postBody);
- LogUtils.error("娓呭睆缁撴灉:"+result);
+ LogUtils.error("娓呭睆缁撴灉:" + result);
+ return result;
}
/**
@@ -127,10 +134,9 @@
* @param username
*/
public void postHtml(String ledCode, String username) {
-
+ //html缃戦〉鍐呭
PostHtml postHtml = new PostHtml(realtimeServerBean.getUrl() + username + "_" + ledCode + ".html");
String postBody = new Gson().toJson(postHtml);
-
//璇锋眰鍦板潃
String url = realtimeServerBean.getCommand() + ledCode;
//淇濆瓨led鏁版嵁
@@ -138,66 +144,69 @@
//璇锋眰
String result = post(url, postBody);
}
- /**
- * html浼犺緭鑷砽ed灞�, 閫氳繃url鑾峰彇html
- * @param ledCode
- * @param username
- */
- public void postHtmlUseNginx(String ledCode, String username){
- PostHtml postHtml = new PostHtml(nginxConfigBean.getUrl() + username + "_" + ledCode + ".html");
- String postBody = new Gson().toJson(postHtml);
-
- //璇锋眰鍦板潃
- String url = realtimeServerBean.getCommand() + ledCode;
- //淇濆瓨led鏁版嵁
- poleLightemitService.updateRequestBody(ledCode, postBody);
- //璇锋眰
- String result = post(url,postBody);
- }
/**
* 瑙嗛浼犺緭鑷砽ed灞�
+ *
* @param screenWidth
* @param screenHeight
- * @param filename
* @param ledCode
*/
- public void postVideo(String screenWidth, String screenHeight, String filename, String ledCode) {
+ public String postFile(String screenWidth, String screenHeight, String ledCode, FileUploadDto fileUploadDto) {
+
+ String fileUrl = fileUploadDto.getFileUrl();
+ String[] split = fileUrl.split("/");
+ String id = split[split.length - 1];
+
//led寮�鍙戞澘涓嬭浇瑙嗛璇锋眰body
DownloadFileToLocal downloadFileToLocal = new DownloadFileToLocal();
- downloadFileToLocal.url = realtimeServerBean.getUrl() + filename;
- downloadFileToLocal.path += filename;
+ downloadFileToLocal.url = realtimeServerBean.getUrl() + "https://ximonsmart.oss-cn-shanghai.aliyuncs.com/" + id;
+ downloadFileToLocal.path += fileUrl;
//led寮�鍙戞澘涓嬭浇瑙嗛璇锋眰
this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(downloadFileToLocal));
//led寮�鍙戞澘瑙嗛鍒楄〃璇锋眰body
SetPlayList setPlayList = new SetPlayList();
- setPlayList.list[0] = "/data/data/com.xixun.xy.conn/files/local/abc/"+filename;
-// setPlayList.pathList[0] = "";
- try{
+ setPlayList.list[0] = fileUrl;
+ setPlayList.pathList[0] = ledCode;
+ try {
setPlayList.width = Integer.valueOf(screenWidth);
setPlayList.height = Integer.valueOf(screenHeight);
- }catch (Exception e){
- return;
+ } catch (Exception e) {
+ return "鎺ㄩ�佸け璐�";
}
String postBody = new Gson().toJson(setPlayList);
- //淇濆瓨led鏁版嵁
- poleLightemitService.updateRequestBody(ledCode, postBody);
+
//led寮�鍙戞澘瑙嗛鍒楄〃璇锋眰
- this.post(realtimeServerBean.getCommand() + ledCode, postBody);
+ String post = this.post(realtimeServerBean.getCommand() + ledCode, postBody);
+ LogUtils.error("瑙嗛涓婁紶缁撴灉:----" + post);
+ if (post.contains("does not exist")) {
+ return "鎺ㄩ�佸け璐�";
+ } else {
+ //{"_type":"success","_id":"ce8dc3ff-dc88-43b7-8f55-60abd8700f1a","timestamp":1653555160535}
+ if (post.startsWith("{") && post.endsWith("}") && post.contains("_type\":\"success")) {
+ //淇濆瓨led鏁版嵁
+ poleLightemitService.updateRequestBody(ledCode, postBody);
+ return "鎺ㄩ�佹垚鍔�";
+ } else {
+ return "鎺ㄩ�佸け璐�";
+ }
+ }
}
+
/**
* led灞忓瓧骞曡缃�
+ *
* @param subTitleSet
* @param ledCode
*/
- public void subTitleSet(SubTitleSet subTitleSet, String ledCode, Boolean isSave){
- String postBody = new Gson().toJson(subTitleSet);
- if(isSave == true){
+ public void subTitleSet(SubTitleSet subTitleSet, String ledCode, Boolean isSave) {
+ String postBody = new Gson().toJson(subTitleSet);
+ if (isSave == true) {
poleLightemitService.updateRequestBody(ledCode, postBody);
}
this.post(realtimeServerBean.getCommand() + ledCode, postBody);
@@ -209,7 +218,6 @@
* @param ledCode
*/
public void clearVideoPlay(String ledCode) {
-// poleLightemitService.updateRequestBody(ledCode, "");
this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new ClearVideoPlay()));
}
@@ -219,8 +227,20 @@
* @param ledCode
*/
public void clearPlayerTask(String ledCode) {
-// poleLightemitService.updateRequestBody(ledCode, "");
this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new ClearPlayerTask()));
+ }
+
+ /**
+ * 鍙戦�佹渶鏂扮殑鏁版嵁
+ *
+ * @param lightemitControlCode
+ */
+ public void sendLastCommand(String lightemitControlCode) {
+ PoleLightemitEntity poleLightemitEntity = poleLightemitService.getLedByLightControlCode(lightemitControlCode);
+ if (poleLightemitEntity == null || StringUtils.isBlank(poleLightemitEntity.getRequestBody())) {
+ return;
+ }
+ this.post(realtimeServerBean.getCommand() + lightemitControlCode, poleLightemitEntity.getRequestBody());
}
/**
@@ -235,7 +255,6 @@
return "";
}
String re;
-
try {
re = JSONObject.parseObject(result).get("result").toString();
} catch (Exception e) {
@@ -257,8 +276,8 @@
* @return
*/
public String getIsScreenOpen(String ledCode) {
+ //鍙戦�佸睆骞曟槸鍚﹀紑鍚殑鎸囦护
String result = this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new IsScreenOpen()));
- //鑾峰彇base64鍥剧墖鏁版嵁
if (StringUtils.isNotBlank(result)) {
String re;
try {
@@ -272,35 +291,20 @@
}
}
- /*
- 鍚姩xwalk
+
+ public boolean getLedOnLine(String ledCode) {
+ //閫氳繃灞忓箷鏄惁寮�鍚寚浠よ幏鍙栧睆骞曟槸鍚﹀湪绾�
+ String result = this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new IsScreenOpen()));
+ result = result.trim();
+ return result.startsWith("{") && result.endsWith("}");
+ }
+
+
+ /**
+ * 鎺у埗灞忓箷寮�鍏�
*/
- /*public void startActivity(String ledCode){
- String result = this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new StartActivity()));
- }*/
-
- /*
- 浣跨敤xwalk鍔犺浇缃戦〉
- */
- /*public void callXwalkFn(String ledCode,String username){
-
- CallXwalkFn callXwalkFn = new CallXwalkFn();
-
- callXwalkFn.setArgUrl(realtimeServerBean.getUrl() + username + "_" + ledCode + ".html");
- String postBody = new Gson().toJson(callXwalkFn);
-
- //璇锋眰鍦板潃
- String url = realtimeServerBean.getCommand() + ledCode;
- //璇锋眰
- String result = post(url,postBody);
- }*/
-
- /*
- 鎺у埗灞忓箷寮�鍏�
- */
public String setScreenOpen(String ledCode, Boolean bool) {
String result = this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new setScreenOpen(bool)));
- //鑾峰彇base64鍥剧墖鏁版嵁
if (StringUtils.isNotBlank(result)) {
String re = "";
try {
@@ -323,8 +327,8 @@
// this.post(realtimeServerBean.getCommand() + lightemitControlCode, poleLightemitEntity.getRequestBody());
// }
- /*
- 璁剧疆led闊抽噺
+ /**
+ * 璁剧疆led闊抽噺
*/
public void setVoiume(String ledCode, Integer volume) {
@@ -334,24 +338,39 @@
//璇锋眰
String result = post(realtimeServerBean.getCommand() + ledCode, postBody);
- LogUtils.error("璁剧疆缁撴灉:-------------------"+result);
+ LogUtils.error("璁剧疆缁撴灉:-------------------" + result);
}
-// 鑾峰彇led闊抽噺
- public String getVoiume(String ledCode){
+
+ /**
+ * 璁剧疆led浜害
+ */
+ public void setBrightness(String ledCode, Integer brightness) {
+
+ SetBrightness setBrightness = new SetBrightness();
+ setBrightness.arg1 = brightness;
+ String postBody = new Gson().toJson(setBrightness);
+
+ //璇锋眰
+ String result = post(realtimeServerBean.getCommand() + ledCode, postBody);
+ LogUtils.error("璁剧疆缁撴灉:-------------------" + result);
+ }
+
+ // 鑾峰彇led闊抽噺
+ public String getVoiume(String ledCode) {
GetVolume getVolume = new GetVolume();
String postBody = new Gson().toJson(getVolume);
//璇锋眰
- String result = post(realtimeServerBean.getCommand() + ledCode,postBody);
+ String result = post(realtimeServerBean.getCommand() + ledCode, postBody);
//璇锋眰
- if(StringUtils.isNotBlank(result)){
- try{
+ if (StringUtils.isNotBlank(result)) {
+ try {
return JSONObject.parseObject(result).get("result").toString();
- }catch (Exception e){
+ } catch (Exception e) {
return "0";
}
- }else{
+ } else {
return "0";
}
}
--
Gitblit v1.9.3