Commit 1d61a0c6 authored by yanzg's avatar yanzg

下载视频

parent 626ac2f9
package com.yanzuoguang.cloud.file;
import com.yanzuoguang.cloud.vo.req.YzgFileCallbackReqVo;
import com.yanzuoguang.cloud.vo.req.YzgFileStatusReqVo;
import com.yanzuoguang.mq.service.MqService;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.mq.vo.QueueVo;
......@@ -14,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 删除目录
......@@ -27,10 +31,15 @@ public class YzgFileProcedure implements InitializingBean {
public static final String YZG_MOVE_FILE = "YZG_MOVE_FILE";
public static final String YZG_CONVERT_IMAGE = "YZG_CONVERT_IMAGE";
public static final String YZG_CONVERT_VIDEO = "YZG_CONVERT_VIDEO";
public static final String YZG_FILE_CREATE_DELAY = "YZG_FILE_CREATE_DELAY";
public static final int YZG_FILE_CREATE_DELAY_TIME = 15 * 1000;
public static final String YZG_FILE_CREATE = "YZG_FILE_CREATE";
public static final String YZG_FILE_STATUS = "YZG_FILE_STATUS";
/**
* 缓存24小时
*/
private MemoryCache<Boolean> folderCache = new MemoryCache<>(24 * 60 * 60);
private Map<String, Boolean> mapCallbackMQ = new HashMap<>();
@Autowired
private MqService mqService;
......@@ -51,6 +60,8 @@ public class YzgFileProcedure implements InitializingBean {
mqService.createQueue(new QueueVo(YZG_MOVE_FILE));
mqService.createQueue(new QueueVo(YZG_CONVERT_IMAGE));
mqService.createQueue(new QueueVo(YZG_CONVERT_VIDEO));
mqService.createQueue(new QueueVo(YZG_FILE_CREATE_DELAY, YZG_FILE_CREATE_DELAY_TIME, YZG_FILE_CREATE));
mqService.createQueue(new QueueVo(YZG_FILE_STATUS));
}
/**
......@@ -132,4 +143,72 @@ public class YzgFileProcedure implements InitializingBean {
public void convertVideo(String json, int dedTime) {
mqService.message(new MessageVo(YZG_CONVERT_VIDEO, json, dedTime));
}
/**
* 生成导出文件任务
*
* @param req
*/
public void fileCreate(YzgFileStatusReqVo req) {
fileCreate(JsonHelper.serialize(req));
}
/**
* 生成导出文件任务
*
* @param json
*/
public void fileCreate(String json) {
mqService.message(new MessageVo(YZG_FILE_CREATE, json, 0));
}
/**
* 生成导出文件任务,等待15秒后再次调用
*
* @param json
*/
public void fileCreateDelay(String json) {
mqService.message(new MessageVo(YZG_FILE_CREATE_DELAY, json, 0));
}
/**
* 写入导出文件状态
*
* @param req
*/
public void fileStatus(YzgFileStatusReqVo req) {
fileStatus(JsonHelper.serialize(req));
}
/**
* 写入导出文件状态
*
* @param json
*/
public void fileStatus(String json) {
mqService.message(new MessageVo(YZG_FILE_STATUS, json, 0));
}
/**
* 调用回调导出服务任务
*
* @param req
*/
public void fileCallback(YzgFileCallbackReqVo req) {
if (StringHelper.isEmpty(req.getFileId(), req.getCallbackMQ(), req.getFileServerPath())) {
return;
}
boolean isCreateCallback = mapCallbackMQ.getOrDefault(req.getCallbackMQ(), false);
if (!isCreateCallback) {
synchronized (mapCallbackMQ) {
isCreateCallback = mapCallbackMQ.getOrDefault(req.getCallbackMQ(), false);
if (!isCreateCallback) {
mqService.createQueue(new QueueVo(req.getCallbackMQ()));
mapCallbackMQ.put(req.getCallbackMQ(), true);
}
}
}
String json = JsonHelper.serialize(req);
mqService.message(new MessageVo(req.getCallbackMQ(), json, 0));
}
}
package com.yanzuoguang.cloud.vo;
import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.BaseVo;
import com.yanzuoguang.util.vo.InitDao;
import io.swagger.annotations.ApiModelProperty;
/**
* 生成Excel文件
*
* @author 颜佐光
*/
@TableAnnotation("yzg_file")
public class YzgFileVo extends BaseVo implements InitDao {
/**
* 文件下载状态:0-等待生成,1-正在生成,2-生成完成,3-生成失败,具体原因查看错误消息
*/
@ApiModelProperty(notes = "文件下载名,用于显示", position = 10)
public static final int FILE_STATUS_INIT = 0;
public static final int FILE_STATUS_RELEASE = 1;
public static final int FILE_STATUS_OK = 2;
public static final int FILE_STATUS_ERROR = 3;
/**
* 文件Id,用于后续文件下载
*/
@ApiModelProperty(notes = "文件Id,用于后续文件下载", position = 10)
private String fileId;
/**
* 公司Id,用于判断每个公司同一个人不能生成多次文件,同一个公司Id需要配置每日最大运行次数,默认每日为50
*/
@ApiModelProperty(notes = "公司Id,用于后续文件下载,同一个公司Id需要配置每日最大运行次数,默认为50", position = 20)
private String companyId;
/**
* 功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ
*/
@ApiModelProperty(notes = "功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ", position = 30)
private String callbackMQ;
/**
* 公司名称,用于对公司Id的说明
*/
@ApiModelProperty(notes = "回调参数字符串,最好是json", position = 40)
private String callbackParameter;
/**
* 文件下载名,用于显示
*/
@ApiModelProperty(notes = "文件下载名,用于显示", position = 50)
private String fileName;
/**
* 文件下载状态:0-等待生成,1-正在生成,2-生成完成,3-生成失败,具体原因查看错误消息
*/
@ApiModelProperty(notes = "文件下载名,用于显示", position = 60)
private Integer fileStatus;
/**
* 文件导出行数,用于显示
*/
@ApiModelProperty(notes = "文件导出行数,用于显示", position = 70)
private Integer fileRow;
/**
* 错误消息
*/
@ApiModelProperty(notes = "错误消息", position = 80)
private String errorMessage;
/**
* 下载时间
*/
@ApiModelProperty(notes = "下载时间", position = 90)
private String downloadDate;
/**
* 下载人
*/
@ApiModelProperty(notes = "下载人", position = 100)
private String downloadUserId;
/**
* 创建时间
*/
@ApiModelProperty(notes = "创建时间", position = 110)
private String createDate;
/**
* 创建人
*/
@ApiModelProperty(notes = "创建人", position = 120)
private String createUserId;
/**
* 初始化数据,去掉空值
*/
@Override
public void init() {
this.fileId = StringHelper.getFirst(this.fileId);
this.companyId = StringHelper.getFirst(this.companyId);
this.callbackMQ = StringHelper.getFirst(this.callbackMQ);
this.callbackParameter = StringHelper.getFirst(this.callbackParameter);
this.fileName = StringHelper.getFirst(this.fileName);
this.fileStatus = StringHelper.getFirst(this.fileStatus);
this.fileRow = StringHelper.getFirst(this.fileRow);
this.errorMessage = StringHelper.getFirst(this.errorMessage);
this.downloadDate = StringHelper.getFirst(this.downloadDate);
this.downloadUserId = StringHelper.getFirst(this.downloadUserId);
this.createDate = StringHelper.getFirst(this.createDate, DateHelper.getNow());
this.createUserId = StringHelper.getFirst(this.createUserId);
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public String getCallbackMQ() {
return callbackMQ;
}
public void setCallbackMQ(String callbackMQ) {
this.callbackMQ = callbackMQ;
}
public String getCallbackParameter() {
return callbackParameter;
}
public void setCallbackParameter(String callbackParameter) {
this.callbackParameter = callbackParameter;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Integer getFileStatus() {
return fileStatus;
}
public void setFileStatus(Integer fileStatus) {
this.fileStatus = fileStatus;
}
public Integer getFileRow() {
return fileRow;
}
public void setFileRow(Integer fileRow) {
this.fileRow = fileRow;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getDownloadDate() {
return downloadDate;
}
public void setDownloadDate(String downloadDate) {
this.downloadDate = downloadDate;
}
public String getDownloadUserId() {
return downloadUserId;
}
public void setDownloadUserId(String downloadUserId) {
this.downloadUserId = downloadUserId;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public String getCreateUserId() {
return createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
}
package com.yanzuoguang.cloud.vo.req;
import com.yanzuoguang.util.vo.BaseVo;
import io.swagger.annotations.ApiModelProperty;
/**
* 生成Excel文件回调MQ
*
* @author 颜佐光
*/
public class YzgFileCallbackReqVo extends BaseVo {
/**
* 文件Id,用于后续文件下载
*/
@ApiModelProperty(notes = "文件Id,用于后续文件下载", position = 10)
private String fileId;
/**
* 功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ
*/
@ApiModelProperty(notes = "功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ", position = 30)
private String callbackMQ;
/**
* 公司名称,用于对公司Id的说明
*/
@ApiModelProperty(notes = "回调参数字符串,最好是json", position = 30)
private String callbackParameter;
/**
* 服务器路径
*/
@ApiModelProperty(notes = "服务器路径", position = 40)
private String fileServerPath;
public YzgFileCallbackReqVo() {
}
public YzgFileCallbackReqVo(String fileId, String callbackMQ, String callbackParameter, String fileServerPath) {
this.fileId = fileId;
this.callbackMQ = callbackMQ;
this.callbackParameter = callbackParameter;
this.fileServerPath = fileServerPath;
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getCallbackMQ() {
return callbackMQ;
}
public void setCallbackMQ(String callbackMQ) {
this.callbackMQ = callbackMQ;
}
public String getCallbackParameter() {
return callbackParameter;
}
public void setCallbackParameter(String callbackParameter) {
this.callbackParameter = callbackParameter;
}
public String getFileServerPath() {
return fileServerPath;
}
public void setFileServerPath(String fileServerPath) {
this.fileServerPath = fileServerPath;
}
}
package com.yanzuoguang.cloud.vo.req;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.BaseVo;
import com.yanzuoguang.util.vo.InitDao;
import io.swagger.annotations.ApiModelProperty;
/**
* 生成Excel文件
*
* @author 颜佐光
*/
public class YzgFileCreateReqVo extends BaseVo implements InitDao {
/**
* 文件Id,用于后续文件下载
*/
@ApiModelProperty(notes = "文件Id,用于后续文件下载", position = 10)
private String fileId;
/**
* 公司Id,用于判断每个公司同一个人不能生成多次文件,同一个公司Id需要配置每日最大运行次数,默认每日为50
*/
@ApiModelProperty(notes = "公司Id,用于后续文件下载,同一个公司Id需要配置每日最大运行次数,默认为50", position = 20)
private String companyId;
/**
* 功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ
*/
@ApiModelProperty(notes = "功能点关键字,同一个callbackMQ需要设置最大执行次数,回调MQ", position = 30)
private String callbackMQ;
/**
* 公司名称,用于对公司Id的说明
*/
@ApiModelProperty(notes = "回调参数字符串,最好是json", position = 40)
private String callbackParameter;
/**
* 同一个MQ的最大次数
*/
@ApiModelProperty(notes = "同一个MQ的最大次数", position = 50)
private int callBackMax;
/**
* 文件下载名,用于显示
*/
@ApiModelProperty(notes = "文件下载名,用于显示", position = 60)
private String fileName;
/**
* 创建时间
*/
@ApiModelProperty(notes = "创建时间", position = 70)
private String createDate;
/**
* 创建人
*/
@ApiModelProperty(notes = "创建人", position = 80)
private String createUserId;
/**
* 同一个用户和公司的每日最大次数
*/
@ApiModelProperty(notes = "同一个用户和公司的每日最大次数", position = 90)
private int createUserCompanyMax;
/**
* 初始化数据,去掉空值
*/
@Override
public void init() {
this.fileId = StringHelper.getFirst(this.fileId, StringHelper.getNewID());
this.companyId = StringHelper.getFirst(this.companyId);
this.callbackMQ = StringHelper.getFirst(this.callbackMQ);
this.callbackParameter = StringHelper.getFirst(this.callbackParameter);
this.callBackMax = StringHelper.getFirst(this.callBackMax, 3);
this.fileName = StringHelper.getFirst(this.fileName);
this.createDate = StringHelper.getFirst(this.createDate, DateHelper.getNow());
this.createUserId = StringHelper.getFirst(this.createUserId);
this.createUserCompanyMax = StringHelper.getFirst(this.createUserCompanyMax, 50);
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public String getCallbackMQ() {
return callbackMQ;
}
public void setCallbackMQ(String callbackMQ) {
this.callbackMQ = callbackMQ;
}
public String getCallbackParameter() {
return callbackParameter;
}
public void setCallbackParameter(String callbackParameter) {
this.callbackParameter = callbackParameter;
}
public int getCallBackMax() {
return callBackMax;
}
public void setCallBackMax(int callBackMax) {
this.callBackMax = callBackMax;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
public String getCreateUserId() {
return createUserId;
}
public void setCreateUserId(String createUserId) {
this.createUserId = createUserId;
}
public int getCreateUserCompanyMax() {
return createUserCompanyMax;
}
public void setCreateUserCompanyMax(int createUserCompanyMax) {
this.createUserCompanyMax = createUserCompanyMax;
}
}
package com.yanzuoguang.cloud.vo.req;
import com.yanzuoguang.cloud.vo.YzgFileVo;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.BaseVo;
import com.yanzuoguang.util.vo.InitDao;
import io.swagger.annotations.ApiModelProperty;
/**
* 生成Excel文件
*
* @author 颜佐光
*/
public class YzgFileStatusReqVo extends BaseVo implements InitDao {
/**
* 文件Id,用于后续文件下载
*/
@ApiModelProperty(notes = "文件Id,用于后续文件下载", position = 10)
private String fileId;
/**
* 公司Id,用于判断每个公司同一个人不能生成多次文件,同一个公司Id需要配置每日最大运行次数,默认每日为50
*/
@ApiModelProperty(notes = "公司Id,用于后续文件下载,同一个公司Id需要配置每日最大运行次数,默认为50", position = 20)
private String companyId;
/**
* 文件下载状态:0-等待生成,1-正在生成,2-生成完成,3-生成失败,具体原因查看错误消息
*/
@ApiModelProperty(notes = "文件下载名,用于显示", position = 30)
private int fileStatus;
/**
* 文件导出行数,用于显示
*/
@ApiModelProperty(notes = "文件导出行数,用于显示", position = 40)
private int fileRow;
/**
* 错误消息
*/
@ApiModelProperty(notes = "错误消息", position = 50)
private String errorMessage;
/**
* 初始化数据,去掉空值
*/
@Override
public void init() {
this.fileId = StringHelper.getFirst(this.fileId, StringHelper.getNewID());
this.companyId = StringHelper.getFirst(this.companyId);
this.fileStatus = StringHelper.getFirst(this.fileStatus);
this.errorMessage = StringHelper.getFirst(this.errorMessage);
}
public YzgFileStatusReqVo() {
}
public YzgFileStatusReqVo(String fileId, String companyId) {
this.fileId = fileId;
this.companyId = companyId;
this.fileStatus = YzgFileVo.FILE_STATUS_OK;
}
public YzgFileStatusReqVo(String fileId, String companyId, int fileRow) {
this.fileId = fileId;
this.companyId = companyId;
this.fileStatus = YzgFileVo.FILE_STATUS_RELEASE;
this.fileRow = fileRow;
}
public YzgFileStatusReqVo(String fileId, String companyId, String errorMessage) {
this.fileId = fileId;
this.companyId = companyId;
this.fileStatus = YzgFileVo.FILE_STATUS_ERROR;
this.errorMessage = errorMessage;
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId;
}
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public int getFileStatus() {
return fileStatus;
}
public void setFileStatus(int fileStatus) {
this.fileStatus = fileStatus;
}
public int getFileRow() {
return fileRow;
}
public void setFileRow(int fileRow) {
this.fileRow = fileRow;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment