Merge branch 'master' of http://47.115.223.229:8888/yangjun/hldy_yunwei_java
# Conflicts: # nursing-unit-iot/nu-iot-biz/src/main/java/com/nu/modules/dingshuo/electricity/utils/MqttConfig.java # nursing-unit-iot/nu-iot-biz/src/main/java/com/nu/modules/dingshuo/electricity/utils/MqttMessageHandler.java # nursing-unit-iot/nu-iot-biz/src/main/java/com/nu/modules/dingshuo/electricity/utils/MqttPublisherParams.java
This commit is contained in:
commit
4124e58b10
|
|
@ -44,33 +44,46 @@ public class DsElectricityMeterController extends JeecgController<DsElectricityM
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public Result<String> add(@RequestBody DsElectricityMeter dsElectricityMeter) {
|
||||
public Result<?> add(@RequestBody DsElectricityMeter dsElectricityMeter) {
|
||||
return service.add(dsElectricityMeter);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
public Result<String> delete(@RequestBody DsElectricityMeter dsElectricityMeter) {
|
||||
public Result<?> delete(@RequestBody DsElectricityMeter dsElectricityMeter) {
|
||||
return service.delete(dsElectricityMeter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
* 清零
|
||||
* @param dsElectricityMeter
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/eleReset")
|
||||
public Result<String> eleReset(DsElectricityMeter dsElectricityMeter) {
|
||||
return service.eleReset(dsElectricityMeter);
|
||||
service.eleReset(dsElectricityMeter);
|
||||
return Result.OK("清零中,请1分钟后刷新页面");
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉闸、合闸
|
||||
* 拉闸
|
||||
* @param dsElectricityMeter
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/eleControl")
|
||||
public Result<String> eleControl(DsElectricityMeter dsElectricityMeter) {
|
||||
return service.eleControl(dsElectricityMeter);
|
||||
@GetMapping(value = "/eleCutOff")
|
||||
public Result<String> eleCutOff(DsElectricityMeter dsElectricityMeter) {
|
||||
service.eleCutOff(dsElectricityMeter);
|
||||
return Result.OK("拉闸中,请1分钟后刷新页面");
|
||||
}
|
||||
|
||||
/**
|
||||
* 合闸
|
||||
* @param dsElectricityMeter
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/eleConnected")
|
||||
public Result<String> eleConnected(DsElectricityMeter dsElectricityMeter) {
|
||||
service.eleConnected(dsElectricityMeter);
|
||||
return Result.OK("合闸中,请1分钟后刷新页面");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,7 +93,8 @@ public class DsElectricityMeterController extends JeecgController<DsElectricityM
|
|||
*/
|
||||
@GetMapping(value = "/eleRead")
|
||||
public Result<String> eleRead(DsElectricityMeter dsElectricityMeter) {
|
||||
return service.eleRead(dsElectricityMeter);
|
||||
service.eleRead(dsElectricityMeter);
|
||||
return Result.OK("抄表中,请1分钟后重新查询");
|
||||
}
|
||||
|
||||
@AutoLog(value = "修改电表信息")
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public class DsElectricityMeter implements Serializable {
|
|||
private String remark;
|
||||
private String izAllocate;//是否分配
|
||||
private String dimension;//设备维度
|
||||
private String delFlag;//删除标识 0正常 1删除
|
||||
|
||||
private String nuId;//护理单元ID
|
||||
private String nuName;//护理单元
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
a.iz_allocate,
|
||||
a.dimension
|
||||
from nu_iot_ds_electricity_meter a
|
||||
<where>
|
||||
where a.del_flag = '0'
|
||||
<if test="params.sn != null and params.sn != ''">
|
||||
AND a.sn = #{params.sn}
|
||||
</if>
|
||||
|
|
@ -42,7 +42,6 @@
|
|||
<if test="params.izAllocate != null and params.izAllocate != ''">
|
||||
AND a.iz_allocate = #{params.izAllocate}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="findAllList" parameterType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter" resultType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter">
|
||||
|
|
@ -63,6 +62,7 @@
|
|||
a.iz_allocate,
|
||||
a.dimension
|
||||
from nu_iot_ds_electricity_meter a
|
||||
where a.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="getElectricityMeter" parameterType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter" resultType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter">
|
||||
|
|
@ -82,12 +82,16 @@
|
|||
old_depart_id as oldDepartId,
|
||||
old_depart_name as oldDepartName,
|
||||
iz_allocate,
|
||||
dimension
|
||||
dimension,
|
||||
del_flag
|
||||
from nu_iot_ds_electricity_meter
|
||||
<where>
|
||||
<if test="sn != null and sn != ''">
|
||||
AND sn = #{sn}
|
||||
</if>
|
||||
<if test="id != null and id != ''">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
|
@ -97,22 +101,25 @@
|
|||
remark,
|
||||
iz_allocate,
|
||||
dimension,
|
||||
create_time
|
||||
create_time,
|
||||
del_flag
|
||||
)
|
||||
values(
|
||||
#{sn},
|
||||
#{remark},
|
||||
'N',
|
||||
'区域维度',
|
||||
now()
|
||||
now(),
|
||||
'0'
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateElectricty" parameterType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter">
|
||||
update nu_iot_ds_electricity_meter
|
||||
set
|
||||
ele_value = #{eleValue},
|
||||
relay_state = #{relayState},
|
||||
remark = #{remark},
|
||||
read_time = #{readTime},
|
||||
update_time = now()
|
||||
<where>
|
||||
<if test="sn != null and sn != ''">
|
||||
|
|
@ -185,7 +192,7 @@
|
|||
a.dimension
|
||||
from nu_iot_ds_electricity_meter a
|
||||
left join nu_base_info c on a.nu_id = c.nu_id
|
||||
<where>
|
||||
where a.del_flag = '0'
|
||||
<if test="params.sn != null and params.sn != ''">
|
||||
AND a.sn LIKE concat('%',#{params.sn},'%')
|
||||
</if>
|
||||
|
|
@ -207,7 +214,6 @@
|
|||
AND a.depart_server_url != #{params.departServerUrl}
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="findDepartList" parameterType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter" resultType="com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter">
|
||||
|
|
@ -216,6 +222,7 @@
|
|||
depart_name as departName
|
||||
from nu_iot_ds_electricity_meter
|
||||
where depart_id is not null
|
||||
and del_flag = '0'
|
||||
<if test="departServerUrl != null and departServerUrl != ''">
|
||||
<if test="dataType != null and dataType == 'source'">
|
||||
AND depart_server_url != #{departServerUrl}
|
||||
|
|
@ -232,6 +239,7 @@
|
|||
nu_name as nuName
|
||||
from nu_iot_ds_electricity_meter
|
||||
where nu_id is not null
|
||||
and del_flag = '0'
|
||||
<if test="departId != null and departId != ''">
|
||||
AND depart_id = #{departId}
|
||||
</if>
|
||||
|
|
@ -266,7 +274,8 @@
|
|||
a.dimension
|
||||
from nu_iot_ds_electricity_meter a
|
||||
left join nu_base_info c on a.nu_id = c.nu_id
|
||||
where a.depart_server_url = #{params.departServerUrl}
|
||||
where a.del_flag = '0'
|
||||
and a.depart_server_url = #{params.departServerUrl}
|
||||
<if test="params.sn != null and params.sn != ''">
|
||||
AND a.sn LIKE concat('%',#{params.sn},'%')
|
||||
</if>
|
||||
|
|
|
|||
|
|
@ -11,16 +11,19 @@ import java.util.Map;
|
|||
|
||||
public interface IDsElectricityMeterService extends IService<DsElectricityMeter> {
|
||||
IPage<DsElectricityMeter> findPage(Page<DsElectricityMeter> page, DsElectricityMeter dsElectricityMeter);
|
||||
Result<String> add(DsElectricityMeter dsElectricityMeter);
|
||||
Result<String> delete(DsElectricityMeter dsElectricityMeter);
|
||||
Result<?> add(DsElectricityMeter dsElectricityMeter);
|
||||
Result<?> delete(DsElectricityMeter dsElectricityMeter);
|
||||
|
||||
List<DsElectricityMeter> findAllList();
|
||||
void updateValue(DsElectricityMeter dsElectricityMeter);
|
||||
void updateRelayState(DsElectricityMeter dsElectricityMeter);
|
||||
|
||||
Result<String> eleReset(DsElectricityMeter dsElectricityMeter);
|
||||
Result<String> eleControl(DsElectricityMeter dsElectricityMeter);
|
||||
Result<String> eleRead(DsElectricityMeter dsElectricityMeter);
|
||||
void eleReset(DsElectricityMeter dsElectricityMeter);
|
||||
void eleCutOff(DsElectricityMeter dsElectricityMeter);
|
||||
void eleConnected(DsElectricityMeter dsElectricityMeter);
|
||||
void eleRead(DsElectricityMeter dsElectricityMeter);
|
||||
|
||||
void processReceivedMessage(String payload);
|
||||
|
||||
void syncElectricity(String dataSourceCode, DsElectricityMeter dsElectricityMeter);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.nu.modules.dingshuo.electricity.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
|
@ -10,6 +12,8 @@ import com.nu.dto.IotElectricityMeterMQDto;
|
|||
import com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter;
|
||||
import com.nu.modules.dingshuo.electricity.mapper.DsElectricityMeterMapper;
|
||||
import com.nu.modules.dingshuo.electricity.service.IDsElectricityMeterService;
|
||||
import com.nu.modules.dingshuo.electricity.utils.MqttMessageHandler;
|
||||
import com.nu.modules.dingshuo.electricity.utils.MqttPublisherParams;
|
||||
import com.nu.modules.syncLog.entity.SyncBizLog;
|
||||
import com.nu.modules.syncLog.entity.SyncLog;
|
||||
import com.nu.modules.syncLog.service.ISyncBizLogService;
|
||||
|
|
@ -18,6 +22,7 @@ import com.nu.utils.RabbitMQUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.utils.UuidUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -43,23 +48,45 @@ public class DsElectricityMeterServiceImpl extends ServiceImpl<DsElectricityMete
|
|||
@Autowired
|
||||
private DsElectricityMeterServiceImpl syncImpl;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private MqttMessageHandler mqttMessageHandler;
|
||||
|
||||
@Autowired
|
||||
private MqttPublisherParams mqttPublisherParams;
|
||||
|
||||
@Override
|
||||
public IPage<DsElectricityMeter> findPage(Page<DsElectricityMeter> page, DsElectricityMeter dsElectricityMeter){
|
||||
return baseMapper.findPage(page,dsElectricityMeter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> add(DsElectricityMeter dsElectricityMeter){
|
||||
public Result<?> add(DsElectricityMeter dsElectricityMeter){
|
||||
DsElectricityMeter entity = baseMapper.getElectricityMeter(dsElectricityMeter);
|
||||
if(entity!=null){
|
||||
return Result.OK("添加失败,设备序号已存在!");
|
||||
if(entity.getDelFlag().equals("0")){
|
||||
return Result.error("添加失败,设备已存在!");
|
||||
}else{
|
||||
DsElectricityMeter dem = new DsElectricityMeter();
|
||||
dem.setId(entity.getId());
|
||||
dem.setDelFlag("0");
|
||||
baseMapper.updateById(dem);
|
||||
}
|
||||
}else{
|
||||
baseMapper.insertElectricty(dsElectricityMeter);
|
||||
}
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
try {
|
||||
mqttMessageHandler.subscribeUplinkMessage(deviceId);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
baseMapper.insertElectricty(dsElectricityMeter);
|
||||
return Result.OK("添加成功!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> delete(DsElectricityMeter dsElectricityMeter){
|
||||
public Result<?> delete(DsElectricityMeter dsElectricityMeter){
|
||||
DsElectricityMeter entity = baseMapper.getElectricityMeter(dsElectricityMeter);
|
||||
if(entity!=null){
|
||||
String izAllocate = entity.getIzAllocate();
|
||||
|
|
@ -67,8 +94,17 @@ public class DsElectricityMeterServiceImpl extends ServiceImpl<DsElectricityMete
|
|||
return Result.OK("设备已分配,无法删除!");
|
||||
}
|
||||
}
|
||||
baseMapper.deleteById(dsElectricityMeter.getId());
|
||||
return Result.OK("添加成功!");
|
||||
DsElectricityMeter dem = new DsElectricityMeter();
|
||||
dem.setId(entity.getId());
|
||||
dem.setDelFlag("1");
|
||||
baseMapper.updateById(dem);
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
try {
|
||||
mqttMessageHandler.unsubscribeUplinkMessage(deviceId);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -86,36 +122,136 @@ public class DsElectricityMeterServiceImpl extends ServiceImpl<DsElectricityMete
|
|||
baseMapper.updateRelayState(dsElectricityMeter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零
|
||||
*/
|
||||
@Override
|
||||
public Result<String> eleReset(DsElectricityMeter dsElectricityMeter){
|
||||
|
||||
return Result.OK("清零中,请1分钟后刷新页面");
|
||||
public void eleReset(DsElectricityMeter dsElectricityMeter){
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
MqttMessageHandler.DownlinkMessage message = mqttPublisherParams.getResetParams(deviceId);
|
||||
try {
|
||||
mqttMessageHandler.publishDownlinkMessage(deviceId,message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉合闸
|
||||
*/
|
||||
@Override
|
||||
public Result<String> eleControl(DsElectricityMeter dsElectricityMeter){
|
||||
Integer type = dsElectricityMeter.getType();
|
||||
public void eleCutOff(DsElectricityMeter dsElectricityMeter){
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
MqttMessageHandler.DownlinkMessage message = mqttPublisherParams.getCutOffParams(deviceId);
|
||||
try {
|
||||
mqttMessageHandler.publishDownlinkMessage(deviceId,message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(type.equals(10)){
|
||||
return Result.OK("拉闸中,请1分钟后刷新页面");
|
||||
}else{
|
||||
return Result.OK("合闸中,请1分钟后刷新页面");
|
||||
@Override
|
||||
public void eleConnected(DsElectricityMeter dsElectricityMeter){
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
MqttMessageHandler.DownlinkMessage message = mqttPublisherParams.getConnectedParams(deviceId);
|
||||
try {
|
||||
mqttMessageHandler.publishDownlinkMessage(deviceId,message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eleRead(DsElectricityMeter dsElectricityMeter){
|
||||
String deviceId = dsElectricityMeter.getSn();
|
||||
MqttMessageHandler.DownlinkMessage message = mqttPublisherParams.getReadingParams(deviceId);
|
||||
try {
|
||||
mqttMessageHandler.publishDownlinkMessage(deviceId,message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抄电表
|
||||
* mqtt收到消息,并处理
|
||||
*/
|
||||
@Override
|
||||
public Result<String> eleRead(DsElectricityMeter dsElectricityMeter){
|
||||
|
||||
return Result.OK("抄表中,请1分钟后重新查询");
|
||||
public void processReceivedMessage(String message){
|
||||
JSONObject jsonObject = new JSONObject(message);
|
||||
JSONObject header = (JSONObject)jsonObject.get("header");
|
||||
JSONObject payload = (JSONObject)jsonObject.get("payload");
|
||||
String name = header.getStr("name");
|
||||
String sn = header.getStr("ID");
|
||||
switch (name){
|
||||
case "901":
|
||||
// 抄表
|
||||
String EgT901 = payload.getStr("EgT");//总有功电能
|
||||
String RelyF901 = payload.getStr("RelyF");//表状态
|
||||
String eleValue901 = "0";
|
||||
String relayState901 = "0";
|
||||
if(RelyF901.equals("ON")){
|
||||
relayState901 = "1";
|
||||
}
|
||||
if(EgT901.toLowerCase().indexOf("kwh")>0){
|
||||
eleValue901 = EgT901.substring(0,EgT901.toLowerCase().indexOf("kwh"));
|
||||
}
|
||||
DsElectricityMeter entity901 = new DsElectricityMeter();
|
||||
entity901.setSn(sn);
|
||||
entity901.setEleValue(eleValue901);
|
||||
entity901.setRelayState(relayState901);
|
||||
entity901.setReadTime(DateUtil.now());
|
||||
baseMapper.updateElectricty(entity901);
|
||||
break;
|
||||
case "902":
|
||||
// 拉闸合闸
|
||||
String result902 = payload.getStr("result");//拉合闸执行结果
|
||||
if(result902.equals("SUCCESS")){
|
||||
// //拉合闸成功,直接抄表,获取表状态
|
||||
DsElectricityMeter dme902 = new DsElectricityMeter();
|
||||
dme902.setSn(sn);
|
||||
// eleRead(dme902);
|
||||
DsElectricityMeter entity902 = baseMapper.getElectricityMeter(dme902);
|
||||
if(entity902!=null){
|
||||
if(entity902.getRelayState().equals("0")){
|
||||
entity902.setRelayState("1");
|
||||
}else{
|
||||
entity902.setRelayState("0");
|
||||
}
|
||||
baseMapper.updateRelayState(entity902);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "904":
|
||||
// 参数配置,包括清零
|
||||
String mtype904 = payload.getStr("mtype");//mtype:200 TCP信息;206 表复位重启;208 表清零
|
||||
String dcode904 = payload.getStr("dcode");
|
||||
if(dcode904.equals("SUCCESS")){
|
||||
if(mtype904.equals("208")){
|
||||
DsElectricityMeter entity904 = new DsElectricityMeter();
|
||||
entity904.setSn(sn);
|
||||
entity904.setEleValue("0");
|
||||
entity904.setReadTime(DateUtil.now());
|
||||
baseMapper.updateValue(entity904);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "601":
|
||||
// 定时主动上报表计数据
|
||||
String EgT601 = payload.getStr("EgT");//总有功电能
|
||||
String RelyF601 = payload.getStr("RelyF");//表状态
|
||||
String eleValue601 = "0";
|
||||
String relayState601 = "0";
|
||||
if(RelyF601.equals("ON")){
|
||||
relayState601 = "1";
|
||||
}
|
||||
if(EgT601.toLowerCase().indexOf("kwh")>0){
|
||||
eleValue601 = EgT601.substring(0,EgT601.toLowerCase().indexOf("kwh"));
|
||||
}
|
||||
DsElectricityMeter entity601 = new DsElectricityMeter();
|
||||
entity601.setSn(sn);
|
||||
entity601.setEleValue(eleValue601);
|
||||
entity601.setRelayState(relayState601);
|
||||
entity601.setReadTime(DateUtil.now());
|
||||
baseMapper.updateElectricty(entity601);
|
||||
break;
|
||||
case "701":
|
||||
// 定时主动上报事件数据
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,8 +279,6 @@ public class DsElectricityMeterServiceImpl extends ServiceImpl<DsElectricityMete
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 抄表同步到业务系统
|
||||
* @param dsElectricityMeter
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package com.nu.modules.dingshuo.electricity.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 配置 MQTT 连接
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "mqtt")
|
||||
public class MqttConfig {
|
||||
|
||||
@Value("${mqtt.broker-url}")
|
||||
private String brokerUrl;
|
||||
|
||||
@Value("${mqtt.client-id}")
|
||||
private String clientId;
|
||||
|
||||
@Value("${mqtt.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${mqtt.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${mqtt.clean-session}")
|
||||
private boolean cleanSession;
|
||||
|
||||
@Value("${mqtt.connection-timeout}")
|
||||
private int connectionTimeout;
|
||||
|
||||
@Value("${mqtt.keep-alive-interval}")
|
||||
private int keepAliveInterval;
|
||||
|
||||
@Bean
|
||||
public MqttConnectOptions mqttConnectOptions() {
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setCleanSession(cleanSession);
|
||||
options.setConnectionTimeout(connectionTimeout);
|
||||
options.setKeepAliveInterval(keepAliveInterval);
|
||||
options.setAutomaticReconnect(true);
|
||||
|
||||
if (username != null && !username.isEmpty()) {
|
||||
options.setUserName(username);
|
||||
}
|
||||
if (password != null && !password.isEmpty()) {
|
||||
options.setPassword(password.toCharArray());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MqttClient mqttClient() throws MqttException {
|
||||
String mqttClientId = clientId + UUID.randomUUID();
|
||||
MqttClient client = new MqttClient(brokerUrl, mqttClientId, new MemoryPersistence());
|
||||
client.connect(mqttConnectOptions());
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.nu.modules.dingshuo.electricity.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nu.modules.dingshuo.electricity.entity.DsElectricityMeter;
|
||||
import com.nu.modules.dingshuo.electricity.service.IDsElectricityMeterService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MqttMessageHandler implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private MqttClient mqttClient;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IDsElectricityMeterService dsElectricityMeterService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 发送下行消息(发布1)
|
||||
* @param deviceId 设备ID
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public void publishDownlinkMessage(String deviceId, MqttMessageHandler.DownlinkMessage message) throws Exception {
|
||||
String topic = "BY/dn/" + deviceId;
|
||||
String payload = objectMapper.writeValueAsString(message);
|
||||
|
||||
MqttMessage mqttMessage = new MqttMessage(payload.getBytes());
|
||||
mqttMessage.setQos(0);
|
||||
mqttMessage.setRetained(false);
|
||||
log.info("发布 - 主题: {}, 消息: {}", topic, payload);
|
||||
mqttClient.publish(topic, mqttMessage);
|
||||
log.info("发布成功 - 主题: {}, 消息: {}", topic, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅上行消息(接收2)
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
public void subscribeUplinkMessage(String deviceId) throws MqttException {
|
||||
String topic = "BY/up/" + deviceId;
|
||||
mqttClient.subscribe(topic, 0, new IMqttMessageListener() {
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
String payload = new String(message.getPayload());
|
||||
log.info("收到上行消息, 主题: {}, 内容: {}", topic, payload);
|
||||
// 解析消息
|
||||
dsElectricityMeterService.processReceivedMessage(payload);
|
||||
}
|
||||
});
|
||||
log.info("已订阅上行主题: {}", topic);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订阅上行消息
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
public void unsubscribeUplinkMessage(String deviceId) throws MqttException {
|
||||
String topic = "BY/up/" + deviceId;
|
||||
log.info("取消已订阅上行主题: {}", topic);
|
||||
mqttClient.unsubscribe(topic);
|
||||
log.info("取消已订阅上行主题成功: {}", topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
// 启动时订阅示例
|
||||
List<DsElectricityMeter> list = dsElectricityMeterService.findAllList();
|
||||
for(int i=0;i<list.size();i++){
|
||||
DsElectricityMeter dem = list.get(i);
|
||||
subscribeUplinkMessage(dem.getSn());
|
||||
}
|
||||
log.info("MQTT客户端启动完成");
|
||||
}
|
||||
|
||||
// 下行消息实体类
|
||||
@Data
|
||||
public static class DownlinkMessage {
|
||||
private Header header;
|
||||
private Map<String, Object> payload = new HashMap<>();
|
||||
|
||||
@Data
|
||||
public static class Header {
|
||||
private String name;
|
||||
private String ID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.nu.modules.dingshuo.electricity.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 发布命令参数
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MqttPublisherParams {
|
||||
|
||||
/**
|
||||
* 获取抄表参数
|
||||
* @return
|
||||
*/
|
||||
public MqttMessageHandler.DownlinkMessage getReadingParams(String deviceId){
|
||||
MqttMessageHandler.DownlinkMessage message = new MqttMessageHandler.DownlinkMessage();
|
||||
MqttMessageHandler.DownlinkMessage.Header header = new MqttMessageHandler.DownlinkMessage.Header();
|
||||
header.setName("801"); //801:表⽰读取表计数据
|
||||
header.setID(deviceId);
|
||||
message.setHeader(header);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("mtype", "101"); //"101"对应上⾏数据中的总有功电量
|
||||
message.setPayload(payload);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉闸
|
||||
* @return
|
||||
*/
|
||||
public MqttMessageHandler.DownlinkMessage getCutOffParams(String deviceId){
|
||||
MqttMessageHandler.DownlinkMessage message = new MqttMessageHandler.DownlinkMessage();
|
||||
MqttMessageHandler.DownlinkMessage.Header header = new MqttMessageHandler.DownlinkMessage.Header();
|
||||
header.setName("802"); //802:表⽰拉合闸命令
|
||||
header.setID(deviceId);
|
||||
message.setHeader(header);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("mtype", "OFF"); //mtype:表⽰信息类型;ON---合闸;OFF---拉闸;KEEPON--保电;KEEPOFF--保电取消
|
||||
payload.put("passwd", "02123456"); //"101"对应上⾏数据中的总有功电量
|
||||
message.setPayload(payload);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合闸
|
||||
* @return
|
||||
*/
|
||||
public MqttMessageHandler.DownlinkMessage getConnectedParams(String deviceId){
|
||||
MqttMessageHandler.DownlinkMessage message = new MqttMessageHandler.DownlinkMessage();
|
||||
MqttMessageHandler.DownlinkMessage.Header header = new MqttMessageHandler.DownlinkMessage.Header();
|
||||
header.setName("802"); //802:表⽰拉合闸命令
|
||||
header.setID(deviceId);
|
||||
message.setHeader(header);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("mtype", "ON"); //mtype:表⽰信息类型;ON---合闸;OFF---拉闸;KEEPON--保电;KEEPOFF--保电取消
|
||||
payload.put("passwd", "02123456"); //"101"对应上⾏数据中的总有功电量
|
||||
message.setPayload(payload);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清零
|
||||
* @return
|
||||
*/
|
||||
public MqttMessageHandler.DownlinkMessage getResetParams(String deviceId){
|
||||
MqttMessageHandler.DownlinkMessage message = new MqttMessageHandler.DownlinkMessage();
|
||||
MqttMessageHandler.DownlinkMessage.Header header = new MqttMessageHandler.DownlinkMessage.Header();
|
||||
header.setName("804"); //804:参数配置
|
||||
header.setID(deviceId);
|
||||
message.setHeader(header);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("mtype", "208");
|
||||
payload.put("Code", "A5A5A5A5");
|
||||
payload.put("passwd", "02123456");
|
||||
message.setPayload(payload);
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -188,6 +188,18 @@ public class CameraInfoController extends JeecgController<CameraInfo, ICameraInf
|
|||
return service.getIpcCapability(cameraInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情信息
|
||||
*
|
||||
* @param cameraInfo
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getDeviceDetails")
|
||||
public Result<JSONObject> getDeviceDetails(CameraInfo cameraInfo) {
|
||||
return service.getDeviceDetails(cameraInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取画面基本信息
|
||||
*
|
||||
|
|
@ -210,6 +222,28 @@ public class CameraInfoController extends JeecgController<CameraInfo, ICameraInf
|
|||
return service.setImageCommon(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取画面操作信息
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/getImageSwitch")
|
||||
public Result<JSONObject> getImageSwitch(@RequestBody Map<String,Object> map) {
|
||||
return service.getImageSwitch(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置画面操作信息
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/setImageSwitch")
|
||||
public Result setImageSwitch(@RequestBody Map<String,Object> map) {
|
||||
return service.setImageSwitch(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取OSD能力集
|
||||
*
|
||||
|
|
|
|||
|
|
@ -326,6 +326,7 @@ public class CameraInfo implements Serializable {
|
|||
private String remarks;//备注
|
||||
private String izAllocate;//是否分配
|
||||
private String dimension;//设备维度
|
||||
private String channel;//通道号
|
||||
|
||||
@TableField(exist = false)
|
||||
private String routeType;//camera监控设备 network网络设备
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
a.maintain_status,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a left join nu_base_info b on a.nu_id = b.nu_id
|
||||
left join nu_iot_tplink_camera_capability c on a.device_index = c.device_index
|
||||
<where>
|
||||
|
|
@ -126,7 +127,8 @@
|
|||
a.ftp_uploadpath as ftpUploadpath,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a left join nu_base_info b on a.nu_id = b.nu_id
|
||||
<where>
|
||||
<if test="projectId != null and projectId != ''">
|
||||
|
|
@ -173,7 +175,8 @@
|
|||
ftp_uploadpath as ftpUploadpath,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a
|
||||
<where>
|
||||
<if test="deviceType != null and deviceType != ''">
|
||||
|
|
@ -229,7 +232,8 @@
|
|||
a.ftp_uploadpath as ftpUploadpath,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a left join nu_base_info b on a.nu_id = b.id
|
||||
where device_index = #{deviceIndex}
|
||||
</select>
|
||||
|
|
@ -325,7 +329,10 @@
|
|||
|
||||
<update id="updateDeviceStatusByDevId">
|
||||
UPDATE nu_iot_tplink_camera
|
||||
SET device_status = #{deviceStatus}
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="deviceStatus != null">device_status = #{deviceStatus},</if>
|
||||
<if test="channel != null">channel = #{channel},</if>
|
||||
</trim>
|
||||
where device_index = #{deviceIndex}
|
||||
</update>
|
||||
|
||||
|
|
@ -376,7 +383,8 @@
|
|||
a.ftp_uploadpath as ftpUploadpath,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a
|
||||
where device_index = #{deviceIndex}
|
||||
</select>
|
||||
|
|
@ -439,7 +447,8 @@
|
|||
c.area_flag as areaFlag,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a
|
||||
left join nu_base_info c on a.nu_id = c.nu_id
|
||||
<where>
|
||||
|
|
@ -545,7 +554,8 @@
|
|||
c.area_flag as areaFlag,
|
||||
a.remarks,
|
||||
a.iz_allocate,
|
||||
a.dimension
|
||||
a.dimension,
|
||||
a.channel
|
||||
from nu_iot_tplink_camera a
|
||||
left join nu_base_info c on a.nu_id = c.nu_id
|
||||
where a.depart_server_url = #{params.departServerUrl}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,11 @@ public interface ICameraInfoService extends IService<CameraInfo> {
|
|||
Result<String> syncDevicesStatus(CameraInfo cameraInfo);
|
||||
Result<String> syncProjectIpcDevice(CameraInfo cameraInfo);
|
||||
Result<JSONObject> getIpcCapability(CameraInfo cameraInfo);
|
||||
Result<JSONObject> getDeviceDetails(CameraInfo cameraInfo);
|
||||
Result<JSONObject> getImageCommon(Map<String,Object> map);
|
||||
Result setImageCommon(Map<String,Object> map);
|
||||
Result<JSONObject> getImageSwitch(Map<String,Object> map);
|
||||
Result setImageSwitch(Map<String,Object> map);
|
||||
Result<JSONObject> getOsdCapability(Map<String,Object> map);
|
||||
Result<JSONObject> getOsd(Map<String,Object> map);
|
||||
Result<String> setOsd(Map<String,Object> map);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -41,6 +41,7 @@ public enum ApiEnum {
|
|||
QUERY_ALARM_LOG("/tums/logManager/v2/queryAlarmLog","查询告警日志列表"),
|
||||
QUERY_UNREAD_ALARM_MSG("/tums/logManager/v2/queryUnreadAlarmMsg","查询未读告警日志列表"),
|
||||
IPC_GET_IPC_CAPABILITY("/tums/deviceManager/v1/getIpcCapability","获取ipc能力集"),
|
||||
GET_DEVICE_DETAILS("/tums/deviceManager/v2/getDeviceDetails","获取设备详情信息"),
|
||||
IPC_PASSTHROUGH("/tums/devConfig/v1/passthrough","设备配置信息"),
|
||||
|
||||
IPC_ADD_PREVIEW_CHN("/tums/preview/v1/addPreviewChn","添加预览通道"),
|
||||
|
|
|
|||
|
|
@ -333,6 +333,20 @@ public class TumsApi {
|
|||
return jsonResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情信息
|
||||
* @param jsonRequest
|
||||
* @return
|
||||
*/
|
||||
public String getDeviceDetails(String jsonRequest){
|
||||
this.createTumsClient();
|
||||
log.info("getDeviceDetails:request:{}",jsonRequest);
|
||||
String jsonResponse = tumsClient.request(jsonRequest, ApiEnum.GET_DEVICE_DETAILS.getValue());
|
||||
log.info("getDeviceDetails:response:{}",jsonResponse);
|
||||
return jsonResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设备配置信息
|
||||
* @param jsonRequest
|
||||
|
|
|
|||
|
|
@ -181,16 +181,15 @@ spring:
|
|||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://192.168.2.199:3306/nu_devops?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
# url: jdbc:mysql://localhost:3306/nursing_unit_001?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: nu_sys
|
||||
password: nu_sys
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#管理
|
||||
# ope:
|
||||
# url: jdbc:mysql://192.168.2.199:3306/nursing_unit?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
# username: nu_sys
|
||||
# password: nu_sys
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
ope:
|
||||
url: jdbc:mysql://192.168.2.199:3306/nursing_unit?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: nu_sys
|
||||
password: nu_sys
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#redis 配置
|
||||
redis:
|
||||
database: 0
|
||||
|
|
@ -378,7 +377,7 @@ downloadkey: hP2K9Z!WLuj"M#8,
|
|||
# MQTT 配置
|
||||
mqtt:
|
||||
broker-url: tcp://121.36.88.64:11001
|
||||
client-id: mqtt-devops
|
||||
client-id: mqtt-devops-
|
||||
username: admin
|
||||
password: admin@123..
|
||||
clean-session: true
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ downloadkey: hP2K9Z!WLuj"M#8,
|
|||
# MQTT 配置
|
||||
mqtt:
|
||||
broker-url: tcp://121.36.88.64:11001
|
||||
client-id: mqtt-devops
|
||||
client-id: mqtt-devops-
|
||||
username: admin
|
||||
password: admin@123..
|
||||
clean-session: true
|
||||
|
|
|
|||
Loading…
Reference in New Issue