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-quill-editor": "3.0.6",
"vue-router": "3.0.2",
"vue-simple-uploader": "^0.7.4",
"vue-splitpane": "1.0.4",
"vuedraggable": "2.20.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) {
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) {
return request({

View File

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

View File

@ -98,14 +98,14 @@
<!-- 添加或修改讲师对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px">
<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-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.imgurl" v-if="false" />
</el-form-item>
<el-form-item label="照片" prop="imgurl">
<el-form-item label="选择照片" prop="imgurl">
<el-upload
class="avatar-uploader"
:action="uploadImgUrl"

View File

@ -2,24 +2,20 @@
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<el-form-item label="讲师姓名" prop="lecturer">
<el-input
v-model="queryParams.lecturer"
placeholder="请输入讲师姓名"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
<el-select v-model="queryParams.lecturer" filterable placeholder="请选择讲师">
<el-option
v-for="item in lecturerOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="所属类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择所属类别" clearable size="small">
<el-option label="请选择字典生成" value />
</el-select>
</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-date-picker
clearable
@ -67,27 +63,15 @@
v-hasPermi="['benyi:video:remove']"
>删除</el-button>
</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-table v-loading="loading" :data="videoList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="培训视频标题" align="center" prop="title" />
<el-table-column label="简介" align="center" prop="information" />
<el-table-column label="讲师" align="center" prop="lecturer" />
<el-table-column label="视频路径" align="center" prop="videourl" />
<el-table-column label="视频简介" align="center" prop="information" />
<el-table-column label="培训讲师" align="center" prop="lecturername" />
<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">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createtime) }}</span>
@ -124,56 +108,61 @@
<!-- 添加或修改培训对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px">
<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-form-item>
<el-form-item label="简介" prop="information">
<el-form-item label="视频简介" prop="information">
<el-input v-model="form.information" type="textarea" placeholder="请输入内容" />
</el-form-item>
<el-form-item label="讲师" prop="lecturer">
<el-input v-model="form.lecturer" placeholder="请选择讲师" />
<el-form-item label="培训讲师" prop="lecturer">
<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 label="视频" prop="videourl">
<!-- <el-input v-model="form.videourl" type="textarea" placeholder="请输入内容" /> -->
<!-- action必选参数, 上传的地址 -->
<el-upload
class="avatar-uploader el-upload--text"
:action="uploadUrl"
:headers="headers"
:show-file-list="false"
:on-success="handleVideoSuccess"
:before-upload="beforeUploadVideo"
:on-progress="uploadVideoProcess"
>
<video
v-if="videoForm.Video !='' && videoFlag == false"
:src="videoForm.Video"
class="avatar"
controls="controls"
>您的浏览器不支持视频播放</video>
<i
v-else-if="videoForm.Video =='' && videoFlag == false"
class="el-icon-plus avatar-uploader-icon"
></i>
<el-progress
v-if="videoFlag == true"
type="circle"
:percentage="videoUploadPercent"
style="margin-top:30px;"
></el-progress>
</el-upload>
<P class="text">请保证视频格式正确且不超过500M</P>
<el-form-item label="选择视频" prop="videourl">
<div id="app">
<el-upload
class="avatar-uploader"
:data="dataObj"
action="http://upload.qiniup.com"
list-type="picture-card"
:show-file-list="false"
:on-error="handleError"
:on-success="handleSuccessVideo"
:on-progress="uploadProcess"
:before-upload="videoBeforeUpload"
:on-remove="handleRemove"
>
<video
v-if="imageUrl.length > 1 && imgFlag == false"
controls="controls"
:src="[qiniuUrl + '/' + imageUrl]"
class="avatar"
></video>
<i
v-else-if="imageUrl.length < 1 && imgFlag == false"
class="el-icon-plus avatar-uploader-icon"
></i>
<el-progress
v-if="imgFlag == true"
type="circle"
:percentage="percent"
style="margin-top: 20px"
></el-progress>
</el-upload>
</div>
</el-form-item>
<el-form-item label="所属类别">
<el-select v-model="form.type" placeholder="请选择所属类别">
<el-option label="请选择字典生成" value />
</el-select>
</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>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
@ -183,6 +172,8 @@
</div>
</template>
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.9.1/lib/index.js"></script>
<script>
import {
listVideo,
@ -190,15 +181,24 @@ import {
delVideo,
addVideo,
updateVideo,
exportVideo
getQiNiuToken
} from "@/api/benyi_train/video";
import { getToken } from "@/utils/auth";
import { listAllLecturer } from "@/api/benyi_train/lecturer";
export default {
name: "Video",
data() {
return {
qiniuUrl: "https://files.benyiedu.com/", // 访
imgFlag: false,
imageUrl: [],
percent: 0,
dialogImageUrl: "",
dialogVisible: false,
listObj: {},
dataObj: {
token: ""
}, // token便token
//
loading: true,
//
@ -213,16 +213,10 @@ export default {
videoList: [],
//
title: "",
//
lecturerOptions: [],
//
open: false,
uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", //
headers: {
Authorization: "Bearer " + getToken()
},
videoForm: [],
//
videoFlag:"",
videoUploadPercent:"",
//
queryParams: {
pageNum: 1,
@ -244,45 +238,64 @@ export default {
},
created() {
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: {
//
beforeUploadVideo(file) {
const isLt500M = file.size / 1024 / 1024 < 500;
if (
[
"video/mp4",
"video/ogg",
"video/flv",
"video/avi",
"video/wmv",
"video/rmvb"
].indexOf(file.type) == -1
) {
this.msgError("请上传正确的视频格式");
return false;
handleRemove(file, fileList) {
this.imageUrl = "";
},
handleSuccessVideo(response) {
console.log(123, response);
this.imgFlag = false;
this.percent = 0;
if (response.hash) {
this.imageUrl = response.hash;
} else {
this.msgError("视频上传失败,请重新上传!");
}
if (!isLt500M) {
this.msgError("上传视频大小不能超过500MB哦!");
},
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;
if (!isVideo) {
this.msgError("请上传正确格式的视频!");
return false;
} else {
if (!isLt500M) {
this.msgError("上传视频文件大小不能超过 500MB!");
return false;
}
}
},
//
uploadVideoProcess(event, file, fileList) {
this.videoFlag = true;
this.videoUploadPercent = file.percentage.toFixed(0);
},
//
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("视频上传失败,请重新上传!");
}
uploadProcess(event, file, fileList) {
this.imgFlag = true;
console.log(event.percent);
this.percent = Math.floor(event.percent);
},
/** 查询培训列表 */
getList() {
@ -331,24 +344,39 @@ export default {
},
/** 新增按钮操作 */
handleAdd() {
this.imageUrl="";
this.reset();
this.open = true;
this.title = "添加培训";
//
listAllLecturer().then(response => {
//console.log(response.lecturer);
this.lecturerOptions = response.lecturer;
});
},
/** 修改按钮操作 */
handleUpdate(row) {
this.imageUrl="";
this.reset();
const id = row.id || this.ids;
getVideo(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改培训";
this.imageUrl = response.data.videourl;
console.log(this.imageUrl);
//
listAllLecturer().then(response => {
//console.log(response.lecturer);
this.lecturerOptions = response.lecturer;
});
});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
this.form.videourl = this.imageUrl;
if (this.form.id != undefined) {
updateVideo(this.form).then(response => {
if (response.code === 200) {
@ -389,23 +417,85 @@ export default {
this.msgSuccess("删除成功");
})
.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>
</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>
<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
{
/**
* 默认大小 50M
* 默认大小 500M
*/
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
public static final long DEFAULT_MAX_SIZE = 500 * 1024 * 1024;
/**
* 默认的文件名最大长度 100

View File

@ -32,7 +32,9 @@ public class MimeTypeUtils
// 压缩文件
"rar", "zip", "gz", "bz2",
// pdf
"pdf" };
"pdf",
//视频
"mp4"};
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";
}
/**
* 获取视频上传路径
*/
public static String getUploadVideoPath()
{
return getProfile() + "/video";
}
}

View File

@ -48,6 +48,18 @@ public class ByLecturerController extends BaseController
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;
import java.util.Date;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -33,6 +38,7 @@ public class ByTrainVideoController extends BaseController
@Autowired
private IByTrainVideoService byTrainVideoService;
/**
* 查询培训列表
*/
@ -76,6 +82,8 @@ public class ByTrainVideoController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody ByTrainVideo byTrainVideo)
{
byTrainVideo.setCreatetime(new Date());
byTrainVideo.setCreateuserid(SecurityUtils.getLoginUser().getUser().getUserId());
return toAjax(byTrainVideoService.insertByTrainVideo(byTrainVideo));
}

View File

@ -10,42 +10,63 @@ import java.util.Date;
/**
* 培训对象 by_train_video
*
*
* @author tsbz
* @date 2020-05-25
*/
public class ByTrainVideo extends BaseEntity
{
public class ByTrainVideo extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 编号 */
/**
* 编号
*/
private Long id;
/** 培训视频标题 */
/**
* 培训视频标题
*/
@Excel(name = "培训视频标题")
private String title;
/** 简介 */
/**
* 简介
*/
@Excel(name = "简介")
private String information;
/** 讲师 */
/**
* 讲师
*/
@Excel(name = "讲师")
private String lecturer;
private Long lecturer;
/** 视频路径 */
/**
* 讲师
*/
@Excel(name = "讲师")
private String lecturername;
/**
* 视频路径
*/
@Excel(name = "视频路径")
private String videourl;
/** 所属类别 */
/**
* 所属类别
*/
@Excel(name = "所属类别")
private String type;
/** 适用班级 */
/**
* 适用班级
*/
@Excel(name = "适用班级")
private String classtype;
/** 上传人员 */
/**
* 上传人员
*/
@Excel(name = "上传人员")
private Long createuserid;
@ -55,76 +76,75 @@ public class ByTrainVideo extends BaseEntity
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createtime;
public void setId(Long id)
{
public void setId(Long id) {
this.id = id;
}
public Long getId()
{
public Long getId() {
return id;
}
public void setTitle(String title)
{
public void setTitle(String title) {
this.title = title;
}
public String getTitle()
{
public String getTitle() {
return title;
}
public void setInformation(String information)
{
public void setInformation(String information) {
this.information = information;
}
public String getInformation()
{
public String getInformation() {
return information;
}
public void setLecturer(String lecturer)
{
public void setLecturer(Long lecturer) {
this.lecturer = lecturer;
}
public String getLecturer()
{
public Long getLecturer() {
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;
}
public String getVideourl()
{
public String getVideourl() {
return videourl;
}
public void setType(String type)
{
public void setType(String type) {
this.type = type;
}
public String getType()
{
public String getType() {
return type;
}
public void setClasstype(String classtype)
{
public void setClasstype(String classtype) {
this.classtype = classtype;
}
public String getClasstype()
{
public String getClasstype() {
return classtype;
}
public void setCreateuserid(Long createuserid)
{
public void setCreateuserid(Long createuserid) {
this.createuserid = createuserid;
}
public Long getCreateuserid()
{
public Long getCreateuserid() {
return createuserid;
}
@ -138,16 +158,17 @@ public class ByTrainVideo extends BaseEntity
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("title", getTitle())
.append("information", getInformation())
.append("lecturer", getLecturer())
.append("videourl", getVideourl())
.append("type", getType())
.append("classtype", getClasstype())
.append("createuserid", getCreateuserid())
.append("createtime", getCreatetime())
.toString();
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("title", getTitle())
.append("information", getInformation())
.append("lecturer", getLecturer())
.append("lecturername", getLecturername())
.append("videourl", getVideourl())
.append("type", getType())
.append("classtype", getClasstype())
.append("createuserid", getCreateuserid())
.append("createtime", getCreatetime())
.toString();
}
}

View File

@ -1,7 +1,12 @@
package com.ruoyi.project.common;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
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.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,32 +22,40 @@ import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.config.ServerConfig;
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
*/
@RestController
public class CommonController
{
public class CommonController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ServerConfig serverConfig;
@Resource
private FileConfig fileConfig;
@Autowired
private FileConfig constantQiniu;
/**
* 通用下载请求
*
*
* @param fileName 文件名称
* @param delete 是否删除
* @param delete 是否删除
*/
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
try
{
if (!FileUtils.isValidFilename(fileName))
{
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
try {
if (!FileUtils.isValidFilename(fileName)) {
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
@ -53,26 +66,23 @@ public class CommonController
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete)
{
if (delete) {
FileUtils.deleteFile(filePath);
}
}
catch (Exception e)
{
} catch (Exception e) {
log.error("下载文件失败", e);
}
}
/**
* 通用上传请求
*/
@PostMapping("/common/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
try
{
public AjaxResult uploadFile(MultipartFile file) throws Exception {
try {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
System.out.println("path=" + filePath);
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
@ -80,19 +90,57 @@ public class CommonController
ajax.put("fileName", fileName);
ajax.put("url", url);
return ajax;
}
catch (Exception e)
{
} catch (Exception e) {
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")
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();
// 数据库资源地址

View File

@ -138,7 +138,7 @@ public class VelocityUtils
{
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);
}

View File

@ -40,15 +40,15 @@ spring:
messages:
# 国际化资源文件路径
basename: i18n/messages
profiles:
profiles:
active: druid
# 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 10MB
# 设置总上传的文件大小
max-request-size: 20MB
multipart:
# 单个文件大小
max-file-size: 50MB
# 设置总上传的文件大小
max-request-size: 100MB
# 服务模块
devtools:
restart:
@ -61,7 +61,7 @@ spring:
# 端口默认为6379
port: 6379
# 密码
password:
password:
# 连接超时时间
timeout: 10s
lettuce:
@ -77,40 +77,40 @@ spring:
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌秘钥
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期默认30分钟
expireTime: 30
# 令牌自定义标识
header: Authorization
# 令牌秘钥
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期默认30分钟
expireTime: 30
# MyBatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.ruoyi.project.**.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mybatis/**/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# 搜索指定包别名
typeAliasesPackage: com.ruoyi.project.**.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mybatis/**/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
params: count=countSql
# 防止XSS攻击
xss:
xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
excludes: /system/notice/*
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
# 代码生成
gen:
gen:
# 作者
author: tsbz
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
@ -118,4 +118,13 @@ gen:
# 自动去除表前缀默认是true
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="information" column="information" />
<result property="lecturer" column="lecturer" />
<result property="lecturername" column="lecturername" />
<result property="videourl" column="videourl" />
<result property="type" column="type" />
<result property="classtype" column="classtype" />
@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<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>
<select id="selectByTrainVideoList" parameterType="ByTrainVideo" resultMap="ByTrainVideoResult">
@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="title != null and title != ''"> and title = #{title}</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="type != null and type != ''"> and type = #{type}</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=",">
<if test="title != null and title != ''">title,</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="type != null and type != ''">type,</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=",">
<if test="title != null and title != ''">#{title},</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="type != null and type != ''">#{type},</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=",">
<if test="title != null and title != ''">title = #{title},</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="type != null and type != ''">type = #{type},</if>
<if test="classtype != null and classtype != ''">classtype = #{classtype},</if>