20200527-zlp-1

培训大视频上传至七牛
This commit is contained in:
paidaxing444
2020-05-27 18:04:57 +08:00
parent 582870a7cc
commit 0e283e22f4
19 changed files with 595 additions and 243 deletions

View File

@ -69,6 +69,7 @@
"vue-cropper": "0.4.9", "vue-cropper": "0.4.9",
"vue-quill-editor": "3.0.6", "vue-quill-editor": "3.0.6",
"vue-router": "3.0.2", "vue-router": "3.0.2",
"vue-simple-uploader": "^0.7.4",
"vue-splitpane": "1.0.4", "vue-splitpane": "1.0.4",
"vuedraggable": "2.20.0", "vuedraggable": "2.20.0",
"vuex": "3.1.0" "vuex": "3.1.0"

View File

@ -9,6 +9,15 @@ export function listLecturer(query) {
}) })
} }
// 查询讲师列表
export function listAllLecturer(query) {
return request({
url: '/benyi/lecturer/listAll',
method: 'get',
params: query
})
}
// 查询讲师详细 // 查询讲师详细
export function getLecturer(id) { export function getLecturer(id) {
return request({ return request({

View File

@ -26,6 +26,15 @@ export function addVideo(data) {
}) })
} }
// 获取七牛云token
export function getQiNiuToken(data) {
return request({
url: '/common/getQiNiuToken',
method: 'post',
data: data
})
}
// 修改培训 // 修改培训
export function updateVideo(data) { export function updateVideo(data) {
return request({ return request({

View File

@ -24,6 +24,7 @@ import Pagination from "@/components/Pagination";
import Video from 'video.js' import Video from 'video.js'
import 'video.js/dist/video-js.css' import 'video.js/dist/video-js.css'
// 全局方法挂载 // 全局方法挂载
Vue.prototype.getDicts = getDicts Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey Vue.prototype.getConfigKey = getConfigKey

View File

@ -98,14 +98,14 @@
<!-- 添加或修改讲师对话框 --> <!-- 添加或修改讲师对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px"> <el-dialog :title="title" :visible.sync="open" width="500px">
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="姓名" prop="name"> <el-form-item label="讲师姓名" prop="name">
<el-input v-model="form.name" placeholder="请输入姓名" /> <el-input v-model="form.name" placeholder="请输入姓名" />
</el-form-item> </el-form-item>
<el-form-item label="简介" prop="information"> <el-form-item label="讲师简介" prop="information">
<el-input v-model="form.information" type="textarea" placeholder="请输入内容" /> <el-input v-model="form.information" type="textarea" placeholder="请输入内容" />
<el-input v-model="form.imgurl" v-if="false" /> <el-input v-model="form.imgurl" v-if="false" />
</el-form-item> </el-form-item>
<el-form-item label="照片" prop="imgurl"> <el-form-item label="选择照片" prop="imgurl">
<el-upload <el-upload
class="avatar-uploader" class="avatar-uploader"
:action="uploadImgUrl" :action="uploadImgUrl"

View File

@ -2,24 +2,20 @@
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<el-form-item label="讲师姓名" prop="lecturer"> <el-form-item label="讲师姓名" prop="lecturer">
<el-input <el-select v-model="queryParams.lecturer" filterable placeholder="请选择讲师">
v-model="queryParams.lecturer" <el-option
placeholder="请输入讲师姓名" v-for="item in lecturerOptions"
clearable :key="item.id"
size="small" :label="item.name"
@keyup.enter.native="handleQuery" :value="item.id"
/> />
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="所属类别" prop="type"> <el-form-item label="所属类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择所属类别" clearable size="small"> <el-select v-model="queryParams.type" placeholder="请选择所属类别" clearable size="small">
<el-option label="请选择字典生成" value /> <el-option label="请选择字典生成" value />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="适用班级" prop="classtype">
<el-select v-model="queryParams.classtype" placeholder="请选择适用班级" clearable size="small">
<el-option label="请选择字典生成" value />
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createtime"> <el-form-item label="创建时间" prop="createtime">
<el-date-picker <el-date-picker
clearable clearable
@ -67,27 +63,15 @@
v-hasPermi="['benyi:video:remove']" v-hasPermi="['benyi:video:remove']"
>删除</el-button> >删除</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['benyi:video:export']"
>导出</el-button>
</el-col>
</el-row> </el-row>
<el-table v-loading="loading" :data="videoList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="videoList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="id" /> <el-table-column label="编号" align="center" prop="id" />
<el-table-column label="培训视频标题" align="center" prop="title" /> <el-table-column label="培训视频标题" align="center" prop="title" />
<el-table-column label="简介" align="center" prop="information" /> <el-table-column label="视频简介" align="center" prop="information" />
<el-table-column label="讲师" align="center" prop="lecturer" /> <el-table-column label="培训讲师" align="center" prop="lecturername" />
<el-table-column label="视频路径" align="center" prop="videourl" />
<el-table-column label="所属类别" align="center" prop="type" /> <el-table-column label="所属类别" align="center" prop="type" />
<el-table-column label="适用班级" align="center" prop="classtype" />
<el-table-column label="上传人员" align="center" prop="createuserid" />
<el-table-column label="创建时间" align="center" prop="createtime" width="180"> <el-table-column label="创建时间" align="center" prop="createtime" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createtime) }}</span> <span>{{ parseTime(scope.row.createtime) }}</span>
@ -124,56 +108,61 @@
<!-- 添加或修改培训对话框 --> <!-- 添加或修改培训对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px"> <el-dialog :title="title" :visible.sync="open" width="500px">
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="标题" prop="title"> <el-form-item label="视频标题" prop="title">
<el-input v-model="form.title" type="textarea" placeholder="请输入内容" /> <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
</el-form-item> </el-form-item>
<el-form-item label="简介" prop="information"> <el-form-item label="视频简介" prop="information">
<el-input v-model="form.information" type="textarea" placeholder="请输入内容" /> <el-input v-model="form.information" type="textarea" placeholder="请输入内容" />
</el-form-item> </el-form-item>
<el-form-item label="讲师" prop="lecturer"> <el-form-item label="培训讲师" prop="lecturer">
<el-input v-model="form.lecturer" placeholder="请选择讲师" /> <el-select v-model="form.lecturer" placeholder="请选择讲师">
<el-input v-model="form.videourl" v-if="false" />
<el-option
v-for="item in lecturerOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="视频" prop="videourl"> <el-form-item label="选择视频" prop="videourl">
<!-- <el-input v-model="form.videourl" type="textarea" placeholder="请输入内容" /> --> <div id="app">
<!-- action必选参数, 上传的地址 -->
<el-upload <el-upload
class="avatar-uploader el-upload--text" class="avatar-uploader"
:action="uploadUrl" :data="dataObj"
:headers="headers" action="http://upload.qiniup.com"
list-type="picture-card"
:show-file-list="false" :show-file-list="false"
:on-success="handleVideoSuccess" :on-error="handleError"
:before-upload="beforeUploadVideo" :on-success="handleSuccessVideo"
:on-progress="uploadVideoProcess" :on-progress="uploadProcess"
:before-upload="videoBeforeUpload"
:on-remove="handleRemove"
> >
<video <video
v-if="videoForm.Video !='' && videoFlag == false" v-if="imageUrl.length > 1 && imgFlag == false"
:src="videoForm.Video"
class="avatar"
controls="controls" controls="controls"
>您的浏览器不支持视频播放</video> :src="[qiniuUrl + '/' + imageUrl]"
class="avatar"
></video>
<i <i
v-else-if="videoForm.Video =='' && videoFlag == false" v-else-if="imageUrl.length < 1 && imgFlag == false"
class="el-icon-plus avatar-uploader-icon" class="el-icon-plus avatar-uploader-icon"
></i> ></i>
<el-progress <el-progress
v-if="videoFlag == true" v-if="imgFlag == true"
type="circle" type="circle"
:percentage="videoUploadPercent" :percentage="percent"
style="margin-top:30px;" style="margin-top: 20px"
></el-progress> ></el-progress>
</el-upload> </el-upload>
<P class="text">请保证视频格式正确且不超过500M</P> </div>
</el-form-item> </el-form-item>
<el-form-item label="所属类别"> <el-form-item label="所属类别">
<el-select v-model="form.type" placeholder="请选择所属类别"> <el-select v-model="form.type" placeholder="请选择所属类别">
<el-option label="请选择字典生成" value /> <el-option label="请选择字典生成" value />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="适用班级">
<el-select v-model="form.classtype" placeholder="请选择适用班级">
<el-option label="请选择字典生成" value />
</el-select>
</el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
@ -183,6 +172,8 @@
</div> </div>
</template> </template>
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.9.1/lib/index.js"></script>
<script> <script>
import { import {
listVideo, listVideo,
@ -190,15 +181,24 @@ import {
delVideo, delVideo,
addVideo, addVideo,
updateVideo, updateVideo,
exportVideo getQiNiuToken
} from "@/api/benyi_train/video"; } from "@/api/benyi_train/video";
import { listAllLecturer } from "@/api/benyi_train/lecturer";
import { getToken } from "@/utils/auth";
export default { export default {
name: "Video", name: "Video",
data() { data() {
return { return {
qiniuUrl: "https://files.benyiedu.com/", // 个人七牛访问前缀
imgFlag: false,
imageUrl: [],
percent: 0,
dialogImageUrl: "",
dialogVisible: false,
listObj: {},
dataObj: {
token: ""
}, // 此处七牛token写成常量方便调试正式环境需要获取token
// 遮罩层 // 遮罩层
loading: true, loading: true,
// 选中数组 // 选中数组
@ -213,16 +213,10 @@ export default {
videoList: [], videoList: [],
// 弹出层标题 // 弹出层标题
title: "", title: "",
//讲师列表
lecturerOptions: [],
// 是否显示弹出层 // 是否显示弹出层
open: false, open: false,
uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
headers: {
Authorization: "Bearer " + getToken()
},
videoForm: [],
//上传进度
videoFlag:"",
videoUploadPercent:"",
// 查询参数 // 查询参数
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
@ -244,45 +238,64 @@ export default {
}, },
created() { created() {
this.getList(); this.getList();
listAllLecturer().then(response => {
console.log(response.lecturer);
this.lecturerOptions = response.lecturer;
});
getQiNiuToken().then(res => {
console.log(res.token);
this.dataObj.token = res.token;
});
}, },
methods: { methods: {
//上传 handleRemove(file, fileList) {
beforeUploadVideo(file) { this.imageUrl = "";
},
handleSuccessVideo(response) {
console.log(123, response);
this.imgFlag = false;
this.percent = 0;
if (response.hash) {
this.imageUrl = response.hash;
} else {
this.msgError("视频上传失败,请重新上传!");
}
},
handleError(err, file, fileList) {
// 上传失败异常处理
const error = JSON.parse(JSON.stringify(err));
console.log(err);
console.log(error);
this.msgError(error.status.toString());
this.imgFlag = false;
this.percent = 0;
},
videoBeforeUpload(file) {
console.log(file);
const _self = this;
const isVideo =
file.type === "video/mp4" ||
file.type === "video/ogg" ||
file.type === "video/flv" ||
file.type === "video/avi" ||
file.type === "video/wmv" ||
file.type === "video/rmvb";
const isLt500M = file.size / 1024 / 1024 < 500; const isLt500M = file.size / 1024 / 1024 < 500;
if ( if (!isVideo) {
[ this.msgError("请上传正确格式的视频!");
"video/mp4", return false;
"video/ogg", } else {
"video/flv", if (!isLt500M) {
"video/avi", this.msgError("上传视频文件大小不能超过 500MB!");
"video/wmv",
"video/rmvb"
].indexOf(file.type) == -1
) {
this.msgError("请上传正确的视频格式");
return false; return false;
} }
if (!isLt500M) {
this.msgError("上传视频大小不能超过500MB哦!");
return false;
} }
}, },
//上传进度 //上传进度
uploadVideoProcess(event, file, fileList) { uploadProcess(event, file, fileList) {
this.videoFlag = true; this.imgFlag = true;
this.videoUploadPercent = file.percentage.toFixed(0); console.log(event.percent);
}, this.percent = Math.floor(event.percent);
//上传后获取路径
handleVideoSuccess(res, file) {
//获取上传图片地址
this.videoFlag = false;
this.videoUploadPercent = 0;
if (res.status == 200) {
this.videoForm.videoUploadId = res.data.uploadId;
this.videoForm.Video = res.data.uploadUrl;
} else {
this.$message.error("视频上传失败,请重新上传!");
}
}, },
/** 查询培训列表 */ /** 查询培训列表 */
getList() { getList() {
@ -331,24 +344,39 @@ export default {
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.imageUrl="";
this.reset(); this.reset();
this.open = true; this.open = true;
this.title = "添加培训"; this.title = "添加培训";
//获取讲师列表
listAllLecturer().then(response => {
//console.log(response.lecturer);
this.lecturerOptions = response.lecturer;
});
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
this.imageUrl="";
this.reset(); this.reset();
const id = row.id || this.ids; const id = row.id || this.ids;
getVideo(id).then(response => { getVideo(id).then(response => {
this.form = response.data; this.form = response.data;
this.open = true; this.open = true;
this.title = "修改培训"; this.title = "修改培训";
this.imageUrl = response.data.videourl;
console.log(this.imageUrl);
//获取讲师列表
listAllLecturer().then(response => {
//console.log(response.lecturer);
this.lecturerOptions = response.lecturer;
});
}); });
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm: function() { submitForm: function() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
this.form.videourl = this.imageUrl;
if (this.form.id != undefined) { if (this.form.id != undefined) {
updateVideo(this.form).then(response => { updateVideo(this.form).then(response => {
if (response.code === 200) { if (response.code === 200) {
@ -389,23 +417,85 @@ export default {
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}) })
.catch(function() {}); .catch(function() {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有培训数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(function() {
return exportVideo(queryParams);
})
.then(response => {
this.download(response.msg);
})
.catch(function() {});
} }
} }
}; };
</script> </script>
<style scoped>
@import url("//unpkg.com/element-ui@2.9.1/lib/theme-chalk/index.css");
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
width: 178px;
height: 178px;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
.image-preview {
width: 178px;
height: 178px;
position: relative;
border: 1px dashed #d9d9d9;
border-radius: 6px;
float: left;
}
.image-preview .image-preview-wrapper {
position: relative;
width: 100%;
height: 100%;
}
.image-preview .image-preview-wrapper img {
width: 100%;
height: 100%;
}
.image-preview .image-preview-action {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
cursor: default;
text-align: center;
color: #fff;
opacity: 0;
font-size: 20px;
background-color: rgba(0, 0, 0, 0.5);
transition: opacity 0.3s;
cursor: pointer;
text-align: center;
line-height: 200px;
}
.image-preview .image-preview-action .el-icon-delete {
font-size: 32px;
}
.image-preview:hover .image-preview-action {
opacity: 1;
}
</style>

View File

@ -249,6 +249,32 @@
<version>5.1.5.RELEASE</version> <version>5.1.5.RELEASE</version>
</dependency> </dependency>
<!-- 网络连接相关 -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
<!-- 七牛云包 -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.2.8</version>
<exclusions>
<exclusion>
<artifactId>okhttp</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 其他工具包 -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,72 @@
package com.ruoyi.common.utils;
import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import com.ruoyi.framework.config.FileConfig;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
public class ByFileUtil {
/**
* File转成编码成BASE64
*
* @param file 文件对象
* @return String
*/
public static String fileToBase64(File file) {
String base64 = null;
try {
byte[] b = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
return Base64.getEncoder().encodeToString(b);
} catch (Exception e) {
e.printStackTrace();
}
return base64;
}
/**
* 将文件上传到七牛云
*/
public static String uploadQNImg(InputStream file, String key, FileConfig constantQiniu) {
// 构造一个带指定Zone对象的配置类 华北 2020-02-06 已改用华东
Configuration cfg = new Configuration(Zone.zone0());
// 其他参数参考类注释
UploadManager uploadManager = new UploadManager(cfg);
// 生成上传凭证,然后准备上传
try {
Auth auth = Auth.create(constantQiniu.getAccessKey(), constantQiniu.getSecretKey());
String upToken = auth.uploadToken(constantQiniu.getBucket());
try {
Response response = uploadManager.put(file, key, upToken, null, null);
// 解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
String returnPath = constantQiniu.getDomain() + "" + putRet.key;
return returnPath;
} catch (QiniuException ex) {
Response r = ex.response;
System.err.println(r.toString());
try {
System.err.println(r.bodyString());
} catch (QiniuException ex2) {
//ignore
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}

View File

@ -21,9 +21,9 @@ import com.ruoyi.framework.config.RuoYiConfig;
public class FileUploadUtils public class FileUploadUtils
{ {
/** /**
* 默认大小 50M * 默认大小 500M
*/ */
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024; public static final long DEFAULT_MAX_SIZE = 500 * 1024 * 1024;
/** /**
* 默认的文件名最大长度 100 * 默认的文件名最大长度 100

View File

@ -32,7 +32,9 @@ public class MimeTypeUtils
// 压缩文件 // 压缩文件
"rar", "zip", "gz", "bz2", "rar", "zip", "gz", "bz2",
// pdf // pdf
"pdf" }; "pdf",
//视频
"mp4"};
public static String getExtension(String prefix) public static String getExtension(String prefix)
{ {

View File

@ -0,0 +1,35 @@
package com.ruoyi.framework.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FileConfig {
@Value("${file.access.key}")
private String accessKey;
@Value("${file.secret.key}")
private String secretKey;
@Value("${file.bucket}")
private String bucket;
@Value("${file.domain}")
private String domain;
public String getAccessKey() {
return accessKey;
}
public String getSecretKey() {
return secretKey;
}
public String getBucket() {
return bucket;
}
public String getDomain() {
return domain;
}
}

View File

@ -113,4 +113,12 @@ public class RuoYiConfig
{ {
return getProfile() + "/upload"; return getProfile() + "/upload";
} }
/**
* 获取视频上传路径
*/
public static String getUploadVideoPath()
{
return getProfile() + "/video";
}
} }

View File

@ -48,6 +48,18 @@ public class ByLecturerController extends BaseController
return getDataTable(list); return getDataTable(list);
} }
/**
* 根据岗位id获取用户信息列表
*/
@GetMapping("/listAll")
public AjaxResult getAllLecturerList(ByLecturer byLecturer) {
AjaxResult ajax = AjaxResult.success();
List<ByLecturer> list = byLecturerService.selectByLecturerList(byLecturer);
ajax.put("lecturer", list);
return ajax;
}
/** /**
* 导出讲师列表 * 导出讲师列表
*/ */

View File

@ -1,6 +1,11 @@
package com.ruoyi.project.benyi.controller; package com.ruoyi.project.benyi.controller;
import java.util.Date;
import java.util.List; import java.util.List;
import com.qiniu.util.Auth;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.config.FileConfig;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -33,6 +38,7 @@ public class ByTrainVideoController extends BaseController
@Autowired @Autowired
private IByTrainVideoService byTrainVideoService; private IByTrainVideoService byTrainVideoService;
/** /**
* 查询培训列表 * 查询培训列表
*/ */
@ -76,6 +82,8 @@ public class ByTrainVideoController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody ByTrainVideo byTrainVideo) public AjaxResult add(@RequestBody ByTrainVideo byTrainVideo)
{ {
byTrainVideo.setCreatetime(new Date());
byTrainVideo.setCreateuserid(SecurityUtils.getLoginUser().getUser().getUserId());
return toAjax(byTrainVideoService.insertByTrainVideo(byTrainVideo)); return toAjax(byTrainVideoService.insertByTrainVideo(byTrainVideo));
} }

View File

@ -14,38 +14,59 @@ import java.util.Date;
* @author tsbz * @author tsbz
* @date 2020-05-25 * @date 2020-05-25
*/ */
public class ByTrainVideo extends BaseEntity public class ByTrainVideo extends BaseEntity {
{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /**
* 编号
*/
private Long id; private Long id;
/** 培训视频标题 */ /**
* 培训视频标题
*/
@Excel(name = "培训视频标题") @Excel(name = "培训视频标题")
private String title; private String title;
/** 简介 */ /**
* 简介
*/
@Excel(name = "简介") @Excel(name = "简介")
private String information; private String information;
/** 讲师 */ /**
* 讲师
*/
@Excel(name = "讲师") @Excel(name = "讲师")
private String lecturer; private Long lecturer;
/** 视频路径 */ /**
* 讲师
*/
@Excel(name = "讲师")
private String lecturername;
/**
* 视频路径
*/
@Excel(name = "视频路径") @Excel(name = "视频路径")
private String videourl; private String videourl;
/** 所属类别 */ /**
* 所属类别
*/
@Excel(name = "所属类别") @Excel(name = "所属类别")
private String type; private String type;
/** 适用班级 */ /**
* 适用班级
*/
@Excel(name = "适用班级") @Excel(name = "适用班级")
private String classtype; private String classtype;
/** 上传人员 */ /**
* 上传人员
*/
@Excel(name = "上传人员") @Excel(name = "上传人员")
private Long createuserid; private Long createuserid;
@ -55,76 +76,75 @@ public class ByTrainVideo extends BaseEntity
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createtime; private Date createtime;
public void setId(Long id) public void setId(Long id) {
{
this.id = id; this.id = id;
} }
public Long getId() public Long getId() {
{
return id; return id;
} }
public void setTitle(String title)
{ public void setTitle(String title) {
this.title = title; this.title = title;
} }
public String getTitle() public String getTitle() {
{
return title; return title;
} }
public void setInformation(String information)
{ public void setInformation(String information) {
this.information = information; this.information = information;
} }
public String getInformation() public String getInformation() {
{
return information; return information;
} }
public void setLecturer(String lecturer)
{ public void setLecturer(Long lecturer) {
this.lecturer = lecturer; this.lecturer = lecturer;
} }
public String getLecturer() public Long getLecturer() {
{
return lecturer; return lecturer;
} }
public void setVideourl(String videourl)
{ public void setLecturername(String lecturername) {
this.lecturername = lecturername;
}
public String getLecturername() {
return lecturername;
}
public void setVideourl(String videourl) {
this.videourl = videourl; this.videourl = videourl;
} }
public String getVideourl() public String getVideourl() {
{
return videourl; return videourl;
} }
public void setType(String type)
{ public void setType(String type) {
this.type = type; this.type = type;
} }
public String getType() public String getType() {
{
return type; return type;
} }
public void setClasstype(String classtype)
{ public void setClasstype(String classtype) {
this.classtype = classtype; this.classtype = classtype;
} }
public String getClasstype() public String getClasstype() {
{
return classtype; return classtype;
} }
public void setCreateuserid(Long createuserid)
{ public void setCreateuserid(Long createuserid) {
this.createuserid = createuserid; this.createuserid = createuserid;
} }
public Long getCreateuserid() public Long getCreateuserid() {
{
return createuserid; return createuserid;
} }
@ -143,6 +163,7 @@ public class ByTrainVideo extends BaseEntity
.append("title", getTitle()) .append("title", getTitle())
.append("information", getInformation()) .append("information", getInformation())
.append("lecturer", getLecturer()) .append("lecturer", getLecturer())
.append("lecturername", getLecturername())
.append("videourl", getVideourl()) .append("videourl", getVideourl())
.append("type", getType()) .append("type", getType())
.append("classtype", getClasstype()) .append("classtype", getClasstype())

View File

@ -1,7 +1,12 @@
package com.ruoyi.project.common; package com.ruoyi.project.common;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.qiniu.util.Auth;
import com.ruoyi.common.utils.ByFileUtil;
import com.ruoyi.framework.config.FileConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -17,18 +22,29 @@ import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.config.ServerConfig; import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.framework.web.domain.AjaxResult;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import static com.ruoyi.common.utils.file.FileUploadUtils.extractFilename;
/** /**
* 通用请求处理 * 通用请求处理
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
public class CommonController public class CommonController {
{
private static final Logger log = LoggerFactory.getLogger(CommonController.class); private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired @Autowired
private ServerConfig serverConfig; private ServerConfig serverConfig;
@Resource
private FileConfig fileConfig;
@Autowired
private FileConfig constantQiniu;
/** /**
* 通用下载请求 * 通用下载请求
@ -37,12 +53,9 @@ public class CommonController
* @param delete 是否删除 * @param delete 是否删除
*/ */
@GetMapping("common/download") @GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
{ try {
try if (!FileUtils.isValidFilename(fileName)) {
{
if (!FileUtils.isValidFilename(fileName))
{
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
} }
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
@ -53,26 +66,23 @@ public class CommonController
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
FileUtils.writeBytes(filePath, response.getOutputStream()); FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete) if (delete) {
{
FileUtils.deleteFile(filePath); FileUtils.deleteFile(filePath);
} }
} } catch (Exception e) {
catch (Exception e)
{
log.error("下载文件失败", e); log.error("下载文件失败", e);
} }
} }
/** /**
* 通用上传请求 * 通用上传请求
*/ */
@PostMapping("/common/upload") @PostMapping("/common/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception public AjaxResult uploadFile(MultipartFile file) throws Exception {
{ try {
try
{
// 上传文件路径 // 上传文件路径
String filePath = RuoYiConfig.getUploadPath(); String filePath = RuoYiConfig.getUploadPath();
System.out.println("path=" + filePath);
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file); String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName; String url = serverConfig.getUrl() + fileName;
@ -80,19 +90,57 @@ public class CommonController
ajax.put("fileName", fileName); ajax.put("fileName", fileName);
ajax.put("url", url); ajax.put("url", url);
return ajax; return ajax;
} } catch (Exception e) {
catch (Exception e)
{
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
/**
* 通用上传请求
*/
@PostMapping("/common/uploadqiniu")
public AjaxResult uploadFileQiNiu(MultipartFile file) throws Exception {
try {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
//String fileName =FileUploadUtils.upload(filePath, file);
String fileName = "video" + extractFilename(file);
System.out.println("start===filename=" + fileName);
InputStream in = file.getInputStream();
String url = ByFileUtil.uploadQNImg(in, fileName, fileConfig);
AjaxResult ajax = AjaxResult.success();
ajax.put("fileName", fileName);
ajax.put("url", url);
System.out.println("end===");
return ajax;
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
/**
* 获取七牛token
**/
@PostMapping("/common/getQiNiuToken")
public AjaxResult getQiNiuToken() {
AjaxResult ajax = AjaxResult.success();
Auth auth = Auth.create(constantQiniu.getAccessKey(), constantQiniu.getSecretKey());
System.out.println("auth:" + auth);
String upToken = auth.uploadToken(constantQiniu.getBucket());
ajax.put("token", upToken);
return ajax;
}
/** /**
* 本地资源通用下载 * 本地资源通用下载
*/ */
@GetMapping("/common/download/resource") @GetMapping("/common/download/resource")
public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
{
// 本地资源路径 // 本地资源路径
String localPath = RuoYiConfig.getProfile(); String localPath = RuoYiConfig.getProfile();
// 数据库资源地址 // 数据库资源地址

View File

@ -138,7 +138,7 @@ public class VelocityUtils
{ {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
} }
else if (template.contains("serviceImpl.java.vm")) else if (template.contains("service.java.vm"))
{ {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
} }

View File

@ -46,9 +46,9 @@ spring:
servlet: servlet:
multipart: multipart:
# 单个文件大小 # 单个文件大小
max-file-size: 10MB max-file-size: 50MB
# 设置总上传的文件大小 # 设置总上传的文件大小
max-request-size: 20MB max-request-size: 100MB
# 服务模块 # 服务模块
devtools: devtools:
restart: restart:
@ -119,3 +119,12 @@ gen:
autoRemovePre: false autoRemovePre: false
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔) # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix: sys_ tablePrefix: sys_
#七牛云
file:
access:
key: 3leP0wEJvWdIck7x4QyzA3lS_Ua8eiFOUEDUro30
secret:
key: auEPimrlHeCBJFc8fcT3s8bOBULKwH_zK95xpQzV
domain: https://files.benyiedu.com/
bucket: bywebfile

View File

@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="title" column="title" /> <result property="title" column="title" />
<result property="information" column="information" /> <result property="information" column="information" />
<result property="lecturer" column="lecturer" /> <result property="lecturer" column="lecturer" />
<result property="lecturername" column="lecturername" />
<result property="videourl" column="videourl" /> <result property="videourl" column="videourl" />
<result property="type" column="type" /> <result property="type" column="type" />
<result property="classtype" column="classtype" /> <result property="classtype" column="classtype" />
@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectByTrainVideoVo"> <sql id="selectByTrainVideoVo">
select id, title, information, lecturer, videourl, type, classtype, createuserid, createtime from by_train_video select id, title, information, lecturer,(select name from by_lecturer where lecturer=by_lecturer.id) as lecturername, videourl, type, classtype, createuserid, createtime from by_train_video
</sql> </sql>
<select id="selectByTrainVideoList" parameterType="ByTrainVideo" resultMap="ByTrainVideoResult"> <select id="selectByTrainVideoList" parameterType="ByTrainVideo" resultMap="ByTrainVideoResult">
@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where> <where>
<if test="title != null and title != ''"> and title = #{title}</if> <if test="title != null and title != ''"> and title = #{title}</if>
<if test="information != null and information != ''"> and information = #{information}</if> <if test="information != null and information != ''"> and information = #{information}</if>
<if test="lecturer != null and lecturer != ''"> and lecturer = #{lecturer}</if> <if test="lecturer != null "> and lecturer = #{lecturer}</if>
<if test="videourl != null and videourl != ''"> and videourl = #{videourl}</if> <if test="videourl != null and videourl != ''"> and videourl = #{videourl}</if>
<if test="type != null and type != ''"> and type = #{type}</if> <if test="type != null and type != ''"> and type = #{type}</if>
<if test="classtype != null and classtype != ''"> and classtype = #{classtype}</if> <if test="classtype != null and classtype != ''"> and classtype = #{classtype}</if>
@ -44,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">title,</if> <if test="title != null and title != ''">title,</if>
<if test="information != null and information != ''">information,</if> <if test="information != null and information != ''">information,</if>
<if test="lecturer != null and lecturer != ''">lecturer,</if> <if test="lecturer != null ">lecturer,</if>
<if test="videourl != null and videourl != ''">videourl,</if> <if test="videourl != null and videourl != ''">videourl,</if>
<if test="type != null and type != ''">type,</if> <if test="type != null and type != ''">type,</if>
<if test="classtype != null and classtype != ''">classtype,</if> <if test="classtype != null and classtype != ''">classtype,</if>
@ -54,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">#{title},</if> <if test="title != null and title != ''">#{title},</if>
<if test="information != null and information != ''">#{information},</if> <if test="information != null and information != ''">#{information},</if>
<if test="lecturer != null and lecturer != ''">#{lecturer},</if> <if test="lecturer != null ">#{lecturer},</if>
<if test="videourl != null and videourl != ''">#{videourl},</if> <if test="videourl != null and videourl != ''">#{videourl},</if>
<if test="type != null and type != ''">#{type},</if> <if test="type != null and type != ''">#{type},</if>
<if test="classtype != null and classtype != ''">#{classtype},</if> <if test="classtype != null and classtype != ''">#{classtype},</if>
@ -68,7 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="title != null and title != ''">title = #{title},</if> <if test="title != null and title != ''">title = #{title},</if>
<if test="information != null and information != ''">information = #{information},</if> <if test="information != null and information != ''">information = #{information},</if>
<if test="lecturer != null and lecturer != ''">lecturer = #{lecturer},</if> <if test="lecturer != null ">lecturer = #{lecturer},</if>
<if test="videourl != null and videourl != ''">videourl = #{videourl},</if> <if test="videourl != null and videourl != ''">videourl = #{videourl},</if>
<if test="type != null and type != ''">type = #{type},</if> <if test="type != null and type != ''">type = #{type},</if>
<if test="classtype != null and classtype != ''">classtype = #{classtype},</if> <if test="classtype != null and classtype != ''">classtype = #{classtype},</if>