| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.OrganizationUnitAlarm; |
| | | import com.moral.api.entity.Sensor; |
| | | import com.moral.api.entity.Version; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.OrganizationUnitAlarmMapper; |
| | | import com.moral.api.mapper.UnitConversionMapper; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.SensorService; |
| | | import com.moral.api.service.UnitConversionService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import org.apache.kafka.streams.state.internals.metrics.Sensors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | OrganizationUnitAlarmMapper organizationUnitAlarmMapper; |
| | | |
| | | @Autowired |
| | | SensorService sensorService; |
| | | |
| | | @Autowired |
| | | UnitConversionService unitConversionService; |
| | | |
| | | @Override |
| | | public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { |
| | | QueryWrapper<Device> wrapper = new QueryWrapper(); |
| | |
| | | |
| | | @Override |
| | | public Map<String, Object> getSensorsByMac(Map<String, Object> params) { |
| | | List<String> sensorCodes = Arrays.asList(Constants.SENSOR_CODE_PM25 |
| | | , Constants.SENSOR_CODE_PM10 |
| | | , Constants.SENSOR_CODE_SO2 |
| | | , Constants.SENSOR_CODE_NO2 |
| | | , Constants.SENSOR_CODE_CO |
| | | , Constants.SENSOR_CODE_O3 |
| | | , Constants.SENSOR_CODE_TEMP |
| | | , "a01002" |
| | | , Constants.SENSOR_CODE_WIND_SPEED |
| | | , Constants.SENSOR_CODE_WIND_DIR |
| | | , "a01006" |
| | | , "a00e12" |
| | | ); |
| | | |
| | | //设备mac |
| | | List<String> macs = (List<String>) params.remove("macs"); |
| | | List<Map<String, Object>> elementLists = new ArrayList<>(); |
| | |
| | | elementLists.add(map); |
| | | } |
| | | |
| | | Map<String, Object> map = elementLists.parallelStream() |
| | | Map<String, Object> map = elementLists.stream() |
| | | .filter(elementList -> elementList.size() != 0) |
| | | .reduce((a, b) -> { |
| | | a.keySet().retainAll(b.keySet()); |
| | | return a; |
| | | }).orElse(new HashMap<>()); |
| | | return map; |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | sensorCodes.forEach(sensorCode -> { |
| | | Object o = map.remove(sensorCode); |
| | | if (o != null) { |
| | | result.put(sensorCode, o); |
| | | } |
| | | }); |
| | | result.putAll(map); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List getMacsByOrgIdAndRegionCode(Integer organizationId,Integer regionCode) { |
| | | public List getMacsByOrgIdAndRegionCode(Integer organizationId, Integer regionCode) { |
| | | QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("mac") |
| | | .eq("organization_id", organizationId) |
| | |
| | | return deviceMapper.selectObjs(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Device getDeviceUnitAlramInforByMac(String mac) { |
| | | Device device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO,mac); |
| | | if(device==null) |
| | | return getDeviceUnitAlramInforByMacFromDb(mac); |
| | | return device; |
| | | } |
| | | |
| | | private Device getDeviceUnitAlramInforByMacFromDb(String mac){ |
| | | QueryWrapper<Device> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("mac",mac); |
| | | wrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | Device device = deviceMapper.selectOne(wrapper); |
| | | if(device==null) |
| | | return null; |
| | | QueryWrapper<OrganizationUnitAlarm> unitAlarmQueryWrapper = new QueryWrapper<>(); |
| | | unitAlarmQueryWrapper.eq("organization_id",device.getOrganizationId()); |
| | | unitAlarmQueryWrapper.eq("version_id",device.getDeviceVersionId()); |
| | | unitAlarmQueryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<OrganizationUnitAlarm> organizationUnitAlarms = organizationUnitAlarmMapper.selectList(unitAlarmQueryWrapper); |
| | | Version version = new Version(); |
| | | version.setId(device.getDeviceVersionId()); |
| | | List<Sensor> sensors = new ArrayList<>(); |
| | | for (OrganizationUnitAlarm organizationUnitAlarm : organizationUnitAlarms) { |
| | | Sensor sensor = sensorService.getSensorByCode(organizationUnitAlarm.getSensorCode()); |
| | | sensor.setUnit(organizationUnitAlarm.getUnitKey()); |
| | | sensor.setShowUnit(organizationUnitAlarm.getShowUnitKey()); |
| | | sensor.setShowUnitKey(organizationUnitAlarm.getShowUnitKey()); |
| | | sensor.setUnitKey(organizationUnitAlarm.getUnitKey()); |
| | | sensor.setAlarmLevel(organizationUnitAlarm.getAlarmLevel()); |
| | | String formula = unitConversionService.getFormula(Integer.valueOf(organizationUnitAlarm.getUnitKey()), Integer.valueOf(organizationUnitAlarm.getShowUnitKey()),sensor.getCode()); |
| | | sensor.setFormula(formula); |
| | | sensors.add(sensor); |
| | | } |
| | | version.setSensors(sensors); |
| | | device.setVersion(version); |
| | | redisTemplate.opsForHash().put(RedisConstants.DEVICE_INFO,mac,device); |
| | | return device; |
| | | } |
| | | |
| | | private Device getDeviceByMacFromDB(String mac) { |
| | | QueryWrapper<Device> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("mac", mac); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } |