Commit e1d0b8ee authored by chenzhao's avatar chenzhao

修改代码

parent 573df0a0
......@@ -7,10 +7,14 @@ import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.RunRecord;
import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.MonitorFanIndicatorImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -20,6 +24,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -37,6 +42,18 @@ public class MonitorFanIdxController extends BaseController {
MonitorFanIndicatorImpl monitorFanIndicator;
@Autowired
StationBasicMapper stationBasicMapper;
@Autowired
CommonServiceImpl commonService;
@Value("${gl.sum.column}")
String sumColumn;
@Value("${gl.avg.column}")
String avgColumn;
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "根据设备编号、场站id、前段展示模块、系统类型查询表数据")
@GetMapping("/getFanIdxInfoByPage")
......@@ -129,4 +146,64 @@ public class MonitorFanIdxController extends BaseController {
@RequestParam(value = "frontModule", required = false) String frontModule) {
return ResponseHelper.buildResponse(monitorFanIndicator.getRealTimeTemperature(equipNum, stationId, frontModule)) ;
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图-总概览")
@GetMapping("/overview")
public ResponseModel<Map<String, Object>> getData(@RequestParam(value = "stationId", required = true)String stationId) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getFanGatewayId();
String [] sumColumns = new String[]{"日发电量","月发电量","年发电量"};
String [] avgColumns = new String[]{"有功功率","瞬时风速"};
List<String> columnList = Arrays.asList(sumColumns);
List<String> columnLists = Arrays.asList(avgColumns);
Map<String, Object> columnMap = new HashMap<>();
for (String column : columnList) {
Double result = commonService.getTotalByIndicatior(gatewayId, column);
columnMap.put(column, result);
}
for (String column : columnLists) {
Double result = commonService.getAvgvalueByIndicatior(gatewayId, column);
columnMap.put(column, result);
}
String num = monitorFanIndicator.getFJCount(gatewayId);
columnMap.put("风机台数",Integer.valueOf(num));
Double capacityl = commonService.getStationCapactityByStationWerks(stationBasic.getStationNumber());
columnMap.put("装机容量",capacityl);
return ResponseHelper.buildResponse(columnMap);
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "概览-全站风速功率曲线")
@GetMapping("/overviewWindSpeed")
public ResponseModel<Map<String, Object>> getOverviewWindSpeed(@RequestParam(value = "stationId", required = true)String stationId) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getFanGatewayId();
Map<String, Object> detailsWindSpeed = monitorFanIndicator.getDetailsWindSpeedAll(gatewayId);
return ResponseHelper.buildResponse(detailsWindSpeed);
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机详情-风速功率曲线")
@GetMapping("/detailsWindSpeed")
public ResponseModel<Map<String, Object>> getDetailsWindSpeed(@RequestParam(value = "stationId", required = true)String stationId,String name) {
name = name + "风机";
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getFanGatewayId();
Map<String, Object> detailsWindSpeed = monitorFanIndicator.getDetailsWindSpeed(gatewayId, name);
return ResponseHelper.buildResponse(detailsWindSpeed);
}
}
......@@ -23,4 +23,18 @@ public class IndicatorsDto {
private String unit;
private String value;
private String valueLabel;
private String distinct;
private String time;
public String getTime() {
String[] ts= time.replace(":00Z","").split("T");
return ts[1];
}
public void setTime(String time) {
this.time = time;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class TemporaryDataDto {
private Long sequenceNumber;
private String createdTime;
private String equipmentIndexName;
private String equipmentNumber;
private String gatewayId;
private float value;
}
package com.yeejoin.amos.boot.module.jxiop.biz.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
@TableName("temporary_data")
public class TemporaryData {
@TableField("sequence_nbr")
private Long sequenceNumber;
@TableField("created_time")
private String createdTime;
@TableField("equipmentIndexName")
private String equipmentIndexName;
@TableField("equipmentNumber")
private String equipmentNumber;
@TableField("gatewayId")
private String gatewayId;
@TableField("value")
private float value;
@TableField("batch_no")
private long batchNo;
}
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
public interface TemporaryDataMapper extends BaseMapper<TemporaryData> {
List<Map<String, String>> timingTemporarysSorageData (@RequestParam(value ="gatewayId" ) String gatewayId);
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.SjglZsjZsbtzMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -13,6 +14,10 @@ public class CommonServiceImpl {
@Autowired
InfluxDButils influxDButils;
@Autowired
SjglZsjZsbtzMapper sjglZsjZsbtzMapper;
/**
* @deprecated 获取指标值总和
* @param gatewayId 网关id 用于拼接sql语句
......@@ -41,4 +46,8 @@ public class CommonServiceImpl {
avageValue = doubleList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
return avageValue;
}
public Double getStationCapactityByStationWerks(String WERKS){
return sjglZsjZsbtzMapper.getStationCapactityByStationWerks(WERKS);
}
}
......@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator;
......@@ -15,16 +17,21 @@ import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ColModel;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.DataGridMock;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.SjglZsjZsbtz;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TpriDmpDatabook;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.TemporaryDataMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import com.yeejoin.amos.boot.module.jxiop.biz.service.IMonitorFanIndicator;
import com.yeejoin.amos.component.robot.BadRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
......@@ -48,6 +55,14 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
@Autowired
InfluxDButils influxDButils;
@Autowired
InfluxDButils influxDButils;
@Autowired
TemporaryDataMapper temporaryDataMapper;
@Autowired
TemporaryDataServiceImpl temporaryDataService;
@Autowired
SjglZsjZsbtzServiceImpl sjglZsjZsbtzServiceImpl;
......@@ -322,4 +337,144 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
return "0";
}
}
public String getFJCount(String gatewayId){
String sql = "SELECT count(DISTINCT equipmentNumber) as value FROM indicators_"+gatewayId;
List<IndicatorsDto> indicatorsDtoList = influxDButils.getListData(sql,IndicatorsDto.class);
if (indicatorsDtoList.size()>0){
return indicatorsDtoList.get(0).getValue();
}
return null;
}
public Map<String,Object> getDetailsWindSpeedAll(String gatewayId){
List<Map<String, String>> list = temporaryDataMapper.timingTemporarysSorageData(gatewayId);
Map<String,Object> map = new HashMap<>();
List<String> values = new ArrayList<>();
List<String> valueList = new ArrayList<>();
Set<String> time = new HashSet<>();
for (Map<String, String> stringStringMap : list) {
if (stringStringMap.get("equipmentIndexName").equals("有功功率")){
values.add(stringStringMap.get("value"));
}else {
valueList.add(stringStringMap.get("value"));
}
time.add(stringStringMap.get("createdTime"));
}
List< Map<String,Object>> seriesData = new ArrayList<>();
Map<String,Object> map3 = new HashMap<>();
Map<String,Object> map1 = new HashMap<>();
Map<String,Object> map2 = new HashMap<>();
map1.put("data", values);
map2.put("data", valueList);
seriesData.add(map1);
seriesData.add(map2);
map.put("seriesData", seriesData);
map.put("axisData",time);
return map;
}
public Map<String,Object> getDetailsWindSpeed(String gatewayId,String name){
Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
String time = "";
try {
time = DateUtils.dateFormat(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
String sql = "SELECT DISTINCT value FROM iot_data_"+gatewayId+" WHERE equipmentIndexName = '瞬时风速' and equipmentSpecificName =~/"+name+"/and time >='"+time+"'GROUP BY time(2m)";
String sql1 = "SELECT DISTINCT value FROM iot_data_"+gatewayId+" WHERE equipmentIndexName = '有功功率' and equipmentSpecificName =~/"+name+"/ and time >='"+time+"'GROUP BY time(2m)";
List<IndicatorsDto> indicatorsDtoList = influxDButils.getListDataAll(sql,IndicatorsDto.class);
List<IndicatorsDto> indicatorsDtoLists = influxDButils.getListDataAll(sql1,IndicatorsDto.class);
LinkedHashMap<String, String> collect = indicatorsDtoList.stream().collect(Collectors.toMap(IndicatorsDto::getTime, IndicatorsDto::getDistinct,(key1, ky2)-> (String) key1,LinkedHashMap::new));
LinkedHashMap<String, String> collects = indicatorsDtoLists.stream().collect(Collectors.toMap(IndicatorsDto::getTime, IndicatorsDto::getDistinct,(key1, ky2)-> (String) key1,LinkedHashMap::new));
Collection<String> values = collect.values();
Collection<String> valuess = collects.values();
Set<String> keySet = collect.keySet();
Set<String> keySets = collects.keySet();
List< Map<String,Object>> seriesData = new ArrayList<>();
Map<String,Object> map = new HashMap<>();
Map<String,Object> map1 = new HashMap<>();
Map<String,Object> map2 = new HashMap<>();
map1.put("data", values);
map2.put("data", valuess);
seriesData.add(map1);
seriesData.add(map2);
map.put("seriesData", seriesData);
map.put("axisData",keySet.size()>keySets.size()?keySet:keySets);
return map;
}
@Scheduled(cron = "0 */1 * * * ?")
private void schedTaskData(){
log.info("定时插入数据开始");
LambdaQueryWrapper<StationBasic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BaseEntity::getIsDelete,false);
List<StationBasic> stationBasics = stationBasicMapper.selectList(wrapper);
for (StationBasic stationBasic : stationBasics) {
timingTemporarysSorageData(stationBasic.getFanGatewayId());
}
}
public void timingTemporarysSorageData(String gatewayId){
String sql = "SELECT * FROM indicators_"+gatewayId+" WHERE equipmentIndexName = '瞬时风速' ";
String sql1 = "SELECT * FROM indicators_"+gatewayId+" WHERE equipmentIndexName = '有功功率'";
List<IndicatorsDto> indicatorsDtoList = influxDButils.getListDataAll(sql,IndicatorsDto.class);
List<IndicatorsDto> indicatorsDtoLists = influxDButils.getListDataAll(sql1,IndicatorsDto.class);
List<TemporaryData> temporaryDatas = new ArrayList<>();
List<TemporaryData> temporaryDatass = new ArrayList<>();
String time = "";
try {
time = DateUtils.dateFormat(new Date(), DateUtils.MINUTE_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
long timeInMillis = new Date().getTime();
for (IndicatorsDto indicatorsDto : indicatorsDtoList) {
try {
TemporaryData temporaryData = new TemporaryData();
temporaryData.setBatchNo(timeInMillis);
temporaryData.setCreatedTime(time.split(" ")[1]);
temporaryData.setEquipmentIndexName(indicatorsDto.getEquipmentIndexName());
temporaryData.setGatewayId(indicatorsDto.getGatewayId());
temporaryData.setValue(Float.valueOf(indicatorsDto.getValue()));
temporaryData.setEquipmentNumber(indicatorsDto.getEquipmentNumber());
temporaryDatas.add(temporaryData);
} catch (Exception e) {
e.printStackTrace();
}
}
for (IndicatorsDto indicatorsDto : indicatorsDtoLists) {
try {
TemporaryData temporaryData = new TemporaryData();
temporaryData.setBatchNo(timeInMillis);
temporaryData.setCreatedTime(time.split(" ")[1]);
temporaryData.setEquipmentIndexName(indicatorsDto.getEquipmentIndexName());
temporaryData.setGatewayId(indicatorsDto.getGatewayId());
temporaryData.setValue(Float.valueOf(indicatorsDto.getValue()));
temporaryData.setEquipmentNumber(indicatorsDto.getEquipmentNumber());
temporaryDatass.add(temporaryData);
} catch (Exception e) {
e.printStackTrace();
}
}
temporaryDataService.saveBatch(temporaryDatas);
temporaryDataService.saveBatch(temporaryDatass);
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.TemporaryDataDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.TemporaryDataMapper;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.service.BaseService;
@Service
public class TemporaryDataServiceImpl extends BaseService<TemporaryDataDto,TemporaryData, TemporaryDataMapper> {
}
......@@ -91,4 +91,37 @@ public class InfluxDButils {
}
return list;
}
public <T> List<T> getListDataAll(String sql, Class<T> clazz) {
List<T> list = new ArrayList<>();
try {
QueryResult query = influxDbConnection.query(sql);
List<QueryResult.Result> queryResults = query.getResults();
for (QueryResult.Result result : queryResults) {
List<QueryResult.Series> series = result.getSeries();
if (series == null) {
continue;
}
for (QueryResult.Series serie : series) {
List<List<Object>> values = serie.getValues();
List<String> columns = serie.getColumns();
for (int i = 0; i < values.size(); ++i) {
T object = clazz.newInstance();
BeanWrapperImpl bean = new BeanWrapperImpl(object);
for (int j = 0; j < columns.size(); ++j) {
String k = columns.get(j);
Object v = values.get(i).get(j);
bean.setPropertyValue(k, v);
}
list.add(object);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.jxiop.biz.mapper2.TemporaryDataMapper">
<select id="timingTemporarysSorageData" resultType="map">
SELECT sum(value) as value ,
created_time as createdTime ,
equipmentIndexName
FROM
`temporary_data`
<where>
<if test="gatewayId != null and gatewayId != ''">
gatewayId = #{gatewayId}
</if>
</where>
GROUP BY batch_no ,equipmentIndexName;
</select>
</mapper>
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