package com.skyline.electricity.timer;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.skyline.electricity.controller.WebSocketController;
|
import com.skyline.electricity.entity.ConfigInfo;
|
import com.skyline.electricity.entity.SysUser;
|
import com.skyline.electricity.mapper.InformationMapper;
|
import com.skyline.electricity.pojo.*;
|
import com.skyline.electricity.service.DetectService;
|
import com.skyline.electricity.service.InfoSynchService;
|
import com.skyline.electricity.service.InformationService;
|
import com.vividsolutions.jts.geom.GeometryFactory;
|
import com.vividsolutions.jts.io.WKTReader;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
@Slf4j
|
@Service
|
//192.168.121.193:9876
|
@RocketMQMessageListener(nameServer = "192.168.121.193:9876",topic = "deviceLocationData", consumerGroup = "test")
|
public class Consumer implements RocketMQListener<String> {
|
|
@Autowired
|
InfoSynchService infoSynchService ;
|
|
@Autowired
|
private DetectService detectService;
|
|
@Autowired
|
WebSocketController webSocketController ;
|
|
@Autowired
|
InformationService informationService ;
|
@Override
|
public void onMessage(String message) {
|
System.out.println("recv msg: "+message);
|
sendAllMessage(message);
|
}
|
|
/*
|
|
private String userId;
|
private String shopId;
|
private String userName;
|
private String userIndex;
|
private String mobile;
|
private String email;
|
private Integer satelliteNum;
|
private String longitude;
|
private String latitude;
|
private String alitude;
|
private String course;
|
private List<Code> events;
|
private String time;
|
private String type;
|
*/
|
|
public void sendAllMessage(String 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));
|
List<RetInfo> list = new ArrayList<>();
|
//查询用户所处围栏
|
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){
|
for( FencePosition f:fencePositionList) {
|
// 判断用户是否是围栏合法用户
|
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())){
|
alertinfo.setStatus("alert");
|
|
}else{
|
alertinfo.setStatus("ok");
|
}
|
list.add(alertinfo) ;
|
}
|
}else{
|
alertinfo.setStatus("ok");
|
list.add(alertinfo) ;
|
}
|
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)+"]" );
|
}
|
|
private void initAlertInfos(JSONObject jsonObject, String personNo, SysUser sysUser, RetInfo alertinfo) {
|
alertinfo.setLatitude(jsonObject.get("w84lat").toString());
|
alertinfo.setLongitude(jsonObject.get("w84lon").toString());
|
// alertinfo.setW84lat(jsonObject.get("w84lat").toString());
|
// alertinfo.setW84lon(jsonObject.get("w84lon").toString());
|
alertinfo.setUserId(personNo);
|
alertinfo.setUserName(sysUser.getName());
|
alertinfo.setType(jsonObject.get("locType").toString());
|
alertinfo.setShopId("197");
|
|
alertinfo.setEmail(sysUser.getEmail());
|
alertinfo.setMobile(sysUser.getMobile());
|
|
alertinfo.setBaseFloor(jsonObject.get("baseFloor").toString());
|
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 void insertInformation(List<RetInfo> list){
|
List<Information> iList = new ArrayList<>() ;
|
for(RetInfo r:list) {
|
Information information = new Information();
|
information.setFence_type(r.getType());
|
information.setName(r.getFence_name());
|
//information.setStartTime(r.getStartTime());
|
//避免时间同步问题
|
information.setStartTime((new Date()).getTime()+"");
|
information.setStatus(r.getStatus());
|
information.setUserId(r.getUserId());
|
information.setWtId(r.getWtId());
|
information.setUserName(r.getUserName());
|
information.setXy(JSONObject.toJSONString(r));
|
information.setHb(r.getHb());
|
iList.add(information);
|
}
|
if( iList != null && iList.size() > 0)
|
informationService.saveList(iList);
|
}
|
}
|