From a231611c394fbf22c862dba35130ea6851916f81 Mon Sep 17 00:00:00 2001 From: zhangwei Date: Mon, 27 Aug 2018 16:39:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=96=B0=E5=A2=9E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=97=B6=E6=A0=B7=E4=BE=8B=E6=96=87=E4=BB=B6=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=88=90=E5=8A=9F=E5=90=8E=E7=AB=8B=E5=88=BB=E5=B0=86?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6=E5=92=8C=E6=A0=B7=E4=BE=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E8=87=B3=E4=B8=AD=E9=97=B4=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwei --- .../configuration/ntc/AvController.java | 20 +++--- .../service/configuration/AvCfgService.java | 62 ++++++++++++++++--- 2 files changed, 66 insertions(+), 16 deletions(-) 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(); }