2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-06 93c4a7420a87b7d7e2bbeeef8e6ccff0a8909a9d
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java
@@ -2,10 +2,10 @@
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.sandu.ximon.admin.config.NginxConfigBean;
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 +14,10 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
 * 熙讯屏幕控制
 */
@Component
public class LightemitUtils {
@@ -24,18 +28,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();
//    public void init(){
//        //重新获取单例
//        poleLightemitService = applicationContext.getBean(PoleLightemitService.class);
//    }
    public void init() {
        //重新获取单例
        poleLightemitService = applicationContext.getBean(PoleLightemitService.class);
    }
    /**
     * post请求封装方法
@@ -117,6 +119,7 @@
        //请求
//        poleLightemitService.updateRequestBody(ledCode, "");
        String result = post(url, postBody);
        LogUtils.error("清屏结果:" + result);
    }
    /**
@@ -137,26 +140,11 @@
        //请求
        String result = post(url, postBody);
    }
    /**
     * html传输至led屏, 通过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);
    }
    /**
     * 视频传输至led屏
     *
     * @param screenWidth
     * @param screenHeight
     * @param filename
@@ -174,12 +162,12 @@
        //led开发板视频列表请求body
        SetPlayList setPlayList = new SetPlayList();
        setPlayList.list[0] = "/data/data/com.xixun.xy.conn/files/local/abc/"+filename;
        setPlayList.list[0] = "/data/data/com.xixun.xy.conn/files/local/abc/" + filename;
//        setPlayList.pathList[0] = "";
        try{
        try {
            setPlayList.width = Integer.valueOf(screenWidth);
            setPlayList.height = Integer.valueOf(screenHeight);
        }catch (Exception e){
        } catch (Exception e) {
            return;
        }
        String postBody = new Gson().toJson(setPlayList);
@@ -191,12 +179,13 @@
    /**
     * 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);
@@ -220,6 +209,19 @@
    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());
    }
    /**
@@ -333,29 +335,42 @@
        //请求
        String result = post(realtimeServerBean.getCommand() + ledCode, postBody);
        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";
        }
    }
*/
    /**
     * 查询定时