diff --git a/src/main/java/com/nis/util/CompileVal.java b/src/main/java/com/nis/util/CompileVal.java index 4321d5e..de110be 100644 --- a/src/main/java/com/nis/util/CompileVal.java +++ b/src/main/java/com/nis/util/CompileVal.java @@ -175,8 +175,9 @@ public class CompileVal { for (NumRegion numRegion : numRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(numRegion.getGroupId())) { - - if (!StringUtil.isEmpty(numRegion.getTableName())&&!type2TableNameIsOk(configCompile.getService(), numRegion.getTableName())) { + + if (!StringUtil.isEmpty(numRegion.getTableName()) + && !type2TableNameIsOk(configCompile.getService(), numRegion.getTableName())) { return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" + numRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } @@ -222,7 +223,8 @@ public class CompileVal { for (StrRegion strRegion : strRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(strRegion.getGroupId())) { - if (!StringUtil.isEmpty(strRegion.getTableName())&&!type2TableNameIsOk(configCompile.getService(), strRegion.getTableName())) { + if (!StringUtil.isEmpty(strRegion.getTableName()) + && !type2TableNameIsOk(configCompile.getService(), strRegion.getTableName())) { return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" + strRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } @@ -270,7 +272,8 @@ public class CompileVal { for (IpRegion ipRegion : ipRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(ipRegion.getGroupId())) { - if (!StringUtil.isEmpty(ipRegion.getTableName())&&!type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { + if (!StringUtil.isEmpty(ipRegion.getTableName()) + && !type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" + ipRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } @@ -349,14 +352,15 @@ public class CompileVal { } } } - + List ipClientRangeList = configCompile.getIpClientRangeList(); if (ipClientRangeList != null && ipClientRangeList.size() > 0) { for (IpRegion ipRegion : ipClientRangeList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(ipRegion.getGroupId())) { - if (!StringUtil.isEmpty(ipRegion.getTableName())&&!type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { + if (!StringUtil.isEmpty(ipRegion.getTableName()) + && !type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { return "配置id为" + configCompile.getCompileId() + "的配置中ipClientRangeList中的regionid为" + ipRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } @@ -406,10 +410,17 @@ public class CompileVal { public static boolean type2TableNameIsOk(Integer serviceType, String tableName) { if (null != serviceType && null != tableName && !tableName.equals("")) { List list = new ArrayList(); - Map sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(serviceType); + Map> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(serviceType); if (sercieNameMap != null && sercieNameMap.size() > 0) { for (Integer type : sercieNameMap.keySet()) { - list.add(sercieNameMap.get(type).toLowerCase()); + + List tableList = sercieNameMap.get(type); + if (tableList != null && tableList.size() > 0) { + for (String table : tableList) { + list.add(table.toLowerCase()); + } + } + } } @@ -727,10 +738,10 @@ public class CompileVal { public static String serviceConfigCompileVal(ConfigCompile configCompile) { Long compileId = configCompile.getCompileId(); Integer action = ServiceAndRDBIndexReal.getActionByService(configCompile.getService()); - if (StringUtil.isEmpty(action)){ - return "编译配置id为" + compileId + "的配置中service的值为"+configCompile.getService()+"时action不存在"; - }else if(action.compareTo(configCompile.getAction())!=0) { - return "编译配置id为" + compileId + "的配置中service的值为"+configCompile.getService()+"时action只能为"+action; + if (StringUtil.isEmpty(action)) { + return "编译配置id为" + compileId + "的配置中service的值为" + configCompile.getService() + "时action不存在"; + } else if (action.compareTo(configCompile.getAction()) != 0) { + return "编译配置id为" + compileId + "的配置中service的值为" + configCompile.getService() + "时action只能为" + action; } if (configCompile.getDoBlacklist() != 1) { return "编译配置id为" + compileId + "的配置中doBlacklist的值只能是1"; diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index a4552bc..80fa700 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -22,7 +22,7 @@ public class ServiceAndRDBIndexReal { /** * 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名 */ - private static Map> sercieNameMap = new HashMap>(); + private static Map>> sercieNameMap = new HashMap>>(); /** * 非maat结构业务类型与表名对应关系,key是业务类型,value是表名 @@ -68,13 +68,20 @@ public class ServiceAndRDBIndexReal { serviceActionMap.put(Integer.valueOf(serviceAction[0]), Integer.valueOf(serviceAction[1])); String type = Configurations.getStringProperty(serviceAction[0], ""); if (type != null && !type.trim().equals("")) { - Map typeMap = new HashMap(); + Map> typeMap = new HashMap>(); String[] typeArrs = type.split(";"); for (String typeStr : typeArrs) { String[] typeArr = typeStr.split(":"); + int tableType = Integer.parseInt(typeArr[0]); String tableNameArr[] = typeArr[1].split(","); for (String tableName : tableNameArr) { - typeMap.put(Integer.parseInt(typeArr[0]), tableName.toUpperCase()); + if (typeMap.containsKey(tableType)) { + typeMap.get(tableType).add(tableName.toUpperCase()); + } else { + List list = new ArrayList(); + list.add(tableName.toUpperCase()); + typeMap.put(tableType, list); + } } } sercieNameMap.put(Integer.parseInt(serviceAction[0]), typeMap); @@ -117,19 +124,23 @@ public class ServiceAndRDBIndexReal { * @return */ public static String getMaatTableName(int service, int type, String tableName) { - Map typeMap = sercieNameMap.get(service); + Map> typeMap = sercieNameMap.get(service); if (typeMap != null && typeMap.size() > 0) { + List tableList = typeMap.get(type); if (tableName == null || tableName.trim().equals("")) { - return typeMap.get(type); + if (tableList.size() > 1) { + logger.error("未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名", service, type, tableName); + throw new RuntimeException("业务类型:"+service+",配置类型:"+type+"对应多个表,请输入具体的表名"); + } else { + return tableList.get(0); + } } else { - String tableNames = typeMap.get(type); - String[] split = tableNames.split(","); - for (String str : split) { + for (String str : tableList) { if (str.toLowerCase().contains(tableName.toLowerCase())) { return str; } else { - logger.error( - "未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名",service,type,tableName); + logger.error("未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名", service, type, tableName); + throw new RuntimeException("未从业务类型和表对应关系中,找到业务类型:"+service+",配置类型:"+type+"表名:"+tableName+"对应的真实表名"); } } @@ -156,11 +167,12 @@ public class ServiceAndRDBIndexReal { return serviceActionMap.get(service); } - public static Map> getSercieNameMap() { + + public static Map>> getSercieNameMap() { return sercieNameMap; } - public static void setSercieNameMap(Map> sercieNameMap) { + public static void setSercieNameMap(Map>> sercieNameMap) { ServiceAndRDBIndexReal.sercieNameMap = sercieNameMap; }