18 changed files with 243 additions and 821 deletions
@ -1,47 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.enums; |
|
||||
|
|
||||
public enum AlarmType { |
|
||||
ALARM_1("1","禁区告警-区域"), |
|
||||
ALARM_2("2","超员告警-区域"), |
|
||||
ALARM_3("3","滞留告警-区域"), |
|
||||
ALARM_4("4","区域过短-区域"), |
|
||||
ALARM_5("5","禁静止超时-区域"), |
|
||||
ALARM_6("6","SOS"), |
|
||||
ALARM_7("7","闯入告警-围栏"), |
|
||||
ALARM_8("8","脱岗告警-围栏"), |
|
||||
ALARM_13("13","车辆超速"), |
|
||||
ALARM_14("14","人员卡充电告警"), |
|
||||
ALARM_15("15","缺员告警-区域"), |
|
||||
ALARM_16("16","脱岗告警-区域"), |
|
||||
ALARM_17("17","车辆路线偏移"), |
|
||||
ALARM_18("18","违规告警"), |
|
||||
ALARM_19("19","二道门离厂告警"); |
|
||||
|
|
||||
|
|
||||
private final String alarmCode; |
|
||||
|
|
||||
private final String alarmContent; |
|
||||
|
|
||||
AlarmType(String alarmCode, String alarmContent) { |
|
||||
this.alarmCode = alarmCode; |
|
||||
this.alarmContent = alarmContent; |
|
||||
} |
|
||||
|
|
||||
public String getAlarmCode() { |
|
||||
return alarmCode; |
|
||||
} |
|
||||
|
|
||||
public String getAlarmContent() { |
|
||||
return alarmContent; |
|
||||
} |
|
||||
|
|
||||
public static String getContentByCode(String code) { |
|
||||
for (AlarmType objEnum : AlarmType.values()) { |
|
||||
if(objEnum.getAlarmCode().equals(code)) { |
|
||||
return objEnum.getAlarmContent(); |
|
||||
} |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.enums; |
|
||||
|
|
||||
public enum UserType { |
|
||||
|
|
||||
ALARM_0("0","在职员工"), |
|
||||
ALARM_1("1","临时访客"), |
|
||||
ALARM_2("2","承包商员工"), |
|
||||
ALARM_3("3","物品"), |
|
||||
ALARM_4("4","车辆"), |
|
||||
ALARM_5("5","司机"); |
|
||||
|
|
||||
private final String alarmCode; |
|
||||
|
|
||||
private final String alarmContent; |
|
||||
|
|
||||
UserType(String alarmCode, String alarmContent) { |
|
||||
this.alarmCode = alarmCode; |
|
||||
this.alarmContent = alarmContent; |
|
||||
} |
|
||||
|
|
||||
public String getAlarmCode() { |
|
||||
return alarmCode; |
|
||||
} |
|
||||
|
|
||||
public String getAlarmContent() { |
|
||||
return alarmContent; |
|
||||
} |
|
||||
|
|
||||
public static String getContentByCode(String code) { |
|
||||
for (UserType objEnum : UserType.values()) { |
|
||||
if(objEnum.getAlarmCode().equals(code)) { |
|
||||
return objEnum.getAlarmContent(); |
|
||||
} |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,73 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class AlarmInfoHx { |
|
||||
/** |
|
||||
* 唯一标示 |
|
||||
*/ |
|
||||
private String uniqueId; |
|
||||
/** |
|
||||
* 企业容器id |
|
||||
*/ |
|
||||
private String containerId ="ningyanghuagongchany"; |
|
||||
/** |
|
||||
* 设备编号 |
|
||||
*/ |
|
||||
private String deviceCode; |
|
||||
/** |
|
||||
* 告警类型 |
|
||||
*/ |
|
||||
private String alarmType; |
|
||||
/** |
|
||||
* 告警内容 |
|
||||
*/ |
|
||||
private String alarmContent; |
|
||||
/** |
|
||||
* 楼层ID |
|
||||
*/ |
|
||||
private String layerId; |
|
||||
/** |
|
||||
* 一级区域id |
|
||||
*/ |
|
||||
private String firAreaId = "HXGK0001"; |
|
||||
/** |
|
||||
* 一级区域名称 |
|
||||
*/ |
|
||||
private String firAreaName = "恒信高科"; |
|
||||
/** |
|
||||
* |
|
||||
*/ |
|
||||
private String userOrgCode = "370910170"; |
|
||||
/** |
|
||||
* |
|
||||
*/ |
|
||||
private String userOrgName = "山东恒信高科能源有限公司"; |
|
||||
/** |
|
||||
* 二级区域id |
|
||||
*/ |
|
||||
private String secAreaId; |
|
||||
/** |
|
||||
* 二级区域名称 |
|
||||
*/ |
|
||||
private String secAreaName; |
|
||||
/** |
|
||||
* 纬度 |
|
||||
*/ |
|
||||
private Double x; |
|
||||
/** |
|
||||
* 经度 |
|
||||
*/ |
|
||||
private Double y; |
|
||||
/** |
|
||||
* 定位时间:yyyy-MM-dd HH:mm:ss |
|
||||
*/ |
|
||||
private String dateTime; |
|
||||
/** |
|
||||
* 处理状态:0:待处理,1:已处理 |
|
||||
*/ |
|
||||
private String dealStatus; |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class AlarmInfoIot { |
|
||||
/** |
|
||||
* 数据类型 |
|
||||
*/ |
|
||||
private String dataType ="alarm"; |
|
||||
/** |
|
||||
* 人员信息 |
|
||||
*/ |
|
||||
private AlarmInfoHx data; |
|
||||
} |
|
||||
@ -0,0 +1,43 @@ |
|||||
|
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
||||
|
|
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
|
||||
|
public class ApiResponse { |
||||
|
private Integer code; |
||||
|
private String msg; |
||||
|
private DataPage data; |
||||
|
|
||||
|
|
||||
|
public Integer getCode() { |
||||
|
return code; |
||||
|
} |
||||
|
|
||||
|
public void setCode(Integer code) { |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public String getMsg() { |
||||
|
return msg; |
||||
|
} |
||||
|
|
||||
|
public void setMsg(String msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
|
||||
|
public DataPage getData() { |
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
public void setData(DataPage data) { |
||||
|
this.data = data; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() { |
||||
|
return "ApiResponse{" + |
||||
|
"code=" + code + |
||||
|
", msg='" + msg + '\'' + |
||||
|
", data=" + data + |
||||
|
'}'; |
||||
|
} |
||||
|
} |
||||
@ -1,54 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
@Data |
|
||||
public class AreaUserInfoHx { |
|
||||
/** |
|
||||
* 唯一标示 |
|
||||
*/ |
|
||||
private String uniqueId; |
|
||||
/** |
|
||||
* 企业容器id |
|
||||
*/ |
|
||||
private String containerId ="ningyanghuagongchany"; |
|
||||
/** |
|
||||
* 单位唯一标志 |
|
||||
*/ |
|
||||
private String orgCode; |
|
||||
/** |
|
||||
* 单位名称 |
|
||||
*/ |
|
||||
private String orgName; |
|
||||
/** |
|
||||
* 区域唯一标志 |
|
||||
*/ |
|
||||
private String areaId; |
|
||||
/** |
|
||||
* 区域名称 |
|
||||
*/ |
|
||||
private String areaName; |
|
||||
/** |
|
||||
* 上级区域唯一标志 |
|
||||
*/ |
|
||||
private String areaPid; |
|
||||
/** |
|
||||
* 上级区域名称 |
|
||||
*/ |
|
||||
private String areaPname; |
|
||||
/** |
|
||||
* 区域内告警数量 |
|
||||
*/ |
|
||||
private String alarmNum; |
|
||||
/** |
|
||||
* 区域内人员数量 |
|
||||
*/ |
|
||||
private String personNum; |
|
||||
/** |
|
||||
* 区域内人员列表 |
|
||||
*/ |
|
||||
private List<UserBaseInfo> personList; |
|
||||
|
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class AreaUserInfoIot { |
|
||||
/** |
|
||||
* 数据类型 |
|
||||
*/ |
|
||||
private String dataType ="areaPersonAlarm"; |
|
||||
/** |
|
||||
* 人员信息 |
|
||||
*/ |
|
||||
private AreaUserInfoHx data; |
|
||||
} |
|
||||
@ -0,0 +1,65 @@ |
|||||
|
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
||||
|
|
||||
|
import com.google.gson.JsonObject; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public class DataPage { |
||||
|
private Integer current; |
||||
|
private Integer total; |
||||
|
private Integer pages; |
||||
|
private Integer size; |
||||
|
private List<Map> records; |
||||
|
|
||||
|
public Integer getCurrent() { |
||||
|
return current; |
||||
|
} |
||||
|
|
||||
|
public void setCurrent(Integer current) { |
||||
|
this.current = current; |
||||
|
} |
||||
|
|
||||
|
public Integer getTotal() { |
||||
|
return total; |
||||
|
} |
||||
|
|
||||
|
public void setTotal(Integer total) { |
||||
|
this.total = total; |
||||
|
} |
||||
|
|
||||
|
public Integer getPages() { |
||||
|
return pages; |
||||
|
} |
||||
|
|
||||
|
public void setPages(Integer pages) { |
||||
|
this.pages = pages; |
||||
|
} |
||||
|
|
||||
|
public Integer getSize() { |
||||
|
return size; |
||||
|
} |
||||
|
|
||||
|
public void setSize(Integer size) { |
||||
|
this.size = size; |
||||
|
} |
||||
|
|
||||
|
public List<Map> getRecords() { |
||||
|
return records; |
||||
|
} |
||||
|
|
||||
|
public void setRecords(List<Map> records) { |
||||
|
this.records = records; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() { |
||||
|
return "DataPage{" + |
||||
|
"current=" + current + |
||||
|
", total=" + total + |
||||
|
", pages=" + pages + |
||||
|
", size=" + size + |
||||
|
", records=" + records + |
||||
|
'}'; |
||||
|
} |
||||
|
} |
||||
@ -1,73 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class DeviceInfoHx { |
|
||||
/** |
|
||||
* 企业容器id |
|
||||
*/ |
|
||||
private String containerId ="ningyanghuagongchany"; |
|
||||
/** |
|
||||
* 设备编号 |
|
||||
*/ |
|
||||
private String deviceCode; |
|
||||
/** |
|
||||
* 设备类型,0:蓝牙;1:GPS |
|
||||
*/ |
|
||||
private String deviceType = "0"; |
|
||||
/** |
|
||||
* 企业编码 |
|
||||
*/ |
|
||||
private String userOrgCode = "370910170"; |
|
||||
/** |
|
||||
* 企业名称 |
|
||||
*/ |
|
||||
private String userOrgName = "山东恒信高科能源有限公司"; |
|
||||
/** |
|
||||
* 设备当前所在的一级区域 ID |
|
||||
*/ |
|
||||
private String firAreaId = "HXGK0001"; |
|
||||
/** |
|
||||
* 设备当前所在的一级区域 name |
|
||||
*/ |
|
||||
private String firAreaName = "恒信高科"; |
|
||||
|
|
||||
/** |
|
||||
* 设备当前所在的二级区域 ID |
|
||||
*/ |
|
||||
private String secondAreaId; |
|
||||
/** |
|
||||
* 设备当前所在的二级区域 name |
|
||||
*/ |
|
||||
private String secondAreaName; |
|
||||
/** |
|
||||
* X |
|
||||
*/ |
|
||||
private Double x; |
|
||||
/** |
|
||||
* Y |
|
||||
*/ |
|
||||
private Double y; |
|
||||
/** |
|
||||
* 是否移动 |
|
||||
*/ |
|
||||
private String move; |
|
||||
/** |
|
||||
* 定位时间 |
|
||||
*/ |
|
||||
private String dateTime; |
|
||||
/** |
|
||||
* 电量状态 |
|
||||
*/ |
|
||||
private String lowPowerStatus; |
|
||||
/** |
|
||||
* 电量 |
|
||||
*/ |
|
||||
private String power; |
|
||||
/** |
|
||||
* 定位时间 |
|
||||
*/ |
|
||||
private String uniqueId; |
|
||||
|
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class DeviceInfoIot { |
|
||||
/** |
|
||||
* 数据类型 |
|
||||
*/ |
|
||||
private String dataType ="position"; |
|
||||
/** |
|
||||
* 人员信息 |
|
||||
*/ |
|
||||
private DeviceInfoHx data; |
|
||||
} |
|
||||
@ -0,0 +1,96 @@ |
|||||
|
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
||||
|
|
||||
|
|
||||
|
|
||||
|
/* |
||||
|
请求数据: |
||||
|
JSON |
||||
|
[ |
||||
|
{ |
||||
|
"descript": "厂房大门温度", |
||||
|
"name": "温度计", |
||||
|
"code": "ModbusRTU@0edb5c08b9f0_/dev/ttyS0_1_10_3", |
||||
|
"max": "100", |
||||
|
"min": "0", |
||||
|
"type": "温度", |
||||
|
"unit": "°C" |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
|
||||
|
字段名 类型 说明 |
||||
|
descript String 描述 |
||||
|
name String 名称 |
||||
|
code String 系统唯一编码,请确认在当前节点中该编码不会重复 |
||||
|
max String 量程上限 如 100,不能为空 |
||||
|
min String 量程下限 如 0,不能为空 |
||||
|
type String 类型,如温度、湿度、压力、液位等等 |
||||
|
unit String 单位,若无则传空字符串 |
||||
|
* */ |
||||
|
|
||||
|
public class SensorDataRequestObj { |
||||
|
private String descript; |
||||
|
private String name; |
||||
|
private String code; |
||||
|
private String max; |
||||
|
private String min; |
||||
|
private String type; |
||||
|
private String unit; |
||||
|
|
||||
|
|
||||
|
public String getDescript() { |
||||
|
return descript; |
||||
|
} |
||||
|
|
||||
|
public void setDescript(String descript) { |
||||
|
this.descript = descript; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
public void setName(String name) { |
||||
|
this.name = name; |
||||
|
} |
||||
|
|
||||
|
public String getCode() { |
||||
|
return code; |
||||
|
} |
||||
|
|
||||
|
public void setCode(String code) { |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public String getMax() { |
||||
|
return max; |
||||
|
} |
||||
|
|
||||
|
public void setMax(String max) { |
||||
|
this.max = max; |
||||
|
} |
||||
|
|
||||
|
public String getMin() { |
||||
|
return min; |
||||
|
} |
||||
|
|
||||
|
public void setMin(String min) { |
||||
|
this.min = min; |
||||
|
} |
||||
|
|
||||
|
public String getType() { |
||||
|
return type; |
||||
|
} |
||||
|
|
||||
|
public void setType(String type) { |
||||
|
this.type = type; |
||||
|
} |
||||
|
|
||||
|
public String getUnit() { |
||||
|
return unit; |
||||
|
} |
||||
|
|
||||
|
public void setUnit(String unit) { |
||||
|
this.unit = unit; |
||||
|
} |
||||
|
} |
||||
@ -1,40 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class UserBaseInfo { |
|
||||
/** |
|
||||
* 企业容器id |
|
||||
*/ |
|
||||
private String containerId ="ningyanghuagongchany"; |
|
||||
/** |
|
||||
* 人员唯一标示 |
|
||||
*/ |
|
||||
private String userCode; |
|
||||
/** |
|
||||
* 人员姓名 |
|
||||
*/ |
|
||||
private String userName; |
|
||||
/** |
|
||||
* 联系电话 |
|
||||
*/ |
|
||||
private String userPhone; |
|
||||
/** |
|
||||
* 人员类型 |
|
||||
*/ |
|
||||
private String userType = "01"; |
|
||||
/** |
|
||||
* 企业编码 |
|
||||
*/ |
|
||||
private String userOrgCode = "370910170"; |
|
||||
/** |
|
||||
* 企业名称 |
|
||||
*/ |
|
||||
private String userOrgName = "山东恒信高科能源有限公司"; |
|
||||
/** |
|
||||
* 绑定设备唯一编码 |
|
||||
*/ |
|
||||
private String cardId; |
|
||||
|
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.domain; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
@Data |
|
||||
public class UserBaseInfoIot { |
|
||||
/** |
|
||||
* 数据类型 |
|
||||
*/ |
|
||||
private String dataType ="baseInfo"; |
|
||||
/** |
|
||||
* 人员信息 |
|
||||
*/ |
|
||||
private UserBaseInfo data; |
|
||||
} |
|
||||
@ -1,114 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.jobhandler; |
|
||||
|
|
||||
import cn.hutool.json.JSONUtil; |
|
||||
|
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.enums.UserType; |
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.AreaUserInfoHx; |
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.AreaUserInfoIot; |
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.UserBaseInfo; |
|
||||
import com.hxjt.dataupload.mqtt.MqttClient; |
|
||||
import com.xxl.job.core.context.XxlJobHelper; |
|
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.beans.factory.annotation.Value; |
|
||||
import org.springframework.http.ResponseEntity; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.springframework.web.client.RestTemplate; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
@Component |
|
||||
@Slf4j |
|
||||
public class AreaPersonInfo2MqttJob { |
|
||||
|
|
||||
@Resource |
|
||||
MqttClient mqttClient; |
|
||||
|
|
||||
@Value("${spring.mqtt.areaTopic:}") |
|
||||
private String areaTopic; |
|
||||
|
|
||||
@Value("${user.token.containerId:}") |
|
||||
private String containerId; |
|
||||
|
|
||||
@Resource |
|
||||
RestTemplate restTemplate; |
|
||||
|
|
||||
@Value("${area.data.url:}") |
|
||||
private String areaPersonUrl; |
|
||||
|
|
||||
@XxlJob("areaInfo2MqttJobHandler") |
|
||||
public void userBaseInfo2MqttJobHandler() throws Exception { |
|
||||
try { |
|
||||
XxlJobHelper.log("Area person info To Mqtt Job Handler Beginning."); |
|
||||
|
|
||||
ResponseEntity<Map> forEntity = restTemplate.getForEntity(areaPersonUrl, Map.class); |
|
||||
Map body = forEntity.getBody(); |
|
||||
List<Map<String,Object>> data = (List<Map<String,Object>>)body.get("data"); |
|
||||
log.info(">>>>>>>>>>>>>>>>>>>>>>area data size:"+data.size()); |
|
||||
data.forEach(alarmMap -> { |
|
||||
try { |
|
||||
AreaUserInfoIot areaUserInfoIot = new AreaUserInfoIot(); |
|
||||
AreaUserInfoHx areaUserInfoHx = new AreaUserInfoHx(); |
|
||||
Object areaId = alarmMap.get("areaId"); |
|
||||
areaUserInfoHx.setUniqueId(containerId + areaId); |
|
||||
areaUserInfoHx.setContainerId(containerId); |
|
||||
areaUserInfoHx.setOrgCode("91370921328482832M"); |
|
||||
areaUserInfoHx.setOrgName("山东恒信高科能源有限公司"); |
|
||||
areaUserInfoHx.setAreaId(areaId != null ? areaId.toString() : ""); |
|
||||
Object areaName = alarmMap.get("areaName"); |
|
||||
areaUserInfoHx.setAreaName(areaName != null ? areaName.toString() : ""); |
|
||||
Object upperLimit = alarmMap.get("upperLimit"); |
|
||||
areaUserInfoHx.setAreaPid(upperLimit != null ? upperLimit.toString() : ""); |
|
||||
Object workLevel = alarmMap.get("workLevel"); |
|
||||
areaUserInfoHx.setAreaPname(workLevel != null ? workLevel.toString() : ""); |
|
||||
List<Map<String,Object>> personList = (List<Map<String,Object>>)alarmMap.get("personList"); |
|
||||
log.info(">>>>>>>>>>>>>>>>>>>>>>person data size:"+personList.size()); |
|
||||
List<UserBaseInfo> users = new ArrayList<>(); |
|
||||
if(personList != null && personList.size()>0){ |
|
||||
areaUserInfoHx.setPersonNum(personList.size() + ""); |
|
||||
personList.forEach(p -> { |
|
||||
try { |
|
||||
UserBaseInfo userBaseInfo = new UserBaseInfo(); |
|
||||
Object empNo = p.get("empNo"); |
|
||||
userBaseInfo.setUserCode(empNo != null ? empNo.toString() : ""); |
|
||||
Object empName = p.get("empName"); |
|
||||
userBaseInfo.setUserName(empName != null ? empName.toString() : ""); |
|
||||
Object deviceNo = p.get("deviceNo"); |
|
||||
userBaseInfo.setCardId(deviceNo != null ? deviceNo.toString() : ""); |
|
||||
userBaseInfo.setUserOrgCode("91370921328482832M"); |
|
||||
userBaseInfo.setUserOrgName("山东恒信高科能源有限公司"); |
|
||||
Object specifictype = p.get("specifictype"); |
|
||||
String contentByCode = UserType.getContentByCode(specifictype != null ? specifictype.toString() : ""); |
|
||||
userBaseInfo.setUserType(contentByCode != null ? contentByCode : ""); |
|
||||
users.add(userBaseInfo); |
|
||||
} catch (Exception e) { |
|
||||
log.error(">>>>>>>>>>>>>>>>>>>>>>occur exception!"+e.getMessage()); |
|
||||
} |
|
||||
}); |
|
||||
} else { |
|
||||
areaUserInfoHx.setPersonNum("0"); |
|
||||
} |
|
||||
areaUserInfoHx.setPersonList(users); |
|
||||
areaUserInfoIot.setData(areaUserInfoHx); |
|
||||
areaUserInfoIot.setDataType("areaPersonAlarm"); |
|
||||
String jsonData = JSONUtil.toJsonStr(areaUserInfoIot); |
|
||||
log.info(jsonData); |
|
||||
mqttClient.publish(0, false,areaTopic, jsonData); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
log.error(">>>>>>>>>>>>>>>>>>>>>>occur exception!"+e.getMessage()); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
log.info(">>>>>>>>>>>>>>>>>>>>>>occur exception!"+e.getMessage()); |
|
||||
} |
|
||||
log.info(">>>>>>>>>>>>>>>Area person info mqtt push finished!"); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,97 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.jobhandler; |
|
||||
|
|
||||
import cn.hutool.core.util.ObjectUtil; |
|
||||
import cn.hutool.json.JSONUtil; |
|
||||
|
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.DeviceInfoHx; |
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.DeviceInfoIot; |
|
||||
import com.hxjt.dataupload.mqtt.MqttClient; |
|
||||
import com.xxl.job.core.context.XxlJobHelper; |
|
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.beans.factory.annotation.Value; |
|
||||
import org.springframework.http.ResponseEntity; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.springframework.web.client.RestTemplate; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
import java.math.BigDecimal; |
|
||||
import java.text.SimpleDateFormat; |
|
||||
import java.util.Date; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.UUID; |
|
||||
|
|
||||
/* |
|
||||
* @description: 定位信息推送 |
|
||||
* @author: ZhangRY |
|
||||
* @date: 2025/4/9 10:51 |
|
||||
* @param: null |
|
||||
* @return: null |
|
||||
**/ |
|
||||
@Component |
|
||||
@Slf4j |
|
||||
public class DeviceInfo2MqttJob { |
|
||||
|
|
||||
@Resource |
|
||||
MqttClient mqttClient; |
|
||||
|
|
||||
@Value("${spring.mqtt.deviceTopic:}") |
|
||||
private String deviceTopic; |
|
||||
|
|
||||
@Value("${user.token.containerId:}") |
|
||||
private String containerId; |
|
||||
|
|
||||
@Resource |
|
||||
RestTemplate restTemplate; |
|
||||
|
|
||||
@Value("${device.real.url:}") |
|
||||
private String deviceUrl; |
|
||||
|
|
||||
@XxlJob("deviceInfo2MqttJobHandler") |
|
||||
public void deviceInfo2MqttJobHandler() throws Exception { |
|
||||
try { |
|
||||
XxlJobHelper.log(" Device base info To Mqtt Job Handler Beginning."); |
|
||||
|
|
||||
ResponseEntity<Map> forEntity = restTemplate.getForEntity(deviceUrl, Map.class); |
|
||||
Map body = forEntity.getBody(); |
|
||||
Map data = (Map) body.get("data"); |
|
||||
List<Map<String,Object>> list = (List<Map<String,Object>>)data.get("list"); |
|
||||
list.forEach(deviceMap -> { |
|
||||
DeviceInfoIot deviceInfoIot = new DeviceInfoIot(); |
|
||||
DeviceInfoHx deviceInfo = new DeviceInfoHx(); |
|
||||
deviceInfo.setContainerId(containerId); |
|
||||
deviceInfo.setUniqueId(UUID.randomUUID().toString()); |
|
||||
Object deviceNo = deviceMap.get("deviceno"); |
|
||||
deviceInfo.setDeviceCode(deviceNo != null ? deviceNo.toString() : ""); |
|
||||
Object crossX = deviceMap.get("longitude"); |
|
||||
deviceInfo.setX(crossX != null ? new Double(crossX.toString()) : 0.0); |
|
||||
Object crossY = deviceMap.get("latitude"); |
|
||||
deviceInfo.setY(crossY != null ? new Double(crossY.toString()) : 0.0); |
|
||||
long dateTime = Long.valueOf(String.valueOf(deviceMap.get("datetime"))); |
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
||||
Date date = new Date(dateTime); |
|
||||
String formattedDate = sdf.format(date); |
|
||||
deviceInfo.setDateTime(formattedDate != null ? formattedDate : ""); |
|
||||
Object electric = deviceMap.get("electric"); |
|
||||
BigDecimal electricBigDecimal = new BigDecimal(ObjectUtil.isEmpty(electric) ? "-1" : String.valueOf(electric)); |
|
||||
BigDecimal criticalValue = new BigDecimal("3.7"); |
|
||||
deviceInfo.setPower(electric != null ? electric.toString() : ""); |
|
||||
deviceInfo.setLowPowerStatus(electricBigDecimal != null && electricBigDecimal.compareTo(criticalValue) >= 0 ? "0": "1"); |
|
||||
deviceInfoIot.setData(deviceInfo); |
|
||||
Object islxsign = deviceMap.get("islxsign"); |
|
||||
deviceInfo.setMove(islxsign != null ? "0".equals(islxsign) ? "1" : "0" : ""); |
|
||||
deviceInfoIot.setDataType("position"); |
|
||||
String jsonData = JSONUtil.toJsonStr(deviceInfoIot); |
|
||||
log.info(jsonData); |
|
||||
XxlJobHelper.log(jsonData); |
|
||||
mqttClient.publish(0, false, deviceTopic, jsonData); |
|
||||
}); |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
log.info(">>>>>>>>>>>>>>>Device base info mqtt push finished!"); |
|
||||
XxlJobHelper.log(">>>>>>>>>>>>>>>Device base info mqtt push finished!"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,179 +0,0 @@ |
|||||
package com.hxjt.dataupload.jobhandler.mqtt.job.user.jobhandler; |
|
||||
|
|
||||
import cn.hutool.crypto.SecureUtil; |
|
||||
import cn.hutool.json.JSONArray; |
|
||||
import cn.hutool.json.JSONObject; |
|
||||
import cn.hutool.json.JSONUtil; |
|
||||
|
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.UserBaseInfo; |
|
||||
import com.hxjt.dataupload.jobhandler.mqtt.job.user.domain.UserBaseInfoIot; |
|
||||
import com.hxjt.dataupload.mqtt.MqttClient; |
|
||||
import com.xxl.job.core.context.XxlJobHelper; |
|
||||
import com.xxl.job.core.handler.annotation.XxlJob; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.apache.http.client.methods.CloseableHttpResponse; |
|
||||
import org.apache.http.client.methods.HttpPost; |
|
||||
import org.apache.http.entity.StringEntity; |
|
||||
import org.apache.http.impl.client.CloseableHttpClient; |
|
||||
import org.apache.http.impl.client.HttpClients; |
|
||||
import org.apache.http.util.EntityUtils; |
|
||||
import org.springframework.beans.factory.annotation.Value; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
|
|
||||
/* |
|
||||
* @description: 人员信息推送 |
|
||||
* @author: ZhangRY |
|
||||
* @date: 2025/4/9 10:51 |
|
||||
* @param: null |
|
||||
* @return: null |
|
||||
**/ |
|
||||
@Component |
|
||||
@Slf4j |
|
||||
public class UserBaseInfo2MqttJob { |
|
||||
|
|
||||
@Resource |
|
||||
MqttClient mqttClient; |
|
||||
|
|
||||
@Value("${spring.mqtt.personTopic:}") |
|
||||
private String personTopic; |
|
||||
|
|
||||
@Value("${user.token.url:}") |
|
||||
private String tokenUrl; |
|
||||
|
|
||||
@Value("${user.token.username:}") |
|
||||
private String username; |
|
||||
|
|
||||
@Value("${user.token.password:}") |
|
||||
private String password; |
|
||||
|
|
||||
@Value("${user.token.orgin:}") |
|
||||
private String origin; |
|
||||
|
|
||||
@Value("${user.token.verCode:}") |
|
||||
private String verCode; |
|
||||
|
|
||||
@Value("${user.token.urlPerson:}") |
|
||||
private String urlPerson; |
|
||||
|
|
||||
@Value("${user.token.containerId:}") |
|
||||
private String containerId; |
|
||||
|
|
||||
@XxlJob("userBaseInfo2MqttJobHandler") |
|
||||
public void userBaseInfo2MqttJobHandler() throws Exception { |
|
||||
try { |
|
||||
XxlJobHelper.log(" User base info To Mqtt Job Handler Beginning."); |
|
||||
|
|
||||
// 创建httpclient对象
|
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
||||
|
|
||||
//创建请求对象
|
|
||||
HttpPost httpPost = new HttpPost(tokenUrl); |
|
||||
|
|
||||
JSONObject jsonObj = new JSONObject(); |
|
||||
jsonObj.putOnce("username", username); |
|
||||
jsonObj.putOnce("password", password); |
|
||||
|
|
||||
StringEntity entity = new StringEntity(jsonObj.toString()); |
|
||||
//指定请求编码方式
|
|
||||
entity.setContentEncoding("utf-8"); |
|
||||
//数据格式
|
|
||||
entity.setContentType("application/json"); |
|
||||
httpPost.setEntity(entity); |
|
||||
httpPost.setHeader("Origin", origin); |
|
||||
httpPost.setHeader("User-Agent", "sdhxgk"); |
|
||||
|
|
||||
//发送请求
|
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost); |
|
||||
//解析返回结果
|
|
||||
int statusCode = response.getStatusLine().getStatusCode(); |
|
||||
log.info("-----------查询token响应码为:" + statusCode); |
|
||||
XxlJobHelper.log("-----------查询token响应码为:" + statusCode); |
|
||||
if (200 == statusCode) { |
|
||||
org.apache.http.HttpEntity entityRes = response.getEntity(); |
|
||||
String body = EntityUtils.toString(entityRes); |
|
||||
|
|
||||
log.info("-----------查询token响应数据为:" + statusCode); |
|
||||
XxlJobHelper.log("-----------查询token响应数据为:" + statusCode); |
|
||||
|
|
||||
JSONObject jsonObject = JSONUtil.parseObj(body); |
|
||||
JSONObject data = JSONUtil.parseObj(jsonObject.get("data")); |
|
||||
String token = data.get("token").toString(); |
|
||||
System.out.println(token); |
|
||||
String number = data.get("number").toString(); |
|
||||
System.out.println(number); |
|
||||
String secNumber = SecureUtil.md5(number); |
|
||||
String secverCode = SecureUtil.md5(verCode); |
|
||||
String twoSec = SecureUtil.md5(secNumber + secverCode); |
|
||||
String threeSec = SecureUtil.md5(twoSec + verCode); |
|
||||
|
|
||||
HttpPost httpPostPerson = new HttpPost(urlPerson); |
|
||||
|
|
||||
|
|
||||
StringEntity entityEmpty = new StringEntity(""); |
|
||||
//指定请求编码方式
|
|
||||
entityEmpty.setContentEncoding("utf-8"); |
|
||||
//数据格式
|
|
||||
entityEmpty.setContentType("application/json"); |
|
||||
httpPostPerson.setEntity(entityEmpty); |
|
||||
httpPostPerson.setHeader("Origin", origin); |
|
||||
httpPostPerson.setHeader("User-Agent", "sdhxgk"); |
|
||||
httpPostPerson.setHeader("token", token); |
|
||||
httpPostPerson.setHeader("number", threeSec); |
|
||||
|
|
||||
//发送请求
|
|
||||
CloseableHttpResponse resPerson = httpClient.execute(httpPostPerson); |
|
||||
//解析返回结果
|
|
||||
int staPersonCode = resPerson.getStatusLine().getStatusCode(); |
|
||||
log.info("-----------查询人员响应码为:" + staPersonCode); |
|
||||
XxlJobHelper.log("-----------查询人员响应码为:" + staPersonCode); |
|
||||
|
|
||||
if (200 == staPersonCode) { |
|
||||
org.apache.http.HttpEntity entPersonRes = resPerson.getEntity(); |
|
||||
String personBody = EntityUtils.toString(entPersonRes); |
|
||||
log.info("-----------查询人员响应数据为:" + personBody); |
|
||||
XxlJobHelper.log("-----------查询人员响应数据为:" + personBody); |
|
||||
resPerson.close(); |
|
||||
JSONObject jsonObjPerson = JSONUtil.parseObj(personBody); |
|
||||
System.out.println(jsonObjPerson); |
|
||||
|
|
||||
JSONArray parseArray = JSONUtil.parseArray(jsonObjPerson.get("data")); |
|
||||
parseArray.forEach(obj -> { |
|
||||
JSONObject person = JSONUtil.parseObj(obj); |
|
||||
Object deviceNo = person.get("cardld"); |
|
||||
Object personName = person.get("empName"); |
|
||||
Object empNo = person.get("userCode"); |
|
||||
// Object specifictype = person.get("userType");
|
|
||||
Object userPhone = person.get("userPhone"); |
|
||||
// Object workUnit = person.get("userOrgName");
|
|
||||
// Object workUnitCode = person.get("userOrgCode");
|
|
||||
|
|
||||
UserBaseInfoIot userBaseInfoIot = new UserBaseInfoIot(); |
|
||||
UserBaseInfo userBaseInfo = new UserBaseInfo(); |
|
||||
userBaseInfo.setContainerId(containerId); |
|
||||
userBaseInfo.setCardId(deviceNo != null ? deviceNo.toString() : null); |
|
||||
userBaseInfo.setUserPhone(userPhone != null ? userPhone.toString() : null); |
|
||||
userBaseInfo.setUserName(personName != null ? personName.toString() : null); |
|
||||
userBaseInfo.setUserCode(empNo != null ? empNo.toString() : null); |
|
||||
// userBaseInfo.setUserType(specifictype != null ? specifictype.toString() : null);
|
|
||||
// userBaseInfo.setUserOrgName(workUnit != null ? workUnit.toString() : null);
|
|
||||
// userBaseInfo.setUserOrgCode(workUnitCode != null ? workUnitCode.toString() : null);
|
|
||||
userBaseInfoIot.setData(userBaseInfo); |
|
||||
userBaseInfoIot.setDataType("baseInfo"); |
|
||||
String jsonData = JSONUtil.toJsonStr(userBaseInfoIot); |
|
||||
XxlJobHelper.log("mqtt push data : " + jsonData); |
|
||||
mqttClient.publish(0, false, personTopic, jsonData); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
//关闭资源
|
|
||||
response.close(); |
|
||||
httpClient.close(); |
|
||||
} catch (Exception e) { |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
log.info(">>>>>>>>>>>>>>>mqtt push finished!"); |
|
||||
XxlJobHelper.log(">>>>>>>>>>>>>>>mqtt push finished!"); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue