| | |
| | | package com.moral.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.moral.entity.*; |
| | | import com.moral.entity.DictionaryData; |
| | | import com.moral.entity.OrganizationLayout; |
| | | import com.moral.entity.OrganizationSensorUnit; |
| | | import com.moral.entity.Sensor; |
| | | import com.moral.entity.SensorUnit; |
| | | import com.moral.entity.layout.RealTimeDeviceLayout; |
| | | import com.moral.entity.layout.RtdLayoutUpload; |
| | | import com.moral.entity.layout.SensorComb; |
| | |
| | | import com.moral.mapper.OrganizationSensorUnitMapper; |
| | | import com.moral.mapper.SensorMapper; |
| | | import com.moral.service.OrganizationLayoutService; |
| | | |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.springframework.stereotype.Service; |
| | | 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.stream.Collectors; |
| | | |
| | | @Service |
| | | public class OrganizationLayoutServiceImpl implements OrganizationLayoutService{ |
| | |
| | | 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) { |
| | |
| | | List<OrganizationLayout> defaultMonitorItems = orgLayoutMapper.selectByExample(example); |
| | | List<SensorComb> defaultSensorCombList = defaultMonitorItems.stream().map( |
| | | item-> { |
| | | SensorComb sensorComb = new SensorComb(); |
| | | sensorComb.setSensorKey(item.getPagePositionValue()); |
| | | sensorComb.setIndex(item.getPagePositionIndex()); |
| | | SensorComb sensorComb = SensorComb.generate(item); |
| | | return sensorComb; |
| | | } |
| | | ).collect(Collectors.toList()); |
| | |
| | | List<OrganizationLayout> coreMonitorItems = orgLayoutMapper.selectByExample(example); |
| | | List<SensorComb> coreSensorCombList = coreMonitorItems.stream().map( |
| | | item-> { |
| | | SensorComb sensorComb = new SensorComb(); |
| | | sensorComb.setSensorKey(item.getPagePositionValue()); |
| | | sensorComb.setIndex(item.getPagePositionIndex()); |
| | | SensorComb sensorComb = SensorComb.generate(item); |
| | | return sensorComb; |
| | | } |
| | | ).collect(Collectors.toList()); |
| | |
| | | List<OrganizationLayout> fixedMonitorItems = orgLayoutMapper.selectByExample(example); |
| | | List<SensorComb> fixedSensorCombList = fixedMonitorItems.stream().map( |
| | | item-> { |
| | | SensorComb sensorComb = new SensorComb(); |
| | | sensorComb.setSensorKey(item.getPagePositionValue()); |
| | | sensorComb.setIndex(item.getPagePositionIndex()); |
| | | SensorComb sensorComb = SensorComb.generate(item); |
| | | return sensorComb; |
| | | } |
| | | ).collect(Collectors.toList()); |
| | |
| | | for (Sensor sensor :sensorList) { |
| | | if(sensor.getSensorKey()!=null |
| | | &&sensor.getSensorKey().equals(sensorComb.getSensorKey())){ |
| | | sensorComb.setName(sensor.getDescription()); |
| | | sensorComb.setSensorId(sensor.getId()); |
| | | sensorComb.setSourceUnit(sensor.getUnit()); |
| | | sensorComb.setTargetUnit(sensor.getUnit()); |
| | | sensorComb.setSensor(sensor); |
| | | // sensorComb.setName(sensor.getDescription()); |
| | | // sensorComb.setSensorId(sensor.getId()); |
| | | // sensorComb.setSourceUnit(sensor.getUnit()); |
| | | // sensorComb.setTargetUnit(sensor.getUnit()); |
| | | } |
| | | } |
| | | } |
| | |
| | | public RealTimeDeviceLayout queryRtdLayoutWithUnit(Integer orgId, Integer versionNo) { |
| | | String pageType = getPageType(versionNo); |
| | | if(queryPageConfigCountByOrgId(orgId,pageType) == 0 ){ |
| | | orgId = dataMapper.selectSupperOrgId(); |
| | | // orgId = dataMapper.selectSupperOrgId(); |
| | | orgId = 0; |
| | | } |
| | | RealTimeDeviceLayout rtdLayout = queryRealTimeDeviceLayout(orgId,versionNo); |
| | | 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) { |
| | | RealTimeDeviceLayout rtdLayout = null; |
| | | if(versionNos.size() == 1) { |
| | | Integer versionNo = versionNos.get(0); |
| | | rtdLayout = queryRtdLayoutWithUnit(orgId,versionNo); |
| | | } else { |
| | | 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 ) { |
| | | rtdLayout = queryRtdLayoutWithUnit(orgId,resultVersion); |
| | | if (rtdLayout !=null) { |
| | | List<Sensor> sensorList = sensorMapper.selectByVersionNos(versionNos); |
| | | List<SensorComb> allMonitorItems = new ArrayList<>(); |
| | | allMonitorItems.addAll(rtdLayout.getDefaultMonitorItems()); |
| | | allMonitorItems.addAll(rtdLayout.getCoreMonitorItems()); |
| | | if(allMonitorItems.size()>0 && sensorList!=null) { |
| | | List<SensorComb> sensrCombPatchs = new ArrayList<>(); |
| | | List<String> fixedItems = getFixedItemKeys(); |
| | | sensorList |
| | | // 排除固定项 |
| | | .stream().filter( |
| | | item -> { |
| | | return !fixedItems.stream().anyMatch( |
| | | key-> key.equals(item.getSensorKey()) |
| | | ); |
| | | } |
| | | ).collect(Collectors.toList()).forEach(sensor -> { |
| | | boolean isPath = !allMonitorItems.stream().anyMatch( |
| | | sensorComb -> sensorComb.getSensorId() ==sensor.getId() |
| | | ); |
| | | if(isPath) { |
| | | SensorComb sensorComb = SensorComb.generate(sensor); |
| | | sensrCombPatchs.add(sensorComb); |
| | | } |
| | | }); |
| | | if( sensrCombPatchs.size() > 0 ) { |
| | | RealTimeDeviceLayout rtdLayoutTemp = new RealTimeDeviceLayout(); |
| | | rtdLayoutTemp.setDefaultMonitorItems(sensrCombPatchs); |
| | | loadUnitToComb(orgId,rtdLayoutTemp); |
| | | rtdLayout.getDefaultMonitorItems() |
| | | .addAll(rtdLayoutTemp.getDefaultMonitorItems()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return rtdLayout; |
| | | } |
| | | |
| | | // 装载单位信息到布局配置 |
| | | private void loadUnitToComb(Integer orgId,RealTimeDeviceLayout rtdLayout) { |
| | | List<SensorComb> allList = new ArrayList<>(); |
| | |
| | | SensorUnit sensorUnit = orgUnit.getSensorUnit(); |
| | | if( sensorUnit!=null && sensorUnit.getSensorId() !=null) { |
| | | if(sensorUnit.getSensorId() == item.getSensorId()) { |
| | | item.setTargetUnit(sensorUnit.getName()); |
| | | item.setEvaluator(sensorUnit.getRules()); |
| | | item.setUnit(sensorUnit); |
| | | // item.setTargetUnit(sensorUnit.getName()); |
| | | // item.setEvaluator(sensorUnit.getRules()); |
| | | } |
| | | } |
| | | } |