Commit fd48fe02 authored by caotao's avatar caotao

1.监盘大屏全国运维数据根据新数据源重新开发。2.监盘大屏区域运维数据根据新数据源重新开发。3.全国新能源接入需要根据物联监盘数据源重新调试开发。

4.全国新能源接入需要根据物联监盘数据源重新调试开发。
parent 9e6849c9
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.Map;
@Data
public class CoreValuesDto {
private String name;
private ArrayList<Map<String,Object>> data;
private Map<String,Object> dataMap;
}
...@@ -13,12 +13,14 @@ public class StationCacheInfoDto implements Serializable { ...@@ -13,12 +13,14 @@ public class StationCacheInfoDto implements Serializable {
private String stationName; private String stationName;
//场站类型 //场站类型
private String stationType; private String stationType;
//场站类型
private String stationNumber;
//所属省份 //所属省份
private String belongProvince; private String belongProvince;
//所属片区 //所属片区
private String belongArea; private String belongArea;
//装机容量 //装机容量
private String installedCapacity; private String installedCapacity="0.0";
//设备数量 //设备数量
private String equipmentNumbers; private String equipmentNumbers;
//风机网关 //风机网关
...@@ -27,4 +29,10 @@ public class StationCacheInfoDto implements Serializable { ...@@ -27,4 +29,10 @@ public class StationCacheInfoDto implements Serializable {
private String boosterGatewayId; private String boosterGatewayId;
//片区code //片区code
private String areaCode; private String areaCode;
//address
private String address;
//core服务配置的场站名称
private String stationCoreName;
//core服务配置的升压站名称
private String boosterCoreName;
} }
package com.yeejoin.amos.boot.module.jxiop.biz.feign;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
//@FeignClient(name = "${mcb.warning.name:MCB-SERVER}", path = "warning", configuration = {FeignConfiguration.class})
@FeignClient(name = "mcb", url = "http://10.20.1.160:10005", path = "core", configuration = {
FeignConfiguration.class })
public interface CoreFeignClient {
/**
* @pare
*/
@GetMapping("/scene-device-info/getValues")
FeignClientResult<List<Object>> getValues(
@RequestParam(required = false, value = "stationNames") String stationNames,
@RequestParam(required = false,value = "pointNames") String pointNames);
}
package com.yeejoin.amos.boot.module.jxiop.biz.feign;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor {
@Autowired
AmosRequestContext amosAuth;
public FeignBasicAuthRequestInterceptor() {
}
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
/* Get token from header */
String authToken = request.getHeader("token");
/* If token not found get it from request parameter */
if (StringUtils.isBlank(authToken)) {
authToken = request.getHeader("X-Access-Token");
}
template.header("X-Access-Token", authToken);
template.header("token", authToken);
template.header("appKey", request.getHeader("appKey"));
template.header("product", request.getHeader("product"));
template.header("clientType", "feignClient");
//User-Agent for core
template.header("User-Agent", "java");
}else {
template.header("X-Access-Token", amosAuth.getToken());
template.header("token", amosAuth.getToken());
template.header("appKey", amosAuth.getAppKey());
template.header("product", amosAuth.getProduct());
template.header("clientType", "feignClient");
//User-Agent for core
template.header("User-Agent", "java");
}
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.feign;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignConfiguration {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
@Bean
public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new FeignBasicAuthRequestInterceptor();
}
@Bean
public FeignErrorDecoder errorDecoder(){
return new FeignErrorDecoder();
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.feign;
import com.alibaba.fastjson.JSONObject;
import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignErrorDecoder implements ErrorDecoder {
private static final Logger log = LoggerFactory.getLogger(FeignErrorDecoder.class);
@Override
public Exception decode(String methodKey, Response response) {
String msg = null;
try {
msg = Util.toString(response.body().asReader(Util.UTF_8));
JSONObject object = JSONObject.parseObject(msg);
throw new RuntimeException(object.get("devMessage").toString());
} catch (IOException e) {
log.error("feign 调用失败" + e.getMessage());
}
throw new RuntimeException(methodKey + "远程调用失败");
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.CoreValuesDto;
import java.util.List;
public interface CoreCommonService {
/**
* @deprecated 远程调用core服务根据厂长名称
* @param stationNames 要查的场站名称需要使用逗号分隔 eg:夏造风机,石灰山风机
* @param pointsNames 要查的测点名称需要使用逗号分隔开 eg:日发电量,月发电量,年发电
* @return CoreValuesDto
*/
List<CoreValuesDto> getValuesByStationNamesAndPointsNames(String stationNames, String pointsNames );
/**
* @deprecated 获取测点数据总和
* @param coreValuesDtoList
* @return
*/
Double getSumOfByPointName(List<CoreValuesDto> coreValuesDtoList,String pointName);
/**
* @deprecated 获取测点数据平均值
* @param coreValuesDtoList
* @return
*/
Double getAverageOfByPointName(List<CoreValuesDto> coreValuesDtoList,String pointName);
}
package com.yeejoin.amos.boot.module.jxiop.biz.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.RegionNationWideDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface MonitorService {
/**
* @Description 根据区域编码动态运维数据
* @param areaCode 区域编码
* @return 全国运维数据
*/
IPage<Map<String, Object>> operationData(String areaCode);
/**
* @Description 全国新能源接入情况
* @return Map<String, Object>
*/
Map<String, Object> accessSituation();
/**
* @Description 区域新能源接入情况
* @return Map<String, Object>
*/
Map<String, Object> qyAccessSituation();
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.CoreValuesDto;
import com.yeejoin.amos.boot.module.jxiop.biz.feign.CoreFeignClient;
import com.yeejoin.amos.boot.module.jxiop.biz.service.CoreCommonService;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class CoreCommonServiceImpl implements CoreCommonService {
private final CoreFeignClient coreFeignClient;
@Override
public List<CoreValuesDto> getValuesByStationNamesAndPointsNames(String stationNames, String pointsNames) {
FeignClientResult<List<Object>> feignClientResult = coreFeignClient.getValues(stationNames, pointsNames);
List<Object> list = feignClientResult.getResult();
List<CoreValuesDto> result = new ArrayList<>();
list.forEach(o -> {
CoreValuesDto coreValuesDto = JSONObject.parseObject(JSONObject.toJSONString(o), CoreValuesDto.class);
coreValuesDto.setDataMap(coreValuesDto.getData().stream().flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b)));
result.add(coreValuesDto);
});
return result;
}
@Override
public Double getSumOfByPointName(List<CoreValuesDto> coreValuesDtoList, String pointName) {
AtomicReference<Double> result = new AtomicReference<>(0.0);
coreValuesDtoList = coreValuesDtoList.stream().filter(coreValuesDto -> coreValuesDto.getDataMap().size() > 0 && coreValuesDto.getDataMap().containsKey(pointName)).collect(Collectors.toList());
coreValuesDtoList.forEach(coreValuesDto -> {
result.set(result.get() + Double.parseDouble(coreValuesDto.getDataMap().get(pointName).toString()));
});
return result.get();
}
@Override
public Double getAverageOfByPointName(List<CoreValuesDto> coreValuesDtoList, String pointName) {
AtomicReference<Double> result = new AtomicReference<>(0.0);
coreValuesDtoList = coreValuesDtoList.stream().filter(coreValuesDto -> coreValuesDto.getDataMap().size() > 0 && coreValuesDto.getDataMap().containsKey(pointName)).collect(Collectors.toList());
coreValuesDtoList.forEach(coreValuesDto -> {
result.set(result.get() + Double.parseDouble(coreValuesDto.getDataMap().get(pointName).toString()));
});
return result.get() / coreValuesDtoList.size();
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jxiop.api.Enum.StationType;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MapRegion;
import com.yeejoin.amos.boot.module.jxiop.api.entity.Region;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.MapRegionMapper;
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.StationCacheInfoDto;
import com.yeejoin.amos.boot.module.jxiop.biz.service.MonitorService;
import lombok.RequiredArgsConstructor;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.io.PipedReader;
import java.util.*;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class MonitorServiceImpl implements MonitorService {
private final RegionMapper regionMapper;
private final MapRegionMapper mapRegionMapper;
private final StationBasicMapper stationBasicMapper;
private final EmqKeeper emqKeeper;
@Override
public IPage<Map<String, Object>> operationData(String areaCode) {
List<StationCacheInfoDto> list = getListStationCacheInfoDto();
if (null != areaCode) {
list = list.stream().filter(e -> e.getAreaCode().toUpperCase(Locale.ROOT).equals(areaCode.toUpperCase(Locale.ROOT))).collect(Collectors.toList());
}
List<Map<String, Object>> mapList = new ArrayList<>();
Map<String, List<StationCacheInfoDto>> listMap = list.stream().collect(Collectors.groupingBy(StationCacheInfoDto::getStationType, Collectors.toList()));
for (StationType value : StationType.values()) {
Map<String, Object> map = new LinkedHashMap<>();
List<StationCacheInfoDto> dtos = listMap.get(value.getCode());
map.put("data", dtos == null ? 0 : dtos.size());
map.put("title", dtos == null ? 0 : dtos.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getInstalledCapacity())).mapToDouble(l -> Double.parseDouble(l.getInstalledCapacity())).sum());
mapList.add(map);
}
IPage<Map<String, Object>> result = new Page<>();
result.setRecords(mapList);
result.setCurrent(1);
result.setTotal(mapList.size());
return result;
}
@Override
public Map<String, Object> accessSituation() {
Map<String, Object> map = new LinkedHashMap<>();
List<StationCacheInfoDto> list = getListStationCacheInfoDto();
double sum = list.stream().mapToDouble(l -> Double.parseDouble(l.getInstalledCapacity())).sum();
Map<String, List<StationCacheInfoDto>> listMap = list.stream().collect(Collectors.groupingBy(StationCacheInfoDto::getStationType, Collectors.toList()));
for (StationType value : StationType.values()) {
List<StationCacheInfoDto> dtos = listMap.get(value.getCode());
map.put(value.getCode(), dtos == null ? 0 : dtos.size());
map.put(value.getCode() + "title", dtos == null ? 0 : dtos.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getInstalledCapacity())).mapToDouble(l -> Double.parseDouble(l.getInstalledCapacity())).sum());
}
map.put("total", list.size());
map.put("num", sum);
try {
emqKeeper.getMqttClient().publish("/accessSituation/topic", JSON.toJSONString(map).getBytes(), 0, true);
} catch (MqttException e) {
}
return map;
}
@Override
public Map<String, Object> qyAccessSituation() {
Map<String, Object> map = new LinkedHashMap<>();
List<StationCacheInfoDto> list = this.getListStationCacheInfoDto();
Map<String, List<StationCacheInfoDto>> belongAreaList = list.stream().collect(Collectors.groupingBy(StationCacheInfoDto::getAreaCode));
for (String s : belongAreaList.keySet()) {
double sum = belongAreaList.get(s).stream().mapToDouble(l -> Double.parseDouble(l.getInstalledCapacity())).sum();
Map<String, List<StationCacheInfoDto>> listMap = list.stream().collect(Collectors.groupingBy(StationCacheInfoDto::getStationType, Collectors.toList()));
for (StationType value : StationType.values()) {
List<StationCacheInfoDto> dtos = listMap.get(value.getCode());
map.put(value.getCode(), dtos == null ? 0 : dtos.size());
map.put(value.getCode() + "title", dtos == null ? 0 : dtos.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getInstalledCapacity())).mapToDouble(l -> Double.parseDouble(l.getInstalledCapacity())).sum());
}
map.put("total", list.size());
map.put("num", sum);
try {
emqKeeper.getMqttClient().publish("/accessSituation/topic/" + s, JSON.toJSONString(map).getBytes(), 1, true);
} catch (MqttException e) {
}
}
return map;
}
/**
* 获取场站的缓存信息,后续启动时需要将此数据从
*
* @return
*/
public List<StationCacheInfoDto> getListStationCacheInfoDto() {
List<StationCacheInfoDto> stationCacheInfoDtos = new ArrayList<>();
List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1));
List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name"));
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area").isNotNull("fan_gateway_id"));
for (int i = 0; i < stationBasicList.size(); i++) {
StationBasic stationBasic = stationBasicList.get(i);
StationCacheInfoDto stationCacheInfoDto = new StationCacheInfoDto();
stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString());
stationCacheInfoDto.setStationName(stationBasic.getStationName());
stationCacheInfoDto.setStationType(stationBasic.getStationType());
stationCacheInfoDto.setBelongProvince(regionList.stream().filter(region -> region.getRegionCode().toString().equals(stationBasic.getBelongArea().replace("[", "").split(",")[0])).map(region -> region.getRegionName()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setBelongArea(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 2)) || mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 3))).map(mapRegion -> mapRegion.getName()).collect(Collectors.toList()).get(0));
Double installedCapacity = 0.0d;
if (!ObjectUtils.isEmpty(stationBasic.getInstalledCapacity())) {
installedCapacity = stationBasic.getInstalledCapacity();
}
stationCacheInfoDto.setInstalledCapacity(String.format("%.2f", installedCapacity));
stationCacheInfoDto.setFanGatewayId(stationBasic.getFanGatewayId());
stationCacheInfoDto.setAreaCode(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 2)) || mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 3))).map(mapRegion -> mapRegion.getAreaCode()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setBoosterGatewayId(stationBasic.getBoosterGatewayId());
stationCacheInfoDto.setBoosterCoreName(stationBasic.getBoosterCoreName());
stationCacheInfoDto.setStationCoreName(stationBasic.getStationCoreName());
stationCacheInfoDtos.add(stationCacheInfoDto);
}
return stationCacheInfoDtos;
}
}
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