From 8f815b50fb5b34ea2e8a28bf945bff63830c5b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= <444841729@qq.com> Date: Thu, 17 Jan 2019 09:07:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlog=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=88=AA=E5=8F=96=E9=95=BF=E5=BA=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java b/bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java index 85b2152..b374b8a 100644 --- a/bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java +++ b/bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java @@ -71,7 +71,8 @@ public class LogAspect { // 请求的参数 Object[] args = joinPoint.getArgs(); try { - String params = JSONUtils.beanToJson(args[0]).substring(0, 4999); + String params = JSONUtils.beanToJson(args[0]); + sysLog.setParams(params.length()>4999?params.substring(0, 4999):params); sysLog.setParams(params); } catch (Exception e) { -- Gitee From f27638fbca74040d834c586653a8db824b8ba2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= <444841729@qq.com> Date: Wed, 23 Jan 2019 10:25:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=8C=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=87=E6=9C=AC=E8=AE=A1=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootdo/src/main/resources/static/js/lay/modules/upload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootdo/src/main/resources/static/js/lay/modules/upload.js b/bootdo/src/main/resources/static/js/lay/modules/upload.js index f8a52d3..d5bd652 100644 --- a/bootdo/src/main/resources/static/js/lay/modules/upload.js +++ b/bootdo/src/main/resources/static/js/lay/modules/upload.js @@ -346,7 +346,7 @@ layui.define('layer' , function(exports){ if(file.size > 1024*options.size){ var size = options.size/1024; size = size >= 1 - ? (Math.floor(size) + (size%1 > 0 ? size.toFixed(1) : 0)) + 'MB' + ? (Math.floor(size) + (size%1 > 0 ? parseFloat(size.toFixed(1)) : 0)) + 'MB' : options.size + 'KB' elemFile.value = ''; limitSize = size; -- Gitee From 7c216bb943f2f2f78b9c6f2da8d95cb37a9ae069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= <444841729@qq.com> Date: Wed, 23 Jan 2019 18:05:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E5=9B=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootdo/bootdo.sql | 17 +-- bootdo/pom.xml | 5 + .../common/controller/FileController.java | 16 ++- .../java/com/bootdo/common/domain/FileDO.java | 24 +++++ .../com/bootdo/common/utils/VideoUtils.java | 102 ++++++++++++++++++ .../resources/mybatis/common/FileMapper.xml | 10 +- .../resources/templates/common/file/file.html | 5 +- 7 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 bootdo/src/main/java/com/bootdo/common/utils/VideoUtils.java diff --git a/bootdo/bootdo.sql b/bootdo/bootdo.sql index 8cbb11c..490d5bb 100644 --- a/bootdo/bootdo.sql +++ b/bootdo/bootdo.sql @@ -994,6 +994,7 @@ CREATE TABLE `sys_file` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `type` int(11) DEFAULT NULL COMMENT '文件类型', `url` varchar(200) DEFAULT NULL COMMENT 'URL地址', + `view_url` varchar(255) DEFAULT NULL COMMENT '预览地址【视频预览图】', `create_date` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=utf8 COMMENT='文件上传'; @@ -1001,14 +1002,14 @@ CREATE TABLE `sys_file` ( -- ---------------------------- -- Records of sys_file -- ---------------------------- -INSERT INTO `sys_file` VALUES ('110', '0', '/files/d64a62e3-6821-48f1-bac6-a1b9945f4afb.jpg', '2017-10-14 16:20:17'); -INSERT INTO `sys_file` VALUES ('111', '0', '/files/aa2c3dc6-495f-48cc-8e12-446eceb2535e.jpg', '2017-10-14 16:20:21'); -INSERT INTO `sys_file` VALUES ('118', '0', '/files/a973499e-3ec7-4d43-8a52-b6f6517c77e3.jpg', '2017-10-20 11:53:52'); -INSERT INTO `sys_file` VALUES ('132', '0', '/files/e6f13526-e31c-4ebe-a3cf-5fd88dd10be6.jpg', '2017-12-18 20:19:51'); -INSERT INTO `sys_file` VALUES ('134', '0', '/files/cd016e72-77f7-4425-afe2-b79dfbdc3ae9.jpeg', '2017-12-18 22:44:07'); -INSERT INTO `sys_file` VALUES ('138', '0', '/files/9ec12ee7-65b5-4cc5-9900-d2ec6185b336.jpg', '2017-12-19 19:55:27'); -INSERT INTO `sys_file` VALUES ('139', '0', '/files/f6aab9d4-00a1-4bc8-a695-40fc472d4ea9.jpg', '2018-01-02 19:53:24'); -INSERT INTO `sys_file` VALUES ('141', '0', '/files/445c5d98-b3b6-4226-a5af-249d1b2a6a34.jpg', '2018-01-09 19:28:53'); +INSERT INTO `sys_file` VALUES ('110', '0', '/files/d64a62e3-6821-48f1-bac6-a1b9945f4afb.jpg',"", '2017-10-14 16:20:17'); +INSERT INTO `sys_file` VALUES ('111', '0', '/files/aa2c3dc6-495f-48cc-8e12-446eceb2535e.jpg',"", '2017-10-14 16:20:21'); +INSERT INTO `sys_file` VALUES ('118', '0', '/files/a973499e-3ec7-4d43-8a52-b6f6517c77e3.jpg',"", '2017-10-20 11:53:52'); +INSERT INTO `sys_file` VALUES ('132', '0', '/files/e6f13526-e31c-4ebe-a3cf-5fd88dd10be6.jpg',"", '2017-12-18 20:19:51'); +INSERT INTO `sys_file` VALUES ('134', '0', '/files/cd016e72-77f7-4425-afe2-b79dfbdc3ae9.jpeg',"", '2017-12-18 22:44:07'); +INSERT INTO `sys_file` VALUES ('138', '0', '/files/9ec12ee7-65b5-4cc5-9900-d2ec6185b336.jpg',"", '2017-12-19 19:55:27'); +INSERT INTO `sys_file` VALUES ('139', '0', '/files/f6aab9d4-00a1-4bc8-a695-40fc472d4ea9.jpg',"", '2018-01-02 19:53:24'); +INSERT INTO `sys_file` VALUES ('141', '0', '/files/445c5d98-b3b6-4226-a5af-249d1b2a6a34.jpg',"", '2018-01-09 19:28:53'); -- ---------------------------- -- Table structure for `sys_log` diff --git a/bootdo/pom.xml b/bootdo/pom.xml index b9befe5..db7237f 100644 --- a/bootdo/pom.xml +++ b/bootdo/pom.xml @@ -127,6 +127,11 @@ fastjson 1.2.31 + + org.bytedeco + javacv-platform + 1.3.1 + org.apache.velocity diff --git a/bootdo/src/main/java/com/bootdo/common/controller/FileController.java b/bootdo/src/main/java/com/bootdo/common/controller/FileController.java index 8f24936..c608024 100644 --- a/bootdo/src/main/java/com/bootdo/common/controller/FileController.java +++ b/bootdo/src/main/java/com/bootdo/common/controller/FileController.java @@ -4,6 +4,11 @@ import com.bootdo.common.config.BootdoConfig; import com.bootdo.common.domain.FileDO; import com.bootdo.common.service.FileService; import com.bootdo.common.utils.*; +import com.bootdo.common.utils.FileType; +import com.bootdo.common.utils.FileUtil; +import com.bootdo.common.utils.R; +import com.bootdo.common.utils.VideoUtils; + import javax.servlet.http.HttpServletRequest; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -145,13 +150,22 @@ public class FileController extends BaseController { } String fileName = file.getOriginalFilename(); fileName = FileUtil.renameToUUID(fileName); - FileDO sysFile = new FileDO(FileType.fileType(fileName), "/files/" + fileName, new Date()); + //获取文件分类 + Integer fileType = FileType.fileType(fileName); + FileDO sysFile = new FileDO(fileType, "/files/" + fileName, new Date()); try { FileUtil.uploadFile(file.getBytes(), bootdoConfig.getUploadPath(), fileName); + //如果是视频文件 + if (fileType==2) { + String filePrefix = fileName.substring(0,fileName.lastIndexOf(".")); + VideoUtils.videoImage(bootdoConfig.getUploadPath() + fileName, bootdoConfig.getUploadPath(),filePrefix+".png" ); + sysFile.setViewUrl("/files/" +filePrefix+".png"); + } } catch (Exception e) { return R.error(); } + if (sysFileService.save(sysFile) > 0) { return R.ok().put("fileName",sysFile.getUrl()); } diff --git a/bootdo/src/main/java/com/bootdo/common/domain/FileDO.java b/bootdo/src/main/java/com/bootdo/common/domain/FileDO.java index 7e3ce72..0c5ec93 100644 --- a/bootdo/src/main/java/com/bootdo/common/domain/FileDO.java +++ b/bootdo/src/main/java/com/bootdo/common/domain/FileDO.java @@ -19,6 +19,8 @@ public class FileDO implements Serializable { private Integer type; // URL地址 private String url; + //预览地址【视频预览图】 + private String viewUrl; // 创建时间 private Date createDate; @@ -28,10 +30,18 @@ public class FileDO implements Serializable { } + public FileDO(Integer type, String url,String viewUrl, Date createDate) { + super(); + this.type = type; + this.url = url; + this.viewUrl = viewUrl; + this.createDate = createDate; + } public FileDO(Integer type, String url, Date createDate) { super(); this.type = type; this.url = url; + this.viewUrl = ""; this.createDate = createDate; } @@ -78,6 +88,19 @@ public class FileDO implements Serializable { return url; } + /** + * 设置:预览地址【视频预览图】 + */ + public void setViewUrl(String viewUrl) { + this.viewUrl = viewUrl; + } + /** + * 获取:预览地址【视频预览图】 + */ + public String getViewUrl() { + return viewUrl; + } + /** * 设置:创建时间 */ @@ -98,6 +121,7 @@ public class FileDO implements Serializable { "id=" + id + ", type=" + type + ", url='" + url + '\'' + + ", viewUrl='" + viewUrl + '\'' + ", createDate=" + createDate + '}'; } diff --git a/bootdo/src/main/java/com/bootdo/common/utils/VideoUtils.java b/bootdo/src/main/java/com/bootdo/common/utils/VideoUtils.java new file mode 100644 index 0000000..fc6f972 --- /dev/null +++ b/bootdo/src/main/java/com/bootdo/common/utils/VideoUtils.java @@ -0,0 +1,102 @@ +package com.bootdo.common.utils; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +import javax.imageio.ImageIO; + +import org.bytedeco.javacv.FFmpegFrameGrabber; +import org.bytedeco.javacv.Frame; +import org.bytedeco.javacv.FrameGrabber; +import org.bytedeco.javacv.Java2DFrameConverter; + +public class VideoUtils { + + /** + * 截取视频第六帧的图片 + * @param filePath 视频路径 + * @param dir 文件存放的根目录 + * @return 图片的相对路径 例:pic/1.png + * @throws FrameGrabber.Exception + */ + public static String videoImage(String filePath,String dir) throws FrameGrabber.Exception { + return videoImage(filePath, dir, null); + } + + /** + * 截取视频第六帧的图片 + * @param filePath 视频路径 + * @param dir 文件存放的根目录 + * @param videoViewImgFileName 视频预览图片名称 + * @return 图片的相对路径 例:pic/1.png + * @throws FrameGrabber.Exception + */ + public static String videoImage(String filePath,String dir,String videoViewImgFileName) throws FrameGrabber.Exception { + String pngPath = ""; + FFmpegFrameGrabber ff = FFmpegFrameGrabber.createDefault(filePath); + + ff.start(); + int ffLength = ff.getLengthInFrames(); + Frame f; + int i = 0; + while (i < ffLength) { + f = ff.grabImage(); + //截取第6帧 + if((i>5) && (f.image != null)){ + //生成图片的相对路径 例如:pic/uuid.png + if (StringUtils.isBlank(videoViewImgFileName)) { + pngPath = getPngPath(); + }else { + pngPath = videoViewImgFileName; + } + //执行截图并放入指定位置 + doExecuteFrame(f, dir+pngPath); + break; + } + i++; + } + ff.stop(); + + return pngPath; + } + + /** + * 生成图片的相对路径 + * @return 图片的相对路径 例:pic/1.png + */ + private static String getPngPath(){ + return "pic/"+getUUID()+".png"; + } + + + /** + * 生成唯一的uuid + * @return uuid + */ + private static String getUUID(){ + return UUID.randomUUID().toString().replace("-",""); + } + + + /** + * 截取缩略图 + * @param f Frame + * @param targerFilePath:封面图片存放路径 + */ + private static void doExecuteFrame(Frame f, String targerFilePath) { + String imagemat = "png"; + if (null == f || null == f.image) { + return; + } + Java2DFrameConverter converter = new Java2DFrameConverter(); + BufferedImage bi = converter.getBufferedImage(f); + File output = new File(targerFilePath); + try { + ImageIO.write(bi, imagemat, output); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/bootdo/src/main/resources/mybatis/common/FileMapper.xml b/bootdo/src/main/resources/mybatis/common/FileMapper.xml index 7e76a93..82f7312 100644 --- a/bootdo/src/main/resources/mybatis/common/FileMapper.xml +++ b/bootdo/src/main/resources/mybatis/common/FileMapper.xml @@ -3,16 +3,18 @@ + @@ -43,12 +46,14 @@ ( `type`, `url`, + `view_url`, `create_date` ) values ( #{type}, #{url}, + #{viewUrl}, #{createDate} ) @@ -58,6 +63,7 @@ `type` = #{type}, `url` = #{url}, + `view_url` = #{viewUrl}, `create_date` = #{createDate} where id = #{id} diff --git a/bootdo/src/main/resources/templates/common/file/file.html b/bootdo/src/main/resources/templates/common/file/file.html index e05b0f7..ac90e97 100644 --- a/bootdo/src/main/resources/templates/common/file/file.html +++ b/bootdo/src/main/resources/templates/common/file/file.html @@ -64,7 +64,8 @@
- image + image + image

@@ -198,7 +199,7 @@ var uploadInst = upload.render({ elem: '#test1', //绑定元素 url: '/common/sysFile/upload', //上传接口 - size: 1000, + size: 1024*10, accept: 'file', done: function (r) { layer.msg(r.msg); -- Gitee