leutu
2024-08-20 bbd50cf91c9a8c7cfe48b3c00dde205b7049ae3b
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){
@@ -88,7 +82,7 @@
                Fence_User fence_user = detectService.checkInAlert(f.getWorkId(),sysUser.getId());
                alertinfo.setFence_name(f.getFname());
                alertinfo.setWtId(f.getWorkId());
                if( fence_user == null && checkHight(alertinfo.getBaseFloor(),f.getStartaltitude())){
                if( fence_user == null && checkHight(alertinfo.getBaseFloor(),f)){
                    alertinfo.setStatus("alert");
                }else{
@@ -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,14 +114,14 @@
        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){
        return  (Integer.parseInt(basefloor)-2)*6.3 >=start ;
    private boolean checkHight(String basefloor,FencePosition f){
        int fl = (int)(f.getEndaltitude()/7)+1 ;
        System.out.println("接收:"+basefloor+" 围栏楼层:"+f.getFname()+":"+fl);
        return  (Integer.parseInt(basefloor)-1) ==fl ;
    }
@@ -137,7 +131,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()/1000+"");
           information.setStatus(r.getStatus());
           information.setUserId(r.getUserId());
           information.setWtId(r.getWtId());