2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-06 93c4a7420a87b7d7e2bbeeef8e6ccff0a8909a9d
Changes
已修改5个文件
已删除1个文件
296 ■■■■■ 文件已修改
sandu-common/pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/config/NginxConfigBean.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/config/ServerConfig.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleLightemitService.java 209 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/resources/application.yml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sandu-common/pom.xml
@@ -126,5 +126,9 @@
            <artifactId>cos_api</artifactId>
            <version>5.6.55</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
        </dependency>
    </dependencies>
</project>
ximon-admin/src/main/java/com/sandu/ximon/admin/config/NginxConfigBean.java
ÎļþÒÑɾ³ý
ximon-admin/src/main/java/com/sandu/ximon/admin/config/ServerConfig.java
@@ -1,53 +1,20 @@
package com.sandu.ximon.admin.config;
import com.sandu.ximon.admin.utils.LogUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class ServerConfig {
    @Value("${server-conf.ip}")
    public String SIP;
    @Value("${nginx.port}")
    public String nginxPort;
    @Value("${nginx.cameraSaveUrl}")
    public String saveUrl;
//    @Value("${broadcast.file-save-url}")
//    private String fileSaveUrl;
    private static String ServerIP;
    private static String NginxPort;
    private static String CameraSaveUrl;
    private static String BroadcastFileSaveUrl;
    private static boolean O2OServer;
    public static String getNginxCameraSaveUrl() {
        return CameraSaveUrl;
    }
    @PostConstruct
    private void loadIP(){
        ServerIP = SIP;
        NginxPort = nginxPort;
        CameraSaveUrl = saveUrl;
       // BroadcastFileSaveUrl = fileSaveUrl;
        LogUtils.print("Server IP ï¼š" +SIP);
        LogUtils.print("NignX Port ï¼š" +nginxPort);
        LogUtils.print("Camera Save Url ï¼š" +CameraSaveUrl);
        LogUtils.print("Broadcast File Save Url ï¼š" +BroadcastFileSaveUrl);
    }
    public static String getServerIP(){
    public static String getServerIP() {
        return ServerIP;
    }
    public static String getNignxPort(){
        return NginxPort;
    }
    public static String getBroadcastFileSaveUrl(){
        return BroadcastFileSaveUrl;
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleLightemitService.java
@@ -1,25 +1,18 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.google.gson.Gson;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.config.NginxConfigBean;
import com.sandu.ximon.admin.config.RealtimeServerBean;
import com.sandu.ximon.admin.entity.*;
import com.sandu.ximon.admin.param.PoleBindingParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.Constant;
import com.sandu.ximon.admin.utils.FileUtil;
import com.sandu.ximon.admin.utils.HtmlTemplateUtils;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.admin.utils.request.SubTitleSet;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.mapper.PoleLightemitEntityMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
@@ -49,8 +42,6 @@
    private String port;
    @Autowired
    ApplicationContext applicationContext;
    @Autowired
    NginxConfigBean nginxConfigBean;
    @Autowired
    PoleLightemitEntityMapper poleLightemitDao;
@@ -247,40 +238,6 @@
    }
    /**
     * LED上传单行字幕
     */
    @Async("taskExecutor")
    public Boolean subTitleSet(SubTitleSetEntity subTitleSetEntity, String path, String userName) {
        if (subTitleSetEntity == null) {
            return false;
        }
        if (subTitleSetEntity.getDirection().equals(Constant.LEFT) || subTitleSetEntity.getDirection().equals(Constant.RIGHT)) {
            //字幕横向滚动
            this.BuildHorizonSingSubTitleText(subTitleSetEntity);
        } else if (subTitleSetEntity.getDirection().equals(Constant.UP) || subTitleSetEntity.getDirection().equals(Constant.DOWN)) {
            //字幕纵向滚动
            try {
                this.BuildVerticalSingSubTitleText(subTitleSetEntity, path, userName);
            } catch (IOException e) {
                return false;
            }
        }
        return true;
    }
    /**
     * LED上传多行字幕
     */
    @Async("taskExecutor")
    public Boolean subMultiTitleSet(SubTitleSetEntity subTitleSetEntity, String path, String userName) {
        try {
            this.BuildVerticalMultiSubTitleText(subTitleSetEntity, path, userName);
            return true;
        } catch (IOException e) {
            return false;
        }
    }
    @Async("taskExecutor")
    public void videoXixunPlayer(String lightemitControlCode, String ip, String filename, Long filesize, Integer videoTime) {
@@ -385,7 +342,7 @@
    }
    /**
     * æ ¹æ®led屏编码设置音量
     * æ ¹æ®led屏编码设置亮度
     *
     * @param lightemitControlCode
     * @param brightness
@@ -395,168 +352,4 @@
        lightemitUtils.setBrightness(lightemitControlCode, brightness);
    }
    /**
     * ä¸Šä¼ æ°´å¹³æ»šåŠ¨å•è¡Œå­—å¹•
     *
     * @param subTitleSetEntity
     */
    private void BuildHorizonSingSubTitleText(SubTitleSetEntity subTitleSetEntity) {
        //拼装LED屏幕设置请求body
        SubTitleSet subTitleSet = new SubTitleSet();
        subTitleSet.num = subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : subTitleSet.num;
        subTitleSet.interval = subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : subTitleSet.interval;
        subTitleSet.step = subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : subTitleSet.step;
        subTitleSet.direction = subTitleSetEntity.getDirection() != null ? subTitleSetEntity.getDirection() : subTitleSet.direction;
        subTitleSet.align = subTitleSetEntity.getAlign() != null ? subTitleSetEntity.getAlign() : subTitleSet.align;
        //拼接html èƒŒæ™¯é»˜è®¤æ˜¾è‰²ä¸ºç™½è‰²
        subTitleSet.html = "<head><style type=\"text/css\">body{background-color:" +
                (subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000") +
                "}</style></head><i style=\"color:" +
                (subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff")
                + "; font-size: " +
                (subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1")
                + "em\">" + subTitleSetEntity.getContent() + "</i>";
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                //清屏操作
                lightemitUtils.clear(poleLightemitEntity.getLightemitControlCode());
                //清除播放列表
                lightemitUtils.clearVideoPlay(poleLightemitEntity.getLightemitControlCode());
                //清除节目列表
                lightemitUtils.clearPlayerTask(poleLightemitEntity.getLightemitControlCode());
                //发送字幕设置请求
                lightemitUtils.subTitleSet(subTitleSet, poleLightemitEntity.getLightemitControlCode(), true);
            }
        }
    }
    /**
     * ä¸Šä¼ åž‚直滚动单行字幕
     *
     * @param subTitleSetEntity
     * @param path
     * @param userName
     * @throws IOException
     */
    private void BuildVerticalSingSubTitleText(SubTitleSetEntity subTitleSetEntity, String path, String userName) throws IOException {
        //html地址
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                String lightemitControlCode = poleLightemitEntity.getLightemitControlCode();
                //获取屏幕宽
                Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
                Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
                String filenameTemp = path + userName + "_" + lightemitControlCode + ".html";
                File htmlFile = new File(filenameTemp);
                if (!htmlFile.exists() || htmlFile.delete()) {
                    htmlFile.createNewFile();
                }
                //若向下滚动,文字顺序相反
                if (Constant.DOWN.equals(subTitleSetEntity.getDirection())) {
                    subTitleSetEntity.setContent(StringUtils.reverse(subTitleSetEntity.getContent()));
                }
                Map<String, Object> params = new HashMap<>();
                params.put("direction", subTitleSetEntity.getDirection());
                params.put("screenWidth", screenWidth);
                params.put("screenHeight", screenHeight);
                params.put("fontSize", subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1");
                params.put("align", subTitleSetEntity.getAlign());
                params.put("fontColor", subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff");
                params.put("backgroundColor", subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000");
                params.put("interval", subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : 50);
                params.put("step", subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : 1);
                params.put("num", subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : -1);
                params.put("contentArray", subTitleSetEntity.getContent().toCharArray());
                String body = new HtmlTemplateUtils().renderPath("classpath:templates/lightemitTemplates/buildVerticalSingSubTitleTemplates.html", params);
                boolean flag = new FileUtil().writeToFile(body, filenameTemp);
                if (flag) {
                    //清屏操作
                    lightemitUtils.clear(lightemitControlCode);
                    //清除播放列表
                    lightemitUtils.clearVideoPlay(lightemitControlCode);
                    //清除节目列表
                    lightemitUtils.clearPlayerTask(lightemitControlCode);
                    //推送
                    lightemitUtils.postHtmlUseNginx(lightemitControlCode, userName);
                }
            }
        }
    }
    /**
     * ä¸Šä¼ åž‚直滚动多行字幕
     *
     * @param subTitleSetEntity
     * @param path
     * @param userName
     * @throws IOException
     */
    private void BuildVerticalMultiSubTitleText(SubTitleSetEntity subTitleSetEntity, String path, String userName) throws IOException {
        //html地址
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                String lightemitControlCode = poleLightemitEntity.getLightemitControlCode();
                //获取屏幕宽
                Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
                Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
                String filenameTemp = path + userName + "_" + lightemitControlCode + ".html";
                File htmlFile = new File(filenameTemp);
                if (!htmlFile.exists() || htmlFile.delete()) {
                    htmlFile.createNewFile();
                }
                Map<String, Object> params = new HashMap<>();
                params.put("direction", subTitleSetEntity.getDirection());
                params.put("screenWidth", screenWidth);
                params.put("screenHeight", screenHeight);
                params.put("fontSize", subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1");
                params.put("align", subTitleSetEntity.getAlign());
                params.put("fontColor", subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff");
                params.put("backgroundColor", subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000");
                params.put("interval", subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : 50);
                params.put("step", subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : 1);
                params.put("num", subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : -1);
                params.put("contentArray", subTitleSetEntity.getContent().split("\n"));
                String body = new HtmlTemplateUtils().renderPath("classpath:templates/lightemitTemplates/buildVerticalSingSubTitleTemplates.html", params);
                boolean flag = new FileUtil().writeToFile(body, filenameTemp);
                if (flag) {
                    //清屏操作
                    lightemitUtils.clear(lightemitControlCode);
                    //清除播放列表
                    lightemitUtils.clearVideoPlay(lightemitControlCode);
                    //清除节目列表
                    lightemitUtils.clearPlayerTask(lightemitControlCode);
                    //推送
                    lightemitUtils.postHtmlUseNginx(lightemitControlCode, userName);
                }
            }
        }
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/LightemitUtils.java
@@ -2,7 +2,6 @@
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.*;
@@ -29,8 +28,6 @@
    PoleLightemitService poleLightemitService;
    @Autowired
    ApplicationContext applicationContext;
    @Autowired
    NginxConfigBean nginxConfigBean;
    //body封装编码
    private final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
@@ -144,24 +141,6 @@
        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屏
@@ -234,6 +213,7 @@
    /**
     * å‘送最新的数据
     *
     * @param lightemitControlCode
     */
    public void sendLastCommand(String lightemitControlCode) {
ximon-admin/src/main/resources/application.yml
@@ -36,15 +36,6 @@
  command: http://112.74.63.130:20018/command/
  url: http://112.74.63.130:20018/
# nginx相关地址
nginx:
  port: 443
  cameraSaveUrl: D:/NginX/nginx-1.15.9/data/file/cameraPresetPoint
nginx-config:
  filePath: D:\NginX\nginx-1.15.9\data\file\
  url: http://47.106.172.9:443/download/
  apkUrl: http://47.106.172.9:443/apk/
  lcdUrl: http://47.106.172.9:443/download/lcd/
server-conf:
  ip: 47.106.172.9 # 47.106.172.9/101.132.131.91