Commit 410a604e authored by chenzhao's avatar chenzhao

增加大屏接口

parent 7ba4a966
package com.yeejoin.amos.boot.module.jxiop.api.Enum;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum StationType {
FJC("风电场","FJC"),
JZGFC("集中光伏场","JZGFC"),
FBSGFC("分布式光伏场","FBSGFC");
private String name;
private String code;
public static String getCode(String name) {
for (StationType stationType : StationType.values())
{
if (stationType.getName().equals(name))
{
return stationType.getCode();
}
}
return null;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed;
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;
......@@ -18,4 +18,5 @@ public interface TemporaryDataMapper extends BaseMapper<TemporaryData> {
@RequestParam(value ="equipmentIndexName" ) String equipmentIndexName);
List<ESWindSpeed> getAllData();
}
......@@ -3,18 +3,37 @@ package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto;
import com.yeejoin.amos.boot.module.jxiop.biz.initdata.StationCacheDataInit;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.SjglZsjZsbtzMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
......@@ -28,6 +47,15 @@ public class CommonServiceImpl {
@Autowired
SjglZsjZsbtzMapper sjglZsjZsbtzMapper;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private StationCacheDataInit stationCacheDataInit;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
/**
* @deprecated 获取指标值总和
* @param gatewayId 网关id 用于拼接sql语句
......@@ -119,4 +147,53 @@ public class CommonServiceImpl {
socialContributionDtoPage.setCurrent(1);
return socialContributionDtoPage;
}
public List<StationCacheInfoDto> getListStationCacheInfoDto(){
List<StationCacheInfoDto> stationCacheInfoDtoList =redisTemplate.opsForList().range("station_info_cache",0,-1);
if(ObjectUtils.isEmpty(stationCacheInfoDtoList)){
try {
stationCacheDataInit.run();
stationCacheInfoDtoList =redisTemplate.opsForList().range("station_info_cache",0,-1);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return stationCacheInfoDtoList;
}
/*
*分组求和
**/
public List<? extends Terms.Bucket> getgroupsum(Map<String,List<String>> value, String keyavg, String groupKey, Class clas){
List<? extends Terms.Bucket> listdata=null;
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
for(String key:value.keySet()){
List<String> va= value.get(key);
queryBuilder.must( QueryBuilders.termsQuery(key, va));
}
TermsAggregationBuilder tb1 = AggregationBuilders.terms("groupKey").field(groupKey);
SumAggregationBuilder buyCountSum = AggregationBuilders.sum("buyCountSum").field(keyavg);
tb1.subAggregation(buyCountSum); // 通过typeId字段分组统计总数
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.addAggregation(tb1)
.withPageable(PageRequest.of(0, 1))
.build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, ESEquipments.class);
if (search.hasAggregations()) {
Aggregations aggregations = search.getAggregations();
if (Objects.nonNull(aggregations)) {
List<Aggregation> list= aggregations.asList();
listdata= list!=null&&!list.isEmpty()?((ParsedStringTerms) list.get(0)).getBuckets():null;
}
}
return listdata;
}
}
......@@ -103,6 +103,9 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
@Autowired
EmqKeeper emqKeeper;
@Autowired
CommonServiceImpl commonServiceImpl;
@Value("${pictureUrl}")
String pictureUrl;
......@@ -1745,22 +1748,32 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
}
public void sendMqttByRanking( List< Map<String,Object>> list,String code,String topic){
list.stream().sorted((o1,o2)->{
double o1Num = Double.parseDouble(o1.get("value").toString());
double o2Num = Double.parseDouble(o2.get("value").toString());
if ((o1Num-o2Num)<0){
return -1;
}else if ((o1Num-o2Num)>0){
return 1;
}else {
return 0;
//先发送区域消息
List<StationCacheInfoDto> listStationCacheInfoDto = commonServiceImpl.getListStationCacheInfoDto();
Map<String, List<StationCacheInfoDto>> belongAreaList = listStationCacheInfoDto.stream().collect(Collectors.groupingBy(StationCacheInfoDto::getBelongArea));
for (String s : belongAreaList.keySet()) {
List<String> ids = belongAreaList.get(s).stream().map(StationCacheInfoDto::getFanGatewayId).collect(Collectors.toList());
String idStrings = String.join(",", ids);
List<Map<String, Object>> dataList = list.stream().filter(e -> idStrings.contains(e.get("gateWayId").toString())).collect(Collectors.toList());
List<Map<String, Object>> resultList = mapListToSort(dataList).stream().limit(5).collect(Collectors.toList());
IPage<Map<String,Object>> result = new Page<>();
result.setRecords(resultList);
result.setCurrent(1);
result.setTotal(resultList.size());
try {
emqKeeper.getMqttClient().publish(s+"/"+topic+"/"+code,JSON.toJSONString(result).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
});
}
//发送全国数据消息
List<Map<String, Object>> maps = mapListToSort(list);
List<Map<String, Object>> resultList = maps.stream().limit(5).collect(Collectors.toList());
IPage<Map<String,Object>> result = new Page<>();
result.setRecords(list);
result.setRecords(resultList);
result.setCurrent(1);
result.setTotal(list.size());
result.setTotal(resultList.size());
try {
emqKeeper.getMqttClient().publish(topic+"/"+code,JSON.toJSONString(result).getBytes(),0,false);
} catch (MqttException e) {
......@@ -1769,6 +1782,22 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
}
List< Map<String,Object>> mapListToSort(List< Map<String,Object>> list){
list.stream().sorted((o1,o2)->{
double o1Num = Double.parseDouble(o1.get("value").toString());
double o2Num = Double.parseDouble(o2.get("value").toString());
if ((o1Num-o2Num)<0){
return -1;
}else if ((o1Num-o2Num)>0){
return 1;
}else {
return 0;
}
});
return list;
}
public Map<String, Object> generatingCapacity (String gatewayId,String query){
String querySql = " SELECT * FROM indicators_"+gatewayId+" WHERE equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量'";
......
package com.yeejoin.amos.boot.module.jxiop.biz.ESDto;
import io.github.classgraph.json.Id;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Data
@Accessors(chain = true)
@Document(indexName = "wind_speed")
public class ESWindSpeed {
@Id
private Long sequenceNumber;
@Field(type = FieldType.Text, index = false)
private String createdTime;
@Field(type = FieldType.Text, index = false)
private String equipmentIndexName;
@Field(type = FieldType.Text, index = false)
private String equipmentNumber;
@Field(type = FieldType.Text, index = false)
private String gatewayId;
@Field(type = FieldType.Double, index = false)
private Double value;
@Field(type = FieldType.Text, index = false)
private String batchNo;
}
......@@ -255,12 +255,15 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "概览-全站功率曲线")
@GetMapping("/overviewWindSpeed")
public ResponseModel<Map<String, Object>> getOverviewWindSpeed(@RequestParam(value = "stationId", required = true)String stationId,@RequestParam(value = "type", required = false)String type) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getBoosterGatewayId();
if (null == type){
gatewayId = stationBasic.getFanGatewayId();
}
public ResponseModel<Map<String, Object>> getOverviewWindSpeed(@RequestParam(value = "stationId", required = false)String stationId,@RequestParam(value = "type", required = false)String type) {
String gatewayId = "";
if (null != stationId){
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
gatewayId = stationBasic.getBoosterGatewayId();
if (null == type){
gatewayId = stationBasic.getFanGatewayId();
}
}
Map<String, Object> detailsWindSpeed = monitorFanIndicator.getDetailsWindSpeedAll(gatewayId);
return ResponseHelper.buildResponse(detailsWindSpeed);
......@@ -854,8 +857,4 @@ public class MonitorFanIdxController extends BaseController {
return CommonResponseUtil.success();
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -17,5 +18,5 @@ public interface TemporaryDataMapper extends BaseMapper<TemporaryData> {
Map<String, String> getStatisticsInfo (@RequestParam(value ="gatewayId" ) String gatewayId,
@RequestParam(value ="equipmentIndexName" ) String equipmentIndexName);
List<ESWindSpeed> getAllData();
}
package com.yeejoin.amos.boot.module.jxiop.biz.repository;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* @description:
* @author: tw
* @createDate: 2023/8/8
*/
@Repository
public interface ESWindSpeedRepository extends PagingAndSortingRepository<ESWindSpeed, Long> {
}
package com.yeejoin.amos.boot.module.jxiop.biz.scheduled;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TemporaryData;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.TemporaryDataMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESWindSpeedRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.ArrayList;
import java.util.List;
@EnableScheduling
public class WindSpeedScheduled {
@Autowired
TemporaryDataMapper temporaryDataMapper;
@Autowired
ESWindSpeedRepository esWindSpeedRepository;
@Scheduled(cron="${windSpeed.cron}")
private void initData(){
esWindSpeedRepository.saveAll(temporaryDataMapper.getAllData());
}
}
......@@ -777,7 +777,6 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
TemporaryData temporaryData = new TemporaryData();
temporaryData.setBatchNo(timeInMillis);
temporaryData.setCreatedTime(time.split(" ")[1]);
temporaryData.setEquipmentIndexName(indicatorsDto.getDisplayName());
temporaryData.setGatewayId(indicatorsDto.getGatewayId());
temporaryData.setValue(Float.valueOf(indicatorsDto.getValue()));
temporaryData.setEquipmentNumber(indicatorsDto.getEquipmentNumber());
......@@ -791,7 +790,6 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
TemporaryData temporaryData = new TemporaryData();
temporaryData.setBatchNo(timeInMillis);
temporaryData.setCreatedTime(time.split(" ")[1]);
temporaryData.setEquipmentIndexName(indicatorsDto.getDisplayName());
temporaryData.setGatewayId(indicatorsDto.getGatewayId());
temporaryData.setValue(Float.valueOf(indicatorsDto.getValue()));
temporaryData.setEquipmentNumber(indicatorsDto.getEquipmentNumber());
......
......@@ -77,7 +77,8 @@ gl.avg.column=有功功率,日利用小时,瞬时风速
#ES 曲线图定时 0 57 23 * * ?
windSpeed.cron = 0 25 9 * * ?
spring.elasticsearch.rest.uris=http://39.98.224.23:9200
......
......@@ -14,6 +14,9 @@
<if test="gatewayId != null and gatewayId != ''">
gatewayId = #{gatewayId}
</if>
<if test="gatewayId == null or gatewayId == ''">
equipmentNumber is not null
</if>
</where>
GROUP BY batch_no ,equipmentIndexName;
</select>
......@@ -29,6 +32,16 @@
FROM
`temporary_data`
WHERE
gatewayId = #{gatewayId} and equipmentIndexName =#{equipmentIndexName}
</select>
<select id="getAllData" resultType="com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed">
SELECT
*
FROM
`temporary_data`
</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