fengxiang
2018-06-27 d32fa50fca18a3fff89b9ec22deaa3d964ddd19b
大屏布局监控点 返回配置数据
5 files modified
149 ■■■■■ changed files
src/main/java/com/moral/controller/ScreenController.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/SensorMapper.java 5 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/OrganizationLayoutService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java 104 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/SensorMapper.xml 24 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java
@@ -108,6 +108,8 @@
    private AlarmDailyService alarmDailyService;
    @Resource
    private OrganizationLayoutService orgLayoutService;
    @Resource
    private  DeviceVersionService dviceVersionService;
    /**
     * Screen login. 大屏登录
     * 
@@ -594,6 +596,18 @@
                return  ResultBean.fail();
            }
        } else {
            MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(Integer.parseInt(primaryKey));
            List<DeviceVersion> versionList = deviceVersionService.queryByOrgId(monitorPoint.getOrganizationId());
            if(versionList.size() > 0) {
            List<Integer> versionNolist =    versionList.stream().map(item -> {
                    return  item.getVersion();
                }).collect(Collectors.toList());
                rtdLayout = orgLayoutService.queryRtdLayoutWithUnit(monitorPoint.getOrganizationId(),versionNolist);
                if(rtdLayout == null) {
                    return ResultBean.fail();
                }
            }
        }
        return new ResultBean(rtdLayout);
    }
src/main/java/com/moral/mapper/SensorMapper.java
@@ -2,6 +2,7 @@
import com.moral.common.mapper.BaseMapper;
import com.moral.entity.Sensor;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@@ -9,7 +10,9 @@
public interface SensorMapper extends BaseMapper<Sensor> {
    List<Sensor> selectByVersionId(Integer deviceVersionId);
    List<Sensor> selectByVersionNo(Integer deviceVersionId);
    List<Sensor> selectByVersionNo(Integer deviceVersionNo);
    List<Sensor> selectByVersionNos(@Param("versionNos") List<Integer> versionNos);
    List<Sensor> selectByOrgId(Integer organizationId);
src/main/java/com/moral/service/OrganizationLayoutService.java
@@ -17,4 +17,6 @@
    void  deleteRtdLayout(Integer orgId, Integer version);
    RealTimeDeviceLayout queryRtdLayoutWithUnit(Integer orgId, Integer versionNo);
    RealTimeDeviceLayout queryRtdLayoutWithUnit(Integer orgId, List<Integer> versionNos);
}
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<>();
src/main/resources/mapper/SensorMapper.xml
@@ -34,7 +34,29 @@
       and dvs.device_version_id in
          (
              select dev.id from device_version dev
                where dev.version = #{versionNo,jdbcType=INTEGER}
                where dev.version = #{deviceVersionNo,jdbcType=INTEGER}
          )
    )
  </select>
  <select id="selectByVersionNos" resultMap="BaseResultMap" parameterType="java.util.List" >
    select
    <include refid="Base_Column_List" />
    from sensor sen
    where EXISTS
    (  select id
       from device_version_sensor dvs
       where sen.id = dvs.sensor_id
       and dvs.device_version_id in
          (
              select dev.id from device_version dev
                 <where>
                   <if test="versionNos!=null and versionNos.size() > 0">
                    dev.version in
                      <foreach collection="versionNos" item="versionNo" open="(" close=")" separator=",">
                             #{versionNo,jdbcType=INTEGER}
                      </foreach>
                   </if>
              </where>
          )
    )
  </select>