1:修改配置新增或取消时,修改id对应关系为当新增或取消成功后才修改id关系,否则不修改id关系

This commit is contained in:
RenKaiGe-Office
2018-06-01 18:04:48 +08:00
parent 25732d44ce
commit ca391db606
3 changed files with 152 additions and 114 deletions

View File

@@ -88,6 +88,7 @@ public class ConfigSourcesController extends BaseRestController {
Map<Integer, List<Map<String, String>>> configMap = new HashMap<Integer, List<Map<String, String>>>(); Map<Integer, List<Map<String, String>>> configMap = new HashMap<Integer, List<Map<String, String>>>();
configMap.put(1, listMap); configMap.put(1, listMap);
configRedisService.saveUnMaatConfig(configMap); configRedisService.saveUnMaatConfig(configMap);
} else { } else {
Integer service = 100; Integer service = 100;
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
@@ -145,7 +146,10 @@ public class ConfigSourcesController extends BaseRestController {
Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>(); Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>();
idMap.put(redisDB, map); idMap.put(redisDB, map);
configRedisService.delMaatConfig(idMap); boolean delMaatConfig = configRedisService.delMaatConfig(idMap);
if (delMaatConfig) {
configRedisService.delMaatRelation(idMap);
}
return "ok"; return "ok";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -165,7 +169,9 @@ public class ConfigSourcesController extends BaseRestController {
listMap = new ArrayList<MaatConfig>(); listMap = new ArrayList<MaatConfig>();
listMap.add(getMaatConfig(service)); listMap.add(getMaatConfig(service));
configMap.put(2, listMap); configMap.put(2, listMap);
configRedisService.saveMaatConfig(configMap); if (configRedisService.saveMaatConfig(configMap)) {
configRedisService.addMaatRelation(configMap);
}
// configRedisService.saveMaatConfig(listMap, service); // configRedisService.saveMaatConfig(listMap, service);
// new ConfigRedisServiceimpl().GETMaatConfig(listMap); // new ConfigRedisServiceimpl().GETMaatConfig(listMap);
return "ok"; return "ok";
@@ -306,7 +312,7 @@ public class ConfigSourcesController extends BaseRestController {
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
String msg = ""; String msg = "";
ConfigCompile compile = configSource.getConfigCompileList().get(0); ConfigCompile compile = configSource.getConfigCompileList().get(0);
//zdx 20180528改为调用rkg接口取消配置 // zdx 20180528改为调用rkg接口取消配置
msg = configSourcesService.cancleConfigSources(thread, start, configSource.getConfigCompileList(), msg = configSourcesService.cancleConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb); configSource.getOpTime(), sb);
@@ -373,11 +379,12 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空", throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
} }
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null // if ((configCompile.getActiveSys() != null) ||
// && !configCompile.getEffectiveRange().equals(""))) { // (configCompile.getEffectiveRange() != null
// count++; // && !configCompile.getEffectiveRange().equals(""))) {
// configSourcesService.setCompileInvalid(configCompile); // count++;
// } // configSourcesService.setCompileInvalid(configCompile);
// }
} }
if (count > 0) { if (count > 0) {
Thread.sleep(14000); Thread.sleep(14000);
@@ -405,33 +412,34 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空", throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
} }
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null // if ((configCompile.getActiveSys() != null) ||
// && !configCompile.getEffectiveRange().equals(""))) { // (configCompile.getEffectiveRange() != null
// try { // && !configCompile.getEffectiveRange().equals(""))) {
// configSourcesService.setCompileValid(configCompile); // try {
// } catch (Exception e1) { // configSourcesService.setCompileValid(configCompile);
// String errorCode = ""; // } catch (Exception e1) {
// String message = e.getMessage(); // String errorCode = "";
// if (null != message && message.length() > 0) { // String message = e.getMessage();
// int index = message.toUpperCase().indexOf("ORA-"); // if (null != message && message.length() > 0) {
// if (index != -1) { // int index = message.toUpperCase().indexOf("ORA-");
// errorCode = message.substring(index + 4, index + 9); // if (index != -1) {
// // errorCode = message.substring(index + 4, index + 9);
// } //
// } // }
// Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil // }
// .throwExceptionInfo(errorCode); // Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil
// for (int errorNum : throwExceptionInfo.keySet()) { // .throwExceptionInfo(errorCode);
// if (errorNum == 998) { // for (int errorNum : throwExceptionInfo.keySet()) {
// thread.setExceptionInfo(e.toString()); // if (errorNum == 998) {
// } else { // thread.setExceptionInfo(e.toString());
// thread.setExceptionInfo(throwExceptionInfo.get(errorNum)); // } else {
// } // thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
// throw new RestServiceException(thread, System.currentTimeMillis() - start, // }
// throwExceptionInfo.get(errorNum), errorNum); // throw new RestServiceException(thread, System.currentTimeMillis() - start,
// } // throwExceptionInfo.get(errorNum), errorNum);
// } // }
// } // }
// }
} }
} }
@@ -509,19 +517,20 @@ public class ConfigSourcesController extends BaseRestController {
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT, produces=org.springframework.http.MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务") @ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务")
public Map updateCommonConfigSource(@RequestBody String jsonString , HttpServletRequest request, public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息 ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
null);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
configSourcesService.saveCommonSources(thread, start, jsonString, sb); configSourcesService.saveCommonSources(thread, start, jsonString, sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功",
"配置数据插入成功" , Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST) @RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
@@ -531,36 +540,39 @@ public class ConfigSourcesController extends BaseRestController {
HttpServletResponse response) { HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息 ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
String filePath =""; null);
String filePath = "";
try { try {
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class); FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
if(null==file){ FileDesc.class);
if (null == file) {
thread.setExceptionInfo("请选择上传文件到file参数"); thread.setExceptionInfo("请选择上传文件到file参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数", throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
} }
if (!StringUtil.isEmpty(fileDesc.getChecksum())) { if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
//验证Md5 // 验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes()); String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'"); System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) { if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致"); thread.setExceptionInfo("checksum与文件MD5值不一致");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
RestBusinessCode.config_integrity_error.getValue()); RestBusinessCode.config_integrity_error.getValue());
} }
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5]; // NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize())); // meta_list[1] = new NameValuePair("fileLength",
// meta_list[2] = new NameValuePair("fileExt", ext); // String.valueOf(file.getSize()));
// meta_list[3] = new NameValuePair("fileAuthor", "rkg"); // meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[4] = new NameValuePair("fileMd5", md5); // meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
logger.info("-----------------调用接口上传文件---------------"); logger.info("-----------------调用接口上传文件---------------");
filePath = FileManager.upload(fdsfile, null); filePath = FileManager.upload(fdsfile, null);
}else{ } else {
thread.setExceptionInfo("请求头信息中缺少checksum参数"); thread.setExceptionInfo("请求头信息中缺少checksum参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数", throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
@@ -571,48 +583,49 @@ public class ConfigSourcesController extends BaseRestController {
} }
JSONObject jsonObj = new JSONObject(); JSONObject jsonObj = new JSONObject();
jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group"))); jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
// jsonObj.put("accessUrl", "filePath"); // jsonObj.put("accessUrl", "filePath");
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "文件上传成功", jsonObj);
"文件上传成功" ,jsonObj);
} }
@RequestMapping(value = "/cfg/v1/fileDigestSources", method = RequestMethod.POST) @RequestMapping(value = "/cfg/v1/fileDigestSources", method = RequestMethod.POST)
@ApiOperation(value = "文件摘要获取", httpMethod = "POST", response = Map.class, notes = "文件摘要获取") @ApiOperation(value = "文件摘要获取", httpMethod = "POST", response = Map.class, notes = "文件摘要获取")
@ApiParam(value = "摘要文件", name = "MultipartFile", required = true) @ApiParam(value = "摘要文件", name = "MultipartFile", required = true)
public Map fileDigestSources(MultipartFile file,HttpServletRequest request, public Map fileDigestSources(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
HttpServletResponse response){
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,file,null); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
//JSONArray fileArray=new JSONArray(); file, null);
if (file==null) { // JSONArray fileArray=new JSONArray();
if (file == null) {
thread.setExceptionInfo("请上传获取摘要的文件到file"); thread.setExceptionInfo("请上传获取摘要的文件到file");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数", throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
} }
JSONObject resultObject = new JSONObject(); JSONObject resultObject = new JSONObject();
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class); FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
FileDesc.class);
try { try {
if (!StringUtil.isEmpty(fileDesc.getChecksum())) { if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
//验证Md5 // 验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes()); String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'"); System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) { if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致"); thread.setExceptionInfo("checksum与文件MD5值不一致");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
RestBusinessCode.config_integrity_error.getValue()); RestBusinessCode.config_integrity_error.getValue());
} }
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5]; // NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize())); // meta_list[1] = new NameValuePair("fileLength",
// String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext); // meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg"); // meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5); // meta_list[4] = new NameValuePair("fileMd5", md5);
logger.info("-----------------调用接口上传文件---------------"); logger.info("-----------------调用接口上传文件---------------");
String filePath = FileManager.upload(fdsfile, null); String filePath = FileManager.upload(fdsfile, null);
resultObject.put("path", filePath.substring(filePath.indexOf("group"))); resultObject.put("path", filePath.substring(filePath.indexOf("group")));
}else{ } else {
thread.setExceptionInfo("请求头信息中缺少checksum参数"); thread.setExceptionInfo("请求头信息中缺少checksum参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数", throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
RestBusinessCode.missing_args.getValue()); RestBusinessCode.missing_args.getValue());
@@ -620,12 +633,12 @@ public class ConfigSourcesController extends BaseRestController {
CommonsMultipartFile filetemp = (CommonsMultipartFile) file; CommonsMultipartFile filetemp = (CommonsMultipartFile) file;
String tempFilePath = filetemp.getStorageDescription().toString(); String tempFilePath = filetemp.getStorageDescription().toString();
tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[")+1, tempFilePath.indexOf("]")); tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[") + 1, tempFilePath.indexOf("]"));
String digestStr = configSourcesService.getDigestGen(request.getRealPath("/"),tempFilePath); String digestStr = configSourcesService.getDigestGen(request.getRealPath("/"), tempFilePath);
resultObject.put("digest", digestStr); resultObject.put("digest", digestStr);
resultObject.put("rawLen", file.getSize()); resultObject.put("rawLen", file.getSize());
}catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.error("文件上传过程中出现异常"); logger.error("文件上传过程中出现异常");
thread.setExceptionInfo("文件上传过程中出现异常"); thread.setExceptionInfo("文件上传过程中出现异常");
@@ -639,8 +652,9 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常", throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常",
RestBusinessCode.unknow_error.getValue()); RestBusinessCode.unknow_error.getValue());
} }
return serviceResponse(thread,System.currentTimeMillis()-start,request, response, "摘要获取成功",resultObject); return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject);
} }
private boolean isBlank(Date datetime) { private boolean isBlank(Date datetime) {
if (null != datetime) { if (null != datetime) {
return true; return true;

View File

@@ -15,18 +15,24 @@ import com.nis.domain.restful.MaatConfig;
* *
*/ */
public interface ConfigRedisService { public interface ConfigRedisService {
/** /**
* 下发非maat配置接口,key是redisDBIndex,value是配置集合 * 下发非maat配置接口,key是redisDBIndex,value是配置集合
* @param configMap * @param configMap
* @return 成功返回true,失败返回false或抛出异常
*/ */
public void saveUnMaatConfig(Map<Integer, List<Map<String, String>>> configMap); public boolean saveUnMaatConfig(Map<Integer, List<Map<String, String>>> configMap);
/** /**
* 保存 maat配置接口,key是redisDBIndex,value是配置集合 * 保存 maat配置接口,key是redisDBIndex,value是配置集合
* @param configMap * @param configMap
* @return 成功返回true,失败返回false或抛出异常
*/ */
public void saveMaatConfig(Map<Integer, List<MaatConfig>> configMap); public boolean saveMaatConfig(Map<Integer, List<MaatConfig>> configMap);
/**
* 下发配置成功后,需要更新编译,组,域等配置id的对应关系
* @param configMap
*/
public void addMaatRelation(Map<Integer, List<MaatConfig>> configMap);
/** /**
* 获取指定key的自增长值 * 获取指定key的自增长值
@@ -38,14 +44,21 @@ public interface ConfigRedisService {
/** /**
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合 * 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
* @param idMap * @param idMap
* @return 成功返回true,失败返回false或抛出异常
*/ */
public void delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap); public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap);
/** /**
* 删除maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合 * 删除maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
* @param idMap * @param idMap
* @return 成功返回true,失败返回false或抛出异常
*/ */
public void delMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap); public boolean delMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap);
/**
* 删除maat类配置成功后,需要更新编译,组,域等配置id的对应关系
* @param idMap
*/
public void delMaatRelation(Map<Integer, Map<Integer, List<Long>>> idMap);
} }

View File

@@ -23,6 +23,7 @@ import com.nis.domain.restful.MaatConfig;
import com.nis.domain.restful.MaatRelation; import com.nis.domain.restful.MaatRelation;
import com.nis.listener.CompileGroupRegionRela; import com.nis.listener.CompileGroupRegionRela;
import com.nis.util.Configurations; import com.nis.util.Configurations;
import com.nis.util.Exceptions;
import com.nis.util.ReadMaatXmlUtil; import com.nis.util.ReadMaatXmlUtil;
import com.nis.util.ServiceAndRDBIndexReal; import com.nis.util.ServiceAndRDBIndexReal;
import com.nis.web.service.SpringContextHolder; import com.nis.web.service.SpringContextHolder;
@@ -32,7 +33,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
private static Logger logger = LoggerFactory.getLogger(ConfigRedisServiceimpl.class); private static Logger logger = LoggerFactory.getLogger(ConfigRedisServiceimpl.class);
@Transactional @Transactional
public void saveUnMaatConfig(Map<Integer, List<Map<String, String>>> configMap) { public boolean saveUnMaatConfig(Map<Integer, List<Map<String, String>>> configMap) {
if (configMap != null && configMap.size() > 0) { if (configMap != null && configMap.size() > 0) {
for (Integer redisDBIndex : configMap.keySet()) { for (Integer redisDBIndex : configMap.keySet()) {
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
@@ -136,10 +137,11 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1); Integer.valueOf(maatVersionStr) + 1);
return true;
} }
} }
} }
return false;
} }
/** /**
@@ -199,7 +201,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
@Override @Override
@Transactional @Transactional
public void saveMaatConfig(Map<Integer, List<MaatConfig>> configMap) { public boolean saveMaatConfig(Map<Integer, List<MaatConfig>> configMap) {
if (configMap != null && configMap.size() > 0) { if (configMap != null && configMap.size() > 0) {
for (Integer redisDBIndex : configMap.keySet()) { for (Integer redisDBIndex : configMap.keySet()) {
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
@@ -218,16 +220,19 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
setConfig(maatConfig, maatXmlConfig, maatVersion, service, redisTemplate, redisDBIndex); setConfig(maatConfig, maatXmlConfig, maatVersion, service, redisTemplate, redisDBIndex);
} }
}
}
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1); Integer.valueOf(maatVersionStr) + 1);
return true;
}
}
} }
} }
addMaatRelation(configMap);
} }
return false;
} }
/** /**
@@ -401,7 +406,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
@Override @Override
@Transactional @Transactional
public void delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) { public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) {
if (idMap != null && idMap.size() > 0) { if (idMap != null && idMap.size() > 0) {
for (Integer redisDBIndex : idMap.keySet()) { for (Integer redisDBIndex : idMap.keySet()) {
RedisTemplate<String, String> redisTemplate = SpringContextHolder RedisTemplate<String, String> redisTemplate = SpringContextHolder
@@ -500,18 +505,19 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1); Integer.valueOf(maatVersionStr) + 1);
return true;
} }
} }
} }
} }
return false;
} }
@Override @Override
@Transactional @Transactional
public void delMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) { public boolean delMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) {
if (idMap != null && idMap.size() > 0) { if (idMap != null && idMap.size() > 0) {
for (Integer redisDBIndex : idMap.keySet()) { for (Integer redisDBIndex : idMap.keySet()) {
RedisTemplate<String, String> redisTemplate = SpringContextHolder RedisTemplate<String, String> redisTemplate = SpringContextHolder
@@ -525,6 +531,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
MaatRelation maatRelation = CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex); MaatRelation maatRelation = CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
if (maatVersionStr != null) { if (maatVersionStr != null) {
Long maatVersion = Long.valueOf(maatVersionStr) + 1; Long maatVersion = Long.valueOf(maatVersionStr) + 1;
if (maatRelation != null && redisTemplate != null) {
for (Integer service : serviceConfigMap.keySet()) { for (Integer service : serviceConfigMap.keySet()) {
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
removeConfig(serviceConfigMap.get(service), maatXmlConfig, maatVersion, service, removeConfig(serviceConfigMap.get(service), maatXmlConfig, maatVersion, service,
@@ -534,13 +541,13 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l); redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1); Integer.valueOf(maatVersionStr) + 1);
return true;
} }
} }
} }
// 删除配置成功后开始删除id对应关系
delMaatRelation(idMap);
} }
}
return false;
} }
/** /**
@@ -595,7 +602,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
* @param service * @param service
* @param redisTemplate * @param redisTemplate
*/ */
public void removeCommonConfig(MaatXmlConfig maatXmlConfig, Set<Long> idList, int type, Double maatVersion, private void removeCommonConfig(MaatXmlConfig maatXmlConfig, Set<Long> idList, int type, Double maatVersion,
int service, RedisTemplate<String, String> redisTemplate, int redisDBIndex) { int service, RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
if (maatXmlConfig != null && idList != null && idList.size() > 0) { if (maatXmlConfig != null && idList != null && idList.size() > 0) {
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList(); List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
@@ -621,10 +628,14 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
} }
String oldKey = keyBF.toString().toUpperCase(); String oldKey = keyBF.toString().toUpperCase();
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
if (redisTemplate.hasKey(oldKey)) {
redisTemplate.rename(oldKey, maatKey.toUpperCase()); redisTemplate.rename(oldKey, maatKey.toUpperCase());
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey,
maatKey.toUpperCase()); maatKey.toUpperCase());
break; break;
} else {
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
}
} }
} }
for (MaatXmlExpr maatXmlExpr : expressionList) { for (MaatXmlExpr maatXmlExpr : expressionList) {