Commit 36b688b7 authored by 王夏晖's avatar 王夏晖

Merge remote-tracking branch 'origin/develop' into develop

parents 12d0668f d5a667ab
......@@ -45,6 +45,12 @@ public class AdaptiveController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.buildingAdaptation(proId, year, month, day));
}
@ApiOperation(value="实际温度定时任务测试", notes="实际温度定时任务测试")
@RequestMapping("/temperature")
public Result temperature() {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.temperature());
}
// @RequestMapping("/tem")
// public Result tem(){
// return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, adaptiveServiceImpl.temperature());
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository;
import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository;
import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository;
......@@ -185,11 +186,13 @@ public class AdaptiveServiceImpl implements AdaptiveService {
//1.查询所有项目的城市code,去重复
List<String> cityCodeList = busProjectRepository.allCityCode();
//2.根据项目code,查询24小时的温度json
cityCodeList.forEach(s -> {
saveList.addAll(this.fromWeather(s));
cityCodeList.forEach(code -> {
// saveList.addAll(this.fromWeather(s));
saveList.add(this.fromWeatherMi(code));
});
//3.先根据结果,删除已经存在的数据,再将所有的结果插入bus_temperature表(批量)
Integer d = busTemperatureRepository.batchDeleteBusTemperature(saveList);
// Integer d = busTemperatureRepository.batchDeleteBusTemperature(saveList);
//小米天气,每隔一小时查询一次,不需要删除
Integer i = busTemperatureRepository.batchSaveBusTemperature(saveList);
return new PersistModel(i);
}
......@@ -235,4 +238,83 @@ public class AdaptiveServiceImpl implements AdaptiveService {
return resultList;
}
/**
* 从小米获得每小时天气
* 1小时请求一次
* @param code
* @return
*/
private BusTemperature fromWeatherMi(String code) {
BusTemperature busTemp = new BusTemperature();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String apiUrl = String.format("http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s", code);
URL url = null;
URLConnection open = null;
InputStream input = null;
try {
//开始请求
url = new URL(apiUrl);
open = url.openConnection();
input = open.getInputStream();
//变成string
String result = IOUtils.toString(input);
JSONObject jsonResult = JSONObject.parseObject(result);
JSONObject weather = (JSONObject) jsonResult.get("weatherinfo");
//温度
BigDecimal temp = new BigDecimal((String) weather.get("temp"));
//时间
Integer hour = Integer.parseInt(((String) weather.get("time")).split(":")[0]);
Date time = DateUtils.setHours(new Date(), hour);
time = DateUtils.setMinutes(time, 0);
time = DateUtils.setSeconds(time, 0);
//赋值对象
busTemp.setCode(code);
busTemp.setTm(time);
busTemp.setTemperature(temp);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return busTemp;
}
public static void main(String[] args) {
List<BusTemperature> resultList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String apiUrl = String.format("http://weatherapi.market.xiaomi.com/wtr-v2/temp/realtime?cityId=%s", "101280101");
URL url = null;
URLConnection open = null;
InputStream input = null;
try {
//开始请求
url = new URL(apiUrl);
open = url.openConnection();
input = open.getInputStream();
//变成string
String result = IOUtils.toString(input);
JSONObject jsonResult = JSONObject.parseObject(result);
JSONObject weather = (JSONObject) jsonResult.get("weatherinfo");
String time = (String) weather.get("time");
Integer hour = Integer.parseInt(time.split(":")[0]);
Date date = DateUtils.setHours(new Date(), hour);
date = DateUtils.setMinutes(date, 0);
date = DateUtils.setSeconds(date, 0);
System.out.println(sdf.format(date));
System.out.println(weather.get("temp"));
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -15,9 +15,10 @@ public class AdaptiveTask {
private AdaptiveService adaptiveServiceImpl;
/**
* 每间隔3小时的第5分钟执行,查询所有项目中存在的城市,未来24小时的温度
* 定时获得天气
* 每小时第45分执行一次
*/
@Scheduled(cron = "0 5 */3 * * ?")
@Scheduled(cron = "0 45 * * * ?")
public void temperature () {
adaptiveServiceImpl.temperature();
}
......
......@@ -97,6 +97,15 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.getEnergyCompare(proId, year, month, type, cType));
}
/**
* 建筑单位面积用量
* @return
*/
@RequestMapping("/busProjectAreaStat")
public Result busProjectAreaStat() {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.statEnergyMonthly());
}
/** -------------碳排放量--------------- */
@ApiOperation(value="查询碳排放量", notes="8条数据,没有“年环比”数据")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")})
......
......@@ -505,7 +505,7 @@ public class OverViewServiceImpl implements OverViewService {
return result;
}
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
@Override
public PersistModel statEnergyMonthly() {
System.out.println("---------------------start--------------------");
......@@ -522,11 +522,12 @@ public class OverViewServiceImpl implements OverViewService {
//2.循环所有的项目,查询对应项目的统计信息
Iterator<BusProject> busProjectIterator = busProjectList.iterator();
while (busProjectIterator.hasNext()) {
BusProject busProject = busProjectIterator.next();
//得到项目主键
String proId = busProjectIterator.next().getProId();
String proId = busProject.getProId();
//查询该项目的水电气面积
// BusProjectAreaVo busProjectAreaVo = busProjectAreaRepository.classifyProjectArea(proId);
BigDecimal area = busProjectIterator.next().getBldArea();
BigDecimal area = busProject.getBldArea();
//3.查询对应项目的能源统计(按月份统计)
EnergyCountM e = new EnergyCountM();
e.setProId(proId);
......@@ -548,9 +549,9 @@ public class OverViewServiceImpl implements OverViewService {
gasSum = gasSum.add(energyCountM.getGas());
}
//算出年度平均值
waterSum = waterSum.multiply(month).divide(listSize).divide(area).setScale(1);
elecSum = elecSum.multiply(month).divide(listSize).divide(area).setScale(1);
gasSum = gasSum.multiply(month).divide(listSize).divide(area).setScale(1);
waterSum = waterSum.multiply(month).divide(listSize.multiply(area), 1, BigDecimal.ROUND_HALF_UP);
elecSum = elecSum.multiply(month).divide(listSize.multiply(area), 1, BigDecimal.ROUND_HALF_UP);
gasSum = gasSum.multiply(month).divide(listSize.multiply(area), 1, BigDecimal.ROUND_HALF_UP);
//需要新增或更新的对象
resultList.add(new BusProjectAreaStat(proId, yearS, waterSum, elecSum, gasSum));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment