1:添加单独修改公共组域配置接口
2:添加单独删除公共组域配置接口
This commit is contained in:
@@ -1803,6 +1803,99 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCommonGroupRegion(List<Map<String, String>> regionMapList, MaatXmlExpr maatXmlExpr,
|
||||
Transaction transaction, int type, int idRelaRedisDBIndex, List<MaatXmlExpr> expressionList)
|
||||
throws Exception {
|
||||
Map<Integer, Double> dbVersionMap = new HashMap<>();// 记录所有redisdb的maatversion,避免每次查询影响性能
|
||||
if (regionMapList != null && regionMapList.size() > 0) {
|
||||
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
String maatKey = null;
|
||||
StringBuffer keyBF = new StringBuffer();
|
||||
for (String keyStr : keySplit) {
|
||||
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||
String keyVal = map.get(keyStr);
|
||||
if (keyVal != null && !keyVal.equals("")) {
|
||||
keyBF.append(keyVal);
|
||||
} else {
|
||||
throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确",
|
||||
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||
}
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String argTableName = map.get("table_name");
|
||||
if (argTableName == null) {
|
||||
throw new ServiceRuntimeException("添加公共组域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||
RestBusinessCode.NotFoundTableName.getValue());
|
||||
} else {
|
||||
keyBF.append(argTableName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String groupId = null;
|
||||
StringBuffer valBF = new StringBuffer();
|
||||
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||
for (String valStr : valSplit) {
|
||||
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||
if (valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||
String user_region = map.get("user_region");
|
||||
valBF.append(user_region + "\t");
|
||||
}
|
||||
String val = map.get(valStr);
|
||||
if (val != null) {
|
||||
valBF.append(val);
|
||||
if (valStr.equals("group_id")) {
|
||||
groupId = val;
|
||||
}
|
||||
} else {
|
||||
// 所有在maat.xml中配置的属性都不可以为空
|
||||
throw new ServiceRuntimeException("未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确",
|
||||
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||
}
|
||||
} else if (valStr.equals(" ")) {
|
||||
valBF.append(" ");
|
||||
} else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
|
||||
valBF.append("\t");
|
||||
} else if (valStr.equals("\\n")) {
|
||||
valBF.append("\n");
|
||||
} else {
|
||||
valBF.append(valStr.trim());
|
||||
}
|
||||
}
|
||||
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
// 将域配置下发到每个db中,并更新MAAT_UPDATE_STATUS等信息
|
||||
int everyDb = Integer.parseInt(db);
|
||||
transaction.select(everyDb);
|
||||
maatKey = keyBF.toString();
|
||||
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", everyDb, maatKey.toUpperCase(),
|
||||
valBF.toString());
|
||||
|
||||
Double maatVersion = null;
|
||||
if (!dbVersionMap.containsKey(everyDb)) {
|
||||
String maatVersionStr = JedisUtils.get("MAAT_VERSION", everyDb);
|
||||
if (maatVersionStr == null) {
|
||||
maatVersionStr = "0";
|
||||
}
|
||||
maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||
dbVersionMap.put(everyDb, maatVersion);
|
||||
} else {
|
||||
maatVersion = dbVersionMap.get(everyDb);
|
||||
}
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, everyDb, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGroupRegion(List<MaatConfig> configList, boolean isAdd) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
@@ -1866,6 +1959,70 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGroupRegion(List<MaatConfig> configList) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
Transaction transaction = resource.multi();
|
||||
try {
|
||||
if (configList != null && configList.size() > 0) {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||
MaatXmlExpr maatXmlExpr12 = null;
|
||||
MaatXmlExpr maatXmlExpr13 = null;
|
||||
MaatXmlExpr maatXmlExpr14 = null;
|
||||
if (maatXmlConfig != null) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
if (expressionList != null && expressionList.size() > 0) {
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getType().intValue() == 12) {
|
||||
maatXmlExpr12 = maatXmlExpr;
|
||||
} else if (maatXmlExpr.getType().intValue() == 13) {
|
||||
maatXmlExpr13 = maatXmlExpr;
|
||||
} else if (maatXmlExpr.getType().intValue() == 14) {
|
||||
maatXmlExpr14 = maatXmlExpr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MaatConfig maatConfig : configList) {
|
||||
|
||||
updateCommonGroupRegion(maatConfig.getIpRegionMapList(), maatXmlExpr12, transaction, 12,
|
||||
idRelaRedisDBIndex, expressionList);
|
||||
updateCommonGroupRegion(maatConfig.getNumRegionMapList(), maatXmlExpr13, transaction, 13,
|
||||
idRelaRedisDBIndex, expressionList);
|
||||
updateCommonGroupRegion(maatConfig.getStrRegionMapList(), maatXmlExpr14, transaction, 14,
|
||||
idRelaRedisDBIndex, expressionList);
|
||||
}
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
transaction.select(Integer.parseInt(db));
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db));
|
||||
// logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb, maatVersion);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("添加公共组域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
transaction.exec();
|
||||
return true;
|
||||
} catch (JedisConnectionException e) {
|
||||
String error = "连接redis异常,保存公共组maat类域配置失败" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||
} catch (Exception e) {
|
||||
|
||||
String error = "保存公共组maat类域配置发生了异常" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
transaction.discard();
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||
} finally {
|
||||
// 释放连接到连接池
|
||||
JedisUtils.returnResource(resource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加分组和域的关联关系
|
||||
*
|
||||
@@ -2131,6 +2288,85 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delCommonGroupRegion(Map<Long, Set<Long>> groupIdAndregionIdMap) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
Transaction transaction = resource.multi();
|
||||
try {
|
||||
if (groupIdAndregionIdMap != null && groupIdAndregionIdMap.size() > 0) {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
transaction.select(idRelaRedisDBIndex);
|
||||
//获取需要删除的regionkey
|
||||
Set<String> set = new HashSet<>();
|
||||
Set<Long> groupIdSet = groupIdAndregionIdMap.keySet();
|
||||
for (Long groupId : groupIdSet) {
|
||||
Set<Long> regionSet = groupIdAndregionIdMap.get(groupId);
|
||||
String commonGroup = "COMMONGROUPREGION:" + groupId;
|
||||
String regionKey = JedisUtils.get(commonGroup, idRelaRedisDBIndex);
|
||||
if (regionKey == null || regionKey.trim().equals("")) {
|
||||
throw new ServiceRuntimeException("无法删除公共组下的域,公共组" + groupId + ",不存在,请检查数据是否正确",
|
||||
RestBusinessCode.CommonGroupIsNotExist.getValue());
|
||||
}
|
||||
String[] keyAndDBArr = org.apache.commons.lang.StringUtils.split(regionKey, ";");
|
||||
for (String keyAndDB : keyAndDBArr) {
|
||||
String key = keyAndDB.substring(0, keyAndDB.indexOf("-"));
|
||||
String regionId = key.substring(keyAndDB.indexOf(",")+1);
|
||||
if(regionId!=null&&!regionId.trim().equals("")) {
|
||||
if(regionSet.contains(Long.parseLong(regionId))) {
|
||||
set.add(key);
|
||||
}
|
||||
}else {
|
||||
throw new ServiceRuntimeException("获取公共组下面域配置的id,域配置的key为" + key + ",请检查数据是否正确",
|
||||
RestBusinessCode.CommonGroupIsNotExist.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
int everyDb = Integer.parseInt(db);
|
||||
|
||||
Double maatVersion = null;
|
||||
String maatVersionStr = JedisUtils.get("MAAT_VERSION", everyDb);
|
||||
if (maatVersionStr == null) {
|
||||
maatVersionStr = "0";
|
||||
}
|
||||
maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||
transaction.select(everyDb);
|
||||
for (String regionKey : set) {
|
||||
String obsKey = regionKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
transaction.rename(regionKey, obsKey);
|
||||
updateMaatInfo(expressionList, obsKey, transaction, maatVersion, everyDb, true);
|
||||
}
|
||||
}
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
transaction.select(Integer.parseInt(db));
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db));
|
||||
}
|
||||
transaction.exec();
|
||||
return true;
|
||||
} else {
|
||||
throw new ServiceRuntimeException("删除公共组中域配置时,参数为空,请检查", RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
|
||||
}
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
String error = "连接redis异常,删除公共组maat类域配置失败" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||
} catch (Exception e) {
|
||||
String error = "删除公共组maat类域配置发生了异常" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
transaction.discard();
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||
} finally {
|
||||
// 释放连接到连接池
|
||||
JedisUtils.returnResource(resource);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMaatInfo(List<MaatXmlExpr> list, String maatKey, Transaction transaction, Double maatVersion,
|
||||
int redisDBIndex, Boolean idDel) {
|
||||
if (list != null && list.size() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user