diff --git a/bootdo/bootdo.sql b/bootdo/bootdo.sql index 8cbb11c4a4b9b4d57425ca4a4331decf23d8db79..490d5bb6915282a8904bc52806cd1e64411d9dee 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 b9befe526d120fe36977356301e50363bb4cc28d..db7237fcf71eb90af092c7f43bc0ce31646e759e 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/aspect/LogAspect.java b/bootdo/src/main/java/com/bootdo/common/aspect/LogAspect.java index 85b2152859a26012dd219113253b65a2a63eacc2..b374b8a1501fa6a9f5801497f6947eb1b14161f6 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) { 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 8f249363aa736e171d3ec1ad70dda43533341753..c608024fa274b5a0dfc4f847191793f8545756f8 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 7e3ce72754b8e87f91c23d55ea0014dccd39e549..0c5ec93e973df630e36768ae45d4b16d535a226e 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 0000000000000000000000000000000000000000..fc6f9721ca3da726a0c93e6ca267261f9deb48c4 --- /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 7e76a93819ca25ba0fe997463029b69d61786c91..82f7312a4e987078cfc08459a55453b17d60dfc9 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/static/js/lay/modules/upload.js b/bootdo/src/main/resources/static/js/lay/modules/upload.js index f8a52d3caab19af20ac953f736ed974814713fd4..d5bd6528de6d0aa8b1450091b40ef2cbe6075205 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; diff --git a/bootdo/src/main/resources/templates/common/file/file.html b/bootdo/src/main/resources/templates/common/file/file.html index e05b0f7cfb2bce448452cd7653b1ff95cd46a0ca..ac90e975e53f14af40f08b7d64d826aa74725fbc 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);