From cc06e680134316be4655422d06056a916b8bd8e4 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Fri, 18 Jun 2021 09:01:43 +0800
Subject: [PATCH] screen-api 修改型号查询bug
---
screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java | 295 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 240 insertions(+), 55 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..76d4e8f 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,39 @@
package com.moral.api.service.impl;
+import com.alibaba.fastjson.JSON;
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.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.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.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 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.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
+
+import javax.servlet.http.HttpServletRequest;
/**
* <p>
@@ -63,12 +64,95 @@
@Autowired
private SysDictDataMapper sysDictDataMapper;
+ @Autowired
+ private LogUtils logUtils;
+
+ @Autowired
+ private RedisTemplate redisTemplate;
+
+ @Autowired
+ private OrganizationUnitAlarmMapper organizationUnitAlarmMapper;
+
+ @Autowired
+ private VersionSensorUnitMapper versionSensorUnitMapper;
+
+ /*
+ * ���redis������������������
+ * */
+ private Map<String, Object> getDeviceInfoFromRedis(String mac) {
+ Map<String, Object> deviceInfo = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DEVICE + mac);
+ return deviceInfo;
+ }
+
+ /*
+ * ������������������redis
+ */
+ private void setDeviceInfoToRedis(String mac, Map<String, Object> deviceInfo) {
+ redisTemplate.opsForValue().set(getDeviceKey(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();
+ }
+
@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);
+ //���������������������������
+ 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());
+
+ }
+ }
+ }
+ //������������������������redis
+ String mac = device.getMac();
+ //���redis���������������������
+ delDeviceInfoFromRedis(mac);
+ //������������������redis
+ setDeviceInfoToRedis(mac, deviceInfo);
+ //������������������
+ 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
@@ -77,18 +161,58 @@
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);
+ Device device = deviceMapper.selectById(deviceId);
+ String mac = device.getMac();
+ //���redis���������������������
+ delDeviceInfoFromRedis(mac);
+ //������������������
+ 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);
deviceMapper.updateById(device);
- //������redis
- Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId());
- RedisUtil.set("device_" + deviceInfo.get("mac"), deviceInfo);
+ String mac = deviceMapper.selectById(deviceId).getMac();
+ //���redis���������������������
+ delDeviceInfoFromRedis(mac);
+ Map<String, Object> deviceInfo = selectDeviceInfoById(deviceId);
+ //������������������redis
+ setDeviceInfoToRedis(mac, deviceInfo);
+ //������������������
+ HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+ StringBuilder content = new StringBuilder();
+ content.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
@@ -118,34 +242,44 @@
}
@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");
+ Object orgId = parameters.get("organizationId");
+ Object mpId = parameters.get("monitorPointId");
+
+ //������������������������������
+ if (orgId != null) {
+ queryWrapper.eq("organization_id", orgId);
+ }
+
+ //������������������������������
+ if (mpId != null) {
+ queryWrapper.eq("monitor_point_id", mpId);
+ }
+
if (name != null) {
queryWrapper.like("name", name);
}
if (mac != null) {
queryWrapper.like("mac", mac);
}
+
//������������,������create_time������
if (order != null && orderType != null) {
@@ -160,44 +294,67 @@
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());
//������
- result.put("profession", device.getProfession());
- result.put("professionName", device.getProfessionName());
+ deviceInfo.put("profession", device.getProfession());
+ deviceInfo.put("professionName", device.getProfessionName());
//������
- 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 +365,24 @@
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;
+ deviceInfo.put("monitorPoint", mpInfo);
+
+ setDeviceInfoToRedis(mac, deviceInfo);
+ return deviceInfo;
}
@Override
@@ -240,4 +399,30 @@
return monitorPointMapper.selectMaps(queryWrapper);
}
+ @Override
+ public Map<String, Object> getDeviceByMac(String mac) {
+ Map<String, Object> deviceInfo = getDeviceInfoFromRedis(mac);
+ if (deviceInfo == null) {
+ 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, Map<String, Object> deviceInfo) {
+ return null;
+ }
+
+ @Override
+ public Map<String, Object> judgeDeviceState(Map<String, Object> deviceData, Map<String, Object> deviceInfo) {
+ return null;
+ }
+
+
}
--
Gitblit v1.8.0