|
|
|
|
package com.rehome.mqttclienttemperature.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.rehome.mqttclienttemperature.dao.TemperatureRepository;
|
|
|
|
|
import com.rehome.mqttclienttemperature.entity.Temperature;
|
|
|
|
|
import com.rehome.mqttclienttemperature.service.TemperatureService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class TemperatureServiceImpl implements TemperatureService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private TemperatureRepository temperatureRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void saveTemperature(String temperatureAndHumidityData,String topic) {
|
|
|
|
|
if(temperatureAndHumidityData!=null&&temperatureAndHumidityData.length()>0){
|
|
|
|
|
String[] strDataTemperature = temperatureAndHumidityData.split(" ");
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
String nowDate = sdf.format(now);
|
|
|
|
|
String nowHour = sdfHour.format(now);
|
|
|
|
|
String dataMinute = sdfMinute.format(now);
|
|
|
|
|
Temperature temperature = new Temperature();
|
|
|
|
|
temperature.setCreateDate(now);
|
|
|
|
|
temperature.setDataDate(nowDate);
|
|
|
|
|
temperature.setDataHour(nowHour);
|
|
|
|
|
temperature.setDataMinute(dataMinute);
|
|
|
|
|
if(topic!=null){
|
|
|
|
|
temperature.setTopic(topic);
|
|
|
|
|
if(topic.equals("WifiSHT/7C87CE9CA4E6/SHT20")){
|
|
|
|
|
temperature.setLocationDesc("广东省珠海市高新区唐家湾镇东岸村水风三街28号501");
|
|
|
|
|
}
|
|
|
|
|
if(topic.equals("WifiSHT/7C87CE9F5CBF/SHT20")){
|
|
|
|
|
temperature.setLocationDesc("广东省珠海市金湾区三灶镇百川路1号1栋1单元1508房");
|
|
|
|
|
}
|
|
|
|
|
if(topic.equals("WifiSHT/4CEBD686B6AA/SHT20")){
|
|
|
|
|
temperature.setLocationDesc("广西壮族自治区崇左市天等县天等镇荣华村弄在屯113号");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
temperature.setHumidity(Double.valueOf(strDataTemperature[0]));
|
|
|
|
|
temperature.setTemperature(Double.valueOf(strDataTemperature[1]));
|
|
|
|
|
|
|
|
|
|
this.temperatureRepository.save(temperature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|