diff --git a/src/main/java/com/nis/domain/restful/FileDesc.java b/src/main/java/com/nis/domain/restful/FileDesc.java index cc22ab4..df20dc8 100644 --- a/src/main/java/com/nis/domain/restful/FileDesc.java +++ b/src/main/java/com/nis/domain/restful/FileDesc.java @@ -14,10 +14,33 @@ import java.util.Date; */ public class FileDesc { + /** + * 文件格式类型 + */ private String filetype; + /** + * 文件数据类型 + */ + private String dataType; + /** + * fileSystem + */ + private String fileSystem; + /** + * 文件创建时间,UTC时间格式 + */ private Date createTime; + /** + * 文件惟一key + */ private String key; + /** + *文件名称 + */ private String fileName; + /** + * 文件md5校验码 + */ private String checksum; /** * diff --git a/src/main/java/com/nis/domain/restful/UpdateStatConfig.java b/src/main/java/com/nis/domain/restful/UpdateStatConfig.java new file mode 100644 index 0000000..872bb7e --- /dev/null +++ b/src/main/java/com/nis/domain/restful/UpdateStatConfig.java @@ -0,0 +1,64 @@ +/** + * + */ +package com.nis.domain.restful; + +import java.io.Serializable; + +import com.wordnik.swagger.annotations.ApiModelProperty; + +/** + * @ClassName:CancleConfigSource + * @Description:TODO(这里用一句话描述这个类的作用) + * @author (zdx) + * @date 2018年6月1日 下午6:08:09 + * @version V1.0 + */ +public class UpdateStatConfig implements Serializable{ + + private static final long serialVersionUID = 6346336602908201877L; + @ApiModelProperty(value = "配置ID", required = true) + private Long cfgId; + @ApiModelProperty(value = "业务ID", required = true) + private Integer service; + @ApiModelProperty(value = "是否有效", required = true) + private Integer isValid; + + /** + * + */ + public UpdateStatConfig() { + super(); + // TODO Auto-generated constructor stub + } + /** + * @param cfgId + * @param service + * @param isValid + */ + public UpdateStatConfig(Long cfgId, Integer service, Integer isValid) { + super(); + this.cfgId = cfgId; + this.service = service; + this.isValid = isValid; + } + public Long getCfgId() { + return cfgId; + } + public void setCfgId(Long cfgId) { + this.cfgId = cfgId; + } + public Integer getService() { + return service; + } + public void setService(Integer service) { + this.service = service; + } + public Integer getIsValid() { + return isValid; + } + public void setIsValid(Integer isValid) { + this.isValid = isValid; + } + +} diff --git a/src/main/java/com/nis/domain/restful/UpdateStatConfigSource.java b/src/main/java/com/nis/domain/restful/UpdateStatConfigSource.java new file mode 100644 index 0000000..c60fe72 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/UpdateStatConfigSource.java @@ -0,0 +1,47 @@ +/** + * + */ +package com.nis.domain.restful; + +import java.io.Serializable; +import java.util.List; + +/** + * @ClassName:CancleConfigSource + * @Description:TODO(这里用一句话描述这个类的作用) + * @author (zdx) + * @date 2018年6月1日 下午6:08:09 + * @version V1.0 + */ +public class UpdateStatConfigSource implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 277603807201929340L; + private List UpdateStatCfgList; + + /** + * + */ + public UpdateStatConfigSource() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @param cancleConfigList + */ + public UpdateStatConfigSource(List UpdateStatCfgList) { + super(); + this.UpdateStatCfgList = UpdateStatCfgList; + } + + public List getUpdateStatCfgList() { + return UpdateStatCfgList; + } + + public void setUpdateStatCfgList(List updateStatCfgList) { + UpdateStatCfgList = updateStatCfgList; + } +} diff --git a/src/main/java/com/nis/util/FileUtils.java b/src/main/java/com/nis/util/FileUtils.java index c233b20..e71bd8b 100644 --- a/src/main/java/com/nis/util/FileUtils.java +++ b/src/main/java/com/nis/util/FileUtils.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.security.MessageDigest; import java.util.Enumeration; import javax.servlet.ServletOutputStream; @@ -728,4 +729,36 @@ public class FileUtils extends org.apache.commons.io.FileUtils { } } } + /** + * 计算文件MD5 + * @param file + * @return + */ + public static String getFileMD5(File file){ + if(!file.isFile()){ + return ""; + } + 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); + } + in.close(); + }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位 + } +// BigInteger bigInt=new BigInteger(1,digest.digest()); + return md5; + } } 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 9ca9ed9..dc54a28 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -1,5 +1,6 @@ package com.nis.web.controller.restful; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -10,6 +11,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import net.sf.json.JSONObject; + import org.apache.commons.codec.digest.DigestUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +27,7 @@ import com.nis.domain.restful.ConfigCompile; import com.nis.domain.restful.ConfigSource; import com.nis.domain.restful.FileDesc; import com.nis.domain.restful.MaatConfig; +import com.nis.domain.restful.UpdateStatConfigSource; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; import com.nis.util.Constants; @@ -41,8 +45,6 @@ import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import com.wordnik.swagger.annotations.ApiParam; -import net.sf.json.JSONObject; - /** * @ClassName: ConfigSourcesController * @Description: 配置存储服务 @@ -88,7 +90,6 @@ public class ConfigSourcesController extends BaseRestController { Map>> configMap = new HashMap>>(); configMap.put(1, listMap); configRedisService.saveUnMaatConfig(configMap); - } else { Integer service = 100; Map map = new HashMap(); @@ -312,32 +313,14 @@ public class ConfigSourcesController extends BaseRestController { checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); String msg = ""; ConfigCompile compile = configSource.getConfigCompileList().get(0); - // zdx 20180528改为调用rkg接口取消配置 - msg = configSourcesService.cancleConfigSources(thread, start, configSource.getConfigCompileList(), + //zdx 20180528改为调用rkg接口取消配置 + msg = configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(), configSource.getOpTime(), sb); if (msg.equals("error")) { - String errorCode = ""; Exception exception = ConfigSourcesService.getMsgList().get(0); - String message = exception.getMessage(); - if (null != message && message.length() > 0) { - int index = message.toUpperCase().indexOf("ORA-"); - if (index != -1) { - errorCode = message.substring(index + 4, index + 9); - - } - } - Map throwExceptionInfo = OracleErrorCodeUtil.throwExceptionInfo(errorCode); - for (int errorNum : throwExceptionInfo.keySet()) { - if (errorNum == 998) { - thread.setExceptionInfo(exception.toString()); - } else { - thread.setExceptionInfo(throwExceptionInfo.get(errorNum)); - } throw new RestServiceException(thread, System.currentTimeMillis() - start, - throwExceptionInfo.get(errorNum), errorNum); - - } + "修改编译配置状态时出现异常"+exception.getMessage(), RestBusinessCode.unknow_error.getValue()); } // configSourcesService.updateConfigSource(thread, start, // configSource.getConfigCompileList(), @@ -379,12 +362,11 @@ public class ConfigSourcesController extends BaseRestController { throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空", RestBusinessCode.missing_args.getValue()); } - // if ((configCompile.getActiveSys() != null) || - // (configCompile.getEffectiveRange() != null - // && !configCompile.getEffectiveRange().equals(""))) { - // count++; - // configSourcesService.setCompileInvalid(configCompile); - // } +// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null +// && !configCompile.getEffectiveRange().equals(""))) { +// count++; +// configSourcesService.setCompileInvalid(configCompile); +// } } if (count > 0) { Thread.sleep(14000); @@ -412,34 +394,33 @@ public class ConfigSourcesController extends BaseRestController { throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空", RestBusinessCode.missing_args.getValue()); } - // if ((configCompile.getActiveSys() != null) || - // (configCompile.getEffectiveRange() != null - // && !configCompile.getEffectiveRange().equals(""))) { - // try { - // configSourcesService.setCompileValid(configCompile); - // } catch (Exception e1) { - // String errorCode = ""; - // String message = e.getMessage(); - // if (null != message && message.length() > 0) { - // int index = message.toUpperCase().indexOf("ORA-"); - // if (index != -1) { - // errorCode = message.substring(index + 4, index + 9); - // - // } - // } - // Map throwExceptionInfo = OracleErrorCodeUtil - // .throwExceptionInfo(errorCode); - // for (int errorNum : throwExceptionInfo.keySet()) { - // if (errorNum == 998) { - // thread.setExceptionInfo(e.toString()); - // } else { - // thread.setExceptionInfo(throwExceptionInfo.get(errorNum)); - // } - // throw new RestServiceException(thread, System.currentTimeMillis() - start, - // throwExceptionInfo.get(errorNum), errorNum); - // } - // } - // } +// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null +// && !configCompile.getEffectiveRange().equals(""))) { +// try { +// configSourcesService.setCompileValid(configCompile); +// } catch (Exception e1) { +// String errorCode = ""; +// String message = e.getMessage(); +// if (null != message && message.length() > 0) { +// int index = message.toUpperCase().indexOf("ORA-"); +// if (index != -1) { +// errorCode = message.substring(index + 4, index + 9); +// +// } +// } +// Map throwExceptionInfo = OracleErrorCodeUtil +// .throwExceptionInfo(errorCode); +// for (int errorNum : throwExceptionInfo.keySet()) { +// if (errorNum == 998) { +// thread.setExceptionInfo(e.toString()); +// } else { +// thread.setExceptionInfo(throwExceptionInfo.get(errorNum)); +// } +// throw new RestServiceException(thread, System.currentTimeMillis() - start, +// throwExceptionInfo.get(errorNum), errorNum); +// } +// } +// } } } @@ -516,23 +497,23 @@ public class ConfigSourcesController extends BaseRestController { return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功", 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) @ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务") - public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, + @ApiParam(value = "回调配置状态修改", name = "updateStatConfigSource", required = true) + public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource, HttpServletRequest request, HttpServletResponse response) { ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, - null); + SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,updateStatConfigSource); StringBuffer sb = new StringBuffer(); + + configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(), new Date(),sb); - configSourcesService.saveCommonSources(thread, start, jsonString, sb); - - return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功", - Constants.IS_DEBUG ? jsonString : null); + return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, + "配置状态修改成功" , Constants.IS_DEBUG ? updateStatConfigSource : null); } - + @RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST) @ApiOperation(value = "样例文件上传服务", httpMethod = "POST", response = Map.class, notes = "样例文件上传服务") @ApiParam(value = "样例文件上传服务", name = "MultipartFile", required = true) @@ -540,42 +521,35 @@ public class ConfigSourcesController extends BaseRestController { HttpServletResponse response) { ConfigSourcesService.setMsgList(new ArrayList());// 清除上次记录的日志信息 long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, - null); - String filePath = ""; + SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null); + String filePath =""; try { - FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")), - FileDesc.class); - if (null == file) { + FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class); + if(null==file){ thread.setExceptionInfo("请选择上传文件到file参数"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数", RestBusinessCode.missing_args.getValue()); - + } if (!StringUtil.isEmpty(fileDesc.getChecksum())) { - // 验证Md5 + //验证Md5 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())) { thread.setExceptionInfo("checksum与文件MD5值不一致"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", RestBusinessCode.config_integrity_error.getValue()); } String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); - FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); - // NameValuePair[] meta_list = new NameValuePair[5]; - // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); - // meta_list[1] = new NameValuePair("fileLength", - // String.valueOf(file.getSize())); - // meta_list[2] = new NameValuePair("fileExt", ext); - // meta_list[3] = new NameValuePair("fileAuthor", "rkg"); - // meta_list[4] = new NameValuePair("fileMd5", md5); + FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext); +// NameValuePair[] meta_list = new NameValuePair[5]; +// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); +// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize())); +// meta_list[2] = new NameValuePair("fileExt", ext); +// meta_list[3] = new NameValuePair("fileAuthor", "rkg"); +// meta_list[4] = new NameValuePair("fileMd5", md5); logger.info("-----------------调用接口上传文件---------------"); filePath = FileManager.upload(fdsfile, null); - } else { - thread.setExceptionInfo("请求头信息中缺少checksum参数"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数", - RestBusinessCode.missing_args.getValue()); } } catch (IOException e) { // TODO Auto-generated catch block @@ -583,62 +557,57 @@ public class ConfigSourcesController extends BaseRestController { } JSONObject jsonObj = new JSONObject(); jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group"))); - // jsonObj.put("accessUrl", "filePath"); - return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "文件上传成功", jsonObj); +// jsonObj.put("accessUrl", "filePath"); + return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, + "文件上传成功" ,jsonObj); } - + @RequestMapping(value = "/cfg/v1/fileDigestSources", method = RequestMethod.POST) @ApiOperation(value = "文件摘要获取", httpMethod = "POST", response = Map.class, notes = "文件摘要获取") @ApiParam(value = "摘要文件", name = "MultipartFile", required = true) - public Map fileDigestSources(MultipartFile file, HttpServletRequest request, HttpServletResponse response) { + public Map fileDigestSources(MultipartFile file,HttpServletRequest request, + HttpServletResponse response){ long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, - file, null); - // JSONArray fileArray=new JSONArray(); - if (file == null) { + SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,file,null); + //JSONArray fileArray=new JSONArray(); + if (file==null) { thread.setExceptionInfo("请上传获取摘要的文件到file"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数", RestBusinessCode.missing_args.getValue()); } 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 { if (!StringUtil.isEmpty(fileDesc.getChecksum())) { - // 验证Md5 + //验证Md5 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())) { thread.setExceptionInfo("checksum与文件MD5值不一致"); throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致", RestBusinessCode.config_integrity_error.getValue()); } String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); - FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); - // NameValuePair[] meta_list = new NameValuePair[5]; - // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); - // meta_list[1] = new NameValuePair("fileLength", - // String.valueOf(file.getSize())); - // meta_list[2] = new NameValuePair("fileExt", ext); - // meta_list[3] = new NameValuePair("fileAuthor", "rkg"); - // meta_list[4] = new NameValuePair("fileMd5", md5); + FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext); + // NameValuePair[] meta_list = new NameValuePair[5]; + // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); + // meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize())); + // meta_list[2] = new NameValuePair("fileExt", ext); + // meta_list[3] = new NameValuePair("fileAuthor", "rkg"); + // meta_list[4] = new NameValuePair("fileMd5", md5); logger.info("-----------------调用接口上传文件---------------"); String filePath = FileManager.upload(fdsfile, null); resultObject.put("path", filePath.substring(filePath.indexOf("group"))); - } else { - thread.setExceptionInfo("请求头信息中缺少checksum参数"); - throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数", - RestBusinessCode.missing_args.getValue()); } - + CommonsMultipartFile filetemp = (CommonsMultipartFile) file; - String tempFilePath = filetemp.getStorageDescription().toString(); - tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[") + 1, tempFilePath.indexOf("]")); - - String digestStr = configSourcesService.getDigestGen(request.getRealPath("/"), tempFilePath); + String tempFilePath = filetemp.getStorageDescription().toString(); + tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[")+1, tempFilePath.indexOf("]")); + + String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator),tempFilePath); resultObject.put("digest", digestStr); resultObject.put("rawLen", file.getSize()); - } catch (IOException e) { + }catch (IOException e) { // TODO Auto-generated catch block logger.error("文件上传过程中出现异常"); thread.setExceptionInfo("文件上传过程中出现异常"); @@ -652,9 +621,8 @@ public class ConfigSourcesController extends BaseRestController { throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常", 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) { if (null != datetime) { return true; diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 706f378..e428031 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -1,10 +1,7 @@ package com.nis.web.service.restful; -import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; -import java.io.File; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.SQLException; @@ -43,6 +40,7 @@ import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.MaatConfig; import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.StrRegion; +import com.nis.domain.restful.UpdateStatConfig; import com.nis.restful.CompileJudgeCode; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; @@ -1125,7 +1123,6 @@ public class ConfigSourcesService extends BaseService { RestBusinessCode.config_integrity_error.getValue()); } - if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) { logger1.error("配置分组数量不能为空" + sb.toString()); thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); @@ -1287,12 +1284,16 @@ public class ConfigSourcesService extends BaseService { if (configMap.containsKey(dbIndex)) { configMap.get(dbIndex).addAll(maatMap.get(service)); }else{ - configMap.put(dbIndex, maatMap.get(service)); + List list = new ArrayList(); + list.addAll(maatMap.get(service)); + configMap.put(dbIndex, list); } } } - configRedisService.saveMaatConfig(configMap); + if (configRedisService.saveMaatConfig(configMap)) { + configRedisService.addMaatRelation(configMap); + } logger1.info("---------------调用maat配置新增接口---------------------"); return "ok"; @@ -1324,8 +1325,9 @@ public class ConfigSourcesService extends BaseService { return dstMap; } - public String cancleConfigSources(SaveRequestLogThread thread, long start, List compileList, + public String updateConfigSources(SaveRequestLogThread thread, long start, List compileList, Date opTime, StringBuffer sb) { + Map> compileMap = new HashMap>(); List compileAllList = new ArrayList(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { @@ -1339,7 +1341,14 @@ public class ConfigSourcesService extends BaseService { RestBusinessCode.config_integrity_error.getValue()); } - compileAllList.add(config); + //compileAllList.add(config); + if (compileMap.containsKey(config.getService())) { + compileMap.get(config.getService()).add(config.getCompileId()); + } else { + List idList = new ArrayList(); + idList.add(config.getCompileId()); + compileMap.put(config.getService(), idList); + } } } else { @@ -1347,7 +1356,36 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), RestBusinessCode.config_integrity_error.getValue()); } - return ""; + Map>> restMap = new HashMap>>(); + Iterator serviceIterator = compileMap.keySet().iterator(); + while (serviceIterator.hasNext()) { + Integer service =Integer.valueOf(serviceIterator.next().toString()); + List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); + 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); + } + } + } + try { + if(configRedisService.delMaatConfig(restMap)){ + configRedisService.delMaatRelation(restMap); + }else{ + RuntimeException e = new RuntimeException("不存在映射关系"); + msgList.add(e); + return "error"; + } + } catch (RuntimeException e) { + // TODO: handle exception + logger1.error(e.getMessage()); + msgList.add(e); + return "error"; + } + return "ok"; } public String saveByJDBCThread(SaveRequestLogThread thread, long start, List configCompileList, StringBuffer sb) { @@ -2517,11 +2555,77 @@ public class ConfigSourcesService extends BaseService { if (configMap.containsKey(dbIndex)) { configMap.get(dbIndex).addAll(dstMaps.get(service)); }else{ - configMap.put(dbIndex, dstMaps.get(service)); + List> list = new ArrayList>(); + list.addAll(dstMaps.get(service)); + configMap.put(dbIndex, list); + } + } + + } + + configRedisService.saveUnMaatConfig(configMap); + + return "ok"; + } + public String updateCommonSources(SaveRequestLogThread thread, long start, List updateStatCfgList, + Date opTime, StringBuffer sb) { + Map> cfgMap = new HashMap>(); + if (null != updateStatCfgList && updateStatCfgList.size() > 0) { + for (UpdateStatConfig config : updateStatCfgList) { + String msg = checkOptForUpdate(config); + if (!msg.equals("ok")) { + thread.setExceptionInfo(msg + sb.toString()); + throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(), + RestBusinessCode.config_integrity_error.getValue()); + } + if (cfgMap.containsKey(config.getService())) { + cfgMap.get(config.getService()).add(config.getCfgId()); + } else { + List idList = new ArrayList(); + idList.add(config.getCfgId()); + cfgMap.put(config.getService(), idList); + } + } + + } else { + thread.setExceptionInfo("配置列表不能为空" + sb.toString()); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置列表不能为空" + sb.toString(), + RestBusinessCode.config_integrity_error.getValue()); + } + Map>> restMap = new HashMap>>(); + Iterator serviceIterator = cfgMap.keySet().iterator(); + while (serviceIterator.hasNext()) { + Integer service =Integer.valueOf(serviceIterator.next().toString()); + List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); + for (Integer dbIndex : dbIndexList) { + if (restMap.containsKey(dbIndex)) { + restMap.get(dbIndex).put(service, cfgMap.get(service)); + }else{ + Map> map = new HashMap>(); + map.put(service, cfgMap.get(service)); + restMap.put(dbIndex, map); } } } - configRedisService.saveUnMaatConfig(configMap); + configRedisService.delUnMaatConfig(restMap); + + return "ok"; + } + private String checkOptForUpdate(UpdateStatConfig config) { + if (StringUtil.isEmpty(config.getCfgId())) { + return "cfgId字段不能为空"; + } + + if (StringUtil.isEmpty(config.getService())) { + return "service字段不能为空"; + } + + if (StringUtil.isEmpty(config.getIsValid())) { + return "配置id为" + config.getCfgId()+"的IsValid字段不能为空"; + } + if (config.getIsValid() != 0) { + return "配置id为" + config.getCfgId() + "的配置在修改时不能为有效"; + } return "ok"; } diff --git a/src/main/resources/serviceTable.properties b/src/main/resources/serviceTable.properties index b499f56..6803b0e 100644 --- a/src/main/resources/serviceTable.properties +++ b/src/main/resources/serviceTable.properties @@ -31,7 +31,7 @@ service=3;15;80;81;82;83;84;85;144;145;146;147;148;149 ##各业务类型对应的redisdb,业务类型:redisdb,多个业务以“;”分隔,多个db以“,”数量不能超过6个 -serviceDBIndex=3:2;15:2;80:2;81:2;82:2;83:2;84:2;85:2;144:2;145:2;146:2;147:2;148:2;149:2;96:3;97:3;98:3;99:3;160:3;161:3;162:3;163:3;100:3;101:3;164:3;165:3 +serviceDBIndex=3:2,3;15:2;80:2;81:2;82:2;83:2;84:2;85:2;144:2;145:2;146:2;147:2;148:2;149:2;96:3;97:3;98:3;99:3;160:3,4;161:3;162:3;163:3;100:3;101:3;164:3;165:3 diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index d645e85..1b4acd1 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -269,11 +269,11 @@ - + - +