修改服务接口应答信息的序列化处理

This commit is contained in:
zhangwei
2018-05-24 10:01:24 +08:00
parent 96bcdfe407
commit 50663761c4
3 changed files with 140 additions and 76 deletions

View File

@@ -1,7 +1,6 @@
package com.nis.web.service.configuration;
import info.monitorenter.cpdetector.util.FileUtil;
import java.io.File;
import java.util.ArrayList;
@@ -9,7 +8,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import net.sf.json.JSONObject;
@@ -21,6 +19,8 @@ import com.google.gson.GsonBuilder;
import com.nis.domain.Page;
import com.nis.domain.configuration.AvFileSampleCfg;
import com.nis.domain.configuration.AvSignSampleCfg;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.maat.ToMaatResult.ResponseData;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.FileUtils;
@@ -71,15 +71,17 @@ public class AvCfgService extends BaseService{
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(new Date());
//调用服务接口获取compileId
String result = "";
Integer compileId = 0;
try {
result ="1";// ConfigServiceUtil.getId(1,1);
List<Integer> compileIds = ConfigServiceUtil.getId(1,1);
if(!StringUtil.isEmpty(compileIds)){
compileId = compileIds.get(0);
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
}
Integer compileId = Integer.parseInt(result);
if(compileId!=0){
entity.setCompileId(compileId);
avCfgDao.insertAvFileSample(entity);
@@ -99,15 +101,17 @@ public class AvCfgService extends BaseService{
entity.setCreatorId(UserUtils.getUser().getId());
entity.setCreateTime(new Date());
//调用服务接口获取compileId
String result = "";
Integer compileId = 0;
try {
result ="1";// ConfigServiceUtil.getId(1,1);
List<Integer> compileIds = ConfigServiceUtil.getId(1,1);
if(!StringUtil.isEmpty(compileIds)){
compileId = compileIds.get(0);
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取编译ID出错");
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>:"+e.getMessage());
}
Integer compileId = Integer.parseInt(result);
if(compileId!=0){
entity.setCompileId(compileId);
avCfgDao.insertAvSignSample(entity);
@@ -164,41 +168,34 @@ public class AvCfgService extends BaseService{
srcMap.put("key",FileUtils.getPrefix(srcFile.getName(), false));
srcMap.put("fileName", srcFile.getName());
srcMap.put("checksum", entity.getSrcMd5());
String result1 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(srcMap));
ToMaatResult result1 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(srcMap));
logger.info("音视频源文件上传响应信息:"+result1);
//获取文件上传响应信息(新的文件访问路径)
Map<String, Object> srcRes = gson.fromJson(result1,Map.class);
String srcAccessUrl = null;
if(!StringUtil.isEmpty(srcRes.get("data"))){
Map<String,Object> data = (Map<String,Object>)srcRes.get("data");
if(!StringUtil.isEmpty(data.get("accessUrl"))){
srcAccessUrl=data.get("accessUrl").toString();
entity.setSrcUrl(srcAccessUrl);
if(!StringUtil.isEmpty(result1)){
ResponseData data = result1.getData();
srcAccessUrl=data.getAccessUrl();
entity.setSrcUrl(srcAccessUrl);
// entity.setSrcPath("");
}
}
File sampleFile = new File(oldSampleUrl);
Map<String,Object> sampleMap = new HashMap();
sampleMap.put("filetype", FileUtils.getSuffix(sampleFile.getName(), false));
srcMap.put("datatype", "fileSystem");//样例文件存入fastdfs
sampleMap.put("datatype", "fileSystem");//样例文件存入fastdfs
sampleMap.put("createTime", entity.getCreateTime());
sampleMap.put("key",FileUtils.getPrefix(sampleFile.getName(), false));
sampleMap.put("fileName", sampleFile.getName());
sampleMap.put("checksum", entity.getSampleMd5());
String result2 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(sampleMap));
ToMaatResult result2 = ConfigServiceUtil.postFileCfg(null, srcFile, JSONObject.fromObject(sampleMap));
logger.info("音视频样例文件上传响应信息:"+result2);
//获取文件上传响应信息(新的文件访问路径)
Map<String, Object> sampleRes = gson.fromJson(result1,Map.class);
String sampleAccessUrl = null;
if(!StringUtil.isEmpty(sampleRes.get("data"))){
Map<String,Object> data = (Map<String,Object>)sampleRes.get("data");
if(!StringUtil.isEmpty(data.get("accessUrl"))){
sampleAccessUrl = data.get("accessUrl").toString();
entity.setSampleUrl(sampleAccessUrl);
// entity.setSamplePath("");
}
if(!StringUtil.isEmpty(result2)){
ResponseData data = result2.getData();
sampleAccessUrl = data.getAccessUrl();
entity.setSampleUrl(sampleAccessUrl);
// entity.setSamplePath("");
}
@@ -220,12 +217,12 @@ public class AvCfgService extends BaseService{
}
if(isAudit==1){
//调用服务接口下发配置数据
String json=gson.toJson(list);
String json=gsonToJson(list);
logger.info("音视频文件样例下发配置参数:"+json);
//调用服务接口下发配置
try {
String result = ConfigServiceUtil.postCallbackCfg(json);
logger.info("音视频文件样例配置下发响应信息:"+result);
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
logger.info("音视频文件样例配置下发响应信息:"+result.getMsg());
} catch (Exception e) {
e.printStackTrace();
logger.info("音视频文件样例配置下发失败");
@@ -233,12 +230,12 @@ public class AvCfgService extends BaseService{
}
}else if(isAudit==3){
//调用服务接口取消配置
String json=gson.toJson(list);
String json=gsonToJson(list);
logger.info("音视频文件样例下发配置参数:"+json);
//调用服务接口下发配置
try {
String result = ConfigServiceUtil.put(json,2);
logger.info("音视频文件样例取消配置响应信息:"+result);
ToMaatResult result = ConfigServiceUtil.put(json,2);
logger.info("音视频文件样例取消配置响应信息:"+result.getMsg());
} catch (Exception e) {
e.printStackTrace();
logger.info("音视频文件样取消配置失败");
@@ -262,9 +259,6 @@ public class AvCfgService extends BaseService{
AvSignSampleCfg entity = new AvSignSampleCfg();
String[] idArray = ids.split(",");
List<AvSignSampleCfg> list = new ArrayList();
Gson gson=new GsonBuilder().disableHtmlEscaping()
.excludeFieldsWithoutExposeAnnotation()
.create();
for(String id :idArray){
entity = getAvSignSampleById(Long.parseLong(id));
entity.setIsAudit(isAudit);
@@ -276,12 +270,12 @@ public class AvCfgService extends BaseService{
}
if(isAudit==1){
//调用服务接口下发配置数据
String json=gson.toJson(list);
String json=gsonToJson(list);
logger.info("文件样例下发配置参数:"+json);
//调用服务接口下发配置
try {
String result = ConfigServiceUtil.postCallbackCfg(json);
logger.info("音视频标志样例配置下发响应信息:"+result);
ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json);
logger.info("音视频标志样例配置下发响应信息:"+result.getMsg());
} catch (Exception e) {
e.printStackTrace();
logger.info("音视频标志样例配置下发失败");
@@ -289,12 +283,12 @@ public class AvCfgService extends BaseService{
}
}else if(isAudit==3){
//调用服务接口取消配置
String json=gson.toJson(list);
String json=gsonToJson(list);
logger.info("标志样例下发配置参数:"+json);
//调用服务接口取消配置
try {
String result = ConfigServiceUtil.put(json, 2);
logger.info("音视频标志样例配置取消配置响应信息:"+result);
ToMaatResult result = ConfigServiceUtil.put(json, 2);
logger.info("音视频标志样例配置取消配置响应信息:"+result.getMsg());
} catch (Exception e) {
e.printStackTrace();
logger.info("音视频标志样例取消配置失败");