From c7dd4a195d8d893d92c49963447cdf6486844584 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 20 Oct 2023 09:45:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wb' into cjl
---
screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java | 524 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 459 insertions(+), 65 deletions(-)
diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index 57be6cd..0fdd0b8 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -1,38 +1,47 @@
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.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.moral.api.entity.Device;
-import com.moral.api.entity.ManageAccount;
-import com.moral.api.entity.MonitorPoint;
-import com.moral.api.entity.Organization;
-import com.moral.api.entity.SysDictData;
-import com.moral.api.entity.SysDictType;
-import com.moral.api.entity.Version;
-import com.moral.api.mapper.DeviceMapper;
-import com.moral.api.mapper.ManageAccountMapper;
-import com.moral.api.mapper.MonitorPointMapper;
-import com.moral.api.mapper.OrganizationMapper;
-import com.moral.api.mapper.SysDictDataMapper;
-import com.moral.api.mapper.SysDictTypeMapper;
+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.service.OrganizationService;
+import com.moral.api.service.SysDictDataService;
+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.redis.RedisUtil;
+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;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import javax.servlet.http.HttpServletRequest;
/**
* <p>
@@ -43,6 +52,7 @@
* @since 2021-05-11
*/
@Service
+@Slf4j
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
@Autowired
@@ -63,32 +73,154 @@
@Autowired
private SysDictDataMapper sysDictDataMapper;
+ @Autowired
+ private SysDictDataService sysDictDataService;
+
+
+ @Autowired
+ private RedisTemplate redisTemplate;
+
+ @Autowired
+ private OrganizationUnitAlarmMapper organizationUnitAlarmMapper;
+
+ @Autowired
+ private VersionSensorUnitMapper versionSensorUnitMapper;
+
+ @Autowired
+ private SpecialDeviceMapper specialDeviceMapper;
+
+ @Autowired
+ private AdjustDataUtils adjustDataUtils;
+
+ @Autowired
+ private OrganizationService organizationService;
+
+ /*
+ * ���redis������������������
+ * */
+ private Map<String, Object> getDeviceInfoFromRedis(String mac) {
+ return (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac);
+ }
+
+ /*
+ * ������������������redis
+ */
+ private void setDeviceInfoToRedis(String mac, Map<String, Object> deviceInfo) {
+ redisTemplate.opsForHash().put(RedisConstants.DEVICE, mac, deviceInfo);
+ }
+
+ /*
+ * ���redis������������������
+ */
+ private void delDeviceInfoFromRedis(String mac) {
+ redisTemplate.opsForHash().delete(RedisConstants.DEVICE, mac);
+ }
+
@Override
@Transactional
public void insert(Device device) {
+ Integer orgId = monitorPointMapper.selectById(device.getMonitorPointId()).getOrganizationId();
+ device.setOrganizationId(orgId);
deviceMapper.insert(device);
Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId());
- RedisUtil.set("device_" + device.getMac(), deviceInfo);
+ //���������������������������
+ 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);
+ 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);
- String mac = deviceMapper.selectById(deviceId).getMac();
- //������redis
- RedisUtil.del("device_" + mac);
+ 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();
+ content.append("������������������").append(device.getName()).append(";").append("mac���").append(mac);
+ LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE);
}
@Override
@Transactional
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);
- //������redis
- Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId());
- RedisUtil.set("device_" + deviceInfo.get("mac"), deviceInfo);
+ 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(oldDevice.getMac());
+ Map<String, Object> deviceInfo = selectDeviceInfoById(deviceId);
+ //������������������redis
+ setDeviceInfoToRedis(mac, deviceInfo);
+ //������deviceInfo������
+ CacheUtils.refreshDeviceAlarmInfo(mac);
+ //������������������
+ HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+ StringBuilder content = new StringBuilder();
+ content.append("������������������" + oldDevice.getMac()).append("==>").append(mac).append("���");
+ Field[] fields = Device.class.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getName().equals("id")) {
+ continue;
+ }
+ if ("serialVersionUID".equals(field.getName())) {
+ continue;
+ }
+ String fieldName = field.getName();
+ PropertyDescriptor pd = null;
+ try {
+ pd = new PropertyDescriptor(fieldName, Device.class);
+ Method method = pd.getReadMethod();
+ Object o1 = method.invoke(oldDevice);
+ Object o2 = method.invoke(device);
+ if (o2 != null) {
+ content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
}
@Override
@@ -112,39 +244,56 @@
@Override
public List<Map<String, Object>> selectMonitorsByOrgId(Integer orgId) {
+ //���������������������
+ List<Organization> organizations = organizationService.getAllChildrenOrganization(orgId);
+ List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
+ orgIds.add(orgId);
QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>();
- queryWrapper.select("id", "name").eq("organization_id", orgId).eq("is_delete", Constants.NOT_DELETE);
+ queryWrapper.select("id", "name")
+ .eq("is_delete", Constants.NOT_DELETE)
+ .in("organization_id", orgIds);
return monitorPointMapper.selectMaps(queryWrapper);
}
@Override
- public List<Map<String, Object>> selectDevicesByOrgId(Integer orgId) {
- QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("is_delete", Constants.NOT_DELETE).eq("organization_id", orgId);
- return deviceMapper.selectMaps(queryWrapper);
+ public Map<String, Object> selectDevicesByOrgId(Map<String, Object> parameters) {
+ return selectDevices(parameters);
}
@Override
- public List<Map<String, Object>> selectDevicesByMpId(Integer mpId) {
- QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("is_delete", Constants.NOT_DELETE).eq("monitor_point_id", mpId);
- return deviceMapper.selectMaps(queryWrapper);
+ public Map<String, Object> selectDevicesByMpId(Map<String, Object> parameters) {
+ return selectDevices(parameters);
}
@Override
- public IPage<Device> selectDevices(Map<String, Object> parameters) {
+ public Map<String, Object> selectDevices(Map<String, Object> parameters) {
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
- Integer page = (Integer) parameters.get("page");
- Integer size = (Integer) parameters.get("size");
+ int page = Integer.parseInt(parameters.get("page").toString());
+ int size = Integer.parseInt(parameters.get("size").toString());
Object order = parameters.get("order");
Object orderType = parameters.get("orderType");
Object name = parameters.get("name");
Object mac = parameters.get("mac");
- if (name != null) {
- queryWrapper.like("name", name);
+ Object orgId = parameters.get("organizationId");
+ Object mpId = parameters.get("monitorPointId");
+
+ //������������������������������,���������������
+ if (orgId != null) {
+ //���������������������
+ List<Organization> organizations = organizationService.getAllChildrenOrganization(Integer.parseInt(orgId.toString()));
+ List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
+ orgIds.add(Integer.parseInt(orgId.toString()));
+ queryWrapper.in("organization_id", orgIds);
}
- if (mac != null) {
- queryWrapper.like("mac", mac);
+
+ //������������������������������
+ if (mpId != null) {
+ queryWrapper.eq("monitor_point_id", mpId);
+ }
+
+ //���������������mac������������
+ if (name != null && mac != null) {
+ queryWrapper.like("name", name).or().like("mac", mac);
}
//������������,������create_time������
@@ -160,44 +309,68 @@
queryWrapper.eq("is_delete", Constants.NOT_DELETE);
Page<Device> devicePage = new Page<>(page, size);
deviceMapper.selectPage(devicePage, queryWrapper);
- return devicePage;
+ List<Device> devices = devicePage.getRecords();
+ List<Map<String, Object>> items = new ArrayList<>();
+ for (Device device : devices) {
+ Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId());
+ items.add(deviceInfo);
+ }
+ Map<String, Object> result = new LinkedHashMap<>();
+ result.put("total", devicePage.getTotal());
+ result.put("totalPage", devicePage.getPages());
+ result.put("current", devicePage.getCurrent());
+ result.put("pageSize", devicePage.getSize());
+ result.put("item", items);
+ return result;
}
@Override
public Map<String, Object> selectDeviceInfoById(Integer deviceId) {
- Map<String, Object> result = new LinkedHashMap<>();
+ String mac = deviceMapper.selectById(deviceId).getMac();
+ Map<String, Object> deviceInfo = getDeviceInfoFromRedis(mac);
+ //������redis������
+ if (deviceInfo != null) {
+ return deviceInfo;
+ }
+ deviceInfo = new LinkedHashMap<>();
DeviceVO device = deviceMapper.selectDeviceInfoById(deviceId);
//������
- result.put("id", device.getId());
- result.put("name", device.getName());
- result.put("mac", device.getMac());
- result.put("address", device.getAddress());
- result.put("longitude", device.getLongitude());
- result.put("latitude", device.getLatitude());
- result.put("createTime", DateUtils.dateToDateString(device.getCreateTime()));
+ deviceInfo.put("id", device.getId());
+ deviceInfo.put("name", device.getName());
+ deviceInfo.put("mac", device.getMac());
+ deviceInfo.put("address", device.getAddress());
+ deviceInfo.put("longitude", device.getLongitude());
+ deviceInfo.put("latitude", device.getLatitude());
+ deviceInfo.put("createTime", DateUtils.dateToDateString(device.getCreateTime()));
+ deviceInfo.put("installTime", device.getInstallTime() == null ? null : DateUtils.dateToDateString(device.getInstallTime()));
+
+ //������������
+ deviceInfo.put("extend", device.getExtend());
+
+ //������������������
+ deviceInfo.put("town", device.getTown());
//������
- result.put("profession", device.getProfession());
- result.put("professionName", device.getProfessionName());
+ deviceInfo.put("professions", device.getProfessions());
//������
- result.put("tech", device.getTech());
- result.put("techName", device.getTechName());
+ deviceInfo.put("tech", device.getTech());
+ deviceInfo.put("techName", device.getTechName());
//���������
- result.put("detector", device.getDetector());
- result.put("detectorName", device.getDetectorName());
+ deviceInfo.put("detector", device.getDetector());
+ deviceInfo.put("detectorName", device.getDetectorName());
//���������
- result.put("purchaser", device.getPurchaser());
- result.put("purchaserName", device.getPurchaserName());
+ deviceInfo.put("purchaser", device.getPurchaser());
+ deviceInfo.put("purchaserName", device.getPurchaserName());
//������
Map<String, Object> versionInfo = new LinkedHashMap<>();
Version version = device.getVersion();
versionInfo.put("id", version.getId());
versionInfo.put("name", version.getName());
- result.put("version", versionInfo);
+ deviceInfo.put("version", versionInfo);
//���������
List<Map<String, Object>> operatorsInfo = new ArrayList<>();
@@ -208,22 +381,37 @@
operatorMap.put("name", operator.getUserName());
operatorsInfo.add(operatorMap);
}
- result.put("operators", operatorsInfo);
+ deviceInfo.put("operators", operatorsInfo);
//������
Map<String, Object> orgInfo = new LinkedHashMap<>();
Organization organization = device.getOrganization();
orgInfo.put("id", organization.getId());
orgInfo.put("name", organization.getName());
- result.put("organization", orgInfo);
+ deviceInfo.put("organization", orgInfo);
//������
Map<String, Object> mpInfo = new LinkedHashMap<>();
MonitorPoint monitorPoint = device.getMonitorPoint();
mpInfo.put("id", monitorPoint.getId());
mpInfo.put("name", monitorPoint.getName());
- result.put("monitorPoint", mpInfo);
- return result;
+ mpInfo.put("areaCode", monitorPoint.getAreaCode());
+ mpInfo.put("cityCode", monitorPoint.getCityCode());
+ mpInfo.put("provinceCode", monitorPoint.getProvinceCode());
+ deviceInfo.put("monitorPoint", mpInfo);
+
+ //������������
+ Map<String, Object> govMpInfo = new LinkedHashMap<>();
+
+ govMpInfo.put("guid", null);
+ govMpInfo.put("name", null);
+ if (device.getGovMonitorPoint() != null) {
+ govMpInfo.put("guid", device.getGovMonitorPoint().getGuid());
+ govMpInfo.put("name", device.getGovMonitorPoint().getName());
+ }
+ deviceInfo.put("govMonitorPoint", govMpInfo);
+ setDeviceInfoToRedis(mac, deviceInfo);
+ return deviceInfo;
}
@Override
@@ -240,4 +428,210 @@
return monitorPointMapper.selectMaps(queryWrapper);
}
+ @Override
+ public Map<String, Object> getDeviceByMac(String mac) {
+ Map<String, Object> deviceInfo = getDeviceInfoFromRedis(mac);
+ if (ObjectUtils.isEmpty(deviceInfo)) {
+ QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("mac", mac).eq("is_delete", Constants.NOT_DELETE);
+ Device device = deviceMapper.selectOne(queryWrapper);
+ if (device != null) {
+ deviceInfo = selectDeviceInfoById(device.getId());
+ setDeviceInfoToRedis(mac, deviceInfo);
+ }
+ }
+ return deviceInfo;
+ }
+
+ @Override
+ public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData,String code) {
+// String mac = deviceData.remove("mac").toString();
+ String mac = deviceData.get("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> govMpInfo = (Map<String, Object>) deviceInfo.get("govMonitorPoint");
+ Map<String, Object> aqiMap = null;
+ if (govMpInfo.get("guid") != null) {
+ aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString());
+ }
+ return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap,code);
+ }
+ deviceData.remove("DataTime");
+ return deviceData;
+ }
+
+ @Override
+ public Map<String, Object> adjustSpecialDeviceData(Map<String, Object> deviceData) {
+// String mac = deviceData.remove("mac").toString();
+ String mac = deviceData.get("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,"0");
+ }
+ deviceData.remove("DataTime");
+ return deviceData;
+ }
+
+ @Override
+ 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();
+
+ //���������������������������������������������������������������
+ if (deviceData.get(sensorCode) != null) {
+ String sensorValue = String.valueOf(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;
+ }
+ }
+ }
+ //������������������
+ Device device1 = new Device();
+ device1.setId(device.getId());
+ device1.setState(String.valueOf(state));
+ deviceMapper.updateById(device1);
+ }
+
+ @Override
+ public List<Map<String, Object>> selectMonitorPiontAndDeviceByOrgId(int orgId) {
+ QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>();
+ monitorPointQueryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ monitorPointQueryWrapper.eq("organization_id", orgId);
+ List<MonitorPoint> monitorPointList = monitorPointMapper.selectList(monitorPointQueryWrapper);
+ List<Map<String, Object>> resultList = new ArrayList<>();
+ for (MonitorPoint monitorPoint : monitorPointList) {
+ Map<String, Object> resultMap = new HashMap<>();
+ resultMap = JSON.parseObject(JSON.toJSONString(monitorPoint), Map.class);
+ int mp_id = monitorPoint.getId();
+ QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
+ deviceQueryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ deviceQueryWrapper.eq("monitor_point_id", mp_id);
+ List<Device> devices = new ArrayList<>();
+ devices = deviceMapper.selectList(deviceQueryWrapper);
+ resultMap.put("devices", devices);
+ resultList.add(resultMap);
+ }
+ return resultList;
+ }
+
+ //���������������������������
+ 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 + 2;
+ break;
+ }
+ }
+ return state;
+ }
+
+ /**
+ * @Description: ���������������������������������������������������������������������������������������������
+ * @Param: [orgId, versionId]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/9/6
+ */
+ 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);
+ //������������������������������������
+ Map<String, SysDictData> sensorAlarms = sysDictDataService.getDictDatasByType("defaultAlarm");
+ if (!ObjectUtils.isEmpty(versionSensorUnits)) {
+ for (VersionSensorUnit versionSensorUnit : versionSensorUnits) {
+ OrganizationUnitAlarm organizationUnitAlarm = new OrganizationUnitAlarm();
+ String sensorCode = versionSensorUnit.getSensorCode();
+ //���������������������
+ SysDictData alarm = sensorAlarms.get(sensorCode);
+ if (alarm != null)
+ organizationUnitAlarm.setAlarmLevel(alarm.getDataValue());
+ organizationUnitAlarm.setOrganizationId(orgId);
+ organizationUnitAlarm.setVersionId(versionId);
+ organizationUnitAlarm.setSensorCode(versionSensorUnit.getSensorCode());
+ organizationUnitAlarm.setUnitKey(versionSensorUnit.getUnitKey());
+ organizationUnitAlarm.setShowUnitKey(versionSensorUnit.getUnitKey());
+ organizationUnitAlarmMapper.insert(organizationUnitAlarm);
+ }
+ }
+ }
+ }
+
+ /**
+ * @Description: ������������������������������������������������������������������������������������������������������������������������������������
+ * @Param: [orgId, versionId]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/9/6
+ */
+ 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);
+ }
+ }
+
+ @Override
+ public void setRedisDevice() {
+ List<Device> list = lambdaQuery().eq(Device::getIsDelete,0).list();
+ for(Device d : list){
+ redisTemplate.opsForHash().delete(RedisConstants.DEVICE, d.getMac());
+ Map<String, Object> deviceInfo = selectDeviceInfoById(d.getId());
+ setDeviceInfoToRedis(d.getMac(), deviceInfo);
+ }
+ }
}
--
Gitblit v1.8.0