| | |
| | | |
| | | 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; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 熙讯屏幕控制 |
| | | */ |
| | | |
| | | @Component |
| | | public class LightemitUtils { |
| | |
| | | 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(){ |
| | | public void init() { |
| | | //重新获取单例 |
| | | poleLightemitService = applicationContext.getBean(PoleLightemitService.class); |
| | | } |
| | |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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数据 |
| | |
| | | //请求 |
| | | 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 |
| | |
| | | |
| | | //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); |
| | |
| | | |
| | | /** |
| | | * 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); |
| | |
| | | * @param ledCode |
| | | */ |
| | | public void clearVideoPlay(String ledCode) { |
| | | // poleLightemitService.updateRequestBody(ledCode, ""); |
| | | this.post(realtimeServerBean.getCommand() + ledCode, new Gson().toJson(new ClearVideoPlay())); |
| | | } |
| | | |
| | |
| | | * @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()); |
| | | } |
| | | |
| | | /** |
| | |
| | | return ""; |
| | | } |
| | | String re; |
| | | |
| | | try { |
| | | re = JSONObject.parseObject(result).get("result").toString(); |
| | | } catch (Exception e) { |
| | |
| | | * @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 { |
| | |
| | | } |
| | | } |
| | | |
| | | /* |
| | | 启动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 { |
| | |
| | | // this.post(realtimeServerBean.getCommand() + lightemitControlCode, poleLightemitEntity.getRequestBody()); |
| | | // } |
| | | |
| | | /* |
| | | 设置led音量 |
| | | /** |
| | | * 设置led音量 |
| | | */ |
| | | public void setVoiume(String ledCode, Integer volume) { |
| | | |
| | |
| | | |
| | | //请求 |
| | | 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"; |
| | | } |
| | | } |