diff --git a/src/main/java/com/nis/web/controller/configuration/ntc/AvController.java b/src/main/java/com/nis/web/controller/configuration/ntc/AvController.java index 5763bc857..3b08b6883 100644 --- a/src/main/java/com/nis/web/controller/configuration/ntc/AvController.java +++ b/src/main/java/com/nis/web/controller/configuration/ntc/AvController.java @@ -131,9 +131,11 @@ public class AvController extends BaseController { entity.setResultPath(resultFileAllPath); File uploadSrcFile = new File(srcFileAllPath); - File uploadSampleFile = new File(sampleFileAllPath); +// File uploadSampleFile = new File(sampleFileAllPath); FileCopyUtils.copy(srcFile.getBytes(), uploadSrcFile);//保存源文件 - String host = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); + entity.setSrcUrl(""); + entity.setSampleUrl(""); + /*String host = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); String srcUrl = host+srcFilePath.substring(srcFilePath.indexOf(Constants.AV_FILE_PATH)+Constants.AV_FILE_PATH.length()-1)+sep+uploadSrcFile.getName(); String sampleUrl = host+sampleFilePath.substring(sampleFilePath.indexOf(Constants.AV_FILE_PATH)+Constants.AV_FILE_PATH.length()-1)+sep+uploadSampleFile.getName(); srcUrl = srcUrl.replace("\\", "/"); @@ -141,7 +143,7 @@ public class AvController extends BaseController { logger.info("srcUrl:"+srcUrl); logger.info("sampleUrl:"+sampleUrl); entity.setSrcUrl(srcUrl); - entity.setSampleUrl(sampleUrl); + entity.setSampleUrl(sampleUrl);*/ // File uploadSrcFile = new File(srcFilePath); // FileCopyUtils.copy(srcFile.getBytes(), uploadSrcFile); @@ -209,10 +211,10 @@ public class AvController extends BaseController { entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); - String oldSrcUrl = entity.getSrcPath(); - String oldSampleUrl = entity.getSamplePath(); +// String oldSrcUrl = entity.getSrcPath(); +// String oldSampleUrl = entity.getSamplePath(); try { - if(isAudit==1){ + /*if(isAudit==1){ Date creatTime = entity.getCreateTime(); //音视频文件上传接口调用 File srcFile = new File(oldSrcUrl); @@ -254,15 +256,15 @@ public class AvController extends BaseController { // entity.setSamplePath(""); } - } + }*/ avCfgService.auditAvFileSample(entity,isAudit); //删除本地源文件和样例文件 - if(!oldSrcUrl.equals(entity.getSrcUrl())){ + /*if(!oldSrcUrl.equals(entity.getSrcUrl())){ FileUtils.deleteFile(oldSrcUrl); } if(!oldSampleUrl.equals(entity.getSampleUrl())){ FileUtils.deleteFile(oldSampleUrl); - } + }*/ }catch(Exception e){ e.printStackTrace(); if(e instanceof MaatConvertException) { 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 5a68dd1e0..1bde1abd0 100644 --- a/src/main/java/com/nis/web/service/configuration/AvCfgService.java +++ b/src/main/java/com/nis/web/service/configuration/AvCfgService.java @@ -20,11 +20,13 @@ 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.CallExternalProceduresException; import com.nis.exceptions.MaatConvertException; import com.nis.util.ConfigServiceUtil; import com.nis.util.Constants; import com.nis.util.FileUtils; +import com.nis.util.JsonMapper; import com.nis.util.StringUtil; import com.nis.web.dao.configuration.AvCfgDao; import com.nis.web.security.UserUtils; @@ -181,16 +183,62 @@ public class AvCfgService extends BaseService{ Integer fileId = resObject.getInt("fileId"); if(state==1 && fileSize>0){//成功 entity.setIsSampleCreated(1);//样例文件创建成功 + if(fileId.equals(entity.getCfgId().intValue())){ + File uploadSampleFile = new File(entity.getSamplePath()); + String sampleMd5 = FileUtils.getFileMD5(uploadSampleFile); + entity.setSampleMd5(sampleMd5); + }else{ + logger.error("调用外部程序返回fileId错误,输入的fileId为:"+entity.getCfgId()+",输出的fileId为:"+fileId); + throw new CallExternalProceduresException(); + } + //文件上传至综合服务 + Date creatTime = entity.getCreateTime(); + //音视频文件上传接口调用 + File srcFile = new File(entity.getSrcPath()); + Map srcMap = new HashMap(); + srcMap.put("filetype", FileUtils.getSuffix(srcFile.getName(), false)); + srcMap.put("datatype", "dbSystem");//源文件存入数据中心 + + srcMap.put("createTime",creatTime); + srcMap.put("key",FileUtils.getPrefix(srcFile.getName(), false)); + srcMap.put("fileName", srcFile.getName()); + srcMap.put("checksum", entity.getSrcMd5()); + ToMaatResult result1 = ConfigServiceUtil.postFileCfg(null, srcFile, JsonMapper.toJsonString(srcMap)); + logger.info("音视频源文件上传响应信息:"+result1.toString()); + //获取文件上传响应信息(新的文件访问路径) + String srcAccessUrl = null; + if(!StringUtil.isEmpty(result1)){ + ResponseData data = result1.getData(); + srcAccessUrl=data.getAccessUrl(); + entity.setSrcUrl(srcAccessUrl); + } + File sampleFile = new File(entity.getSamplePath()); + Map sampleMap = new HashMap(); + sampleMap.put("filetype", FileUtils.getSuffix(sampleFile.getName(), false)); + sampleMap.put("datatype", "fileSystem");//样例文件存入fastdfs + sampleMap.put("createTime", creatTime); + sampleMap.put("key",FileUtils.getPrefix(sampleFile.getName(), false)); + sampleMap.put("fileName", sampleFile.getName()); + sampleMap.put("checksum", entity.getSampleMd5()); + ToMaatResult result2 = ConfigServiceUtil.postFileCfg(null, sampleFile, JsonMapper.toJsonString(sampleMap)); + logger.info("音视频样例文件上传响应信息:"+result2.toString()); + //获取文件上传响应信息(新的文件访问路径) + String sampleAccessUrl = null; + if(!StringUtil.isEmpty(result2)){ + ResponseData data = result2.getData(); + sampleAccessUrl = data.getAccessUrl(); + entity.setSampleUrl(sampleAccessUrl); + + } + //删除本地源文件和样例文件 + FileUtils.deleteFile(entity.getSrcPath()); + FileUtils.deleteFile(entity.getSamplePath()); }else{ entity.setIsSampleCreated(-1);//样例文件创建失败 + logger.error("样例文件生成失败"); + throw new CallExternalProceduresException(); } - if(fileId.equals(entity.getCfgId().intValue())){ - File uploadSampleFile = new File(entity.getSamplePath()); - String sampleMd5 = FileUtils.getFileMD5(uploadSampleFile); - entity.setSampleMd5(sampleMd5); - }else{ - logger.info("调用外部程序返回fileId错误,输入的fileId为:"+entity.getCfgId()+",输出的fileId为:"+fileId); - } + }else{ throw new CallExternalProceduresException(); }