From a0341d4100c15c57fb645fd1f23225563e306712 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Wed, 28 Feb 2018 10:55:55 +0800
Subject: [PATCH] 设备和监控点 两模块修改,同步reids里的信息。数据字典功能添加
---
src/main/resources/mapper/DictionaryMapper.xml | 12 +++
src/main/resources/mapper/DictionaryDataMapper.xml | 16 ++++
src/main/java/com/moral/entity/DictionaryData.java | 73 ++++++++++++++++++
src/main/java/com/moral/mapper/DictionaryDataMapper.java | 8 ++
src/main/resources/mapper/DeviceMapper.xml | 2
src/main/resources/mapper/MonitorPointMapper.xml | 3
src/main/java/com/moral/entity/Dictionary.java | 33 ++++++++
src/main/java/com/moral/mapper/DictionaryMapper.java | 8 ++
src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 22 ++++-
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | 35 ++++++++
src/main/java/com/moral/mapper/MonitorPointMapper.java | 2
11 files changed, 207 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/moral/entity/Dictionary.java b/src/main/java/com/moral/entity/Dictionary.java
new file mode 100644
index 0000000..be69fe8
--- /dev/null
+++ b/src/main/java/com/moral/entity/Dictionary.java
@@ -0,0 +1,33 @@
+package com.moral.entity;
+
+public class Dictionary {
+ private String dictName;
+
+ private Integer dictValue;
+
+ private Integer isDelete;
+
+ public String getDictName() {
+ return dictName;
+ }
+
+ public void setDictName(String dictName) {
+ this.dictName = dictName == null ? null : dictName.trim();
+ }
+
+ public Integer getDictValue() {
+ return dictValue;
+ }
+
+ public void setDictValue(Integer dictValue) {
+ this.dictValue = dictValue;
+ }
+
+ public Integer getIsDelete() {
+ return isDelete;
+ }
+
+ public void setIsDelete(Integer isDelete) {
+ this.isDelete = isDelete;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/entity/DictionaryData.java b/src/main/java/com/moral/entity/DictionaryData.java
new file mode 100644
index 0000000..05fdaf4
--- /dev/null
+++ b/src/main/java/com/moral/entity/DictionaryData.java
@@ -0,0 +1,73 @@
+package com.moral.entity;
+
+public class DictionaryData {
+ private Integer id;
+
+ private Integer dictValue;
+
+ private String dictDataName;
+
+ private Object dictDataValue;
+
+ private Integer isFixed;
+
+ private Integer isDelete;
+
+ private Integer parentId;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Integer getDictValue() {
+ return dictValue;
+ }
+
+ public void setDictValue(Integer dictValue) {
+ this.dictValue = dictValue;
+ }
+
+ public String getDictDataName() {
+ return dictDataName;
+ }
+
+ public void setDictDataName(String dictDataName) {
+ this.dictDataName = dictDataName == null ? null : dictDataName.trim();
+ }
+
+ public Object getDictDataValue() {
+ return dictDataValue;
+ }
+
+ public void setDictDataValue(Object dictDataValue) {
+ this.dictDataValue = dictDataValue;
+ }
+
+ public Integer getIsFixed() {
+ return isFixed;
+ }
+
+ public void setIsFixed(Integer isFixed) {
+ this.isFixed = isFixed;
+ }
+
+ public Integer getIsDelete() {
+ return isDelete;
+ }
+
+ public void setIsDelete(Integer isDelete) {
+ this.isDelete = isDelete;
+ }
+
+ public Integer getParentId() {
+ return parentId;
+ }
+
+ public void setParentId(Integer parentId) {
+ this.parentId = parentId;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/mapper/DictionaryDataMapper.java b/src/main/java/com/moral/mapper/DictionaryDataMapper.java
new file mode 100644
index 0000000..4c5a3c3
--- /dev/null
+++ b/src/main/java/com/moral/mapper/DictionaryDataMapper.java
@@ -0,0 +1,8 @@
+package com.moral.mapper;
+
+import com.moral.common.mapper.BaseMapper;
+import com.moral.entity.DictionaryData;
+
+public interface DictionaryDataMapper extends BaseMapper<DictionaryData> {
+ DictionaryData selectByPrimaryKey(Integer id);
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/mapper/DictionaryMapper.java b/src/main/java/com/moral/mapper/DictionaryMapper.java
new file mode 100644
index 0000000..52a8429
--- /dev/null
+++ b/src/main/java/com/moral/mapper/DictionaryMapper.java
@@ -0,0 +1,8 @@
+package com.moral.mapper;
+
+import com.moral.common.mapper.BaseMapper;
+import com.moral.entity.Dictionary;
+
+public interface DictionaryMapper extends BaseMapper<Dictionary> {
+ Dictionary selectByPrimaryKey(String dictName);
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/mapper/MonitorPointMapper.java b/src/main/java/com/moral/mapper/MonitorPointMapper.java
index f6244bc..efb0a64 100644
--- a/src/main/java/com/moral/mapper/MonitorPointMapper.java
+++ b/src/main/java/com/moral/mapper/MonitorPointMapper.java
@@ -10,6 +10,6 @@
public interface MonitorPointMapper extends BaseMapper<MonitorPoint>{
List<MonitorPoint> selectWithAreaNameByExample(Example example);
List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters);
-
List<MonitorPoint> selectByMap(Map<String, Object> params);
+ List<Integer> selectOrganizationIds(int id);
}
\ No newline at end of file
diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
index 3b53edd..74b3571 100644
--- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -12,6 +12,7 @@
import com.moral.common.bean.PageResult;
import com.moral.common.util.ExampleUtil;
import com.moral.common.util.RedisUtils;
+import com.moral.mapper.MonitorPointMapper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
@@ -32,7 +33,8 @@
@Resource
private DeviceMapper deviceMapper;
-
+ @Resource
+ private MonitorPointMapper monitorPointMapper;
@Resource
private AccountService accountService;
private Class ENTITY_CLASS = Device.class;
@@ -205,8 +207,20 @@
/*
������ redis ���������������
*/
- private void refreshDeviceInRedis(String mac){
- getDeviceWithOrgIdsByMac(mac);
+ private void refreshDeviceInRedis(Device device){
+ if(!StringUtils.isBlank(device.getMac())){
+ Device simpleDevice = new Device();
+ simpleDevice.setId(device.getId());
+ simpleDevice.setDeviceVersion(device.getDeviceVersion());
+ simpleDevice.setMac(device.getMac());
+ simpleDevice.setMonitorPointId(device.getMonitorPointId());
+ if(device.getMonitorPointId()!=null){
+ List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(device.getMonitorPointId());
+ simpleDevice.setOrganizationIds(orgIds);
+ }
+ String key = "device_"+device.getMac();
+ redisUtils.set(key,simpleDevice);
+ }
}
@Override
public PageBean queryByPageBean(PageBean pageBean) {
@@ -256,7 +270,7 @@
}else{
deviceMapper.updateByPrimaryKeySelective(device);
//������redis���������������
- refreshDeviceInRedis(device.getMac());
+ refreshDeviceInRedis(device);
}
}
catch (Exception ex){
diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
index e979b68..beed2e6 100644
--- a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -12,6 +12,9 @@
import com.moral.common.bean.Constants;
import com.moral.common.bean.PageBean;
import com.moral.common.util.*;
+import com.moral.entity.Device;
+import com.moral.mapper.DeviceMapper;
+import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import com.moral.entity.MonitorPoint;
@@ -24,6 +27,8 @@
public class MonitorPointServiceImpl implements MonitorPointService {
@Resource
private MonitorPointMapper monitorPointMapper;
+ @Resource
+ private DeviceMapper deviceMapper;
@Resource
RedisUtils redisUtils;
private static Class ENTITY_CLASS = MonitorPoint.class;
@@ -84,15 +89,43 @@
monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
monitorPointMapper.insertSelective(monitorPoint);
}else{
- // TODO ������������id������������������redis���������������
monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
+ // ������������������������������ ���redis���������������
+ refreshDevicesInRedis(monitorPoint.getId());
}
}
catch (Exception ex){
throw ex;
}
}
+ /*
+ ������������������������������ ���redis���������������
+ */
+ private void refreshDevicesInRedis(int monitorPointId){
+ Device device = new Device();
+ device.setMonitorPointId(monitorPointId);
+ List<Device> deviceList = deviceMapper.select(device);
+ 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());
+ // ������������������������������������������������������������������
+ simpleDevice.setOrganizationIds(orgIds);
+ redisUtils.set(key,simpleDevice);
+ }
+ });
+ }
+ }
+ }
@Override
public void deleteByIds(Integer... ids) {
MonitorPoint monitorPoint = new MonitorPoint();
diff --git a/src/main/resources/mapper/DeviceMapper.xml b/src/main/resources/mapper/DeviceMapper.xml
index 1bbef74..846ad57 100644
--- a/src/main/resources/mapper/DeviceMapper.xml
+++ b/src/main/resources/mapper/DeviceMapper.xml
@@ -194,7 +194,7 @@
</resultMap>
<!-- resultMap������ -->
<select id="selectOrganizationIds" resultType="INTEGER">
- call proc_organization_id_select(#{id,jdbcType=INTEGER});
+ call proc_organizationIds_GetByDeviceId(#{id,jdbcType=INTEGER});
</select>
<select id="selectWithOrgIdsByMac" parameterType="java.lang.String" resultMap="BaseResultWithOrgIdsMap">
select
diff --git a/src/main/resources/mapper/DictionaryDataMapper.xml b/src/main/resources/mapper/DictionaryDataMapper.xml
new file mode 100644
index 0000000..5d502f6
--- /dev/null
+++ b/src/main/resources/mapper/DictionaryDataMapper.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.moral.mapper.DictionaryDataMapper" >
+ <resultMap id="BaseResultMap" type="com.moral.entity.DictionaryData" >
+ <id column="id" property="id" jdbcType="INTEGER" />
+ <result column="dict_value" property="dictValue" jdbcType="INTEGER" />
+ <result column="dict_data_name" property="dictDataName" jdbcType="VARCHAR" />
+ <result column="dict_data_value" property="dictDataValue" jdbcType="OTHER" />
+ <result column="is_fixed" property="isFixed" jdbcType="INTEGER" />
+ <result column="is_delete" property="isDelete" jdbcType="INTEGER" />
+ <result column="parent_id" property="parentId" jdbcType="INTEGER" />
+ </resultMap>
+ <sql id="Base_Column_List" >
+ id, dict_value, dict_data_name, dict_data_value, is_fixed, is_delete, parent_id
+ </sql>
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/DictionaryMapper.xml b/src/main/resources/mapper/DictionaryMapper.xml
new file mode 100644
index 0000000..f81c477
--- /dev/null
+++ b/src/main/resources/mapper/DictionaryMapper.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.moral.mapper.DictionaryMapper" >
+ <resultMap id="BaseResultMap" type="com.moral.entity.Dictionary" >
+ <id column="dict_name" property="dictName" jdbcType="VARCHAR" />
+ <result column="dict_value" property="dictValue" jdbcType="INTEGER" />
+ <result column="is_delete" property="isDelete" jdbcType="INTEGER" />
+ </resultMap>
+ <sql id="Base_Column_List" >
+ dict_name, dict_value, is_delete
+ </sql>
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/MonitorPointMapper.xml b/src/main/resources/mapper/MonitorPointMapper.xml
index ee6e6af..5e6b2a4 100644
--- a/src/main/resources/mapper/MonitorPointMapper.xml
+++ b/src/main/resources/mapper/MonitorPointMapper.xml
@@ -115,4 +115,7 @@
]]>
</where>
</select>
+ <select id="selectOrganizationIds" parameterType="integer" resultType="integer">
+ call proc_organizationIds_GetByMonitorPointId(#{id,jdbcType=NUMERIC})
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.8.0