Przeglądaj źródła

屏幕绑定气象站,屏幕截屏

crazycat 2 lat temu
rodzic
commit
20601cd0b6

+ 4 - 0
src/main/java/com/welampiot/common/Constant.java

@@ -2,6 +2,8 @@ package com.welampiot.common;
 
 public class Constant {
     public static String success="0000";
+    // 平台访问地址
+    public static String WEB_HOST = "http://www.lampmind.com";
 
     // 国标接口访问地址
     public static String GB_HOST_ADDRESS = "http://47.112.108.98:8089";
@@ -9,4 +11,6 @@ public class Constant {
     public static String ZK_HOST_ADDRESS = "http://47.112.108.98:8060";
     // 国标流媒体播放地址
     public static String GB_PLAY_HOST_ADDRESS = "https://gb.lampmind.com:8087";
+    // 屏幕节目访问域名地址
+    public static String SCREEN_PRO_ADDRESS = "http://www.lampmind.com";
 }

+ 13 - 0
src/main/java/com/welampiot/configuration/ScreenConfig.java

@@ -0,0 +1,13 @@
+package com.welampiot.configuration;
+
+public class ScreenConfig {
+    // 太龙屏幕配置信息
+    public static String taiLongHost = "https://openapi.vnnox.com";  // 地址
+    public static String taiLongUsername = "weclouds"; // 账号
+    public static String taiLongPassword = "weclouds@123"; // 密码
+
+    // 熙迅屏幕配置信息
+    public static String xiXunServerHost = "127.0.0.1"; // 服务端地址
+    public static int xiXunServerPort = 8082; // 服务端端口
+    public static int xiXunServerTimeout = 10000; // 指令默认超时时间 10000 毫秒
+}

+ 5 - 5
src/main/java/com/welampiot/controller/NewLampPoleController.java

@@ -591,19 +591,19 @@ public class NewLampPoleController {
                 newString.add(1,o.getAcount());
                 newString.add(2,o.getCompany());
                 switch (o.getOperaType()) {
-                    case "5":
+                    case 5:
                         newString.add(3, "退出登录");
                         break;
-                    case "4":
+                    case 4:
                         newString.add(3, "指令");
                         break;
-                    case "3":
+                    case 3:
                         newString.add(3, "编辑");
                         break;
-                    case "2":
+                    case 2:
                         newString.add(3, "删除");
                         break;
-                    case "1":
+                    case 1:
                         newString.add(3, "添加");
                         break;
                     default:

Plik diff jest za duży
+ 185 - 1
src/main/java/com/welampiot/controller/ScreenController.java


+ 1 - 0
src/main/java/com/welampiot/dao/OperationLogDao.java

@@ -20,4 +20,5 @@ public interface OperationLogDao {
     void deleteLogListById(@Param("id") Integer id);
 
     List<OperationLogDTO> getOperationLogList(OperationLogVO vo);
+    int add(OperationLogDTO operationLogDTO);
 }

+ 2 - 0
src/main/java/com/welampiot/dao/ScreenDao.java

@@ -38,4 +38,6 @@ public interface ScreenDao {
     void updateLampPoleScreenData(ScreenDTO dto);
 
     Integer checkScreenData(ScreenDTO dto);
+    ScreenDTO getScreenById(@Param("id")int id);
+    void updateByDto(ScreenDTO dto);
 }

+ 7 - 4
src/main/java/com/welampiot/dto/OperationLogDTO.java

@@ -8,17 +8,20 @@ public class OperationLogDTO {
     private String time;
     private String acount;
     private String remark;
-    private String operaType;
+    private int operaType;
     private String operation;
-    private String sectionId;
-    private String areaId;
+    private int sectionId;
+    private int areaId;
     private Integer os;
     private Integer type;
     private Integer userId;
     private Integer devType;
     private String deviceName;
     private String sn;
-    private String devId;
+    private int devId;
+    private String sqlLog;
+    private String ipAddr;
+    private String location;
     private String name;//用户名
     private String updateTime;
     private String area;

+ 1 - 0
src/main/java/com/welampiot/dto/ScreenDTO.java

@@ -153,6 +153,7 @@ public class ScreenDTO implements Serializable {
     private Integer count;
 
     private Integer online;
+    private String path;  // 截屏地址
 
     private static final long serialVersionUID = 1L;
 }

+ 1 - 0
src/main/java/com/welampiot/service/OperationLogService.java

@@ -13,4 +13,5 @@ public interface OperationLogService {
     void deleteLogListById(Integer id);
 
     List<OperationLogDTO> getOperationLogList(OperationLogVO vo);
+    int add(OperationLogDTO operationLogDTO);
 }

+ 3 - 0
src/main/java/com/welampiot/service/ScreenService.java

@@ -3,6 +3,7 @@ package com.welampiot.service;
 import com.welampiot.dto.ScreenDTO;
 import com.welampiot.vo.ScreenDetailsVO;
 import com.welampiot.vo.ScreenVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -35,4 +36,6 @@ public interface ScreenService {
     void updateLampPoleScreenData(ScreenDTO dto);
 
     Integer checkScreenData(ScreenDTO dto);
+    ScreenDTO getScreenById(int id);
+    void updateByDto(ScreenDTO dto);
 }

+ 16 - 11
src/main/java/com/welampiot/service/impl/OperationLogServiceImpl.java

@@ -32,23 +32,23 @@ public class OperationLogServiceImpl implements OperationLogService {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         logList.forEach(logDTO ->{
             switch (logDTO.getOperaType()){
-                case "5" :
-                    logDTO.setOperaType("5");
+                case 5 :
+                    logDTO.setOperaType(5);
                     break;
-                case "4" :
-                    logDTO.setOperaType("4");
+                case 4 :
+                    logDTO.setOperaType(4);
                     break;
-                case "3" :
-                    logDTO.setOperaType("3");
+                case 3 :
+                    logDTO.setOperaType(3);
                     break;
-                case "2" :
-                    logDTO.setOperaType("2");
+                case 2 :
+                    logDTO.setOperaType(2);
                     break;
-                case "1" :
-                    logDTO.setOperaType("1");
+                case 1 :
+                    logDTO.setOperaType(1);
                     break;
                 default :
-                    logDTO.setOperaType("0");
+                    logDTO.setOperaType(0);
                     break;
             }
             if (logDTO.getArea() == null){
@@ -110,4 +110,9 @@ public class OperationLogServiceImpl implements OperationLogService {
     public List<OperationLogDTO> getOperationLogList(OperationLogVO vo) {
         return operationLogDao.getOperationLogList(vo);
     }
+
+    @Override
+    public int add(OperationLogDTO operationLogDTO) {
+        return operationLogDao.add(operationLogDTO);
+    }
 }

+ 10 - 0
src/main/java/com/welampiot/service/impl/ScreenServiceImpl.java

@@ -253,6 +253,16 @@ public class ScreenServiceImpl implements ScreenService {
         return screenDao.checkScreenData(dto);
     }
 
+    @Override
+    public ScreenDTO getScreenById(int id) {
+        return screenDao.getScreenById(id);
+    }
+
+    @Override
+    public void updateByDto(ScreenDTO dto) {
+        screenDao.updateByDto(dto);
+    }
+
     @Override
     public Integer getTotalBySectionList(ScreenDTO dto) {
         return screenDao.getTotalBySectionList(dto);

+ 202 - 0
src/main/java/com/welampiot/utils/ScreenUtil.java

@@ -0,0 +1,202 @@
+package com.welampiot.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.welampiot.configuration.ScreenConfig;
+import com.welampiot.dto.ScreenDTO;
+import com.welampiot.dto.SystemConfigDto;
+import com.welampiot.service.SystemConfigService;
+
+import java.io.*;
+import java.net.ConnectException;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ScreenUtil {
+    /**
+     * 诺瓦显示屏获取token值
+     * @param systemConfigService
+     * @return token
+     */
+    public static String getTaiLongToken(SystemConfigService systemConfigService){
+        SystemConfigDto taiLongToken = systemConfigService.getOneBykey("TaiLongToken");
+        SystemConfigDto taiLongTokenExpireTime = systemConfigService.getOneBykey("TaiLongTokenExpireTime");
+
+        if (taiLongToken == null || taiLongTokenExpireTime == null || System.currentTimeMillis() > Timestamp.valueOf(taiLongTokenExpireTime.getValue()).getTime()){
+            String url = ScreenConfig.taiLongHost+"/v1/oauth/token";
+            String data = "{\"username\":\""+ScreenConfig.taiLongUsername+"\",\"password\":\""+ScreenConfig.taiLongPassword+"\"}";
+            HashMap<String, String> stringStringHashMap = new HashMap<>();
+            stringStringHashMap.put("username",ScreenConfig.taiLongUsername);
+            stringStringHashMap.put("Content-Type","application/json");
+            String s = WebUtils.requestPost(url, data,stringStringHashMap);
+            Map jsonObject = JSON.parseObject(s,Map.class);
+            if (jsonObject != null){
+                if (jsonObject.containsKey("status") && (int)jsonObject.get("status") == 0 && jsonObject.containsKey("data")){
+                    JSONObject data2 = (JSONObject) jsonObject.get("data");
+                    String token = (String) data2.get("token");
+                    if (taiLongToken == null){
+                        SystemConfigDto systemConfigDto = new SystemConfigDto();
+                        systemConfigDto.setKey("TaiLongToken");
+                        systemConfigDto.setValue(token);
+                        systemConfigService.addByDto(systemConfigDto);
+                    }else {
+                        taiLongToken.setValue(token);
+                        systemConfigService.updateByDto(taiLongToken);
+                    }
+                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    Date date = new Date(System.currentTimeMillis()+12*3600*1000);
+                    String format = simpleDateFormat.format(date);
+                    if (taiLongTokenExpireTime == null){
+                        SystemConfigDto systemConfigDto = new SystemConfigDto();
+                        systemConfigDto.setKey("TaiLongTokenExpireTime");
+                        systemConfigDto.setValue(format);
+                        systemConfigService.addByDto(systemConfigDto);
+                    }else {
+                        taiLongTokenExpireTime.setValue(format);
+                        systemConfigService.updateByDto(taiLongTokenExpireTime);
+                    }
+                    return token;
+                }
+            }
+            return "";
+        }else {
+            return taiLongToken.getValue();
+        }
+    }
+
+    /**
+     * 诺瓦显示发送节目信息
+     * @param systemConfigService
+     * @param url 发送地址
+     * @param data 发送内容
+     * @return 返回发送结果
+     */
+    public static String sendTaiLongPro(SystemConfigService systemConfigService,String url,String data){
+        String taiLongToken = getTaiLongToken(systemConfigService);
+        url = ScreenConfig.taiLongHost+url;
+        HashMap<String, String> stringStringHashMap = new HashMap<>();
+        stringStringHashMap.put("username",ScreenConfig.taiLongUsername);
+        stringStringHashMap.put("token",taiLongToken);
+        stringStringHashMap.put("Content-Type","application/json");
+        String s = WebUtils.requestPost(url, data,stringStringHashMap);
+        return s;
+    }
+
+    /**
+     * 熙迅屏幕发送指令信息
+     * @param msg 指令信息
+     * @return  指令返回信息
+     */
+    public static String sendXiXunInfo(String msg) {
+        try {
+            //创建客户端的Socket对象
+            Socket socket = new Socket(ScreenConfig.xiXunServerHost, ScreenConfig.xiXunServerPort);
+            socket.setSoTimeout(ScreenConfig.xiXunServerTimeout);
+
+            //获取输出流,写数据
+            OutputStream outputStream = socket.getOutputStream();
+            outputStream.write(msg.getBytes());
+
+            //接收服务器的反馈
+            InputStream inputStream = socket.getInputStream();
+            byte[] bys = new byte[1024];
+            int len = inputStream.read(bys);
+            String s = new String(bys, 0, len);
+            //释放资源
+            socket.close();
+            return s;
+        }
+        catch (ConnectException e4) {
+        }
+        catch (Exception e5) {
+        }
+        return "";
+    }
+    /**
+     * 熙迅屏幕发送指令信息
+     * @param msg 指令信息
+     * @param timeout 指令超时时间
+     * @return  指令返回信息
+     */
+    public static String sendXiXunInfo(String msg,int timeout) {
+        try {
+            //创建客户端的Socket对象
+            Socket socket = new Socket(ScreenConfig.xiXunServerHost, ScreenConfig.xiXunServerPort);
+            socket.setSoTimeout(timeout);
+
+            //获取输出流,写数据
+            OutputStream outputStream = socket.getOutputStream();
+            outputStream.write(msg.getBytes());
+
+            //接收服务器的反馈
+            InputStream inputStream = socket.getInputStream();
+            byte[] bys = new byte[1024];
+            int len = inputStream.read(bys);
+            String s = new String(bys, 0, len);
+            //释放资源
+            socket.close();
+            return s;
+        }
+        catch (ConnectException e4) {
+        }
+        catch (Exception e5) {
+        }
+        return "";
+    }
+
+    /**
+     * 熙迅屏幕本地缓存网页信息
+     * @param num 屏幕序列号
+     * @param url 缓存网页地址
+     * @param screenId 屏幕id
+     * @return 缓存后的网页地址
+     */
+    public static String xiXunUploadWebInfo(String num,String url,int screenId) {
+        String newUrl = "/weather/weather_"+System.currentTimeMillis()+".html";
+        String cmd = "{\"type\":\"downloadFileToLocal\",\"url\":\""+url+"\",\"path\":\""+newUrl+"\",\"_id\":\"save_web_"+screenId+"\"}";
+        sendXiXunInfo("{\"cardId\":\""+num+"\",\"cmd\":"+cmd+"}");
+        cmd = "{\"type\":\"getLocalFileLength\",\"path\":\""+newUrl+"\",\"_id\":\"get_save_web_"+screenId+"\"}";
+        String s = WebUtils.requestGet(url);
+        File file = new File("../upload/test.html");
+        try{
+            if (!file.exists()) file.createNewFile();
+            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
+                    new FileOutputStream("../upload/test.html"));
+            bufferedOutputStream.write(s.getBytes());
+        }catch (Exception e){
+        }
+        file = new File("../upload/test.html");
+        long size = file.length();
+        String s1 = sendXiXunInfo("{\"cardId\":\"" + num + "\",\"cmd\":" + cmd + "}");
+        if (s1.length() != 0){
+            JSONObject jsonObject = JSON.parseObject(s1);
+            long length = (long)jsonObject.get("length");
+            int times = 1;
+            while (length != size && times < 3){
+                times ++;
+                s1 = sendXiXunInfo("{\"cardId\":\"" + num + "\",\"cmd\":" + cmd + "}");
+                if (s1.length() == 0) break;
+                jsonObject = JSON.parseObject(s1);
+                length = (long)jsonObject.get("length");
+            }
+
+            if (length == size) return "file:///data/data/com.xixun.xy.conn/files/local"+newUrl;
+        }
+        return url;
+    }
+
+//    public static void screenshot(ScreenDTO dto){
+//        if (dto.getDevType() == 0){ // 熙迅
+//            String cmd = "{\"cardId\":\""+dto.getNum()+"\",\"cmd\":{\"type\": \"callCardService\",\"fn\": \"screenshot\",\"arg1\": 100,\"arg2\": 50,\"_id\":\"get_screen_image_"+dto.getNum()+"\"}}";
+//            sendXiXunInfo(cmd,0);
+//        } else if (dto.getDevType() == 1) {
+//            sendTaiLongPro();
+//        }
+//    }
+}

+ 9 - 0
src/main/java/com/welampiot/utils/ToolUtils.java

@@ -152,6 +152,15 @@ public class ToolUtils {
         return user;
     }
 
+    public UserDTO getUser(HttpServletRequest request) {
+        String username = request.getParameter("username");
+        ArrayList<Object> sectionList = new ArrayList<>();
+        if (user == null) {
+            user = userService.findUserByUserName(username);
+        }
+        return user;
+    }
+
     /**
      * 返回接口信息,不带数据
      * @param code 状态码

+ 56 - 2
src/main/java/com/welampiot/utils/WebUtils.java

@@ -1,6 +1,11 @@
 package com.welampiot.utils;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.welampiot.configuration.ScreenConfig;
+import com.welampiot.dto.SystemConfigDto;
+import com.welampiot.service.OperationLogService;
+import com.welampiot.service.SystemConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -17,8 +22,9 @@ import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.List;
-import java.util.Map;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Slf4j
 public class WebUtils
@@ -104,7 +110,54 @@ public class WebUtils
         }
         return response.toString();
     }
+    /**
+     * 模拟post请求
+     * @param url  请求地址
+     * @param param  请求参数
+     * @param header  请求头
+     * @return 请求返回信息
+     * @throws Exception
+     */
+    public static String requestPost(String url, String param,Map header) {
+        StringBuilder response;
+        try {
+            URL obj = new URL(url);
+            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+            con.setRequestMethod("POST");
+            con.setRequestProperty("User-Agent", "Mozilla/5.0");
+            con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
+
+            con.setDoOutput(true);
+            con.setReadTimeout(5000);
+            Set set = header.keySet();
+            for (Object s:set) {
+                con.setRequestProperty((String) s, (String) header.get(s));
+            }
+            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
+            wr.writeBytes(param);
+            wr.flush();
+            wr.close();
+
+            BufferedReader in = new BufferedReader(
+                    new InputStreamReader(con.getInputStream()));
+            String inputLine;
+            response = new StringBuilder();
 
+            while ((inputLine = in.readLine()) != null) {
+                response.append(inputLine);
+            }
+            in.close();
+        }catch (Exception e){
+            return "";
+        }
+        return response.toString();
+    }
+    /**
+     * 模拟get请求
+     * @param url  请求地址
+     * @return 请求返回信息
+     * @throws Exception
+     */
     public static String requestGet(String url) {
         CloseableHttpResponse response = null;
         BufferedReader in = null;
@@ -145,4 +198,5 @@ public class WebUtils
         }
         return result;
     }
+
 }

+ 3 - 1
src/main/resources/mapper/EnvmonitorMapper.xml

@@ -242,10 +242,12 @@
     
     <select id="getEnvmonitorMpDataById" resultType="EnvmonitorDTO">
         select
+            e.id,
             e.mp_status as mpStatus,
             e.mp_start_time as mpStartTime,
             e.mp_end_time as mpEndTime,
-            e.mp_bright as mpBright,
+            e.mp_bright as mpBright,e.rate,
+            e.lamp_pole_id as lampPoleId,e.devType,e.serial_port as serialPort,
             e.mp_illumination as mpIllumination
         from envmonitor e
         where

+ 39 - 0
src/main/resources/mapper/OperationLogMapper.xml

@@ -109,4 +109,43 @@
         </if>
     </select>
 
+    <insert id="add" parameterType="com.welampiot.dto.OperationLogDTO" useGeneratedKeys="true" keyProperty="id"
+    >
+        insert into operation_log(userid,remark,time
+        <if test="acount != null">,acount</if>
+        <if test="operation != null">,operation</if>
+        <if test="os != null">,os</if>
+        <if test="type != null">,type</if>
+        <if test="devType != null">,devtype</if>
+        <if test="deviceName != null">,deviceName</if>
+        <if test="area != null">,area</if>
+        <if test="section != null">,section</if>
+        <if test="sn != null">,sn</if>
+        <if test="sectionId != null">,sectionid</if>
+        <if test="areaId != null">,areaid</if>
+        <if test="devId != null">,devid</if>
+        <if test="sqlLog != null">,sql_log</if>
+        <if test="ipAddr != null">,ip_addr</if>
+        <if test="location != null">,location</if>
+        )
+        values
+        (#{userId},#{remark},#{time}
+        <if test="acount != null">,#{acount}</if>
+        <if test="operation != null">,#{operation}</if>
+        <if test="os != null">,#{os}</if>
+        <if test="type != null">,#{type}</if>
+        <if test="devType != null">,#{devType}</if>
+        <if test="deviceName != null">,#{deviceName}</if>
+        <if test="area != null">,#{area}</if>
+        <if test="section != null">,#{section}</if>
+        <if test="sn != null">,#{sn}</if>
+        <if test="sectionId != null">,#{sectionId}</if>
+        <if test="areaId != null">,#{areaId}</if>
+        <if test="devId != null">,#{devId}</if>
+        <if test="sqlLog != null">,#{sqlLog}</if>
+        <if test="ipAddr != null">,#{ipAddr}</if>
+        <if test="location != null">,#{location}</if>
+        )
+    </insert>
+
 </mapper>

+ 31 - 0
src/main/resources/mapper/ScreenMapper.xml

@@ -135,6 +135,27 @@
         limit 1
     </select>
 
+    <select id="getScreenById" resultType="com.welampiot.dto.ScreenDTO" parameterType="int">
+        SELECT
+        s.id,
+        s.model,
+        s.type,
+        s.num,s.devType,s.tailong_id as taiLongId,
+        s.netStatus,lp.sectionid as sectionId,
+        s.status,
+        s.light,
+        s.volume,
+        s.width,
+        s.height,
+        s.playingid AS playingId,
+        s.type,
+        s.maxLight
+        FROM screen s
+        LEFT JOIN lamp_pole lp
+        ON s.lamp_pole_id = lp.id
+        WHERE s.id = #{id}
+    </select>
+
     <delete id="deleteScreenById">
         delete
         from screen
@@ -177,6 +198,16 @@
         </if>
     </update>
 
+    <update id="updateByDto" parameterType="ScreenDTO">
+        update
+        screen s
+        set
+        <if test="type != null">s.type = #{type},</if>
+        <if test="weatherId != null">s.weatherid = #{weatherId},</if>
+        s.id = #{id}
+        where s.id = #{id}
+    </update>
+
     <select id="checkScreenData" resultType="Integer">
         select count(*)
         from screen s