From 15c4ec98dace455967335a27d0f0efdcdfc61f29 Mon Sep 17 00:00:00 2001 From: lizijie <lzjiiie@163.com> Date: Sat, 22 Jun 2019 17:18:48 +0800 Subject: [PATCH] 生成预测数据 --- src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 110 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java index e79b10e..1be75e8 100644 --- a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java +++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java @@ -2,9 +2,12 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Resource; @@ -14,11 +17,13 @@ import com.moral.mapper.OrganizationMapper; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; import com.github.pagehelper.PageHelper; import com.moral.common.bean.Constants; import com.moral.common.bean.PageBean; import com.moral.common.util.ExampleUtil; +import com.moral.common.util.ParameterUtils; import com.moral.common.util.RedisUtils; import com.moral.common.util.StringUtils; import com.moral.common.util.ValidateUtil; @@ -26,7 +31,9 @@ import com.moral.entity.MonitorPoint; import com.moral.mapper.DeviceMapper; import com.moral.mapper.MonitorPointMapper; +import com.moral.service.DeviceService; import com.moral.service.MonitorPointService; +import com.moral.service.OrganizationService; import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example.Criteria; @@ -44,6 +51,12 @@ @Resource DictionaryDataMapper dictionaryDataMapper; + @Resource + private DeviceService deviceService; + + @Resource + private OrganizationService organizationService; + private static Class ENTITY_CLASS = MonitorPoint.class; @Override public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) { @@ -60,10 +73,10 @@ List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); params.put("orgIds",orgIds); monitorPointList = monitorPointMapper.selectByMap(params); - for(MonitorPoint monitorPoint:monitorPointList){ - Integer state = getStateFromRedis(monitorPoint.getId()); - monitorPoint.setState(state); - } +// for(MonitorPoint monitorPoint:monitorPointList){ +// Integer state = getStateFromRedis(monitorPoint.getId()); +// monitorPoint.setState(state); +// } } return monitorPointList == null ? new ArrayList<>() : monitorPointList; } @@ -231,7 +244,10 @@ criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE); if (Constants.isNotSpecialOrgId(orgId)) { - criteria.andEqualTo("organizationId", orgId); + //criteria.andEqualTo("organizationId", orgId); + Set<Integer> organizationIds = organizationService.getChildOrganizationIds(orgId); + criteria.andIn("organizationId", organizationIds); + } example.orderBy("name").asc(); return monitorPointMapper.selectByExample(example); @@ -253,4 +269,93 @@ public MonitorPoint queryMonitorPointById(Integer mpointId) { return this.monitorPointMapper.selectByPrimaryKey(mpointId); } + + @Override + public List<MonitorPoint> getMonitorPointsAndDevicesByRegion(Map<String, Object> parameters) { + //������������ + Object organizationId = parameters.remove("organizationId"); + ValidateUtil.notNull(organizationId, "param.is.null"); + ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null"); + + //������������������ + ParameterUtils.getRegionType4RegionCode(parameters); + + Example example = new Example(MonitorPoint.class); + Criteria criteria = example.createCriteria(); + criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE); + 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); + } + + } + return monitorPoints; + } + + @SuppressWarnings("unchecked") + @Override + public Collection<Object> getDevicesStateByRegion(Map<String, Object> parameters) { + //������������ + Object organizationId = parameters.remove("organizationId"); + ValidateUtil.notNull(organizationId, "param.is.null"); + ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null"); + + //������������������ + ParameterUtils.getRegionType4RegionCode(parameters); + + if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) { + Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString())); + parameters.put("orgIds", organizationIds); + } + List<Map<String, Object>> monitorPoints = deviceMapper.getDevicesStateByRegion(parameters); + Map<String, Object> result = new HashMap<String, Object>(); + Map<String,Object> device; + List<Map<String, Object>> devices; + for (Map<String, Object> map : monitorPoints) { + String id = map.get("id").toString(); + + device = new HashMap<String,Object>(); + device.put("id", map.remove("deviceId")); + device.put("name", map.remove("deviceName")); + device.put("state", map.remove("state")); + device.put("mac", map.remove("mac")); + + if (result.containsKey(id)) { + Map<String, Object> monitorPoint = (Map<String, Object>) result.get(id); + devices = (List<Map<String, Object>>) monitorPoint.get("devices"); + } else { + devices = new ArrayList<Map<String, Object>>(); + result.put(id, map); + } + devices.add(device); + map.put("devices", devices); + result.put(id, map); + } + + return result.values(); + } + + @Override + public void isCompensateCalculation(Map<String, Object> parameters) { + MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(parameters.get("monitorPointId").toString())); + if (Integer.valueOf(320581).equals(monitorPoint.getAreaCode())) { + parameters.put("compensate", true); + } + + } } -- Gitblit v1.8.0