| | |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | OrganizationUnitAlarmMapper organizationUnitAlarmMapper; |
| | | |
| | | @Autowired |
| | | SensorService sensorService; |
| | | |
| | | @Autowired |
| | | UnitConversionService unitConversionService; |
| | | |
| | | @Override |
| | | public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } |