1:添加对区域ip管控类域配置的支持

2:优化对数据的判断抛出相应的异常
This commit is contained in:
RenKaiGe-Office
2018-06-04 10:18:31 +08:00
parent 226cab3796
commit 90e96391f8
8 changed files with 265 additions and 190 deletions

View File

@@ -313,14 +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接口取消配置
// zdx 20180528改为调用rkg接口取消配置
msg = configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb);
if (msg.equals("error")) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"修改编译配置状态时出现异常"+exception.getMessage(), RestBusinessCode.unknow_error.getValue());
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"修改编译配置状态时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue());
}
// configSourcesService.updateConfigSource(thread, start,
// configSource.getConfigCompileList(),
@@ -362,11 +362,12 @@ 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);
@@ -394,33 +395,34 @@ 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<Integer, String> 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<Integer, String> 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);
// }
// }
// }
}
}
@@ -497,23 +499,25 @@ 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)
@ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务")
@ApiParam(value = "回调配置状态修改", name = "updateStatConfigSource", required = true)
public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource, HttpServletRequest request,
HttpServletResponse response) {
public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource,
HttpServletRequest request, HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,updateStatConfigSource);
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
updateStatConfigSource);
StringBuffer sb = new StringBuffer();
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(), new Date(),sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"配置状态修改成功" , Constants.IS_DEBUG ? updateStatConfigSource : null);
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(),
new Date(), sb);
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)
@@ -521,33 +525,37 @@ public class ConfigSourcesController extends BaseRestController {
HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
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
String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'");
// 验证Md5
String md5 = DigestUtils.md5Hex(file.getInputStream());
//String md5 = DigestUtils.md5Hex(file.getBytes());
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);
}
@@ -557,57 +565,58 @@ 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
String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'");
// 验证Md5
String md5 = DigestUtils.md5Hex(file.getInputStream());
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")));
}
CommonsMultipartFile filetemp = (CommonsMultipartFile) file;
String tempFilePath = filetemp.getStorageDescription().toString();
tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[")+1, tempFilePath.indexOf("]"));
String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator),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("文件上传过程中出现异常");
@@ -621,8 +630,9 @@ 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;