From d5e423fca69fbf2c5ccb0920641c3af78d02e2bf Mon Sep 17 00:00:00 2001 From: RenKaiGe-Office Date: Thu, 16 Aug 2018 18:43:29 +0800 Subject: [PATCH] =?UTF-8?q?1:=E4=BF=AE=E6=94=B9maat=E7=B1=BB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=A8=8B=E5=BA=8F=202:=E6=B7=BB=E5=8A=A0unmaat?= =?UTF-8?q?=E7=B1=BB=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nis/util/ServiceAndRDBIndexReal.java | 11 + .../restful/MaatTestController.java | 567 ++++++++---------- .../service/restful/MaatTestServiceimpl.java | 339 ++++++++++- 3 files changed, 564 insertions(+), 353 deletions(-) diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index 8c420a4..4fe4233 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -342,4 +342,15 @@ public class ServiceAndRDBIndexReal { public static Integer getValveDBIndex() { return valveDBIndex; } + + public static Map getUnMaatSercieNameMap() { + return unMaatSercieNameMap; + } + + public static void setUnMaatSercieNameMap(Map unMaatSercieNameMap) { + ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap; + } + + + } diff --git a/src/main/java/com/nis/web/controller/restful/MaatTestController.java b/src/main/java/com/nis/web/controller/restful/MaatTestController.java index 7af2f6a..7f9f5fa 100644 --- a/src/main/java/com/nis/web/controller/restful/MaatTestController.java +++ b/src/main/java/com/nis/web/controller/restful/MaatTestController.java @@ -10,20 +10,31 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import com.nis.domain.restful.*; -import com.nis.web.service.AuditLogThread; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +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.domain.restful.CommonSourceFieldCfg; +import com.nis.domain.restful.ConfigCompile; +import com.nis.domain.restful.ConfigGroupRelation; +import com.nis.domain.restful.DigestRegion; +import com.nis.domain.restful.IpRegion; +import com.nis.domain.restful.NumRegion; +import com.nis.domain.restful.StrRegion; import com.nis.util.Configurations; import com.nis.util.ExceptionUtil; import com.nis.util.FileUtils; +import com.nis.util.ReadCommSourceXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; import com.nis.util.StringUtil; +import com.nis.web.service.AuditLogThread; import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.restful.ConfigRedisService; import com.nis.web.service.restful.ConfigSourcesService; @@ -33,11 +44,10 @@ import com.wordnik.swagger.annotations.ApiOperation; import com.wordnik.swagger.annotations.ApiParam; @RestController -@RequestMapping("test") -@Api(value = "ConfigSourcesController", description = "测试maat及非maat配置入库,取消功能") +@RequestMapping("${servicePath}/test") +@Api(value = "MaatTestController", description = "测试maat及unMaat配置入库,取消功能") public class MaatTestController { - // private static Logger logger = - // LoggerFactory.getLogger(MaatTestController.class); + private static Logger logger = LoggerFactory.getLogger(MaatTestController.class); @Autowired MaatTestServiceimpl maatTestServiceimpl; @Autowired @@ -48,259 +58,6 @@ public class MaatTestController { ServicesRequestLogService servicesRequestLogService; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - @RequestMapping(value = "/cfg/v1/saveUnMaat", method = RequestMethod.GET) - @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") - @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) - public String saveUnMaat(Integer type) { - try { - List> listMap = new ArrayList>(); - if (type == 1) { - Map map = new HashMap(); - Integer service = 261; - long id = configRedisService.getIncrId("seq_compileid"); - // int id=2; - map.put("cfg_id", id + ""); - map.put("is_valid", "1"); - map.put("dst_file", "home"); - map.put("dst_file_md5", "fasdfdasfsdafdsafadsf"); - map.put("op_time", new Date().getTime() + ""); - map.put("level", "20"); - map.put("file_id", id + ""); - map.put("service", service + ""); - listMap.add(map); - - Map>> configMap = new HashMap>>(); - configMap.put(1, listMap); - configRedisService.saveUnMaatConfig(configMap); - } else { - Integer service = 265; - Map map = new HashMap(); - long id = configRedisService.getIncrId("seq_compileid"); - // int id=2; - map.put("cfg_id", id + ""); - map.put("is_valid", "1"); - map.put("service", "100"); - map.put("description", "123" + id); - map.put("level", "20"); - listMap.add(map); - map.put("service", service + ""); - - Map>> configMap = new HashMap>>(); - configMap.put(1, listMap); - configRedisService.saveUnMaatConfig(configMap); - } - return "ok"; - } catch (Exception e) { - e.printStackTrace(); - } - return "false"; - } - - @RequestMapping(value = "/cfg/v1/delUnMaat", method = RequestMethod.GET) - @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") - @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) - public String delUnMaat(int redisDB, int service, long id) { - try { - Map> map = new HashMap>(); - ArrayList arrayList = new ArrayList(); - arrayList.add(id); - map.put(service, arrayList); - Map>> idMap = new HashMap>>(); - idMap.put(redisDB, map); - configRedisService.delUnMaatConfig(idMap, true); - // configRedisService.saveMaatConfig(listMap, service); - // new ConfigRedisServiceimpl().GETMaatConfig(listMap); - return "ok"; - } catch (Exception e) { - e.printStackTrace(); - } - return "false"; - } - - @RequestMapping(value = "/cfg/v1/delMaat", method = RequestMethod.GET) - @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") - @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) - public String delMaat(int redisDB, int service, long id) { - try { - Map> map = new HashMap>(); - ArrayList arrayList = new ArrayList(); - arrayList.add(id); - map.put(service, arrayList); - Map>> idMap = new HashMap>>(); - idMap.put(redisDB, map); - - boolean delMaatConfig = configRedisService.delMaatConfig(idMap); - return "ok"; - } catch (Exception e) { - e.printStackTrace(); - } - return "false"; - } - - @RequestMapping(value = "/cfg/v1/saveMaat", method = RequestMethod.GET) - @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") - @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) - public String saveMaat(Integer service) { - try { - Map> configMap = new HashMap>(); - List redisDBByService = ServiceAndRDBIndexReal.getRedisDBByService(service); - long seq_groupid = configRedisService.getIncrId("SEQ_GROUPID"); - List listMap = new ArrayList(); - long seq_regionid2 = configRedisService.getIncrId("SEQ_REGIONID"); - listMap.add(getMaatConfig1(service, seq_groupid, seq_regionid2)); - // listMap.add(getMaatConfig2(service, seq_groupid,seq_regionid2)); - - for (Integer db : redisDBByService) { - configMap.put(db, listMap); - } - configRedisService.saveMaatConfig(configMap); - // configRedisService.saveMaatConfig(listMap, service); - // new ConfigRedisServiceimpl().GETMaatConfig(listMap); - return "ok"; - } catch (Exception e) { - e.printStackTrace(); - } - return "false"; - } - - public MaatConfig getMaatConfig1(Integer service, long seq_groupid, long seq_regionid2) { - String time = new Date().getTime() + ""; - Map configMap1 = new HashMap(); - long seq_compileid = configRedisService.getIncrId("SEQ_COMPILEID"); - long seq_regionid1 = configRedisService.getIncrId("SEQ_REGIONID"); - // int id=2; - configMap1.put("compile_id", seq_compileid + ""); - configMap1.put("service", service + ""); - configMap1.put("action", "0"); - configMap1.put("do_blacklist", "1"); - configMap1.put("do_log", "1"); - configMap1.put("effective_range", "0"); - configMap1.put("user_region", "0"); - configMap1.put("is_valid", "1"); - configMap1.put("group_num", "1"); - configMap1.put("father_cfg_id", "0"); - configMap1.put("op_time", time); - - List> groupMapList = new ArrayList>(); - Map groupMap1 = new HashMap(); - groupMap1.put("group_id", seq_groupid + ""); - groupMap1.put("compile_id", seq_compileid + ""); - groupMap1.put("is_valid", "1"); - groupMap1.put("op_time", time); - groupMap1.put("service", service + ""); - groupMapList.add(groupMap1); - Long incrId = configRedisService.getIncrId("SEQ_GROUPID"); - Map groupMap2 = new HashMap(); - groupMap2.put("group_id", incrId + ""); - groupMap2.put("compile_id", seq_compileid + ""); - groupMap2.put("is_valid", "1"); - groupMap2.put("op_time", time); - groupMap2.put("service", service + ""); - groupMapList.add(groupMap2); - List> ipRegionMapList = new ArrayList>(); - Map strMap = new HashMap(); - strMap.put("group_id", incrId + ""); - strMap.put("region_id", seq_regionid1 + ""); - strMap.put("addr_type", "4"); - strMap.put("src_ip", "0.0.0.0"); - strMap.put("mask_src_ip", "255.255.255.255"); - strMap.put("src_port", "0"); - strMap.put("mask_src_port", "0"); - strMap.put("dst_ip", "0.0.0.0"); - strMap.put("mask_dst_ip", "255.255.255.255"); - strMap.put("dst_port", "0"); - strMap.put("mask_dst_port", "0"); - strMap.put("protocol", "0"); - strMap.put("direction", "0"); - strMap.put("is_valid", "1"); - strMap.put("op_time", time); - strMap.put("service", service + ""); - - ipRegionMapList.add(strMap); - - strMap = new HashMap(); - strMap.put("group_id", seq_groupid + ""); - strMap.put("region_id", seq_regionid2 + ""); - strMap.put("addr_type", "4"); - strMap.put("src_ip", "0.0.0.0"); - strMap.put("mask_src_ip", "255.255.255.255"); - strMap.put("src_port", "0"); - strMap.put("mask_src_port", "0"); - strMap.put("dst_ip", "0.0.0.0"); - strMap.put("mask_dst_ip", "255.255.255.255"); - strMap.put("dst_port", "0"); - strMap.put("mask_dst_port", "0"); - strMap.put("protocol", "0"); - strMap.put("direction", "0"); - strMap.put("is_valid", "1"); - strMap.put("op_time", time); - strMap.put("service", service + ""); - ipRegionMapList.add(strMap); - - MaatConfig maatConfig = new MaatConfig(); - maatConfig.setCompileMap(configMap1); - maatConfig.setGroupMapList(groupMapList); - maatConfig.setService(service); - maatConfig.setIpRegionMapList(ipRegionMapList); - return maatConfig; - } - - public MaatConfig getMaatConfig2(Integer service, long seq_groupid, long seq_regionid2) { - String time = new Date().getTime() + ""; - Map configMap = new HashMap(); - long seq_compileid = configRedisService.getIncrId("SEQ_COMPILEID"); - - // int id=2; - configMap.put("compile_id", seq_compileid + ""); - configMap.put("service", service + ""); - configMap.put("action", "0"); - configMap.put("do_blacklist", "1"); - configMap.put("do_log", "1"); - configMap.put("effective_range", "0"); - configMap.put("user_region", "0"); - configMap.put("is_valid", "1"); - configMap.put("group_num", "1"); - configMap.put("father_cfg_id", "0"); - configMap.put("op_time", time); - - List> groupMapList = new ArrayList>(); - Map groupMap = new HashMap(); - groupMap.put("group_id", seq_groupid + ""); - groupMap.put("compile_id", seq_compileid + ""); - groupMap.put("is_valid", "1"); - groupMap.put("op_time", time); - groupMap.put("service", service + ""); - groupMapList.add(groupMap); - - List> ipRegionMapList = new ArrayList>(); - Map strMap = new HashMap(); - strMap = new HashMap(); - strMap.put("group_id", seq_groupid + ""); - strMap.put("region_id", seq_regionid2 + ""); - strMap.put("addr_type", "4"); - strMap.put("src_ip", "0.0.0.0"); - strMap.put("mask_src_ip", "255.255.255.255"); - strMap.put("src_port", "0"); - strMap.put("mask_src_port", "0"); - strMap.put("dst_ip", "0.0.0.0"); - strMap.put("mask_dst_ip", "255.255.255.255"); - strMap.put("dst_port", "0"); - strMap.put("mask_dst_port", "0"); - strMap.put("protocol", "0"); - strMap.put("direction", "0"); - strMap.put("is_valid", "1"); - strMap.put("op_time", time); - strMap.put("service", service + ""); - ipRegionMapList.add(strMap); - - MaatConfig maatConfig = new MaatConfig(); - maatConfig.setCompileMap(configMap); - maatConfig.setGroupMapList(groupMapList); - maatConfig.setService(service); - maatConfig.setIpRegionMapList(ipRegionMapList); - return maatConfig; - } - @RequestMapping(value = "/cfg/v1/testDelMaat", method = RequestMethod.GET) @ApiOperation(value = "测试批量删除maat配置", httpMethod = "GET", response = String.class, notes = "测试批量删除maat配置,configId为配置id,多个配置id用逗号分隔") @ApiParam(value = "测试批量删除maat配置", name = "testDelMaat", required = true) @@ -323,7 +80,7 @@ public class MaatTestController { compileMap.put(serviceType, idList); } } - FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "开始删除业务类型" + serviceType + "下的配置" + configId + "\n", + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "开始删除业务类型" + serviceType + "下的maat配置" + configId + "\n", Configurations.getStringProperty("maatTestLogPath", ""), true); Map>> restMap = new HashMap>>(); @@ -350,70 +107,28 @@ public class MaatTestController { try { if (!configRedisService.delMaatConfig(restMap)) { FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的配置" + configId + "失败\n", + sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的maat配置" + configId + "失败\n", Configurations.getStringProperty("maatTestLogPath", ""), true); return "error"; } else { FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的配置" + configId + "成功\n", + sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的maat配置" + configId + "成功\n", Configurations.getStringProperty("maatTestLogPath", ""), true); } } catch (Exception e) { - e.printStackTrace(); - FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的配置" + configId + "失败,失败原因:" - + ExceptionUtil.getExceptionMsg(e) + "\n", - Configurations.getStringProperty("maatTestLogPath", ""), true); + String exceptionMsg = ExceptionUtil.getExceptionMsg(e); + logger.error(exceptionMsg); + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的maat配置" + configId + + "失败,失败原因:" + exceptionMsg + "\n", Configurations.getStringProperty("maatTestLogPath", ""), true); return "error"; } return "ok"; } - @RequestMapping(value = "/cfg/v1/testSaveMaatMore", method = RequestMethod.GET) - @ApiOperation(value = "测试批量保存maat配置", httpMethod = "GET", response = String.class, notes = "测试批量保存maat配置,service:需要保存的业务类型,saveCount:保存几条配置") - @ApiParam(value = "测试批量保存maat配置", name = "testSaveMaat", required = true) - public String testSaveMaatMore(@RequestParam(required = true) Integer service, - @RequestParam(required = true) Integer saveCount, Integer forCount) { - List list = new ArrayList(); - try { - - for (int a = 0; a < forCount; a++) { - long start = System.currentTimeMillis(); - AuditLogThread thread = new AuditLogThread(); - StringBuffer sb = new StringBuffer(); - List configCompileList = new ArrayList(); - for (int i = 0; i < saveCount; i++) { - configCompileList.add(getConfigCompile(service)); - } - // 保存测试配置 - configSourcesService.saveMaatConfig(thread, start, configCompileList, sb); - List compileIdList = new ArrayList(); - for (ConfigCompile configCompile : configCompileList) { - compileIdList.add(configCompile.getCompileId()); - } - FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条数据成功,配置id是" - + compileIdList + "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n", - Configurations.getStringProperty("maatTestLogPath", ""), true); - // 验证数据是否在正确 - maatTestServiceimpl.getKeys(configCompileList); - list.add(testDelMaat(compileIdList.toString().replace("[", "").replace("]", ""), service)); - } - - // return "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" - // + service + "&configId=" - // + compileIdList.toString().replace("[", "").replace("]", ""); - } catch (Exception e) { - // TODO: handle exception - e.printStackTrace(); - } - return list.toString(); - } - @RequestMapping(value = "/cfg/v1/testSaveMaat", method = RequestMethod.GET) - @ApiOperation(value = "测试批量保存maat配置", httpMethod = "GET", response = String.class, notes = "测试批量保存maat配置,service:需要保存的业务类型,saveCount:保存几条配置") + @ApiOperation(value = "测试批量保存maat配置", httpMethod = "GET", response = String.class, notes = "测试批量保存maat配置,service:需要保存的业务类型,service为-1表示下发所有maat类配置,saveCount:保存几条配置") @ApiParam(value = "测试批量保存maat配置", name = "testSaveMaat", required = true) public Map testSaveMaat(@RequestParam(required = true) Integer service, @RequestParam(required = true) Integer saveCount) { @@ -442,17 +157,16 @@ public class MaatTestController { compileIdList.add(configCompile.getCompileId()); } FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "业务类型" + ser + "添加" + saveCount + "条数据成功,配置id是" + sdf.format(new Date()) + "\t" + "业务类型" + ser + "添加" + saveCount + "条maat配置成功,配置id是" + compileIdList + "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n", Configurations.getStringProperty("maatTestLogPath", ""), true); // 验证数据是否在正确 - maatTestServiceimpl.getKeys(configCompileList); - map.put(ser, "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" + ser + maatTestServiceimpl.getMaatKeys(configCompileList); + map.put(ser, "http://127.0.0.1:8080/galaxy/service/test/cfg/v1/testDelMaat?serviceType=" + ser + "&configId=" + compileIdList.toString().replace("[", "").replace("]", "")); - - + testDelMaat(compileIdList.toString().replace("[", "").replace("]", ""), ser); - + } } else { if (sercieNameMap.containsKey(service)) { @@ -467,12 +181,12 @@ public class MaatTestController { compileIdList.add(configCompile.getCompileId()); } FileUtils.addStrToFile( - sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条数据成功,配置id是" + sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条maat配置成功,配置id是" + compileIdList + "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n", Configurations.getStringProperty("maatTestLogPath", ""), true); // 验证数据是否在正确 - maatTestServiceimpl.getKeys(configCompileList); - map.put(service, "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" + maatTestServiceimpl.getMaatKeys(configCompileList); + map.put(service, "http://127.0.0.1:8080/galaxy/service/test/cfg/v1/testDelMaat?serviceType=" + service + "&configId=" + compileIdList.toString().replace("[", "").replace("]", "")); testDelMaat(compileIdList.toString().replace("[", "").replace("]", ""), service); } else { @@ -485,19 +199,13 @@ public class MaatTestController { } } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + String exceptionMsg = ExceptionUtil.getExceptionMsg(e); + logger.error(exceptionMsg); + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "error:添加业务类型" + service + "下的maat配置失败,失败原因:" + exceptionMsg + "\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); map.put(-4, "error"); } - - - - - - - - - return map; } @@ -625,6 +333,7 @@ public class MaatTestController { private ConfigGroupRelation getConfigGroupRelation(long compileId) { ConfigGroupRelation group = new ConfigGroupRelation(); group.setCompileId(compileId); + group.setGroupId(configRedisService.getIncrId("SEQ_GROUPID")); group.setIsValid(1); group.setOpTime(new Date()); @@ -694,4 +403,204 @@ public class MaatTestController { } + @RequestMapping(value = "/cfg/v1/testSaveUnMaat", method = RequestMethod.GET) + @ApiOperation(value = "测试批量保存unmaat配置", httpMethod = "GET", response = Map.class, notes = "测试批量保存unmaat配置,service需要保存的业务类型,service为-1表示下发所有unmaat类配置,saveCount为每类配置下发的条数") + @ApiParam(value = "测试批量保存unmaat配置", name = "测试批量删除unmaat配置", required = true) + public Map testSaveUnMaat(@RequestParam(required = true) Integer service, + @RequestParam(required = true) Integer saveCount, HttpServletRequest request, + HttpServletResponse response) { + Map map = new HashMap(); + try { + if (service == -1) { + Map unMaatSercieNameMap = ServiceAndRDBIndexReal.getUnMaatSercieNameMap(); + if (unMaatSercieNameMap != null && unMaatSercieNameMap.size() > 0) { + Set keySet = unMaatSercieNameMap.keySet(); + for (Integer ser : keySet) { + getUnMaatStr(ser, saveCount, map); + } + } + } else { + getUnMaatStr(service, saveCount, map); + } + } catch (Exception e) { + String exceptionMsg = ExceptionUtil.getExceptionMsg(e); + logger.error(exceptionMsg); + + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:添加业务类型" + service + "下的unMaat类配置失败,失败原因:" + + exceptionMsg + "\n", Configurations.getStringProperty("maatTestLogPath", ""), true); + + map.put(-4, "error"); + } + return map; + } + + @RequestMapping(value = "/cfg/v1/testDelUnMaat", method = RequestMethod.GET) + @ApiOperation(value = "测试批量删除unmaat配置", httpMethod = "GET", response = String.class, notes = "测试批量删除unmaat配置,configId为配置id,多个配置id用逗号分隔") + @ApiParam(value = "测试批量删除unmaat配置", name = "testDelMaat", required = true) + public String testDelUnMaat(@RequestParam(required = true) String configId, + @RequestParam(required = true) Integer serviceType) { + String[] configArr = null; + if (configId.contains(",")) { + configArr = configId.split(","); + } else { + configArr = new String[1]; + configArr[0] = configId; + } + Map> compileMap = new HashMap>(); + for (String id : configArr) { + if (compileMap.containsKey(serviceType)) { + compileMap.get(serviceType).add(Long.valueOf(id.trim())); + } else { + List idList = new ArrayList(); + idList.add(Long.valueOf(id.trim())); + compileMap.put(serviceType, idList); + } + } + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "开始删除业务类型" + serviceType + "下的unmaat类配置" + configId + "\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + + 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) { + for (Integer dbIndex : dbIndexList) { + if (restMap.containsKey(dbIndex)) { + restMap.get(dbIndex).put(service, compileMap.get(service)); + } else { + Map> map = new HashMap>(); + map.put(service, compileMap.get(service)); + restMap.put(dbIndex, map); + } + } + } else { + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:获取业务类型" + service + "对应的redisDb失败\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return "error"; + } + } + try { + if (!configRedisService.delUnMaatConfig(restMap, true)) { + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的unmaat类配置" + + configId + "失败\n", Configurations.getStringProperty("maatTestLogPath", ""), true); + return "error"; + } else { + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的unmaat类配置" + configId + "成功\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + + } + } catch (Exception e) { + String exceptionMsg = ExceptionUtil.getExceptionMsg(e); + logger.error(exceptionMsg); + FileUtils + .addStrToFile( + sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的unMaat类配置" + configId + + "失败,失败原因:" + exceptionMsg + "\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + + return "error"; + } + return "ok"; + } + + /** + * 组装json串,然后下发配置,在验证配置是否正确,然后删除配置 + * @param service + * @param saveCount + * @param map + */ + private void getUnMaatStr(Integer service, Integer saveCount, Map map) { + try { + ArrayList compileIdList = new ArrayList(); + List commonSourceFieldCfgList = ReadCommSourceXmlUtil + .getCommonSourceCfgByService(service.toString()); + if (commonSourceFieldCfgList != null && commonSourceFieldCfgList.size() > 0) { + StringBuffer jsonString = new StringBuffer(); + jsonString.append("["); + for (int i = 0; i < saveCount; i++) { + jsonString.append("{"); + for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { + String fieldType = commonSourceFieldCfg.getFieldType(); + String srcName = commonSourceFieldCfg.getSrcName(); + jsonString.append("\""); + jsonString.append(srcName); + jsonString.append("\":"); + if (fieldType.equals("String")) { + if (srcName.toLowerCase().equals("service")) { + jsonString.append("\"" + service + "\""); + } else if (srcName.toLowerCase().equals("dstfile")) { + jsonString.append( + "\"http://10.0.6.249/group1/M00/00/02/CgAG-VtziqWAIzafAAITEbfJ8Zw992.jpg\""); + } else { + jsonString.append("\"" + UUID.randomUUID() + "\""); + } + } else if (fieldType.equals("Number")) { + if (srcName.toLowerCase().equals("addrtype")) { + jsonString.append("4"); + } else if (srcName.toLowerCase().equals("action")) { + jsonString.append(ServiceAndRDBIndexReal.getActionByService(service)); + } else if (srcName.toLowerCase().equals("protocol")) { + jsonString.append("0"); + } else if (srcName.toLowerCase().equals("direction")) { + jsonString.append("0"); + } else if (srcName.toLowerCase().equals("location")) { + jsonString.append("1"); + } else if (srcName.toLowerCase().equals("isvalid")) { + jsonString.append("1"); + } else if (srcName.toLowerCase().equals("cfgid")) { + Long incrId = configRedisService.getIncrId("seq_compileid"); + compileIdList.add(incrId); + jsonString.append(incrId); + } else { + if (commonSourceFieldCfg.getDefaultVal() != null) { + jsonString.append(commonSourceFieldCfg.getDefaultVal()); + } else { + jsonString.append(System.currentTimeMillis()); + } + } + } else if (fieldType.equals("IP")) { + if (srcName.toLowerCase().equals("srcip")) { + jsonString.append("\"1.1.1.1\""); + } else { + jsonString.append("\"2.2.2.2\""); + } + } else if (fieldType.equals("Port")) { + jsonString.append("\"80\""); + } else if (fieldType.equals("Date")) { + jsonString.append("\"" + sdf.format(new Date()) + "\""); + } + jsonString.append(","); + } + String str = jsonString.substring(0, jsonString.lastIndexOf(",")); + jsonString.setLength(0); + jsonString.append(str); + jsonString.append("},"); + } + String jsonStr = jsonString.substring(0, jsonString.lastIndexOf(",")); + jsonStr += "]"; + map.put(service, "http://127.0.0.1:8080/galaxy/service/test/cfg/v1/testDelUnMaat?serviceType=" + service + + "&configId=" + compileIdList.toString().replace("[", "").replace("]", "")); + configSourcesService.saveCommonSources(null, -1, jsonStr); + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条数据成功,配置id是" + + compileIdList + "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + + // 验证数据是否在正确 + maatTestServiceimpl.getUnMaatKeys(jsonStr, service); + // 删除配置 + testDelUnMaat(compileIdList.toString().replace("[", "").replace("]", ""), service); + } + } catch (Exception e) { + String exceptionMsg = ExceptionUtil.getExceptionMsg(e); + logger.error(exceptionMsg); + FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:添加业务类型" + service + "下的unMaat类配置失败,失败原因:" + + exceptionMsg + "\n", Configurations.getStringProperty("maatTestLogPath", ""), true); + map.put(-4, "error"); + } + + } } diff --git a/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java b/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java index feadae2..9dc4a32 100644 --- a/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java @@ -1,36 +1,51 @@ package com.nis.web.service.restful; import java.lang.reflect.Field; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.nis.domain.MaatXmlConfig; import com.nis.domain.MaatXmlExpr; +import com.nis.domain.restful.CommonSourceFieldCfg; import com.nis.domain.restful.ConfigCompile; import com.nis.domain.restful.ConfigGroupRelation; import com.nis.domain.restful.DigestRegion; import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.StrRegion; +import com.nis.restful.RestBusinessCode; +import com.nis.restful.RestServiceException; +import com.nis.util.BasicProvingUtil; import com.nis.util.CamelUnderlineUtil; import com.nis.util.Configurations; +import com.nis.util.Constants; import com.nis.util.FileUtils; import com.nis.util.JedisUtils; +import com.nis.util.ReadCommSourceXmlUtil; import com.nis.util.ReadMaatXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; +import com.nis.util.StringUtil; + +import net.sf.json.JSONObject; @Service() public class MaatTestServiceimpl { - // private static Logger logger = - // LoggerFactory.getLogger(MaatTestServiceimpl.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - public void getKeys(List configCompileList) { + public void getMaatKeys(List configCompileList) throws Exception { if (configCompileList != null && configCompileList.size() > 0) { for (ConfigCompile configCompile : configCompileList) { Integer service = configCompile.getService(); @@ -45,7 +60,7 @@ public class MaatTestServiceimpl { } public void getConfigByKey(Integer redisDB, Integer service, ConfigCompile configCompile, - MaatXmlConfig maatXmlConfig) { + MaatXmlConfig maatXmlConfig) throws Exception { if (maatXmlConfig != null && configCompile != null) { Long compileId = configCompile.getCompileId(); validData(service, 10, compileId, configCompile.getCompileId(), redisDB, null, maatXmlConfig, configCompile, @@ -95,7 +110,7 @@ public class MaatTestServiceimpl { } public void validData(Integer service, Integer type, Long compileId, Long id, Integer redisDb, String tableName, - MaatXmlConfig maatXmlConfig, Object obj, ConfigCompile configCompile) { + MaatXmlConfig maatXmlConfig, Object obj, ConfigCompile configCompile) throws Exception { List expressionList = maatXmlConfig.getExpressionList(); String[] valArr = null; String key = null; @@ -131,11 +146,16 @@ public class MaatTestServiceimpl { } } key = keyBF.toString().toUpperCase(); - String[] valSplit = maatXmlExpr.getValueExpression().split(";"); + String[] valSplit = maatXmlExpr.getValueExpression().replace("; 0;\\n", "").replace("\\t", "") + .split(";"); for (String valStr : valSplit) { - if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) { - valStr = valStr.trim().replace("[", "").replace("]", ""); - valList.add(valStr); + if (valStr != null && !valStr.trim().equals("")) { + if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) { + valStr = valStr.trim().replace("[", "").replace("]", ""); + valList.add(valStr); + } else { + valList.add(valStr); + } } } String val = JedisUtils.get(key, redisDb); @@ -143,7 +163,7 @@ public class MaatTestServiceimpl { break; } } - if (sysoLog(valArr, valList, obj, redisDb, key, configCompile,service)) { + if (sysoLog(valArr, valList, obj, redisDb, key, configCompile, service)) { FileUtils .addStrToFile( "\t" + sdf.format(new Date()) + " 编译配置id为" + compileId + "的配置中,在" + redisDb + "号redis库中key=" @@ -153,23 +173,22 @@ public class MaatTestServiceimpl { } private boolean sysoLog(String[] valArr, List valList, Object obj, Integer redisDb, String key, - ConfigCompile configCompile,Integer service) { + ConfigCompile configCompile, Integer service) throws Exception { if (valList == null || valList.size() == 0) { FileUtils.addStrToFile( - "\t" + sdf.format(new Date()) + " error:service="+service +"时拼接value属性名,value表达式为空请检查\n", + "\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接value属性名,value表达式为空请检查\n", Configurations.getStringProperty("maatTestLogPath", ""), true); return false; } if (valArr == null || valArr.length == 0) { FileUtils.addStrToFile( - "\t" + sdf.format(new Date()) + " error:service="+service +"时拼接value值错误,value数组为空\n", + "\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接value值错误,value数组为空\n", Configurations.getStringProperty("maatTestLogPath", ""), true); return false; } if (valList == null || key.trim().equals("")) { - FileUtils.addStrToFile( - "\t" + sdf.format(new Date()) + " error:service="+service +"时拼接key=null请检查\n", + FileUtils.addStrToFile("\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接key=null请检查\n", Configurations.getStringProperty("maatTestLogPath", ""), true); return false; } @@ -198,16 +217,288 @@ public class MaatTestServiceimpl { return bool; } - private String getFieldValueByFieldName(String fieldName, Object obj) { - try { - // Field field = obj.getClass().getField(fieldName); + private String getFieldValueByFieldName(String fieldName, Object obj) throws Exception { + // Field field = obj.getClass().getField(fieldName); - Field field = obj.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(obj).toString(); - } catch (Exception e) { - e.printStackTrace(); + Field field = obj.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(obj).toString(); + } + + public void getUnMaatKeys(String jsonStr, Integer service) { + MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); + List redisDBList = ServiceAndRDBIndexReal.getRedisDBByService(service); + for (Integer redisDB : redisDBList) { + JsonArray jsonObjectList = new JsonParser().parse(jsonStr).getAsJsonArray(); + for (int i = 0; i < jsonObjectList.size(); i++) { + JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); + Map srcMap = JSONObject.fromObject(JSONObject.fromObject((jsonObj.toString()))); + validUnMaatConfig(service, redisDB, maatXmlConfig, srcToDstMap(srcMap, service)); + } } - return null; + } + + /** + * 根据applicationConfig-parser.xml将srcmap转换为dstmap,即将srcName替换为dstName + * @param srcMap + * @param service + * @return + */ + private Map srcToDstMap(Map srcMap, Integer service) { + Map dstMap = new HashMap(); + List commonSourceFieldCfgList = ReadCommSourceXmlUtil + .getCommonSourceCfgByService(srcMap.get("service").toString().trim()); + if (StringUtil.isEmpty(commonSourceFieldCfgList)) { + throw new RestServiceException(RestBusinessCode.ServiceIsWrong.getErrorReason() + ",请检查service配置是否正确", + RestBusinessCode.ServiceIsWrong.getValue()); + } + // 获取IP类型 + Integer ipType = null; + String ipTypeName = ""; + + for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { + if (commonSourceFieldCfg.getDstName().equals("addr_type")) { + Object obj = srcMap.get(commonSourceFieldCfg.getSrcName()); + String dstVal = obj.toString().trim(); + ipTypeName = commonSourceFieldCfg.getSrcName(); + // regexp 特殊格式正则验证 + Boolean valFlag = true; + if (!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())) { + Pattern pattern = Pattern.compile(commonSourceFieldCfg.getRegexp()); + Matcher matcher = pattern.matcher(dstVal); + valFlag = valFlag & matcher.matches(); + } + if (!valFlag) { + throw new RestServiceException(RestBusinessCode.IpTypeIsWrong.getErrorReason(), + RestBusinessCode.IpTypeIsWrong.getValue()); + } + ipType = Integer.parseInt(dstVal); + } + // 验证service与action是否匹配 + if (commonSourceFieldCfg.getDstName().equals("action")) { + Object obj = srcMap.get(commonSourceFieldCfg.getSrcName()); + String dstVal = obj.toString().trim(); + if (Integer.valueOf(dstVal).compareTo(ServiceAndRDBIndexReal + .getActionByService(Integer.valueOf(srcMap.get("service").toString().trim()))) != 0) { + throw new RestServiceException(RestBusinessCode.ServiceUnmatchAction.getErrorReason(), + RestBusinessCode.ServiceUnmatchAction.getValue()); + } + } + } + if (ipType == null) { + ipType = 4; + } + for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { + // 是否必填 + if (commonSourceFieldCfg.getIsRequired() && !srcMap.containsKey(commonSourceFieldCfg.getSrcName())) { + throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数不能为空", + RestBusinessCode.FieldIsNull.getValue()); + } + Object obj = srcMap.get(commonSourceFieldCfg.getSrcName()); + String dstVal = obj.toString().trim(); + // 字段类型 String Number Date Ip Port + String dstStr = StringUtil.isEmpty(dstVal) ? commonSourceFieldCfg.getDefaultVal() : dstVal; + if (!StringUtil.isEmpty(dstStr) && dstStr.startsWith("[") && dstStr.endsWith("]")) { + dstStr = srcMap.get(dstStr.substring(1, dstStr.length() - 1)).toString(); + } + + if ("dstFile".equals(commonSourceFieldCfg.getSrcName())) { + if ("dst_file".equals(commonSourceFieldCfg.getDstName())) { + String maatTableName = ServiceAndRDBIndexReal + .getUnMaatTableName(Integer.valueOf(srcMap.get("service").toString().trim())); + String dstPath = Constants.MM_SAMPLE_DST_PATH.replace("{tableType}", + maatTableName.substring(maatTableName.lastIndexOf("_") + 1)); + dstStr = dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/") + 1)); + } else if ("file_id".equals(commonSourceFieldCfg.getDstName())) { + dstStr = dstStr.substring(dstStr.indexOf("group")); + } + } + switch (commonSourceFieldCfg.getFieldType()) { + case "Number": + if (!StringUtil.isNumeric(dstStr)) { + throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数不能格式不正确,必需是数值型", + RestBusinessCode.MastNumberic.getValue()); + } + break; + case "Date": + try { + sdf.setLenient(false); + Date date = sdf.parse(dstStr); + dstStr = date.getTime() + "000"; + } catch (ParseException e) { + // TODO Auto-generated catch block + throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数格式不正确或不是规范的日期串", + RestBusinessCode.MastDate.getValue()); + } + break; + case "IP": + Boolean isSrcInfo = commonSourceFieldCfg.getIsSrcInfo(); + Integer valAddrType = ipType; + if (ipType.intValue() == 46) { + valAddrType = isSrcInfo ? 4 : 6; + } else if (ipType.intValue() == 64) { + valAddrType = isSrcInfo ? 6 : 4; + } else if (ipType.intValue() == 10) { + valAddrType = null; + } + if (!BasicProvingUtil.isIpOrIpMask(dstStr, valAddrType)) { + throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数格式不正确或与" + ipTypeName + "不一致", + RestBusinessCode.IpIsUnMatchType.getValue()); + } + break; + case "Port": + if (!BasicProvingUtil.isPortOrPortMask(dstStr)) { + throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数不能格式不正确,不是合法的Port", + RestBusinessCode.PortIsNotVal.getValue()); + } + break; + + } + // 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)) { + flag = true; + } + + } 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) { + flag = true; + } + } + if (flag) { + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数不在有效范围(" + commonSourceFieldCfg.getRange() + ")", + RestBusinessCode.ValueInWrongRange.getValue()); + } + } + // regexp 特殊格式正则验证 + Boolean valFlag = true; + if (!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())) { + Pattern pattern = Pattern.compile(commonSourceFieldCfg.getRegexp()); + Matcher matcher = pattern.matcher(dstStr); + valFlag = valFlag & matcher.matches(); + } + if (valFlag) { + dstMap.put(commonSourceFieldCfg.getDstName(), dstStr); + } else { + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数格式与正则(" + commonSourceFieldCfg.getRegexp() + ")不匹配", + RestBusinessCode.ValueInWrongRegexp.getValue()); + } + } + return dstMap; + } + + public void validUnMaatConfig(Integer service, Integer redisDb, MaatXmlConfig maatXmlConfig, + Map map) { + Long compileId = Long.parseLong(map.get("cfg_id"));// 配置id固定叫cfg_id + List expressionList = maatXmlConfig.getExpressionList(); + String[] valArr = null; + String key = null; + List valList = new ArrayList(); + for (MaatXmlExpr maatXmlExpr : expressionList) { + StringBuffer keyBF = new StringBuffer(); + String[] keySplit = maatXmlExpr.getKeyExpression().split(";"); + for (String keyStr : keySplit) { + if (!StringUtils.isEmpty(keyStr) + && keyStr.trim().startsWith("[") & keyStr.toLowerCase().contains("id")) { + keyBF.append(compileId); + } else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) { + keyStr = keyStr.trim().replace("{", "").replace("}", ""); + if (keyStr.toLowerCase().contains("un_maat_table_name")) { + String unMaatTableName = ServiceAndRDBIndexReal.getUnMaatTableName(service); + if (unMaatTableName == null) { + throw new RuntimeException("未从业务类型和表对应关系中,找到业务类型:" + service + ",对应的真实表名"); + } else { + keyBF.append(unMaatTableName); + } + } + } else { + keyBF.append(keyStr.trim()); + } + } + key = keyBF.toString().toUpperCase(); + String[] valSplit = maatXmlExpr.getValueExpression().replace("; 0;\\n", "").replace("\\t", "") + .split(";"); + for (String valStr : valSplit) { + if (valStr != null && !valStr.trim().equals("")) { + if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) { + valStr = valStr.trim().replace("[", "").replace("]", ""); + valList.add(valStr);// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t + } else { + valList.add(valStr); + } + } + } + String val = JedisUtils.get(key, redisDb).replace(" ", "\t"); + valArr = val.split("\\t"); + break; + } + if (sysoUnMaatLog(valArr, valList, redisDb, key, map, service)) { + FileUtils + .addStrToFile( + "\t" + sdf.format(new Date()) + " 编译配置id为" + compileId + "的配置中,在" + redisDb + "号redis库中key=" + + key + "的值与实际插入的值相符\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + } + } + + private boolean sysoUnMaatLog(String[] valArr, List valList, Integer redisDb, String key, + Map map, Integer service) { + + if (valList == null || valList.size() == 0) { + FileUtils.addStrToFile( + "\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接value属性名,value表达式为空请检查\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return false; + } + if (valArr == null || valArr.length == 0) { + FileUtils.addStrToFile( + "\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接value值错误,value数组为空\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return false; + } + if (valList == null || key.trim().equals("")) { + FileUtils.addStrToFile("\t" + sdf.format(new Date()) + " error:service=" + service + "时拼接key=null请检查\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return false; + } + boolean bool = true; + for (int i = 0; i < valList.size(); i++) { + String attrName = valList.get(i); + if (!attrName.toLowerCase().equals("op_time")) { + // String filedName = CamelUnderlineUtil.underlineToCamel(attrName); + if (!isNum(attrName)) { + String beanVal = map.get(attrName); + String redisVal = valArr[i]; + if (beanVal == null || redisVal == null || !beanVal.trim().equals(redisVal.trim())) { + FileUtils.addStrToFile( + "\t" + sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i + + "位" + attrName + "的值:" + redisVal + "与实际传的值不一样,实际值是:{}\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return false; + } + } + } + } + return bool; + } + + public boolean isNum(String str) { + try { + Integer.parseInt(str); + } catch (Exception e) { + return false; + } + + return true; } }