diff --git a/src/main/java/com/nis/domain/maat/ToMaatResult.java b/src/main/java/com/nis/domain/maat/ToMaatResult.java index 5b407fbd0..c2fd2f32c 100644 --- a/src/main/java/com/nis/domain/maat/ToMaatResult.java +++ b/src/main/java/com/nis/domain/maat/ToMaatResult.java @@ -9,6 +9,7 @@ package com.nis.domain.maat; import java.io.Serializable; +import java.util.List; /** * @ClassName: ToMaatResult.java @@ -30,6 +31,59 @@ public class ToMaatResult implements Serializable{ private String reason; private String msg; private String fromuri; + private ResponseData data; + public static class ResponseData{ + private String sourceName; + private Integer num; + private List pzIdList; + private String accessUrl; + private Long rawLen; + private String digest; + private MaatCfg configCompileList; + public String getSourceName() { + return sourceName; + } + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + public Integer getNum() { + return num; + } + public void setNum(Integer num) { + this.num = num; + } + public List getPzIdList() { + return pzIdList; + } + public void setPzIdList(List pzIdList) { + this.pzIdList = pzIdList; + } + public String getAccessUrl() { + return accessUrl; + } + public void setAccessUrl(String accessUrl) { + this.accessUrl = accessUrl; + } + public Long getRawLen() { + return rawLen; + } + public void setRawLen(Long rawLen) { + this.rawLen = rawLen; + } + public String getDigest() { + return digest; + } + public void setDigest(String digest) { + this.digest = digest; + } + public MaatCfg getConfigCompileList() { + return configCompileList; + } + public void setConfigCompileList(MaatCfg configCompileList) { + this.configCompileList = configCompileList; + } + + } /** * status * @return status @@ -100,5 +154,10 @@ public class ToMaatResult implements Serializable{ public void setFromuri(String fromuri) { this.fromuri = fromuri; } - + public ResponseData getData() { + return data; + } + public void setData(ResponseData data) { + this.data = data; + } } diff --git a/src/main/java/com/nis/util/ConfigServiceUtil.java b/src/main/java/com/nis/util/ConfigServiceUtil.java index 38d9a4e40..1f1efdce3 100644 --- a/src/main/java/com/nis/util/ConfigServiceUtil.java +++ b/src/main/java/com/nis/util/ConfigServiceUtil.java @@ -18,23 +18,14 @@ import net.sf.json.JSONObject; import org.glassfish.jersey.media.multipart.FormDataMultiPart; import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.LinkedTreeMap; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; +import com.jcraft.jsch.Logger; +import com.nis.domain.maat.ToMaatResult; +import com.nis.domain.maat.ToMaatResult.ResponseData; import com.nis.exceptions.MaatConvertException; import com.nis.util.httpclient.ClientUtil; public class ConfigServiceUtil { - private static Gson gson = new GsonBuilder() - .registerTypeAdapter(new TypeToken() {}.getType(), new MapTypeAdapter()) - .registerTypeAdapter(new TypeToken() {}.getType(), new MapTypeAdapter()) - .create(); - public static class MapTypeAdapter extends TypeAdapter { + /*public static class MapTypeAdapter extends TypeAdapter { @Override public Object read(JsonReader in) throws IOException { JsonToken token = in.peek(); @@ -93,7 +84,7 @@ public class ConfigServiceUtil { // 序列化无需实现 } - } + }*/ /** * 从后台服务获取compileid,groupid,regionid * @param type 1是compileid,2是groupid,3是regionid @@ -117,11 +108,14 @@ public class ConfigServiceUtil { Response response= header.get(); if( response.getStatus() == 200){ result= response.readEntity(String.class); - Map resMap = gson.fromJson(result,Map.class); - if(!StringUtil.isEmpty(resMap)){ - Map dataMap = (Map)resMap.get("data"); - if(!StringUtil.isEmpty(dataMap)){ - list = (List)dataMap.get("pzIdList"); +// result = "{\"status\":200,\"businessCode\":2000,\"reason\":\"数据获取操作成功\"," +// + "\"msg\":\"配置ID获取成功\",\"fromuri\":\"/galaxy/service/cfg/v1/configPzIdSources\"," +// + "\"traceCode\":\"2018052409232108368751\",\"data\":{\"sourceName\":\"CONFIG_COMPILE\",\"num\":1,\"pzIdList\":[22]}}"; + JSONObject resObject = JSONObject.fromObject(result); + ToMaatResult bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); + if(!StringUtil.isEmpty(bean)){ + if(!StringUtil.isEmpty(bean.getData())){ + list = bean.getData().getPzIdList(); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } @@ -139,8 +133,9 @@ public class ConfigServiceUtil { * @return * @throws Exception */ - public static String postMaatCfg(String params) throws Exception{ + public static ToMaatResult postMaatCfg(String params) throws Exception{ String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL+Constants.MAAT_CFG; //创建连接 WebTarget wt = ClientUtil.getWebTarger(url); @@ -149,11 +144,12 @@ public class ConfigServiceUtil { Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON)); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; - + return bean; } /** * 回调配置提交 @@ -161,8 +157,9 @@ public class ConfigServiceUtil { * @return * @throws Exception */ - public static String postCallbackCfg(String params) throws Exception{ + public static ToMaatResult postCallbackCfg(String params) throws Exception{ String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL+Constants.CALLBACK_CFG; //创建连接 WebTarget wt = ClientUtil.getWebTarger(url); @@ -171,10 +168,12 @@ public class ConfigServiceUtil { Response response= header.post(Entity.entity(params, MediaType.APPLICATION_JSON)); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; + return bean; } /** @@ -183,8 +182,9 @@ public class ConfigServiceUtil { * @return * @throws Exception */ - public static String postFileCfg(String params,File file,JSONObject fileDesc) throws Exception{ + public static ToMaatResult postFileCfg(String params,File file,JSONObject fileDesc) throws Exception{ String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL+Constants.FILE_UPLOAD_CFG; //创建连接 WebTarget wt = ClientUtil.getWebTarger(url); @@ -195,10 +195,12 @@ public class ConfigServiceUtil { Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType())); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; + return bean; } /** @@ -207,8 +209,9 @@ public class ConfigServiceUtil { * @param type,1表示maat配置取消,2表示回调配置取消 * @return */ - public static String delete(String params,Integer type){ + public static ToMaatResult delete(String params,Integer type){ String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL; if(type==1){ url = url+Constants.MAAT_CFG; @@ -222,10 +225,12 @@ public class ConfigServiceUtil { Response response= header.delete(); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; + return bean; } /** @@ -234,8 +239,9 @@ public class ConfigServiceUtil { * @param type,1表示maat配置取消,2表示回调配置取消 * @return */ - public static String put(String params,Integer type){ + public static ToMaatResult put(String params,Integer type){ String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL; if(type==1){ url = url+Constants.MAAT_CFG; @@ -249,10 +255,12 @@ public class ConfigServiceUtil { Response response= header.put(Entity.entity(params, MediaType.APPLICATION_JSON)); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; + return bean; } /** * 信息获取 @@ -260,8 +268,9 @@ public class ConfigServiceUtil { * @return * @throws Exception */ - public static String getFileDigest(String params,File file,Map fileDesc) throws Exception{ - String result = null; + public static ToMaatResult getFileDigest(String params,File file,Map fileDesc) throws Exception{ + String result = null; + ToMaatResult bean = null; String url = Constants.SERVICE_URL+Constants.FILE_DIGEST_CFG; //创建连接 WebTarget wt = ClientUtil.getWebTarger(url); @@ -272,10 +281,12 @@ public class ConfigServiceUtil { Response response= header.post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType())); if( response.getStatus() == 200){ result= response.readEntity(String.class); + JSONObject resObject = JSONObject.fromObject(result); + bean = (ToMaatResult) JSONObject.toBean(resObject,ToMaatResult.class); }else{ throw new MaatConvertException(":"+response.readEntity(String.class)); } - return result; + return bean; } public static void main(String[] args) { try { diff --git a/src/main/java/com/nis/web/service/configuration/AvCfgService.java b/src/main/java/com/nis/web/service/configuration/AvCfgService.java index 098d64fc2..16e99ed50 100644 --- a/src/main/java/com/nis/web/service/configuration/AvCfgService.java +++ b/src/main/java/com/nis/web/service/configuration/AvCfgService.java @@ -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 compileIds = ConfigServiceUtil.getId(1,1); + if(!StringUtil.isEmpty(compileIds)){ + compileId = compileIds.get(0); + } } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+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 compileIds = ConfigServiceUtil.getId(1,1); + if(!StringUtil.isEmpty(compileIds)){ + compileId = compileIds.get(0); + } } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+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 srcRes = gson.fromJson(result1,Map.class); String srcAccessUrl = null; - if(!StringUtil.isEmpty(srcRes.get("data"))){ - Map data = (Map)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 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 sampleRes = gson.fromJson(result1,Map.class); String sampleAccessUrl = null; - if(!StringUtil.isEmpty(sampleRes.get("data"))){ - Map data = (Map)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 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("音视频标志样例取消配置失败");