package com.yw.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yw.entity.Lux;
import com.yw.entity.User;
import com.yw.mapper.LuxMapper;
import com.yw.util.MQTTUtil;
import com.yw.util.PushCallback;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;
/**
* Demo Class
*
* @Class MQTTController
* @Author Administrator
* @Date 2020/5/29
* @Version Code No.1
* @Description:
**/
@Controller
public class MQTTController {
private ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml");
private LuxMapper luxMapper = ioc.getBean("luxMapper", LuxMapper.class);
/**
* 进行客户端连接
*
* @param user
* @return int
* @Author Administrator
**/
@RequestMapping("/sendMessage")
@ResponseBody
public int sendMessage(@RequestBody User user) throws MqttException {
if (!"".equals(user.getUsername()) || user.getUsername() != null || !"".equals(user.getPassword()) || user.getPassword() != null
|| !"\n".equals(user.getUsername()) || !"\t".equals(user.getUsername()) || !"\n".equals(user.getPassword()) || !"\t".equals(user.getPassword())) {
MQTTUtil.USERNAME = user.getUsername();
MQTTUtil.PWD = user.getPassword();
MQTTUtil.start();
if (MQTTUtil.client.isConnected()) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
/**
* 进行历史数据保存
*
* @param lux
* @return
* @Author Administrator
**/
@RequestMapping("/historyData")
@ResponseBody
public void historyData(@RequestBody Lux lux) {
System.out.println("输出lux:" + lux);
saveLux(lux.getLuxNumber());
}
/**
* 进行开关灯数据展示
*
* @param
* @return java.util.List
* @Author Administrator
**/
@RequestMapping("/switchData")
@ResponseBody
public List switchData(@RequestBody String date) throws Exception {
JSONObject jsonData = JSONObject.parseObject(date);
List<Lux> list = luxMapper.selectList(new EntityWrapper<Lux>()
.like("lux_time", jsonData.getString("date"))
.orderDesc(Collections.singleton("lux_id"))
.last("limit 2"));
return list;
}
/**
* 将从服务器防发过来的数据展示到前端
*
* @param
* @return String
* @Author Administrator
**/
@RequestMapping("/showMessage")
@ResponseBody
public String showMessage(@RequestBody Lux lux) {
lux = PushCallback.getLux();
return lux.getLuxNumber();
}
/**
* 保存数据到数据库
*
* @param
* @return java.lang.void
* @Author Administrator
**/
public void saveLux(String number) {
Lux lux = new Lux();
lux.setLuxNumber(number);
lux.setLuxTime(new java.util.Date());
System.out.println(lux);
Integer integer = luxMapper.insertAllColumn(lux);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于MQTT协议+物联网云平台的智慧路灯管理系统源码(在PC机上Web开发,采集端的数据采用MQTT.fx进行模拟,数据通过MQTT协议进行传输到服务器,再获取服务器数据,并最终显示在前端应用中).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于MQTT协议+物联网云平台的智慧路灯管理系统源码(在PC机上Web开发,采集端的数据采用MQTT.fx进行模拟).zip (101个子文件)
MQTTController.class 4KB
MQTTController.class 4KB
MQTTUtil.class 2KB
MQTTUtil.class 2KB
testMP.class 2KB
PushCallback.class 2KB
PushCallback.class 2KB
Lux.class 1KB
Lux.class 1KB
User.class 1KB
User.class 1KB
LuxMapper.class 399B
LuxMapper.class 399B
things.css 1KB
things.css 1KB
index.html 5KB
index.html 5KB
Things.iml 190B
mybatis-3.4.6.jar 1.55MB
jackson-databind-2.8.8.jar 1.18MB
spring-context-4.3.6.RELEASE.jar 1.08MB
spring-core-4.3.6.RELEASE.jar 1.07MB
spring-integration-core-4.3.6.RELEASE.jar 1.01MB
mysql-connector-java-5.1.45.jar 976KB
spring-webmvc-4.3.6.RELEASE.jar 893KB
spring-web-4.3.6.RELEASE.jar 798KB
spring-beans-4.3.6.RELEASE.jar 745KB
mchange-commons-java-0.2.15.jar 609KB
spring-test-4.3.6.RELEASE.jar 585KB
fastjson-1.2.51.jar 566KB
c3p0-0.9.5.3.jar 487KB
log4j-1.2.17.jar 478KB
spring-orm-4.3.6.RELEASE.jar 466KB
spring-jdbc-4.3.6.RELEASE.jar 417KB
jsqlparser-1.1.jar 377KB
spring-messaging-4.3.6.RELEASE.jar 374KB
spring-aop-4.3.6.RELEASE.jar 371KB
jackson-core-2.8.8.jar 276KB
spring-tx-4.3.6.RELEASE.jar 261KB
spring-expression-4.3.6.RELEASE.jar 257KB
gson-2.8.5.jar 236KB
org.eclipse.paho.client.mqttv3-1.0.2.jar 157KB
mybatis-plus-support-2.3.jar 145KB
spring-retry-1.1.3.RELEASE.jar 106KB
mybatis-plus-core-2.3.jar 101KB
javax.servlet-api-3.1.0.jar 94KB
mybatis-plus-generate-2.3.jar 63KB
commons-logging-1.2.jar 60KB
jackson-annotations-2.8.0.jar 54KB
mybatis-spring-1.3.2.jar 52KB
spring-integration-mqtt-4.3.6.RELEASE.jar 38KB
mybatis-plus-2.3.jar 261B
MQTTController.java 3KB
MQTTUtil.java 3KB
testMP.java 2KB
PushCallback.java 2KB
Lux.java 1KB
User.java 734B
LuxMapper.java 716B
jquery-3.2.1.min.js 85KB
jquery-3.2.1.min.js 85KB
index.js 4KB
index.js 4KB
index.jsp 11KB
index.jsp 11KB
Things.kotlin_module 16B
Things.kotlin_module 16B
MANIFEST.MF 83B
MANIFEST.MF 83B
.name 7B
log4j.properties 324B
log4j.properties 324B
log4j.properties 324B
db.properties 133B
db.properties 133B
db.properties 133B
light.svg 4KB
light.svg 4KB
dim.svg 4KB
dim.svg 4KB
workspace.xml 49KB
uiDesigner.xml 9KB
pom.xml 6KB
Things_war_exploded.xml 5KB
applicationContext.xml 3KB
applicationContext.xml 3KB
applicationContext.xml 3KB
web.xml 2KB
web.xml 2KB
Project_Default.xml 1KB
SpringMVC-config.xml 1KB
SpringMVC-config.xml 1KB
SpringMVC-config.xml 1KB
misc.xml 640B
checkstyle-idea.xml 609B
compiler.xml 561B
mybatis-config.xml 206B
mybatis-config.xml 206B
mybatis-config.xml 206B
encodings.xml 204B
共 101 条
- 1
- 2
资源评论
土豆片片
- 粉丝: 1567
- 资源: 5642
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功