From d32fa50fca18a3fff89b9ec22deaa3d964ddd19b Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Wed, 27 Jun 2018 12:34:27 +0800 Subject: [PATCH] 大屏布局监控点 返回配置数据 --- src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java | 104 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java b/src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java index 304ff2c..067caf3 100644 --- a/src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java +++ b/src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java @@ -16,9 +16,9 @@ import tk.mybatis.mapper.entity.Example; import javax.annotation.Resource; -import javax.naming.Name; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -29,30 +29,34 @@ OrganizationLayoutMapper orgLayoutMapper; @Resource OrganizationSensorUnitMapper orgUnitMapper; - private static String pageLayoutFixedItems = "page_layout_fixed_items"; + private static String page_layout_fixed_items = "page_layout_fixed_items"; + private static String page_layout_versions_sort = "page_layout_versions_sort"; @Resource DictionaryDataMapper dataMapper; - private DictionaryData queryDictionaryData(String dictDataKey) { + private Optional<String> queryDictionaryDataValue(String dictDataKey) { DictionaryData query = new DictionaryData(); query.setDictDataKey(dictDataKey); List<DictionaryData> dataList = dataMapper.select(query); List<String> fixedItemKeys = new ArrayList<>(); + String json = null; if(dataList.size()>0) { - return dataList.get(0); + DictionaryData data = dataList.get(0); + json = data.getDictDataValue() != null ? data.getDictDataValue().toString() : null; } - return null; + return Optional.of(json); } @Override public List<String> getFixedItemKeys() { - DictionaryData dictionaryData = queryDictionaryData(pageLayoutFixedItems); + Optional jsonString = queryDictionaryDataValue(page_layout_fixed_items); List<String> fixedItemKeys = new ArrayList<>(); - if(dictionaryData!=null && dictionaryData.getDictDataValue()!=null ) { - List<String> keyList = JSON.parseObject(dictionaryData.getDictDataValue().toString(), - new TypeReference<List<String>>(){}); - if(keyList!=null) { - fixedItemKeys.addAll(keyList); - } + if(jsonString.isPresent()) { + List<String> keyList = JSON.parseObject(jsonString.get().toString(), + new TypeReference<List<String>>(){}); + if(keyList!=null) { + fixedItemKeys.addAll(keyList); } + } + return fixedItemKeys; } public Integer queryPageConfigCountByOrgId(Integer orgId,String pageType) { @@ -222,6 +226,82 @@ loadUnitToComb(orgId,rtdLayout); return rtdLayout; } + private List<Integer> getVersionNosSort() { + List<Integer> versionNoList = new ArrayList<>(); + Optional<String> jsonString = queryDictionaryDataValue(page_layout_versions_sort); + if( jsonString.isPresent() ) { + versionNoList = JSON.parseArray(jsonString.get(),Integer.class); + } + return versionNoList; + } + @Override + public RealTimeDeviceLayout queryRtdLayoutWithUnit(Integer orgId, List<Integer> versionNos) { + + List<Integer> versionNosSort = getVersionNosSort(); + Integer resultVersion = null; + for( int num =0 ; num < versionNosSort.size(); num++ ) { + Integer version =versionNosSort.get(num); + for (Integer ver:versionNos) { + if(ver == version) { + resultVersion = ver; + versionNos.remove(ver); + break; + } + } + if(resultVersion!=null) { + break; + } + } + if(resultVersion != null ) { + String pageType = getPageType(resultVersion); + if(queryPageConfigCountByOrgId(orgId,pageType) == 0 ){ + orgId = dataMapper.selectSupperOrgId(); + } + RealTimeDeviceLayout rtdLayout = queryRealTimeDeviceLayout(orgId,resultVersion); + if (rtdLayout !=null) { + List<Sensor> sensorList = sensorMapper.selectByVersionNos(versionNos); + List<SensorComb> sensorCombList = sensorList.stream().map( + item -> { + SensorComb sensorComb = new SensorComb(); + sensorComb.setSensorId(item.getId()); + sensorComb.setSensorKey(item.getSensorKey()); + sensorComb.setName(item.getDescription()); + sensorComb.setSourceUnit(item.getUnit()); + sensorComb.setTargetUnit(item.getUnit()); + return sensorComb; + } + ).collect(Collectors.toList()); + List<SensorComb> allMonitorItems = new ArrayList<>(); + allMonitorItems.addAll(rtdLayout.getDefaultMonitorItems()); + allMonitorItems.addAll(rtdLayout.getCoreMonitorItems()); + if(allMonitorItems.size()>0 && sensorCombList!=null) { + List<SensorComb> sensrCombPatchs = new ArrayList<>(); + sensorCombList + // ��������������� + .stream().filter( + item -> { + List<String> fixedItems = getFixedItemKeys(); + return !fixedItems.stream().anyMatch( + key-> key.equals(item.getSensorKey()) + ); + } + ).collect(Collectors.toList()).forEach(item -> { + boolean isPath = !allMonitorItems.stream().anyMatch( + sensorComb -> sensorComb.getSensorId() == item.getSensorId() + ); + if(isPath) { + sensrCombPatchs.add(item); + } + }); + rtdLayout.getDefaultMonitorItems().addAll(sensrCombPatchs); + loadUnitToComb(orgId,rtdLayout); + return rtdLayout; + } + } + } + return null; + } + // ��������������������������������� private void loadUnitToComb(Integer orgId,RealTimeDeviceLayout rtdLayout) { List<SensorComb> allList = new ArrayList<>(); -- Gitblit v1.8.0