在本地合并冲突
This commit is contained in:
@@ -20,8 +20,8 @@ public class DynamicJedisDataBase {
|
|||||||
* @param index
|
* @param index
|
||||||
* @param redisTemplate
|
* @param redisTemplate
|
||||||
*/
|
*/
|
||||||
public static void setRedisDataBase(int index, RedisTemplate redisTemplate) {
|
public static void setRedisDataBase1(int index, RedisTemplate redisTemplate) {
|
||||||
JedisConnectionFactory connectionFactory = SpringContextHolder.getBean("connectionFactory");
|
JedisConnectionFactory connectionFactory = SpringContextHolder.getBean("connectionFactory"+index);
|
||||||
connectionFactory.setDatabase(index);
|
connectionFactory.setDatabase(index);
|
||||||
redisTemplate.setConnectionFactory(connectionFactory);
|
redisTemplate.setConnectionFactory(connectionFactory);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.nis.domain.restful;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Title: CompileAndGroupRelations</p>
|
||||||
|
* <p>Description: 记录下发配置时编译id与分组,域配置之间的关系,用于更新id关系数据字典</p>
|
||||||
|
* <p>Company: IIE</p>
|
||||||
|
* @author rkg
|
||||||
|
* @date 2018年5月25日
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CompileAndGroupRelations implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long compileId;
|
||||||
|
private List<GroupAndRegionRelations> groupIdList;
|
||||||
|
|
||||||
|
public Long getCompileId() {
|
||||||
|
return compileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompileId(Long compileId) {
|
||||||
|
this.compileId = compileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GroupAndRegionRelations> getGroupIdList() {
|
||||||
|
return groupIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupIdList(List<GroupAndRegionRelations> groupIdList) {
|
||||||
|
this.groupIdList = groupIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.nis.domain.restful;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Title: GroupAndRegionRelations</p>
|
||||||
|
* <p>Description: 记录下发配置时编译id与分组,域配置之间的关系,用于更新id关系数据字典</p>
|
||||||
|
* <p>Company: IIE</p>
|
||||||
|
* @author rkg
|
||||||
|
* @date 2018年5月25日
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GroupAndRegionRelations implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long groupId;
|
||||||
|
private Long regionId;
|
||||||
|
public Long getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
public void setGroupId(Long groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
public Long getRegionId() {
|
||||||
|
return regionId;
|
||||||
|
}
|
||||||
|
public void setRegionId(Long regionId) {
|
||||||
|
this.regionId = regionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,55 +3,65 @@ package com.nis.domain.restful;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MaatRelation implements Serializable {
|
public class MaatRelation implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
private Map<Long, List<Long>> compileAndGroupMap;
|
* 编译id与groupid的对应关系,key是编译id,value使用set不允许重复
|
||||||
private Map<Long, List<Long>> groupAndCompileMap;
|
*/
|
||||||
|
private Map<Long, Set<Long>> compileAndGroupMap;
|
||||||
|
/**
|
||||||
|
* groupid与编译id的对应关系,key是groupid,value使用set不允许重复
|
||||||
|
*/
|
||||||
|
private Map<Long, Set<Long>> groupAndCompileMap;
|
||||||
// private Map<Long, List<Long>> regionAndGroupMap;
|
// private Map<Long, List<Long>> regionAndGroupMap;
|
||||||
private Map<Long, List<Long>> groupAndRegionMap;
|
/**
|
||||||
|
* groupid与regionid的对应关系,key是groupid,value使用set不允许重复
|
||||||
|
*/
|
||||||
|
private Map<Long, Set<Long>> groupAndRegionMap;
|
||||||
|
|
||||||
public Map<Long, List<Long>> getCompileAndGroupMap() {
|
public Map<Long, Set<Long>> getCompileAndGroupMap() {
|
||||||
return compileAndGroupMap;
|
return compileAndGroupMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCompileAndGroupMap(Map<Long, List<Long>> compileAndGroupMap) {
|
public void setCompileAndGroupMap(Map<Long, Set<Long>> compileAndGroupMap) {
|
||||||
this.compileAndGroupMap = compileAndGroupMap;
|
this.compileAndGroupMap = compileAndGroupMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, List<Long>> getGroupAndCompileMap() {
|
public Map<Long, Set<Long>> getGroupAndCompileMap() {
|
||||||
return groupAndCompileMap;
|
return groupAndCompileMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroupAndCompileMap(Map<Long, List<Long>> groupAndCompileMap) {
|
public void setGroupAndCompileMap(Map<Long, Set<Long>> groupAndCompileMap) {
|
||||||
this.groupAndCompileMap = groupAndCompileMap;
|
this.groupAndCompileMap = groupAndCompileMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, List<Long>> getGroupAndRegionMap() {
|
public Map<Long, Set<Long>> getGroupAndRegionMap() {
|
||||||
return groupAndRegionMap;
|
return groupAndRegionMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroupAndRegionMap(Map<Long, List<Long>> groupAndRegionMap) {
|
public void setGroupAndRegionMap(Map<Long, Set<Long>> groupAndRegionMap) {
|
||||||
this.groupAndRegionMap = groupAndRegionMap;
|
this.groupAndRegionMap = groupAndRegionMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removKey(MaatRelation maatRelation, long compileId) {
|
public static void removKey(MaatRelation maatRelation, long compileId) {
|
||||||
|
|
||||||
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
||||||
List<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
Set<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
Long groupId = list.get(i);
|
if (list != null && list.size() > 0) {
|
||||||
|
for (Long groupId : list) {
|
||||||
// }
|
// }
|
||||||
// for (Long groupId: list.size()) {
|
// for (Long groupId: list.size()) {
|
||||||
if (maatRelation.getGroupAndCompileMap().containsKey(groupId)) {
|
if (maatRelation.getGroupAndCompileMap().containsKey(groupId)) {
|
||||||
// && maatRelation.getGroupAndCompileMap().get(groupId).size() == 1
|
// && maatRelation.getGroupAndCompileMap().get(groupId).size() == 1
|
||||||
// && maatRelation.getGroupAndCompileMap().get(groupId).get(0).longValue() ==
|
// && maatRelation.getGroupAndCompileMap().get(groupId).get(0).longValue() ==
|
||||||
// compileId) {
|
// compileId) {
|
||||||
List<Long> compileIdList = maatRelation.getGroupAndCompileMap().get(groupId);
|
Set<Long> compileIdList = maatRelation.getGroupAndCompileMap().get(groupId);
|
||||||
if (compileIdList.size() == 1) {// 当前的groupid只属于当前的compileid,没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
if (compileIdList.size() == 1) {// 当前的groupid只属于当前的compileid,没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
||||||
for (Long id : compileIdList) {
|
for (Long id : compileIdList) {
|
||||||
if (id.longValue() == compileId) {
|
if (id.longValue() == compileId) {
|
||||||
@@ -62,43 +72,50 @@ public class MaatRelation implements Serializable {
|
|||||||
maatRelation.getGroupAndCompileMap().remove(groupId);// 删除当前组所对应的编译
|
maatRelation.getGroupAndCompileMap().remove(groupId);// 删除当前组所对应的编译
|
||||||
// maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId);
|
// maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId);
|
||||||
// maatRelation.getCompileAndGroupMap().get(compileId)
|
// maatRelation.getCompileAndGroupMap().get(compileId)
|
||||||
list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));// 删除编译下面的组
|
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||||
|
// 删除编译下面的组
|
||||||
|
list.remove(groupId);// 删除编译下面的组
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 这个组对应了多个编译配置被分组复用了,这时将这个组和编译的关系置为无效,编译置为无效
|
// 这个组对应了多个编译配置被分组复用了,这时将这个组和编译的关系置为无效,编译置为无效
|
||||||
list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));// 删除编译下面的这个组
|
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||||
maatRelation.getGroupAndCompileMap().get(groupId)
|
// 删除编译下面的这个组
|
||||||
.remove(maatRelation.getGroupAndCompileMap().get(groupId).indexOf(compileId));// 删除分组关系中的组和编译关系
|
// maatRelation.getGroupAndCompileMap().get(groupId)
|
||||||
|
// .remove(maatRelation.getGroupAndCompileMap().get(groupId).indexOf(compileId));//
|
||||||
|
// 删除分组关系中的组和编译关系
|
||||||
|
|
||||||
|
list.remove(groupId);// 删除编译下面的这个组
|
||||||
|
maatRelation.getGroupAndCompileMap().get(groupId).remove(compileId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 当前的groupid属于多个组,被分组复用了,所以不对这个组进行操作,也不对这个组下面的域进行操作
|
// 当前的groupid属于多个组,被分组复用了,所以不对这个组进行操作,也不对这个组下面的域进行操作
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void syso(MaatRelation maatRelation) {
|
public static void syso(MaatRelation maatRelation) {
|
||||||
Map<Long, List<Long>> getCompileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
Map<Long, Set<Long>> getCompileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||||
for (Long compile : getCompileAndGroupMap.keySet()) {
|
for (Long compile : getCompileAndGroupMap.keySet()) {
|
||||||
List<Long> groupList = getCompileAndGroupMap.get(compile);
|
Set<Long> groupList = getCompileAndGroupMap.get(compile);
|
||||||
for (Long group : groupList) {
|
for (Long group : groupList) {
|
||||||
System.out.println("编译:" + compile + "组:" + group);
|
System.out.println("编译:" + compile + "组:" + group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<Long, List<Long>> getGroupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
Map<Long, Set<Long>> getGroupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||||
for (Long group : getGroupAndCompileMap.keySet()) {
|
for (Long group : getGroupAndCompileMap.keySet()) {
|
||||||
List<Long> compileList = getGroupAndCompileMap.get(group);
|
Set<Long> compileList = getGroupAndCompileMap.get(group);
|
||||||
for (Long compile : compileList) {
|
for (Long compile : compileList) {
|
||||||
System.out.println("组:" + group + "编译:" + compile);
|
System.out.println("组:" + group + "编译:" + compile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<Long, List<Long>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
Map<Long, Set<Long>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||||
List<Long> regionList = getGroupAndRegionMap.get(group);
|
Set<Long> regionList = getGroupAndRegionMap.get(group);
|
||||||
for (Long region : regionList) {
|
for (Long region : regionList) {
|
||||||
System.out.println("组:" + group + "域:" + region);
|
System.out.println("组:" + group + "域:" + region);
|
||||||
}
|
}
|
||||||
@@ -121,27 +138,95 @@ public class MaatRelation implements Serializable {
|
|||||||
compileId = 2;
|
compileId = 2;
|
||||||
removKey(maatRelation, compileId);
|
removKey(maatRelation, compileId);
|
||||||
syso(maatRelation);
|
syso(maatRelation);
|
||||||
|
|
||||||
|
addKey(maatRelation, setCGR());
|
||||||
|
syso(maatRelation);
|
||||||
|
|
||||||
|
|
||||||
|
compileId = 99999L;
|
||||||
|
removKey(maatRelation, compileId);
|
||||||
|
syso(maatRelation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompileAndGroupRelations setCGR() {
|
||||||
|
CompileAndGroupRelations cGR = new CompileAndGroupRelations();
|
||||||
|
cGR.setCompileId(99999L);
|
||||||
|
|
||||||
|
List<GroupAndRegionRelations> groupIdList = new ArrayList<GroupAndRegionRelations>();
|
||||||
|
GroupAndRegionRelations gRR = new GroupAndRegionRelations();
|
||||||
|
gRR.setGroupId(100L);
|
||||||
|
gRR.setRegionId(200L);
|
||||||
|
groupIdList.add(gRR);
|
||||||
|
|
||||||
|
gRR = new GroupAndRegionRelations();
|
||||||
|
gRR.setGroupId(100L);
|
||||||
|
gRR.setRegionId(300L);
|
||||||
|
groupIdList.add(gRR);
|
||||||
|
cGR.setGroupIdList(groupIdList);
|
||||||
|
return cGR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addKey(MaatRelation maatRelation, CompileAndGroupRelations compileAndGroupRelations) {
|
||||||
|
|
||||||
|
long compileId = compileAndGroupRelations.getCompileId();
|
||||||
|
List<GroupAndRegionRelations> groupIdList = compileAndGroupRelations.getGroupIdList();
|
||||||
|
if (groupIdList != null && groupIdList.size() > 0) {
|
||||||
|
for (GroupAndRegionRelations gRR : groupIdList) {
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap2 = maatRelation.getCompileAndGroupMap();
|
||||||
|
if (compileAndGroupMap2 != null && compileAndGroupMap2.size() > 0) {
|
||||||
|
if (!compileAndGroupMap2.containsKey(compileId)) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getGroupId());
|
||||||
|
compileAndGroupMap2.put(compileId, set);
|
||||||
|
} else {
|
||||||
|
compileAndGroupMap2.get(compileId).add(gRR.getGroupId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap2 = maatRelation.getGroupAndCompileMap();
|
||||||
|
if (groupAndCompileMap2 != null && groupAndCompileMap2.size() > 0) {
|
||||||
|
if (!groupAndCompileMap2.containsKey(gRR.getGroupId())) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(compileId);
|
||||||
|
groupAndCompileMap2.put(gRR.getGroupId(), set);
|
||||||
|
} else {
|
||||||
|
groupAndCompileMap2.get(gRR.getGroupId()).add(compileId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||||
|
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||||
|
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getRegionId());
|
||||||
|
groupAndRegionMap2.put(gRR.getGroupId(), set);
|
||||||
|
} else {
|
||||||
|
groupAndRegionMap2.get(gRR.getGroupId()).add(gRR.getRegionId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MaatRelation getMaat() {
|
public static MaatRelation getMaat() {
|
||||||
MaatRelation maatRelation = new MaatRelation();
|
MaatRelation maatRelation = new MaatRelation();
|
||||||
Map<Long, List<Long>> compileAndGroupMap = new HashMap<Long, List<Long>>();
|
Map<Long, Set<Long>> compileAndGroupMap = new HashMap<Long, Set<Long>>();
|
||||||
List<Long> list = new ArrayList<Long>();
|
Set<Long> list = new HashSet<Long>();
|
||||||
list.add(1l);
|
list.add(1l);
|
||||||
compileAndGroupMap.put(1l, list);
|
compileAndGroupMap.put(1l, list);
|
||||||
list = new ArrayList<Long>();
|
list = new HashSet<Long>();
|
||||||
list.add(1l);
|
list.add(1l);
|
||||||
compileAndGroupMap.put(2l, list);
|
compileAndGroupMap.put(2l, list);
|
||||||
Map<Long, List<Long>> groupAndCompileMap = new HashMap<Long, List<Long>>();
|
Map<Long, Set<Long>> groupAndCompileMap = new HashMap<Long, Set<Long>>();
|
||||||
list = new ArrayList<Long>();
|
list = new HashSet<Long>();
|
||||||
list.add(1l);
|
list.add(1l);
|
||||||
list.add(2l);
|
list.add(2l);
|
||||||
groupAndCompileMap.put(1l, list);
|
groupAndCompileMap.put(1l, list);
|
||||||
// Map<Long, List<Long>> regionAndGroupMap = new HashMap<Long, List<Long>>();
|
// Map<Long, List<Long>> regionAndGroupMap = new HashMap<Long, List<Long>>();
|
||||||
list = new ArrayList<Long>();
|
list = new HashSet<Long>();
|
||||||
list.add(1l);
|
list.add(1l);
|
||||||
// regionAndGroupMap.put(1l, list);
|
// regionAndGroupMap.put(1l, list);
|
||||||
Map<Long, List<Long>> groupAndRegionMap = new HashMap<Long, List<Long>>();
|
Map<Long, Set<Long>> groupAndRegionMap = new HashMap<Long, Set<Long>>();
|
||||||
groupAndRegionMap.put(1l, list);
|
groupAndRegionMap.put(1l, list);
|
||||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||||
|
|||||||
297
src/main/java/com/nis/listener/CompileGroupRegionRela.java
Normal file
297
src/main/java/com/nis/listener/CompileGroupRegionRela.java
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
package com.nis.listener;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
|
|
||||||
|
import com.nis.domain.restful.CompileAndGroupRelations;
|
||||||
|
import com.nis.domain.restful.GroupAndRegionRelations;
|
||||||
|
import com.nis.domain.restful.MaatRelation;
|
||||||
|
import com.nis.web.service.SpringContextHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目启动时加载数据字典
|
||||||
|
*
|
||||||
|
* @author RenKaiGe-Office
|
||||||
|
* @Date:2018-05-24
|
||||||
|
*/
|
||||||
|
public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CompileGroupRegionRela.class);
|
||||||
|
|
||||||
|
private static RedisTemplate<String, String> redisTemplate = null;
|
||||||
|
private static JedisConnectionFactory connectionFactory = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储redis所有库中,编译分组域等配置关系,key是redis库
|
||||||
|
*/
|
||||||
|
private static Map<Integer, MaatRelation> idRelationMap = new ConcurrentHashMap<Integer, MaatRelation>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent event) {
|
||||||
|
try {
|
||||||
|
redisTemplate = SpringContextHolder.getBean("redisTemplate");
|
||||||
|
connectionFactory = SpringContextHolder.getBean("connectionFactory");
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
connectionFactory.setDatabase(i);
|
||||||
|
redisTemplate.setConnectionFactory(connectionFactory);
|
||||||
|
getAllId(i);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getAllId(int redisDBIndex) {
|
||||||
|
Map<Long, Set<Long>> groupCompileIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Map<Long, Set<Long>> groupRegionIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Set<String> keySet = redisTemplate.keys("EFFECTIVE_RULE:*");
|
||||||
|
if (keySet != null && keySet.size() > 0) {
|
||||||
|
for (String keys : keySet) {
|
||||||
|
if (!keys.toLowerCase().contains("config_compile")) {
|
||||||
|
try {
|
||||||
|
String value = redisTemplate.opsForValue().get(keys).toString();
|
||||||
|
if (keys.toLowerCase().contains("config_group")) {
|
||||||
|
String[] split = value.split("\t");
|
||||||
|
String groupIdStr = split[0];
|
||||||
|
String compileIdStr = split[1];
|
||||||
|
if (groupCompileIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||||
|
groupCompileIdMap.get(Long.valueOf(groupIdStr)).add(Long.valueOf(compileIdStr));
|
||||||
|
} else {
|
||||||
|
Set<Long> list = new HashSet<Long>();
|
||||||
|
list.add(Long.valueOf(compileIdStr));
|
||||||
|
groupCompileIdMap.put(Long.valueOf(groupIdStr), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
String[] split = value.split("\t");
|
||||||
|
String regionIdStr = split[0];
|
||||||
|
String groupIdStr = split[1];
|
||||||
|
if (groupRegionIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||||
|
groupRegionIdMap.get(Long.valueOf(groupIdStr)).add(Long.valueOf(regionIdStr));
|
||||||
|
} else {
|
||||||
|
Set<Long> list = new HashSet<Long>();
|
||||||
|
list.add(Long.valueOf(regionIdStr));
|
||||||
|
groupRegionIdMap.put(Long.valueOf(groupIdStr), list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("从redis中查询" + keys + "数据失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Long groupId : groupCompileIdMap.keySet()) {
|
||||||
|
if (idRelationMap.containsKey(redisDBIndex)) {
|
||||||
|
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||||
|
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||||
|
for (Long compileId : compileIdList) {
|
||||||
|
if (compileAndGroupMap.containsKey(compileId)) {
|
||||||
|
compileAndGroupMap.get(compileId).add(groupId);
|
||||||
|
} else {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(groupId);
|
||||||
|
compileAndGroupMap.put(compileId, set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||||
|
if (groupAndCompileMap.containsKey(groupId)) {
|
||||||
|
groupAndCompileMap.get(groupId).addAll(compileIdList);
|
||||||
|
} else {
|
||||||
|
groupAndCompileMap.put(groupId, compileIdList);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||||
|
if (groupAndRegionMap.containsKey(groupId)) {
|
||||||
|
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||||
|
} else {
|
||||||
|
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
MaatRelation maatRelation = new MaatRelation();
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||||
|
for (Long compileId : compileIdList) {
|
||||||
|
if (compileAndGroupMap.containsKey(compileId)) {
|
||||||
|
compileAndGroupMap.get(compileId).add(groupId);
|
||||||
|
} else {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(groupId);
|
||||||
|
compileAndGroupMap.put(compileId, set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
groupAndCompileMap.put(groupId, compileIdList);
|
||||||
|
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||||
|
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||||
|
idRelationMap.put(redisDBIndex, maatRelation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从字典中删除编译id的关系
|
||||||
|
* @param redisDBIndex 哪个redis库
|
||||||
|
* @param compileId
|
||||||
|
*/
|
||||||
|
public static void delIdRelation(int redisDBIndex, long compileId) {
|
||||||
|
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||||
|
if (maatRelation != null) {
|
||||||
|
removKey(maatRelation, compileId);
|
||||||
|
} else {
|
||||||
|
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removKey(MaatRelation maatRelation, long compileId) {
|
||||||
|
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
||||||
|
Set<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
||||||
|
|
||||||
|
if (list != null && list.size() > 0) {
|
||||||
|
for (Long groupId : list) {
|
||||||
|
// }
|
||||||
|
// for (Long groupId: list.size()) {
|
||||||
|
if (maatRelation.getGroupAndCompileMap().containsKey(groupId)) {
|
||||||
|
// && maatRelation.getGroupAndCompileMap().get(groupId).size() == 1
|
||||||
|
// && maatRelation.getGroupAndCompileMap().get(groupId).get(0).longValue() ==
|
||||||
|
// compileId) {
|
||||||
|
Set<Long> compileIdList = maatRelation.getGroupAndCompileMap().get(groupId);
|
||||||
|
if (compileIdList.size() == 1) {// 当前的groupid只属于当前的compileid,没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
||||||
|
for (Long id : compileIdList) {
|
||||||
|
if (id.longValue() == compileId) {
|
||||||
|
// 这个group没有被分组复用,所以需要将这个组下面的域配置置为无效,组也要置为无效
|
||||||
|
if (maatRelation.getGroupAndRegionMap().containsKey(groupId)) {
|
||||||
|
// 把当前组置为无效,把当前组下的所有域置为无效
|
||||||
|
maatRelation.getGroupAndRegionMap().remove(groupId);// 删除组对应的域
|
||||||
|
maatRelation.getGroupAndCompileMap().remove(groupId);// 删除当前组所对应的编译
|
||||||
|
// maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId);
|
||||||
|
// maatRelation.getCompileAndGroupMap().get(compileId)
|
||||||
|
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||||
|
// 删除编译下面的组
|
||||||
|
list.remove(groupId);// 删除编译下面的组
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 这个组对应了多个编译配置被分组复用了,这时将这个组和编译的关系置为无效,编译置为无效
|
||||||
|
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||||
|
// 删除编译下面的这个组
|
||||||
|
// maatRelation.getGroupAndCompileMap().get(groupId)
|
||||||
|
// .remove(maatRelation.getGroupAndCompileMap().get(groupId).indexOf(compileId));//
|
||||||
|
// 删除分组关系中的组和编译关系
|
||||||
|
|
||||||
|
list.remove(groupId);// 删除编译下面的这个组
|
||||||
|
maatRelation.getGroupAndCompileMap().get(groupId).remove(compileId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 当前的groupid属于多个组,被分组复用了,所以不对这个组进行操作,也不对这个组下面的域进行操作
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加配置
|
||||||
|
* @param redisDBIndex 向哪个库添加配置
|
||||||
|
* @param compileAndGroupRelations id映射关系
|
||||||
|
*/
|
||||||
|
public static void addIdRelation(int redisDBIndex, CompileAndGroupRelations compileAndGroupRelations) {
|
||||||
|
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||||
|
if (maatRelation != null) {
|
||||||
|
addKey(maatRelation, compileAndGroupRelations);
|
||||||
|
} else {
|
||||||
|
maatRelation = new MaatRelation();
|
||||||
|
addKey(maatRelation, compileAndGroupRelations);
|
||||||
|
idRelationMap.put(redisDBIndex, maatRelation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addKey(MaatRelation maatRelation, CompileAndGroupRelations compileAndGroupRelations) {
|
||||||
|
long compileId = compileAndGroupRelations.getCompileId();
|
||||||
|
List<GroupAndRegionRelations> groupIdList = compileAndGroupRelations.getGroupIdList();
|
||||||
|
if (groupIdList != null && groupIdList.size() > 0) {
|
||||||
|
for (GroupAndRegionRelations gRR : groupIdList) {
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap2 = maatRelation.getCompileAndGroupMap();
|
||||||
|
if (compileAndGroupMap2 != null && compileAndGroupMap2.size() > 0) {
|
||||||
|
if (!compileAndGroupMap2.containsKey(compileId)) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getGroupId());
|
||||||
|
compileAndGroupMap2.put(compileId, set);
|
||||||
|
} else {
|
||||||
|
compileAndGroupMap2.get(compileId).add(gRR.getGroupId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getGroupId());
|
||||||
|
compileAndGroupMap.put(compileId, set);
|
||||||
|
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap2 = maatRelation.getGroupAndCompileMap();
|
||||||
|
if (groupAndCompileMap2 != null && groupAndCompileMap2.size() > 0) {
|
||||||
|
if (!groupAndCompileMap2.containsKey(gRR.getGroupId())) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(compileId);
|
||||||
|
groupAndCompileMap2.put(gRR.getGroupId(), set);
|
||||||
|
} else {
|
||||||
|
groupAndCompileMap2.get(gRR.getGroupId()).add(compileId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(compileId);
|
||||||
|
groupAndCompileMap.put(gRR.getGroupId(), set);
|
||||||
|
|
||||||
|
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||||
|
}
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||||
|
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||||
|
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getRegionId());
|
||||||
|
groupAndRegionMap2.put(gRR.getGroupId(), set);
|
||||||
|
} else {
|
||||||
|
groupAndRegionMap2.get(gRR.getGroupId()).add(gRR.getRegionId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||||
|
Set<Long> set = new HashSet<Long>();
|
||||||
|
set.add(gRR.getRegionId());
|
||||||
|
groupAndRegionMap.put(gRR.getGroupId(), set);
|
||||||
|
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Integer, MaatRelation> getIdRelationMap() {
|
||||||
|
return idRelationMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setIdRelationMap(Map<Integer, MaatRelation> idRelationMap) {
|
||||||
|
CompileGroupRegionRela.idRelationMap = idRelationMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -15,12 +16,14 @@ import net.sf.json.JSONObject;
|
|||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import com.nis.datasource.DynamicJedisDataBase;
|
||||||
import com.nis.domain.restful.ConfigCompile;
|
import com.nis.domain.restful.ConfigCompile;
|
||||||
import com.nis.domain.restful.ConfigSource;
|
import com.nis.domain.restful.ConfigSource;
|
||||||
import com.nis.domain.restful.FileDesc;
|
import com.nis.domain.restful.FileDesc;
|
||||||
@@ -37,6 +40,7 @@ import com.nis.web.service.ServicesRequestLogService;
|
|||||||
import com.nis.web.service.fdfs.FastDFSFile;
|
import com.nis.web.service.fdfs.FastDFSFile;
|
||||||
import com.nis.web.service.fdfs.FileManager;
|
import com.nis.web.service.fdfs.FileManager;
|
||||||
import com.nis.web.service.restful.ConfigRedisService;
|
import com.nis.web.service.restful.ConfigRedisService;
|
||||||
|
import com.nis.web.service.restful.ConfigRedisServiceimpl;
|
||||||
import com.nis.web.service.restful.ConfigSourcesService;
|
import com.nis.web.service.restful.ConfigSourcesService;
|
||||||
import com.wordnik.swagger.annotations.Api;
|
import com.wordnik.swagger.annotations.Api;
|
||||||
import com.wordnik.swagger.annotations.ApiOperation;
|
import com.wordnik.swagger.annotations.ApiOperation;
|
||||||
@@ -49,6 +53,7 @@ import com.wordnik.swagger.annotations.ApiParam;
|
|||||||
* @date 2016年9月5日 下午6:20:33
|
* @date 2016年9月5日 下午6:20:33
|
||||||
* @version V1.0
|
* @version V1.0
|
||||||
*/
|
*/
|
||||||
|
//@Scope("prototype")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("${servicePath}")
|
@RequestMapping("${servicePath}")
|
||||||
@Api(value = "ConfigSourcesController", description = "配置存储服务,包括管控、监测、白名单的控制类")
|
@Api(value = "ConfigSourcesController", description = "配置存储服务,包括管控、监测、白名单的控制类")
|
||||||
@@ -62,7 +67,7 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ConfigRedisService configRedisService;
|
ConfigRedisService configRedisService;
|
||||||
|
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.GET)
|
@RequestMapping(value = "/cfg/v1/save", method = RequestMethod.GET)
|
||||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||||
public String testRedis(Integer type) {
|
public String testRedis(Integer type) {
|
||||||
@@ -85,7 +90,6 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
configRedisService.saveUnMaatConfig(listMap, service);
|
configRedisService.saveUnMaatConfig(listMap, service);
|
||||||
} else {
|
} else {
|
||||||
Integer service = 100;
|
Integer service = 100;
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
long id = configRedisService.getIncrId("seq_compileid");
|
long id = configRedisService.getIncrId("seq_compileid");
|
||||||
// int id=2;
|
// int id=2;
|
||||||
@@ -105,7 +109,7 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/saveMaat", method = RequestMethod.GET)
|
@RequestMapping(value = "/cfg/v1/saveMaat", method = RequestMethod.GET)
|
||||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||||
public String saveMaat(Integer service) {
|
public String saveMaat(Integer service) {
|
||||||
@@ -200,7 +204,6 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
maatConfig.setIpRegionMapList(ipRegionMapList);
|
maatConfig.setIpRegionMapList(ipRegionMapList);
|
||||||
return maatConfig;
|
return maatConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
|
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
|
||||||
@ApiOperation(value = "业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
@ApiOperation(value = "业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||||
@ApiParam(value = "业务配置数据源", name = "configSource", required = true)
|
@ApiParam(value = "业务配置数据源", name = "configSource", required = true)
|
||||||
@@ -219,30 +222,7 @@ public class ConfigSourcesController extends BaseRestController {
|
|||||||
// 验证配置编译数据
|
// 验证配置编译数据
|
||||||
validateConfigSource(thread, start, configSource);
|
validateConfigSource(thread, start, configSource);
|
||||||
Long benginTime = System.currentTimeMillis();
|
Long benginTime = System.currentTimeMillis();
|
||||||
String msg = configSourcesService.saveByJDBCThread(thread, start, configSource.getConfigCompileList(), sb);
|
configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
|
||||||
if (msg.equals("error")) {
|
|
||||||
String errorCode = "";
|
|
||||||
Exception exception = ConfigSourcesService.getMsgList().get(0);
|
|
||||||
String str = exception.getMessage();
|
|
||||||
if (null != str && str.length() > 0) {
|
|
||||||
int index = str.toUpperCase().indexOf("ORA-");
|
|
||||||
if (index != -1) {
|
|
||||||
errorCode = str.substring(index + 4, index + 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil.throwExceptionInfo(errorCode);
|
|
||||||
for (int errorNum : throwExceptionInfo.keySet()) {
|
|
||||||
if (errorNum == 998) {
|
|
||||||
thread.setExceptionInfo(exception.toString());
|
|
||||||
} else {
|
|
||||||
thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
|
|
||||||
}
|
|
||||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
||||||
throwExceptionInfo.get(errorNum), errorNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// configSourcesService.insertConfigSourceData(thread, start,
|
|
||||||
// configSource.getConfigCompileList(), sb);
|
|
||||||
|
|
||||||
Long endSaveTime = System.currentTimeMillis();
|
Long endSaveTime = System.currentTimeMillis();
|
||||||
Long time = (endSaveTime - benginTime) / 1000;
|
Long time = (endSaveTime - benginTime) / 1000;
|
||||||
|
|||||||
@@ -584,9 +584,9 @@ public class ConfigTestController extends BaseRestController {
|
|||||||
configCompile.setContLabel("0");
|
configCompile.setContLabel("0");
|
||||||
configCompile.setTaskId(0);
|
configCompile.setTaskId(0);
|
||||||
configCompile.setGuaranteeId(0);
|
configCompile.setGuaranteeId(0);
|
||||||
configCompile.setAffAirId(0);
|
configCompile.setAffairId(0);
|
||||||
configCompile.setTopIcId(0);
|
configCompile.setTopicId(0);
|
||||||
configCompile.setDoBlackList(0l);
|
configCompile.setDoBlacklist(0l);
|
||||||
configCompile.setDoLog(0);
|
configCompile.setDoLog(0);
|
||||||
configCompile.setEffectiveRange("0");
|
configCompile.setEffectiveRange("0");
|
||||||
configCompile.setConfigPercent(100l);
|
configCompile.setConfigPercent(100l);
|
||||||
|
|||||||
@@ -243,9 +243,9 @@ public class SaveConfigTestController extends BaseRestController {
|
|||||||
configCompile.setContLabel("0");
|
configCompile.setContLabel("0");
|
||||||
configCompile.setTaskId(0);
|
configCompile.setTaskId(0);
|
||||||
configCompile.setGuaranteeId(0);
|
configCompile.setGuaranteeId(0);
|
||||||
configCompile.setAffAirId(0);
|
configCompile.setAffairId(0);
|
||||||
configCompile.setTopIcId(0);
|
configCompile.setTopicId(0);
|
||||||
configCompile.setDoBlackList(1l);
|
configCompile.setDoBlacklist(1l);
|
||||||
configCompile.setDoLog(0);
|
configCompile.setDoLog(0);
|
||||||
configCompile.setEffectiveRange("0");
|
configCompile.setEffectiveRange("0");
|
||||||
configCompile.setConfigPercent(100l);
|
configCompile.setConfigPercent(100l);
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
package com.nis.web.dao.impl;
|
package com.nis.web.dao.impl;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.nis.web.service.SpringContextHolder;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public abstract class BaseRedisDao<K, V> {
|
public abstract class BaseRedisDao<K, V> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RedisTemplate<K, V> redisTemplate;
|
protected RedisTemplate<K, V> redisTemplate;
|
||||||
|
|
||||||
// public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
|
// public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
|
||||||
// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||||
// redisTemplate.setKeySerializer(stringRedisSerializer);
|
// redisTemplate.setKeySerializer(stringRedisSerializer);
|
||||||
// redisTemplate.setValueSerializer(stringRedisSerializer);
|
// redisTemplate.setValueSerializer(stringRedisSerializer);
|
||||||
// this.redisTemplate = redisTemplate;
|
// this.redisTemplate = redisTemplate;
|
||||||
// }
|
// }
|
||||||
|
protected static void setRedisDataBase(int index, RedisTemplate redisTemplate) {
|
||||||
|
JedisConnectionFactory connectionFactory = SpringContextHolder.getBean("connectionFactory" + index);
|
||||||
|
//connectionFactory.setDatabase(index);
|
||||||
|
redisTemplate.setConnectionFactory(connectionFactory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import com.nis.domain.restful.MaatConfig;
|
|||||||
public interface ConfigRedisService {
|
public interface ConfigRedisService {
|
||||||
/**
|
/**
|
||||||
* 保存非maat配置接口,例如ysp文件样例,ysp标志样例
|
* 保存非maat配置接口,例如ysp文件样例,ysp标志样例
|
||||||
* @param listMap
|
* @param listMap 配置集合,一个map是一个集合
|
||||||
* @param service 业务类型
|
* @param service 业务类型
|
||||||
*/
|
*/
|
||||||
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service);
|
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service);
|
||||||
@@ -35,4 +35,18 @@ public interface ConfigRedisService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long getIncrId(String key);
|
public Long getIncrId(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除非maat类配置
|
||||||
|
* @param compileIdList 配置id集合
|
||||||
|
* @param service 配置id所属的业务类型
|
||||||
|
*/
|
||||||
|
public void delUnMaatConfig(List<Long> compileIdList, int service);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除maat类配置
|
||||||
|
* @param compileIdList 配置id集合
|
||||||
|
* @param service 配置id所属的业务类型
|
||||||
|
*/
|
||||||
|
public void delMaatConfig(List<Long> compileIdList, int service);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,28 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.nis.datasource.DynamicJedisDataBase;
|
|
||||||
import com.nis.domain.MaatXmlConfig;
|
import com.nis.domain.MaatXmlConfig;
|
||||||
import com.nis.domain.MaatXmlExpr;
|
import com.nis.domain.MaatXmlExpr;
|
||||||
import com.nis.domain.MaatXmlSeq;
|
import com.nis.domain.MaatXmlSeq;
|
||||||
import com.nis.domain.restful.MaatConfig;
|
import com.nis.domain.restful.MaatConfig;
|
||||||
|
import com.nis.domain.restful.MaatRelation;
|
||||||
|
import com.nis.listener.CompileGroupRegionRela;
|
||||||
import com.nis.util.Configurations;
|
import com.nis.util.Configurations;
|
||||||
import com.nis.util.ReadMaatXmlUtil;
|
import com.nis.util.ReadMaatXmlUtil;
|
||||||
import com.nis.web.dao.impl.BaseRedisDao;
|
import com.nis.web.dao.impl.BaseRedisDao;
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> implements ConfigRedisService {
|
public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> implements ConfigRedisService {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ConfigRedisServiceimpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
||||||
*/
|
*/
|
||||||
@@ -62,14 +67,26 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
public void saveUnMaatConfig2(List<Map<String, String>> listMap, int service) {
|
||||||
private OperRedisService operRedisService;
|
System.out.println(redisTemplate.getConnectionFactory());
|
||||||
|
setRedisDataBase(2, redisTemplate);
|
||||||
|
System.out.println(redisTemplate.getConnectionFactory());
|
||||||
|
String maatVersion = redisTemplate.opsForValue().get("MAAT_VERSION");
|
||||||
|
System.out.println("maatVersion:" + maatVersion);
|
||||||
|
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service) {
|
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service) {
|
||||||
if (listMap != null && listMap.size() > 0) {
|
if (listMap != null && listMap.size() > 0) {
|
||||||
DynamicJedisDataBase.setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
||||||
String maatVersionStr = operRedisService.getMaatVersion(getRedisDBByService(service));
|
// String maatVersionStr =
|
||||||
|
// operRedisService.getMaatVersion(getRedisDBByService(service));
|
||||||
|
String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION");
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
if (maatVersionStr != null) {
|
if (maatVersionStr != null) {
|
||||||
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||||
for (Map<String, String> map : listMap) {
|
for (Map<String, String> map : listMap) {
|
||||||
@@ -80,7 +97,7 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
String maatKey = "";
|
String maatKey = "";
|
||||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
if (16 == maatXmlExpr.getType().intValue()) {
|
if (0 == maatXmlExpr.getType().intValue()) {
|
||||||
StringBuffer keyBF = new StringBuffer();
|
StringBuffer keyBF = new StringBuffer();
|
||||||
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||||
for (String keyStr : keySplit) {
|
for (String keyStr : keySplit) {
|
||||||
@@ -130,7 +147,7 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
}
|
}
|
||||||
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||||
for (MaatXmlSeq maatXmlSeq : seqList) {
|
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||||
// DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(),
|
// setRedisDataBase(maatXmlSeq.getRedisDB(),
|
||||||
// redisTemplate);
|
// redisTemplate);
|
||||||
String seqKey = maatXmlSeq.getSequenceKey();
|
String seqKey = maatXmlSeq.getSequenceKey();
|
||||||
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
||||||
@@ -143,14 +160,15 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
|
||||||
}
|
}
|
||||||
|
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
setRedisDataBase(2, redisTemplate);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
if (i == 5) {
|
if (i == 5) {
|
||||||
@@ -158,14 +176,14 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 切换redis数据库
|
// 切换redis数据库
|
||||||
DynamicJedisDataBase.setRedisDataBase(3, redisTemplate);
|
setRedisDataBase(3, redisTemplate);
|
||||||
for (int i = 10; i < 20; i++) {
|
for (int i = 10; i < 20; i++) {
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
if (i == 5) {
|
if (i == 5) {
|
||||||
// int a = 1 / 0;
|
// int a = 1 / 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DynamicJedisDataBase.setRedisDataBase(4, redisTemplate);
|
setRedisDataBase(4, redisTemplate);
|
||||||
for (int i = 20; i < 30; i++) {
|
for (int i = 20; i < 30; i++) {
|
||||||
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
redisTemplate.boundZSetOps("1").add("a" + i, i);
|
||||||
if (i == 25) {
|
if (i == 25) {
|
||||||
@@ -177,28 +195,36 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void saveMaatConfig(List<MaatConfig> maatConfigList, int service) {
|
public void saveMaatConfig(List<MaatConfig> maatConfigList, int service) {
|
||||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||||
String maatVersionStr = operRedisService.getMaatVersion(getRedisDBByService(service));
|
Integer redisDBIndex = getRedisDBByService(service);
|
||||||
|
setRedisDataBase(redisDBIndex, redisTemplate);
|
||||||
|
String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION");
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
MaatRelation maatRelation = CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||||
if (maatVersionStr != null) {
|
if (maatVersionStr != null) {
|
||||||
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||||
for (MaatConfig maatConfig : maatConfigList) {
|
for (MaatConfig maatConfig : maatConfigList) {
|
||||||
// Integer service = maatConfig.getService();
|
|
||||||
// if (service != null) {
|
|
||||||
DynamicJedisDataBase.setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
|
||||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||||
setConfig(maatConfig, maatXmlConfig, maatVersion, service);
|
setConfig(maatConfig, maatXmlConfig, maatVersion, service,maatRelation);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfig(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Long maatVersion, int service) {
|
public void setConfig(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Long maatVersion, int service, MaatRelation maatRelation ) {
|
||||||
Map<String, String> compileMap = maatConfig.getCompileMap();
|
Map<String, String> compileMap = maatConfig.getCompileMap();
|
||||||
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service);// 10代表是编译配置
|
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service);// 10代表是编译配置
|
||||||
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
|
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
|
||||||
if (groupMapList != null && groupMapList.size() > 0) {
|
if (groupMapList != null && groupMapList.size() > 0) {
|
||||||
for (Map<String, String> map : groupMapList) {
|
for (Map<String, String> map : groupMapList) {
|
||||||
|
map.get("");
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setCommonConfig(maatXmlConfig, map, 11, maatVersion.doubleValue(), service);// 11代表是分组配置
|
setCommonConfig(maatXmlConfig, map, 11, maatVersion.doubleValue(), service);// 11代表是分组配置
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +264,7 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
setCommonConfig(maatXmlConfig, map, 17, maatVersion.doubleValue(), service);// 17代表是文本相似性域配置
|
setCommonConfig(maatXmlConfig, map, 17, maatVersion.doubleValue(), service);// 17代表是文本相似性域配置
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateCommonKey(maatXmlConfig);
|
// updateCommonKey(maatXmlConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCommonConfig(MaatXmlConfig maatXmlConfig, Map<String, String> map, int type, Double maatVersion,
|
public void setCommonConfig(MaatXmlConfig maatXmlConfig, Map<String, String> map, int type, Double maatVersion,
|
||||||
@@ -308,8 +334,6 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
public void updateCommonKey(MaatXmlConfig maatXmlConfig) {
|
public void updateCommonKey(MaatXmlConfig maatXmlConfig) {
|
||||||
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||||
for (MaatXmlSeq maatXmlSeq : seqList) {
|
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||||
// DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(),
|
|
||||||
// redisTemplate);
|
|
||||||
String seqKey = maatXmlSeq.getSequenceKey();
|
String seqKey = maatXmlSeq.getSequenceKey();
|
||||||
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
||||||
Integer operation = maatXmlSeq.getOperation();
|
Integer operation = maatXmlSeq.getOperation();
|
||||||
@@ -321,7 +345,10 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Long getIncrId(String key) {
|
public Long getIncrId(String key) {
|
||||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
//
|
||||||
|
// connectionFactory.setDatabase(0);
|
||||||
|
// redisTemplate.setConnectionFactory(connectionFactory);
|
||||||
|
|
||||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||||
// redisTemplate.getConnectionFactory());
|
// redisTemplate.getConnectionFactory());
|
||||||
//
|
//
|
||||||
@@ -330,6 +357,8 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
||||||
// }
|
// }
|
||||||
// return id;
|
// return id;
|
||||||
|
setRedisDataBase(0, redisTemplate);
|
||||||
|
// System.out.println(redisTemplate.getConnectionFactory());
|
||||||
return redisTemplate.boundValueOps(key.toUpperCase()).increment(1l);
|
return redisTemplate.boundValueOps(key.toUpperCase()).increment(1l);
|
||||||
// return redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
// return redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||||
}
|
}
|
||||||
@@ -367,4 +396,116 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
|||||||
getRedisDBByService(80);
|
getRedisDBByService(80);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delUnMaatConfig(List<Long> compileIdList, int service) {
|
||||||
|
if (compileIdList != null && compileIdList.size() > 0) {
|
||||||
|
Integer redisDBIndex = getRedisDBByService(service);
|
||||||
|
setRedisDataBase(redisDBIndex, redisTemplate);
|
||||||
|
String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION");
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
|
if (maatVersionStr != null) {
|
||||||
|
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||||
|
for (Long id : compileIdList) {
|
||||||
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||||
|
if (maatXmlConfig != null) {
|
||||||
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
|
String maatKey = "";
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
if (0 == maatXmlExpr.getType().intValue()) {
|
||||||
|
StringBuffer keyBF = new StringBuffer();
|
||||||
|
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||||
|
for (String keyStr : keySplit) {
|
||||||
|
if (!StringUtils.isEmpty(keyStr) && keyStr.toUpperCase().equals("EFFECTIVE_RULE")) {
|
||||||
|
keyStr = "OBSOLETE_RULE";
|
||||||
|
keyBF.append(keyStr.trim());
|
||||||
|
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||||
|
// keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||||
|
keyBF.append(id);
|
||||||
|
} else {
|
||||||
|
keyBF.append(keyStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maatKey = keyBF.toString();
|
||||||
|
String oldKey = maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||||
|
redisTemplate.rename(oldKey.toString().toUpperCase(), keyBF.toString().toUpperCase());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// redisTemplate.boundValueOps(keyBF.toString().toUpperCase()).set(valBF.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||||
|
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||||
|
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
|
||||||
|
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
|
||||||
|
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||||
|
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(maatKey, score);
|
||||||
|
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_VERSION_TIMER")) {
|
||||||
|
Long nowTime = new Date().getTime();
|
||||||
|
nowTime = nowTime / 1000l;
|
||||||
|
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||||
|
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "", score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||||
|
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||||
|
// setRedisDataBase(maatXmlSeq.getRedisDB(),
|
||||||
|
// redisTemplate);
|
||||||
|
String seqKey = maatXmlSeq.getSequenceKey();
|
||||||
|
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
||||||
|
Integer operation = maatXmlSeq.getOperation();
|
||||||
|
if (operation == 1) {
|
||||||
|
redisTemplate.boundValueOps(seqKey.toUpperCase()).increment(1l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
||||||
|
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
public void delMaatConfig(List<Long> compileIdList, int service) {
|
||||||
|
if (compileIdList != null && compileIdList.size() > 0) {
|
||||||
|
Integer redisDBIndex = getRedisDBByService(service);
|
||||||
|
setRedisDataBase(redisDBIndex, redisTemplate);
|
||||||
|
MaatRelation maatRelation = CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||||
|
|
||||||
|
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||||
|
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||||
|
Map<Long, Set<Long>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||||
|
// String maatVersionStr =
|
||||||
|
// operRedisService.getMaatVersion(getRedisDBByService(service));
|
||||||
|
// if (maatVersionStr != null) {
|
||||||
|
// Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||||
|
// for (MaatConfig maatConfig : maatConfigList) {
|
||||||
|
// // Integer service = maatConfig.getService();
|
||||||
|
// // if (service != null) {
|
||||||
|
// setRedisDataBase(getRedisDBByService(service),
|
||||||
|
// redisTemplate);
|
||||||
|
// MaatXmlConfig maatXmlConfig =
|
||||||
|
// ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||||
|
// setConfig(maatConfig, maatXmlConfig, maatVersion, service);
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
// redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import com.nis.web.dao.impl.BaseRedisDao;
|
|||||||
@Service()
|
@Service()
|
||||||
public class OperRedisService extends BaseRedisDao<String, String> {
|
public class OperRedisService extends BaseRedisDao<String, String> {
|
||||||
|
|
||||||
public String getMaatVersion(int redisIndex) {
|
public String getMaatVersion1(int redisIndex) {
|
||||||
DynamicJedisDataBase.setRedisDataBase(redisIndex, redisTemplate);
|
//DynamicJedisDataBase.setRedisDataBase(redisIndex, redisTemplate);
|
||||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||||
// redisTemplate.getConnectionFactory());
|
// redisTemplate.getConnectionFactory());
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -25,17 +25,38 @@
|
|||||||
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
||||||
</bean>
|
</bean>
|
||||||
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
|
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
|
||||||
<bean id="connectionFactory"
|
<bean id="connectionFactory0"
|
||||||
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||||
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||||
p:database="0" scope="prototype"/>
|
p:database="0" />
|
||||||
<!-- p:password="" scope="prototype"-->
|
|
||||||
|
|
||||||
|
<!-- p:password="" scope="prototype" -->
|
||||||
|
<bean id="connectionFactory1"
|
||||||
|
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||||
|
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||||
|
p:database="1" />
|
||||||
|
|
||||||
|
<bean id="connectionFactory2"
|
||||||
|
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||||
|
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||||
|
p:database="2" />
|
||||||
|
|
||||||
|
<!-- p:password="" scope="prototype" -->
|
||||||
|
<bean id="connectionFactory3"
|
||||||
|
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||||
|
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||||
|
p:database="3" />
|
||||||
|
|
||||||
|
<bean id="connectionFactory4"
|
||||||
|
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||||
|
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||||
|
p:database="4" />
|
||||||
|
|
||||||
<bean id="stringRedisSerializer"
|
<bean id="stringRedisSerializer"
|
||||||
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
||||||
|
|
||||||
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
|
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
|
||||||
<property name="connectionFactory" ref="connectionFactory" />
|
<property name="connectionFactory" ref="connectionFactory0" />
|
||||||
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
|
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
|
||||||
<property name="keySerializer" ref="stringRedisSerializer" />
|
<property name="keySerializer" ref="stringRedisSerializer" />
|
||||||
<property name="valueSerializer" ref="stringRedisSerializer" />
|
<property name="valueSerializer" ref="stringRedisSerializer" />
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ jdbc.product.driver=oracle.jdbc.driver.OracleDriver
|
|||||||
#jdbc.product.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.17)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVICE_NAME = ORCL)(FAILOVER_MODE =(TYPE = select)(METHOD = basic)(RETRIES = 180)(DELAY = 180))))
|
#jdbc.product.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.17)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVICE_NAME = ORCL)(FAILOVER_MODE =(TYPE = select)(METHOD = basic)(RETRIES = 180)(DELAY = 180))))
|
||||||
#jdbc.product.url=jdbc:oracle:thin:@10.0.6.212:1523:app
|
#jdbc.product.url=jdbc:oracle:thin:@10.0.6.212:1523:app
|
||||||
jdbc.product.url=jdbc:oracle:thin:@10.0.6.165:1521:orcl
|
jdbc.product.url=jdbc:oracle:thin:@10.0.6.165:1521:orcl
|
||||||
|
#jdbc.product.url=jdbc:oracle:thin:@10.0.6.104:1521:orcl
|
||||||
#jdbc.product.url=jdbc:oracle:thin:@10.174.196.20:1521:orcl
|
#jdbc.product.url=jdbc:oracle:thin:@10.174.196.20:1521:orcl
|
||||||
jdbc.product.username=kaz_maat
|
jdbc.product.username=kaz_maat
|
||||||
|
#jdbc.product.username=zdx
|
||||||
#jdbc.product.username=dfxj_2015
|
#jdbc.product.username=dfxj_2015
|
||||||
#jdbc.product.username=gk_pz
|
#jdbc.product.username=gk_pz
|
||||||
#jdbc.product.username=z2_5x9pz
|
#jdbc.product.username=z2_5x9pz
|
||||||
@@ -126,11 +128,11 @@ jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ==
|
|||||||
#####################################################################################################################################
|
#####################################################################################################################################
|
||||||
##redis连接
|
##redis连接
|
||||||
#####################################################################################################################################
|
#####################################################################################################################################
|
||||||
redis.host=10.0.6.228
|
#redis.host=10.0.6.228
|
||||||
#redis.host=10.0.6.32
|
redis.host=10.0.6.249
|
||||||
redis.port=6379
|
redis.port=6379
|
||||||
redis.pass=
|
redis.pass=
|
||||||
redis.maxIdle=10
|
redis.maxIdle=100
|
||||||
redis.maxTotal=15
|
redis.maxTotal=150
|
||||||
redis.maxWaitMillis=1000
|
redis.maxWaitMillis=1000
|
||||||
redis.testOnBorrow=true
|
redis.testOnBorrow=true
|
||||||
|
|||||||
@@ -160,4 +160,16 @@
|
|||||||
<taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
|
<taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
|
||||||
</taglib>
|
</taglib>
|
||||||
</jsp-config>
|
</jsp-config>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 项目启动时加载编译id,组id,域id之间的关系 -->
|
||||||
|
<!-- <listener> -->
|
||||||
|
<!-- <listener-class> -->
|
||||||
|
<!-- com.nis.listener.SystemConfigListener -->
|
||||||
|
<!-- </listener-class> -->
|
||||||
|
<!-- </listener> -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
Reference in New Issue
Block a user