From b95fd235f28073131ffc4b9417219bdd576d3c7c Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Mon, 16 Jul 2018 15:26:49 +0800
Subject: [PATCH] 大屏登录 返回地址信息,超级管理员组织,返回 中国
---
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | 95 +++++++++++++++++++++++++++++++++++++----------
1 files changed, 75 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
index baa1462..78c626f 100644
--- a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.service.impl;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -7,7 +8,8 @@
import java.util.stream.Collectors;
import javax.annotation.Resource;
-
+import com.moral.mapper.DictionaryDataMapper;
+import com.moral.mapper.OrganizationMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@@ -34,7 +36,12 @@
@Resource
private DeviceMapper deviceMapper;
@Resource
+ private OrganizationMapper orgMapper;
+ @Resource
RedisUtils redisUtils;
+ @Resource
+ DictionaryDataMapper dictionaryDataMapper;
+
private static Class ENTITY_CLASS = MonitorPoint.class;
@Override
public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) {
@@ -43,12 +50,20 @@
}
@Override
public List<MonitorPoint> queryWithStateByMap(Map<String, Object> params){
- List<MonitorPoint> monitorPointList = monitorPointMapper.selectByMap(params);
- for(MonitorPoint monitorPoint:monitorPointList){
- Integer state = getStateFromRedis(monitorPoint.getId());
- monitorPoint.setState(state);
+ params.put("isDelete",Constants.IS_DELETE_FALSE);
+ Object orgIdObj = params.get("orgId");
+ List<MonitorPoint> monitorPointList = null;
+ if(orgIdObj != null) {
+ Integer orgId = Integer.parseInt(orgIdObj.toString());
+ List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId);
+ params.put("orgIds",orgIds);
+ monitorPointList = monitorPointMapper.selectByMap(params);
+ for(MonitorPoint monitorPoint:monitorPointList){
+ Integer state = getStateFromRedis(monitorPoint.getId());
+ monitorPoint.setState(state);
+ }
}
- return monitorPointList;
+ return monitorPointList == null ? new ArrayList<>() : monitorPointList;
}
private Integer getStateFromRedis(Integer monitorPointId){
StringBuilder key = new StringBuilder();
@@ -93,9 +108,17 @@
monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
monitorPointMapper.insertSelective(monitorPoint);
}else{
+ MonitorPoint queryMonitorPoint = new MonitorPoint();
+ queryMonitorPoint.setId(monitorPoint.getId());
+ queryMonitorPoint.setOrganizationId(monitorPoint.getOrganizationId());
+ // num = 1,���������������,������������������������
+ Integer num = monitorPointMapper.selectCount(queryMonitorPoint);
+ boolean needRefreshCach = (num!=1);
monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
- // ������������������������������ ���redis���������������
- refreshDevicesInRedis(monitorPoint.getId());
+ if(needRefreshCach){
+ // ������������������������������ ���redis���������������
+ refreshDevicesInRedis(monitorPoint.getId());
+ }
}
}
catch (Exception ex){
@@ -106,24 +129,24 @@
������������������������������ ���redis���������������
*/
private void refreshDevicesInRedis(int monitorPointId){
- Device device = new Device();
- device.setMonitorPointId(monitorPointId);
- List<Device> deviceList = deviceMapper.select(device);
+ Device queryDevice = new Device();
+ queryDevice.setMonitorPointId(monitorPointId);
+ List<Device> deviceList = deviceMapper.select(queryDevice);
if (!CollectionUtils.isEmpty(deviceList)){
List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(monitorPointId);
if (!CollectionUtils.isEmpty(orgIds)){
deviceList.stream().forEach(dev ->{
if(!StringUtils.isNullOrEmpty(dev.getMac())){
String key = "device_"+dev.getMac();
- // ��������������������� ������������redis
- Device simpleDevice = new Device();
- simpleDevice.setId(dev.getId());
- simpleDevice.setDeviceVersion(dev.getDeviceVersion());
- simpleDevice.setMac(dev.getMac());
- simpleDevice.setMonitorPointId(dev.getMonitorPointId());
+// // ��������������������� ������������redis
+// Device simpleDevice = new Device();
+// simpleDevice.setId(dev.getId());
+// simpleDevice.setDeviceVersion(dev.getDeviceVersion());
+// simpleDevice.setMac(dev.getMac());
+// simpleDevice.setMonitorPointId(dev.getMonitorPointId());
// ������������������������������������������������������������������
- simpleDevice.setOrganizationIds(orgIds);
- redisUtils.set(key,simpleDevice);
+ dev.setOrganizationIds(orgIds);
+ redisUtils.set(key,dev);
}
});
}
@@ -153,10 +176,25 @@
Criteria criteria = example.createCriteria();
criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE).andLike("name", "%" + name + "%");
- example.or().andEqualTo("isDelete", Constants.IS_DELETE_FALSE).andCondition("getPY(REPLACE (REPLACE (name,'���',''),'���','')) like ", "%" + name + "%");
+ example.or().andEqualTo("isDelete", Constants.IS_DELETE_FALSE)
+ .andCondition("getPY(" + getReplaceStr("name") + ") like ", "%" + name + "%");
List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
return monitorPoints;
+ }
+
+ private String getReplaceStr(String name){
+ List<String[]> list = new ArrayList<String[]>();
+ list.add(new String[]{"���",""});
+ list.add(new String[]{"���",""});
+ for (String[] string : list) {
+ name = replace(name,string[0],string[1]);
+ }
+ return name;
+ }
+
+ private String replace(String name,String fromStr,String toStr){
+ return "REPLACE (" + name + ",'" + fromStr + "','" + toStr + "')";
}
/**
@@ -188,4 +226,21 @@
example.orderBy("name").asc();
return monitorPointMapper.selectByExample(example);
}
+ @Override
+ public List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters) {
+ Example example = new Example(MonitorPoint.class);
+ Criteria criteria = example.createCriteria();
+
+ criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
+ criteria.andEqualTo(parameters.get("name").toString(), parameters.get("value"));
+ return monitorPointMapper.selectByExample(example);
+ }
+ @Override
+ public List<Integer> queryVersionsById(Integer id){
+ return monitorPointMapper.selectVersionsById(id);
+ }
+ @Override
+ public MonitorPoint queryMonitorPointById(Integer mpointId) {
+ return this.monitorPointMapper.selectByPrimaryKey(mpointId);
+ }
}
--
Gitblit v1.8.0