You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
5.3 KiB
Java
115 lines
5.3 KiB
Java
package com.rehome.mqttclienttemperature.service.impl;
|
|
|
|
import com.rehome.mqttclienttemperature.dao.TemperatureEspRepository;
|
|
import com.rehome.mqttclienttemperature.dao.TemperatureRepository;
|
|
import com.rehome.mqttclienttemperature.entity.Temperature;
|
|
import com.rehome.mqttclienttemperature.entity.TemperatureEsp;
|
|
import com.rehome.mqttclienttemperature.service.TemperatureEspService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class TemperatureEspServiceImpl implements TemperatureEspService {
|
|
@Resource
|
|
private TemperatureEspRepository temperatureEspRepository;
|
|
|
|
@Override
|
|
public void saveTemperature(String temperatureValue, String humidityValue) {
|
|
try {
|
|
if(temperatureValue!=null&&temperatureValue.length()>0&&humidityValue!=null&&humidityValue.length()>0){
|
|
Date now = new Date();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdfHour = new SimpleDateFormat("yyyy-MM-dd HH");
|
|
SimpleDateFormat sdfMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
SimpleDateFormat sdfSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
String nowDate = sdf.format(now);
|
|
String nowHour = sdfHour.format(now);
|
|
String dataMinute = sdfMinute.format(now);
|
|
String dataSecond = sdfSecond.format(now);
|
|
TemperatureEsp temperatureEsp = new TemperatureEsp();
|
|
temperatureEsp.setCreateDate(now);
|
|
temperatureEsp.setDataDate(nowDate);
|
|
temperatureEsp.setDataHour(nowHour);
|
|
temperatureEsp.setDataMinute(dataMinute);
|
|
temperatureEsp.setSource("http");
|
|
|
|
String topic = "/device/esp8266/001";
|
|
if(topic!=null){
|
|
temperatureEsp.setTopic(topic);
|
|
if(topic.equals("/device/esp8266/001")){
|
|
temperatureEsp.setLocationDesc("广东省珠海市高新区唐家湾镇南方软件园B2栋4楼珠海瑞洪智能系统工程有限公司");
|
|
}
|
|
if(topic.equals("WifiSHT/7C87CE9F5CBF/SHT20")){
|
|
temperatureEsp.setLocationDesc("广东省珠海市金湾区三灶镇百川路1号1栋1单元1508房");
|
|
}
|
|
if(topic.equals("WifiSHT/4CEBD686B6AA/SHT20")){
|
|
temperatureEsp.setLocationDesc("广西壮族自治区崇左市天等县天等镇荣华村弄在屯113号");
|
|
}
|
|
}
|
|
temperatureEsp.setHumidity(humidityValue);
|
|
temperatureEsp.setTemperature(temperatureValue);
|
|
|
|
//mysql
|
|
this.temperatureEspRepository.save(temperatureEsp);
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void saveTemperature(String temperatureValue, String humidityValue, String topic) {
|
|
try {
|
|
if(temperatureValue!=null&&temperatureValue.length()>0&&humidityValue!=null&&humidityValue.length()>0){
|
|
Date now = new Date();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdfHour = new SimpleDateFormat("yyyy-MM-dd HH");
|
|
SimpleDateFormat sdfMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
SimpleDateFormat sdfSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
String nowDate = sdf.format(now);
|
|
String nowHour = sdfHour.format(now);
|
|
String dataMinute = sdfMinute.format(now);
|
|
String dataSecond = sdfSecond.format(now);
|
|
TemperatureEsp temperatureEsp = new TemperatureEsp();
|
|
temperatureEsp.setCreateDate(now);
|
|
temperatureEsp.setDataDate(nowDate);
|
|
temperatureEsp.setDataHour(nowHour);
|
|
temperatureEsp.setDataMinute(dataMinute);
|
|
temperatureEsp.setSource("mqtt");
|
|
|
|
if(topic!=null){
|
|
temperatureEsp.setTopic(topic);
|
|
if(topic.equals("/device/esp8266/001")){
|
|
temperatureEsp.setLocationDesc("广东省珠海市高新区唐家湾镇南方软件园B2栋4楼珠海瑞洪智能系统工程有限公司");
|
|
}
|
|
if(topic.equals("WifiSHT/7C87CE9F5CBF/SHT20")){
|
|
temperatureEsp.setLocationDesc("广东省珠海市金湾区三灶镇百川路1号1栋1单元1508房");
|
|
}
|
|
if(topic.equals("WifiSHT/4CEBD686B6AA/SHT20")){
|
|
temperatureEsp.setLocationDesc("广西壮族自治区崇左市天等县天等镇荣华村弄在屯113号");
|
|
}
|
|
}
|
|
temperatureEsp.setHumidity(humidityValue);
|
|
temperatureEsp.setTemperature(temperatureValue);
|
|
|
|
//mysql
|
|
this.temperatureEspRepository.save(temperatureEsp);
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void saveTemperature(TemperatureEsp temperatureEsp) {
|
|
this.temperatureEspRepository.save(temperatureEsp);
|
|
}
|
|
}
|