kaiyu
2020-12-02 dcf1385a88fdf517e2cc60b50ea2e0a30e5652ca
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -42,6 +42,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
@@ -275,6 +276,11 @@
    }
    @Override
    public List<MonitorPoint> getMonitorPointsByOrganizationIds(Set<Integer> orgIds) {
        return monitorPointMapper.getMonitorPointsByOrganizationIds(orgIds);
    }
    @Override
    public List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters) {
        Example example = new Example(MonitorPoint.class);
        Criteria criteria = example.createCriteria();
@@ -294,49 +300,53 @@
        return this.monitorPointMapper.selectByPrimaryKey(mpointId);
    }
    /**
    * @Description: 如果站点中没有设备则不会返回站点
            * @Param: [parameters]
            * @return: java.util.List<com.moral.entity.MonitorPoint>
            * @Author: 下雨听风
            * @Date: 2020/12/2
            */
    @Override
    public List<MonitorPoint> getMonitorPointsAndDevicesByRegion(Map<String, Object> parameters) {
        //校验参数
        Object organizationId = parameters.remove("organizationId");
        //判断参数是否为null,如果为null则抛出自定义异常,msgKey为异常信息
        ValidateUtil.notNull(organizationId, "param.is.null");
        ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
        //组装查询条件
        ParameterUtils.getRegionType4RegionCode(parameters);
        //查询对应code的站点数据
        Example example = new Example(MonitorPoint.class);
        Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        //判断是否为本公司开发人员,如果不是则添加orgid限制用户查看权限
        if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) {
            //criteria.andEqualTo("organizationId", organizationId);
            Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString()));
            criteria.andIn("organizationId", organizationIds);
        }
        criteria.andEqualTo(parameters.get("regionType") + "Code", parameters.remove("regionCode"));
        //查询监控点数据
        List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
        //查询监控点下所有的设备
        Iterator<MonitorPoint> iterator = monitorPoints.iterator();
      /*while (iterator.hasNext()) {
         MonitorPoint monitorPoint = iterator.next();
         List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId());
         if (ObjectUtils.isEmpty(devices)) {
            iterator.remove();
         } else {
            monitorPoint.setDevices(devices);
         }
      }*/
        Example deviceExample = new Example(Device.class);//实例化
        //查询所有设备信息
        Example deviceExample = new Example(Device.class);
        Criteria deviceCriteria = deviceExample.createCriteria();
        deviceCriteria.orEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        List<Device> devicesInfo = deviceMapper.selectByExample(deviceExample);
        Example monitorExample = new Example(MonitorPoint.class);//实例化
        //获取所有站点信息
        Example monitorExample = new Example(MonitorPoint.class);
        Criteria monitorCriteria = monitorExample.createCriteria();
        monitorCriteria.orEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        List<MonitorPoint> monitorPointInfo = monitorPointMapper.selectByExample(monitorExample);
        //获取所有设备附加属性
        List<DeviceProperty> devicePropertyList = devicePropertyMapper.selectAll();
        //附加属性全部添加到设备实体中
        for (Device d : devicesInfo) {
            for (DeviceProperty dp : devicePropertyList) {
                if (dp.getId().equals(d.getId())) {
@@ -344,6 +354,8 @@
                }
            }
        }
        //把对应的设备信息添加到站点中
        Map<Integer, List<Device>> monitorDeviceMap = new HashMap();
        for (MonitorPoint m : monitorPointInfo) {
            List<Device> monitorDevices = new ArrayList<>();
@@ -354,6 +366,9 @@
            }
            monitorDeviceMap.put(m.getId(), monitorDevices);
        }
        //对应地区Code的迭代器,向站点中添加设备信息
        Iterator<MonitorPoint> iterator = monitorPoints.iterator();
        while (iterator.hasNext()) {
            MonitorPoint monitorPoint = iterator.next();
            for (Map.Entry<Integer, List<Device>> entry : monitorDeviceMap.entrySet()) {
@@ -368,6 +383,89 @@
        }
        return monitorPoints;
    }
    /**
    * @Description: 如果站点中没有设备也会返回站点
            * @Param: [parameters]
            * @return: java.util.List<com.moral.entity.MonitorPoint>
            * @Author: 下雨听风
            * @Date: 2020/12/2
            */
    @Override
    public List<MonitorPoint> getMonitorPointsAndDevicesByRegionNew(Map<String, Object> parameters) {
        //校验参数
        Object organizationId = parameters.remove("organizationId");
        //判断参数是否为null,如果为null则抛出自定义异常,msgKey为异常信息
        ValidateUtil.notNull(organizationId, "param.is.null");
        ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
        //组装查询条件
        ParameterUtils.getRegionType4RegionCode(parameters);
        //查询对应code的站点数据
        Example example = new Example(MonitorPoint.class);
        Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        //判断是否为本公司开发人员,如果不是则添加orgid限制用户查看权限
        if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) {
            Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString()));
            criteria.andIn("organizationId", organizationIds);
        }
        criteria.andEqualTo(parameters.get("regionType") + "Code", parameters.remove("regionCode"));
        List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
        //查询所有设备信息
        Example deviceExample = new Example(Device.class);
        Criteria deviceCriteria = deviceExample.createCriteria();
        deviceCriteria.orEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        List<Device> devicesInfo = deviceMapper.selectByExample(deviceExample);
        //获取所有站点信息
        Example monitorExample = new Example(MonitorPoint.class);
        Criteria monitorCriteria = monitorExample.createCriteria();
        monitorCriteria.orEqualTo("isDelete", Constants.IS_DELETE_FALSE);
        List<MonitorPoint> monitorPointInfo = monitorPointMapper.selectByExample(monitorExample);
        //获取所有设备附加属性
        List<DeviceProperty> devicePropertyList = devicePropertyMapper.selectAll();
        //附加属性全部添加到设备实体中
        for (Device d : devicesInfo) {
            for (DeviceProperty dp : devicePropertyList) {
                if (dp.getId().equals(d.getId())) {
                    d.setDeviceProperty(dp);
                }
            }
        }
        //把对应的设备信息添加到站点中
        Map<Integer, List<Device>> monitorDeviceMap = new HashMap();
        for (MonitorPoint m : monitorPointInfo) {
            List<Device> monitorDevices = new ArrayList<>();
            for (Device d : devicesInfo) {
                if (m.getId().equals(d.getMonitorPointId())) {
                    monitorDevices.add(d);
                }
            }
            monitorDeviceMap.put(m.getId(), monitorDevices);
        }
        //对应地区Code的迭代器,向站点中添加设备信息
        Iterator<MonitorPoint> iterator = monitorPoints.iterator();
        while (iterator.hasNext()) {
            MonitorPoint monitorPoint = iterator.next();
            for (Map.Entry<Integer, List<Device>> entry : monitorDeviceMap.entrySet()) {
                if (monitorPoint.getId().equals(entry.getKey())) {
                    if (!CollectionUtils.isEmpty(entry.getValue())) {
                        monitorPoint.setDevices(entry.getValue());
                    }
                }
            }
        }
        return monitorPoints;
    }
    @SuppressWarnings("unchecked")
    @Override
@@ -796,5 +894,36 @@
        return params;
    }
    @Override
    public JSONObject getMacList(int monitPointId) {
        JSONObject params = new JSONObject();
        MonitorPoint monitorPoint = monitorPointMapper.getMonitorPointById(monitPointId);
        //获取厂界所有设备
        List<Device> deviceList = deviceService.getDeviceById2(monitPointId);
        params.put("longitudeCompany", monitorPoint.getLongitude());
        params.put("latitudeCompany", monitorPoint.getLatitude());
        params.put("latitudeCompany", monitorPoint.getLatitude());
        params.put("monitPointId", monitPointId);
        params.put("deviceList", deviceList);
        return params;
    }
    @Override
    public List<MonitorPoint> getMonitorPointListByAccountId(int id) {
        return monitorPointMapper.getMonitorPointListByAccountId(id);
    }
    @Override
    public MonitorPoint byIdGetMonitorPoint(int id) {
        return monitorPointMapper.byIdGetMonitorPoint(id);
    }
    @Override
    public String getOrgIdByMac(String mac) {
        return monitorPointMapper.getOrgIdByMac(mac);
    }
}