Commit 7b8750f9 authored by caotao's avatar caotao

优化缓存数据逻辑

parent c51e1a35
...@@ -43,8 +43,8 @@ public class StationCacheDataInit implements CommandLineRunner { ...@@ -43,8 +43,8 @@ public class StationCacheDataInit implements CommandLineRunner {
Logger logger = LoggerFactory.getLogger(StationCacheDataInit.class); Logger logger = LoggerFactory.getLogger(StationCacheDataInit.class);
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
List<StationCacheInfoDto> stationCacheInfoDtos = new ArrayList<>();
redisTemplate.delete("station_info_cache"); redisTemplate.delete("station_info_cache");
List<StationCacheInfoDto> stationCacheInfoDtos = new ArrayList<>();
List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1)); List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1));
List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name")); 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")); List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area").isNotNull("fan_gateway_id"));
......
...@@ -18,6 +18,7 @@ import com.yeejoin.amos.boot.module.jxiop.biz.initdata.StationCacheDataInit; ...@@ -18,6 +18,7 @@ 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.mapper2.SjglZsjZsbtzMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository; import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil; import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.*;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.ScriptType;
...@@ -44,6 +45,7 @@ import java.util.*; ...@@ -44,6 +45,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j
public class CommonServiceImpl { public class CommonServiceImpl {
@Autowired @Autowired
...@@ -240,14 +242,14 @@ public class CommonServiceImpl { ...@@ -240,14 +242,14 @@ public class CommonServiceImpl {
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(indicator)); queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(indicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(gatewayId)); queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(gatewayId));
likeQuerCondtion.put(CommonConstans.QueryStringFrontMoudle, "逆变器"); likeQuerCondtion.put(CommonConstans.QueryStringFrontMoudle, "逆变器");
List<ESEquipments> result = getListDataByCondtions(queryCondtion, null, ESEquipments.class,likeQuerCondtion); List<ESEquipments> result = getListDataByCondtions(queryCondtion, null, ESEquipments.class, likeQuerCondtion);
Double totalvalue = 0.00; Double totalvalue = 0.00;
try { try {
totalvalue = result.stream().filter(stringObjectMap -> !ObjectUtils.isEmpty(stringObjectMap.getValueF())).mapToDouble(l -> Double.parseDouble(l.getValueF().toString())).sum(); totalvalue = result.stream().filter(stringObjectMap -> !ObjectUtils.isEmpty(stringObjectMap.getValueF())).mapToDouble(l -> Double.parseDouble(l.getValueF().toString())).sum();
} catch (Exception e) { } catch (Exception e) {
return totalvalue; return totalvalue;
} }
return Double.valueOf(String.format("%.4f", totalvalue*CommonConstans.pvGenPoweActor)); return Double.valueOf(String.format("%.4f", totalvalue * CommonConstans.pvGenPoweActor));
} }
public Double getTotalByIndicatiorAndParams(String gatewayId, String indicator, String querySql) { public Double getTotalByIndicatiorAndParams(String gatewayId, String indicator, String querySql) {
...@@ -388,42 +390,42 @@ public class CommonServiceImpl { ...@@ -388,42 +390,42 @@ public class CommonServiceImpl {
* @deprecated 获取缓存场站信息数据 * @deprecated 获取缓存场站信息数据
*/ */
public List<StationCacheInfoDto> getListStationCacheInfoDto() { public List<StationCacheInfoDto> getListStationCacheInfoDto() {
List<StationCacheInfoDto> stationCacheInfoDtoList = redisTemplate.opsForList().range("station_info_cache", 0, -1);
if (ObjectUtils.isEmpty(stationCacheInfoDtoList)) {
try {
List<StationCacheInfoDto> stationCacheInfoDtos = new ArrayList<>(); List<StationCacheInfoDto> stationCacheInfoDtos = new ArrayList<>();
stationCacheInfoDtos = redisTemplate.opsForList().range("station_info_cache", 0, -1);
if (ObjectUtils.isEmpty(stationCacheInfoDtos)) {
List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1)); List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1));
List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name")); 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")); List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area").isNotNull("fan_gateway_id"));
stationBasicList.forEach(stationBasic -> { for (int i = 0; i < stationBasicList.size(); i++) {
StationBasic stationBasic = stationBasicList.get(i);
StationCacheInfoDto stationCacheInfoDto = new StationCacheInfoDto(); StationCacheInfoDto stationCacheInfoDto = new StationCacheInfoDto();
stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString()); stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString());
stationCacheInfoDto.setStationName(stationBasic.getStationName()); stationCacheInfoDto.setStationName(stationBasic.getStationName());
stationCacheInfoDto.setStationType(stationBasic.getStationType()); 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.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)); 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));
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.setInstalledCapacity(String.format("%.2f", sjglZsjZsbtzMapper.getStationCapactityByStationWerks(stationBasic.getStationNumber()))); stationCacheInfoDto.setInstalledCapacity(String.format("%.2f", sjglZsjZsbtzMapper.getStationCapactityByStationWerks(stationBasic.getStationNumber())));
try {
List<QueryDto> queryDtoList = new ArrayList<>(); List<QueryDto> queryDtoList = new ArrayList<>();
queryDtoList.add(new QueryDto("gatewayId", stationBasic.getFanGatewayId())); queryDtoList.add(new QueryDto("gatewayId", stationBasic.getFanGatewayId()));
queryDtoList.add(new QueryDto("equipmentIndexName.keyword", "有功功率")); queryDtoList.add(new QueryDto("equipmentIndexName.keyword", "有功功率"));
if (!stationBasic.getStationType().equals("FDZ")) { if (!stationBasic.getStationType().equals("FDZ")) {
queryDtoList.add(new QueryDto("frontModule", "逆变器")); queryDtoList.add(new QueryDto("frontModule", "逆变器"));
} }
stationCacheInfoDto.setEquipmentNumbers(this.getCount(queryDtoList, "equipmentNumber.Keyword", ESEquipments.class).toString()); stationCacheInfoDto.setEquipmentNumbers(getCount(queryDtoList, "equipmentNumber.Keyword", ESEquipments.class).toString());
} catch (Exception exception) {
log.info("--------------------查询ES错误---------------------------");
}
stationCacheInfoDto.setFanGatewayId(stationBasic.getFanGatewayId()); stationCacheInfoDto.setFanGatewayId(stationBasic.getFanGatewayId());
stationCacheInfoDto.setBoosterGatewayId(stationBasic.getBoosterGatewayId()); stationCacheInfoDto.setBoosterGatewayId(stationBasic.getBoosterGatewayId());
stationCacheInfoDtos.add(stationCacheInfoDto); stationCacheInfoDtos.add(stationCacheInfoDto);
});
redisTemplate.opsForList().leftPushAll("station_info_cache", stationCacheInfoDtos);
return stationCacheInfoDtos;
} catch (Exception e) {
throw new RuntimeException(e);
} }
redisTemplate.opsForList().leftPushAll("station_info_cache", stationCacheInfoDtos);
} }
return stationCacheInfoDtoList; return stationCacheInfoDtos;
} }
/** /**
* @param stationId 场站id * @param stationId 场站id
* @return 缓存的场站对象 * @return 缓存的场站对象
...@@ -494,7 +496,6 @@ public class CommonServiceImpl { ...@@ -494,7 +496,6 @@ public class CommonServiceImpl {
} }
/** /**
* 根据查询条件获取列表信息 * 根据查询条件获取列表信息
* *
...@@ -539,7 +540,6 @@ public class CommonServiceImpl { ...@@ -539,7 +540,6 @@ public class CommonServiceImpl {
} }
public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Map<String, String> notMustQuerCondtion, Class<T> tClass) { public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Map<String, String> notMustQuerCondtion, Class<T> tClass) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(mustQuerCondtion)) { if (!ObjectUtils.isEmpty(mustQuerCondtion)) {
...@@ -571,19 +571,20 @@ public class CommonServiceImpl { ...@@ -571,19 +571,20 @@ public class CommonServiceImpl {
} }
return null; return null;
} }
public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) { public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00; Double result = 0.00;
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF()!= null).mapToDouble(ESEquipments::getValueF).average().getAsDouble(); result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).average().getAsDouble();
return result; return result;
} }
public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) { public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00; Double result = 0.00;
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF()!= null).mapToDouble(ESEquipments::getValueF).sum(); result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).sum();
return result; return result;
} }
public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Class<T> tClass,Map<String, String> likeQuerCondtion) { public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Class<T> tClass, Map<String, String> likeQuerCondtion) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(mustQuerCondtion)) { if (!ObjectUtils.isEmpty(mustQuerCondtion)) {
for (String key : mustQuerCondtion.keySet()) { for (String key : mustQuerCondtion.keySet()) {
...@@ -599,7 +600,7 @@ public class CommonServiceImpl { ...@@ -599,7 +600,7 @@ public class CommonServiceImpl {
if (!ObjectUtils.isEmpty(likeQuerCondtion)) { if (!ObjectUtils.isEmpty(likeQuerCondtion)) {
for (String key : likeQuerCondtion.keySet()) { for (String key : likeQuerCondtion.keySet()) {
queryBuilder.must(QueryBuilders.wildcardQuery(key, "*"+likeQuerCondtion.get(key)+"*")); queryBuilder.must(QueryBuilders.wildcardQuery(key, "*" + likeQuerCondtion.get(key) + "*"));
} }
} }
Query query = new NativeSearchQueryBuilder() Query query = new NativeSearchQueryBuilder()
......
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