diff --git a/src/main/java/com/nis/interceptor/LogInterceptor.java b/src/main/java/com/nis/interceptor/LogInterceptor.java index 405e721..e3569fd 100644 --- a/src/main/java/com/nis/interceptor/LogInterceptor.java +++ b/src/main/java/com/nis/interceptor/LogInterceptor.java @@ -5,8 +5,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.text.SimpleDateFormat; -import java.util.Enumeration; -import java.util.Map; import javax.servlet.ServletInputStream; import javax.servlet.ServletRequest; diff --git a/src/main/java/com/nis/util/ExceptionUtil.java b/src/main/java/com/nis/util/ExceptionUtil.java new file mode 100644 index 0000000..6f004c2 --- /dev/null +++ b/src/main/java/com/nis/util/ExceptionUtil.java @@ -0,0 +1,31 @@ +package com.nis.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +/** + *

Title: ExceptionUtils.java

+ *

Description: 获取异常信息内容

+ *

Company: IIE

+ * @author rkg + * @date 2018年3月5日 + * + */ + +public class ExceptionUtil { + public static String getExceptionMsg(Exception e) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream pout = new PrintStream(out); + e.printStackTrace(pout); + String msg = new String(out.toByteArray()); + pout.close(); + try { + out.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + return msg; + + } +} diff --git a/src/main/java/com/nis/util/FileUtils.java b/src/main/java/com/nis/util/FileUtils.java index e71bd8b..579116b 100644 --- a/src/main/java/com/nis/util/FileUtils.java +++ b/src/main/java/com/nis/util/FileUtils.java @@ -3,12 +3,16 @@ */ package com.nis.util; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.Reader; import java.net.URLEncoder; import java.security.MessageDigest; import java.util.Enumeration; @@ -667,7 +671,6 @@ public class FileUtils extends org.apache.commons.io.FileUtils { } - /** * 获取文件后缀 * @@ -689,10 +692,8 @@ public class FileUtils extends org.apache.commons.io.FileUtils { } // 文件下载 - public static void fileDownload(HttpServletRequest request, - HttpServletResponse response, - String filename, - String filepath) throws IOException{ + public static void fileDownload(HttpServletRequest request, HttpServletResponse response, String filename, + String filepath) throws IOException { FileInputStream in = null; ServletOutputStream out = null; try { @@ -718,47 +719,152 @@ public class FileUtils extends org.apache.commons.io.FileUtils { out.write(buffer, 0, len); } out.flush(); - } finally { + } finally { if (in != null) { in.close(); - in=null; + in = null; } if (out != null) { out.close(); - out=null; + out = null; } } } + /** * 计算文件MD5 * @param file * @return */ - public static String getFileMD5(File file){ - if(!file.isFile()){ + public static String getFileMD5(File file) { + if (!file.isFile()) { return ""; } - String md5 = ""; - MessageDigest digest=null; - FileInputStream in=null; - byte[] buffer=new byte[1024]; + String md5 = ""; + MessageDigest digest = null; + FileInputStream in = null; + byte[] buffer = new byte[1024]; int len; - try{ - digest=MessageDigest.getInstance("MD5"); - in=new FileInputStream(file); - while ((len=in.read(buffer,0,1024)) !=-1) { - digest.update(buffer,0,len); + try { + digest = MessageDigest.getInstance("MD5"); + in = new FileInputStream(file); + while ((len = in.read(buffer, 0, 1024)) != -1) { + digest.update(buffer, 0, len); } in.close(); - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); return ""; } byte[] b = digest.digest(); - for (int i=0; i < b.length; i++) { - md5 += Integer.toString( (b[i] & 0xff ) + 0x100, 16).substring(1);//加0x100是因为有的b[i]的十六进制只有1位 + for (int i = 0; i < b.length; i++) { + md5 += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);// 加0x100是因为有的b[i]的十六进制只有1位 } -// BigInteger bigInt=new BigInteger(1,digest.digest()); + // BigInteger bigInt=new BigInteger(1,digest.digest()); return md5; } + + /** + * 以字节为单位读取文件,通常用于读取二进制文件,如图片 + * @param path 文件路径 + * @return + */ + public static String readByBytes(String path) { + String content = null; + try { + InputStream inputStream = new FileInputStream(path); + + StringBuffer sb = new StringBuffer(); + int c = 0; + byte[] bytes = new byte[1024]; + while ((c = inputStream.read(bytes)) != -1) { + sb.append(new String(bytes, 0, c, "utf-8")); + } + content = sb.toString(); + inputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return content; + } + + /** + * 以行为单位读取文件,常用语读取面向行的格式化文件 + * @param path + * @return + */ + public static String readByLines(String path) { + String content = null; + try { + + BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(new FileInputStream(path), "utf-8")); + + StringBuffer sb = new StringBuffer(); + String temp = null; + while ((temp = bufferedReader.readLine()) != null) { + sb.append(temp); + } + content = sb.toString(); + bufferedReader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return content; + } + + /** + * 以字符串为单位读取文件,常用与读取文本文件 + * @param path + * @return + */ + public static String readByChar(String path) { + String content = null; + try { + Reader reader = new InputStreamReader(new FileInputStream(path), "utf-8"); + + StringBuffer sb = new StringBuffer(); + char[] tempChars = null; + while ((reader.read(tempChars)) != -1) { + sb.append(tempChars); + } + content = sb.toString(); + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return content; + } + + /** + * 把content的内容写到文件中 + * @param content 内容 + * @param path 文件路径 + * @param isAppend 是否追加,true追加,flase是覆盖文件 + * @return + */ + public static boolean addStrToFile(String content, String path, boolean isAppend) { + FileWriter fw = null; + try { + fw = new FileWriter(new File(path), isAppend); + if (content != null) { + fw.write(content); + } + + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (fw != null) { + try { + fw.flush(); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + } + return true; + } } 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 345942b..bdcb635 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -74,14 +74,14 @@ public class ConfigSourcesController extends BaseRestController { List> listMap = new ArrayList>(); if (type == 1) { Map map = new HashMap(); - Integer service = 98; + 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("time_stamp", new Date().getTime() + ""); + map.put("op_time", new Date().getTime() + ""); map.put("level", "20"); map.put("file_id", id + ""); map.put("service", service + ""); @@ -91,7 +91,7 @@ public class ConfigSourcesController extends BaseRestController { configMap.put(1, listMap); configRedisService.saveUnMaatConfig(configMap); } else { - Integer service = 100; + Integer service = 265; Map map = new HashMap(); long id = configRedisService.getIncrId("seq_compileid"); // int id=2; 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 2074fe4..4854f66 100644 --- a/src/main/java/com/nis/web/controller/restful/MaatTestController.java +++ b/src/main/java/com/nis/web/controller/restful/MaatTestController.java @@ -1,12 +1,14 @@ package com.nis.web.controller.restful; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.UUID; -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; @@ -20,7 +22,10 @@ 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.ServiceAndRDBIndexReal; +import com.nis.util.StringUtil; import com.nis.web.service.SaveRequestLogThread; import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.restful.ConfigRedisService; @@ -34,7 +39,8 @@ import com.wordnik.swagger.annotations.ApiParam; @RequestMapping("${servicePath}") @Api(value = "ConfigSourcesController", description = "测试maat及非maat配置入库,取消功能") public class MaatTestController { - private static Logger logger = LoggerFactory.getLogger(MaatTestController.class); + // private static Logger logger = + // LoggerFactory.getLogger(MaatTestController.class); @Autowired MaatTestServiceimpl maatTestServiceimpl; @Autowired @@ -43,29 +49,134 @@ public class MaatTestController { ConfigSourcesService configSourcesService; @Autowired ServicesRequestLogService servicesRequestLogService; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @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) + public String testDelMaat(@RequestParam(required = true) String configId, + @RequestParam(required = true) Integer serviceType) { + String[] configArr = null; + if (configId.contains(",")) { + configArr = configId.split(","); + } + 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 + "下的配置" + 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" + "获取业务类型" + service + "对应的redisDb失败\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return "error"; + } + } + try { + if (!configRedisService.delMaatConfig(restMap)) { + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的配置" + configId + "失败\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + return "error"; + } else { + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的配置" + configId + "成功\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); + + } + } catch (Exception e) { + e.printStackTrace(); + FileUtils.addStrToFile( + sdf.format(new Date()) + "\t" + "删除业务类型" + serviceType + "下的配置" + configId + "失败,失败原因:" + + ExceptionUtil.getExceptionMsg(e) + "\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(); + for (int a = 0; a < forCount; a++) { + long start = System.currentTimeMillis(); + SaveRequestLogThread thread = new SaveRequestLogThread(); + 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 list.toString(); + // return "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" + // + service + "&configId=" + // + compileIdList.toString().replace("[", "").replace("]", ""); + } @RequestMapping(value = "/cfg/v1/testSaveMaat", method = RequestMethod.GET) @ApiOperation(value = "测试批量保存maat配置", httpMethod = "GET", response = String.class, notes = "测试批量保存maat配置,service:需要保存的业务类型,saveCount:保存几条配置") @ApiParam(value = "测试批量保存maat配置", name = "testSaveMaat", required = true) public String testSaveMaat(@RequestParam(required = true) Integer service, @RequestParam(required = true) Integer saveCount) { - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = new SaveRequestLogThread(); - 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()); - } - logger.warn("业务类型{}添加{}条数据成功,配置id是{}", service, saveCount, compileIdList); - // 验证数据是否在正确 - maatTestServiceimpl.getKeys(configCompileList); - return "ok"; + long start = System.currentTimeMillis(); + SaveRequestLogThread thread = new SaveRequestLogThread(); + 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); + return "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" + service + "&configId=" + + compileIdList.toString().replace("[", "").replace("]", ""); } private ConfigCompile getConfigCompile(Integer service) { diff --git a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java index a79ac19..fcf13a4 100644 --- a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java +++ b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java @@ -1,18 +1,16 @@ package com.nis.web.dao.impl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.StringRedisSerializer; -import org.springframework.stereotype.Repository; import com.nis.web.service.SpringContextHolder; -@Repository -public abstract class BaseRedisDao { +public class BaseRedisDao { + private static Logger logger = LoggerFactory.getLogger(BaseRedisDao.class); - //@Autowired - protected RedisTemplate redisTemplate1; + // @Autowired + // protected RedisTemplate redisTemplate1; // public void setRedisTemplate(RedisTemplate redisTemplate) { // StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); @@ -20,9 +18,60 @@ public abstract class BaseRedisDao { // redisTemplate.setValueSerializer(stringRedisSerializer); // this.redisTemplate = redisTemplate; // } - protected static void setRedisDataBase(int index, RedisTemplate redisTemplate) { - JedisConnectionFactory connectionFactory = SpringContextHolder.getBean("connectionFactory" + index); - //connectionFactory.setDatabase(index); - redisTemplate.setConnectionFactory(connectionFactory); + // protected static void setRedisDataBase(int index, RedisTemplate + // redisTemplate) { + // JedisConnectionFactory connectionFactory = + // SpringContextHolder.getBean("connectionFactory" + index); + // connectionFactory.setDatabase(index); + // redisTemplate.setConnectionFactory(connectionFactory); + // } + + /** + * 利用redis连接对象判断key是否存在,在事务中判断key是否存在时由于判断是否开启了multi(事务需要开启multi),直接返回了null,导致判断key的时候出现了问题 + * @param index 几号redis库 + * @param key 需要判断的key + * @param redisTemplate RedisTemplate对象 + * @return + */ + public static Boolean keyIsExist(int index, String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean("redisTemplateNoTrans" + index); + if (redisTemplate != null) { + redisTemplate.setEnableTransactionSupport(false); + Boolean hasKey = redisTemplate.hasKey(key); + if (hasKey == null) { + logger.error("判断key是否存在时出现错误"); + } + return hasKey; + } else { + throw new RuntimeException("从" + index + "号redis库中判断" + key + "是否存在时失败,失败原因:redisTemplate为null请联系开发人员"); + } } + + /** + * 获取自增长id + * @param index + * @param key + * @return + */ + public static Long getIncr(int index, String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean("redisTemplateNoTrans" + index); + if (redisTemplate != null) { + redisTemplate.setEnableTransactionSupport(false); + Long id = redisTemplate.boundValueOps(key.toUpperCase()).increment(1l); + return id; + } else { + throw new RuntimeException("从" + index + "号redis库中获取" + key + "的自增长值时失败,失败原因:redisTemplate为null请联系开发人员"); + } + } + + public static String getValByKey(int index, String key) { + RedisTemplate redisTemplate = SpringContextHolder.getBean("redisTemplateNoTrans" + index); + if (redisTemplate != null) { + redisTemplate.setEnableTransactionSupport(false); + return redisTemplate.opsForValue().get(key); + } else { + throw new RuntimeException("从" + index + "号redis库中获取" + key + "的值时失败,失败原因:redisTemplate为null请联系开发人员"); + } + } + } diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java index 0f5854d..0bc56b3 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java @@ -18,13 +18,11 @@ import org.springframework.util.StringUtils; import com.nis.domain.MaatXmlConfig; import com.nis.domain.MaatXmlExpr; import com.nis.domain.MaatXmlSeq; -import com.nis.domain.restful.CompileAndGroupRelations; -import com.nis.domain.restful.GroupAndRegionRelations; import com.nis.domain.restful.MaatConfig; -import com.nis.listener.CompileGroupRegionRela; import com.nis.util.Configurations; import com.nis.util.ReadMaatXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; +import com.nis.web.dao.impl.BaseRedisDao; import com.nis.web.service.SpringContextHolder; @Service() @@ -41,7 +39,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { .getBean("redisTemplate" + redisDBIndex); List> listMap = configMap.get(redisDBIndex); if (listMap != null && listMap.size() > 0) { - String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION"); + String maatVersionStr = BaseRedisDao.getValByKey(redisDBIndex, "MAAT_VERSION"); if (maatVersionStr == null) { maatVersionStr = "0"; } @@ -140,7 +138,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { if (!seqKey.toUpperCase().equals("MAAT_VERSION")) { Integer operation = maatXmlSeq.getOperation(); if (operation == 1) { - redisTemplate.boundValueOps(seqKey.toUpperCase()).increment(1l); + BaseRedisDao.getIncr(redisDBIndex, seqKey.toUpperCase()); + // redisTemplate.boundValueOps().increment(1l); } } @@ -149,7 +148,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { throw new RuntimeException("无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确"); } } - redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); + BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION"); logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, Integer.valueOf(maatVersionStr) + 1); count++; @@ -175,11 +174,12 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { */ private void addMaatRelation(Map> configMap) { if (configMap != null && configMap.size() > 0) { + int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); + RedisTemplate redisTemplate = SpringContextHolder + .getBean("redisTemplate" + idRelaRedisDBIndex); for (Integer redisDBIndex : configMap.keySet()) { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { - int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); - RedisTemplate redisTemplate = SpringContextHolder - .getBean("redisTemplate" + idRelaRedisDBIndex); + List maatConfigList = configMap.get(redisDBIndex); if (maatConfigList != null && maatConfigList.size() > 0) { Map> compileAndGroupMap = new HashMap>(); @@ -217,21 +217,20 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { Map> map = new HashMap>(); int service = maatConfig.getService(); MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), - redisTemplate, map, redisDBIndex, compileId); + addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), map, + redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(), - redisTemplate, map, redisDBIndex, compileId); + map, redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(), - redisTemplate, map, redisDBIndex, compileId); + map, redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 15, maatConfig.getStrStrRegionMapList(), - redisTemplate, map, redisDBIndex, compileId); + map, redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 16, - maatConfig.getFileDigestRegionMapList(), redisTemplate, map, redisDBIndex, - compileId); + maatConfig.getFileDigestRegionMapList(), map, redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 17, - maatConfig.getFileLikeRegionMapList(), redisTemplate, map, redisDBIndex, compileId); + maatConfig.getFileLikeRegionMapList(), map, redisDBIndex, compileId); addGroupAndRegionRelations(maatXmlConfig, service, 18, maatConfig.getIpClientRangeMapList(), - redisTemplate, map, redisDBIndex, compileId); + map, redisDBIndex, compileId); for (String groupIdStr : map.keySet()) { List list = map.get(groupIdStr); @@ -289,8 +288,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { * @param compileAndGroupRelations */ private Map> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type, - List> regionMapList, RedisTemplate redisTemplate, - Map> groupAndRegionMap, int redisDBIndex, String compileId) { + List> regionMapList, Map> groupAndRegionMap, int redisDBIndex, + String compileId) { if (regionMapList != null && regionMapList.size() > 0) { for (Map map : regionMapList) { List expressionList = maatXmlConfig.getExpressionList(); @@ -341,103 +340,6 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { } - /** - * 下发配置成功后,需要更新编译,组,域等配置id的对应关系 - */ - public void addMaatRelationOld(Map> configMap) { - if (configMap != null && configMap.size() > 0) { - for (Integer redisDBIndex : configMap.keySet()) { - if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { - List maatConfigList = configMap.get(redisDBIndex); - if (maatConfigList != null && maatConfigList.size() > 0) { - for (MaatConfig maatConfig : maatConfigList) { - Map compileMap = maatConfig.getCompileMap(); - String cfgIdStr = compileMap.get("compile_id"); - CompileAndGroupRelations compileAndGroupRelations = new CompileAndGroupRelations(); - compileAndGroupRelations.setCompileId(Long.valueOf(cfgIdStr)); - compileAndGroupRelations.setGroupIdList(new ArrayList()); - - int service = maatConfig.getService(); - MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), - compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(), - compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(), - compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 15, - maatConfig.getStrStrRegionMapList(), compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 16, - maatConfig.getFileDigestRegionMapList(), compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 17, - maatConfig.getFileLikeRegionMapList(), compileAndGroupRelations); - addGroupAndRegionRelationsOld(maatXmlConfig, service, 18, - maatConfig.getIpClientRangeMapList(), compileAndGroupRelations); - - CompileGroupRegionRela.addIdRelation(redisDBIndex, compileAndGroupRelations); - } - } - } else { - throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号"); - } - } - } else { - throw new RuntimeException("参数不能为空"); - } - - } - - /** - * 封装组id与域id对应关系并添加到对象中 - * @param regionMapList - * @param compileAndGroupRelations - */ - private void addGroupAndRegionRelationsOld(MaatXmlConfig maatXmlConfig, int service, int type, - List> regionMapList, CompileAndGroupRelations compileAndGroupRelations) { - if (regionMapList != null && regionMapList.size() > 0 && compileAndGroupRelations != null) { - for (Map map : regionMapList) { - List expressionList = maatXmlConfig.getExpressionList(); - String maatKey = null; - for (MaatXmlExpr maatXmlExpr : expressionList) { - if (type == maatXmlExpr.getType().intValue()) { - StringBuffer keyBF = new StringBuffer(); - String[] keySplit = maatXmlExpr.getKeyExpression().split(";"); - for (String keyStr : keySplit) { - if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) { - keyStr = keyStr.trim().replace("[", "").replace("]", ""); - keyBF.append(map.get(keyStr)); - } else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) { - keyStr = keyStr.trim().replace("{", "").replace("}", ""); - if (keyStr.toLowerCase().contains("table_name")) { - String argTableName = map.get("table_name"); - String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type, - argTableName == null ? null : argTableName); - if (maatTableName == null) { - throw new RuntimeException( - "未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名"); - } else { - keyBF.append(maatTableName); - } - } - - } else { - keyBF.append(keyStr.trim()); - } - } - maatKey = keyBF.toString(); - break; - } - } - String groupIdStr = map.get("group_id"); - GroupAndRegionRelations groupAndRegionRelations = new GroupAndRegionRelations(); - groupAndRegionRelations.setGroupId(Long.valueOf(groupIdStr)); - groupAndRegionRelations.setRegionId(maatKey); - compileAndGroupRelations.getGroupIdList().add(groupAndRegionRelations); - } - } - - } - @Override @Transactional public boolean saveMaatConfig(Map> configMap) { @@ -447,7 +349,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { RedisTemplate redisTemplate = SpringContextHolder .getBean("redisTemplate" + redisDBIndex); - String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION"); + String maatVersionStr = BaseRedisDao.getValByKey(redisDBIndex, "MAAT_VERSION"); if (maatVersionStr == null) { maatVersionStr = "0"; } @@ -460,7 +362,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); setConfig(maatConfig, maatXmlConfig, maatVersion, service, redisTemplate, redisDBIndex); } - redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); + BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION"); + // redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, Integer.valueOf(maatVersionStr) + 1); count++; @@ -682,8 +585,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { } public Long getIncrId(String key) { - RedisTemplate redisTemplate = SpringContextHolder.getBean("redisTemplate0"); - Long id = redisTemplate.boundValueOps(key.toUpperCase()).increment(1l); + Long id = BaseRedisDao.getIncr(0, key); logger.info("从0号redis数据库获取{}成功,自增后的值是{}", key, id); return id; } @@ -698,9 +600,10 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { .getBean("redisTemplate" + redisDBIndex); Map> serviceConfigMap = idMap.get(redisDBIndex); if (serviceConfigMap != null && serviceConfigMap.size() > 0) { - String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION"); + String maatVersionStr = BaseRedisDao.getValByKey(redisDBIndex, "MAAT_VERSION"); if (maatVersionStr == null) { - maatVersionStr = "0"; + throw new RuntimeException("从" + redisDBIndex + + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); } if (maatVersionStr != null) { Long maatVersion = Long.valueOf(maatVersionStr) + 1; @@ -745,7 +648,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { } maatKey = keyBF.toString(); String oldKey = maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); - if (redisTemplate.hasKey(oldKey.toString().toUpperCase())) { + if (BaseRedisDao.keyIsExist(redisDBIndex, + oldKey.toString().toUpperCase())) { redisTemplate.rename(oldKey.toString().toUpperCase(), keyBF.toString().toUpperCase()); logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, @@ -757,8 +661,6 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { + "请检查id映射关系是否正确"); } } - // redisTemplate.boundValueOps(keyBF.toString().toUpperCase()).set(valBF.toString()); - } for (MaatXmlExpr maatXmlExpr : expressionList) { if (maatXmlExpr.getKeyExpression().toUpperCase() @@ -797,7 +699,9 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { if (!seqKey.toUpperCase().equals("MAAT_VERSION")) { Integer operation = maatXmlSeq.getOperation(); if (operation == 1) { - redisTemplate.boundValueOps(seqKey.toUpperCase()).increment(1l); + + BaseRedisDao.getIncr(redisDBIndex, seqKey.toUpperCase()); + // redisTemplate.boundValueOps(seqKey.toUpperCase()).increment(1l); } } @@ -807,7 +711,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { "无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确"); } } - redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); + BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION"); + // redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, Integer.valueOf(maatVersionStr) + 1); count++; @@ -837,19 +742,16 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { public boolean delMaatConfig(Map>> idMap) { if (idMap != null && idMap.size() > 0) { int count = 0; + int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); for (Integer redisDBIndex : idMap.keySet()) { - - int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); - RedisTemplate idRredisTemplate = SpringContextHolder - .getBean("redisTemplate" + idRelaRedisDBIndex); - RedisTemplate redisTemplate = SpringContextHolder .getBean("redisTemplate" + redisDBIndex); Map> serviceConfigMap = idMap.get(redisDBIndex); if (serviceConfigMap != null && serviceConfigMap.size() > 0) { - String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION"); + String maatVersionStr = BaseRedisDao.getValByKey(redisDBIndex, "MAAT_VERSION"); if (maatVersionStr == null) { - maatVersionStr = "0"; + throw new RuntimeException("从" + redisDBIndex + + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); } // MaatRelation maatRelation = // CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex); @@ -859,10 +761,11 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { for (Integer service : serviceConfigMap.keySet()) { MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); removeConfig(serviceConfigMap.get(service), maatXmlConfig, maatVersion, service, - redisTemplate, redisDBIndex, idRredisTemplate); + redisTemplate, redisDBIndex, idRelaRedisDBIndex); } - redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); + BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION"); + // redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, Integer.valueOf(maatVersionStr) + 1); count++; @@ -892,36 +795,54 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { * @param maatRelation id对应关系对象 */ private void removeConfig(List idList, MaatXmlConfig maatXmlConfig, Long maatVersion, int service, - RedisTemplate redisTemplate, int redisDBIndex, - RedisTemplate idRredisTemplate) { + RedisTemplate redisTemplate, int redisDBIndex, int idRelaRedisDBIndex) { + if (idList != null && idList.size() > 0 && maatXmlConfig != null) { for (Long id : idList) { removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion.doubleValue(), service, redisTemplate, redisDBIndex, null);// 10代表是编译配置 String compileStr = redisDBIndex + ":COMPILEGROUP:" + id; // 获取当前编译下所有的分组id - String groupCompileStrs = idRredisTemplate.opsForValue().get(compileStr); - if (groupCompileStrs != null && !groupCompileStrs.equals("")) { + String groupCompileStrs = BaseRedisDao.getValByKey(idRelaRedisDBIndex, compileStr); + if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) { String[] split = groupCompileStrs.split(";"); for (String groupId : split) { - String compileGroupStr = idRredisTemplate.opsForValue().get(groupId); - String[] compileGroupArr = compileGroupStr.split(";");// 获取组对应的编译id - if (compileGroupArr != null && compileGroupArr.length == 1) {// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 - for (String compileId : compileGroupArr) { - if (compileId.equals(compileStr)) {// - String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION"); - String regionStr = idRredisTemplate.opsForValue().get(groupRegionKey); - String[] regionKeyArr = regionStr.split(";"); - if (regionKeyArr != null && regionKeyArr.length > 0) { - removeRegionConfig(maatXmlConfig, regionKeyArr, maatVersion.doubleValue(), - service, redisTemplate, redisDBIndex); + String compileGroupStr = BaseRedisDao.getValByKey(idRelaRedisDBIndex, groupId); + if (compileGroupStr != null && !compileGroupStr.trim().equals("")) { + String[] compileGroupArr = compileGroupStr.split(";");// 获取组对应的编译id + if (compileGroupArr != null && compileGroupArr.length == 1) {// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 + for (String compileId : compileGroupArr) { + if (compileId.equals(compileStr)) {// + String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION"); + String regionStr = BaseRedisDao.getValByKey(idRelaRedisDBIndex, groupRegionKey); + if (regionStr != null && !regionStr.trim().equals("")) { + String[] regionKeyArr = regionStr.split(";"); + if (regionKeyArr != null && regionKeyArr.length > 0) { + removeRegionConfig(maatXmlConfig, regionKeyArr, + maatVersion.doubleValue(), service, redisTemplate, + redisDBIndex); + } + } else { + throw new RuntimeException( + "从" + idRelaRedisDBIndex + "号redis库中获取" + groupRegionKey + + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + + } } } } + removeCompileAndGroupConfig(maatXmlConfig, + groupId.replace(redisDBIndex + ":GROUPCOMPILE:", ""), 11, maatVersion.doubleValue(), + service, redisTemplate, redisDBIndex, id + "");// 11代表是分组配置 + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + "号redis库中获取" + groupId + + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + } - removeCompileAndGroupConfig(maatXmlConfig, groupId.replace(redisDBIndex + ":GROUPCOMPILE:", ""), - 11, maatVersion.doubleValue(), service, redisTemplate, redisDBIndex, id + "");// 11代表是分组配置 } + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + "号redis库中获取" + compileStr + + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); } } } else { @@ -972,13 +893,14 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { oldKey += compileId; } maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); - if (redisTemplate.hasKey(oldKey)) { + if (BaseRedisDao.keyIsExist(redisDBIndex, oldKey)) { redisTemplate.rename(oldKey, maatKey.toUpperCase()); logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase()); break; } else { - throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确"); + throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + + "请检查id映射关系是否正确,或该配置已经被取消,已经被取消的配置不可再次取消,否则将抛出异常"); } } } @@ -1023,7 +945,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { for (String oldKey : regionArr) { oldKey = oldKey.replace(redisDBIndex + ":", ""); maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); - if (redisTemplate.hasKey(oldKey)) { + if (BaseRedisDao.keyIsExist(redisDBIndex, oldKey)) { redisTemplate.rename(oldKey, maatKey.toUpperCase()); logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase()); } else { @@ -1082,12 +1004,16 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { if (idList != null && idList.size() > 0) { for (Long compileId : idList) { String compileStr = redisDBIndex + ":COMPILEGROUP:" + compileId; - String groupCompileStr = redisTemplate.opsForValue().get(compileStr);// 根据编译id获取该编译下的分组关系 + String groupCompileStr = BaseRedisDao.getValByKey(idRelaRedisDBIndex, compileStr);// 根据编译id获取该编译下的分组关系 if (groupCompileStr != null && !groupCompileStr.equals("")) { String[] groupCompileStrSplit = groupCompileStr.split(";");// 得到分组关系 for (String groupCompile : groupCompileStrSplit) {// 遍历所有分组关系 - String compileGroupStr = redisTemplate.opsForValue() - .get(groupCompile.toUpperCase());// 获取当前分组关系对应的编译信息 + // String compileGroupStr = redisTemplate.opsForValue() + // .get(groupCompile.toUpperCase());// 获取当前分组关系对应的编译信息 + + String compileGroupStr = BaseRedisDao.getValByKey(idRelaRedisDBIndex, + groupCompile.toUpperCase());// 获取当前分组关系对应的编译信息 + if (compileGroupStr != null && !compileGroupStr.equals("")) { String[] compileGroupStrSplit = compileGroupStr.split(";"); if (compileGroupStrSplit != null && compileGroupStrSplit.length == 1 @@ -1096,12 +1022,21 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { .equals(compileStr.toUpperCase())) { String groupRegion = groupCompile.replaceAll("GROUPCOMPILE", "GROUPREGION"); - if (redisTemplate.hasKey(groupRegion)) { + if (BaseRedisDao.keyIsExist(idRelaRedisDBIndex, groupRegion)) { redisTemplate.delete(groupRegion);// 删除组对应的域 + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + + "号redis库中判断"+groupRegion+"组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + } - if (redisTemplate.hasKey(groupCompile.toUpperCase())) { + if (BaseRedisDao.keyIsExist(idRelaRedisDBIndex, + groupCompile.toUpperCase())) { redisTemplate.delete(groupCompile.toUpperCase());// 删除当前组所对应的编译 + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + + "号redis库中判断"+groupCompile.toUpperCase()+"组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + } } @@ -1121,12 +1056,21 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { redisTemplate.opsForValue().set(groupCompile, sb.substring(0, sb.length() - 1)); } + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + "号redis库中获取" + + groupCompile.toUpperCase() + + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + } } - if (redisTemplate.hasKey(compileStr.toUpperCase())) { + if (BaseRedisDao.keyIsExist(idRelaRedisDBIndex, compileStr.toUpperCase())) { redisTemplate.delete(compileStr.toUpperCase());// 删除编译下面所有的组 } + } else { + throw new RuntimeException("从" + idRelaRedisDBIndex + "号redis库中获取" + compileStr + + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常"); + } } } @@ -1140,30 +1084,4 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { throw new RuntimeException("参数不能为空"); } } - - public void delMaatRelationOld(Map>> idMap) { - if (idMap != null && idMap.size() > 0) { - for (Integer redisDBIndex : idMap.keySet()) { - if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { - // MaatRelation maatRelation = - // CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex); - Map> map = idMap.get(redisDBIndex); - if (map != null && map.size() > 0) { - for (Integer service : map.keySet()) { - List idList = map.get(service); - if (idList != null && idList.size() > 0) { - for (Long compileId : idList) { - CompileGroupRegionRela.delIdRelation(redisDBIndex, compileId); - } - } - } - } - } else { - throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号"); - } - } - } else { - throw new RuntimeException("参数不能为空"); - } - } } 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 b69b827..60451e0 100644 --- a/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/MaatTestServiceimpl.java @@ -1,11 +1,11 @@ package com.nis.web.service.restful; import java.lang.reflect.Field; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -19,13 +19,17 @@ import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.StrRegion; import com.nis.util.CamelUnderlineUtil; +import com.nis.util.Configurations; +import com.nis.util.FileUtils; import com.nis.util.ReadMaatXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; import com.nis.web.service.SpringContextHolder; @Service() public class MaatTestServiceimpl { - private static Logger logger = LoggerFactory.getLogger(MaatTestServiceimpl.class); + // private static Logger logger = + // LoggerFactory.getLogger(MaatTestServiceimpl.class); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public void getKeys(List configCompileList) { if (configCompileList != null && configCompileList.size() > 0) { @@ -106,7 +110,7 @@ public class MaatTestServiceimpl { if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[") & keyStr.toLowerCase().contains("id")) { if (type == 11) { - keyBF.append(compileId + "" + id); + keyBF.append(id + "" + compileId); } else { keyBF.append(id); } @@ -142,7 +146,11 @@ public class MaatTestServiceimpl { } } if (sysoLog(valArr, valList, obj, redisDb, key)) { - logger.warn("编译配置id为{}的配置中,在{}号redis库中key={}的值与实际插入的值相符", compileId, redisDb, key); + FileUtils + .addStrToFile("\t" + + sdf.format(new Date()) + " 编译配置id为" + compileId + "的配置中,在" + redisDb + + "号redis库中key=" + key + "的值与实际插入的值相符\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); } } @@ -155,8 +163,10 @@ public class MaatTestServiceimpl { String beanVal = getFieldValueByFieldName(filedName, obj); String redisVal = valArr[i]; if (!beanVal.trim().equals(redisVal.trim())) { - logger.warn("{}号redis库中key={}的值第{}位{}的值:{}与实际传的值不一样,实际值是:{}", redisDb, key, i, attrName, redisVal, - beanVal); + FileUtils.addStrToFile("\t" + + sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i + "位" + + attrName + "的值:" + redisVal + "与实际传的值不一样,实际值是:{}\n", + Configurations.getStringProperty("maatTestLogPath", ""), true); bool = false; } } diff --git a/src/main/resources/applicationContext-redis.xml b/src/main/resources/applicationContext-redis.xml index 81e8b4c..e463587 100644 --- a/src/main/resources/applicationContext-redis.xml +++ b/src/main/resources/applicationContext-redis.xml @@ -99,9 +99,6 @@ - - - @@ -113,10 +110,6 @@ - - - - @@ -212,15 +205,6 @@ - - - - - - - - - @@ -231,4 +215,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 02e6234..c7e9698 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -85,7 +85,7 @@ bonecp.hive.statementsCacheSize=100 ##################################################################################################################################### #redis.host=10.0.6.228 redis.host=10.0.6.249 -redis.port=6379 +redis.port=6380 redis.pass= redis.maxIdle=5 redis.maxTotal=250 diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 118bc75..8833690 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,8 +1,8 @@ #Log4j -log4j.rootLogger=info,console,file,warnFile +log4j.rootLogger=info,console,file # 控制台日志设置 log4j.appender.console=org.apache.log4j.ConsoleAppender -#log4j.appender.console.Threshold=info +log4j.appender.console.Threshold=info log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}] [%-5p] [Thread\:%t] %l %x - <%m>%n @@ -16,22 +16,6 @@ log4j.appender.file.DatePattern='.'yyyy-MM-dd log4j.appender.file.layout=org.apache.log4j.PatternLayout #log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss} %X{ip} [%t] %5p %c{1} %m%n log4j.appender.file.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}] [%-5p] %X{ip} [Thread\:%t] %l %x - %m%n - - -# 文件日志设置 -log4j.appender.warnFile=org.apache.log4j.DailyRollingFileAppender -log4j.appender.warnFile.Threshold=warn -log4j.appender.warnFile.encoding=UTF-8 -log4j.appender.warnFile.Append=true -log4j.appender.warnFile.file=${nis.root}/WEB-INF/log/warn.log -log4j.appender.warnFile.DatePattern='.'yyyy-MM-dd -log4j.appender.warnFile.layout=org.apache.log4j.PatternLayout -#log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss} %X{ip} [%t] %5p %c{1} %m%n -log4j.appender.warnFile.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}] [%-5p] %X{ip} [Thread\:%t] %l %x - %m%n - - - - #MyBatis 配置,com.nis.web.dao是mybatis接口所在包 log4j.logger.com.nis.web.dao=debug #bonecp数据源配置 diff --git a/src/main/resources/maatXml/maat.xml b/src/main/resources/maatXml/maat.xml index 475ec8b..a576d96 100644 --- a/src/main/resources/maatXml/maat.xml +++ b/src/main/resources/maatXml/maat.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://www.w3school.com.cn maat.xsd"> - + EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id] [cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[op_time];&nbsp;[level];\t;[file_id];\n diff --git a/src/main/resources/nis.properties b/src/main/resources/nis.properties index 22b7d77..ef919fa 100644 --- a/src/main/resources/nis.properties +++ b/src/main/resources/nis.properties @@ -248,4 +248,6 @@ digest.gen.tool.path=maat-redis/digest_gen #redis中有多少个数据库(需要加1,代码中用的小于不是小于等于) maxRedisDBIndex=12 ##存放编译,分组,域配置id关系的redis数据库编号 -idRelaRedisDBIndex=15 \ No newline at end of file +idRelaRedisDBIndex=15 +#maat测试程序输出日志的文件目录 +maatTestLogPath=c:/maat/mmat.log \ No newline at end of file