diff --git a/src/main/java/com/nis/restful/RestBusinessCode.java b/src/main/java/com/nis/restful/RestBusinessCode.java index 81b1dda..583db7a 100644 --- a/src/main/java/com/nis/restful/RestBusinessCode.java +++ b/src/main/java/com/nis/restful/RestBusinessCode.java @@ -5,6 +5,11 @@ package com.nis.restful; */ public enum RestBusinessCode { + + /** + * 服务内部异常 + */ + service_runtime_error (30000, "服务内部异常!"), /** * 未知错误 */ @@ -48,7 +53,394 @@ public enum RestBusinessCode { update_success(2002, "数据更新操作成功"), - delete_success(2003, "数据删除操作成功"); + delete_success(2003, "数据删除操作成功"), + /** + * 完整性验证 10000 编译:10000 分组:10100 数值类:10200 IP类:10300 字符串类:10400 摘要类:10500 回调类:10600 + * 配置格式验证 20000 编译:20000 分组:20100 数值类:20200 IP类:20300 字符串类:20400 摘要类:20500 回调类:20600 + */ + + /** + * 编译配置不能为空 + */ + CompileIsNull(10001, "Maat配置不能为空"), + /** + * 编译配置的的compileId不能为空 + */ + CompileIdIsNull(10002, "Maat配置的compileId字段不能为空"), + + /** + * 编译配置的的service不能为空 + */ + ServiceIsNull(10003, "配置的service属性不能为空"), + + /** + * 编译配置的action不能为空 + */ + ActionIsNull(10004, "Maat配置的action不能为空"), + + /** + * 编译配置的的compileId不能为空 + */ + DoBlacklistIsNull(10005, "Maat配置的doBlacklist不能为空"), + /** + * 编译配置的的compileId不能为空 + */ + DoBlacklistIsWrongRange(10006, "Maat配置的doBlacklist的值不在有效范围"), + + /** + * 编译配置的的doLog不能为空 + */ + DoLogIsNull(10007, "Maat配置的doLog不能为空"), + /** + * 编译配置的的doLog不能为空 + */ + DoLogIsWrongRange(10008, "Maat配置的doLog的值不在有效范围"), + /** + * 编译配置的effectiveRange不能为空 + */ + EffectiveRangeIsNull(10009, "Maat配置的effectiveRange不能为空"), + /** + * 编译配置的startTime不能为空 + */ + StartTimeIsNull(10010, "Maat配置的startTime不能为空"), + + /** + * 编译配置的的endTime不能为空 + */ + EndTimeIsNull(10011, "Maat配置的endTime不能为空"), + + /** + * 配置的isValid不能为空 + */ + IsValidIsNull(10013, "配置isValid属性不能为空"), + + /** + * 编译配置的groupNum不能为空 + */ + GroupNumIsNull(10016, "Maat配置groupNum属性,不能为空"), + /** + * 编译配置的的fatherCfgId不能为空 + */ + FatherCfgIdIsNull(10017, "Maat配置的fatherCfgId不能为空"), + /** + * 编译配置的缺少配置分组信息 + */ + CompileGroupIsNull(10018, "Maat配置的缺少groupRelationList"), + + /** + * 编译配置的opTime不能为空 + */ + OpTimeIsNull(10019, "Maat配置的opTime不能为空"), + + //分组配置数据完整性业务码10100~ + + /** + * 编译配置的的配置分组的CompileId不能为空 + */ + GroupsCompileIdIsNull(10100, "Maat配置的配置分组的compileId不能为空"), + + /** + * 编译配置的的配置分组的groupId不能为空 + */ + GroupIdIsNull(10101, "Maat配置的的配置分组的groupId不能为空"), + + /** + * 编译配置的的配置分组的isValid不能为空 + */ + GroupsIsValidIsNull(10102, "编译配置的的配置分组的isValid不能为空"), + +// /** +// * 编译配置的的配置分组的opTime不能为空 +// */ +// GroupsOpTimeIsNull(1037, "编译配置的的配置分组的opTime不能为空"), + + /** + * 域配置的groupid在配置分组关系中不存在 + */ + RegionsGroupIdIsNotFound(10103, "域配置的groupid在配置分组关系中不存在"), + /** + *域配置的regionId不能为空 + */ + RegionIdIsNull(10104, "域配置的regionId不能为空"), + + /** + *域配置的groupId不能为空 + */ + RegionsGroupIdIsNull(10105, "域配置的groupId不能为空"), + + //数值类域数据完整性业务码10200~ + /** + * 编译配置中缺少数值类域配置信息 + */ + NumRegionIsNull(10200, "Maat配置中不能缺少数值类域配置信息"), + + /** + *数值域配置的lowBoundary不能为空 + */ + LowBoundaryIsNull(10201, "数值域配置的lowBoundary不能为空"), + /** + *数值域配置的upBoundary不能为空 + */ + UpBoundaryIsNull(10202, "数值域配置的upBoundary不能为空"), + + //数值类域数据完整性业务码10300~ + /** + * 编译配置中缺少IP类域配置信息 + */ + IpRegionIsNull(10300, "Maat配置中不能缺少IP类域配置信息"), + + /** + * IP类域配置的addrType不能为空 + */ + AddrTypeIsNull(10301,"IP类域配置的addrType不能为空"), + /** + * IP类域配置的srcIp不能为空 + */ + SrcIpIsNull(10302,"IP类域配置的srcIp不能为空"), + /** + * IP类域配置的maskSrcIp不能为空 + */ + MaskSrcIpIsNull(10303,"IP类域配置的maskSrcIp不能为空"), + + /** + * IP类域配置的srcPort不能为空 + */ + SrcPortIsNull(10304,"IP类域配置的srcPort不能为空"), + /** + * IP类域配置的maskSrcPort不能为空 + */ + MaskSrcPortIsNull(10305,"IP类域配置的maskSrcPort不能为空"), + /** + * IP类域配置的dstIp不能为空 + */ + DstIpIsNull(10306,"IP类域配置的dstIp不能为空"), + /** + * IP类域配置的maskDstIp不能为空 + */ + MaskDstIpIsNull(10307,"IP类域配置的maskDstIp不能为空"), + + /** + * IP类域配置的dstPort不能为空 + */ + DstPortIsNull(10308,"IP类域配置的dstPort不能为空"), + /** + * IP类域配置的maskDstPort不能为空 + */ + MaskDstPortIsNull(10309,"IP类域配置的maskDstPort不能为空"), + /** + * IP类域配置的protocol不能为空 + */ + ProtocolIsNull(10310,"IP类域配置的protocol不能为空"), + /** + * IP类域配置的direction不能为空 + */ + DirectionIsNull(10311,"IP类域配置的direction不能为空"), + + //数值类域数据完整性业务码10400~ + /** + * 编译配置中缺少字符串类域配置信息 + */ + StrRegionIsNull(10400, "Maat配置中不能缺少字符串类域配置信息"), + /** + * 字符串类域配置的keywords不能为空 + */ + KeywordsIsNull(10401,"字符串类域配置的keywords不能为空"), + /** + * 字符串类域配置的district不能为空 + */ + DistrictIsNull(10402,"字符串类域配置的district不能为空"), + /** + * 字符串类域配置的exprType不能为空 + */ + ExprTypeIsNull(10403,"字符串类域配置的keywords不能为空"), + + /** + * 字符串类域配置的matchMethod不能为空 + */ + MatchMethodIsNull(10404,"字符串类域配置的matchMethod不能为空"), + + /** + * 字符串类域配置的isHexbin不能为空 + */ + IsHexbinIsNull(10405,"字符串类域配置的isHexbin不能为空"), + + //摘要类域数据完整性业务码10500~ + /** + * 摘要类域配置的rawLen不能为空 + */ + RawLenIsNull(10500,"摘要类域配置的rawLen不能为空"), + /** + * 摘要类域配置的digest的值只能是1到10 + */ + DigestIsNull(10501,"摘要类域配置的digest不能为空"), + + /** + * 摘要类域配置的cfdsLevel不能为空 + */ + CfdsLevelIsNull(10502,"摘要类域配置的cfdsLevel不能为空"), + + /** + * 回调类配置的cfgId字段不能为空 + */ + CfgIdIsNull(10600,"配置的cfgId字段不能为空"), + /** + * 回调类配置的属性不能为空 + */ + FieldIsNull(10601,"配置属性不能为空"), + /** + * 回调类上传文件不能为空 + */ + FileIsNull(10602,"上传文件不能为空"), + + /** + * 回调类checksum与文件MD5值不一致 + */ + CheckSumIsWrong(10603,"checksum与文件MD5值不一致"), + + //配置业务格式验证 20000 + /** + * 编译配置的groupNum属性值等于0 + */ + GroupNumIsZero(20001, "Maat配置groupNum属性值,不能等于0"), + /** + * 编译配置的groupNum属性值大于8 + */ + GroupNumGtEight(20002, "Maat配置的groupNum属性值大于8"), + + /** + * 编译配置的groupNum属性值与groupRelationList长度不相等 + */ + GroupNumNEQGroupList(20003, "Maat配置的groupNum属性值与groupRelationList长度不等"), + /** + * 编译配置的的fatherCfgId不能为空 + */ + FatherCfgIdIsWrongRange(20004, "Maat配置的fatherCfgId值不在有效范围"), + /** + * 编译配置的service与action不匹配 + */ + ServiceUnmatchAction(20005, "Maat配置的service与action不匹配"), + /** + * 编译配置的的startTime不能晚于endTime + */ + EndTimeGTStartTime(20006, "Maat配置的startTime不能晚于endTime"), + /** + * 配置的isValid在添加时不能为无效 + */ + IsValidIsT(20007, "配置增加操作,isValid值不能无效"), + /** + * 配置的isValid在配置取消时不能为有效 + */ + IsValidIsF(20008, "配置取消操作,isValid值不能为有效"), +// /** +// * 编译配置的groupRelationList的配置在添加时不能为无效 +// */ +// GroupRegionIsValid(1021, "编译配置的分组配置在添加时不能为无效"), +// +// /** +// * 编译配置的groupRelationList的配置在添加时不能为有效 +// */ +// GroupRegionIsNotValid(1021, "编译配置的分组配置在修改时不能为有效"), + + /** + * 配置分组与编译配置的compileId不一致 + */ + CompileIdIsNeq(20009,"Maat配置分组与编译配置的compileId不一致"), + + /** + * 配置分组中同一groupId出现多次 + */ + GroupIdIsRepeat(20100,"Maat配置分组中同一groupId不能出现多次"), + + /** + * tableName与编译配置业务类型不一致 + */ + TableNameUnmatchService(20101, "tableName与编译配置业务类型不匹配"), + + /** + *数值域配置的lowBoundary值不在有效范围内 + */ + LowBoundaryIsWrongRange(20200, "数值域配置的lowBoundary值不在有效范围内"), + /** + *数值域配置的upBoundary值不在有效范围内 + */ + UpBoundaryIsWrongRange(20201, "数值域配置的upBoundary值不在有效范围内"), + /** + *数值域配置的lowBoundary大于upBoundary值 + */ + LowBoundaryGTUpBoundary(20202, "数值域配置的lowBoundary大于upBoundary值"), + + /** + * IP类域配置的direction的值不在有效范围 + */ + DirectionIsWrongRange(20300,"Maat配置的direction的值只能是0或1"), + + /** + * IP类域配置的IP或IpMask与addrType不一致 + */ + IPUnMatchAddrType(20301,"Maat配置IP或IpMask与addrType不一致"), + /** + * IP类域配置的port格式不正确 + */ + PortIsNotVal(20302,"配置port或portMask格式不正确"), + /** + * IP类域配置的srcIp和dstIp不能相同 + */ + SrcIpEQDstIp(20303,"Maat配置的srcIp和dstIp不能相同"), + + /** + * 字符串域配置的exprType的值只能是0(无表达式)或者1(与表达式) + */ + ExprTypeIsWrongRange(20400,"Maat配置的exprType的值只能是0(无表达式)或者1(与表达式)"), + + /** + * 字符串域配置的matchMethod的值只能是0(无表达式)或者1(与表达式) + */ + MatchMethodIsWrongRange(20401,"Maat配置的matchMethod的值只能是0(子串匹配),1(右匹配),2(左匹配),3(完全匹配)"), + + /** + * 字符串域配置的isHexbin的值只能是0(大小写不敏感,且非HEX)或者1(HEX)或者2(大小写敏感,且非HEX) + */ + IsHexbinIsWrongRange(20402,"Maat配置的isHexbin的值只能是0(大小写不敏感,且非HEX)或者1(HEX)或者2(大小写敏感,且非HEX)"), + /** + * 摘要类域配置的cfdsLevel的值只能是1到10 + */ + CfdsLevelIsWrongRange(20500,"Maat配置cfdsLevel的值只能是1到10"), + + + //回调类 + /** + * 回调类service配置不正确 + */ + ServiceIsWrong(20600,"service的值配置不正确"), + + /** + * 回调类ipType属性只能为4(IPV4)、6(IPV6) + */ + IpTypeIsWrong(20601,"ipType属性只能为4(IPV4)、6(IPV6)"), + + /** + * 回调类的XX属性不是数值类型 + */ + MastNumberic(20602,"属性值不是数值类型"), + /** + * 回调类的XX属性不是数值类型 + */ + MastDate(20602,"属性值不是日期类型"), + /** + * 回调类的XX属性不是数值类型 + */ + IpIsUnMatchType(20603,"配置IP或Mask与addrType不一致"), + /** + * 回调类的XX属性取值不在Range范围内 + */ + ValueInWrongRange(20604,"属性取值不在Range范围内"), + /** + * 回调类的XX属性取值符合正则表达式验证 + */ + ValueInWrongRegexp(20605,"属性值与正则表达式不匹配"), + + IsValidInWrongRange(20606,"isValid属性格式不正确"), + ; diff --git a/src/main/java/com/nis/util/CompileVal.java b/src/main/java/com/nis/util/CompileVal.java index 274821d..cff5591 100644 --- a/src/main/java/com/nis/util/CompileVal.java +++ b/src/main/java/com/nis/util/CompileVal.java @@ -13,11 +13,24 @@ import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.StrRegion; import com.nis.listener.SystemConfigListener; -import com.nis.restful.CompileJudgeCode; +import com.nis.restful.RestBusinessCode; import com.nis.web.service.restful.ConfigSourcesService; public class CompileVal { + private static Integer businessCode = null; + /** + * @param businessCode the businessCode to set + */ + public static void setBusinessCode(Integer businessCode) { + CompileVal.businessCode = businessCode; + } + /** + * @return the businessCode + */ + public static Integer getBusinessCode() { + return businessCode; + } /** * 判断当前编译配置中的groupNum属性值与配置分组groupList大小是否小于等于8且大于0 * @@ -37,76 +50,44 @@ public class CompileVal { return valCompile; } } - if (null == configCompile.getCompileId()) { - return "compileId字段不能为空"; - } - - if (null == configCompile.getGroupNum()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumIsNull.getErrorReason(); - } - - if (null != configCompile.getGroupNum() && configCompile.getGroupNum() > 8) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumGtEight.getErrorReason(); - } if (null != configCompile.getGroupNum() && configCompile.getGroupNum() <= 0) { + businessCode = RestBusinessCode.GroupNumIsZero.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumEQZero.getErrorReason(); + + RestBusinessCode.GroupNumIsZero.getErrorReason(); } + if (null != configCompile.getGroupNum() && configCompile.getGroupNum() > 8) { + businessCode = RestBusinessCode.GroupNumGtEight.getValue(); + return "编译配置id为" + configCompile.getCompileId() + "的配置中" + + RestBusinessCode.GroupNumGtEight.getErrorReason(); + } + - if (null == configCompile.getGroupRelationList()) { + if (null == configCompile.getGroupRelationList()||configCompile.getGroupRelationList().size()==0) { + businessCode = RestBusinessCode.CompileGroupIsNull.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.CompileGroupIsNull.getErrorReason(); - } - if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() <= 0) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListEQZero.getErrorReason(); - } - if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 8) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListGtEight.getErrorReason(); + + RestBusinessCode.CompileGroupIsNull.getErrorReason(); } if (configCompile.getGroupRelationList().size() != configCompile.getGroupNum()) { + businessCode = RestBusinessCode.GroupNumNEQGroupList.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumNEQGroupList.getErrorReason(); + + RestBusinessCode.GroupNumNEQGroupList.getErrorReason(); } - // int sizeCount = 0; - // if (configCompile.getIpRegionList() == null && - // configCompile.getStrRegionList() == null - // && configCompile.getNumRegionList() == null) { - // return "编译配置id为" + configCompile.getCompileId() + "的配置中" - // + CompileJudgeCode.CompileNotNull.getErrorReason(); - // } else { - // if (configCompile.getIpRegionList() != null) { - // sizeCount += configCompile.getIpRegionList().size(); - // } - // if (configCompile.getStrRegionList() != null) { - // sizeCount += configCompile.getStrRegionList().size(); - // } - // if (configCompile.getNumRegionList() != null) { - // sizeCount += configCompile.getNumRegionList().size(); - // } - // - // if (sizeCount == 0) { - // return "编译配置id为" + configCompile.getCompileId() + "的配置中" - // + CompileJudgeCode.CompileNotNull.getErrorReason(); - // } - // } if (!isUpdate) { if (configCompile.getIsValid() != 1) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置在添加时不能为无效"; } } else { + businessCode = RestBusinessCode.IsValidIsF.getValue(); if (configCompile.getIsValid() != 0) { return "编译配置id为" + configCompile.getCompileId() + "的配置在修改时不能为有效"; } } - return CompileJudgeCode.GroupNumAndListLtEight.getErrorReason(); + return "ok"; } else { - return "编译配置id为" + configCompile.getCompileId() + "的" + CompileJudgeCode.CompileIsNull.getErrorReason(); + return RestBusinessCode.CompileIsNull.getErrorReason(); } } @@ -134,10 +115,12 @@ public class CompileVal { if (groupRelationList.size() > 0) { for (ConfigGroupRelation configGroupRelation : groupRelationList) { if (!isUpdate && (null == configGroupRelation.getIsValid() || configGroupRelation.getIsValid() != 1)) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置groupRelationList字段中的groupId为" + configGroupRelation.getGroupId() + "的配置在添加时不能为无效"; } if (isUpdate && (null == configGroupRelation.getIsValid() || configGroupRelation.getIsValid() != 0)) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置groupRelationList字段中的groupId为" + configGroupRelation.getGroupId() + "的配置在修改时不能为有效"; } @@ -150,26 +133,30 @@ public class CompileVal { } if (!configGroupRelation.getCompileId().equals(compileId)) { + businessCode = RestBusinessCode.CompileIdIsNeq.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中groupRelationList字段中的groupId为" + configGroupRelation.getGroupId() + "的配置分组与编译配置id不一致"; } if (!groupList.contains(configGroupRelation.getGroupId())) { groupList.add(configGroupRelation.getGroupId()); } else { + businessCode = RestBusinessCode.GroupIdIsRepeat.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中groupRelationList存在多个groupId为" + configGroupRelation.getGroupId() + "的配置分组"; } } - } else { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListEQZero.getErrorReason(); } +// else { +// return "编译配置id为" + configCompile.getCompileId() + "的配置中" +// + CompileJudgeCode.GroupListEQZero.getErrorReason(); +// } List regionGroupIdList = new ArrayList();// 所有域配置中groupId的集合,不重复 List numRegionList = configCompile.getNumRegionList(); if (numRegionList == null) { + businessCode = RestBusinessCode.NumRegionIsNull.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.NumRegionIsNull.getErrorReason(); + + RestBusinessCode.NumRegionIsNull.getErrorReason(); } if (numRegionList.size() > 0) { for (NumRegion numRegion : numRegionList) { @@ -178,19 +165,23 @@ public class CompileVal { if (!StringUtil.isEmpty(numRegion.getTableName()) && !type2TableNameIsOk(configCompile.getService(), numRegion.getTableName())) { + businessCode = RestBusinessCode.TableNameUnmatchService.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" + numRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } if (!isUpdate && numRegion.getIsValid() != 1) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" + numRegion.getRegionId() + "的域配置在添加时不能为无效"; } if (isUpdate && numRegion.getIsValid() != 0) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" + numRegion.getRegionId() + "的域配置在修改时不能为有效"; } if (groupList.size() > 0 && !groupList.contains(numRegion.getGroupId())) { + businessCode = RestBusinessCode.RegionsGroupIdIsNotFound.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" + numRegion.getRegionId() + "的配置的groupid在配置分组关系中不存在"; } @@ -216,8 +207,9 @@ public class CompileVal { List strRegionList = configCompile.getStrRegionList(); if (strRegionList == null) { + businessCode = RestBusinessCode.StrRegionIsNull.getValue(); return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.StrRegionIsNull.getErrorReason(); + + RestBusinessCode.StrRegionIsNull.getErrorReason(); } if (strRegionList != null && strRegionList.size() > 0) { for (StrRegion strRegion : strRegionList) { @@ -225,19 +217,23 @@ public class CompileVal { // !regionGroupIdList.contains(strRegion.getGroupId())) { if (!StringUtil.isEmpty(strRegion.getTableName()) && !type2TableNameIsOk(configCompile.getService(), strRegion.getTableName())) { + businessCode = RestBusinessCode.TableNameUnmatchService.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" + strRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } if (!isUpdate && strRegion.getIsValid() != 1) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" + strRegion.getRegionId() + "的域配置在添加时不能为无效"; } if (isUpdate && strRegion.getIsValid() != 0) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" + strRegion.getRegionId() + "的域配置在修改时不能为有效"; } if (groupList.size() > 0 && !groupList.contains(strRegion.getGroupId())) { + businessCode = RestBusinessCode.RegionsGroupIdIsNotFound.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" + strRegion.getRegionId() + "的配置的groupid在配置分组关系中不存在"; } @@ -266,7 +262,9 @@ public class CompileVal { List ipRegionList = configCompile.getIpRegionList(); if (ipRegionList == null) { - return CompileJudgeCode.IpRegionIsNull.getErrorReason(); + businessCode = RestBusinessCode.IpRegionIsNull.getValue(); + return "编译配置id为" + configCompile.getCompileId() + "的配置中" + + RestBusinessCode.IpRegionIsNull.getErrorReason(); } if (ipRegionList != null && ipRegionList.size() > 0) { for (IpRegion ipRegion : ipRegionList) { @@ -274,20 +272,24 @@ public class CompileVal { // !regionGroupIdList.contains(ipRegion.getGroupId())) { if (!StringUtil.isEmpty(ipRegion.getTableName()) && !type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { + businessCode = RestBusinessCode.TableNameUnmatchService.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" + ipRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } if (!isUpdate && (null == ipRegion.getIsValid() || ipRegion.getIsValid() != 1)) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" + ipRegion.getRegionId() + "的域配置在添加时不能为无效"; } if (isUpdate && (null == ipRegion.getIsValid() || ipRegion.getIsValid() != 0)) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" + ipRegion.getRegionId() + "的域配置在修改时不能为有效"; } if (groupList.size() > 0 && !groupList.contains(ipRegion.getGroupId())) { + businessCode = RestBusinessCode.RegionsGroupIdIsNotFound.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" + ipRegion.getRegionId() + "的配置的groupid在配置分组关系中不存在"; } @@ -321,15 +323,18 @@ public class CompileVal { // 不验证表名和业务类型是否对应 if (!isUpdate && digestRegion.getIsValid() != 1) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中digestRegionList中的regionid为" + digestRegion.getRegionId() + "的域配置在添加时不能为无效"; } if (isUpdate && digestRegion.getIsValid() != 0) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中digestRegionList中的regionid为" + digestRegion.getRegionId() + "的域配置在修改时不能为有效"; } if (groupList.size() > 0 && !groupList.contains(digestRegion.getGroupId())) { + businessCode = RestBusinessCode.RegionsGroupIdIsNotFound.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中digestRegion中的regionid为" + digestRegion.getRegionId() + "的配置的groupid在配置分组关系中不存在"; } @@ -361,20 +366,24 @@ public class CompileVal { // !regionGroupIdList.contains(ipRegion.getGroupId())) { if (!StringUtil.isEmpty(ipRegion.getTableName()) && !type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { + businessCode = RestBusinessCode.TableNameUnmatchService.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipClientRangeList中的regionid为" + ipRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; } if (!isUpdate && (null == ipRegion.getIsValid() || ipRegion.getIsValid() != 1)) { + businessCode = RestBusinessCode.IsValidIsT.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipClientRangeList中的regionid为" + ipRegion.getRegionId() + "的域配置在添加时不能为无效"; } if (isUpdate && (null == ipRegion.getIsValid() || ipRegion.getIsValid() != 0)) { + businessCode = RestBusinessCode.IsValidIsF.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipClientRangeList中的regionid为" + ipRegion.getRegionId() + "的域配置在修改时不能为有效"; } if (groupList.size() > 0 && !groupList.contains(ipRegion.getGroupId())) { + businessCode = RestBusinessCode.RegionsGroupIdIsNotFound.getValue(); return "配置id为" + configCompile.getCompileId() + "的配置中ipClientRangeList中的regionid为" + ipRegion.getRegionId() + "的配置的groupid在配置分组关系中不存在"; } @@ -397,7 +406,7 @@ public class CompileVal { } } } - return CompileJudgeCode.CompileGroupSizeGtZero.getErrorReason(); + return "ok"; } /** @@ -449,12 +458,12 @@ public class CompileVal { public static String compileIsOk(ConfigCompile configCompile, boolean isUpdate, StringBuffer sb) { String msg1 = groupNumAndListIsOk(configCompile, isUpdate); - if (msg1 != CompileJudgeCode.GroupNumAndListLtEight.getErrorReason()) { + if (!"ok".equals(msg1)) { return msg1; } String msg2 = compileGroupSizeIsGtZero(configCompile, isUpdate, sb); - if (msg2 != CompileJudgeCode.CompileGroupSizeGtZero.getErrorReason()) { + if (!"ok".equals(msg2)) { return msg2; } String latentMsg = ",数据中可能存在的问题:"; @@ -463,7 +472,7 @@ public class CompileVal { sb.setLength(0); sb.append(latentMsg); } - return CompileJudgeCode.CompileIsOk.getErrorReason(); + return "ok"; } public static void setSbStr(String str, StringBuffer sb) { @@ -475,44 +484,56 @@ public class CompileVal { public static String valCompile(ConfigCompile configCompile) { Long compileId = configCompile.getCompileId(); if (null == compileId) { - return "compileId字段不能为空"; + businessCode = RestBusinessCode.CompileIdIsNull.getValue(); + return RestBusinessCode.CompileIdIsNull.getErrorReason(); } if (null == configCompile.getService()) { - return "id为" + compileId + "的编译配置中service不能为空"; + businessCode = RestBusinessCode.ServiceIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中service不能为空"; } if (null == configCompile.getAction()) { - return "id为" + compileId + "的编译配置中action不能为空"; + businessCode = RestBusinessCode.ActionIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中action不能为空"; } if (null == configCompile.getDoBlacklist()) { - return "id为" + compileId + "的编译配置中doBlacklist不能为空"; + businessCode = RestBusinessCode.DoBlacklistIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中doBlacklist不能为空"; } if (null == configCompile.getDoLog()) { - return "id为" + compileId + "的编译配置中doLog不能为空"; + businessCode = RestBusinessCode.DoLogIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中doLog不能为空"; } if (null == configCompile.getEffectiveRange() || configCompile.getEffectiveRange().equals("")) { - return "id为" + compileId + "的编译配置中effectiveRange不能为空"; + businessCode = RestBusinessCode.EffectiveRangeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中effectiveRange不能为空"; } if (null == configCompile.getStartTime()) { - return "id为" + compileId + "的编译配置中startTime不能为空"; + businessCode = RestBusinessCode.StartTimeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中startTime不能为空"; } if (null == configCompile.getEndTime()) { - return "id为" + compileId + "的编译配置中endTime不能为空"; + businessCode = RestBusinessCode.EndTimeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中endTime不能为空"; } // if (null == configCompile.getUserRegion() || configCompile.getUserRegion().equals("")) { -// return "id为" + compileId + "的编译配置中userRegion不能为空"; +// return "编译配置id为" + compileId + "的编译配置中userRegion不能为空"; // } if (null == configCompile.getIsValid()) { - return "id为" + compileId + "的编译配置中isValid不能为空"; + businessCode = RestBusinessCode.IsValidIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中isValid不能为空"; } if (null == configCompile.getGroupNum()) { - return "id为" + compileId + "的编译配置中groupNum不能为空"; + businessCode = RestBusinessCode.GroupNumIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中groupNum不能为空"; } if (null == configCompile.getFatherCfgId()) { - return "id为" + compileId + "的编译配置中fatherCfgId不能为空"; + businessCode = RestBusinessCode.FatherCfgIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中fatherCfgId不能为空"; } if (null == configCompile.getOpTime()) { - return "id为" + compileId + "的编译配置中opTime不能为空"; + businessCode = RestBusinessCode.OpTimeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中opTime不能为空"; } return "ok"; } @@ -520,67 +541,84 @@ public class CompileVal { public static String valCompileGroup(ConfigGroupRelation configGroupRelation, Long compileId) { Long groupId = configGroupRelation.getGroupId(); if (null == groupId) { - return "id为" + compileId + "的编译配置中的配置分组的groupId不能为空"; + businessCode = RestBusinessCode.GroupIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的配置分组的groupId不能为空"; } if (null == configGroupRelation.getCompileId()) { - return "id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置compileId不能为空"; + businessCode = RestBusinessCode.GroupsCompileIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置compileId不能为空"; } if (null == configGroupRelation.getIsValid()) { - return "id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置isValid不能为空"; + businessCode = RestBusinessCode.GroupsIsValidIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置isValid不能为空"; } if (null == configGroupRelation.getOpTime()) { - return "id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置opTime不能为空"; + businessCode = RestBusinessCode.OpTimeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的配置opTime不能为空"; } return "ok"; } public static String valIpRegion(IpRegion ipRegion, Long compileId) { - Long regionId = ipRegion.getRegionId(); if (null == regionId) { - return "id为" + compileId + "的编译配置中的ip类域配置的regionId不能为空"; + businessCode = RestBusinessCode.RegionIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置的regionId不能为空"; } if (null == ipRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置groupId不能为空"; + businessCode = RestBusinessCode.RegionsGroupIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置groupId不能为空"; } if (null == ipRegion.getAddrType()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置addrType不能为空"; + businessCode = RestBusinessCode.AddrTypeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置addrType不能为空"; } if (null == ipRegion.getSrcIp() || ipRegion.getSrcIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置srcIp不能为空"; + businessCode = RestBusinessCode.SrcIpIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置srcIp不能为空"; } if (null == ipRegion.getMaskSrcIp() || ipRegion.getMaskSrcIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskSrcIp不能为空"; + businessCode = RestBusinessCode.MaskSrcIpIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskSrcIp不能为空"; } if (null == ipRegion.getSrcPort() || ipRegion.getSrcPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置srcPort不能为空"; + businessCode = RestBusinessCode.SrcPortIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置srcPort不能为空"; } if (null == ipRegion.getMaskSrcPort() || ipRegion.getMaskSrcPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskSrcPort不能为空"; + businessCode = RestBusinessCode.MaskSrcPortIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskSrcPort不能为空"; } if (null == ipRegion.getDstIp() || ipRegion.getDstIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置dstIp不能为空"; + businessCode = RestBusinessCode.DstIpIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置dstIp不能为空"; } if (null == ipRegion.getMaskDstIp() || ipRegion.getMaskDstIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskDstIp不能为空"; + businessCode = RestBusinessCode.MaskDstIpIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskDstIp不能为空"; } if (null == ipRegion.getDstPort() || ipRegion.getDstPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置dstPort不能为空"; + businessCode = RestBusinessCode.DstPortIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置dstPort不能为空"; } if (null == ipRegion.getMaskDstPort() || ipRegion.getMaskDstPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskDstPort不能为空"; + businessCode = RestBusinessCode.MaskDstPortIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置maskDstPort不能为空"; } if (null == ipRegion.getProtocol()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置protocol不能为空"; + businessCode = RestBusinessCode.ProtocolIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置protocol不能为空"; } if (null == ipRegion.getDirection()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置direction不能为空"; + businessCode = RestBusinessCode.DirectionIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置direction不能为空"; } if (null == ipRegion.getIsValid()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置isValid不能为空"; + businessCode = RestBusinessCode.IsValidIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的配置isValid不能为空"; } return "ok"; } @@ -588,16 +626,20 @@ public class CompileVal { public static String valNumRegion(NumRegion numRegion, Long compileId) { Long regionId = numRegion.getRegionId(); if (null == regionId) { - return "id为" + compileId + "的编译配置中的数值类域配置的regionId不能为空"; + businessCode = RestBusinessCode.RegionIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的数值类域配置的regionId不能为空"; } if (null == numRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置groupId不能为空"; + businessCode = RestBusinessCode.RegionsGroupIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置groupId不能为空"; } if (null == numRegion.getLowBoundary()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置lowBoundary不能为空"; + businessCode = RestBusinessCode.LowBoundaryIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置lowBoundary不能为空"; } if (null == numRegion.getUpBoundary()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置upBoundary不能为空"; + businessCode = RestBusinessCode.UpBoundaryIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的配置upBoundary不能为空"; } return "ok"; } @@ -605,28 +647,35 @@ public class CompileVal { public static String valStrRegion(StrRegion strRegion, Long compileId, boolean isDirtrict) { Long regionId = strRegion.getRegionId(); if (null == regionId) { - return "id为" + compileId + "的编译配置中的字符串类域配置的regionId不能为空"; + businessCode = RestBusinessCode.RegionIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置的regionId不能为空"; } if (null == strRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置groupId不能为空"; + businessCode = RestBusinessCode.RegionsGroupIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置groupId不能为空"; } if (isDirtrict && (null == strRegion.getDistrict() || strRegion.getDistrict().equals(""))) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置district不能为空"; + businessCode = RestBusinessCode.DistrictIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置district不能为空"; } if (null == strRegion.getKeywords() || strRegion.getKeywords().equals("")) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置keywords不能为空"; + businessCode = RestBusinessCode.KeywordsIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置keywords不能为空"; } if (null == strRegion.getExprType()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置exprType不能为空"; + businessCode = RestBusinessCode.ExprTypeIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置exprType不能为空"; } if (null == strRegion.getMatchMethod()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置matchMethod不能为空"; + businessCode = RestBusinessCode.MatchMethodIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置matchMethod不能为空"; } if (null == strRegion.getIsHexbin()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置isHexbin不能为空"; + businessCode = RestBusinessCode.MatchMethodIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置isHexbin不能为空"; } return "ok"; } @@ -634,65 +683,80 @@ public class CompileVal { public static String valDigestRegion(DigestRegion digestRegion, Long compileId) { Long regionId = digestRegion.getRegionId(); if (null == regionId) { - return "id为" + compileId + "的编译配置中的摘要类域配置的regionId不能为空"; + businessCode = RestBusinessCode.RegionIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的摘要类域配置的regionId不能为空"; } if (null == digestRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置groupId不能为空"; + businessCode = RestBusinessCode.RegionsGroupIdIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置groupId不能为空"; } if (null == digestRegion.getRawLen()) { - return "id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置rawLen不能为空"; + businessCode = RestBusinessCode.RawLenIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置rawLen不能为空"; } if (null == digestRegion.getDigest() || digestRegion.getDigest().equals("")) { - return "id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置digest不能为空"; + businessCode = RestBusinessCode.DigestIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的摘要类域配置id为" + regionId + "的配置digest不能为空"; } if (null == digestRegion.getCfdsLevel()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置cfdsLevel不能为空"; + businessCode = RestBusinessCode.CfdsLevelIsNull.getValue(); + return "编译配置id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的配置cfdsLevel不能为空"; } return "ok"; } public static String serviceIpClientRegionVal(IpRegion ipRegion, Long compileId) { if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置srcIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置maskSrcIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置dstIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置maskDstIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getSrcPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置srcPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskSrcPort())) { // if (!BasicProvingUtil.isIntType(ipRegion.getMaskSrcPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置maskSrcPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getDstPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置dstPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskDstPort())) { // if (!BasicProvingUtil.isIntType(ipRegion.getMaskDstPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置maskDstPort的格式不正确"; } if (ipRegion.getSrcIp().equals(ipRegion.getDstIp())) { + businessCode = RestBusinessCode.SrcIpEQDstIp.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置srcIp和dstIp不能相同"; } if (ipRegion.getDirection() != 1 && ipRegion.getDirection() != 0) { + businessCode = RestBusinessCode.DirectionIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中ipClientRangeList中regionId为" + ipRegion.getRegionId() + "的域配置direction的值不正确,只能是0或1"; } @@ -717,46 +781,56 @@ public class CompileVal { public static String serviceIpRegionVal(IpRegion ipRegion, Long compileId) { if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置srcIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置maskSrcIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置dstIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), ipRegion.getAddrType())) { + businessCode = RestBusinessCode.IPUnMatchAddrType.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置maskDstIp的格式不正确或与addrType不一致"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getSrcPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置srcPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskSrcPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); // if (!BasicProvingUtil.isIntType(ipRegion.getMaskSrcPort())) { return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置maskSrcPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getDstPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置dstPort的格式不正确"; } if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskDstPort())) { // if (!BasicProvingUtil.isIntType(ipRegion.getMaskDstPort())) { + businessCode = RestBusinessCode.PortIsNotVal.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置maskDstPort的格式不正确"; } if (ipRegion.getSrcIp().equals(ipRegion.getDstIp())) { + businessCode = RestBusinessCode.SrcIpEQDstIp.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置srcIp和dstIp不能相同"; } if (ipRegion.getDirection() != 1 && ipRegion.getDirection() != 0) { + businessCode = RestBusinessCode.DirectionIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置direction的值不正确,只能是0或1"; } @@ -784,14 +858,17 @@ public class CompileVal { Long upBoundary = numRegion.getUpBoundary(); if (lowBoundary <= upBoundary) { if (lowBoundary > 4294967295l || lowBoundary < 0l) { + businessCode = RestBusinessCode.LowBoundaryIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中numRegionList中regionId为" + numRegion.getRegionId() + "的域配置lowBoundary的值不能大于2的32次方减一(4294967295)或者小于0"; } if (upBoundary > 4294967295l || upBoundary < 0l) { + businessCode = RestBusinessCode.UpBoundaryIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中numRegionList中regionId为" + numRegion.getRegionId() + "的域配置upBoundary的值不能大于2的32次方减一(4294967295)或者小于0"; } } else { + businessCode = RestBusinessCode.LowBoundaryGTUpBoundary.getValue(); return "编译配置id为" + compileId + "的配置中numRegionList中regionId为" + numRegion.getRegionId() + "的域配置lowBoundary的值大于upBoundary,应该是小于或等于"; } @@ -802,23 +879,26 @@ 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) { + if (action.compareTo(configCompile.getAction()) != 0) { + businessCode = RestBusinessCode.ServiceUnmatchAction.getValue(); return "编译配置id为" + compileId + "的配置中service的值为" + configCompile.getService() + "时action只能为" + action; } if (configCompile.getDoBlacklist() != 1) { + businessCode = RestBusinessCode.DoBlacklistIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中doBlacklist的值只能是1"; } if (configCompile.getDoLog() != 0 && configCompile.getDoLog() != 1 && configCompile.getDoLog() != 2) { + businessCode = RestBusinessCode.DoLogIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中doLog的值只能是0(不需要),1(需要),2(只记录结构化日志,不记录非结构化日志)"; } if (configCompile.getFatherCfgId() != 0) { + businessCode = RestBusinessCode.FatherCfgIdIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中fatherCfgId的值只能是0"; } if (configCompile.getStartTime().getTime() > configCompile.getEndTime().getTime()) { + businessCode = RestBusinessCode.EndTimeGTStartTime.getValue(); return "编译配置id为" + compileId + "的配置中startTime不能比endTime晚"; } return "ok"; @@ -830,15 +910,18 @@ public class CompileVal { Integer matchMethod = strRegion.getMatchMethod(); Integer isHexbin = strRegion.getIsHexbin(); if (exprType != 0 && exprType != 1) { + businessCode = RestBusinessCode.ExprTypeIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() + "的域配置exprType的值只能是0(无表达式)或者1(与表达式)"; } if (matchMethod != 0 && matchMethod != 1 && matchMethod != 2 && matchMethod != 3) { + businessCode = RestBusinessCode.MatchMethodIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() + "的域配置matchMethod的值只能是0(子串匹配),1(右匹配),2(左匹配),3(完全匹配)"; } if (isHexbin != 0 && isHexbin != 1 && isHexbin != 2) { + businessCode = RestBusinessCode.IsHexbinIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() + "的域配置isHexbin的值只能是0(大小写不敏感,且非HEX)或者1(HEX)或者2(大小写敏感,且非HEX)"; } @@ -851,6 +934,7 @@ public class CompileVal { Integer cfdsLevel = digestRegion.getCfdsLevel(); if (!(cfdsLevel >= 1 && cfdsLevel <= 10)) { + businessCode = RestBusinessCode.CfdsLevelIsWrongRange.getValue(); return "编译配置id为" + compileId + "的配置中digestRegionList中regionId为" + digestRegion.getRegionId() + "的域配置cfdsLevel的值只能是1到10"; } diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index 316eca3..702772f 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -179,11 +179,11 @@ public class ServiceAndRDBIndexReal { index = i; } } - if (index!=-1) { + if (index!=-1&&tableList!=null) { return tableList.get(index); } else { logger.error("未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名", service, type, tableName); - throw new RuntimeException("未从业务类型和表对应关系中,找到业务类型:"+service+",配置类型:"+type+"表名:"+tableName+"对应的真实表名"); + throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到业务类型:"+service+",配置类型:"+type+"表名:"+tableName+"对应的真实表名"); } } diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index 59d93f5..b05892c 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -28,6 +28,7 @@ import com.nis.domain.restful.FileDesc; import com.nis.domain.restful.MaatConfig; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; +import com.nis.util.CompileVal; import com.nis.util.Constants; import com.nis.util.FileUtils; import com.nis.util.OracleErrorCodeUtil; @@ -324,7 +325,7 @@ public class ConfigSourcesController extends BaseRestController { @ApiParam(value = "业务配置数据源", name = "configSource", required = true) public Map createConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request, HttpServletResponse response) { - + CompileVal.setBusinessCode(null); ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, @@ -342,7 +343,7 @@ public class ConfigSourcesController extends BaseRestController { if ("error".equals(msg)) { Exception exception = ConfigSourcesService.getMsgList().get(0); throw new RestServiceException(thread, System.currentTimeMillis() - start, - "存储编译配置时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue()); + "存储编译配置时出现异常" + exception.getMessage(),CompileVal.getBusinessCode()); } Long endSaveTime = System.currentTimeMillis(); Long time = (endSaveTime - benginTime) / 1000; @@ -362,6 +363,7 @@ public class ConfigSourcesController extends BaseRestController { @ApiParam(value = "业务配置数据源", name = "configSource", required = true) public Map updateConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request, HttpServletResponse response) { + CompileVal.setBusinessCode(null); ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, @@ -383,7 +385,7 @@ public class ConfigSourcesController extends BaseRestController { if (msg.equals("error")) { Exception exception = ConfigSourcesService.getMsgList().get(0); throw new RestServiceException(thread, System.currentTimeMillis() - start, - "修改编译配置状态时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue()); + "修改编译配置状态时出现异常" + exception.getMessage(),CompileVal.getBusinessCode()); } // configSourcesService.updateConfigSource(thread, start, // configSource.getConfigCompileList(), @@ -551,17 +553,17 @@ public class ConfigSourcesController extends BaseRestController { @ApiOperation(value = "回调配置存储", httpMethod = "POST", response = Map.class, notes = "回调配置存储服务") public Map createCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, HttpServletResponse response) { + CompileVal.setBusinessCode(null); ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, null); StringBuffer sb = new StringBuffer(); - String msg = configSourcesService.saveCommonSources(thread, start, jsonString, sb); if (msg.equals("error")) { Exception exception = ConfigSourcesService.getMsgList().get(0); throw new RestServiceException(thread, System.currentTimeMillis() - start, - "存储回调配置时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue()); + "存储回调配置时出现异常" + exception.getMessage(), CompileVal.getBusinessCode()); } return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功", Constants.IS_DEBUG ? jsonString : null); @@ -572,17 +574,17 @@ public class ConfigSourcesController extends BaseRestController { @ApiParam(value = "回调配置状态修改", name = "updateStatConfigSource", required = true) public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, HttpServletResponse response) { + CompileVal.setBusinessCode(null); ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, jsonString); StringBuffer sb = new StringBuffer(); - String msg = configSourcesService.updateCommonSources(thread, start, jsonString, new Date(), sb); if (msg.equals("error")) { Exception exception = ConfigSourcesService.getMsgList().get(0); throw new RestServiceException(thread, System.currentTimeMillis() - start, - "修改回调配置状态时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue()); + "修改回调配置状态时出现异常" + exception.getMessage(), CompileVal.getBusinessCode()); } return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置状态修改成功", Constants.IS_DEBUG ? jsonString : null); @@ -604,7 +606,7 @@ public class ConfigSourcesController extends BaseRestController { if (null == file) { thread.setExceptionInfo("请选择上传文件到file参数"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数", - RestBusinessCode.missing_args.getValue()); + RestBusinessCode.FileIsNull.getValue()); } if (!StringUtil.isEmpty(fileDesc.getChecksum())) { @@ -615,7 +617,7 @@ public class ConfigSourcesController extends BaseRestController { if (!md5.equals(fileDesc.getChecksum())) { thread.setExceptionInfo("checksum与文件MD5值不一致"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", - RestBusinessCode.config_integrity_error.getValue()); + RestBusinessCode.CheckSumIsWrong.getValue()); } String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); @@ -650,7 +652,7 @@ public class ConfigSourcesController extends BaseRestController { if (file == null) { thread.setExceptionInfo("请上传获取摘要的文件到file"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数", - RestBusinessCode.missing_args.getValue()); + RestBusinessCode.FileIsNull.getValue()); } JSONObject resultObject = new JSONObject(); FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")), @@ -664,7 +666,7 @@ public class ConfigSourcesController extends BaseRestController { if (!md5.equals(fileDesc.getChecksum())) { thread.setExceptionInfo("checksum与文件MD5值不一致"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", - RestBusinessCode.config_integrity_error.getValue()); + RestBusinessCode.CheckSumIsWrong.getValue()); } String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 59d4ef6..d3357a8 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -1,7 +1,9 @@ package com.nis.web.service.restful; +import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.SQLException; @@ -39,7 +41,6 @@ import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.MaatConfig; import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.StrRegion; -import com.nis.restful.CompileJudgeCode; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; import com.nis.util.BasicProvingUtil; @@ -100,42 +101,42 @@ public class ConfigSourcesService extends BaseService { private StrRegionDao strRegionDao; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - + @Autowired ConfigRedisService configRedisService; - + public static Map> getTableRelation() { Map> tableMap = new HashMap>(); Map typeMap = new HashMap(); typeMap.put("MM_AV_IP", "ip"); tableMap.put(80, typeMap); tableMap.put(144, typeMap); - + typeMap = new HashMap(); typeMap.put("MM_AV_URL", "str"); tableMap.put(81, typeMap); tableMap.put(145, typeMap); - + typeMap = new HashMap(); typeMap.put("MM_PIC_IP", "ip"); tableMap.put(82, typeMap); tableMap.put(146, typeMap); - + typeMap = new HashMap(); typeMap.put("MM_PIC_URL", "str"); tableMap.put(83, typeMap); tableMap.put(147, typeMap); - + typeMap = new HashMap(); typeMap.put("MM_VOIP_IP", "ip"); tableMap.put(84, typeMap); tableMap.put(148, typeMap); - + typeMap = new HashMap(); typeMap.put("MM_VOIP_ACCOUNT", "str"); tableMap.put(85, typeMap); tableMap.put(149, typeMap); - + typeMap = new HashMap(); typeMap.put("REUSE_IP", "ip"); typeMap.put("HID_CONTENT", "ip"); @@ -146,37 +147,36 @@ public class ConfigSourcesService extends BaseService { typeMap.put("CTRL_VOIP_BLACKACCOUNT_REGION", "str"); typeMap.put("CTRL_MEDIA_FILE_FP", "digest"); tableMap.put(0, typeMap); - + typeMap = new HashMap(); typeMap.put("DF_IP_PORT", "ip"); - typeMap.put("GSB_PZ_IP", "ip");//IP复用 + typeMap.put("GSB_PZ_IP", "ip");// IP复用 typeMap.put("CTRL_MEDIA_FILE_FP", "digest"); tableMap.put(1, typeMap); typeMap = new HashMap(); typeMap.put("FX_IP_PORT", "ip"); typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("GSB_PZ_IP", "ip");//网站伪造 + typeMap.put("GSB_PZ_IP", "ip");// 网站伪造 tableMap.put(2, typeMap); - typeMap = new HashMap(); typeMap.put("CTRL_VOIP_BLACKACCOUNT_REGION", "str"); tableMap.put(118, typeMap); - + typeMap = new HashMap(); typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); typeMap.put("UNIVERSAL_IP", "ip"); typeMap.put("DF_HTTP_REQ_HDR", "str"); typeMap.put("DF_HTTP_URL", "str"); - typeMap.put("GSB_PZ_IP", "ip");//内容篡改 + typeMap.put("GSB_PZ_IP", "ip");// 内容篡改 tableMap.put(3, typeMap); typeMap = new HashMap(); typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); typeMap.put("UNIVERSAL_IP", "ip"); typeMap.put("DF_HTTP_RES_HDR", "str"); - typeMap.put("GSB_PZ_IP", "ip");//随机丢包 + typeMap.put("GSB_PZ_IP", "ip");// 随机丢包 typeMap.put("CTRL_URL_REGION", "str"); tableMap.put(4, typeMap); @@ -222,7 +222,7 @@ public class ConfigSourcesService extends BaseService { typeMap.put("UNIVERSAL_IP", "ip"); typeMap.put("FX_HTTP_REQ_HDR", "str"); typeMap.put("FX_HTTP_URL", "str"); - + typeMap.put("WHITE_LIST_IP", "ip"); tableMap.put(15, typeMap); @@ -331,8 +331,7 @@ public class ConfigSourcesService extends BaseService { typeMap.put("DJ_HTTP_RES_BODY", "str"); typeMap.put("DJ_HTTP_URL", "str"); tableMap.put(62, typeMap); - - + typeMap = new HashMap(); typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); typeMap.put("UNIVERSAL_IP", "ip"); @@ -343,8 +342,8 @@ public class ConfigSourcesService extends BaseService { } /** - * 批量(mybatis方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效). - * 符合要求调用updateConfigCompile方法继续验证 + * 批量(mybatis方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效, + * 程序会根据传过来的编译配置和域配置等信息自动设置为无效). 符合要求调用updateConfigCompile方法继续验证 * * @param thread * 保存异常信息入库对象 @@ -355,47 +354,59 @@ public class ConfigSourcesService extends BaseService { * @return * @throws Exception */ - public void updateConfigSource(SaveRequestLogThread thread, long start, List configSource, - Date opTime, StringBuffer sb) { - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + public void updateConfigSource(SaveRequestLogThread thread, long start, + List configSource, Date opTime, StringBuffer sb) { + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); SqlSession batchSqlSession = null; try { - batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, + false); if (null != configSource && configSource.size() > 0) { for (ConfigCompile config : configSource) { String msg = CompileVal.compileIsOk(config, true, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { + if (!"ok".equals(msg)) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), + CompileVal.getBusinessCode()); } - updateConfigCompile(thread, start, config, batchSqlSession, opTime, sb); + updateConfigCompile(thread, start, config, batchSqlSession, + opTime, sb); } } else { thread.setExceptionInfo("编译配置不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "编译配置不能为空" + + sb.toString(), + CompileVal.getBusinessCode()); } logger1.info("数据保存到数据库提交事务开始"); batchSqlSession.commit(); logger1.info("数据保存到数据库成功"); } catch (RestServiceException e) { logger1.error(e); - thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage() + sb.toString(), - e.getErrorCode()); + thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + + sb.toString()); + throw new RestServiceException(thread, System.currentTimeMillis() + - start, e.getMessage() + sb.toString(), e.getErrorCode()); } catch (Exception e) { logger1.error(e); String errorCode = OracleErrorCodeUtil.getOraCode(e); if (!StringUtils.isEmpty(errorCode)) { logger1.error("数据更新发生异常!"); - thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString()); - OracleErrorCodeUtil.throwExceptionInfo(thread, System.currentTimeMillis() - start, errorCode); + thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + + sb.toString()); + OracleErrorCodeUtil.throwExceptionInfo(thread, + System.currentTimeMillis() - start, errorCode); } else { thread.setExceptionInfo("数据更新发生异常" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "数据更新发生异常" + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "数据更新发生异常" + + sb.toString(), RestBusinessCode.unknow_error.getValue()); } } finally { @@ -407,11 +418,15 @@ public class ConfigSourcesService extends BaseService { } /** - * 批量(mybatis方式)修改配置业务逻辑-->2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) + * 批量(mybatis方式)修改配置业务逻辑-->2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效( + * 因为如果数据库中的编译配置与配置分组关系以及域配置均是无效 + * ,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) * 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用) - * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 + * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息, + * 如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 * - * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可) + * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能( + * 方法内注释的代码,如果以后业务需要调整打开下面代码即可) * * @param thread * 保存异常信息入库对象 @@ -423,24 +438,30 @@ public class ConfigSourcesService extends BaseService { * @throws Exception */ - public void updateConfigCompile(SaveRequestLogThread thread, long start, ConfigCompile config, - SqlSession batchSqlSession, Date opTime, StringBuffer sb) throws Exception { + public void updateConfigCompile(SaveRequestLogThread thread, long start, + ConfigCompile config, SqlSession batchSqlSession, Date opTime, + StringBuffer sb) throws Exception { List ipRegionList = config.getIpRegionList(); List strRegionList = config.getStrRegionList(); List numRegionList = config.getNumRegionList(); - List groupRelationList = config.getGroupRelationList(); + List groupRelationList = config + .getGroupRelationList(); if (config.getIsValid() == 1) { if (groupRelationList == null || groupRelationList.size() == 0) { thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "配置分组数量不能为空" + + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } if ((ipRegionList == null || ipRegionList.size() == 0) && (strRegionList == null || strRegionList.size() == 0) && (numRegionList == null || numRegionList.size() == 0)) { thread.setExceptionInfo("域配置数量不能全部为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "域配置数量不能全部为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "域配置数量不能全部为空" + + sb.toString(), + RestBusinessCode.config_integrity_error.getValue()); } } @@ -456,30 +477,37 @@ public class ConfigSourcesService extends BaseService { List queryCompileGroupByPID = configGroupRelationDao .queryCompileGroupByPID(config.getCompileId()); - if (null == queryCompileGroupByPID || queryCompileGroupByPID.size() == 0) { - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "配置id为" + config.getCompileId() + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(), + if (null == queryCompileGroupByPID + || queryCompileGroupByPID.size() == 0) { + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "配置id为" + config.getCompileId() + + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效 - if (null != queryCompileGroupByPID && queryCompileGroupByPID.size() > 0) { + if (null != queryCompileGroupByPID + && queryCompileGroupByPID.size() > 0) { for (ConfigGroupRelation configGroupRelation : queryCompileGroupByPID) { configGroupRelation.setIsValid(0); configGroupRelation.setOpTime(opTime); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { batchSqlSession.getMapper(ConfigGroupRelationDao.class) .updateConfigGroupRelation(configGroupRelation); } } } -// config.setLastUpdate(new Date()); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(ConfigCompileDao.class).updateConfigCompile(config); + // config.setLastUpdate(new Date()); + if (Configurations.getStringProperty("isCommit", "false").equals( + "true")) { + batchSqlSession.getMapper(ConfigCompileDao.class) + .updateConfigCompile(config); } } else { - regionUpdate(thread, start, config, queryCompileGroupByPID, batchSqlSession, opTime, sb); + regionUpdate(thread, start, config, queryCompileGroupByPID, + batchSqlSession, opTime, sb); } // } else {// 数据库中编译配置为无效状态不能进行操作 @@ -503,10 +531,13 @@ public class ConfigSourcesService extends BaseService { * 当前编译下所有的配置分组关系 * @return */ - public void regionUpdate(SaveRequestLogThread thread, long start, ConfigCompile config, - List queryCompileGroupByPID, SqlSession batchSqlSession, Date opTime, StringBuffer sb) + public void regionUpdate(SaveRequestLogThread thread, long start, + ConfigCompile config, + List queryCompileGroupByPID, + SqlSession batchSqlSession, Date opTime, StringBuffer sb) throws Exception { - Map>> regionMap = getRegionList(thread, System.currentTimeMillis() - start, config, + Map>> regionMap = getRegionList(thread, + System.currentTimeMillis() - start, config, queryCompileGroupByPID, batchSqlSession, sb); Map> validMap = regionMap.get("validMap");// 获取该编译配置下所有的配置分组关系及组下有效的域配置id Map> noValidMap = regionMap.get("noValidMap");// 获取该编译配置下所有的配置分组关系及组下无效的域配置id @@ -522,29 +553,39 @@ public class ConfigSourcesService extends BaseService { List tableList = new ArrayList(); for (IpRegion ipRegion : ipRegionList) { if (ipRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(ipRegion.getRegionId())) { + if (null != validList + && validList.contains(ipRegion.getRegionId())) { if (ipRegion.getIsValid() == 0) { ipRegion.setOpTime(opTime); ipRegion.setLastUpdate(new Date()); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(IpRegionDao.class).updateIpRegion(ipRegion); + if (Configurations.getStringProperty( + "isCommit", "false").equals("true")) { + batchSqlSession + .getMapper(IpRegionDao.class) + .updateIpRegion(ipRegion); } count++; - if (!tableList.contains(ipRegion.getTableName())) { + if (!tableList + .contains(ipRegion.getTableName())) { tableList.add(ipRegion.getTableName()); } } - } else if (null != noValidList && noValidList.contains(ipRegion.getRegionId())) { - String msg = "不能修改无效的ip类域配置compile为" + config.getCompileId() + "regionid为" + } else if (null != noValidList + && noValidList.contains(ipRegion.getRegionId())) { + String msg = "不能修改无效的ip类域配置compile为" + + config.getCompileId() + "regionid为" + ipRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } else { - String msg = "找不到对应的的ip类域配置compile为" + config.getCompileId() + "regionid为" + String msg = "找不到对应的的ip类域配置compile为" + + config.getCompileId() + "regionid为" + ipRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } } @@ -556,29 +597,40 @@ public class ConfigSourcesService extends BaseService { List tableList = new ArrayList(); for (StrRegion strRegion : strRegionList) { if (strRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(strRegion.getRegionId())) { + if (null != validList + && validList.contains(strRegion.getRegionId())) { if (strRegion.getIsValid() == 0) { strRegion.setOpTime(opTime); strRegion.setLastUpdate(new Date()); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(StrRegionDao.class).updateStrRegion(strRegion); + if (Configurations.getStringProperty( + "isCommit", "false").equals("true")) { + batchSqlSession.getMapper( + StrRegionDao.class) + .updateStrRegion(strRegion); } count++; - if (!tableList.contains(strRegion.getTableName())) { + if (!tableList.contains(strRegion + .getTableName())) { tableList.add(strRegion.getTableName()); } } - } else if (null != noValidList && noValidList.contains(strRegion.getRegionId())) { - String msg = "不能修改无效的字符串类域配置compile为" + config.getCompileId() + "regionid为" + } else if (null != noValidList + && noValidList + .contains(strRegion.getRegionId())) { + String msg = "不能修改无效的字符串类域配置compile为" + + config.getCompileId() + "regionid为" + strRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } else { - String msg = "找不到对应的的字符串类域配置compile为" + config.getCompileId() + "regionid为" + String msg = "找不到对应的的字符串类域配置compile为" + + config.getCompileId() + "regionid为" + strRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } } @@ -589,30 +641,41 @@ public class ConfigSourcesService extends BaseService { List tableList = new ArrayList(); for (NumRegion numRegion : numRegionList) { if (numRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(numRegion.getRegionId())) { + if (null != validList + && validList.contains(numRegion.getRegionId())) { if (numRegion.getIsValid() == 0) { numRegion.setOpTime(opTime); numRegion.setLastUpdate(new Date()); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(NumRegionDao.class).updateNumRegion(numRegion); + if (Configurations.getStringProperty( + "isCommit", "false").equals("true")) { + batchSqlSession.getMapper( + NumRegionDao.class) + .updateNumRegion(numRegion); } count++; - if (!tableList.contains(numRegion.getTableName())) { + if (!tableList.contains(numRegion + .getTableName())) { tableList.add(numRegion.getTableName()); } } - } else if (null != noValidList && noValidList.contains(numRegion.getRegionId())) { - String msg = "不能修改无效的数值类域配置compile为" + config.getCompileId() + "regionid为" + } else if (null != noValidList + && noValidList + .contains(numRegion.getRegionId())) { + String msg = "不能修改无效的数值类域配置compile为" + + config.getCompileId() + "regionid为" + numRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } else { - String msg = "找不到对应的的数值类域配置compile为" + config.getCompileId() + "regionid为" + String msg = "找不到对应的的数值类域配置compile为" + + config.getCompileId() + "regionid为" + numRegion.getRegionId() + sb.toString(); thread.setExceptionInfo(msg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg, RestBusinessCode.missing_args.getValue()); } } @@ -620,15 +683,19 @@ public class ConfigSourcesService extends BaseService { } if (count == validList.size()) {// 数据库中当前配置分组下有效的域配置,均被修改为无效,所以要将该配置分组置为无效 - List groupRelationList = config.getGroupRelationList(); + List groupRelationList = config + .getGroupRelationList(); for (ConfigGroupRelation configGroupRelation : groupRelationList) { if (configGroupRelation.getGroupId().equals(regionId)) { num++; configGroupRelation.setIsValid(0); configGroupRelation.setOpTime(opTime); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(ConfigGroupRelationDao.class) - .updateConfigGroupRelation(configGroupRelation); + if (Configurations.getStringProperty("isCommit", + "false").equals("true")) { + batchSqlSession.getMapper( + ConfigGroupRelationDao.class) + .updateConfigGroupRelation( + configGroupRelation); } } } @@ -638,22 +705,27 @@ public class ConfigSourcesService extends BaseService { if (num == validMap.size()) {// 所有的域均是无效的所有的组均是无效,需要将编译配置置为无效 config.setIsValid(0); - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { - batchSqlSession.getMapper(ConfigCompileDao.class).updateConfigCompile(config); + if (Configurations.getStringProperty("isCommit", "false").equals( + "true")) { + batchSqlSession.getMapper(ConfigCompileDao.class) + .updateConfigCompile(config); } } } - public Map>> getRegionList(SaveRequestLogThread thread, long start, - ConfigCompile config, List queryCompileGroupByPID, SqlSession batchSqlSession, - StringBuffer sb) { + public Map>> getRegionList( + SaveRequestLogThread thread, long start, ConfigCompile config, + List queryCompileGroupByPID, + SqlSession batchSqlSession, StringBuffer sb) { Map>> map = new HashMap>>(); Map> tableRelationMap = getTableRelation(); - Map updateTableMap = tableRelationMap.get(config.getService().intValue());// 根据service获取需要操作的域配置表 + Map updateTableMap = tableRelationMap.get(config + .getService().intValue());// 根据service获取需要操作的域配置表 if (null == updateTableMap) { thread.setExceptionInfo("找不到编译对应的service" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "找不到编译对应的service" + sb.toString(), RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "找不到编译对应的service" + sb.toString(), + RestBusinessCode.missing_args.getValue()); } Long[] groupId = new Long[queryCompileGroupByPID.size()]; @@ -666,14 +738,17 @@ public class ConfigSourcesService extends BaseService { List numRegionExistList = new ArrayList(); for (String tableName : updateTableMap.keySet()) { if (updateTableMap.get(tableName).equals("ip")) { - List queryIpRegionByGroupId = ipRegionDao.queryIpRegionByGroupId(tableName, groupId); + List queryIpRegionByGroupId = ipRegionDao + .queryIpRegionByGroupId(tableName, groupId); ipRegionExistList.addAll(queryIpRegionByGroupId); } if (updateTableMap.get(tableName).equals("num")) { - numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId(tableName, groupId)); + numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId( + tableName, groupId)); } if (updateTableMap.get(tableName).equals("str")) { - strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId(tableName, groupId)); + strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId( + tableName, groupId)); } } @@ -785,31 +860,33 @@ public class ConfigSourcesService extends BaseService { } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * 批量插入配置编译数据在数据库中循环 * * @param configSource * @throws Exception */ - public void insertConfigSourceData(SaveRequestLogThread thread, long _start, List configSource, - StringBuffer sb) { - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + public void insertConfigSourceData(SaveRequestLogThread thread, + long _start, List configSource, StringBuffer sb) { + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); SqlSession batchSqlSession = null; try { // batchSqlSession = // sqlSessionFactory.openSession(ExecutorType.SIMPLE, false); batchSqlSession = sqlSessionFactory.openSession(); int index = 150; - int count = configSource.size() % index == 0 ? configSource.size() / index - : configSource.size() / index + 1; + int count = configSource.size() % index == 0 ? configSource.size() + / index : configSource.size() / index + 1; for (int i = 0; i < count; i++) { int start = i * index; int end = i * index + index; if (end > configSource.size()) { end = configSource.size(); } - List compileList = configSource.subList(start, end); + List compileList = configSource.subList(start, + end); insertConfigComLileData(thread, _start, compileList, sb); // logger1.info(insertConfigComLile); } @@ -820,19 +897,23 @@ public class ConfigSourcesService extends BaseService { } catch (RestServiceException e) { logger1.error(e); - thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - _start, e.getMessage() + sb.toString(), - e.getErrorCode()); + thread.setExceptionInfo(e.getMessage() + " " + e.getCause() + + sb.toString()); + throw new RestServiceException(thread, System.currentTimeMillis() + - _start, e.getMessage() + sb.toString(), e.getErrorCode()); } catch (Exception e) { logger1.error(e); String errorCode = OracleErrorCodeUtil.getOraCode(e); if (!StringUtils.isEmpty(errorCode)) { thread.setExceptionInfo("数据保存发生异常" + sb.toString()); - OracleErrorCodeUtil.throwExceptionInfo(thread, System.currentTimeMillis() - _start, errorCode); + OracleErrorCodeUtil.throwExceptionInfo(thread, + System.currentTimeMillis() - _start, errorCode); } else { thread.setExceptionInfo("数据保存发生异常" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - _start, "数据保存发生异常" + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - _start, "数据保存发生异常" + + sb.toString(), RestBusinessCode.unknow_error.getValue()); } @@ -852,8 +933,9 @@ public class ConfigSourcesService extends BaseService { * @return * @throws Exception */ - private String insertConfigComLileData(SaveRequestLogThread thread, long start, - List configCompileList, StringBuffer sb) throws Exception { + private String insertConfigComLileData(SaveRequestLogThread thread, + long start, List configCompileList, StringBuffer sb) + throws Exception { List groupRelationList = new ArrayList(); Map> strRegionMap = new HashMap>(); @@ -863,68 +945,91 @@ public class ConfigSourcesService extends BaseService { for (ConfigCompile configCompile : configCompileList) { String msg = CompileVal.compileIsOk(configCompile, false, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { + if (!"ok".equals(msg)) { logger1.error(msg); thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + msg + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } - if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0) { + if (null != configCompile.getGroupRelationList() + && configCompile.getGroupRelationList().size() > 0) { groupRelationList.addAll(configCompile.getGroupRelationList()); } else { logger1.error("配置分组数量不能为空" + sb.toString()); thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "配置分组数量不能为空" + + sb.toString(), RestBusinessCode.missing_args.getValue()); } - if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) { + if (null != configCompile.getStrRegionList() + && configCompile.getStrRegionList().size() > 0) { for (StrRegion strRegion : configCompile.getStrRegionList()) { if (!isStrStrongRegion(strRegion.getTableName())) { if (strRegion.getRegionId() == null) { - String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString(); + String errorMsg = "字符类域配置id不能为空 ,表名---" + + strRegion.getTableName() + "" + + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, RestBusinessCode.missing_args.getValue()); } if (strRegionMap.containsKey(strRegion.getTableName())) { - strRegionMap.get(strRegion.getTableName()).add(strRegion); + strRegionMap.get(strRegion.getTableName()).add( + strRegion); } else { List strRegionList = new ArrayList(); strRegionList.add(strRegion); - strRegionMap.put(strRegion.getTableName(), strRegionList); + strRegionMap.put(strRegion.getTableName(), + strRegionList); } } else { if (strRegion.getRegionId() == null) { - String errorMsg = "增强字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString(); + String errorMsg = "增强字符类域配置id不能为空 ,表名---" + + strRegion.getTableName() + "" + + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, RestBusinessCode.missing_args.getValue()); } - if (strStongRegionMap.containsKey(strRegion.getTableName())) { - strStongRegionMap.get(strRegion.getTableName()).add(strRegion); + if (strStongRegionMap.containsKey(strRegion + .getTableName())) { + strStongRegionMap.get(strRegion.getTableName()) + .add(strRegion); } else { List strStrongRegionList = new ArrayList(); strStrongRegionList.add(strRegion); - strStongRegionMap.put(strRegion.getTableName(), strStrongRegionList); + strStongRegionMap.put(strRegion.getTableName(), + strStrongRegionList); } } } } - if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) { + if (null != configCompile.getIpRegionList() + && configCompile.getIpRegionList().size() > 0) { for (IpRegion ipRegion : configCompile.getIpRegionList()) { - if (!ipRegion.getTableName().toUpperCase().equals("DJ_IP_PORT")) { + if (!ipRegion.getTableName().toUpperCase() + .equals("DJ_IP_PORT")) { ipRegion.setProtocol(0); } if (ipRegion.getRegionId() == null) { - String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString(); + String errorMsg = "ip类域配置id不能为空 ,表名---" + + ipRegion.getTableName() + "" + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, errorMsg, RestBusinessCode.missing_args.getValue()); } @@ -938,27 +1043,33 @@ public class ConfigSourcesService extends BaseService { } } - if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) { + if (null != configCompile.getNumRegionList() + && configCompile.getNumRegionList().size() > 0) { for (NumRegion numRegion : configCompile.getNumRegionList()) { if (numRegion.getRegionId() == null) { - String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString(); + String errorMsg = "数值类域配置id不能为空 ,表名---" + + numRegion.getTableName() + "" + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, errorMsg, RestBusinessCode.missing_args.getValue()); } if (numRegionMap.containsKey(numRegion.getTableName())) { - numRegionMap.get(numRegion.getTableName()).add(numRegion); + numRegionMap.get(numRegion.getTableName()).add( + numRegion); } else { List numRegionList = new ArrayList(); numRegionList.add(numRegion); - numRegionMap.put(numRegion.getTableName(), numRegionList); + numRegionMap.put(numRegion.getTableName(), + numRegionList); } } } } - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { configCompileDao.saveCompileBatch(configCompileList); if (groupRelationList.size() > 0) { for (ConfigGroupRelation group : groupRelationList) { @@ -966,36 +1077,43 @@ public class ConfigSourcesService extends BaseService { } } for (String str : strRegionMap.keySet()) { - strRegionDao.saveStrRegionBatch(strRegionMap.get(str).get(0).getTableName(), strRegionMap.get(str)); + strRegionDao.saveStrRegionBatch(strRegionMap.get(str).get(0) + .getTableName(), strRegionMap.get(str)); } for (String strStrong : strStongRegionMap.keySet()) { - strRegionDao.saveStrStrongRegionBatch(strStongRegionMap.get(strStrong).get(0).getTableName(), + strRegionDao.saveStrStrongRegionBatch( + strStongRegionMap.get(strStrong).get(0).getTableName(), strStongRegionMap.get(strStrong)); } for (String ip : ipRegionMap.keySet()) { - ipRegionDao.saveIpRegionBatch(ipRegionMap.get(ip).get(0).getTableName(), ipRegionMap.get(ip)); + ipRegionDao.saveIpRegionBatch(ipRegionMap.get(ip).get(0) + .getTableName(), ipRegionMap.get(ip)); } for (String num : numRegionMap.keySet()) { - numRegionDao.saveNumRegionBatch(numRegionMap.get(num).get(0).getTableName(), numRegionMap.get(num)); + numRegionDao.saveNumRegionBatch(numRegionMap.get(num).get(0) + .getTableName(), numRegionMap.get(num)); } } return "编译配置数据验证成功"; } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public Page queryAllCompile(Page page, ConfigCompileTest entity) + public Page queryAllCompile( + Page page, ConfigCompileTest entity) throws SQLException { entity.setPage(page); - page.setList(configCompileDao.queryAllCompile(entity.getSearchEndTime(), entity.getSearchStartTime(), + page.setList(configCompileDao.queryAllCompile( + entity.getSearchEndTime(), entity.getSearchStartTime(), entity.getService(), entity.getCompileId())); return page; } public List queryAllCompile(ConfigCompileTest entity) { - return configCompileDao.queryAllCompile(entity.getSearchEndTime(), entity.getSearchStartTime(), - entity.getService(), entity.getCompileId()); + return configCompileDao.queryAllCompile(entity.getSearchEndTime(), + entity.getSearchStartTime(), entity.getService(), + entity.getCompileId()); } public List queryConfigCompileByIdArr(String compileIdArr) { @@ -1006,18 +1124,22 @@ public class ConfigSourcesService extends BaseService { return configGroupRelationDao.queryCompileGroupByPID(compileId); } - public List getStrRegionByGId(List tableList, Long[] groupId) { + public List getStrRegionByGId(List tableList, + Long[] groupId) { List strRegionList = new ArrayList(); if (null != tableList && tableList.size() > 0) { for (String tableName : tableList) { List queryStrRegionByGroupId = null; if (isStrStrongRegion(tableName)) { - queryStrRegionByGroupId = strRegionDao.queryStrStrongRegionByGroupId(tableName, groupId); + queryStrRegionByGroupId = strRegionDao + .queryStrStrongRegionByGroupId(tableName, groupId); } else { - queryStrRegionByGroupId = strRegionDao.queryStrRegionByGroupId(tableName, groupId); + queryStrRegionByGroupId = strRegionDao + .queryStrRegionByGroupId(tableName, groupId); } - if (null != queryStrRegionByGroupId && queryStrRegionByGroupId.size() > 0) { + if (null != queryStrRegionByGroupId + && queryStrRegionByGroupId.size() > 0) { for (StrRegion strRegion : queryStrRegionByGroupId) { strRegion.setTableName(tableName); strRegionList.add(strRegion); @@ -1031,7 +1153,8 @@ public class ConfigSourcesService extends BaseService { } public List getIpRegionByGId(String table, Long[] groupId) { - List queryIpRegionByGroupId = ipRegionDao.queryIpRegionByGroupId(table, groupId); + List queryIpRegionByGroupId = ipRegionDao + .queryIpRegionByGroupId(table, groupId); for (IpRegion ipRegion : queryIpRegionByGroupId) { ipRegion.setTableName(table); } @@ -1039,7 +1162,8 @@ public class ConfigSourcesService extends BaseService { } public List getNumRegionByGId(String table, Long[] groupId) { - List queryNumRegionByGroupId = numRegionDao.queryNumRegionByGroupId(table, groupId); + List queryNumRegionByGroupId = numRegionDao + .queryNumRegionByGroupId(table, groupId); for (NumRegion numRegion : queryNumRegionByGroupId) { numRegion.setTableName(table); } @@ -1105,426 +1229,548 @@ public class ConfigSourcesService extends BaseService { * @param sb * @return */ - public String saveMaatConfig(SaveRequestLogThread thread, long start, List configCompileList, - StringBuffer sb) { -// List maatConfigList = new ArrayList(); -// List serviceList = new ArrayList(); + public String saveMaatConfig(SaveRequestLogThread thread, long start, + List configCompileList, StringBuffer sb) { + // List maatConfigList = new ArrayList(); + // List serviceList = new ArrayList(); Map> maatMap = new HashMap>(); - - for (ConfigCompile configCompile : configCompileList) { - Integer service = Integer.valueOf(configCompile.getService().toString()); - MaatConfig maatConfig = new MaatConfig(); - String msg = CompileVal.compileIsOk(configCompile, false, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { - logger1.error(msg); - thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); - } - - if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) { - logger1.error("配置分组数量不能为空" + sb.toString()); - thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(), - RestBusinessCode.missing_args.getValue()); - } - if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) { - for (StrRegion strRegion : configCompile.getStrRegionList()) { - if (strRegion.getRegionId() == null) { - String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString(); - logger1.error(errorMsg); - thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, - RestBusinessCode.missing_args.getValue()); - } - } - } - - if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) { - for (IpRegion ipRegion : configCompile.getIpRegionList()) { - if (ipRegion.getRegionId() == null) { - String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString(); - logger1.error(errorMsg); - thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, - RestBusinessCode.missing_args.getValue()); - } - } - } - - if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) { - for (NumRegion numRegion : configCompile.getNumRegionList()) { - if (numRegion.getRegionId() == null) { - String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString(); - logger1.error(errorMsg); - thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, - RestBusinessCode.missing_args.getValue()); - } - } - } - if (null != configCompile.getDigestRegionList() && configCompile.getDigestRegionList().size() > 0) { - for (DigestRegion digestRegion : configCompile.getDigestRegionList()) { - if (digestRegion.getRegionId() == null) { - String errorMsg = "摘要类域配置id不能为空 ,表名---" + digestRegion.getTableName() + "" + sb.toString(); - logger1.error(errorMsg); - thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, - RestBusinessCode.missing_args.getValue()); - } - } - } - - if (null != configCompile.getIpClientRangeList() && configCompile.getIpClientRangeList().size() > 0) { - for (IpRegion ipRegion : configCompile.getIpClientRangeList()) { - if (ipRegion.getRegionId() == null) { - String errorMsg = "生效范围IP域类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString(); - logger1.error(errorMsg); - thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, - RestBusinessCode.missing_args.getValue()); - } - } - } - - maatConfig.setService(service); - //编译 - maatConfig.setCompileMap(convertObjectToMap(configCompile, ConfigCompile.class)); - //分组 - List> dstMaplList = null; - if (!StringUtil.isEmpty(configCompile.getGroupRelationList())) { - dstMaplList = new ArrayList>(); - for (ConfigGroupRelation group : configCompile.getGroupRelationList()) { - dstMaplList.add(convertObjectToMap(group, ConfigGroupRelation.class)); - } - } - maatConfig.setGroupMapList(dstMaplList); - //字符串域 - dstMaplList = null; - List> strongMapList = null; - if (!StringUtil.isEmpty(configCompile.getStrRegionList())) { - dstMaplList = new ArrayList>(); - for (StrRegion region : configCompile.getStrRegionList()) { - if(StringUtil.isEmpty(region.getDistrict())){ - dstMaplList.add(convertObjectToMap(region, StrRegion.class)); - }else{ - if (StringUtil.isEmpty(strongMapList)) { - strongMapList = new ArrayList>(); - } - strongMapList.add(convertObjectToMap(region, StrRegion.class)); - } - } - } - maatConfig.setStrRegionMapList(dstMaplList); -// 增强字符串域 - if (!StringUtil.isEmpty(strongMapList)&&strongMapList.size()>0) { - maatConfig.setStrStrRegionMapList((strongMapList)); - } - //数值域 - dstMaplList = null; - if (!StringUtil.isEmpty(configCompile.getNumRegionList())) { - dstMaplList = new ArrayList>(); - for (NumRegion region : configCompile.getNumRegionList()) { - dstMaplList.add(convertObjectToMap(region, NumRegion.class)); - } - } - maatConfig.setNumRegionMapList(dstMaplList); - - //Ip域 - dstMaplList = null; - if (!StringUtil.isEmpty(configCompile.getIpRegionList())) { - dstMaplList = new ArrayList>(); - for (IpRegion region : configCompile.getIpRegionList()) { - dstMaplList.add(convertObjectToMap(region, IpRegion.class)); - } - } - maatConfig.setIpRegionMapList(dstMaplList); - - //摘要类域 - dstMaplList = null; - if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) { - dstMaplList = new ArrayList>(); - for (DigestRegion region : configCompile.getDigestRegionList()) { - dstMaplList.add(convertObjectToMap(region, DigestRegion.class)); - } - } - - maatConfig.setFileDigestRegionMapList(dstMaplList); - - //文本相似性域 -// dstMaplList = null; -// maatConfig.setFileLikeRegionMapList(dstMaplList); - - - //生效范围IP域 - dstMaplList = null; - if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) { - dstMaplList = new ArrayList>(); - for (IpRegion region : configCompile.getIpClientRangeList()) { - dstMaplList.add(convertObjectToMap(region, IpRegion.class)); - } - } - maatConfig.setIpClientRangeMapList(dstMaplList); - - if (maatMap.containsKey(service)) { - maatMap.get(service).add(maatConfig); - }else{ - List maatCfgList = new ArrayList(); - maatCfgList.add(maatConfig); - maatMap.put(service, maatCfgList); - - } - } - - - //调用接口入redis Map> configMap = new HashMap>(); - Iterator serviceIterator = maatMap.keySet().iterator(); - while (serviceIterator.hasNext()) { - Integer service =Integer.valueOf(serviceIterator.next().toString()); - List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); - if (!StringUtil.isEmpty(dbIndexList)&&dbIndexList.size()>0) { - for (Integer dbIndex : dbIndexList) { - //分发到阀门有些业务需要添加编译属性到域配置 - List newMaatConfigList = new ArrayList(); - newMaatConfigList.addAll(maatMap.get(service)); - if (dbIndex.intValue()==ServiceAndRDBIndexReal.getValveDBIndex().intValue()) { - Map> maatToValueMap = ServiceAndRDBIndexReal.getMaatToValveMap(); - if (maatToValueMap.containsKey(service)) { - - Map regionAndFiledMap = maatToValueMap.get(service); - //for (MaatConfig maatConfig : newMaatConfigList) { - for (int i = 0; i > listMaps =new ArrayList>(); - listMaps.addAll((List>) object); - String [] fields = regionAndFiledMap.get(regionName); - for (String fieldName : fields) { - String value = newMaatConfig.getCompileMap().get(fieldName.toLowerCase()); - if (!StringUtil.isEmpty(value)) { - for (Map map: listMaps) { - map.put(fieldName.toLowerCase(), value); + CompileVal.setBusinessCode(null); + try { + + for (ConfigCompile configCompile : configCompileList) { + Integer service = Integer.valueOf(configCompile.getService() + .toString()); + MaatConfig maatConfig = new MaatConfig(); + String msg = CompileVal.compileIsOk(configCompile, false, sb); + if (!"ok".equals(msg)) { + logger1.error(msg); + thread.setExceptionInfo(msg + sb.toString()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), + CompileVal.getBusinessCode()); + } + + if (!(null != configCompile.getGroupRelationList() && configCompile + .getGroupRelationList().size() > 0)) { + logger1.error("配置分组列表不能为空" + sb.toString()); + thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "配置分组列表不能为空" + + sb.toString(), + RestBusinessCode.CompileGroupIsNull.getValue()); + } + if (null != configCompile.getStrRegionList() + && configCompile.getStrRegionList().size() > 0) { + for (StrRegion strRegion : configCompile.getStrRegionList()) { + if (strRegion.getRegionId() == null) { + String errorMsg = "字符类域配置id不能为空 ,表名---" + + strRegion.getTableName() + "" + + sb.toString(); + logger1.error(errorMsg); + thread.setExceptionInfo(errorMsg); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, + RestBusinessCode.RegionIdIsNull.getValue()); + } + } + } + + if (null != configCompile.getIpRegionList() + && configCompile.getIpRegionList().size() > 0) { + for (IpRegion ipRegion : configCompile.getIpRegionList()) { + if (ipRegion.getRegionId() == null) { + String errorMsg = "ip类域配置id不能为空 ,表名---" + + ipRegion.getTableName() + "" + + sb.toString(); + logger1.error(errorMsg); + thread.setExceptionInfo(errorMsg); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, + RestBusinessCode.RegionIdIsNull.getValue()); + } + } + } + + if (null != configCompile.getNumRegionList() + && configCompile.getNumRegionList().size() > 0) { + for (NumRegion numRegion : configCompile.getNumRegionList()) { + if (numRegion.getRegionId() == null) { + String errorMsg = "数值类域配置id不能为空 ,表名---" + + numRegion.getTableName() + "" + + sb.toString(); + logger1.error(errorMsg); + thread.setExceptionInfo(errorMsg); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, + RestBusinessCode.RegionIdIsNull.getValue()); + } + } + } + if (null != configCompile.getDigestRegionList() + && configCompile.getDigestRegionList().size() > 0) { + for (DigestRegion digestRegion : configCompile + .getDigestRegionList()) { + if (digestRegion.getRegionId() == null) { + String errorMsg = "摘要类域配置id不能为空 ,表名---" + + digestRegion.getTableName() + "" + + sb.toString(); + logger1.error(errorMsg); + thread.setExceptionInfo(errorMsg); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, + RestBusinessCode.RegionIdIsNull.getValue()); + } + } + } + + if (null != configCompile.getIpClientRangeList() + && configCompile.getIpClientRangeList().size() > 0) { + for (IpRegion ipRegion : configCompile + .getIpClientRangeList()) { + if (ipRegion.getRegionId() == null) { + String errorMsg = "生效范围IP域类域配置id不能为空 ,表名---" + + ipRegion.getTableName() + "" + + sb.toString(); + logger1.error(errorMsg); + thread.setExceptionInfo(errorMsg); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, + RestBusinessCode.RegionIdIsNull.getValue()); + } + } + } + + maatConfig.setService(service); + // 编译 + maatConfig.setCompileMap(convertObjectToMap(configCompile, + ConfigCompile.class)); + // 分组 + List> dstMaplList = null; + if (!StringUtil.isEmpty(configCompile.getGroupRelationList())) { + dstMaplList = new ArrayList>(); + for (ConfigGroupRelation group : configCompile + .getGroupRelationList()) { + dstMaplList.add(convertObjectToMap(group, + ConfigGroupRelation.class)); + } + } + maatConfig.setGroupMapList(dstMaplList); + // 字符串域 + dstMaplList = null; + List> strongMapList = null; + if (!StringUtil.isEmpty(configCompile.getStrRegionList())) { + dstMaplList = new ArrayList>(); + for (StrRegion region : configCompile.getStrRegionList()) { + if (StringUtil.isEmpty(region.getDistrict())) { + dstMaplList.add(convertObjectToMap(region, + StrRegion.class)); + } else { + if (StringUtil.isEmpty(strongMapList)) { + strongMapList = new ArrayList>(); + } + strongMapList.add(convertObjectToMap(region, + StrRegion.class)); + } + } + } + maatConfig.setStrRegionMapList(dstMaplList); + // 增强字符串域 + if (!StringUtil.isEmpty(strongMapList) + && strongMapList.size() > 0) { + maatConfig.setStrStrRegionMapList((strongMapList)); + } + // 数值域 + dstMaplList = null; + if (!StringUtil.isEmpty(configCompile.getNumRegionList())) { + dstMaplList = new ArrayList>(); + for (NumRegion region : configCompile.getNumRegionList()) { + dstMaplList.add(convertObjectToMap(region, + NumRegion.class)); + } + } + maatConfig.setNumRegionMapList(dstMaplList); + + // Ip域 + dstMaplList = null; + if (!StringUtil.isEmpty(configCompile.getIpRegionList())) { + dstMaplList = new ArrayList>(); + for (IpRegion region : configCompile.getIpRegionList()) { + dstMaplList.add(convertObjectToMap(region, + IpRegion.class)); + } + } + maatConfig.setIpRegionMapList(dstMaplList); + + // 摘要类域 + dstMaplList = null; + if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) { + dstMaplList = new ArrayList>(); + for (DigestRegion region : configCompile + .getDigestRegionList()) { + dstMaplList.add(convertObjectToMap(region, + DigestRegion.class)); + } + } + + maatConfig.setFileDigestRegionMapList(dstMaplList); + + // 文本相似性域 + // dstMaplList = null; + // maatConfig.setFileLikeRegionMapList(dstMaplList); + + // 生效范围IP域 + dstMaplList = null; + if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) { + dstMaplList = new ArrayList>(); + for (IpRegion region : configCompile.getIpClientRangeList()) { + dstMaplList.add(convertObjectToMap(region, + IpRegion.class)); + } + } + maatConfig.setIpClientRangeMapList(dstMaplList); + + if (maatMap.containsKey(service)) { + maatMap.get(service).add(maatConfig); + } else { + List maatCfgList = new ArrayList(); + maatCfgList.add(maatConfig); + maatMap.put(service, maatCfgList); + + } + } + + // 调用接口入redis + + Iterator serviceIterator = maatMap.keySet().iterator(); + while (serviceIterator.hasNext()) { + Integer service = Integer.valueOf(serviceIterator.next() + .toString()); + List dbIndexList = ServiceAndRDBIndexReal + .getRedisDBByService(service); + if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { + for (Integer dbIndex : dbIndexList) { + // 分发到阀门有些业务需要添加编译属性到域配置 + List newMaatConfigList = new ArrayList(); + newMaatConfigList.addAll(maatMap.get(service)); + if (dbIndex.intValue() == ServiceAndRDBIndexReal + .getValveDBIndex().intValue()) { + Map> maatToValueMap = ServiceAndRDBIndexReal + .getMaatToValveMap(); + if (maatToValueMap.containsKey(service)) { + + Map regionAndFiledMap = maatToValueMap + .get(service); + // for (MaatConfig maatConfig : + // newMaatConfigList) { + for (int i = 0; i < newMaatConfigList.size(); i++) { + MaatConfig maatConfig = newMaatConfigList + .get(i); + MaatConfig newMaatConfig = (MaatConfig) JsonMapper + .fromJsonString(JsonMapper + .toJsonString(maatConfig), + MaatConfig.class); + Iterator iterator = regionAndFiledMap + .keySet().iterator(); + while (iterator.hasNext()) { + String regionName = iterator.next() + .toString(); + PropertyDescriptor pd; + try { + pd = new PropertyDescriptor( + regionName + "MapList", + MaatConfig.class); + Method method = pd.getReadMethod(); + Object object = method + .invoke(newMaatConfig); + + if (object != null) { + + List> listMaps = new ArrayList>(); + listMaps.addAll((List>) object); + String[] fields = regionAndFiledMap + .get(regionName); + for (String fieldName : fields) { + String value = newMaatConfig + .getCompileMap() + .get(fieldName + .toLowerCase()); + if (!StringUtil + .isEmpty(value)) { + for (Map map : listMaps) { + map.put(fieldName + .toLowerCase(), + value); + } } } + method = pd.getWriteMethod(); + method.invoke(newMaatConfig, + listMaps); } - method = pd.getWriteMethod(); - method.invoke(newMaatConfig, listMaps); + newMaatConfigList.set(i, + newMaatConfig); + } catch (Exception e) { + // TODO Auto-generated catch block + CompileVal.setBusinessCode(30000); + e = new RuntimeException( + "未找到域列表,请检查域类型是否正确!"); + msgList.add(e); + return "error"; } - newMaatConfigList.set(i, newMaatConfig); - } catch (Exception e) { - // TODO Auto-generated catch block - e = new RuntimeException("未找到域列表,请检查域类型是否正确!"); - msgList.add(e); - return "error"; + } - } } } + + if (configMap.containsKey(dbIndex)) { + configMap.get(dbIndex).addAll(newMaatConfigList); + } else { + List list = new ArrayList(); + list.addAll(newMaatConfigList); + configMap.put(dbIndex, list); + } + } - - if (configMap.containsKey(dbIndex)) { - configMap.get(dbIndex).addAll(newMaatConfigList); - }else{ - List list = new ArrayList(); - list.addAll(newMaatConfigList); - configMap.put(dbIndex, list); - } - + } else { + RuntimeException e = new RuntimeException( + "service与写入数据库序号映射关系不存在"); + CompileVal.setBusinessCode(30000); + msgList.add(e); + return "error"; } - }else { - RuntimeException e = new RuntimeException("service与写入数据库序号映射关系不存在"); - msgList.add(e); - return "error"; } + } catch (Exception e) { + // TODO: handle exception + msgList.add(e); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + return "error"; } try { logger1.info("---------------调用maat配置新增接口---------------------"); configRedisService.saveMaatConfig(configMap); } catch (Exception e) { // TODO: handle exception + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(30000); + } logger1.error(e.getMessage()); msgList.add(e); return "error"; } return "ok"; } - private Map convertObjectToMap(Object obj,Class clazz){ - Map dstMap = new HashMap(); - try { - Field[] fields= obj.getClass().getDeclaredFields(); - for (Field field : fields) { - if("serialVersionUID".equals(field.getName())) - continue; - String dstName = CamelUnderlineUtil.camelToUnderline(field.getName()); - PropertyDescriptor pd; - pd = new PropertyDescriptor(field.getName(), clazz); - Method method = pd.getReadMethod(); - Object dstObject = method.invoke(obj); - if (dstObject instanceof Date) { - dstObject = convertToTimeStamp16((Date)dstObject); - }if(dstObject instanceof ArrayList){ - dstObject = ""; - } - dstMap.put(dstName, StringUtil.isEmpty(dstObject)?"":dstObject.toString()); + + private Map convertObjectToMap(Object obj, Class clazz) + throws IntrospectionException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + Map dstMap = new HashMap(); + Field[] fields = obj.getClass().getDeclaredFields(); + for (Field field : fields) { + if ("serialVersionUID".equals(field.getName())) + continue; + String dstName = CamelUnderlineUtil.camelToUnderline(field + .getName()); + PropertyDescriptor pd; + pd = new PropertyDescriptor(field.getName(), clazz); + Method method = pd.getReadMethod(); + Object dstObject = method.invoke(obj); + if (dstObject instanceof Date) { + dstObject = convertToTimeStamp16((Date) dstObject); } - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - logger1.error(e.getMessage()); + if (dstObject instanceof ArrayList) { + dstObject = ""; + } + dstMap.put(dstName, + StringUtil.isEmpty(dstObject) ? "" : dstObject.toString()); } return dstMap; } - - public String updateConfigSources(SaveRequestLogThread thread, long start, List compileList, - Date opTime, StringBuffer sb) { + + public String updateConfigSources(SaveRequestLogThread thread, long start, + List compileList, Date opTime, StringBuffer sb) { Map> compileMap = new HashMap>(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { String msg = checkCompileOptForUpdate(config); - if (config.getOpTime()==null) { + if (config.getOpTime() == null) { config.setOpTime(opTime); } if (!msg.equals("ok")) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), + CompileVal.getBusinessCode()); } - - //compileAllList.add(config); + + // compileAllList.add(config); if (compileMap.containsKey(config.getService())) { - compileMap.get(config.getService()).add(config.getCompileId()); + compileMap.get(config.getService()).add( + config.getCompileId()); } else { List idList = new ArrayList(); idList.add(config.getCompileId()); compileMap.put(config.getService(), idList); } } - + } else { thread.setExceptionInfo("编译配置不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "编译配置不能为空" + sb.toString(), + RestBusinessCode.CompileIsNull.getValue()); } Map>> restMap = new HashMap>>(); Iterator serviceIterator = compileMap.keySet().iterator(); while (serviceIterator.hasNext()) { - Integer service =Integer.valueOf(serviceIterator.next().toString()); - List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); - if (!StringUtil.isEmpty(dbIndexList)&&dbIndexList.size()>0) { + Integer service = Integer + .valueOf(serviceIterator.next().toString()); + List dbIndexList = ServiceAndRDBIndexReal + .getRedisDBByService(service); + if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { for (Integer dbIndex : dbIndexList) { if (restMap.containsKey(dbIndex)) { - restMap.get(dbIndex).put(service, compileMap.get(service)); - }else{ + restMap.get(dbIndex).put(service, + compileMap.get(service)); + } else { Map> map = new HashMap>(); map.put(service, compileMap.get(service)); restMap.put(dbIndex, map); } } - }else { - RuntimeException e = new RuntimeException("service值为"+service+",与写入数据库序号映射关系不存在"); + } else { + RuntimeException e = new RuntimeException("service值为" + service + + ",与写入数据库序号映射关系不存在"); + CompileVal.setBusinessCode(30000); msgList.add(e); return "error"; } } try { - if(!configRedisService.delMaatConfig(restMap)){ + if (!configRedisService.delMaatConfig(restMap)) { RuntimeException e = new RuntimeException("不存在映射关系"); + CompileVal.setBusinessCode(30000); msgList.add(e); return "error"; } } catch (RuntimeException e) { // TODO: handle exception logger1.error(e.getMessage()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(30000); + } msgList.add(e); return "error"; } return "ok"; } - public String saveByJDBCThread(SaveRequestLogThread thread, long start, List configCompileList, - StringBuffer sb) { + + public String saveByJDBCThread(SaveRequestLogThread thread, long start, + List configCompileList, StringBuffer sb) { List groupRelationList = new ArrayList(); Map> strRegionMap = new HashMap>(); Map> strStongRegionMap = new HashMap>(); Map> ipRegionMap = new HashMap>(); Map> numRegionMap = new HashMap>(); Map> digestRegionMap = new HashMap>(); + for (ConfigCompile configCompile : configCompileList) { String msg = CompileVal.compileIsOk(configCompile, false, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { + if (!"ok".equals(msg)) { logger1.error(msg); thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + msg + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } - if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0) { + if (null != configCompile.getGroupRelationList() + && configCompile.getGroupRelationList().size() > 0) { groupRelationList.addAll(configCompile.getGroupRelationList()); } else { logger1.error("配置分组数量不能为空" + sb.toString()); thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "配置分组数量不能为空" + + sb.toString(), RestBusinessCode.missing_args.getValue()); } - if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) { + if (null != configCompile.getStrRegionList() + && configCompile.getStrRegionList().size() > 0) { for (StrRegion strRegion : configCompile.getStrRegionList()) { if (!isStrStrongRegion(strRegion.getTableName())) { if (strRegion.getRegionId() == null) { - String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString(); + String errorMsg = "字符类域配置id不能为空 ,表名---" + + strRegion.getTableName() + "" + + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, RestBusinessCode.missing_args.getValue()); } if (strRegionMap.containsKey(strRegion.getTableName())) { - strRegionMap.get(strRegion.getTableName()).add(strRegion); + strRegionMap.get(strRegion.getTableName()).add( + strRegion); } else { List strRegionList = new ArrayList(); strRegionList.add(strRegion); - strRegionMap.put(strRegion.getTableName(), strRegionList); + strRegionMap.put(strRegion.getTableName(), + strRegionList); } } else { if (strRegion.getRegionId() == null) { - String errorMsg = "增强字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString(); + String errorMsg = "增强字符类域配置id不能为空 ,表名---" + + strRegion.getTableName() + "" + + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + errorMsg, RestBusinessCode.missing_args.getValue()); } - if (strStongRegionMap.containsKey(strRegion.getTableName())) { - strStongRegionMap.get(strRegion.getTableName()).add(strRegion); + if (strStongRegionMap.containsKey(strRegion + .getTableName())) { + strStongRegionMap.get(strRegion.getTableName()) + .add(strRegion); } else { List strStrongRegionList = new ArrayList(); strStrongRegionList.add(strRegion); - strStongRegionMap.put(strRegion.getTableName(), strStrongRegionList); + strStongRegionMap.put(strRegion.getTableName(), + strStrongRegionList); } } } } - if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) { + if (null != configCompile.getIpRegionList() + && configCompile.getIpRegionList().size() > 0) { for (IpRegion ipRegion : configCompile.getIpRegionList()) { - if (!ipRegion.getTableName().toUpperCase().equals("DJ_IP_PORT")) { + if (!ipRegion.getTableName().toUpperCase() + .equals("DJ_IP_PORT")) { ipRegion.setProtocol(0); } if (ipRegion.getRegionId() == null) { - String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString(); + String errorMsg = "ip类域配置id不能为空 ,表名---" + + ipRegion.getTableName() + "" + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, errorMsg, RestBusinessCode.missing_args.getValue()); } @@ -1538,48 +1784,62 @@ public class ConfigSourcesService extends BaseService { } } - if (null != configCompile.getNumRegionList() && configCompile.getNumRegionList().size() > 0) { + if (null != configCompile.getNumRegionList() + && configCompile.getNumRegionList().size() > 0) { for (NumRegion numRegion : configCompile.getNumRegionList()) { if (numRegion.getRegionId() == null) { - String errorMsg = "数值类域配置id不能为空 ,表名---" + numRegion.getTableName() + "" + sb.toString(); + String errorMsg = "数值类域配置id不能为空 ,表名---" + + numRegion.getTableName() + "" + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, errorMsg, RestBusinessCode.missing_args.getValue()); } if (numRegionMap.containsKey(numRegion.getTableName())) { - numRegionMap.get(numRegion.getTableName()).add(numRegion); + numRegionMap.get(numRegion.getTableName()).add( + numRegion); } else { List numRegionList = new ArrayList(); numRegionList.add(numRegion); - numRegionMap.put(numRegion.getTableName(), numRegionList); + numRegionMap.put(numRegion.getTableName(), + numRegionList); } } } - - if (null != configCompile.getDigestRegionList() && configCompile.getDigestRegionList().size() > 0) { - for (DigestRegion digestRegion : configCompile.getDigestRegionList()) { + + if (null != configCompile.getDigestRegionList() + && configCompile.getDigestRegionList().size() > 0) { + for (DigestRegion digestRegion : configCompile + .getDigestRegionList()) { if (digestRegion.getRegionId() == null) { - String errorMsg = "摘要类域配置id不能为空 ,表名---" + digestRegion.getTableName() + "" + sb.toString(); + String errorMsg = "摘要类域配置id不能为空 ,表名---" + + digestRegion.getTableName() + "" + + sb.toString(); logger1.error(errorMsg); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg, + throw new RestServiceException(thread, + System.currentTimeMillis() - start, errorMsg, RestBusinessCode.missing_args.getValue()); } - if (digestRegionMap.containsKey(digestRegion.getTableName())) { - digestRegionMap.get(digestRegion.getTableName()).add(digestRegion); + if (digestRegionMap + .containsKey(digestRegion.getTableName())) { + digestRegionMap.get(digestRegion.getTableName()).add( + digestRegion); } else { List digestRegionList = new ArrayList(); digestRegionList.add(digestRegion); - digestRegionMap.put(digestRegion.getTableName(), digestRegionList); + digestRegionMap.put(digestRegion.getTableName(), + digestRegionList); } } } } - - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { int count = 0; if (null != configCompileList && configCompileList.size() > 0) { count += 1; @@ -1599,22 +1859,25 @@ public class ConfigSourcesService extends BaseService { if (null != numRegionMap && numRegionMap.size() > 0) { count += numRegionMap.size(); } - + if (null != digestRegionMap && digestRegionMap.size() > 0) { count += digestRegionMap.size(); } - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); Connection conn = sqlSessionFactory.openSession().getConnection(); CountDownLatch latch = new CountDownLatch(count); - SaveCompileByJDBCThread compile = new SaveCompileByJDBCThread(conn, latch, start); + SaveCompileByJDBCThread compile = new SaveCompileByJDBCThread(conn, + latch, start); compile.setCompileList(configCompileList); Thread compileThread = new Thread(compile); compileThread.start(); if (groupRelationList.size() > 0) { - SaveCompileByJDBCThread group = new SaveCompileByJDBCThread(conn, latch, start); + SaveCompileByJDBCThread group = new SaveCompileByJDBCThread( + conn, latch, start); group.setGroupList(groupRelationList); Thread groupThread = new Thread(group); @@ -1624,7 +1887,8 @@ public class ConfigSourcesService extends BaseService { if (strRegionMap.size() > 0) { for (String str : strRegionMap.keySet()) { - SaveCompileByJDBCThread strRegion = new SaveCompileByJDBCThread(false, str, conn, latch, start); + SaveCompileByJDBCThread strRegion = new SaveCompileByJDBCThread( + false, str, conn, latch, start); strRegion.setStrRegionList(strRegionMap.get(str)); Thread strThread = new Thread(strRegion); strThread.start(); @@ -1633,9 +1897,10 @@ public class ConfigSourcesService extends BaseService { } if (strStongRegionMap.size() > 0) { for (String strStrong : strStongRegionMap.keySet()) { - SaveCompileByJDBCThread strongRegion = new SaveCompileByJDBCThread(true, strStrong, conn, latch, - start); - strongRegion.setStrRegionList(strStongRegionMap.get(strStrong)); + SaveCompileByJDBCThread strongRegion = new SaveCompileByJDBCThread( + true, strStrong, conn, latch, start); + strongRegion.setStrRegionList(strStongRegionMap + .get(strStrong)); Thread strongStrThread = new Thread(strongRegion); strongStrThread.start(); @@ -1643,7 +1908,8 @@ public class ConfigSourcesService extends BaseService { } if (ipRegionMap.size() > 0) { for (String ip : ipRegionMap.keySet()) { - SaveCompileByJDBCThread ipRegion = new SaveCompileByJDBCThread(ip, conn, latch, start); + SaveCompileByJDBCThread ipRegion = new SaveCompileByJDBCThread( + ip, conn, latch, start); ipRegion.setIpRegionList(ipRegionMap.get(ip)); Thread ipThread = new Thread(ipRegion); ipThread.start(); @@ -1652,7 +1918,8 @@ public class ConfigSourcesService extends BaseService { } if (numRegionMap.size() > 0) { for (String num : numRegionMap.keySet()) { - SaveCompileByJDBCThread numRegion = new SaveCompileByJDBCThread(num, conn, latch, start); + SaveCompileByJDBCThread numRegion = new SaveCompileByJDBCThread( + num, conn, latch, start); numRegion.setNumRegionList(numRegionMap.get(num)); Thread numThread = new Thread(numRegion); numThread.start(); @@ -1661,14 +1928,16 @@ public class ConfigSourcesService extends BaseService { } if (digestRegionMap.size() > 0) { for (String digest : digestRegionMap.keySet()) { - SaveCompileByJDBCThread digestRegion = new SaveCompileByJDBCThread(digest, conn, latch, start); - digestRegion.setDigestRegionList(digestRegionMap.get(digest)); + SaveCompileByJDBCThread digestRegion = new SaveCompileByJDBCThread( + digest, conn, latch, start); + digestRegion.setDigestRegionList(digestRegionMap + .get(digest)); Thread digestThread = new Thread(digestRegion); digestThread.start(); } } - + try { latch.await(); if (msgList.size() > 0) { @@ -1682,7 +1951,8 @@ public class ConfigSourcesService extends BaseService { e.printStackTrace(); logger1.error(e); if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据插入失败", + e = new RestServiceException(thread, + System.currentTimeMillis() - start, "编译配置数据插入失败", RestBusinessCode.unknow_error.getValue()); } throw ((RestServiceException) e); @@ -1690,23 +1960,26 @@ public class ConfigSourcesService extends BaseService { } return "ok"; } - - private String convertToTimeStamp16(Date date){ -// sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - return date.getTime()+"000"; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + private String convertToTimeStamp16(Date date) { + // sdf.setTimeZone(TimeZone.getTimeZone("UTC")); + return date.getTime() + "000"; + } + + // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** - * 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效). - * 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) + * 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效, + * 程序会根据传过来的编译配置和域配置等信息自动设置为无效). + * 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效 + * ,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) * 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用) - * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 + * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息, + * 如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 * * * - * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可) + * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能( + * 方法内注释的代码,如果以后业务需要调整打开下面代码即可) * * @param thread * 保存异常信息入库对象 @@ -1717,8 +1990,8 @@ public class ConfigSourcesService extends BaseService { * @return * @throws Exception */ - public String updateByJDBCThread(SaveRequestLogThread thread, long start, List compileList, - Date opTime, StringBuffer sb) { + public String updateByJDBCThread(SaveRequestLogThread thread, long start, + List compileList, Date opTime, StringBuffer sb) { List compileAllList = new ArrayList(); List groupRelationAllList = new ArrayList(); Map> strRegionMap = new HashMap>(); @@ -1727,27 +2000,37 @@ public class ConfigSourcesService extends BaseService { if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { String msg = CompileVal.compileIsOk(config, true, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { + if (!"ok".equals(msg)) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } List ipRegionList = config.getIpRegionList();// 获取编译下所有ip类域配置(要修改的数据) List strRegionList = config.getStrRegionList();// 获取编译下所有字符串类域配置(要修改的数据 List numRegionList = config.getNumRegionList();// 获取编译下所有数值类域配置(要修改的数据 - List groupRelationList = config.getGroupRelationList(); + List groupRelationList = config + .getGroupRelationList(); if (config.getIsValid() == 1) { - if (groupRelationList == null || groupRelationList.size() == 0) { + if (groupRelationList == null + || groupRelationList.size() == 0) { thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "配置分组数量不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + "配置分组数量不能为空" + sb.toString(), + RestBusinessCode.config_integrity_error + .getValue()); } if ((ipRegionList == null || ipRegionList.size() == 0) && (strRegionList == null || strRegionList.size() == 0) && (numRegionList == null || numRegionList.size() == 0)) { thread.setExceptionInfo("域配置数量不能全部为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "域配置数量不能全部为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + "域配置数量不能全部为空" + sb.toString(), + RestBusinessCode.config_integrity_error + .getValue()); } } @@ -1757,20 +2040,26 @@ public class ConfigSourcesService extends BaseService { // if (configCompile.getIsValid() == 1) {// // 数据库中编译配置为有效状态才可以进行修改操作 /** - * 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志 + * 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效, + * 否则不修改域配置是否生效标志 * 2:编译配置置为有效,不修改编译配置状态(编译配置不能从无效变有效,只能从有效变无效)仅修改编译配置其他属性, */ List queryCompileGroupByPID = configGroupRelationDao .queryCompileGroupByPID(config.getCompileId()); - if (null == queryCompileGroupByPID || queryCompileGroupByPID.size() == 0) { - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "配置id为" + config.getCompileId() + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + sb.toString(), + if (null == queryCompileGroupByPID + || queryCompileGroupByPID.size() == 0) { + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "配置id为" + + config.getCompileId() + + "的配置在数据库中找不到对应的配置分组关系,请检查json串是否正确" + + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效 - if (null != queryCompileGroupByPID && queryCompileGroupByPID.size() > 0) { + if (null != queryCompileGroupByPID + && queryCompileGroupByPID.size() > 0) { for (ConfigGroupRelation configGroupRelation : queryCompileGroupByPID) { configGroupRelation.setIsValid(0); @@ -1780,10 +2069,12 @@ public class ConfigSourcesService extends BaseService { } } else { - Map>> regionMap = getRegionList(thread, - System.currentTimeMillis() - start, config, queryCompileGroupByPID, sb); + Map>> regionMap = getRegionList( + thread, System.currentTimeMillis() - start, config, + queryCompileGroupByPID, sb); Map> validMap = regionMap.get("validMap");// 获取该编译配置下所有的配置分组关系及组下有效的域配置id - Map> noValidMap = regionMap.get("noValidMap");// 获取该编译配置下所有的配置分组关系及组下无效的域配置id + Map> noValidMap = regionMap + .get("noValidMap");// 获取该编译配置下所有的配置分组关系及组下无效的域配置id int num = 0; for (Long regionId : validMap.keySet()) {// 遍历配置分组 @@ -1793,30 +2084,54 @@ public class ConfigSourcesService extends BaseService { if (null != ipRegionList && ipRegionList.size() > 0) { for (IpRegion ipRegion : ipRegionList) { if (ipRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(ipRegion.getRegionId())) { + if (null != validList + && validList.contains(ipRegion + .getRegionId())) { if (ipRegion.getIsValid() == 0) { ipRegion.setLastUpdate(new Date()); - if (ipRegionMap.containsKey(ipRegion.getTableName())) { - ipRegionMap.get(ipRegion.getTableName()).add(ipRegion); + if (ipRegionMap + .containsKey(ipRegion + .getTableName())) { + ipRegionMap + .get(ipRegion + .getTableName()) + .add(ipRegion); } else { List ipList = new ArrayList(); ipList.add(ipRegion); - ipRegionMap.put(ipRegion.getTableName(), ipList); + ipRegionMap + .put(ipRegion + .getTableName(), + ipList); } count++; } - } else if (null != noValidList && noValidList.contains(ipRegion.getRegionId())) { - String errorMsg = "不能修改无效的ip类域配置compile为" + config.getCompileId() + "regionid为" - + ipRegion.getRegionId() + sb.toString(); + } else if (null != noValidList + && noValidList.contains(ipRegion + .getRegionId())) { + String errorMsg = "不能修改无效的ip类域配置compile为" + + config.getCompileId() + + "regionid为" + + ipRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } else { - String errorMsg = "找不到对应的的ip类域配置compile为" + config.getCompileId() + "regionid为" - + ipRegion.getRegionId() + sb.toString(); + String errorMsg = "找不到对应的的ip类域配置compile为" + + config.getCompileId() + + "regionid为" + + ipRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } } } @@ -1826,31 +2141,54 @@ public class ConfigSourcesService extends BaseService { if (null != strRegionList && strRegionList.size() > 0) { for (StrRegion strRegion : strRegionList) { if (strRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(strRegion.getRegionId())) { + if (null != validList + && validList.contains(strRegion + .getRegionId())) { if (strRegion.getIsValid() == 0) { strRegion.setLastUpdate(new Date()); - if (strRegionMap.containsKey(strRegion.getTableName())) { - strRegionMap.get(strRegion.getTableName()).add(strRegion); + if (strRegionMap + .containsKey(strRegion + .getTableName())) { + strRegionMap + .get(strRegion + .getTableName()) + .add(strRegion); } else { List strList = new ArrayList(); strList.add(strRegion); - strRegionMap.put(strRegion.getTableName(), strList); + strRegionMap.put(strRegion + .getTableName(), + strList); } count++; } - } else if (null != noValidList && noValidList.contains(strRegion.getRegionId())) { - String errorMsg = "不能修改无效的字符串类域配置compile为" + config.getCompileId() + "regionid为" - + strRegion.getRegionId() + sb.toString(); + } else if (null != noValidList + && noValidList.contains(strRegion + .getRegionId())) { + String errorMsg = "不能修改无效的字符串类域配置compile为" + + config.getCompileId() + + "regionid为" + + strRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } else { - String errorMsg = "找不到对应的的字符串类域配置compile为" + config.getCompileId() + "regionid为" - + strRegion.getRegionId() + sb.toString(); + String errorMsg = "找不到对应的的字符串类域配置compile为" + + config.getCompileId() + + "regionid为" + + strRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } } } @@ -1859,43 +2197,68 @@ public class ConfigSourcesService extends BaseService { if (null != numRegionList && numRegionList.size() > 0) { for (NumRegion numRegion : numRegionList) { if (numRegion.getGroupId().equals(regionId)) { - if (null != validList && validList.contains(numRegion.getRegionId())) { + if (null != validList + && validList.contains(numRegion + .getRegionId())) { if (numRegion.getIsValid() == 0) { numRegion.setLastUpdate(new Date()); - if (numRegionMap.containsKey(numRegion.getTableName())) { - numRegionMap.get(numRegion.getTableName()).add(numRegion); + if (numRegionMap + .containsKey(numRegion + .getTableName())) { + numRegionMap + .get(numRegion + .getTableName()) + .add(numRegion); } else { List numList = new ArrayList(); numList.add(numRegion); - numRegionMap.put(numRegion.getTableName(), numList); + numRegionMap.put(numRegion + .getTableName(), + numList); } count++; } - } else if (null != noValidList && noValidList.contains(numRegion.getRegionId())) { - String errorMsg = "不能修改无效的数值类域配置compile为" + config.getCompileId() + "regionid为" - + numRegion.getRegionId() + sb.toString(); + } else if (null != noValidList + && noValidList.contains(numRegion + .getRegionId())) { + String errorMsg = "不能修改无效的数值类域配置compile为" + + config.getCompileId() + + "regionid为" + + numRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } else { - String errorMsg = "找不到对应的的数值类域配置compile为" + config.getCompileId() + "regionid为" - + numRegion.getRegionId() + sb.toString(); + String errorMsg = "找不到对应的的数值类域配置compile为" + + config.getCompileId() + + "regionid为" + + numRegion.getRegionId() + + sb.toString(); thread.setExceptionInfo(errorMsg); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - errorMsg, RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() + - start, errorMsg, + RestBusinessCode.missing_args + .getValue()); } } } } if (count == validList.size()) {// 数据库中当前配置分组下有效的域配置,均被修改为无效,所以要将该配置分组置为无效 for (ConfigGroupRelation configGroupRelation : groupRelationList) { - if (configGroupRelation.getGroupId().equals(regionId)) { + if (configGroupRelation.getGroupId().equals( + regionId)) { num++; configGroupRelation.setIsValid(0); - groupRelationAllList.add(configGroupRelation); + groupRelationAllList + .add(configGroupRelation); } } @@ -1916,11 +2279,13 @@ public class ConfigSourcesService extends BaseService { } else { thread.setExceptionInfo("编译配置不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "编译配置不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } // 程序是否入库,测试分析数据的时间 - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { int count = 0; if (null != compileAllList && compileAllList.size() > 0) { count += 1; @@ -1938,16 +2303,19 @@ public class ConfigSourcesService extends BaseService { count += numRegionMap.size(); } - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); Connection conn = sqlSessionFactory.openSession().getConnection(); CountDownLatch latch = new CountDownLatch(count); - UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); compileThread.setCompileList(compileAllList); Thread compile = new Thread(compileThread); compile.start(); if (null != groupRelationAllList && groupRelationAllList.size() > 0) { - UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); groupThread.setGroupList(groupRelationAllList); Thread group = new Thread(groupThread); group.start(); @@ -1955,8 +2323,8 @@ public class ConfigSourcesService extends BaseService { } if (null != strRegionMap && strRegionMap.size() > 0) { for (String str : strRegionMap.keySet()) { - UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread(str, conn, latch, start, - opTime); + UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread( + str, conn, latch, start, opTime); strRegion.setStrRegionList(strRegionMap.get(str)); Thread strThread = new Thread(strRegion); strThread.start(); @@ -1965,7 +2333,8 @@ public class ConfigSourcesService extends BaseService { if (null != ipRegionMap && ipRegionMap.size() > 0) { for (String ip : ipRegionMap.keySet()) { - UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread(ip, conn, latch, start, opTime); + UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread( + ip, conn, latch, start, opTime); ipRegion.setIpRegionList(ipRegionMap.get(ip)); Thread ipThread = new Thread(ipRegion); ipThread.start(); @@ -1974,8 +2343,8 @@ public class ConfigSourcesService extends BaseService { } if (null != numRegionMap && numRegionMap.size() > 0) { for (String num : numRegionMap.keySet()) { - UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread(num, conn, latch, start, - opTime); + UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread( + num, conn, latch, start, opTime); numRegion.setNumRegionList(numRegionMap.get(num)); Thread numThread = new Thread(numRegion); numThread.start(); @@ -1995,7 +2364,8 @@ public class ConfigSourcesService extends BaseService { e.printStackTrace(); logger1.error(e); if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败", + e = new RestServiceException(thread, + System.currentTimeMillis() - start, "编译配置数据修改失败", RestBusinessCode.unknow_error.getValue()); } throw ((RestServiceException) e); @@ -2006,23 +2376,29 @@ public class ConfigSourcesService extends BaseService { } /** - * 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效,程序会根据传过来的编译配置和域配置等信息自动设置为无效). - * 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) + * 批量(jdbc多线程方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效, + * 程序会根据传过来的编译配置和域配置等信息自动设置为无效). + * 2:判断配置在数据库中是否已经是无效了如果是无效则提示不能修改无效的配置为有效(因为如果数据库中的编译配置与配置分组关系以及域配置均是无效 + * ,传过来的数据是编译配置和配置分组关系是有效,域配置是无效,这样会将数据库中无效的编译配置置为有效,这是不允许的) * 3:如果编译配置置为无效将所有的配置分组关系置为无效,不修改域配置状态(分组复用考虑,域可能被其他的组引用) - * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息,如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 + * 4:如果编译配置为有效,域配置为无效,则先获取该编译配置下各个配置分组关系下的所有有效的域配置信息和所有无效的域配置信息, + * 如果数据库中有效的域配置信息和前端传过来置为无效的的域配置信息个数,id都相等,则将对应域配置,配置分组关系,编译配置均置为无效 * * * - * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能(方法内注释的代码,如果以后业务需要调整打开下面代码即可) + * 20161124讨论暂时先去掉2步骤,因为界面目前传过来的数据编译配置,配置分组关系,域配置均是无效,所以就不执行第2步骤了影响性能( + * 方法内注释的代码,如果以后业务需要调整打开下面代码即可) * * * - * 20161215讨论确定修改时前端发过来的配置都是无效的不会存在即有无效又有有效的情况,且配置中的个数与添加时保持一致,即添加时插入了1条编译配置2条配置分组关系3条域配置,在修改时也会传过来1条编译配置2条配置分组关系3条域配置,不会多或者少配置 + * 20161215讨论确定修改时前端发过来的配置都是无效的不会存在即有无效又有有效的情况,且配置中的个数与添加时保持一致, + * 即添加时插入了1条编译配置2条配置分组关系3条域配置,在修改时也会传过来1条编译配置2条配置分组关系3条域配置,不会多或者少配置 * * * * - * 2017-1-16:和杨老师讨论确定存在分组复用情况,当编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志 + * 2017-1-16:和杨老师讨论确定存在分组复用情况,当编译配置置为无效,需要将其下所有配置分组置为无效, + * 如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志 * * @param thread * 保存异常信息入库对象 @@ -2033,8 +2409,8 @@ public class ConfigSourcesService extends BaseService { * @return * @throws Exception */ - public String updateByJDBCThread12(SaveRequestLogThread thread, long start, List compileList, - Date opTime, StringBuffer sb) { + public String updateByJDBCThread12(SaveRequestLogThread thread, long start, + List compileList, Date opTime, StringBuffer sb) { List compileAllList = new ArrayList(); List groupRelationAllList = new ArrayList(); Map> strRegionMap = new HashMap>(); @@ -2044,19 +2420,24 @@ public class ConfigSourcesService extends BaseService { if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { String msg = CompileVal.compileIsOk(config, true, sb); - if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) { + if (!"ok".equals(msg)) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } /** - * 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效,否则不修改域配置是否生效标志 + * 1:编译配置置为无效,需要将其下所有配置分组置为无效,如果数据中将域配置置为了无效则将域配置置为无效, + * 否则不修改域配置是否生效标志 * 2:编译配置置为有效,不修改编译配置状态(编译配置不能从无效变有效,只能从有效变无效)仅修改编译配置其他属性, */ - List groupRelationList = config.getGroupRelationList(); + List groupRelationList = config + .getGroupRelationList(); if (config.getIsValid() == 0) {// 编译配置修改为无效,需要将所有的配置分组置为无效 - if (null != groupRelationList && groupRelationList.size() > 0) { + if (null != groupRelationList + && groupRelationList.size() > 0) { for (ConfigGroupRelation configGroupRelation : groupRelationList) { configGroupRelation.setIsValid(0); groupRelationAllList.add(configGroupRelation); @@ -2066,12 +2447,15 @@ public class ConfigSourcesService extends BaseService { if (null != ipRegionList && ipRegionList.size() > 0) { for (IpRegion ipRegion : ipRegionList) { if (ipRegion.getIsValid() == 0) { - if (ipRegionMap.containsKey(ipRegion.getTableName())) { - ipRegionMap.get(ipRegion.getTableName()).add(ipRegion); + if (ipRegionMap.containsKey(ipRegion + .getTableName())) { + ipRegionMap.get(ipRegion.getTableName()) + .add(ipRegion); } else { List ipList = new ArrayList(); ipList.add(ipRegion); - ipRegionMap.put(ipRegion.getTableName(), ipList); + ipRegionMap.put(ipRegion.getTableName(), + ipList); } } } @@ -2080,12 +2464,15 @@ public class ConfigSourcesService extends BaseService { if (null != strRegionList && strRegionList.size() > 0) { for (StrRegion strRegion : strRegionList) { if (strRegion.getIsValid() == 0) { - if (strRegionMap.containsKey(strRegion.getTableName())) { - strRegionMap.get(strRegion.getTableName()).add(strRegion); + if (strRegionMap.containsKey(strRegion + .getTableName())) { + strRegionMap.get(strRegion.getTableName()) + .add(strRegion); } else { List strList = new ArrayList(); strList.add(strRegion); - strRegionMap.put(strRegion.getTableName(), strList); + strRegionMap.put(strRegion.getTableName(), + strList); } } } @@ -2094,27 +2481,36 @@ public class ConfigSourcesService extends BaseService { if (null != numRegionList && numRegionList.size() > 0) { for (NumRegion numRegion : numRegionList) { if (numRegion.getIsValid() == 0) { - if (numRegionMap.containsKey(numRegion.getTableName())) { - numRegionMap.get(numRegion.getTableName()).add(numRegion); + if (numRegionMap.containsKey(numRegion + .getTableName())) { + numRegionMap.get(numRegion.getTableName()) + .add(numRegion); } else { List numList = new ArrayList(); numList.add(numRegion); - numRegionMap.put(numRegion.getTableName(), numList); + numRegionMap.put(numRegion.getTableName(), + numList); } } } } - - List digestRegionList = config.getDigestRegionList();// 获取编译下所有摘要类域配置(要修改的数据 + + List digestRegionList = config + .getDigestRegionList();// 获取编译下所有摘要类域配置(要修改的数据 if (null != digestRegionList && digestRegionList.size() > 0) { for (DigestRegion digestRegion : digestRegionList) { if (digestRegion.getIsValid() == 0) { - if (digestRegionMap.containsKey(digestRegion.getTableName())) { - digestRegionMap.get(digestRegion.getTableName()).add(digestRegion); + if (digestRegionMap.containsKey(digestRegion + .getTableName())) { + digestRegionMap.get( + digestRegion.getTableName()).add( + digestRegion); } else { List digestList = new ArrayList(); digestList.add(digestRegion); - digestRegionMap.put(digestRegion.getTableName(), digestList); + digestRegionMap.put( + digestRegion.getTableName(), + digestList); } } } @@ -2125,11 +2521,13 @@ public class ConfigSourcesService extends BaseService { } else { thread.setExceptionInfo("编译配置不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "编译配置不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } // 程序是否入库,测试分析数据的时间 - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { int count = 0; if (null != compileAllList && compileAllList.size() > 0) { count += 1; @@ -2146,16 +2544,19 @@ public class ConfigSourcesService extends BaseService { if (null != numRegionMap && numRegionMap.size() > 0) { count += numRegionMap.size(); } - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); Connection conn = sqlSessionFactory.openSession().getConnection(); CountDownLatch latch = new CountDownLatch(count); - UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); compileThread.setCompileList(compileAllList); Thread compile = new Thread(compileThread); compile.start(); if (null != groupRelationAllList && groupRelationAllList.size() > 0) { - UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); groupThread.setGroupList(groupRelationAllList); Thread group = new Thread(groupThread); group.start(); @@ -2163,8 +2564,8 @@ public class ConfigSourcesService extends BaseService { } if (null != strRegionMap && strRegionMap.size() > 0) { for (String str : strRegionMap.keySet()) { - UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread(str, conn, latch, start, - opTime); + UpdateCompileByJDBCThread strRegion = new UpdateCompileByJDBCThread( + str, conn, latch, start, opTime); strRegion.setStrRegionList(strRegionMap.get(str)); Thread strThread = new Thread(strRegion); strThread.start(); @@ -2173,7 +2574,8 @@ public class ConfigSourcesService extends BaseService { if (null != ipRegionMap && ipRegionMap.size() > 0) { for (String ip : ipRegionMap.keySet()) { - UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread(ip, conn, latch, start, opTime); + UpdateCompileByJDBCThread ipRegion = new UpdateCompileByJDBCThread( + ip, conn, latch, start, opTime); ipRegion.setIpRegionList(ipRegionMap.get(ip)); Thread ipThread = new Thread(ipRegion); ipThread.start(); @@ -2182,8 +2584,8 @@ public class ConfigSourcesService extends BaseService { } if (null != numRegionMap && numRegionMap.size() > 0) { for (String num : numRegionMap.keySet()) { - UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread(num, conn, latch, start, - opTime); + UpdateCompileByJDBCThread numRegion = new UpdateCompileByJDBCThread( + num, conn, latch, start, opTime); numRegion.setNumRegionList(numRegionMap.get(num)); Thread numThread = new Thread(numRegion); numThread.start(); @@ -2191,8 +2593,8 @@ public class ConfigSourcesService extends BaseService { } if (null != digestRegionMap && digestRegionMap.size() > 0) { for (String num : digestRegionMap.keySet()) { - UpdateCompileByJDBCThread digestRegion = new UpdateCompileByJDBCThread(num, conn, latch, start, - opTime); + UpdateCompileByJDBCThread digestRegion = new UpdateCompileByJDBCThread( + num, conn, latch, start, opTime); digestRegion.setDigestRegionList(digestRegionMap.get(num)); Thread digestThread = new Thread(digestRegion); digestThread.start(); @@ -2211,7 +2613,8 @@ public class ConfigSourcesService extends BaseService { e.printStackTrace(); logger1.error(e); if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败", + e = new RestServiceException(thread, + System.currentTimeMillis() - start, "编译配置数据修改失败", RestBusinessCode.unknow_error.getValue()); } throw ((RestServiceException) e); @@ -2233,18 +2636,20 @@ public class ConfigSourcesService extends BaseService { * @param sb * @return */ - public String updateByJDBCThread3(SaveRequestLogThread thread, long start, List compileList, - Date opTime, StringBuffer sb) { + public String updateByJDBCThread3(SaveRequestLogThread thread, long start, + List compileList, Date opTime, StringBuffer sb) { List compileAllList = new ArrayList(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { String msg = checkCompileOptForUpdate(config); - if (config.getOpTime()==null) { + if (config.getOpTime() == null) { config.setOpTime(opTime); } if (!msg.equals("ok")) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + throw new RestServiceException(thread, + System.currentTimeMillis() - start, msg + + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } @@ -2253,30 +2658,34 @@ public class ConfigSourcesService extends BaseService { } else { thread.setExceptionInfo("编译配置不能为空" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "编译配置不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } // 程序是否入库,测试分析数据的时间 - if (Configurations.getStringProperty("isCommit", "false").equals("true")) { + if (Configurations.getStringProperty("isCommit", "false") + .equals("true")) { int count = 0; if (null != compileAllList && compileAllList.size() > 0) { count += 1; - count += 1; //将所有compile与Group的对应关系都置为失效 zdx20170814 + count += 1; // 将所有compile与Group的对应关系都置为失效 zdx20170814 } - - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + + SqlSessionFactory sqlSessionFactory = SpringContextHolder + .getBean(SqlSessionFactory.class); Connection conn = sqlSessionFactory.openSession().getConnection(); CountDownLatch latch = new CountDownLatch(count); - - UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + + UpdateCompileByJDBCThread compileThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); compileThread.setCompileList(compileAllList); Thread compile = new Thread(compileThread); compile.start(); - - UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread(conn, latch, start, opTime); + UpdateCompileByJDBCThread groupThread = new UpdateCompileByJDBCThread( + conn, latch, start, opTime); groupThread.setCompileList(compileAllList); - //仅用做判定线程执行时选择执行方法 zdx20170816 + // 仅用做判定线程执行时选择执行方法 zdx20170816 groupThread.setGroupList(new ArrayList()); Thread group = new Thread(groupThread); group.start(); @@ -2294,7 +2703,8 @@ public class ConfigSourcesService extends BaseService { e.printStackTrace(); logger1.error(e); if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据修改失败", + e = new RestServiceException(thread, + System.currentTimeMillis() - start, "编译配置数据修改失败", RestBusinessCode.unknow_error.getValue()); } throw ((RestServiceException) e); @@ -2303,7 +2713,7 @@ public class ConfigSourcesService extends BaseService { } return "ok"; } - + /** * * @Description:验证compileId+isValid @@ -2313,24 +2723,30 @@ public class ConfigSourcesService extends BaseService { * @return */ private String checkCompileOptForUpdate(ConfigCompile config) { + if (StringUtil.isEmpty(config.getCompileId())) { - return "compileId字段不能为空"; + CompileVal.setBusinessCode(RestBusinessCode.CompileIdIsNull.getValue()); + return RestBusinessCode.CompileIdIsNull.getErrorReason(); } - + if (StringUtil.isEmpty(config.getService())) { - return "service字段不能为空"; + + CompileVal.setBusinessCode(RestBusinessCode.ServiceIsNull.getValue()); + return RestBusinessCode.ServiceIsNull.getErrorReason(); } - + if (StringUtil.isEmpty(config.getIsValid())) { - return "编译配置id为" + config.getCompileId()+"的IsValid字段不能为空"; + CompileVal.setBusinessCode(RestBusinessCode.IsValidIsNull.getValue()); + return "编译配置id为" + config.getCompileId() + "的IsValid字段不能为空"; } if (config.getIsValid() != 0) { + CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue()); return "编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效"; } - + return "ok"; } - + /** * 获取编译配置下所有的配置分组关系对应的有效,无效域配置id * @@ -2344,16 +2760,19 @@ public class ConfigSourcesService extends BaseService { * 当前编译下所有的配置分组关系 * @return */ - public Map>> getRegionList(SaveRequestLogThread thread, long start, - ConfigCompile config, List queryCompileGroupByPID, StringBuffer sb) { + public Map>> getRegionList( + SaveRequestLogThread thread, long start, ConfigCompile config, + List queryCompileGroupByPID, StringBuffer sb) { Map>> map = new HashMap>>(); Map> tableRelationMap = getTableRelation(); - Map updateTableMap = tableRelationMap.get(config.getService().intValue());// 根据service获取需要操作的域配置表 + Map updateTableMap = tableRelationMap.get(config + .getService().intValue());// 根据service获取需要操作的域配置表 if (null == updateTableMap || updateTableMap.size() == 0) { thread.setExceptionInfo("找不到编译对应的service" + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, - "找不到编译对应的service" + sb.toString(), RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, System.currentTimeMillis() + - start, "找不到编译对应的service" + sb.toString(), + RestBusinessCode.missing_args.getValue()); } Long[] groupId = new Long[queryCompileGroupByPID.size()]; @@ -2366,13 +2785,16 @@ public class ConfigSourcesService extends BaseService { List numRegionExistList = new ArrayList(); for (String tableName : updateTableMap.keySet()) { if (updateTableMap.get(tableName).equals("ip")) { - ipRegionExistList.addAll(ipRegionDao.queryIpRegionByGroupId(tableName, groupId)); + ipRegionExistList.addAll(ipRegionDao.queryIpRegionByGroupId( + tableName, groupId)); } if (updateTableMap.get(tableName).equals("num")) { - numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId(tableName, groupId)); + numRegionExistList.addAll(numRegionDao.queryNumRegionByGroupId( + tableName, groupId)); } if (updateTableMap.get(tableName).equals("str")) { - strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId(tableName, groupId)); + strRegionExistList.addAll(strRegionDao.queryStrRegionByGroupId( + tableName, groupId)); } } @@ -2483,9 +2905,10 @@ public class ConfigSourcesService extends BaseService { } - ////////////////////////////////////////////////////////////////////////////// + // //////////////////////////////////////////////////////////////////////////// - public String configModifySources(List configCompileList) throws Exception { + public String configModifySources(List configCompileList) + throws Exception { for (ConfigCompile configCompile : configCompileList) { Long compileId = configCompile.getCompileId(); @@ -2497,213 +2920,312 @@ public class ConfigSourcesService extends BaseService { } return "ok"; } - - public String saveCommonSources(SaveRequestLogThread thread, long start,String jsonString, - StringBuffer sb) { - JsonArray jsonObjectList = new JsonParser().parse(jsonString).getAsJsonArray(); - Map>> dstMaps = new HashMap>>(); + + public String saveCommonSources(SaveRequestLogThread thread, long start, + String jsonString, StringBuffer sb) { + CompileVal.setBusinessCode(null); + JsonArray jsonObjectList = new JsonParser().parse(jsonString) + .getAsJsonArray(); + Map>> dstMaps = new HashMap>>(); for (int i = 0; i < jsonObjectList.size(); i++) { - JsonObject jsonObj=(JsonObject) jsonObjectList.get(i); - Map srcMap = JSONObject.fromObject(JSONObject.fromObject((jsonObj.toString()))); - if(srcMap.containsKey("service")){ - Map dstMap = new HashMap(); - List commonSourceFieldCfgList = ReadCommSourceXmlUtil.getCommonSourceCfgByService(srcMap.get("service").toString().trim()); + JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); + Map srcMap = JSONObject.fromObject(JSONObject + .fromObject((jsonObj.toString()))); + if (srcMap.containsKey("service")) { + Map dstMap = new HashMap(); + List commonSourceFieldCfgList = ReadCommSourceXmlUtil + .getCommonSourceCfgByService(srcMap.get("service") + .toString().trim()); if (StringUtil.isEmpty(commonSourceFieldCfgList)) { - logger1.error("service请检查service配置是否正确"); + logger1.error(RestBusinessCode.ServiceIsWrong.getErrorReason()+",请检查service配置是否正确"); thread.setExceptionInfo("请检查service配置是否正确"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,"请检查service配置是否正确", - RestBusinessCode.wrong_range.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + "请检查service配置是否正确", + RestBusinessCode.ServiceIsWrong.getValue()); } - //获取IP类型 + // 获取IP类型 Integer ipType = null; - String ipTypeName =""; + String ipTypeName = ""; for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { - if(commonSourceFieldCfg.getDstName().equals("ip_type")){ - String dstVal = srcMap.get(commonSourceFieldCfg.getSrcName()).toString(); + if (commonSourceFieldCfg.getDstName().equals("ip_type")) { + String dstVal = srcMap.get( + commonSourceFieldCfg.getSrcName()).toString(); ipTypeName = commonSourceFieldCfg.getSrcName(); - //regexp 特殊格式正则验证 + // regexp 特殊格式正则验证 Boolean valFlag = true; - if(!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())){ - Pattern pattern = Pattern.compile(commonSourceFieldCfg.getRegexp()); + if (!StringUtil.isEmpty(commonSourceFieldCfg + .getRegexp())) { + Pattern pattern = Pattern + .compile(commonSourceFieldCfg.getRegexp()); Matcher matcher = pattern.matcher(dstVal); - valFlag = valFlag&matcher.matches(); + valFlag = valFlag & matcher.matches(); } if (!valFlag) { - logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数格式不正确或数据不在有效范围", - RestBusinessCode.param_formate_error.getValue()); + logger1.error(RestBusinessCode.IpTypeIsWrong + .getErrorReason()); + thread.setExceptionInfo(RestBusinessCode.IpTypeIsWrong + .getErrorReason()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + RestBusinessCode.IpTypeIsWrong + .getErrorReason(), + RestBusinessCode.IpTypeIsWrong + .getValue()); } ipType = Integer.parseInt(dstVal); } } for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { - //是否必填 - if(commonSourceFieldCfg.getIsRequired()&&!srcMap.containsKey(commonSourceFieldCfg.getSrcName())){ - logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能为空"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能为空"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能为空", - RestBusinessCode.missing_args.getValue()); + // 是否必填 + if (commonSourceFieldCfg.getIsRequired() + && !srcMap.containsKey(commonSourceFieldCfg + .getSrcName())) { + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数不能为空"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + "参数不能为空"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + "参数不能为空", + RestBusinessCode.FieldIsNull.getValue()); } - //字段类型 String Number Date Ip Port - String dstStr = StringUtil.isEmpty(srcMap.get(commonSourceFieldCfg.getSrcName()))?commonSourceFieldCfg.getDefaultVal():srcMap.get(commonSourceFieldCfg.getSrcName()).toString(); - if (!StringUtil.isEmpty(dstStr)&&dstStr.startsWith("[")&&dstStr.endsWith("]")) { - dstStr = srcMap.get(dstStr.substring(1, dstStr.length()-1)).toString(); + // 字段类型 String Number Date Ip Port + String dstStr = StringUtil.isEmpty(srcMap + .get(commonSourceFieldCfg.getSrcName())) ? commonSourceFieldCfg + .getDefaultVal() : srcMap.get( + commonSourceFieldCfg.getSrcName()).toString(); + if (!StringUtil.isEmpty(dstStr) && dstStr.startsWith("[") + && dstStr.endsWith("]")) { + dstStr = srcMap.get( + dstStr.substring(1, dstStr.length() - 1)) + .toString(); } switch (commonSourceFieldCfg.getFieldType()) { - case "Number": - if(!StringUtil.isNumeric(dstStr)){ - logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型", - RestBusinessCode.missing_args.getValue()); - } - break; - case "Date": - try { -// sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - System.out.println("--------------------TimeZone:"+sdf.getTimeZone()); - Date date = sdf.parse(dstStr); - dstStr = date.getTime()+"000"; - } catch (ParseException e) { - // TODO Auto-generated catch block - logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必须是日期型", - RestBusinessCode.missing_args.getValue()); - } - break; - case "Ip": - if (!BasicProvingUtil.isIpOrIpMask(dstStr,ipType)) { - logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确或与"+ipTypeName+"不一致"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确或与"+ipTypeName+"不一致"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数格式不正确或与"+ipTypeName+"不一致", - RestBusinessCode.missing_args.getValue()); - } - break; - case "Port": - if (!BasicProvingUtil.isPortOrPortMask(dstStr)) { - logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,不是合法的Port", - RestBusinessCode.missing_args.getValue()); - } - break; - + case "Number": + if (!StringUtil.isNumeric(dstStr)) { + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数不能格式不正确,必需是数值型"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + "参数不能格式不正确,必需是数值型"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + + "参数不能格式不正确,必需是数值型", + RestBusinessCode.MastNumberic.getValue()); + } + break; + case "Date": + try { + // sdf.setTimeZone(TimeZone.getTimeZone("UTC")); + System.out.println("--------------------TimeZone:" + + sdf.getTimeZone()); + Date date = sdf.parse(dstStr); + dstStr = date.getTime() + "000"; + } catch (ParseException e) { + // TODO Auto-generated catch block + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数格式不正确,必须是日期型"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + "参数格式不正确,必须是日期型"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + + "参数不能格式不正确,必须是日期型", + RestBusinessCode.MastDate.getValue()); + } + break; + case "Ip": + if (!BasicProvingUtil.isIpOrIpMask(dstStr, ipType)) { + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数格式不正确或与" + ipTypeName + "不一致"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + + "参数格式不正确或与" + + ipTypeName + + "不一致"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + + "参数格式不正确或与" + ipTypeName + "不一致", + RestBusinessCode.IpIsUnMatchType.getValue()); + } + break; + case "Port": + if (!BasicProvingUtil.isPortOrPortMask(dstStr)) { + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数格式不正确,不是合法的Port"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + "参数格式不正确,不是合法的Port"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + + "参数不能格式不正确,不是合法的Port", + RestBusinessCode.PortIsNotVal.getValue()); + } + break; + } - //range取值范围验证 - if(!StringUtil.isEmpty(commonSourceFieldCfg.getRange())){ - String [] range= commonSourceFieldCfg.getRange().split("-"); + // range取值范围验证 + if (!StringUtil.isEmpty(commonSourceFieldCfg.getRange())) { + String[] range = commonSourceFieldCfg.getRange().split( + "-"); Boolean flag = false; - if (range.length==2) { - if(!(Long.valueOf(range[0]).compareTo(Long.valueOf(dstStr))<=0&&Long.valueOf(range[1]).compareTo(Long.valueOf(dstStr))>=0)){ + if (range.length == 2) { + if (!(Long.valueOf(range[0]).compareTo( + Long.valueOf(dstStr)) <= 0 && Long.valueOf( + range[1]).compareTo(Long.valueOf(dstStr)) >= 0)) { flag = true; } - - }else if (commonSourceFieldCfg.getRange().startsWith("-")) {//只有最大值限制 - if(Long.valueOf(range[0]).compareTo(Long.valueOf(dstStr))<=0){ + + } else if (commonSourceFieldCfg.getRange().startsWith( + "-")) {// 只有最大值限制 + if (Long.valueOf(range[0]).compareTo( + Long.valueOf(dstStr)) <= 0) { flag = true; } - }else if (commonSourceFieldCfg.getRange().endsWith("-")) {//只有最小值限制 - if(Long.valueOf(range[0]).compareTo(Long.valueOf(dstStr))>=0){ + } else if (commonSourceFieldCfg.getRange() + .endsWith("-")) {// 只有最小值限制 + if (Long.valueOf(range[0]).compareTo( + Long.valueOf(dstStr)) >= 0) { flag = true; } } if (flag) { - logger1.error(commonSourceFieldCfg.getSrcName()+"参数不在有效范围("+ commonSourceFieldCfg.getRange()+")"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不在有效范围("+ commonSourceFieldCfg.getRange()+")"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数不在有效范围("+ commonSourceFieldCfg.getRange()+")", - RestBusinessCode.wrong_range.getValue()); + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数不在有效范围(" + + commonSourceFieldCfg.getRange() + ")"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + + "参数不在有效范围(" + + commonSourceFieldCfg.getRange() + ")"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + + "参数不在有效范围(" + + commonSourceFieldCfg.getRange() + + ")", + RestBusinessCode.ValueInWrongRange.getValue()); } } - //regexp 特殊格式正则验证 + // regexp 特殊格式正则验证 Boolean valFlag = true; - if(!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())){ - Pattern pattern = Pattern.compile(commonSourceFieldCfg.getRegexp()); + if (!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())) { + Pattern pattern = Pattern.compile(commonSourceFieldCfg + .getRegexp()); Matcher matcher = pattern.matcher(dstStr); - valFlag = valFlag&matcher.matches(); + valFlag = valFlag & matcher.matches(); } if (valFlag) { - dstMap.put(commonSourceFieldCfg.getDstName(),dstStr); - }else{ - logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则("+commonSourceFieldCfg.getRegexp()+")不匹配"); - thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式与正则("+commonSourceFieldCfg.getRegexp()+")不匹配"); - throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数格式与正则("+commonSourceFieldCfg.getRegexp()+")不匹配", - RestBusinessCode.param_formate_error.getValue()); + dstMap.put(commonSourceFieldCfg.getDstName(), dstStr); + } else { + logger1.error(commonSourceFieldCfg.getSrcName() + + "参数格式与正则(" + commonSourceFieldCfg.getRegexp() + + ")不匹配"); + thread.setExceptionInfo(commonSourceFieldCfg + .getSrcName() + + "参数格式与正则(" + + commonSourceFieldCfg.getRegexp() + ")不匹配"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + commonSourceFieldCfg.getSrcName() + "参数格式与正则(" + + commonSourceFieldCfg.getRegexp() + + ")不匹配", + RestBusinessCode.ValueInWrongRegexp.getValue()); } } - if (StringUtil.isEmpty(dstMaps.get(Integer.valueOf(srcMap.get("service").toString())))) { - List> list = new ArrayList>(); + if (StringUtil.isEmpty(dstMaps.get(Integer.valueOf(srcMap.get( + "service").toString())))) { + List> list = new ArrayList>(); list.add(dstMap); - dstMaps.put(Integer.valueOf(srcMap.get("service").toString()), list); - }else{ - List> list = dstMaps.get(Integer.valueOf(srcMap.get("service").toString())); + dstMaps.put( + Integer.valueOf(srcMap.get("service").toString()), + list); + } else { + List> list = dstMaps.get(Integer + .valueOf(srcMap.get("service").toString())); list.add(dstMap); - + } - }else{ + } else { thread.setExceptionInfo("service参数不能为空"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "service参数不能为空", - RestBusinessCode.missing_args.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, "service参数不能为空", + RestBusinessCode.ServiceIsNull.getValue()); } } logger1.info("------------------调用非maat配置新增接口-------------------"); - //按service分库 + // 按service分库 Map>> configMap = new HashMap>>(); Iterator serviceIterator = dstMaps.keySet().iterator(); while (serviceIterator.hasNext()) { - Integer service =Integer.valueOf(serviceIterator.next().toString()); - List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); - if (!StringUtil.isEmpty(dbIndexList)&&dbIndexList.size()>0) { + Integer service = Integer + .valueOf(serviceIterator.next().toString()); + List dbIndexList = ServiceAndRDBIndexReal + .getRedisDBByService(service); + if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { for (Integer dbIndex : dbIndexList) { if (configMap.containsKey(dbIndex)) { configMap.get(dbIndex).addAll(dstMaps.get(service)); - }else{ + } else { List> list = new ArrayList>(); list.addAll(dstMaps.get(service)); configMap.put(dbIndex, list); } } - }else { - RuntimeException e = new RuntimeException("service与写入数据库序号映射关系不存在"); + } else { + RuntimeException e = new RuntimeException( + "service与写入数据库序号映射关系不存在"); + CompileVal.setBusinessCode(30000); msgList.add(e); return "error"; } - + } try { configRedisService.saveUnMaatConfig(configMap); } catch (Exception e) { // TODO: handle exception logger1.error(e.getMessage()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(30000); + } msgList.add(e); return "error"; } - + return "ok"; } - public String updateCommonSources(SaveRequestLogThread thread, long start,String jsonString, - Date opTime, StringBuffer sb) { + + public String updateCommonSources(SaveRequestLogThread thread, long start, + String jsonString, Date opTime, StringBuffer sb) { JsonArray jsonObjectList = null; try { - jsonObjectList = new JsonParser().parse(jsonString).getAsJsonArray(); + jsonObjectList = new JsonParser().parse(jsonString) + .getAsJsonArray(); } catch (Exception e) { // TODO: handle exception logger1.error(e.getMessage()); + CompileVal.setBusinessCode(30000); thread.setExceptionInfo(e.getMessage() + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage() + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, System.currentTimeMillis() + - start, e.getMessage() + sb.toString(), + CompileVal.getBusinessCode()); } - // + // Map> cfgMap = new HashMap>(); for (int i = 0; i < jsonObjectList.size(); i++) { - JsonObject jsonObj=(JsonObject) jsonObjectList.get(i); - Map srcMap = JSONObject.fromObject(JSONObject.fromObject((jsonObj.toString()))); + JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); + Map srcMap = JSONObject.fromObject(JSONObject + .fromObject((jsonObj.toString()))); String msg = checkOptForUpdate(srcMap); if (!msg.equals("ok")) { thread.setExceptionInfo(msg + sb.toString()); - throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), - RestBusinessCode.config_integrity_error.getValue()); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + msg + sb.toString(), + CompileVal.getBusinessCode()); } Integer service = Integer.valueOf(srcMap.get("service").toString()); Long cfgId = Long.valueOf(srcMap.get("cfgId").toString()); @@ -2715,24 +3237,28 @@ public class ConfigSourcesService extends BaseService { cfgMap.put(service, idList); } } - + Map>> restMap = new HashMap>>(); Iterator serviceIterator = cfgMap.keySet().iterator(); while (serviceIterator.hasNext()) { - Integer service =Integer.valueOf(serviceIterator.next().toString()); - List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); - if (!StringUtil.isEmpty(dbIndexList)&&dbIndexList.size()>0) { + Integer service = Integer + .valueOf(serviceIterator.next().toString()); + List dbIndexList = ServiceAndRDBIndexReal + .getRedisDBByService(service); + if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { for (Integer dbIndex : dbIndexList) { if (restMap.containsKey(dbIndex)) { restMap.get(dbIndex).put(service, cfgMap.get(service)); - }else{ + } else { Map> map = new HashMap>(); map.put(service, cfgMap.get(service)); restMap.put(dbIndex, map); } } - }else { - RuntimeException e = new RuntimeException("service与写入数据库序号映射关系不存在"); + } else { + RuntimeException e = new RuntimeException( + "service与写入数据库序号映射关系不存在"); + CompileVal.setBusinessCode(30000); msgList.add(e); return "error"; } @@ -2742,47 +3268,62 @@ public class ConfigSourcesService extends BaseService { } catch (Exception e) { // TODO: handle exception logger1.error(e.getMessage()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(30000); + } msgList.add(e); return "error"; } return "ok"; } + private String checkOptForUpdate(Map srcMap) { String cfgId = srcMap.get("cfgId").toString(); String service = srcMap.get("service").toString(); String isValid = srcMap.get("isValid").toString(); if (StringUtil.isEmpty(cfgId)) { - return "cfgId字段不能为空"; - }else if(!StringUtil.isNumeric(cfgId)){ - return "cfgId字段格式不正确"; + CompileVal.setBusinessCode(RestBusinessCode.CfgIdIsNull.getValue()); + return RestBusinessCode.CfgIdIsNull.getErrorReason(); + } else if (!StringUtil.isNumeric(cfgId)) { + CompileVal.setBusinessCode(RestBusinessCode.MastNumberic.getValue()); + return "cfgId字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(); } - + if (StringUtil.isEmpty(service)) { - return "service字段不能为空"; - }else if(!StringUtil.isNumeric(service)){ - return "service字段格式不正确"; + CompileVal.setBusinessCode(RestBusinessCode.ServiceIsNull.getValue()); + return RestBusinessCode.ServiceIsNull.getErrorReason(); + } else if (!StringUtil.isNumeric(service)) { + CompileVal.setBusinessCode(RestBusinessCode.MastNumberic.getValue()); + return "service字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(); } - + if (StringUtil.isEmpty(isValid)) { - return "配置id为" + srcMap.get("cfgId")+"的isValid字段不能为空"; - }else { - if(!StringUtil.isNumeric(service)){ - return "isValid字段格式不正确"; - }else if(!isValid.equals("0")){ - return "isValid字段取值只能是0(失效)"; + CompileVal.setBusinessCode(RestBusinessCode.IsValidIsNull.getValue()); + return "配置id为" + srcMap.get("cfgId") + "的isValid字段不能为空"; + } else { + if (!StringUtil.isNumeric(service)) { + CompileVal.setBusinessCode(RestBusinessCode.IsValidInWrongRange.getValue()); + return RestBusinessCode.IsValidInWrongRange.getErrorReason(); + } else if (!isValid.equals("0")) { + CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue()); + return RestBusinessCode.IsValidIsF.getErrorReason(); } } return "ok"; } - private boolean isIp(String ipStr){ - if (!(BasicProvingUtil.isIpOrIpMask(ipStr,4)||BasicProvingUtil.isIpOrIpMask(ipStr,6))) { + + private boolean isIp(String ipStr) { + if (!(BasicProvingUtil.isIpOrIpMask(ipStr, 4) || BasicProvingUtil + .isIpOrIpMask(ipStr, 6))) { return false; } return true; - + } - - public String setCompileInvalid(ConfigCompile configCompile) throws Exception { + + public String setCompileInvalid(ConfigCompile configCompile) + throws Exception { configCompileDao.setCompileInvalid(configCompile.getCompileId(), 0); return "ok"; } @@ -2792,32 +3333,34 @@ public class ConfigSourcesService extends BaseService { return "ok"; } - public String getDigestGen(String realPath,String filePath)throws Exception{ + public String getDigestGen(String realPath, String filePath) + throws Exception { System.out.println("----------------getDigestGen"); - String content=""; - String digestGenToolPath=Constants.DIGEST_GEN_TOOL_PATH; - String chmodCommond="chmod +x "+realPath+digestGenToolPath;//执行权限命令 -// System.out.println("----------------chmodCommod:"+chmodCommond); - String commondStr=realPath+digestGenToolPath+" -f "+filePath; //执行 - //执行摘要获取命令 digest -f /home/aa.txt -// System.out.println("------------commondStr:"+commondStr); + String content = ""; + String digestGenToolPath = Constants.DIGEST_GEN_TOOL_PATH; + String chmodCommond = "chmod +x " + realPath + digestGenToolPath;// 执行权限命令 + // System.out.println("----------------chmodCommod:"+chmodCommond); + String commondStr = realPath + digestGenToolPath + " -f " + filePath; // 执行 + // 执行摘要获取命令 digest -f /home/aa.txt + // System.out.println("------------commondStr:"+commondStr); Runtime.getRuntime().exec(chmodCommond); - Process p=Runtime.getRuntime().exec(commondStr); - byte[] b=new byte[1024]; - StringBuffer sb=new StringBuffer(); + Process p = Runtime.getRuntime().exec(commondStr); + byte[] b = new byte[1024]; + StringBuffer sb = new StringBuffer(); while (p.getInputStream().read(b) != -1) { sb.append(new String(b, "UTF-8")); } - content=sb.toString(); + content = sb.toString(); if (!StringUtil.isBlank(content)) { content = StringUtil.stripAll(content); } -// System.out.println("-------------------->>"+content); - String[] digestGenReslt=content.split(" "); - if(digestGenReslt.length >=4 && !StringUtil.isEmpty(digestGenReslt[3])){ - return digestGenReslt[3]; + // System.out.println("-------------------->>"+content); + String[] digestGenReslt = content.split(" "); + if (digestGenReslt.length >= 4 + && !StringUtil.isEmpty(digestGenReslt[3])) { + return digestGenReslt[3]; } return null; } - + } diff --git a/src/main/resources/commonSources/commonSources.xml b/src/main/resources/commonSources/commonSources.xml index f4f455f..f07bfad 100644 --- a/src/main/resources/commonSources/commonSources.xml +++ b/src/main/resources/commonSources/commonSources.xml @@ -44,6 +44,7 @@ + diff --git a/src/main/resources/serviceTable.properties b/src/main/resources/serviceTable.properties index 6669e19..a7797af 100644 --- a/src/main/resources/serviceTable.properties +++ b/src/main/resources/serviceTable.properties @@ -67,8 +67,8 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16; 544=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;12:PXY_CTRL_IP;18:NTC_IP_RANGE 545=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;14:PXY_CTRL_HTTP_URL;18:NTC_IP_RANGE -560=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;15:PXY_CTRL_HTTP_REQ_BODY;18:NTC_IP_RANGE -561=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;15:PXY_CTRL_HTTP_RES_BODY;18:NTC_IP_RANGE +560=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;14:PXY_CTRL_HTTP_REQ_BODY;18:NTC_IP_RANGE +561=10:PXY_CTRL_COMPILE;11:PXY_CTRL_GROUP;14:PXY_CTRL_HTTP_RES_BODY;18:NTC_IP_RANGE 768=10:IR_POLICY_COMPILE;11:IR_POLICY_GROUP;12:IR_POLICY_IP;18:NTC_IP_RANGE