From 6c914caa1e16d709d16c39b6ae55bd8b5c8f0283 Mon Sep 17 00:00:00 2001 From: leutu <leutu@qq.com> Date: 星期二, 20 八月 2024 09:54:50 +0800 Subject: [PATCH] 使用本地时间戳,避免时间不同步无法推送数据 --- src/main/java/com/skyline/electricity/timer/Consumer.java | 40 +++++++++++++--------------------------- 1 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/skyline/electricity/timer/Consumer.java b/src/main/java/com/skyline/electricity/timer/Consumer.java index 13d7c43..ca48a60 100644 --- a/src/main/java/com/skyline/electricity/timer/Consumer.java +++ b/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("銆恮ebsocket娑堟伅銆戝箍鎾秷鎭�:"+message); + System.out.println("銆恮ebsocket娑堟伅銆戝箍鎾秷鎭�:"+message); JSONObject jsonObject = JSONObject.parseObject(message); String personNo = jsonObject.getString("personNo"); SysUser sysUser = infoSynchService.selectUserInfoById(personNo) ; - //System.out.println("銆恥ser]:"+JSONObject.toJSONString(sysUser)); + System.out.println("銆恥ser]:"+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("銆怓encePosition]:"+JSONObject.toJSONString(fencePositionList)); + List<FencePosition> fencePositionList = (List<FencePosition>)this.detectService.checkInFence(jsonObject.get("w84lat").toString(),jsonObject.get("w84lon").toString()); + System.out.println("銆怓encePosition]:"+JSONObject.toJSONString(fencePositionList)); RetInfo alertinfo = new RetInfo(); initAlertInfos(jsonObject, personNo, sysUser, alertinfo); if( fencePositionList != null && fencePositionList.size() > 0){ @@ -102,8 +96,8 @@ } insertInformation(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)+"]" ); +// if( list != null && list.size() > 0) +// System.out.println( "websocket status ..["+webSocketController.sendAllMessage(JSONObject.toJSONString(list))+"["+JSONObject.toJSONString(list)+"]" ); } private void initAlertInfos(JSONObject jsonObject, String personNo, SysUser sysUser, RetInfo alertinfo) { @@ -120,22 +114,12 @@ 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()); } - /** - * 鍒ゆ柇鍥存爮妤煎眰涓庝笂鎶ヤ綅缃ゼ灞備竴鑷达紝鍚﹀垯涓嶆姤璀� - * @param basefloor - * @param start - * @return - */ private boolean checkHight(String basefloor,double start){ - double f = start/6.3; - int ff = (int)f+2; - return (ff-Integer.parseInt(basefloor)) >= 0 ; + return (Integer.parseInt(basefloor)-2)*6.3 >=start ; } @@ -145,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()); -- Gitblit v1.9.3