diff --git a/src/main/java/com/nis/restful/CompileJudgeCode.java b/src/main/java/com/nis/restful/CompileJudgeCode.java deleted file mode 100644 index 139da39..0000000 --- a/src/main/java/com/nis/restful/CompileJudgeCode.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.nis.restful; - -public enum CompileJudgeCode { - /** - * 当前编译配置中的groupNum属性值与配置分组groupList大小不等 - */ - GroupNumNEQGroupList(1, "groupNum属性值与groupRelationList大小不等"), - /** - * 当前编译配置中的groupNum属性值与配置分组groupList大小相等 - */ - GroupNumEQGroupList(2, "groupNum属性值与groupRelationList大小不等"), - /** - * 当前编译配置中的groupNum属性值与配置分组groupList大小均小于等于8且均大于0 - */ - GroupNumAndListLtEight(3, "groupNum属性值与groupRelationList大小均小于等于8且均大于0"), - /** - * 当前编译配置中的groupNum属性值大于8 - */ - GroupNumGtEight(4, "groupNum属性值大于8"), - /** - * 当前编译配置中的配置分组groupList大小大于8 - */ - GroupListGtEight(5, "groupRelationList大小大于8"), - - /** - * 当前编译配置中的groupNum属性值等于0 - */ - GroupNumEQZero(6, "groupNum属性值等于0"), - /** - * 当前编译配置中的配置分组groupList等于0 - */ - GroupListEQZero(7, "groupRelationList大小不能为0"), - - /** - * 配置分组中域配置个数大于0 - */ - CompileGroupSizeGtZero(8, "配置分组中的域配置均正常"), - - /** - * 配置分组中域配置个数为0 - */ - //CompileGroupSizeEqZero(9, "groupRelationList中有一个或多个groupId在strRegionList或ipRegionList或numRegionList中不存在"), - /** - * 配置分组集合中存在相同的配置分组id - */ - CompileGroupIdIsRepeat(10, "groupRelationList中存在相同的groupId"), - /** - * 有域配置中的配置分组id没有对应的配置分组(在配置分组集合中找不到该配置分组id) - */ - //CompileGroupIdNotExist(11, "有一个或多个strRegionList或ipRegionList或numRegionList中的groupId在groupRelationList中不存在"), - - /** - * 配置分组中的compileId与编译配置中的compileId不一致 - */ - //CoupileGroupListPidIsError(12, "groupRelationList中有一个或多个compileId与编译配置中compileId不一致"), - /** - * 配置分组 前台不能设置分组为无效 - */ - CompileGroupNotIsInvalid(13, "配置分组不能设置为无效"), - /** - * 编译为无效 域配置全部不能为无效 - */ - CompileALLIsInvalid(14, "编译配置和域配置不能同时为无效"), - /** - * 编译为有效 域配置至少有一个为无效 - */ - CompileIsValide(15, "当编译为有效时域配置至少有一个为无效"), - /** - * 添加配置不能为无效 - */ - CompileIsNotInvalid(16, "添加时不能为无效"), - /** - * 当编译配置有效时 域配置不能都是空 - */ - CompileNotNull(17, "当编译配置有效时,域配置不能都是空"), - - /** - * 缺少配置分组信息 - */ - CompileGroupIsNull(18, "缺少配置分组信息"), - - /** - * 缺少ip类域配置信息 - */ - IpRegionIsNull(19, "缺少ip类域配置信息"), - - /** - * 缺少字符串类域配置信息 - */ - StrRegionIsNull(20, "缺少字符串类域配置信息"), - - /** - * 缺少数值类域配置信息 - */ - NumRegionIsNull(21, "缺少数值类域配置信息"), - /** - * 编译配置不能为空 - */ - CompileIsNull(22, "编译配置不能为空"), - /** - * groupNum不能为空 - */ - GroupNumIsNull(23, "groupNum不能为空"), - /** - * groupRelationList不能为空 - */ - GroupListIsNull(24, "groupRelationList不能为空"), - /** - * groupRelationList不能为空 - */ - //ServiceType2TableName(25, "域配置中的表名与编译配置的业务类型不一致"), - /** - * 当前编译配置中的groupNum属性与配置分组groupList大小相等且均大于0小于等于8, 且每个配置分组中域配置个数大于0 - */ - CompileIsOk(26, "编译配置完全正确"); - - private final int value; // 错误码 - private String errorReason; // 错误原因 - - public int getValue() { - return value; - } - - public String getErrorReason() { - return errorReason; - } - - public void setErrorReason(String errorReason) { - this.errorReason = errorReason; - } - - private CompileJudgeCode(int value, String errorReason) { - this.value = value; - this.errorReason = errorReason; - } - - public static CompileJudgeCode valueOf(int errorCode) { - for (CompileJudgeCode status : values()) { - if (status.value == errorCode) { - return status; - } - } - throw new IllegalArgumentException("No matching constant for [" + errorCode + "]"); - } -} \ No newline at end of file diff --git a/src/main/java/com/nis/util/CompileJudge.java b/src/main/java/com/nis/util/CompileJudge.java deleted file mode 100644 index 38938ed..0000000 --- a/src/main/java/com/nis/util/CompileJudge.java +++ /dev/null @@ -1,704 +0,0 @@ -package com.nis.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import com.nis.domain.restful.ConfigCompile; -import com.nis.domain.restful.ConfigGroupRelation; -import com.nis.domain.restful.DataDictionaryValue; -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.web.service.restful.ConfigSourcesService; - -public class CompileJudge { - - /** - * 判断当前编译配置中的groupNum属性值与配置分组groupList大小是否小于等于8且大于0 - * - * @param configCompile - * 编译配置对象 - * @return GroupNumAndListLtEight GroupNumGtEight GroupListGtEight - * GroupNumEQZero GroupListEQZero - * - * - */ - @SuppressWarnings("null") - public static String groupNumAndListIsOk(ConfigCompile configCompile, boolean isUpdate) { - if (null != configCompile) { - if (!isUpdate && Constants.BASE_VALIDATE) { - String valCompile = valCompile(configCompile); - if (!valCompile.equals("ok")) { - return valCompile; - } - } - - if (null == configCompile.getGroupRelationList() && null != configCompile.getCompileId()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.CompileGroupIsNull.getErrorReason(); - } - if (!isUpdate) { - if (null == configCompile.getGroupNum()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumIsNull.getErrorReason(); - } - - if (configCompile.getGroupNum() > 8) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumGtEight.getErrorReason(); - } - - if (configCompile.getGroupNum() <= 0) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumEQZero.getErrorReason(); - } - - if (null == configCompile.getGroupRelationList()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListIsNull.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(); - } - - if (configCompile.getGroupRelationList().size() != configCompile.getGroupNum()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumNEQGroupList.getErrorReason(); - } - } else { - if (null == configCompile.getCompileId()) { - return "compileId字段不能为空"; - } - if (null == configCompile.getGroupRelationList()) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListIsNull.getErrorReason(); - } - if (configCompile.getIsValid() == 1) { - if (null != configCompile.getGroupNum() && configCompile.getGroupNum() > 8) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumGtEight.getErrorReason(); - } - if (null != configCompile.getGroupNum() && configCompile.getGroupNum() < 0) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupNumEQZero.getErrorReason(); - } - - if (null != configCompile.getGroupRelationList() - && configCompile.getGroupRelationList().size() > 8) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListGtEight.getErrorReason(); - } - - if (null != configCompile.getGroupRelationList() - && configCompile.getGroupRelationList().size() <= 0) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListEQZero.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(); - } - } - } - } - return CompileJudgeCode.GroupNumAndListLtEight.getErrorReason(); - } else { - return "编译配置id为" + configCompile.getCompileId() + "的" + CompileJudgeCode.CompileIsNull.getErrorReason(); - } - - } - - /** - * 判断编译配置中所有配置分组内域配置个数是否大于0 - * - * @param configCompile - * 编译配置对象 - * @return CompileGroupSizeGtZero CompileGroupSizeEqZero - * CompileGroupIdNotExist CompileGroupIdIsRepeat GroupListEQZero - */ - public static String compileGroupSizeIsGtZero(ConfigCompile configCompile, boolean isUpdate, StringBuffer sb) { - Long compileId = configCompile.getCompileId(); - List groupList = new ArrayList();// 配置分组中groupId集合 - List groupRelationList = configCompile.getGroupRelationList(); - // 插入配置时不能是无效 - if (!isUpdate && configCompile.getIsValid() == 0) { - return "配置id为" + configCompile.getCompileId() + "的配置" - + CompileJudgeCode.CompileIsNotInvalid.getErrorReason(); - } - Integer isValid = configCompile.getIsValid(); - boolean configFlag = false; - if (null == groupRelationList) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.CompileGroupIsNull.getErrorReason(); - } - - if ((!isUpdate) || (isUpdate && configCompile.getIsValid() == 1)) {// 添加或者修改域配置 - if (groupRelationList.size() > 0) { - for (ConfigGroupRelation configGroupRelation : groupRelationList) { - if (!isUpdate && Constants.BASE_VALIDATE) { - String valCompileGroup = valCompileGroup(configGroupRelation, compileId); - if (!valCompileGroup.equals("ok")) { - return valCompileGroup; - } - } - - if (!configGroupRelation.getCompileId().equals(compileId)) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中groupRelationList字段中的compileId为" - + configGroupRelation.getCompileId() + "的配置分组与编译配置id不一致"; - } - if (!groupList.contains(configGroupRelation.getGroupId())) { - groupList.add(configGroupRelation.getGroupId()); - } else { - return "编译配置id为" + configCompile.getCompileId() + "的配置中groupRelationList存在多个groupid为" - + configGroupRelation.getGroupId() + "的配置分组"; - } - - if (configGroupRelation.getIsValid() == 0) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中groupRelationList中groupid为" - + configGroupRelation.getGroupId() + "的配置分组不能设置为无效"; - } - } - } else { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.GroupListEQZero.getErrorReason(); - } - } - - List regionGroupIdList = new ArrayList();// 所有域配置中groupId的集合,不重复 - List numRegionList = configCompile.getNumRegionList(); - if (numRegionList == null) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.NumRegionIsNull.getErrorReason(); - } - if (numRegionList.size() > 0) { - for (NumRegion numRegion : numRegionList) { - // if (configCompile.getIsValid() != 0 && - // !regionGroupIdList.contains(numRegion.getGroupId())) { - if (!regionGroupIdList.contains(numRegion.getGroupId())) { - regionGroupIdList.add(numRegion.getGroupId()); - } - if (!type2TableNameIsOk(configCompile.getService(), numRegion.getTableName())) { - return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" - + numRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; - } - - if (!isUpdate && Constants.BASE_VALIDATE) { - String valNumRegion = valNumRegion(numRegion, compileId); - if (!valNumRegion.equals("ok")) { - return valNumRegion; - } - } - - if (isUpdate && isValid == 1 && numRegion.getIsValid() == 0) { - configFlag = true; - } - if (configCompile.getIsValid() != 0 && !groupList.contains(numRegion.getGroupId())) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中numRegionList中groupid为" - + numRegion.getGroupId() + "的域配置在groupRelationList中不存在"; - } - - // 插入配置时不能是无效 - if (!isUpdate && numRegion.getIsValid() == 0) { - return "配置id为" + configCompile.getCompileId() + "的配置中numRegionList中的regionid为" - + numRegion.getRegionId() + "的域配置" + CompileJudgeCode.CompileIsNotInvalid.getErrorReason(); - } - - } - } - - List strRegionList = configCompile.getStrRegionList(); - if (strRegionList == null) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中" - + CompileJudgeCode.StrRegionIsNull.getErrorReason(); - } - if (strRegionList != null && strRegionList.size() > 0) { - for (StrRegion strRegion : strRegionList) { - // if (configCompile.getIsValid() != 0 && - // !regionGroupIdList.contains(strRegion.getGroupId())) { - if (!regionGroupIdList.contains(strRegion.getGroupId())) { - regionGroupIdList.add(strRegion.getGroupId()); - } - if (!type2TableNameIsOk(configCompile.getService(), strRegion.getTableName())) { - return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" - + strRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; - } - if (!isUpdate && Constants.BASE_VALIDATE) { - String valStrRegion = valStrRegion(strRegion, compileId, - ConfigSourcesService.isStrStrongRegion(strRegion.getTableName())); - if (!valStrRegion.equals("ok")) { - return valStrRegion; - } - } - if (!isUpdate && Constants.SERVICE_VALIDATE) { - String serviceStrRegionVal = serviceStrRegionVal(strRegion, compileId); - if (!serviceStrRegionVal.equals("ok")) { - return serviceStrRegionVal; - } - } - if (isUpdate && isValid == 1 && strRegion.getIsValid() == 0) { - configFlag = true; - } - if (configCompile.getIsValid() != 0 && !groupList.contains(strRegion.getGroupId())) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中strRegionList中groupid为" - + strRegion.getGroupId() + "的域配置在groupRelationList中不存在"; - } - - // 插入配置时不能是无效 - if (!isUpdate && strRegion.getIsValid() == 0) { - return "配置id为" + configCompile.getCompileId() + "的配置中strRegionList中的regionid为" - + strRegion.getRegionId() + "的域配置" + CompileJudgeCode.CompileIsNotInvalid.getErrorReason(); - } - - } - } - - List ipRegionList = configCompile.getIpRegionList(); - - if (ipRegionList == null) { - return CompileJudgeCode.IpRegionIsNull.getErrorReason(); - } - if (ipRegionList != null && ipRegionList.size() > 0) { - for (IpRegion ipRegion : ipRegionList) { - // if (configCompile.getIsValid() != 0 && - // !regionGroupIdList.contains(ipRegion.getGroupId())) { - if (!regionGroupIdList.contains(ipRegion.getGroupId())) { - regionGroupIdList.add(ipRegion.getGroupId()); - } - - if (!type2TableNameIsOk(configCompile.getService(), ipRegion.getTableName())) { - return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" - + ipRegion.getRegionId() + "的域配置tableName与编译配置业务类型不一致"; - } - if (!isUpdate && Constants.BASE_VALIDATE) { - String valIpRegion = valIpRegion(ipRegion, compileId); - if (!valIpRegion.equals("ok")) { - return valIpRegion; - } - } - - if (!isUpdate && Constants.SERVICE_VALIDATE) { - String serviceIpRegionVal = serviceIpRegionVal(ipRegion, compileId); - if (!serviceIpRegionVal.equals("ok")) { - return serviceIpRegionVal; - } - } - - if (isUpdate && isValid == 1 && ipRegion.getIsValid() == 0) { - configFlag = true; - } - if (configCompile.getIsValid() != 0 && !groupList.contains(ipRegion.getGroupId())) { - return "编译配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中groupid为" - + ipRegion.getGroupId() + "的域配置在groupRelationList中不存在"; - } - - // 插入配置时不能是无效 - if (!isUpdate && ipRegion.getIsValid() == 0) { - return "配置id为" + configCompile.getCompileId() + "的配置中ipRegionList中的regionid为" - + ipRegion.getRegionId() + "的域配置" + CompileJudgeCode.CompileIsNotInvalid.getErrorReason(); - } - - } - } - - // if (configCompile.getIsValid() != 0 && regionGroupIdList.size() > 0 - // && groupList.size() > 0) {// 添加配置或修改域配置时判断配置分组集合中groupId是否都在域配置使用 - if (groupList.size() > 0) {// 修改域配置时判断配置分组集合中groupId是否都在域配置使用 - for (Long groupId : groupList) { - if (!regionGroupIdList.contains(groupId)) { - // setSbStr("配置id为" + configCompile.getCompileId() + - // "的配置中配置分组groupid为" + groupId+ "的配置在域配置中未被使用(可能是分组复用情况).", - // sb);//20161206业务修改:业务目前不会出现分组复用情形,如果前端传过来的json串出现分组复用情形则直接返回异常提示信息 - return "配置id为" + configCompile.getCompileId() + "的配置中配置分组groupid为" + groupId + "的配置在域配置中未被使用"; - } - // if (configCompile.getIsValid() != 0 && isUpdate && - // !regionGroupIdList.contains(groupId)) { - // return "配置id为" + configCompile.getCompileId() + - // "的配置在修改时域配置中的groupid为" + groupId - // + "的配置在groupRelationList中不存在"; - // } - } - } - - if (regionGroupIdList.size() > 0) { - for (Long groupId : regionGroupIdList) { - if (!groupList.contains(groupId)) { - return "配置id为" + configCompile.getCompileId() + "的配置中域配置中的groupid为" + groupId + "的域配置在配置分组关系中不存在"; - } - } - } - - if (configCompile.getIsValid() != 0 && !isUpdate) { - // if (!(regionGroupIdList.size() > 0)) { - // return CompileJudgeCode.CompileGroupSizeEqZero; - // } - if (!(groupList.size() > 0)) { - return "配置id为" + configCompile.getCompileId() + "的配置在添加时" - + CompileJudgeCode.GroupListEQZero.getErrorReason(); - } - } - - // 编译为有效 域配置至少有一个为无效 - if (isUpdate && isValid == 1) { - if (!configFlag) { - return "配置id为" + configCompile.getCompileId() + "的配置在修改时" - + CompileJudgeCode.CompileIsValide.getErrorReason(); - } - } - - return CompileJudgeCode.CompileGroupSizeGtZero.getErrorReason(); - } - - /** - * 验证业务类型与域配置的表名是否对应 - * - * @param serviceType - * @param tableName - * @return - */ - public static boolean type2TableNameIsOk(Integer serviceType, String tableName) { - if (null != serviceType && null != tableName && !tableName.equals("")) { - Map> tableRelation = ConfigSourcesService.getTableRelation(); - Map map = tableRelation.get(serviceType.intValue()); - if (null != map) { - if (map.containsKey(tableName.toUpperCase())) { - return true; - } else { - return false; - } - } else { - return false; - } - } else { - return false; - } - } - - /** - * 判断当前编译配置中的groupNum属性与配置分组groupList大小是否相等且是否均大于0小于等于8, 且每个配置分组中域配置个数大于0 - * - * @param configCompile - * @return GroupNumNEQGroupList GroupNumGtEight GroupListGtEight - * GroupNumEQZero GroupListEQZero CompileGroupSizeEqZero - * CompileGroupIdNotExist CompileGroupIdIsRepeat CompileIsOk - * 只有返回CompileIsOk才说明该条配置正常否则该条配置不正常,可根据枚举中成员的注释具体在返回错误信息 - */ - public static String compileIsOk(ConfigCompile configCompile, boolean isUpdate, StringBuffer sb) { - - String msg1 = groupNumAndListIsOk(configCompile, isUpdate); - if (msg1 != CompileJudgeCode.GroupNumAndListLtEight.getErrorReason()) { - return msg1; - } - - String msg2 = compileGroupSizeIsGtZero(configCompile, isUpdate, sb); - if (msg2 != CompileJudgeCode.CompileGroupSizeGtZero.getErrorReason()) { - return msg2; - } - String latentMsg = ",数据中可能存在的问题:"; - if (sb.length() > 0 && !sb.toString().contains(latentMsg)) { - latentMsg = latentMsg + sb.toString(); - sb.setLength(0); - sb.append(latentMsg); - } - return CompileJudgeCode.CompileIsOk.getErrorReason(); - } - - public static void setSbStr(String str, StringBuffer sb) { - if (sb.length() <= 1024) { - sb.append(str); - } - } - - public static String valCompile(ConfigCompile configCompile) { - Long compileId = configCompile.getCompileId(); - if (null == compileId) { - return "compileId字段不能为空"; - } - if (null == configCompile.getService()) { - return "id为" + compileId + "的编译配置中service不能为空"; - } - - if (null == configCompile.getAction()) { - return "id为" + compileId + "的编译配置中action不能为空"; - } - if (null == configCompile.getDoBlacklist()) { - return "id为" + compileId + "的编译配置中doBlacklist不能为空"; - } - if (null == configCompile.getDoLog()) { - return "id为" + compileId + "的编译配置中doLog不能为空"; - } - if (null == configCompile.getEffectiveRange() || configCompile.getEffectiveRange().equals("")) { - return "id为" + compileId + "的编译配置中effectiveRange不能为空"; - } - if (null == configCompile.getStartTime()) { - return "id为" + compileId + "的编译配置中startTime不能为空"; - } - if (null == configCompile.getEndTime()) { - return "id为" + compileId + "的编译配置中endTime不能为空"; - } - if (null == configCompile.getUserRegion() || configCompile.getUserRegion().equals("")) { - return "id为" + compileId + "的编译配置中userRegion不能为空"; - } - if (null == configCompile.getIsValid()) { - return "id为" + compileId + "的编译配置中isValid不能为空"; - } - if (null == configCompile.getGroupNum()) { - return "id为" + compileId + "的编译配置中groupNum不能为空"; - } - if (null == configCompile.getFatherCfgId()) { - return "id为" + compileId + "的编译配置中fatherCfgId不能为空"; - } - if (null == configCompile.getOpTime()) { - return "id为" + compileId + "的编译配置中opTime不能为空"; - } - return "ok"; - } - - public static String valCompileGroup(ConfigGroupRelation configGroupRelation, Long compileId) { - Long groupId = configGroupRelation.getGroupId(); - if (null == groupId) { - return "id为" + compileId + "的编译配置中的配置分组的groupId不能为空"; - } - - if (null == configGroupRelation.getCompileId()) { - return "id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的compileId不能为空"; - } - if (null == configGroupRelation.getIsValid()) { - return "id为" + compileId + "的编译配置中的配置分组id为" + groupId + "的isValid不能为空"; - } - - if (null == configGroupRelation.getOpTime()) { - 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不能为空"; - } - if (null == ipRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的groupId不能为空"; - } - if (null == ipRegion.getAddrType()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的addrType不能为空"; - } - if (null == ipRegion.getSrcIp() || ipRegion.getSrcIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的srcIp不能为空"; - } - - if (null == ipRegion.getMaskSrcIp() || ipRegion.getMaskSrcIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的maskSrcIp不能为空"; - } - if (null == ipRegion.getSrcPort() || ipRegion.getSrcPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的srcPort不能为空"; - } - if (null == ipRegion.getMaskSrcPort() || ipRegion.getMaskSrcPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的maskSrcPort不能为空"; - } - if (null == ipRegion.getDstIp() || ipRegion.getDstIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的dstIp不能为空"; - } - if (null == ipRegion.getMaskDstIp() || ipRegion.getMaskDstIp().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的maskDstIp不能为空"; - } - if (null == ipRegion.getDstPort() || ipRegion.getDstPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的dstPort不能为空"; - } - if (null == ipRegion.getMaskDstPort() || ipRegion.getMaskDstPort().equals("")) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的maskDstPort不能为空"; - } - if (null == ipRegion.getProtocol()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的protocol不能为空"; - } - if (null == ipRegion.getDirection()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的direction不能为空"; - } - if (null == ipRegion.getIsValid()) { - return "id为" + compileId + "的编译配置中的ip类域配置id为" + regionId + "的isValid不能为空"; - } - return "ok"; - } - - public static String valNumRegion(NumRegion numRegion, Long compileId) { - Long regionId = numRegion.getRegionId(); - if (null == regionId) { - return "id为" + compileId + "的编译配置中的数值类域配置的regionId不能为空"; - } - if (null == numRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的groupId不能为空"; - } - if (null == numRegion.getLowBoundary()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的lowBoundary不能为空"; - } - if (null == numRegion.getUpBoundary()) { - return "id为" + compileId + "的编译配置中的数值类域配置id为" + regionId + "的upBoundary不能为空"; - } - return "ok"; - } - - public static String valStrRegion(StrRegion strRegion, Long compileId, boolean isDirtrict) { - Long regionId = strRegion.getRegionId(); - if (null == regionId) { - return "id为" + compileId + "的编译配置中的字符串类域配置的regionId不能为空"; - } - if (null == strRegion.getGroupId()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的groupId不能为空"; - } - if (isDirtrict && (null == strRegion.getDistrict() || strRegion.getDistrict().equals(""))) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的district不能为空"; - } - - if (null == strRegion.getKeywords() || strRegion.getKeywords().equals("")) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的keywords不能为空"; - } - - if (null == strRegion.getExprType()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的exprType不能为空"; - } - - if (null == strRegion.getMatchMethod()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的matchMethod不能为空"; - } - if (null == strRegion.getIsHexbin()) { - return "id为" + compileId + "的编译配置中的字符串类域配置id为" + regionId + "的isHexbin不能为空"; - } - return "ok"; - } - - public static String serviceIpRegionVal(IpRegion ipRegion, Long compileId) { - if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), ipRegion.getAddrType())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置srcIp的格式不正确或与addrType不一致"; - } - if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), ipRegion.getAddrType())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置maskSrcIp的格式不正确或与addrType不一致"; - } - if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), ipRegion.getAddrType())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置dstIp的格式不正确或与addrType不一致"; - } - if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), ipRegion.getAddrType())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置maskDstIp的格式不正确或与addrType不一致"; - } - - if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getSrcPort())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置srcPort的格式不正确"; - } - // 端口掩码目前先不做0-65535校验,仅做是否是数字校验 - // if (BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskSrcPort())) { - if (!BasicProvingUtil.isIntType(ipRegion.getMaskSrcPort())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置maskSrcPort的格式不正确"; - } - if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getDstPort())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置dstPort的格式不正确"; - } - // 端口掩码目前先不做0-65535校验,仅做是否是数字校验 - // if (BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskDstPort())) { - if (!BasicProvingUtil.isIntType(ipRegion.getMaskDstPort())) { - return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() - + "的域配置maskDstPort的格式不正确"; - } - // if (null == ipRegion.getDirection() || (ipRegion.getDirection() != 1 - // && ipRegion.getDirection() != 0)) { - // return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + - // ipRegion.getRegionId() - // + "的域配置direction的值不正确,只能是0或1"; - // } - return "ok"; - } - - public static String serviceStrRegionVal(StrRegion strRegion, Long compileId) { - String url[] = { "DF_HTTP_URL", "DF_FTP_URL", "DJ_HTTP_URL", "DJ_FTP_URL", "DF_L2TP_URL", "DF_PPTP_URL" }; - String mail[] = { "DF_MAIL_HDR", "DJ_MAIL_HDR" }; - String keyWord[] = { "DF_HTTP_REQ_HDR", "DF_HTTP_RES_HDR", "DF_HTTP_REQ_BODY", "DF_HTTP_RES_BODY", - "DF_MAIL_BODY", "DF_DNS_REGION", "DF_SSL_REGION", "FX_HTTP_REQ_HDR", "FX_DNS_REGION", "DJ_IP_PKT_BIN", - "DJ_HTTP_REQ_HDR", "DJ_HTTP_RES_HDR", "DJ_HTTP_REQ_BODY", "DJ_HTTP_RES_BODY", "DJ_MAIL_BODY", - "DJ_DNS_RES_REGION", "DJ_DNS_REQ_REGION", "DJ_SSL_REGION", "FX_HTTP_URL" }; - - List urlList = Arrays.asList(url); - List mailList = Arrays.asList(mail); - List keyWordList = Arrays.asList(keyWord); - - String tableName = strRegion.getTableName(); - String keywords = strRegion.getKeywords(); - if (urlList.contains(tableName.toUpperCase())) { - List dictValue = SystemConfigListener.getDictValue("url"); - if (null != dictValue && dictValue.size() > 0) { - for (DataDictionaryValue dataDictionaryValue : dictValue) { - if (dataDictionaryValue.getDataDictValue().equals(keywords)) { - return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() - + "的域配置keywords=" + keywords + "被设置为禁配"; - } - } - } - - } else if (mailList.contains(tableName.toUpperCase())) { - List dictValue = SystemConfigListener.getDictValue("email"); - if (null != dictValue && dictValue.size() > 0) { - for (DataDictionaryValue dataDictionaryValue : dictValue) { - if (dataDictionaryValue.getDataDictValue().equals(keywords)) { - return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() - + "的域配置keywords=" + keywords + "被设置为禁配"; - } - } - } - } else if (keyWordList.contains(tableName.toUpperCase())) { - List dictValue = SystemConfigListener.getDictValue("keywords"); - if (null != dictValue && dictValue.size() > 0) { - String[] split = keywords.split("(?<=[^\\\\])&"); - for (String str : split) { - for (DataDictionaryValue dataDictionaryValue : dictValue) { - if (dataDictionaryValue.getDataDictValue().equals(str)) { - return "编译配置id为" + compileId + "的配置中strRegionList中regionId为" + strRegion.getRegionId() - + "的域配置keywords=" + str + "被设置为禁配"; - } - } - } - } - } - return "ok"; - - } - - public static void main(String[] args) { - String key = "中\\&国\\&人&河南人&周口人&郸城人"; - String[] split = key.split("(?<=[^\\\\])&"); - for (String str : split) { - System.out.println(str); - } - - } - -} diff --git a/src/main/java/com/nis/util/CompileVal.java b/src/main/java/com/nis/util/CompileVal.java index 2c3f157..6204c5d 100644 --- a/src/main/java/com/nis/util/CompileVal.java +++ b/src/main/java/com/nis/util/CompileVal.java @@ -146,10 +146,6 @@ public class CompileVal { } } } -// else { -// return "编译配置id为" + configCompile.getCompileId() + "的配置中" -// + CompileJudgeCode.GroupListEQZero.getErrorReason(); -// } List regionGroupIdList = new ArrayList();// 所有域配置中groupId的集合,不重复 List numRegionList = configCompile.getNumRegionList(); @@ -244,14 +240,14 @@ public class CompileVal { if (!isUpdate && Constants.BASE_VALIDATE) { String valStrRegion = valStrRegion(strRegion, compileId, - ConfigSourcesService.isStrStrongRegion(strRegion.getTableName())); + ConfigSourcesService.isStrStrongRegion(strRegion.getTableName(),configCompile.getService())); if (!valStrRegion.equals("ok")) { return valStrRegion; } } if (!isUpdate && Constants.SERVICE_VALIDATE) { String serviceStrRegionVal = serviceStrRegionVal(strRegion, compileId, - ConfigSourcesService.isStrStrongRegion(strRegion.getTableName())); + ConfigSourcesService.isStrStrongRegion(strRegion.getTableName(),configCompile.getService())); if (!serviceStrRegionVal.equals("ok")) { return serviceStrRegionVal; } 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 9355e56..6e4a836 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -378,9 +378,22 @@ public class ConfigSourcesController extends BaseRestController { logger.info("-----------------调用接口上传文件---------------"); filePath = FileManager.upload(fdsfile, null); } - } catch (IOException e) { + }catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("文件上传异常:"+e.getMessage()); + Exception exception = new RuntimeException( + "文件上传异常:"+e.getMessage()); + throw new RestServiceException(thread, System.currentTimeMillis() - start, + "文件上传异常:" + exception.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + }catch (Exception e) { + // TODO: handle exception + logger.error(e.getMessage()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue()); + } + throw new RestServiceException(thread, System.currentTimeMillis() - start, + e.getMessage(), CompileVal.getBusinessCode()); } JSONObject jsonObj = new JSONObject(); // jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group"))); @@ -431,10 +444,20 @@ public class ConfigSourcesController extends BaseRestController { } } catch (IOException e) { // TODO Auto-generated catch block - logger.error("文件上传过程中出现异常"); - thread.setExceptionInfo("文件上传过程中出现异常"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "文件上传过程中出现异常", - RestBusinessCode.unknow_error.getValue()); + logger.error("文件上传异常:"+e.getMessage()); + Exception exception = new RuntimeException( + "文件上传异常:"+e.getMessage()); + throw new RestServiceException(thread, System.currentTimeMillis() - start, + "文件上传异常:" + exception.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + }catch (Exception e) { + // TODO: handle exception + logger.error(e.getMessage()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + if (e.getMessage().startsWith("后台错误:")) { + CompileVal.setBusinessCode(RestBusinessCode.service_runtime_error.getValue()); + } + throw new RestServiceException(thread, System.currentTimeMillis() - start, + e.getMessage(), CompileVal.getBusinessCode()); } try { String tempFilePath = request.getRealPath(File.separator) + "upload" + File.separator diff --git a/src/main/java/com/nis/web/controller/restful/ConfigTestController.java b/src/main/java/com/nis/web/controller/restful/ConfigTestController.java deleted file mode 100644 index 4b8532f..0000000 --- a/src/main/java/com/nis/web/controller/restful/ConfigTestController.java +++ /dev/null @@ -1,820 +0,0 @@ -package com.nis.web.controller.restful; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.net.URL; -import java.net.URLConnection; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.nis.crypt.AESUtil; -import com.nis.domain.Page; -import com.nis.domain.restful.ConfigCompile; -import com.nis.domain.restful.ConfigCompileTest; -import com.nis.domain.restful.ConfigGroupRelation; -import com.nis.domain.restful.ConfigSourceTest; -import com.nis.domain.restful.IpRegion; -import com.nis.domain.restful.IpRegionTest; -import com.nis.domain.restful.NumRegion; -import com.nis.domain.restful.NumRegionTest; -import com.nis.domain.restful.StrRegion; -import com.nis.domain.restful.StrRegionTest; -import com.nis.restful.RestBusinessCode; -import com.nis.restful.RestServiceException; -import com.nis.util.Configurations; -import com.nis.util.Constants; -import com.nis.util.JsonDateValueProcessor; -import com.nis.util.StringUtils; -import com.nis.web.controller.BaseRestController; -import com.nis.web.service.SaveRequestLogThread; -import com.nis.web.service.ServicesRequestLogService; -import com.nis.web.service.restful.ConfigSourcesService; -import com.wordnik.swagger.annotations.Api; -import com.wordnik.swagger.annotations.ApiOperation; - -import net.sf.json.JSONArray; -import net.sf.json.JsonConfig; - -/** - * @ClassName: ConfigSourceTestsController - * @Description: 配置存储服务 - * @author (zx) - * @date 2016年9月5日 下午6:20:33 - * @version V1.0 - */ -@RestController -//@RequestMapping("${servicePath}") -@Api(value = "ConfigTestController", description = "配置存储服务,包括管控、监测、白名单的控制类") -public class ConfigTestController extends BaseRestController { - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Logger logger = LoggerFactory.getLogger(ConfigTestController.class); - @Autowired - protected ConfigSourcesService configSourcesService; - - @Autowired - protected ServicesRequestLogService servicesRequestLogService; - private long allCount = 0l; - - @RequestMapping(value = "/cfg/v1/insertBatch", method = RequestMethod.POST) - @ApiOperation(value = "批量业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储") - public Map insertBatchaaaaa(@RequestParam(value = "configCount", required = false) Long configCount, - @RequestParam(value = "action", required = false) Integer action, - @RequestParam(value = "serviceType", required = false) Long serviceType, - @RequestParam(value = "startTime", required = false) String startTime, - @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request, - HttpServletResponse response) throws Exception { - StringBuffer sb = new StringBuffer(); - allCount = 0l; - long dataCount = 0l; - long start = System.currentTimeMillis(); - SaveRequestLogThread thread1 = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, - null); - if (configCount == null) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "批量增加条数不能为空", - RestBusinessCode.missing_args.getValue()); - } - - if (startTime == null || startTime.equals("")) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "开始时间不能为空", - RestBusinessCode.missing_args.getValue()); - } - - if (endTime == null || endTime.equals("")) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "结束时间不能为空", - RestBusinessCode.missing_args.getValue()); - } - - System.out.println("configCount" + configCount); - System.out.println("action" + action); - System.out.println("serviceType" + serviceType); - System.out.println("startTime" + startTime); - System.out.println("endTime" + endTime); - Integer[] zeroArr = { 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - Integer[] oneArr = { 15, 16, 32, 33, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 }; - Integer[] twoArr = { 2 }; - - try { - Date date = new Date(); - // String date = "2016-09-26T03:39:30.577Z"; - ConfigSourceTest configSource = new ConfigSourceTest(); - configSource.setOpTime(date); - configSource.setOpAction(1); - configSource.setOperator("rkg"); - configSource.setVersion("0.1"); - List configCompileList = new ArrayList(); - long count = System.currentTimeMillis() + 1; - - for (Integer x = 0; x < zeroArr.length; x++) { - for (Long i = 1l; i <= configCount; i++) { - count++; - dataCount++; - ConfigCompile configCompile = setCompileTest(zeroArr[x].longValue(), 0, date, startTime, endTime, - count); - configCompileList.add(configCompile); - } - } - for (Integer x = 15; x < oneArr.length + 15; x++) { - for (Long i = 1l; i <= configCount; i++) { - count++; - dataCount++; - ConfigCompile configCompile = setCompileTest(oneArr[x - 15].longValue(), 1, date, startTime, - endTime, count); - configCompileList.add(configCompile); - } - } - for (Integer x = 50; x < twoArr.length + 50; x++) { - for (Long i = 1l; i <= configCount; i++) { - count++; - dataCount++; - ConfigCompile configCompile = setCompileTest(twoArr[x - 50].longValue(), 2, date, startTime, - endTime, count); - configCompileList.add(configCompile); - } - } - - configSource.setConfigCompileList(configCompileList); - validateConfigSourceTest(thread1, start, configSource); - - JsonConfig jsonConfig = new JsonConfig(); - jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); - JSONArray jsonArray = JSONArray.fromObject(configSource, jsonConfig); - String jsonStr = jsonArray.getString(0); - String distisct = "\"district\":\"\","; - if (jsonStr.contains(distisct)) { - jsonStr = jsonStr.replaceAll(distisct, ""); - } - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, - request, configSource); - System.out.println("开始执行插入操作" + dataCount + "条配置总计" + allCount + "条数据"); - Long benginTime = System.currentTimeMillis(); - configSourcesService.insertConfigSourceData(thread, System.currentTimeMillis() - start, - configSource.getConfigCompileList(), sb); - Long endSaveTime = System.currentTimeMillis(); - Long time = (endSaveTime - benginTime) / 1000; - System.out.println("插入了" + dataCount + "条配置总计" + allCount + "条数据总共需要" + time + "秒"); - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据插入成功", - configSource); - } catch (Exception e) { - thread1.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - return serviceResponse(thread1, System.currentTimeMillis() - start, request, response, "编译配置数据插入失败", null); - } - } - - @RequestMapping(value = "/test/v1/insertBatchss", method = RequestMethod.POST) - @ApiOperation(value = "批量业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储") - public Map insertBatch(@RequestParam(value = "configCount", required = false) Long configCount, - @RequestParam(value = "action", required = false) Integer action, - @RequestParam(value = "serviceType", required = false) Long serviceType, - @RequestParam(value = "startTime", required = false) String startTime, - @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request, - HttpServletResponse response) throws Exception { - StringBuffer sb = new StringBuffer(); - long start = System.currentTimeMillis(); - SaveRequestLogThread thread1 = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - if (configCount == null) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "批量增加条数不能为空", - RestBusinessCode.missing_args.getValue()); - } - - if (serviceType == null) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "业务类型不能为空", - RestBusinessCode.missing_args.getValue()); - } - - if (startTime == null || startTime.equals("")) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "开始时间不能为空", - RestBusinessCode.missing_args.getValue()); - } - - if (endTime == null || endTime.equals("")) { - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "结束时间不能为空", - RestBusinessCode.missing_args.getValue()); - } - - System.out.println("configCount" + configCount); - System.out.println("action" + action); - System.out.println("serviceType" + serviceType); - System.out.println("startTime" + startTime); - System.out.println("endTime" + endTime); - - try { - Date date = new Date(); - // String date = "2016-09-26T03:39:30.577Z"; - ConfigSourceTest configSource = new ConfigSourceTest(); - configSource.setOpTime(date); - configSource.setOpAction(1); - configSource.setOperator("rkg"); - configSource.setVersion("0.1"); - List configCompileList = new ArrayList(); - for (Long i = 0l; i < configCount; i++) { - ConfigCompile configCompile = setCompileTest(serviceType, action, date, startTime, endTime, i); - configCompileList.add(configCompile); - } - configSource.setConfigCompileList(configCompileList); - validateConfigSourceTest(thread1, start, configSource); - Long benginTime = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, - request, configSource); - configSourcesService.insertConfigSourceData(thread, System.currentTimeMillis() - start, - configSource.getConfigCompileList(), sb); - Long endSaveTime = System.currentTimeMillis(); - Long time = (endSaveTime - benginTime) / 1000; - System.out.println("插入" + configCount + "条数据总共需要" + time + "秒"); - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据插入成功", - configSource); - } catch (Exception e) { - thread1.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - return serviceResponse(thread1, System.currentTimeMillis() - start, request, response, "编译配置数据插入失败", null); - } - } - - @RequestMapping(value = "/test/v1/findCompile", method = RequestMethod.POST) - public Map findCompile(ConfigCompileTest configCompileTest, HttpServletRequest request, - HttpServletResponse response) { - long start = System.currentTimeMillis(); - SaveRequestLogThread thread1 = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - configCompileTest); - - Page page = new Page(); - int no = configCompileTest.getPagesNo() == null ? 1 : configCompileTest.getPagesNo(); - int size = configCompileTest.getPagesSize() == null ? 10 : configCompileTest.getPagesSize(); - page.setPageNo(no); - page.setPageSize(size); - Page queryAllCompile = null; - try { - if (configCompileTest.getSearchStartTime() != null && !configCompileTest.getSearchStartTime().equals("")) { - configCompileTest.setStartTime(sdf.parse(configCompileTest.getSearchStartTime())); - // configCompile.setStartTime(configCompile.getSearchStartTime()); - } - if (configCompileTest.getSearchEndTime() != null && !configCompileTest.getSearchEndTime().equals("")) { - configCompileTest.setEndTime(sdf.parse(configCompileTest.getSearchEndTime())); - - // configCompile.setEndTime(configCompile.getSearchEndTime()); - } - queryAllCompile = configSourcesService.queryAllCompile(page, configCompileTest); - } catch (SQLException e) { - thread1.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "编译配置获取失败"); - } catch (Exception e) { - thread1.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - throw new RestServiceException(thread1, System.currentTimeMillis() - start, "编译配置获取失败"); - } - return serviceResponse(thread1, System.currentTimeMillis() - start, request, response, "编译配置获取成功", - queryAllCompile); - } - - public ConfigSourceTest setConfigSourceTest() throws Exception { - Long configCount = 2l; - Date date = new Date(); - // String date = "2016-09-26T03:39:30.577Z"; - ConfigSourceTest configSource = new ConfigSourceTest(); - configSource.setOpTime(date); - configSource.setOpAction(1); - configSource.setOperator("rkg"); - configSource.setVersion("0.1"); - List configCompileList = new ArrayList(); - Long serviceType = 1l; - Integer action = 0; - - String startTime = "2016-09-26"; - String endTime = "2016-09-29"; - for (Long i = 0l; i < configCount; i++) { - ConfigCompile configCompile = setCompileTest(serviceType, action, date, startTime, endTime, i); - configCompileList.add(configCompile); - } - configSource.setConfigCompileList(configCompileList); - // validateConfigSourceTest(thread1, start,configSource); - return configSource; - } - - @RequestMapping(value = "/test/v1/saveByQuery", method = RequestMethod.POST) - public String saveByQuery(String id, HttpServletRequest request, HttpServletResponse response) { - System.out.println(id); - try { - // String url = - // "http://127.0.0.1:8888/galaxy/service/cfg/v1/configSources"; - String url = Configurations.getStringProperty("httpUrl", ""); - ConfigSourceTest configSource = new ConfigSourceTest(); - configSource.setOpTime(new Date()); - configSource.setOpAction(1); - configSource.setOperator("rkg"); - configSource.setVersion("0.1"); - id = id.replace("[", ""); - id = id.replace("]", ""); - id = id.substring(1); - List configCompileList = new ArrayList(); - List queryConfigCompileByIdArr = configSourcesService.queryConfigCompileByIdArr(id); - for (int i = 0; i < queryConfigCompileByIdArr.size(); i++) { - ConfigCompile configCompile = queryConfigCompileByIdArr.get(i); - ConfigCompile compileInfo = getCompileInfo(configCompile); - configCompileList.add(compileInfo); - } - configSource.setConfigCompileList(configCompileList); - JsonConfig jsonConfig = new JsonConfig(); - jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); - JSONArray jsonArray = JSONArray.fromObject(configSource, jsonConfig); - String jsonStr = jsonArray.getString(0); - String distisct = "\"district\":\"\","; - if (jsonStr.contains(distisct)) { - jsonStr = jsonStr.replaceAll(distisct, ""); - } - System.out.println(jsonStr); - String result = sendPost(url, jsonStr); - System.out.println(result); - if (result.equals("")) { - return "error"; - } else { - return "ok"; - } - - } catch (Exception e) { - e.printStackTrace(); - - } - - return "error"; - } - - @RequestMapping(value = "/test/v1/saveAllByQuery", method = RequestMethod.POST) - public String saveAllByQuery(ConfigCompileTest configCompileTest, HttpServletRequest request, - HttpServletResponse respons) throws Exception { - try { - if (configCompileTest.getSearchStartTime() != null && !configCompileTest.getSearchStartTime().equals("")) { - configCompileTest.setStartTime(sdf.parse(configCompileTest.getSearchStartTime())); - // configCompile.setStartTime(configCompile.getSearchStartTime()); - } - if (configCompileTest.getSearchEndTime() != null && !configCompileTest.getSearchEndTime().equals("")) { - configCompileTest.setEndTime(sdf.parse(configCompileTest.getSearchEndTime())); - - // configCompile.setEndTime(configCompile.getSearchEndTime()); - } - List compileList = new ArrayList(); - List queryAllCompile = configSourcesService.queryAllCompile(configCompileTest); - - for (int i = 0; i < queryAllCompile.size(); i++) { - ConfigCompile configCompile = queryAllCompile.get(i); - ConfigCompile compileInfo = getCompileInfo(configCompile); - compileList.add(compileInfo); - } - - ConfigSourceTest configSource = new ConfigSourceTest(); - configSource.setOpTime(new Date()); - configSource.setOpAction(1); - configSource.setOperator("rkg"); - configSource.setVersion("0.1"); - configSource.setConfigCompileList(compileList); - JsonConfig jsonConfig = new JsonConfig(); - jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); - // String url = - // "http://127.0.0.1:8888/galaxy/service/cfg/v1/configSources"; - String url = Configurations.getStringProperty("httpUrl", ""); - JSONArray jsonArray = JSONArray.fromObject(configSource, jsonConfig); - String jsonStr = jsonArray.getString(0); - String distisct = "\"district\":\"\","; - if (jsonStr.contains(distisct)) { - jsonStr = jsonStr.replaceAll(distisct, ""); - } - System.out.println(jsonStr); - String result = sendPost(url, jsonStr); - System.out.println(result); - if (result.equals("")) { - return "error"; - } else { - return "ok"; - } - - } catch (Exception e) { - e.printStackTrace(); - } - return "error"; - } - - public ConfigCompile getCompileInfo(ConfigCompile configCompileTest) { - List groupByCompileList = configSourcesService - .getGroupByCompile(configCompileTest.getCompileId()); - configCompileTest.setGroupRelationList(groupByCompileList); - Long[] groupIdArr = new Long[groupByCompileList.size()]; - for (int i = 0; i < groupByCompileList.size(); i++) { - groupIdArr[i] = groupByCompileList.get(i).getGroupId(); - } - - Map tableMap = configSourcesService.getTableMap(configCompileTest.getService().intValue()); - List strTable = new ArrayList(); - String ipTable = null; - String numTable = null; - - if (null != tableMap && tableMap.size() > 0) { - for (String str : tableMap.keySet()) { - if (tableMap.get(str).equals("ip")) { - ipTable = str; - } else if (tableMap.get(str).equals("num")) { - numTable = str; - } else if (tableMap.get(str).equals("str")) { - strTable.add(str); - } - } - } - if (strTable.size() > 0) { - - List strRegionList = configSourcesService.getStrRegionByGId(strTable, groupIdArr); - if (null != strRegionList && strRegionList.size() > 0) { - configCompileTest.setStrRegionList(strRegionList); - } - } - - if (ipTable != null) { - if (ipTable.equals("DF_IP_PORT")) { - System.out.println("DF_IP_PORT" + configCompileTest.getService()); - } - if (ipTable.equals("FX_IP_PORT")) { - System.out.println("FX_IP_PORT" + configCompileTest.getService()); - } - List ipRegionByGId = configSourcesService.getIpRegionByGId(ipTable, groupIdArr); - if (null != ipRegionByGId && ipRegionByGId.size() > 0) { - configCompileTest.setIpRegionList(ipRegionByGId); - } - } - - if (numTable != null) { - List numRegionList = configSourcesService.getNumRegionByGId(numTable, groupIdArr); - if (null != numRegionList && numRegionList.size() > 0) { - configCompileTest.setNumRegionList(numRegionList); - } - } - - return configCompileTest; - } - - /** - * 向指定URL发送POST方法的请求 - * - * @param url - * 发送请求的url - * @param param - * 请求参数,格式为 name1=value1&name2=value2的形式 - * @return 所代表远程资源的相应结果 - */ - public String sendPost(String url, String param) { - // ConfigSourceTest - PrintWriter out = null; - BufferedReader in = null; - String result = ""; - try { - URL realUrl = new URL(url); - // 打开和URL之间的连接 - URLConnection conn = realUrl.openConnection(); - // 设置通用的请求属性 - conn.setRequestProperty("accept", "*/*"); - conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - conn.setDoOutput(true); - conn.setDoInput(true); - conn.setConnectTimeout(200000); - conn.setReadTimeout(3000000); - conn.connect(); - // 获取URLConnection对象对应的输出流 - out = new PrintWriter(conn.getOutputStream()); - // 发送请求参数 - out.print(param); - // flush输出流的缓冲 - out.flush(); - out.close(); - InputStream inputStream = conn.getInputStream(); - in = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = in.readLine()) != null) { - result += line; - } - } catch (Exception e) { - System.out.println("发送POST请求出现异常" + e); - e.printStackTrace(); - } finally { - try { - if (out != null) { - out.close(); - } - if (in != null) { - in.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return result; - } - - public String sendGet(String url, String param) { - BufferedReader in = null; - String result = ""; - try { - String urlNameString = url + "?" + param; - urlNameString = "http://127.0.0.1:8888/galaxy/service/log/v1/dfStatLogDailySources?pageNo=1&pageSize=2"; - URL realUrl = new URL(urlNameString); - // 打开和URL之间的连接 - URLConnection conn = realUrl.openConnection(); - // 设置通用的请求属性 - conn.setRequestProperty("accept", "*/*"); - conn.setRequestProperty("connection", "Keep-Alive"); - conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - - conn.connect(); - - Map> headerFields = conn.getHeaderFields(); - for (String key : headerFields.keySet()) { - System.out.println(key); - } - - InputStream inputStream = conn.getInputStream(); - in = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = in.readLine()) != null) { - result += line; - } - } catch (Exception e) { - System.out.println("发送POST请求出现异常" + e); - e.printStackTrace(); - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return result; - } - - public ConfigCompileTest setCompileTest(Long serviceType, Integer action, Date date, String startTime, - String endTime, Long index) throws Exception { - - Long compileId = System.currentTimeMillis() + index; - System.out.println("compileId--------------------------" + compileId); - ConfigCompileTest configCompile = new ConfigCompileTest(); - configCompile.setCompileId(compileId); -// configCompile.setService(serviceType); - configCompile.setAction(action); -// configCompile.setContType(0); -// configCompile.setAttrType(0); - configCompile.setContLabel("0"); - configCompile.setTaskId(0); -// configCompile.setGuaranteeId(0); - configCompile.setAffairId(0); -// configCompile.setTopicId(0); -// configCompile.setDoBlacklist(0l); - configCompile.setDoLog(0); - configCompile.setEffectiveRange("0"); -// configCompile.setConfigPercent(100l); -// configCompile.setConfigOption(1); - configCompile.setStartTime(sdf.parse(startTime)); - configCompile.setEndTime(sdf.parse(endTime)); - // configCompile.setStartTime(startTime); - // configCompile.setEndTime(endTime); - -// configCompile.setActiveSys(0); -// configCompile.setLastUpdate(date); -// configCompile.setProcSeq(compileId); - configCompile.setUserRegion("0"); - configCompile.setIsValid(1); - configCompile.setGroupNum(1); - configCompile.setFatherCfgId(0l); - configCompile.setOpTime(date); - Long groupId = System.currentTimeMillis() + (long) ((Math.random()) * 100000); - configCompile.setGroupRelationList(setGroupList(compileId, date, groupId)); - Map tableMap = configSourcesService.getTableMap(serviceType.intValue()); - List strTable = new ArrayList(); - String ipTable = null; - String numTable = null; - - if (null != tableMap && tableMap.size() > 0) { - for (String str : tableMap.keySet()) { - if (tableMap.get(str).equals("ip")) { - ipTable = str; - } else if (tableMap.get(str).equals("num")) { - numTable = str; - } else if (tableMap.get(str).equals("str")) { - strTable.add(str); - } - } - } - - configCompile.setStrRegionList(setStrRegionList(serviceType, groupId, date, strTable, index)); - configCompile.setIpRegionList(setIpRegionList(serviceType, groupId, date, ipTable, index)); - configCompile.setNumRegionList(setNumRegionList(serviceType, groupId, date, numTable, index)); - return configCompile; - - } - - public List setGroupList(Long compileId, Date date, Long groupId) { - List groupRelationList = new ArrayList(); - ConfigGroupRelation configGroupRelation = new ConfigGroupRelation(); - configGroupRelation.setGroupId(groupId); -// configGroupRelation.setId(groupId); - configGroupRelation.setCompileId(compileId); - configGroupRelation.setIsValid(1); - configGroupRelation.setOpTime(date); - groupRelationList.add(configGroupRelation); - allCount++; - return groupRelationList; - } - - public List setStrRegionList(Long service, Long groupId, Date date, List tableName, Long index) { - List strRegionList = new ArrayList(); - if (tableName != null & tableName.size() > 0) { - Long regionId = System.currentTimeMillis() + index; - System.out.println("Strid--------------------------" + regionId); - StrRegionTest strRegion = new StrRegionTest(); - strRegion.setRegionId(regionId); - strRegion.setGroupId(groupId); - strRegion.setKeywords("百度"); - strRegion.setExprType(0); - strRegion.setMatchMethod(0); - strRegion.setIsHexbin(0); - strRegion.setIsValid(1); - strRegion.setOpTime(date); - if (configSourcesService.isStrStrongRegion(tableName.get(0))) { - strRegion.setDistrict("南京"); - } - strRegion.setTableName(tableName.get(0)); - strRegion.setProcSeq(regionId); - strRegionList.add(strRegion); - - StrRegionTest strRegion1 = new StrRegionTest(); - Long regionId1 = System.currentTimeMillis() + index + 100000; - System.out.println("Strid===================================" + regionId); - strRegion1.setRegionId(regionId1); - strRegion1.setGroupId(groupId); - strRegion1.setKeywords("新浪"); - strRegion1.setExprType(0); - strRegion1.setMatchMethod(0); - strRegion1.setIsHexbin(0); - strRegion1.setIsValid(1); - strRegion1.setOpTime(date); - strRegion1.setProcSeq(regionId1); - if (tableName.size() > 1) { - strRegion1.setTableName(tableName.get(1)); - if (configSourcesService.isStrStrongRegion(tableName.get(1))) { - strRegion1.setDistrict("北京"); - } - } else { - strRegion1.setTableName(tableName.get(0)); - if (configSourcesService.isStrStrongRegion(tableName.get(0))) { - strRegion1.setDistrict("上海"); - } - } - strRegionList.add(strRegion1); - allCount++; - return strRegionList; - } else { - return strRegionList; - } - - } - - public List setIpRegionList(Long service, Long groupId, Date date, String tableName, Long index) { - List ipRegionList = new ArrayList(); - if (tableName != null) { - - IpRegionTest ipRegion = new IpRegionTest(); - Long regionId = System.currentTimeMillis() + index; - System.out.println("Ipid--------------------------" + regionId); - ipRegion.setRegionId(regionId); - ipRegion.setGroupId(groupId); - ipRegion.setAddrType(4); - ipRegion.setSrcIp("0.0.0.0"); - ipRegion.setMaskSrcIp("0.0.0.0"); - ipRegion.setSrcPort("0"); - ipRegion.setMaskSrcPort("0"); - ipRegion.setDstIp("0.0.0.0"); - ipRegion.setMaskDstIp("0.0.0.0"); - ipRegion.setDstPort("0"); - ipRegion.setMaskDstPort("0"); - ipRegion.setProtocol(0); - ipRegion.setDirection(0); - ipRegion.setIsValid(1); - ipRegion.setOpTime(date); - ipRegion.setTableName(tableName); - ipRegion.setProcSeq(regionId); - ipRegionList.add(ipRegion); - allCount++; - return ipRegionList; - } else { - return ipRegionList; - } - } - - public List setNumRegionList(Long service, Long groupId, Date date, String tableName, Long index) { - List numRegionList = new ArrayList(); - if (tableName != null) { - - NumRegionTest numRegion = new NumRegionTest(); - Long regionId = System.currentTimeMillis() + index; - System.out.println("numid--------------------------" + regionId); - numRegion.setRegionId(regionId); - numRegion.setGroupId(groupId); - numRegion.setLowBoundary(index); - numRegion.setUpBoundary(index); - numRegion.setIsValid(1); - numRegion.setOpTime(date); - numRegion.setTableName(tableName); - numRegion.setProcSeq(regionId); - numRegionList.add(numRegion); - allCount++; - return numRegionList; - } else { - return numRegionList; - } - } - - private void validateConfigSourceTest(SaveRequestLogThread thread, long start, ConfigSourceTest configSource) { - String errorInfo = ""; - List configCompileList = configSource.getConfigCompileList(); - if (StringUtils.isEmpty(configSource.getOperator())) { - errorInfo = "get operator is Empty"; - } - if (StringUtils.isEmpty(configSource.getVersion())) { - errorInfo = "get version is Empty"; - } - - if (!isBlank(configSource.getOpTime())) { - errorInfo = "get OpTime is Empty"; - } - - if (configCompileList.size() <= 0) { - errorInfo = "编译配置不能为空"; - } - if (!errorInfo.equals("")) { - throw new RestServiceException(thread, System.currentTimeMillis() - start, errorInfo, - RestBusinessCode.missing_args.getValue()); - } - - } - - private boolean isBlank(Date datetime) { - if (null != datetime) { - return true; - } - return false; - } - - public static synchronized String getId() { - - long nowDate = new Date().getTime(); - String hexString = Integer.toHexString((int) nowDate); - return hexString; - } - - public static void main(String[] args) { - try { - -// Calendar cl = Calendar.getInstance(); -// cl.add(Calendar.SECOND, 10); -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); -// System.out.println(sdf.format(cl.getTime().getTime() - 8 * 60 * 60 * 1000)); - // props.setProperty("jdbc.product.password", new - // String(AESUtil.decrypt(Base64.decodeBase64(productPassword), - // productScretKey))); - String Key = AESUtil.initKeyString(); - String password = new String(Base64.encodeBase64(AESUtil.encrypt("changan@2016".getBytes(), Key))); - String watchpwd = new String(AESUtil.decrypt(Base64.decodeBase64(password), Key)); - // String decryptKey = new - // String(AESUtil.decrypt(Base64.decodeBase64("IkkVipTYFzqpSaX3nYwjRQ=="), - // "lsBezRxQ38m60L5pWhzoyA==")); - System.out.println(Key); - System.out.println(password); - System.out.println(watchpwd); - List list = new ArrayList(); - // list.add("1"); - // new ConfigTestController().setStrRegionList(1l, 2l, new Date(), - // list); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} 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 6d03f07..5160a93 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -104,241 +104,6 @@ public class ConfigSourcesService extends BaseService { @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"); - typeMap.put("GSB_PZ_IP", "ip"); - typeMap.put("FAKE_REGION_EXTEND", "str"); - typeMap.put("KEYWORD_RANDOM_REGION", "str"); - typeMap.put("CTRL_URL_REGION", "str"); - 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("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");// 网站伪造 - 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");// 内容篡改 - 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("CTRL_URL_REGION", "str"); - tableMap.put(4, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_HTTP_REQ_BODY", "str"); - typeMap.put("DF_HTTP_RES_BODY", "str"); - tableMap.put(5, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_MAIL_HDR", "str"); - typeMap.put("DF_MAIL_BODY", "str"); - tableMap.put(13, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_DNS_REGION", "str"); - tableMap.put(6, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_FTP_URL", "str"); - tableMap.put(14, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - tableMap.put(7, typeMap); - tableMap.put(8, typeMap); - tableMap.put(9, typeMap); - tableMap.put(10, typeMap); - tableMap.put(11, typeMap); - typeMap.put("DF_SSL_REGION", "str"); - tableMap.put(12, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - 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); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("FX_DNS_REGION", "str"); - tableMap.put(16, typeMap); - - typeMap = new HashMap(); - typeMap.put("DJ_IP_PORT", "ip"); - typeMap.put("DJ_IP_PKT_BIN", "str"); - tableMap.put(48, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_HTTP_REQ_HDR", "str"); - typeMap.put("DJ_HTTP_URL", "str"); - tableMap.put(49, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_HTTP_RES_HDR", "str"); - tableMap.put(50, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_HTTP_REQ_BODY", "str"); - typeMap.put("DJ_HTTP_RES_BODY", "str"); - tableMap.put(51, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_MAIL_HDR", "str"); - typeMap.put("DJ_MAIL_BODY", "str"); - tableMap.put(60, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_DNS_RES_REGION", "str"); - typeMap.put("DJ_DNS_REQ_REGION", "str"); - tableMap.put(52, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_FTP_URL", "str"); - tableMap.put(53, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - tableMap.put(54, typeMap); - tableMap.put(55, typeMap); - tableMap.put(56, typeMap); - tableMap.put(57, typeMap); - tableMap.put(58, typeMap); - typeMap.put("DJ_SSL_REGION", "str"); - tableMap.put(59, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_L2TP_URL", "str"); - tableMap.put(32, typeMap); - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_PPTP_URL", "str"); - tableMap.put(33, typeMap); - - // 20161109新增业务类型 - 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_REQ_BODY", "str"); - typeMap.put("DF_HTTP_URL", "str"); - tableMap.put(17, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DF_HTTP_RES_HDR", "str"); - typeMap.put("DF_HTTP_RES_BODY", "str"); - typeMap.put("DF_HTTP_URL", "str"); - tableMap.put(18, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_HTTP_REQ_HDR", "str"); - typeMap.put("DJ_HTTP_REQ_BODY", "str"); - typeMap.put("DJ_HTTP_URL", "str"); - tableMap.put(61, typeMap); - - typeMap = new HashMap(); - typeMap.put("UNIVERSAL_PROTO_TYPE", "num"); - typeMap.put("UNIVERSAL_IP", "ip"); - typeMap.put("DJ_HTTP_RES_HDR", "str"); - 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"); - tableMap.put(35, typeMap); - tableMap.put(36, typeMap); - tableMap.put(37, typeMap); - return tableMap; - } /** * 批量(mybatis方式)修改配置业务逻辑-->1:先进行基础配置验证传过来的json串是否符合格式(配置分组关系前端不能设置为无效, @@ -717,16 +482,36 @@ public class ConfigSourcesService extends BaseService { List queryCompileGroupByPID, SqlSession batchSqlSession, StringBuffer sb) { Map>> map = new HashMap>>(); - Map> tableRelationMap = getTableRelation(); - Map updateTableMap = tableRelationMap.get(config - .getService().intValue());// 根据service获取需要操作的域配置表 - if (null == updateTableMap) { + Map updateTableMap = new HashMap(); + Map> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(config + .getService().intValue()); + if (sercieNameMap != null && sercieNameMap.size() > 0) { + for (Integer type : sercieNameMap.keySet()) { + String typeStr=""; +// 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置, + if ("12".equals(type.toString())) { + typeStr="ip"; + }else if ("13".equals(type.toString())) { + typeStr="str"; + }else if ("14".equals(type.toString())||"15".equals(type.toString())) { + typeStr="num"; + } + if (!"".equals(typeStr)) { + List tableList = sercieNameMap.get(type); + if (tableList != null && tableList.size() > 0) { + for (String table : tableList) { + updateTableMap.put(table.toUpperCase(),typeStr); + } + } + } + } + }else{ thread.setExceptionInfo("找不到编译对应的service" + sb.toString()); throw new RestServiceException(thread, System.currentTimeMillis() - start, "找不到编译对应的service" + sb.toString(), RestBusinessCode.missing_args.getValue()); } - + Long[] groupId = new Long[queryCompileGroupByPID.size()]; for (int i = 0; i < queryCompileGroupByPID.size(); i++) { groupId[i] = queryCompileGroupByPID.get(i).getGroupId(); @@ -966,7 +751,7 @@ public class ConfigSourcesService extends BaseService { if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) { for (StrRegion strRegion : configCompile.getStrRegionList()) { - if (!isStrStrongRegion(strRegion.getTableName())) { + if (!isStrStrongRegion(strRegion.getTableName(),configCompile.getService())) { if (strRegion.getRegionId() == null) { String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" @@ -1123,33 +908,33 @@ public class ConfigSourcesService extends BaseService { return configGroupRelationDao.queryCompileGroupByPID(compileId); } - 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); - } else { - queryStrRegionByGroupId = strRegionDao - .queryStrRegionByGroupId(tableName, groupId); - } - - if (null != queryStrRegionByGroupId - && queryStrRegionByGroupId.size() > 0) { - for (StrRegion strRegion : queryStrRegionByGroupId) { - strRegion.setTableName(tableName); - strRegionList.add(strRegion); - } - } - - } - } - - return strRegionList; - } +// 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); +// } else { +// queryStrRegionByGroupId = strRegionDao +// .queryStrRegionByGroupId(tableName, groupId); +// } +// +// if (null != queryStrRegionByGroupId +// && queryStrRegionByGroupId.size() > 0) { +// for (StrRegion strRegion : queryStrRegionByGroupId) { +// strRegion.setTableName(tableName); +// strRegionList.add(strRegion); +// } +// } +// +// } +// } +// +// return strRegionList; +// } public List getIpRegionByGId(String table, Long[] groupId) { List queryIpRegionByGroupId = ipRegionDao @@ -1169,28 +954,24 @@ public class ConfigSourcesService extends BaseService { return queryNumRegionByGroupId; } - public static boolean isStrStrongRegion(String tableName) { + public static boolean isStrStrongRegion(String tableName,Integer service) { if (null != tableName && !tableName.equals("")) { - tableName = tableName.toUpperCase(); List tableList = new ArrayList(); - tableList.add("DF_HTTP_REQ_HDR"); - tableList.add("FX_HTTP_REQ_HDR"); - tableList.add("DF_HTTP_RES_HDR"); - tableList.add("DF_DNS_REGION"); - tableList.add("FX_DNS_REGION"); - tableList.add("DF_SSL_REGION"); - tableList.add("DF_MAIL_HDR"); - tableList.add("DF_MAIL_BODY"); - - tableList.add("DJ_HTTP_REQ_HDR"); - tableList.add("DJ_HTTP_RES_HDR"); - tableList.add("DJ_DNS_REQ_REGION"); - tableList.add("DJ_DNS_RES_REGION"); - tableList.add("DJ_SSL_REGION"); - tableList.add("DJ_MAIL_HDR"); - tableList.add("DJ_MAIL_BODY"); - // tableList.add("DF_L2TP_URL");//20161021数据库中该表改为普通字符串表 - // tableList.add("DF_PPTP_URL");//20161021数据库中该表改为普通字符串表 + Map> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(service); + if (sercieNameMap != null && sercieNameMap.size() > 0) { + for (Integer type : sercieNameMap.keySet()) { + String typeStr=""; + // 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置, + if ("15".equals(type.toString())) { + List tableNameList = sercieNameMap.get(type); + if (tableNameList != null && tableNameList.size() > 0) { + for (String table : tableNameList) { + tableList.add(table.toUpperCase()); + } + } + } + } + } if (tableList.contains(tableName)) { return true; } else { @@ -1202,12 +983,12 @@ public class ConfigSourcesService extends BaseService { } - public Map getTableMap(Integer service) { - if (map == null || map.size() == 0) { - map = getTableRelation(); - } - return map.get(service); - } +// public Map getTableMap(Integer service) { +// if (map == null || map.size() == 0) { +// map = getTableRelation(); +// } +// return map.get(service); +// } public Map> getMap() { return map; @@ -1547,10 +1328,13 @@ public class ConfigSourcesService extends BaseService { return "error"; } } - } catch (Exception e) { + }catch (RestServiceException e ){ + msgList.add(e); + return "error"; + }catch (Exception e) { // TODO: handle exception msgList.add(e); - //CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); + CompileVal.setBusinessCode(RestBusinessCode.unknow_error.getValue()); return "error"; } try { @@ -1708,7 +1492,7 @@ public class ConfigSourcesService extends BaseService { if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) { for (StrRegion strRegion : configCompile.getStrRegionList()) { - if (!isStrStrongRegion(strRegion.getTableName())) { + if (!isStrStrongRegion(strRegion.getTableName(),configCompile.getService())) { if (strRegion.getRegionId() == null) { String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" @@ -2764,11 +2548,30 @@ public class ConfigSourcesService extends BaseService { 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获取需要操作的域配置表 - if (null == updateTableMap || updateTableMap.size() == 0) { + Map updateTableMap = new HashMap(); + Map> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(config + .getService().intValue()); + if (sercieNameMap != null && sercieNameMap.size() > 0) { + for (Integer type : sercieNameMap.keySet()) { + String typeStr=""; +// 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置, + if ("12".equals(type.toString())) { + typeStr="ip"; + }else if ("13".equals(type.toString())) { + typeStr="str"; + }else if ("14".equals(type.toString())||"15".equals(type.toString())) { + typeStr="num"; + } + if (!"".equals(typeStr)) { + List tableList = sercieNameMap.get(type); + if (tableList != null && tableList.size() > 0) { + for (String table : tableList) { + updateTableMap.put(table.toUpperCase(),typeStr); + } + } + } + } + }else{ thread.setExceptionInfo("找不到编译对应的service" + sb.toString()); throw new RestServiceException(thread, System.currentTimeMillis() - start, "找不到编译对应的service" + sb.toString(), diff --git a/src/main/resources/applicationConfig-rule.properties b/src/main/resources/applicationConfig-rule.properties index ea4cebe..532e7b2 100644 --- a/src/main/resources/applicationConfig-rule.properties +++ b/src/main/resources/applicationConfig-rule.properties @@ -35,7 +35,7 @@ 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; #0x12 DNS阻断 18=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;15:NTC_DNS_REGION;18:NTC_IP_RANGE #0x13 SSL阻断 -19=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:NTC_SSL_SNI,NTC_SSL_SAN,NTC_SSL_CA;18:NTC_IP_RANGE +19=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:NTC_SSL_SNI,NTC_SSL_SAN,NTC_SSL_CN;18:NTC_IP_RANGE #0x14 MAIL阻断 20=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;15:NTC_MAIL_HDR,NTC_MAIL_BODY;16:NTC_FILE_DIGEST;18:NTC_IP_RANGE #0x15 FTP阻断 @@ -69,7 +69,7 @@ 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; #0x82 DNS监测 130=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;15:NTC_DNS_REGION;18:NTC_IP_RANGE #0x83 SSL监测 -131=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:NTC_SSL_SNI,NTC_SSL_SAN,NTC_SSL_CA;18:NTC_IP_RANGE +131=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:NTC_SSL_SNI,NTC_SSL_SAN,NTC_SSL_CN;18:NTC_IP_RANGE #0x84 MAIL监测 132=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;15:NTC_MAIL_HDR,NTC_MAIL_BODY;16:NTC_FILE_DIGEST;18:NTC_IP_RANGE #0x85 FTP监测