|  |  | 
 |  |  | package com.moral.api.service.impl; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.alibaba.fastjson.JSONObject; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.googlecode.aviator.AviatorEvaluator; | 
 |  |  | import com.googlecode.aviator.Expression; | 
 |  |  | import com.moral.api.entity.*; | 
 |  |  | import com.moral.api.mapper.*; | 
 |  |  | import com.moral.api.pojo.vo.device.DeviceVO; | 
 |  |  | import com.moral.api.service.DeviceService; | 
 |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
 |  |  |  | 
 |  |  | import com.moral.api.util.CacheUtils; | 
 |  |  | import com.moral.api.util.AdjustDataUtils; | 
 |  |  | import com.moral.api.util.LogUtils; | 
 |  |  | import com.moral.constant.Constants; | 
 |  |  | import com.moral.constant.RedisConstants; | 
 |  |  | import com.moral.util.ConvertUtils; | 
 |  |  | import com.moral.util.DateUtils; | 
 |  |  |  | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.ObjectUtils; | 
 |  |  | import org.springframework.util.StringUtils; | 
 |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
 |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
 |  |  |  | 
 |  |  | 
 |  |  |  * @since 2021-05-11 | 
 |  |  |  */ | 
 |  |  | @Service | 
 |  |  | @Slf4j | 
 |  |  | public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private VersionSensorUnitMapper versionSensorUnitMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SpecialDeviceMapper specialDeviceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private AdjustDataUtils adjustDataUtils; | 
 |  |  |  | 
 |  |  |     /* | 
 |  |  |      * 从redis获取设备信息 | 
 |  |  |      * */ | 
 |  |  |     private Map<String, Object> getDeviceInfoFromRedis(String mac) { | 
 |  |  |         Map<String, Object> deviceInfo = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DEVICE + mac); | 
 |  |  |         return deviceInfo; | 
 |  |  |         return (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /* | 
 |  |  |      * 设备信息存入redis | 
 |  |  |      */ | 
 |  |  |     private void setDeviceInfoToRedis(String mac, Map<String, Object> deviceInfo) { | 
 |  |  |         redisTemplate.opsForValue().set(getDeviceKey(mac), deviceInfo); | 
 |  |  |         redisTemplate.opsForHash().put(RedisConstants.DEVICE, mac, deviceInfo); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /* | 
 |  |  |      * 从redis删除设备信息 | 
 |  |  |      */ | 
 |  |  |     private void delDeviceInfoFromRedis(String mac) { | 
 |  |  |         redisTemplate.delete(getDeviceKey(mac)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /* | 
 |  |  |      * 获取设备信息在redis里的key | 
 |  |  |      */ | 
 |  |  |     private String getDeviceKey(String mac) { | 
 |  |  |         return keysConnect(RedisConstants.DEVICE, mac); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //redis key前缀 | 
 |  |  |     private String keysConnect(String... keys) { | 
 |  |  |         StringBuilder key = new StringBuilder(keys[0]); | 
 |  |  |         for (int i = 1; i < keys.length; i++) { | 
 |  |  |             key.append("_"); | 
 |  |  |             key.append(keys[i]); | 
 |  |  |         } | 
 |  |  |         return key.toString().toLowerCase(); | 
 |  |  |         redisTemplate.opsForHash().delete(RedisConstants.DEVICE, mac); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |         deviceMapper.insert(device); | 
 |  |  |         Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId()); | 
 |  |  |         //维护组织型号关系表 | 
 |  |  |         QueryWrapper<OrganizationUnitAlarm> queryOrganizationVersionWrapper = new QueryWrapper<>(); | 
 |  |  |         queryOrganizationVersionWrapper.eq("organization_id",orgId); | 
 |  |  |         queryOrganizationVersionWrapper.eq("version_id",device.getDeviceVersionId()); | 
 |  |  |         queryOrganizationVersionWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         List<OrganizationUnitAlarm> organizationUnitAlarms = organizationUnitAlarmMapper.selectList(queryOrganizationVersionWrapper); | 
 |  |  |         if(ObjectUtils.isEmpty(organizationUnitAlarms)){ | 
 |  |  |             QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper =new QueryWrapper<>(); | 
 |  |  |             queryVersionSensorUnitWrapper.eq("version_id",device.getDeviceVersionId()); | 
 |  |  |             queryVersionSensorUnitWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |             List<VersionSensorUnit> versionSensorUnits = versionSensorUnitMapper.selectList(queryVersionSensorUnitWrapper); | 
 |  |  |             if(!ObjectUtils.isEmpty(versionSensorUnits)){ | 
 |  |  |                 for (VersionSensorUnit versionSensorUnit : versionSensorUnits) { | 
 |  |  |                     OrganizationUnitAlarm organizationUnitAlarm = new OrganizationUnitAlarm(); | 
 |  |  |                     organizationUnitAlarm.setOrganizationId(orgId); | 
 |  |  |                     organizationUnitAlarm.setVersionId(device.getDeviceVersionId()); | 
 |  |  |                     organizationUnitAlarm.setSensorCode(versionSensorUnit.getSensorCode()); | 
 |  |  |                     organizationUnitAlarm.setUnitKey(versionSensorUnit.getUnitKey()); | 
 |  |  |                     organizationUnitAlarmMapper.insert(organizationUnitAlarm); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         insertOrganizationUnitAlarm(orgId, device.getDeviceVersionId()); | 
 |  |  |         //新增设备信息存入redis | 
 |  |  |         String mac = device.getMac(); | 
 |  |  |         //从redis中删除设备信息 | 
 |  |  |         delDeviceInfoFromRedis(mac); | 
 |  |  |         //设备信息存入redis | 
 |  |  |         setDeviceInfoToRedis(mac, deviceInfo); | 
 |  |  |         //刷新deviceInfo缓存 | 
 |  |  |         CacheUtils.refreshDeviceAlarmInfo(); | 
 |  |  |         //操作日志记录 | 
 |  |  |         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
 |  |  |         StringBuilder content = new StringBuilder(); | 
 |  |  |         content.append("添加了设备:").append(device.getName()).append(";").append("mac:").append(mac); | 
 |  |  |         content.append("添加了设备:").append(device.getName()).append(":").append("mac:").append(mac); | 
 |  |  |         logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional | 
 |  |  |     public void delete(Integer deviceId) { | 
 |  |  |         Device device = deviceMapper.selectById(deviceId); | 
 |  |  |         UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>(); | 
 |  |  |         updateWrapper.eq("id", deviceId).set("is_delete", Constants.DELETE); | 
 |  |  |         deviceMapper.update(null, updateWrapper); | 
 |  |  |         Device device = deviceMapper.selectById(deviceId); | 
 |  |  |         String mac = device.getMac(); | 
 |  |  |         //从redis中删除设备信息 | 
 |  |  |         delDeviceInfoFromRedis(mac); | 
 |  |  |         //维护组织型号关系表 | 
 |  |  |         Integer versionId = device.getDeviceVersionId(); | 
 |  |  |         Integer orgId = device.getOrganizationId(); | 
 |  |  |         deleteOrganizationUnitAlarm(orgId, versionId); | 
 |  |  |         //刷新deviceInfo缓存 | 
 |  |  |         CacheUtils.refreshDeviceAlarmInfo(); | 
 |  |  |         //操作日志记录 | 
 |  |  |         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
 |  |  |         StringBuilder content = new StringBuilder(); | 
 |  |  | 
 |  |  |     public void update(Device device) { | 
 |  |  |         Integer deviceId = device.getId(); | 
 |  |  |         Device oldDevice = deviceMapper.selectById(deviceId); | 
 |  |  |         //判断是否更新了站点,如果更新了站点则查询对应站点的组织id进行更新 | 
 |  |  |         if (!ObjectUtils.isEmpty(device.getMonitorPointId())) { | 
 |  |  |             MonitorPoint monitorPoint = monitorPointMapper.selectById(device.getMonitorPointId()); | 
 |  |  |             device.setOrganizationId(monitorPoint.getOrganizationId()); | 
 |  |  |         } | 
 |  |  |         deviceMapper.updateById(device); | 
 |  |  |         String mac = deviceMapper.selectById(deviceId).getMac(); | 
 |  |  |         Device updateDevice = deviceMapper.selectById(deviceId); | 
 |  |  |         String mac = updateDevice.getMac(); | 
 |  |  |         //维护组织型号关系表 | 
 |  |  |         Integer oldOrgId = oldDevice.getOrganizationId(); | 
 |  |  |         Integer newOrgId = updateDevice.getOrganizationId(); | 
 |  |  |         Integer oldVersionId = oldDevice.getDeviceVersionId(); | 
 |  |  |         Integer newVersionId = updateDevice.getDeviceVersionId(); | 
 |  |  |         if (!oldOrgId.equals(newOrgId) || !oldVersionId.equals(newVersionId)) { | 
 |  |  |             deleteOrganizationUnitAlarm(oldOrgId, oldVersionId); | 
 |  |  |             insertOrganizationUnitAlarm(newOrgId, newVersionId); | 
 |  |  |         } | 
 |  |  |         //从redis中删除设备信息 | 
 |  |  |         delDeviceInfoFromRedis(mac); | 
 |  |  |         delDeviceInfoFromRedis(oldDevice.getMac()); | 
 |  |  |         Map<String, Object> deviceInfo = selectDeviceInfoById(deviceId); | 
 |  |  |         //设备信息存入redis | 
 |  |  |         setDeviceInfoToRedis(mac, deviceInfo); | 
 |  |  |         //刷新deviceInfo缓存 | 
 |  |  |         CacheUtils.refreshDeviceAlarmInfo(); | 
 |  |  |         //操作日志记录 | 
 |  |  |         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
 |  |  |         StringBuilder content = new StringBuilder(); | 
 |  |  |         content.append("修改了设备:").append(mac).append(":"); | 
 |  |  |         content.append("修改了设备:" + oldDevice.getMac()).append("==>").append(mac).append(":"); | 
 |  |  |         Field[] fields = Device.class.getDeclaredFields(); | 
 |  |  |         for (Field field : fields) { | 
 |  |  |             if (field.getName().equals("id")) { | 
 |  |  | 
 |  |  |                 Object o1 = method.invoke(oldDevice); | 
 |  |  |                 Object o2 = method.invoke(device); | 
 |  |  |                 if (o2 != null) { | 
 |  |  |                     content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(";"); | 
 |  |  |                     content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(":"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } catch (Exception e) { | 
 |  |  | 
 |  |  |             queryWrapper.eq("monitor_point_id", mpId); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //设备名模糊查询 | 
 |  |  |         if (name != null) { | 
 |  |  |             queryWrapper.like("name", name); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //mac模糊查询 | 
 |  |  |         if (mac != null) { | 
 |  |  |             queryWrapper.like("mac", mac); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         //排序参数,默认create_time降序 | 
 |  |  |         if (order != null && orderType != null) { | 
 |  |  | 
 |  |  |         result.put("item", items); | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> selectDeviceInfoById(Integer deviceId) { | 
 |  |  | 
 |  |  |         MonitorPoint monitorPoint = device.getMonitorPoint(); | 
 |  |  |         mpInfo.put("id", monitorPoint.getId()); | 
 |  |  |         mpInfo.put("name", monitorPoint.getName()); | 
 |  |  |         mpInfo.put("areaCode", monitorPoint.getAreaCode()); | 
 |  |  |         mpInfo.put("cityCode", monitorPoint.getCityCode()); | 
 |  |  |         mpInfo.put("provinceCode", monitorPoint.getProvinceCode()); | 
 |  |  |         deviceInfo.put("monitorPoint", mpInfo); | 
 |  |  |  | 
 |  |  |         setDeviceInfoToRedis(mac, deviceInfo); | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> getDeviceByMac(String mac) { | 
 |  |  |         Map<String, Object> deviceInfo = getDeviceInfoFromRedis(mac); | 
 |  |  |         if (deviceInfo == null) { | 
 |  |  |         if (ObjectUtils.isEmpty(deviceInfo)) { | 
 |  |  |             QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); | 
 |  |  |             queryWrapper.eq("mac", mac).eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |             Device device = deviceMapper.selectOne(queryWrapper); | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData, Map<String, Object> deviceInfo) { | 
 |  |  |         return null; | 
 |  |  |     public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData) { | 
 |  |  |         String mac = deviceData.remove("mac").toString(); | 
 |  |  |         //从redis获取校准公式 | 
 |  |  |         Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac); | 
 |  |  |         if (!ObjectUtils.isEmpty(adjustFormula)) { | 
 |  |  |             Map<String, Object> deviceInfo = getDeviceByMac(mac); | 
 |  |  |             Map<String, Object> monitorPoint = (Map<String, Object>) deviceInfo.get("monitorPoint"); | 
 |  |  |             String areaCode = monitorPoint.get("areaCode").toString(); | 
 |  |  |             String cityCode = monitorPoint.get("cityCode").toString(); | 
 |  |  |  | 
 |  |  |             Map<String, Object> aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, areaCode); | 
 |  |  |             if (ObjectUtils.isEmpty(aqiMap)) { | 
 |  |  |                 aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, cityCode); | 
 |  |  |             } | 
 |  |  |             return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap); | 
 |  |  |         } | 
 |  |  |         deviceData.remove("DataTime"); | 
 |  |  |         return deviceData; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> judgeDeviceState(Map<String, Object> deviceData, Map<String, Object> deviceInfo) { | 
 |  |  |         return null; | 
 |  |  |     public Map<String, Object> adjustSpecialDeviceData(Map<String, Object> deviceData) { | 
 |  |  |         String mac = deviceData.remove("mac").toString(); | 
 |  |  |         //从redis获取校准公式 | 
 |  |  |         Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac); | 
 |  |  |         if (!ObjectUtils.isEmpty(adjustFormula)) { | 
 |  |  |             Organization organization = specialDeviceMapper.selectOrgByMac(mac); | 
 |  |  |             String areaCode = organization.getAreaCode().toString(); | 
 |  |  |             String cityCode = organization.getCityCode().toString(); | 
 |  |  |             Map<String, Object> aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, areaCode); | 
 |  |  |             if (ObjectUtils.isEmpty(aqiMap)) { | 
 |  |  |                 aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, cityCode); | 
 |  |  |             } | 
 |  |  |             return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap); | 
 |  |  |         } | 
 |  |  |         deviceData.remove("DataTime"); | 
 |  |  |         return deviceData; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional | 
 |  |  |     public void judgeDeviceState(Map<String, Object> deviceData) { | 
 |  |  |         String mac = deviceData.remove("mac").toString(); | 
 |  |  |         Device device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, mac); | 
 |  |  |         Version version = device.getVersion(); | 
 |  |  |         List<Sensor> sensors = version.getSensors(); | 
 |  |  |         Expression expression; | 
 |  |  |         int state = 1; | 
 |  |  |         for (Sensor sensor : sensors) { | 
 |  |  |             //因子报警等级 | 
 |  |  |             String alarmLevel = sensor.getAlarmLevel(); | 
 |  |  |             if (StringUtils.isEmpty(alarmLevel)) { | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |             List<Object> list = JSONObject.parseObject(alarmLevel, List.class); | 
 |  |  |             String sensorCode = sensor.getCode(); | 
 |  |  |             //转换公式 | 
 |  |  |             String formula = sensor.getFormula(); | 
 |  |  |             //转换单位前因子值 | 
 |  |  |             String sensorValue = (String) deviceData.get(sensorCode); | 
 |  |  |             double value = Double.parseDouble(sensorValue); | 
 |  |  |             //单位转换 | 
 |  |  |             if (formula != null) { | 
 |  |  |                 //转换后因子值 | 
 |  |  |                 sensorValue = formula.replace("{0}", sensorValue); | 
 |  |  |                 expression = AviatorEvaluator.compile(sensorValue); | 
 |  |  |                 value = Double.parseDouble(expression.execute().toString()); | 
 |  |  |             } | 
 |  |  |             int sensorState = judgeState(list, value); | 
 |  |  |             if (sensorState > state) { | 
 |  |  |                 state = sensorState; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         //修改设备状态 | 
 |  |  |         UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>(); | 
 |  |  |         updateWrapper.eq("id", device.getId()).set("state", String.valueOf(state)); | 
 |  |  |         deviceMapper.update(null, updateWrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //根据因子值判断状态 | 
 |  |  |     private int judgeState(List<Object> levels, Double data) { | 
 |  |  |         int state = 1; | 
 |  |  |         for (int i = levels.size() - 1; i >= 0; i--) { | 
 |  |  |             Double level = Double.parseDouble(levels.get(i).toString()); | 
 |  |  |             if (data >= level) { | 
 |  |  |                 state = i + 1; | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return state; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void insertOrganizationUnitAlarm(Integer orgId, Integer versionId) { | 
 |  |  |         QueryWrapper<OrganizationUnitAlarm> queryOrganizationVersionWrapper = new QueryWrapper<>(); | 
 |  |  |         queryOrganizationVersionWrapper.eq("organization_id", orgId); | 
 |  |  |         queryOrganizationVersionWrapper.eq("version_id", versionId); | 
 |  |  |         queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |         List<OrganizationUnitAlarm> organizationUnitAlarms = organizationUnitAlarmMapper.selectList(queryOrganizationVersionWrapper); | 
 |  |  |         if (ObjectUtils.isEmpty(organizationUnitAlarms)) { | 
 |  |  |             QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper = new QueryWrapper<>(); | 
 |  |  |             queryVersionSensorUnitWrapper.eq("version_id", versionId); | 
 |  |  |             queryVersionSensorUnitWrapper.eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |             List<VersionSensorUnit> versionSensorUnits = versionSensorUnitMapper.selectList(queryVersionSensorUnitWrapper); | 
 |  |  |             if (!ObjectUtils.isEmpty(versionSensorUnits)) { | 
 |  |  |                 for (VersionSensorUnit versionSensorUnit : versionSensorUnits) { | 
 |  |  |                     OrganizationUnitAlarm organizationUnitAlarm = new OrganizationUnitAlarm(); | 
 |  |  |                     organizationUnitAlarm.setOrganizationId(orgId); | 
 |  |  |                     organizationUnitAlarm.setVersionId(versionId); | 
 |  |  |                     organizationUnitAlarm.setSensorCode(versionSensorUnit.getSensorCode()); | 
 |  |  |                     organizationUnitAlarm.setUnitKey(versionSensorUnit.getUnitKey()); | 
 |  |  |                     organizationUnitAlarm.setShowUnitKey(versionSensorUnit.getUnitKey()); | 
 |  |  |                     organizationUnitAlarmMapper.insert(organizationUnitAlarm); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void deleteOrganizationUnitAlarm(Integer orgId, Integer versionId) { | 
 |  |  |         QueryWrapper<Device> queryOrganizationVersionWrapper = new QueryWrapper<>(); | 
 |  |  |         queryOrganizationVersionWrapper.eq("organization_id", orgId); | 
 |  |  |         queryOrganizationVersionWrapper.eq("device_version_id", versionId); | 
 |  |  |         queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |         List<Device> devices = deviceMapper.selectList(queryOrganizationVersionWrapper); | 
 |  |  |         if (ObjectUtils.isEmpty(devices)) {//如果为空,则组织没有该型号的设备了。 | 
 |  |  |             UpdateWrapper deleteWrapper = new UpdateWrapper(); | 
 |  |  |             deleteWrapper.eq("organization_id", orgId); | 
 |  |  |             deleteWrapper.eq("version_id", versionId); | 
 |  |  |             deleteWrapper.eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |             deleteWrapper.set("is_delete", Constants.DELETE); | 
 |  |  |             organizationUnitAlarmMapper.update(null, deleteWrapper); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |