在数据入库前校验service是否需要向阀门中额外添加属性,如果额外添加了属性,则验证service对应的redisdb中是否包含阀门,如果不包含给予错误提示
This commit is contained in:
@@ -592,6 +592,12 @@ public enum RestBusinessCode {
|
||||
*/
|
||||
RegionIsNotExist(5002010,"删除分组复用域配置时,无法在关联关系中找到对应的域配置信息,之前该域没有添加过,或者关联关系被损坏请检查"),
|
||||
|
||||
|
||||
/**
|
||||
*配置文件内容有误
|
||||
*/
|
||||
PropertiesIsError(5002011,"配置文件内容有误"),
|
||||
|
||||
/**
|
||||
* 无法从Map中获取配置的属性值
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ServiceAndRDBIndexReal {
|
||||
* 记录哪些service可以被分组复用(只有maat类配置可以被分组复用)
|
||||
* Map<Service,Map<regionName,List<tableName>>
|
||||
*/
|
||||
private static Map<Integer,Map<String, List<String>>> serviceGroupReuseMap = new HashMap<Integer, Map<String,List<String>>>();
|
||||
private static Map<Integer, Map<String, List<String>>> serviceGroupReuseMap = new HashMap<Integer, Map<String, List<String>>>();
|
||||
|
||||
/**
|
||||
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
||||
@@ -66,26 +66,23 @@ public class ServiceAndRDBIndexReal {
|
||||
if (unMaatService != null && !unMaatService.trim().equals("")) {
|
||||
String[] split = unMaatService.split(";");
|
||||
for (String str : split) {
|
||||
String[] serviceAction = str.split(":");
|
||||
if (serviceAction.length==2) {
|
||||
serviceActionMap.put(Integer.valueOf(serviceAction[0]),
|
||||
Integer.valueOf(serviceAction[1]));
|
||||
}else{
|
||||
serviceActionMap.put(Integer.valueOf(serviceAction[0]),
|
||||
null);
|
||||
}
|
||||
String serviceType = Configurations.getStringProperty(serviceAction[0], "");
|
||||
if (serviceType != null && !serviceType.trim().equals("")) {
|
||||
String[] typeArrs = serviceType.split(";");
|
||||
for (String typeStr : typeArrs) {
|
||||
String[] typeArr = typeStr.split(":");
|
||||
String tableNameArr[] = typeArr[1].split(",");
|
||||
for (String tableName : tableNameArr) {
|
||||
unMaatSercieNameMap.put(Integer.parseInt(serviceAction[0]),
|
||||
tableName.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] serviceAction = str.split(":");
|
||||
if (serviceAction.length == 2) {
|
||||
serviceActionMap.put(Integer.valueOf(serviceAction[0]), Integer.valueOf(serviceAction[1]));
|
||||
} else {
|
||||
serviceActionMap.put(Integer.valueOf(serviceAction[0]), null);
|
||||
}
|
||||
String serviceType = Configurations.getStringProperty(serviceAction[0], "");
|
||||
if (serviceType != null && !serviceType.trim().equals("")) {
|
||||
String[] typeArrs = serviceType.split(";");
|
||||
for (String typeStr : typeArrs) {
|
||||
String[] typeArr = typeStr.split(":");
|
||||
String tableNameArr[] = typeArr[1].split(",");
|
||||
for (String tableName : tableNameArr) {
|
||||
unMaatSercieNameMap.put(Integer.parseInt(serviceAction[0]), tableName.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,17 +158,17 @@ public class ServiceAndRDBIndexReal {
|
||||
if (!StringUtil.isEmpty(serviceRepeatedReal)) {
|
||||
String[] serviceRepeatedRealArr = serviceRepeatedReal.split(";");
|
||||
for (String serviceRepeated : serviceRepeatedRealArr) {
|
||||
String [] serInfos = serviceRepeated.split(":");
|
||||
String [] regionInfos = serInfos[1].split("[|]");
|
||||
String[] serInfos = serviceRepeated.split(":");
|
||||
String[] regionInfos = serInfos[1].split("[|]");
|
||||
for (String regionInfo : regionInfos) {
|
||||
String [] regionTabName = regionInfo.split("@");
|
||||
String [] tableNames = regionTabName[1].split(",");
|
||||
String[] regionTabName = regionInfo.split("@");
|
||||
String[] tableNames = regionTabName[1].split(",");
|
||||
for (String tableName : tableNames) {
|
||||
Integer ser = Integer.valueOf(serInfos[0]);
|
||||
if(serviceGroupReuseMap.containsKey(ser)){
|
||||
if (serviceGroupReuseMap.containsKey(ser)) {
|
||||
serviceGroupReuseMap.get(ser).get(regionTabName[0]).add(tableName);
|
||||
}else{
|
||||
Map<String,List<String>> regTabMap = new HashMap<String, List<String>>();
|
||||
} else {
|
||||
Map<String, List<String>> regTabMap = new HashMap<String, List<String>>();
|
||||
List<String> tabList = new ArrayList<String>();
|
||||
tabList.add(tableName);
|
||||
regTabMap.put(regionTabName[0], tabList);
|
||||
@@ -183,8 +180,6 @@ public class ServiceAndRDBIndexReal {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// getUnMaatTable();
|
||||
getMaatTable();
|
||||
@@ -326,7 +321,7 @@ public class ServiceAndRDBIndexReal {
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断service是否被分组复用
|
||||
* @param service
|
||||
@@ -336,10 +331,25 @@ public class ServiceAndRDBIndexReal {
|
||||
if (service != null) {
|
||||
return serviceGroupReuseMap.containsKey(service);
|
||||
} else {
|
||||
throw new ServiceRuntimeException("判断service是否是分组复用时发生了异常,异常原因:service=null", RestBusinessCode.ServiceIsNull.getValue());
|
||||
throw new ServiceRuntimeException("判断service是否是分组复用时发生了异常,异常原因:service=null",
|
||||
RestBusinessCode.ServiceIsNull.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前service是否是向阀门添加action,service或者userregion等属性
|
||||
* @param service
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAddASU(int service) {
|
||||
boolean isValve = false;
|
||||
Map<String, String[]> map2 = maatToValveMap.get(service);
|
||||
if (map2 != null && map2.size() > 0) {
|
||||
isValve = true;
|
||||
}
|
||||
return isValve;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型获取unmaat配置表名
|
||||
* @param service
|
||||
@@ -401,6 +411,7 @@ public class ServiceAndRDBIndexReal {
|
||||
public static void setUnMaatSercieNameMap(Map<Integer, String> unMaatSercieNameMap) {
|
||||
ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serviceGroupReuseMap
|
||||
*/
|
||||
@@ -416,7 +427,7 @@ public class ServiceAndRDBIndexReal {
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.addAll(map.get(regionName));
|
||||
groupReuseRegionMap.put(regionName, list);
|
||||
}else{
|
||||
} else {
|
||||
groupReuseRegionMap.get(regionName).addAll(map.get(regionName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,6 +445,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
Transaction transaction = resource.multi();
|
||||
try {
|
||||
Set<Integer> keySet = configMap.keySet();
|
||||
for (Integer redisDBIndex : configMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
|
||||
transaction.select(redisDBIndex);
|
||||
@@ -458,6 +459,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
int service = maatConfig.getService();
|
||||
if (ServiceAndRDBIndexReal.isAddASU(service)) {
|
||||
if (!keySet.contains(TAPREDISDB)) {
|
||||
throw new ServiceRuntimeException("业务类型:" + service + ",需要向阀门" + TAPREDISDB + "号库分发,但是当前只往"
|
||||
+ keySet + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确",RestBusinessCode.PropertiesIsError.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
setConfig(maatConfig, maatXmlConfig, maatVersion, service, transaction,
|
||||
redisDBIndex);
|
||||
|
||||
@@ -52,19 +52,12 @@ public class MaatTestServiceimpl {
|
||||
Integer service = configCompile.getService();
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
List<Integer> redisDBList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
|
||||
boolean isValve = false;
|
||||
Map<String, String[]> map2 = ServiceAndRDBIndexReal.getMaatToValveMap().get(service);
|
||||
if (map2 != null && map2.size() > 0) {
|
||||
isValve = true;
|
||||
}
|
||||
if (isValve) {
|
||||
if (ServiceAndRDBIndexReal.isAddASU(service)) {
|
||||
if (!redisDBList.contains(TAPREDISDB)) {
|
||||
throw new RuntimeException("业务类型:" + service + ",需要向阀门" + TAPREDISDB + "号库分发,但是当前只往"
|
||||
+ redisDBList + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确");
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer redisDB : redisDBList) {
|
||||
getConfigByKey(redisDB, service, configCompile, maatXmlConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user