非maat配置取消

This commit is contained in:
zhangdongxu
2018-06-02 13:01:27 +08:00
parent 351354d56d
commit ba4e1ec4ef
8 changed files with 374 additions and 135 deletions

View File

@@ -14,10 +14,33 @@ import java.util.Date;
*/ */
public class FileDesc { public class FileDesc {
/**
* 文件格式类型
*/
private String filetype; private String filetype;
/**
* 文件数据类型
*/
private String dataType;
/**
* fileSystem
*/
private String fileSystem;
/**
* 文件创建时间UTC时间格式
*/
private Date createTime; private Date createTime;
/**
* 文件惟一key
*/
private String key; private String key;
/**
*文件名称
*/
private String fileName; private String fileName;
/**
* 文件md5校验码
*/
private String checksum; private String checksum;
/** /**
* *

View File

@@ -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;
}
}

View File

@@ -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<UpdateStatConfig> UpdateStatCfgList;
/**
*
*/
public UpdateStatConfigSource() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param cancleConfigList
*/
public UpdateStatConfigSource(List<UpdateStatConfig> UpdateStatCfgList) {
super();
this.UpdateStatCfgList = UpdateStatCfgList;
}
public List<UpdateStatConfig> getUpdateStatCfgList() {
return UpdateStatCfgList;
}
public void setUpdateStatCfgList(List<UpdateStatConfig> updateStatCfgList) {
UpdateStatCfgList = updateStatCfgList;
}
}

View File

@@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.ServletOutputStream; 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;
}
} }

View File

@@ -1,5 +1,6 @@
package com.nis.web.controller.restful; package com.nis.web.controller.restful;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@@ -10,6 +11,8 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; 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.ConfigSource;
import com.nis.domain.restful.FileDesc; import com.nis.domain.restful.FileDesc;
import com.nis.domain.restful.MaatConfig; import com.nis.domain.restful.MaatConfig;
import com.nis.domain.restful.UpdateStatConfigSource;
import com.nis.restful.RestBusinessCode; import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException; import com.nis.restful.RestServiceException;
import com.nis.util.Constants; 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.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam; import com.wordnik.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
/** /**
* @ClassName: ConfigSourcesController * @ClassName: ConfigSourcesController
* @Description: 配置存储服务 * @Description: 配置存储服务
@@ -88,7 +90,6 @@ 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>();
@@ -312,32 +313,14 @@ 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.updateConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb); configSource.getOpTime(), sb);
if (msg.equals("error")) { if (msg.equals("error")) {
String errorCode = "";
Exception exception = ConfigSourcesService.getMsgList().get(0); 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<Integer, String> 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, throw new RestServiceException(thread, System.currentTimeMillis() - start,
throwExceptionInfo.get(errorNum), errorNum); "修改编译配置状态时出现异常"+exception.getMessage(), RestBusinessCode.unknow_error.getValue());
}
} }
// configSourcesService.updateConfigSource(thread, start, // configSourcesService.updateConfigSource(thread, start,
// configSource.getConfigCompileList(), // configSource.getConfigCompileList(),
@@ -379,12 +362,11 @@ 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) || // if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// (configCompile.getEffectiveRange() != null // && !configCompile.getEffectiveRange().equals(""))) {
// && !configCompile.getEffectiveRange().equals(""))) { // count++;
// count++; // configSourcesService.setCompileInvalid(configCompile);
// configSourcesService.setCompileInvalid(configCompile); // }
// }
} }
if (count > 0) { if (count > 0) {
Thread.sleep(14000); Thread.sleep(14000);
@@ -412,34 +394,33 @@ 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) || // if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// (configCompile.getEffectiveRange() != null // && !configCompile.getEffectiveRange().equals(""))) {
// && !configCompile.getEffectiveRange().equals(""))) { // try {
// try { // configSourcesService.setCompileValid(configCompile);
// configSourcesService.setCompileValid(configCompile); // } catch (Exception e1) {
// } catch (Exception e1) { // String errorCode = "";
// String errorCode = ""; // String message = e.getMessage();
// String message = e.getMessage(); // if (null != message && message.length() > 0) {
// if (null != message && message.length() > 0) { // int index = message.toUpperCase().indexOf("ORA-");
// int index = message.toUpperCase().indexOf("ORA-"); // if (index != -1) {
// if (index != -1) { // errorCode = message.substring(index + 4, index + 9);
// errorCode = message.substring(index + 4, index + 9); //
// // }
// } // }
// } // Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil
// Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil // .throwExceptionInfo(errorCode);
// .throwExceptionInfo(errorCode); // for (int errorNum : throwExceptionInfo.keySet()) {
// for (int errorNum : throwExceptionInfo.keySet()) { // if (errorNum == 998) {
// if (errorNum == 998) { // thread.setExceptionInfo(e.toString());
// thread.setExceptionInfo(e.toString()); // } else {
// } else { // thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
// thread.setExceptionInfo(throwExceptionInfo.get(errorNum)); // }
// } // throw new RestServiceException(thread, System.currentTimeMillis() - start,
// throw new RestServiceException(thread, System.currentTimeMillis() - start, // throwExceptionInfo.get(errorNum), errorNum);
// throwExceptionInfo.get(errorNum), errorNum); // }
// } // }
// } // }
// }
} }
} }
@@ -516,23 +497,23 @@ public class ConfigSourcesController extends BaseRestController {
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/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 = "回调配置状态修改服务") @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) { 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, SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,updateStatConfigSource);
null);
StringBuffer sb = new StringBuffer(); 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 ? updateStatConfigSource : null);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功",
Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST) @RequestMapping(value = "/cfg/v1/fileUploadSources", 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)
@@ -540,42 +521,35 @@ 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, SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null);
null); String filePath ="";
String filePath = "";
try { try {
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")), FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class);
FileDesc.class); if(null==file){
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", // meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize()));
// 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("-----------------调用接口上传文件---------------");
filePath = FileManager.upload(fdsfile, null); filePath = FileManager.upload(fdsfile, null);
} else {
thread.setExceptionInfo("请求头信息中缺少checksum参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
RestBusinessCode.missing_args.getValue());
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@@ -583,62 +557,57 @@ 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, "文件上传成功", jsonObj); return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"文件上传成功" ,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, HttpServletResponse response) { public Map fileDigestSources(MultipartFile file,HttpServletRequest request,
HttpServletResponse response){
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,file,null);
file, null); //JSONArray fileArray=new JSONArray();
// JSONArray fileArray=new JSONArray(); if (file==null) {
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 fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class);
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", // meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize()));
// 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 {
thread.setExceptionInfo("请求头信息中缺少checksum参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
RestBusinessCode.missing_args.getValue());
} }
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(File.separator),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("文件上传过程中出现异常");
@@ -652,9 +621,8 @@ 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

@@ -1,10 +1,7 @@
package com.nis.web.service.restful; package com.nis.web.service.restful;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; 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.MaatConfig;
import com.nis.domain.restful.NumRegion; import com.nis.domain.restful.NumRegion;
import com.nis.domain.restful.StrRegion; import com.nis.domain.restful.StrRegion;
import com.nis.domain.restful.UpdateStatConfig;
import com.nis.restful.CompileJudgeCode; import com.nis.restful.CompileJudgeCode;
import com.nis.restful.RestBusinessCode; import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException; import com.nis.restful.RestServiceException;
@@ -1125,7 +1123,6 @@ public class ConfigSourcesService extends BaseService {
RestBusinessCode.config_integrity_error.getValue()); RestBusinessCode.config_integrity_error.getValue());
} }
if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) { if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) {
logger1.error("配置分组数量不能为空" + sb.toString()); logger1.error("配置分组数量不能为空" + sb.toString());
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString()); thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
@@ -1287,12 +1284,16 @@ public class ConfigSourcesService extends BaseService {
if (configMap.containsKey(dbIndex)) { if (configMap.containsKey(dbIndex)) {
configMap.get(dbIndex).addAll(maatMap.get(service)); configMap.get(dbIndex).addAll(maatMap.get(service));
}else{ }else{
configMap.put(dbIndex, maatMap.get(service)); List<MaatConfig> list = new ArrayList<MaatConfig>();
list.addAll(maatMap.get(service));
configMap.put(dbIndex, list);
} }
} }
} }
configRedisService.saveMaatConfig(configMap); if (configRedisService.saveMaatConfig(configMap)) {
configRedisService.addMaatRelation(configMap);
}
logger1.info("---------------调用maat配置新增接口---------------------"); logger1.info("---------------调用maat配置新增接口---------------------");
return "ok"; return "ok";
@@ -1324,8 +1325,9 @@ public class ConfigSourcesService extends BaseService {
return dstMap; return dstMap;
} }
public String cancleConfigSources(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList, public String updateConfigSources(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
Date opTime, StringBuffer sb) { Date opTime, StringBuffer sb) {
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>(); List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
if (null != compileList && compileList.size() > 0) { if (null != compileList && compileList.size() > 0) {
for (ConfigCompile config : compileList) { for (ConfigCompile config : compileList) {
@@ -1339,7 +1341,14 @@ public class ConfigSourcesService extends BaseService {
RestBusinessCode.config_integrity_error.getValue()); 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<Long> idList = new ArrayList<Long>();
idList.add(config.getCompileId());
compileMap.put(config.getService(), idList);
}
} }
} else { } else {
@@ -1347,7 +1356,36 @@ public class ConfigSourcesService extends BaseService {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(), throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
RestBusinessCode.config_integrity_error.getValue()); RestBusinessCode.config_integrity_error.getValue());
} }
return ""; Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
Iterator serviceIterator = compileMap.keySet().iterator();
while (serviceIterator.hasNext()) {
Integer service =Integer.valueOf(serviceIterator.next().toString());
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
for (Integer dbIndex : dbIndexList) {
if (restMap.containsKey(dbIndex)) {
restMap.get(dbIndex).put(service, compileMap.get(service));
}else{
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
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<ConfigCompile> configCompileList, public String saveByJDBCThread(SaveRequestLogThread thread, long start, List<ConfigCompile> configCompileList,
StringBuffer sb) { StringBuffer sb) {
@@ -2517,11 +2555,77 @@ public class ConfigSourcesService extends BaseService {
if (configMap.containsKey(dbIndex)) { if (configMap.containsKey(dbIndex)) {
configMap.get(dbIndex).addAll(dstMaps.get(service)); configMap.get(dbIndex).addAll(dstMaps.get(service));
}else{ }else{
configMap.put(dbIndex, dstMaps.get(service)); List<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.addAll(dstMaps.get(service));
configMap.put(dbIndex, list);
}
}
}
configRedisService.saveUnMaatConfig(configMap);
return "ok";
}
public String updateCommonSources(SaveRequestLogThread thread, long start, List<UpdateStatConfig> updateStatCfgList,
Date opTime, StringBuffer sb) {
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
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<Long> idList = new ArrayList<Long>();
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<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
Iterator serviceIterator = cfgMap.keySet().iterator();
while (serviceIterator.hasNext()) {
Integer service =Integer.valueOf(serviceIterator.next().toString());
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
for (Integer dbIndex : dbIndexList) {
if (restMap.containsKey(dbIndex)) {
restMap.get(dbIndex).put(service, cfgMap.get(service));
}else{
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
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"; return "ok";
} }

View File

@@ -31,7 +31,7 @@ service=3;15;80;81;82;83;84;85;144;145;146;147;148;149
##各业务类型对应的redisdb,业务类型:redisdb,多个业务以“;”分隔,多个db以“,”数量不能超过6个 ##各业务类型对应的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

View File

@@ -269,11 +269,11 @@
<!-- 支持Shiro对Controller的方法级AOP安全控制 end --> <!-- 支持Shiro对Controller的方法级AOP安全控制 end -->
<!-- 上传文件拦截设置最大文件大小10m=10*1024*1024(B)=10485760 bytes --> <!-- 上传文件拦截设置最大文件大小100m=10*1024*1024(B)=104857600 bytes -->
<bean id="multipartResolver" <bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property> <property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760"></property> <property name="maxUploadSize" value="104857600"></property>
<!--<property name="maxInMemorySize" value="1000"></property> --> <!--<property name="maxInMemorySize" value="1000"></property> -->
<property name="uploadTempDir" value="/upload"></property> <property name="uploadTempDir" value="/upload"></property>
</bean> </bean>