设备参数编辑,集成mqtt
This commit is contained in:
parent
224fcc9235
commit
d2aefea0d9
|
@ -68,6 +68,16 @@ spring:
|
|||
# 热部署开关
|
||||
enabled: true
|
||||
# redis 配置
|
||||
# mqtt
|
||||
mqtt:
|
||||
username: hwl # 用户名
|
||||
password: 123456 # 密码
|
||||
hostUrl: tcp://broker.emqx.io:1883 # tcp://ip:端口
|
||||
clientId: mqttx_3afa35e9 # 客户端id
|
||||
defaultTopic: topic # 订阅主题
|
||||
timeout: 100 # 超时时间 (单位:秒)
|
||||
keepalive: 60 # 心跳 (单位:秒)
|
||||
enabled: false # 是否使能mqtt功能
|
||||
redis:
|
||||
# 地址
|
||||
host: localhost
|
||||
|
|
|
@ -140,6 +140,20 @@
|
|||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--mqtt-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-integration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-mqtt</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
package com.ruoyi.common.utils.mqtt;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties("spring.mqtt")
|
||||
public class MqttConfig {
|
||||
@Autowired
|
||||
private MqttPushClient mqttPushClient;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String hostUrl;
|
||||
/**
|
||||
* 客户Id
|
||||
*/
|
||||
private String clientId;
|
||||
/**
|
||||
* 默认连接话题
|
||||
*/
|
||||
private String defaultTopic;
|
||||
/**
|
||||
* 超时时间
|
||||
*/
|
||||
private int timeout;
|
||||
/**
|
||||
* 保持连接数
|
||||
*/
|
||||
private int keepalive;
|
||||
/**
|
||||
* mqtt功能使能
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getHostUrl() {
|
||||
return hostUrl;
|
||||
}
|
||||
|
||||
public void setHostUrl(String hostUrl) {
|
||||
this.hostUrl = hostUrl;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getDefaultTopic() {
|
||||
return defaultTopic;
|
||||
}
|
||||
|
||||
public void setDefaultTopic(String defaultTopic) {
|
||||
this.defaultTopic = defaultTopic;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public int getKeepalive() {
|
||||
return keepalive;
|
||||
}
|
||||
|
||||
public void setKeepalive(int keepalive) {
|
||||
this.keepalive = keepalive;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MqttPushClient getMqttPushClient() {
|
||||
if(enabled == true){
|
||||
String mqtt_topic[] = StringUtils.split(defaultTopic, ",");
|
||||
mqttPushClient.connect(hostUrl, clientId, username, password, timeout, keepalive);//连接
|
||||
for(int i=0; i<mqtt_topic.length; i++){
|
||||
mqttPushClient.subscribe(mqtt_topic[i], 0);//订阅主题
|
||||
}
|
||||
}
|
||||
return mqttPushClient;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.ruoyi.common.utils.mqtt;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.ruoyi.common.core.domain.AjaxResult.error;
|
||||
import static com.ruoyi.common.core.domain.AjaxResult.success;
|
||||
|
||||
@Component
|
||||
public class MqttPushClient {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MqttPushClient.class);
|
||||
|
||||
@Autowired
|
||||
private PushCallback pushCallback;
|
||||
|
||||
private static MqttClient client;
|
||||
|
||||
private static MqttClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
private static void setClient(MqttClient client) {
|
||||
MqttPushClient.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户端连接
|
||||
*
|
||||
* @param host ip+端口
|
||||
* @param clientID 客户端Id
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param timeout 超时时间
|
||||
* @param keepalive 保留数
|
||||
*/
|
||||
public void connect(String host, String clientID, String username, String password, int timeout, int keepalive) {
|
||||
MqttClient client;
|
||||
try {
|
||||
client = new MqttClient(host, clientID, new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setCleanSession(true);
|
||||
options.setUserName(username);
|
||||
options.setPassword(password.toCharArray());
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepalive);
|
||||
MqttPushClient.setClient(client);
|
||||
try {
|
||||
client.setCallback(pushCallback);
|
||||
client.connect(options);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布
|
||||
*
|
||||
* @param qos 连接方式
|
||||
* @param retained 是否保留
|
||||
* @param topic 主题
|
||||
* @param pushMessage 消息体
|
||||
*/
|
||||
public AjaxResult publish(int qos, boolean retained, String topic, String pushMessage) {
|
||||
MqttMessage message = new MqttMessage();
|
||||
message.setQos(qos);
|
||||
message.setRetained(retained);
|
||||
message.setPayload(pushMessage.getBytes());
|
||||
MqttTopic mTopic = MqttPushClient.getClient().getTopic(topic);
|
||||
if (null == mTopic) {
|
||||
logger.error("topic not exist");
|
||||
}
|
||||
MqttDeliveryToken token;
|
||||
try {
|
||||
token = mTopic.publish(message);
|
||||
token.waitForCompletion();
|
||||
return success();
|
||||
} catch (MqttPersistenceException e) {
|
||||
e.printStackTrace();
|
||||
return error();
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅某个主题
|
||||
*
|
||||
* @param topic 主题
|
||||
* @param qos 连接方式
|
||||
*/
|
||||
public void subscribe(String topic, int qos) {
|
||||
logger.info("开始订阅主题" + topic);
|
||||
try {
|
||||
MqttPushClient.getClient().subscribe(topic, qos);
|
||||
} catch (MqttException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.ruoyi.common.utils.mqtt;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PushCallback implements MqttCallback {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MqttPushClient.class);
|
||||
|
||||
@Autowired
|
||||
private MqttConfig mqttConfig;
|
||||
|
||||
private static MqttClient client;
|
||||
|
||||
private static String _topic;
|
||||
private static String _qos;
|
||||
private static String _msg;
|
||||
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
// 连接丢失后,一般在这里面进行重连
|
||||
logger.info("连接断开,可以做重连");
|
||||
if (client == null || !client.isConnected()) {
|
||||
mqttConfig.getMqttPushClient();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
|
||||
// subscribe后得到的消息会执行到这里面
|
||||
logger.info("接收消息主题 : " + topic);
|
||||
logger.info("接收消息Qos : " + mqttMessage.getQos());
|
||||
logger.info("接收消息内容 : " + new String(mqttMessage.getPayload()));
|
||||
|
||||
_topic = topic;
|
||||
_qos = mqttMessage.getQos()+"";
|
||||
_msg = new String(mqttMessage.getPayload());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
logger.info("deliveryComplete---------" + iMqttDeliveryToken.isComplete());
|
||||
}
|
||||
|
||||
//别的Controller层会调用这个方法来 获取 接收到的硬件数据
|
||||
public String receive() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("topic", _topic);
|
||||
jsonObject.put("qos", _qos);
|
||||
jsonObject.put("msg", _msg);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -244,22 +244,22 @@
|
|||
<!-- 定时浇水 -->
|
||||
<el-col :span="12" class="col-style">
|
||||
<el-form-item class="el-form-item" label="定时" label-width="60px" prop="regularWatering"><!-- 浇水规则json -->
|
||||
<el-switch v-model="form.pulseMode" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
<el-switch v-model="form.regularWatering" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
</el-form-item>
|
||||
<div class="fontdesc margin-40px">按照间隔时间进行定时浇水</div>
|
||||
<div class="div1" >
|
||||
<span class="span1">浇水间隔时间:</span>
|
||||
<span class="span3">分</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num3"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.regularWateringJsonObj.intervalTime.min"></el-input-number>
|
||||
<span class="span3">时</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num2"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.regularWateringJsonObj.intervalTime.hour"></el-input-number>
|
||||
</div>
|
||||
<div class="div1">
|
||||
<span class="span1">浇水时间:</span>
|
||||
<span class="span3">秒</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num4"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.regularWateringJsonObj.sprayTime.sec"></el-input-number>
|
||||
<span class="span3">分</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num5"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.regularWateringJsonObj.sprayTime.min"></el-input-number>
|
||||
</div>
|
||||
<div class="div1 font11">
|
||||
<span>单次浇水时间不可超过20分钟,防止电机过度发热,浇水量大可缩短浇水间隔时间</span>
|
||||
|
@ -269,48 +269,39 @@
|
|||
<!-- 智能土壤湿度 -->
|
||||
<el-col :span="12" class="col-style ">
|
||||
<el-form-item label="智能土壤湿度" class="margin-40px el-form-item" label-width="100px" prop="soilMoistureOpen">
|
||||
<el-switch v-model="form.pulseMode" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
<el-switch v-model="form.soilMoisture" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
</el-form-item>
|
||||
<div class="fontdesc margin-40px">开启设备将自动调整土壤湿度</div>
|
||||
<span class="margin-5px margin-40px">启动土壤湿度</span>
|
||||
<el-slider v-model="form.waterIntensity1" class="margin-5px margin-40px">
|
||||
<el-slider v-model="form.soilMoistureOpen" class="margin-5px margin-40px">
|
||||
</el-slider>
|
||||
<span class="margin-5px margin-40px">停止土壤湿度</span>
|
||||
<el-slider v-model="form.waterIntensity2" class="margin-5px margin-40px">
|
||||
<el-slider v-model="form.soilMoistureClose" class="margin-5px margin-40px">
|
||||
</el-slider>
|
||||
<!-- <el-form-item label="启动" prop="soilMoistureOpen">-->
|
||||
<!-- <el-input v-model="form.soilMoistureOpen" placeholder="请输入启动土壤湿度值" />-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="停止" prop="soilMoistureClose"><!– 土壤湿度值 –>-->
|
||||
<!-- <el-input v-model="form.soilMoistureClose" placeholder="请输入停止土壤湿度值" />-->
|
||||
<!-- </el-form-item>-->
|
||||
</el-col>
|
||||
|
||||
<!-- 脉冲模式 -->
|
||||
<el-col :span="12" class="col-style">
|
||||
<el-form-item class="el-form-item" label="脉冲模式" prop="pulseMode">
|
||||
<el-switch v-model="form.pulseMode2" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
<el-switch v-model="form.pulseMode" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
</el-form-item>
|
||||
<div class="fontdesc margin-40px">开启脉冲将会浇水停止相互循环</div>
|
||||
<div class="div1" >
|
||||
<span class="span1">浇水时间:</span>
|
||||
<span class="span3">秒</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num2"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.pulseModeParamObj.sprayTime"></el-input-number>
|
||||
</div>
|
||||
<div class="div1">
|
||||
<span class="span1">停止时间:</span>
|
||||
<span class="span3">秒</span>
|
||||
<el-input-number class="span2" size="mini" v-model="num2"></el-input-number>
|
||||
<el-input-number class="span2" size="mini" v-model="form.pulseModeParamObj.endTime"></el-input-number>
|
||||
</div>
|
||||
<!-- <el-form-item label="脉冲模式参数" prop="pulseModeParam">-->
|
||||
<!-- <el-input v-model="form.pulseModeParam" placeholder="请输入脉冲模式参数" />-->
|
||||
<!-- </el-form-item>-->
|
||||
</el-col>
|
||||
|
||||
<!-- 水流强度 -->
|
||||
<el-col :span="12" class="col-style">
|
||||
<el-form-item class="el-form-item" label="水流强度" label-width="90px" prop="waterIntensity">
|
||||
<el-switch v-model="form.pulseMode3" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
<el-switch v-model="form.waterIntensitySwitch" class="drawer-switch switch-margin" active-color="#13ce66"/>
|
||||
</el-form-item>
|
||||
<div class="fontdesc margin-40px">水流强度分为5档</div>
|
||||
<el-slider :max="5"
|
||||
|
@ -368,6 +359,20 @@ export default {
|
|||
dicts: ['as_pulse_mode', 'as_screen_rest_time', 'as_online_status', 'as_water_intensity'],
|
||||
data() {
|
||||
return {
|
||||
intervalTime: null,
|
||||
sprayTime: null,
|
||||
//启动土壤湿度值
|
||||
soilMoistureOpen:0,
|
||||
//停止土壤湿度值
|
||||
soilMoistureClose:0,
|
||||
//脉冲模式 {"sprayTime":1,"endTime":1}
|
||||
pulseModeParam:{},
|
||||
//水流强度
|
||||
waterIntensity: 1,
|
||||
//定时浇水json {"intervalTime":{"hour":1,"min":1},"sprayTime":{"min":1,"sec":1}}
|
||||
regularWateringJson: {
|
||||
intervalTime:null
|
||||
},
|
||||
//用户列表
|
||||
userOptions:[],
|
||||
//型号列表
|
||||
|
@ -406,7 +411,42 @@ export default {
|
|||
nickName: null,
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
form: {
|
||||
/**1.定时浇水开关*/
|
||||
regularWatering:false,
|
||||
//定时浇水json {"intervalTime":{"hour":1,"min":1},"sprayTime":{"min":1,"sec":1}}
|
||||
regularWateringJsonObj:{
|
||||
intervalTime:{
|
||||
hour:1,
|
||||
min:1
|
||||
},
|
||||
sprayTime:{
|
||||
min:1,
|
||||
sec:1
|
||||
}
|
||||
},
|
||||
regularWateringJson:null,
|
||||
/**2.智能土壤湿度开关*/
|
||||
soilMoisture:false,
|
||||
//启动土壤湿度值
|
||||
soilMoistureOpen:38,
|
||||
//停止土壤湿度值
|
||||
soilMoistureClose:88,
|
||||
|
||||
/**3.脉冲模式开关*/
|
||||
pulseMode:false,
|
||||
//脉冲模式 {"sprayTime":1,"endTime":1}
|
||||
pulseModeParamObj:{
|
||||
sprayTime:1,
|
||||
endTime:1
|
||||
},
|
||||
pulseModeParam:null,
|
||||
|
||||
/**3.水流强度开关*/
|
||||
waterIntensitySwitch:false,
|
||||
//水流强度
|
||||
waterIntensity: 4
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
deviceName: [
|
||||
|
@ -455,6 +495,32 @@ export default {
|
|||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
/**1.定时浇水开关*/
|
||||
//定时浇水json {"intervalTime":{"hour":1,"min":1},"sprayTime":{"min":1,"sec":1}}
|
||||
regularWateringJsonObj:{
|
||||
intervalTime:{
|
||||
hour:null,
|
||||
min:null
|
||||
},
|
||||
sprayTime:{
|
||||
min:null,
|
||||
sec:null
|
||||
}
|
||||
},
|
||||
regularWateringJson:null,
|
||||
/**2.智能土壤湿度开关*/
|
||||
soilMoisture:false,
|
||||
|
||||
/**3.脉冲模式开关*/
|
||||
//脉冲模式 {"sprayTime":1,"endTime":1}
|
||||
pulseModeParamObj:{
|
||||
sprayTime:null,
|
||||
endTime:null
|
||||
},
|
||||
pulseModeParam:null,
|
||||
/**3.水流强度开关*/
|
||||
waterIntensitySwitch:false,
|
||||
//水流强度
|
||||
deviceId: null,
|
||||
picture: null,
|
||||
deviceName: null,
|
||||
|
@ -473,7 +539,6 @@ export default {
|
|||
soilMoistureClose: null,
|
||||
waterIntensity: null,
|
||||
pulseMode: null,
|
||||
pulseModeParam: null,
|
||||
screenRestTime: null,
|
||||
version: null,
|
||||
createBy: null,
|
||||
|
@ -500,12 +565,7 @@ export default {
|
|||
this.single = selection.length!==1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加设备";
|
||||
this.loading = true;
|
||||
getInitData() {
|
||||
listClassify(this.queryParams).then(response => {
|
||||
this.classifyOptions = response.rows;
|
||||
});
|
||||
|
@ -518,16 +578,32 @@ export default {
|
|||
listUser(this.queryParams).then(response4 => {
|
||||
this.userOptions = response4.rows;
|
||||
});
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加设备";
|
||||
this.loading = true;
|
||||
this.getInitData();
|
||||
this.loading = false;
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const deviceId = row.deviceId || this.ids
|
||||
this.getInitData();
|
||||
getDevice(deviceId).then(response => {
|
||||
this.form = response.data;
|
||||
/** 参数解析成对象*/
|
||||
this.form.pulseModeParamObj = JSON.parse(this.form.pulseModeParam);
|
||||
this.form.regularWateringJsonObj = JSON.parse(this.form.regularWateringJson);
|
||||
this.form.regularWatering = JSON.parse(this.form.regularWatering);
|
||||
this.form.pulseMode = JSON.parse(this.form.pulseMode);
|
||||
this.form.soilMoisture = JSON.parse(this.form.soilMoisture);
|
||||
this.form.waterIntensitySwitch = JSON.parse(this.form.waterIntensitySwitch);
|
||||
this.open = true;
|
||||
this.title = "修改设备列表";
|
||||
this.title = "修改设备";
|
||||
});
|
||||
},
|
||||
/** 手动浇水 */
|
||||
|
@ -536,15 +612,14 @@ export default {
|
|||
const deviceId = row.deviceId || this.ids
|
||||
watering(deviceId).then(response => {
|
||||
this.$modal.msgSuccess("手动浇水");
|
||||
// this.form = response.data;
|
||||
// this.open = true;
|
||||
// this.title = "修改设备列表";
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
this.form.pulseModeParam = JSON.stringify(this.form.pulseModeParamObj);
|
||||
this.form.regularWateringJson = JSON.stringify(this.form.regularWateringJsonObj);
|
||||
if (this.form.deviceId != null) {
|
||||
updateDevice(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.ruoyi.device.controller;
|
|||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -78,7 +80,7 @@ public class AsDeviceController extends BaseController
|
|||
public AjaxResult watering(@PathVariable("deviceId") Long deviceId)
|
||||
{
|
||||
AsDevice device = asDeviceService.selectAsDeviceByDeviceId(deviceId);
|
||||
return success(asDeviceService.watering(device));
|
||||
return asDeviceService.watering(device);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,6 +91,7 @@ public class AsDeviceController extends BaseController
|
|||
@PostMapping
|
||||
public AjaxResult add(@RequestBody AsDevice asDevice)
|
||||
{
|
||||
System.out.println("接收到参数----asDevice"+ JSON.toJSONString(asDevice));
|
||||
asDevice.setCreateBy(getUsername());
|
||||
return toAjax(asDeviceService.insertAsDevice(asDevice));
|
||||
}
|
||||
|
|
|
@ -75,15 +75,15 @@ public class AsDevice extends BaseEntity
|
|||
|
||||
/** 启动土壤湿度值 */
|
||||
@Excel(name = "启动土壤湿度值")
|
||||
private String soilMoistureOpen;
|
||||
private Integer soilMoistureOpen;
|
||||
|
||||
/** 停止土壤湿度值 */
|
||||
@Excel(name = "停止土壤湿度值")
|
||||
private String soilMoistureClose;
|
||||
private Integer soilMoistureClose;
|
||||
|
||||
/** 水流强度 */
|
||||
@Excel(name = "水流强度")
|
||||
private String waterIntensity;
|
||||
private Integer waterIntensity;
|
||||
|
||||
/** 脉冲模式 */
|
||||
@Excel(name = "脉冲模式")
|
||||
|
@ -105,4 +105,21 @@ public class AsDevice extends BaseEntity
|
|||
@Excel(name = "版本号")
|
||||
private String version;
|
||||
|
||||
/** 备注 */
|
||||
@Excel(name = "备注")
|
||||
private String remark;
|
||||
|
||||
/** 定时浇水规则 */
|
||||
@Excel(name = "定时浇水规则")
|
||||
private String regularWateringJson;
|
||||
|
||||
/** 智能土壤开关:false-关;true-开 */
|
||||
@Excel(name = "智能土壤开关")
|
||||
private String soilMoisture;
|
||||
|
||||
/** 水流强度开关:false-关;true-开 */
|
||||
@Excel(name = "水流强度开关")
|
||||
private String waterIntensitySwitch;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.ruoyi.device.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
|
||||
/**
|
||||
|
@ -65,5 +67,5 @@ public interface IAsDeviceService
|
|||
* @param device 设备列表主键
|
||||
* @return 结果
|
||||
*/
|
||||
public String watering(AsDevice device);
|
||||
public AjaxResult watering(AsDevice device);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ package com.ruoyi.device.service.impl;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.mqtt.MqttPushClient;
|
||||
import com.ruoyi.device.domain.AsDeviceClassify;
|
||||
import com.ruoyi.device.domain.AsDeviceVersion;
|
||||
import com.ruoyi.device.domain.AsModel;
|
||||
|
@ -43,8 +46,10 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
@Resource
|
||||
private AsDeviceVersionMapper versionMapper;
|
||||
|
||||
// @Resource
|
||||
// private AsW
|
||||
|
||||
|
||||
@Resource
|
||||
private MqttPushClient mqttPushClient;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -131,10 +136,11 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public String watering(AsDevice device) {
|
||||
public AjaxResult watering(AsDevice device) {
|
||||
// TODO 手动浇水 调用 onenet
|
||||
|
||||
AjaxResult publish = mqttPushClient.publish(0, false, "topic", "hello world!");
|
||||
System.out.println("topic发送成功-----"+ JSON.toJSONString(publish));
|
||||
// TODO 保存浇水记录 as_watering_record
|
||||
return null;
|
||||
return publish;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="regularWateringJson" column="regular_watering_json" />
|
||||
<result property="soilMoisture" column="soil_moisture" />
|
||||
<result property="waterIntensitySwitch" column="water_intensity_switch" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAsDeviceVo">
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status, user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode, pulse_mode_param, screen_rest_time, version, create_by, create_time, update_by, update_time, remark from as_device
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status, user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode, pulse_mode_param, screen_rest_time, version, version_id, create_by, create_time, update_by, update_time, remark, regular_watering_json, soil_moisture, water_intensity_switch from as_device
|
||||
</sql>
|
||||
|
||||
<select id="selectAsDeviceList" parameterType="AsDevice" resultMap="AsDeviceResult">
|
||||
|
@ -84,6 +87,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="regularWateringJson != null">regular_watering_json,</if>
|
||||
<if test="soilMoisture != null">soil_moisture,</if>
|
||||
<if test="waterIntensitySwitch != null">water_intensity_switch</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="picture != null">#{picture},</if>
|
||||
|
@ -112,6 +118,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="regularWateringJson != null">#{regularWateringJson},</if>
|
||||
<if test="soilMoisture != null">#{soilMoisture},</if>
|
||||
<if test="waterIntensitySwitch != null">#{waterIntensitySwitch}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -144,6 +153,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="regularWateringJson != null">regular_watering_json = #{regularWateringJson},</if>
|
||||
<if test="soilMoisture != null">soil_moisture = #{soilMoisture},</if>
|
||||
<if test="waterIntensitySwitch != null">water_intensity_switch = #{waterIntensitySwitch}</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
</update>
|
||||
|
|
Loading…
Reference in New Issue
Block a user