a4e99a6a39284643fdf2b04dbe55212e5954973c..6c914caa1e16d709d16c39b6ae55bd8b5c8f0283
2024-08-20 leutu
使用本地时间戳,避免时间不同步无法推送数据
6c914c 对比 | 目录
2024-08-13 leutu
推送代码忘记去掉注释,另外schederTask注意时间戳同步
75e50e 对比 | 目录
已修改3个文件
46 ■■■■■ 文件已修改
src/main/java/com/skyline/electricity/timer/Consumer.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/skyline/electricity/timer/SchedulerTask.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/skyline/electricity/timer/Consumer.java
@@ -19,7 +19,6 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
@Slf4j
@@ -41,7 +40,7 @@
    InformationService informationService ;
    @Override
    public void onMessage(String message) {
        //System.out.println("recv msg:  "+message);
        System.out.println("recv msg:  "+message);
        sendAllMessage(message);
    }
@@ -64,22 +63,17 @@
     */
    public void sendAllMessage(String message) {
        //System.out.println("【websocket消息】广播消息:"+message);
        System.out.println("【websocket消息】广播消息:"+message);
        JSONObject jsonObject = JSONObject.parseObject(message);
        String personNo = jsonObject.getString("personNo");
        SysUser sysUser = infoSynchService.selectUserInfoById(personNo) ;
        //System.out.println("【user]:"+JSONObject.toJSONString(sysUser));
        System.out.println("【user]:"+JSONObject.toJSONString(sysUser));
        List<RetInfo> list = new ArrayList<>();
        //查询用户所处围栏
        List<FencePosition> fencePositionList = null ;
        try{
            fencePositionList = (List<FencePosition>)this.detectService.checkInFence(jsonObject.get("w84lat").toString(),jsonObject.get("w84lon").toString());
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        //System.out.println("【FencePosition]:"+JSONObject.toJSONString(fencePositionList));
        List<FencePosition> fencePositionList = (List<FencePosition>)this.detectService.checkInFence(jsonObject.get("w84lat").toString(),jsonObject.get("w84lon").toString());
        System.out.println("【FencePosition]:"+JSONObject.toJSONString(fencePositionList));
        RetInfo alertinfo = new RetInfo();
        initAlertInfos(jsonObject, personNo, sysUser, alertinfo);
        if( fencePositionList != null && fencePositionList.size() > 0){
@@ -101,7 +95,7 @@
            list.add(alertinfo) ;
        }
        insertInformation(list);
       // System.out.println( "list:"+jsonObject.toJSONString(list));
        System.out.println( "list:"+jsonObject.toJSONString(list));
//        if( list != null && list.size() > 0)
//            System.out.println( "websocket status ..["+webSocketController.sendAllMessage(JSONObject.toJSONString(list))+"["+JSONObject.toJSONString(list)+"]" );
    }
@@ -120,10 +114,8 @@
        alertinfo.setMobile(sysUser.getMobile());
        alertinfo.setBaseFloor(jsonObject.get("baseFloor").toString());
        String time = Long.toString(new Date().getTime());
        alertinfo.setStartTime(time.substring(0,time.length()-3));
        alertinfo.setHb(jsonObject.getIntValue("hb"));
        alertinfo.setStartTime(jsonObject.get("timestamp").toString());
        alertinfo.setHb(jsonObject.getInteger("hb").intValue());
    }
    private boolean checkHight(String basefloor,double start){
@@ -137,7 +129,9 @@
           Information information = new Information();
           information.setFence_type(r.getType());
           information.setName(r.getFence_name());
           information.setStartTime(r.getStartTime());
           //information.setStartTime(r.getStartTime());
           //避免时间同步问题
           information.setStartTime((new Date()).getTime()+"");
           information.setStatus(r.getStatus());
           information.setUserId(r.getUserId());
           information.setWtId(r.getWtId());
src/main/java/com/skyline/electricity/timer/SchedulerTask.java
@@ -1,15 +1,5 @@
package com.skyline.electricity.timer;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.*;
import org.springframework.context.annotation.*;
import org.springframework.beans.factory.annotation.*;
@@ -93,11 +83,12 @@
        List<RetInfo> rlist = new ArrayList<>();
        list.stream().forEach(r->rlist.add(JSONObject.parseObject(r,RetInfo.class))) ;
        if( list != null && list.size() > 0){
            System.out.println("scheduled....push size:"+list.size());
            webSocketController.sendAllMessage(JSONObject.toJSONString(rlist));
        }
       //     System.out.println( "websocket status ..["+JSONObject.toJSONString(rlist)+"]" );
        //推送报警信息
        pushIM(rlist);
        //pushIM(rlist);
    }
    /**
src/main/resources/application-dev.yml
@@ -24,6 +24,11 @@
    jdbc-url: jdbc:postgresql://10.69.206.79:5432/HBLFDC
    username: postgres
    password: Terra2024!
#    type: org.apache.commons.dbcp.BasicDataSource
#    driverClassName:  org.postgresql.Driver
#    jdbc-url: jdbc:postgresql://192.168.11.28:5433/HBLFDC
#    username: postgres
#    password: 123456
    #连接池配置
    dbcp2:
      maxWait: 120000