Commit 8a933c23 by xmh

运维服务:

1. <feat> 可以一次上传多个录像文件
1 parent c8aa9e36
......@@ -8,13 +8,13 @@ package com.viontech.fanxing.commons.constant;
*/
public enum TaskStatus {
/** 未部署 */
AWAIT(0),
/** 运行中 */
RUNNING(1),
/** 暂停 */
PAUSE(2),
/** 等待执行 */
AWAIT(0),
/** 资源不足 */
/** 无法运行 */
CAN_NOT_RUN(4);
public int val;
......
......@@ -8,7 +8,6 @@ import java.util.List;
public class ChannelVo extends ChannelVoBase {
private MultipartFile file;
private Boolean tree;
public ChannelVo() {
......@@ -27,13 +26,4 @@ public class ChannelVo extends ChannelVoBase {
this.tree = tree;
return this;
}
public MultipartFile getFile() {
return file;
}
public ChannelVo setFile(MultipartFile file) {
this.file = file;
return this;
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
......@@ -87,8 +88,8 @@ public class ChannelController extends ChannelBaseController {
}
@PostMapping("/video/upload")
public Object uploadVideo(ChannelVo channelVo) {
Channel channel = channelService.uploadVideo(channelVo);
return JsonMessageUtil.getSuccessJsonMsg(channel);
public Object uploadVideo(@RequestParam List<MultipartFile> files, @RequestParam(required = false) List<Long> tags) {
channelService.uploadVideo(files, tags);
return JsonMessageUtil.getSuccessJsonMsg("success");
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -14,6 +15,6 @@ public interface ChannelService extends BaseService<Channel> {
List<DictCodeVo> channelOrg(List<Channel> channels);
Channel uploadVideo(ChannelVo channelVo);
void uploadVideo(List<MultipartFile> files, List<Long> tags);
}
\ No newline at end of file
......@@ -182,48 +182,45 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Channel uploadVideo(ChannelVo channelVo) {
MultipartFile file = channelVo.getFile();
String originalFilename = file.getOriginalFilename();
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
String extension = FilenameUtils.getExtension(originalFilename);
if (StringUtils.isBlank(extension) || !vionConfig.getSupportedVideoFormats().contains(extension.toLowerCase())) {
throw new FanXingException("不支持的视频格式:" + extension);
}
String unid = UUID.randomUUID().toString();
String filename = unid + "." + extension;
File video = new File(basePath + filename);
video.getParentFile().mkdirs();
try {
FileUtils.copyToFile(file.getInputStream(), video);
} catch (IOException e) {
throw new RuntimeException(e);
}
public void uploadVideo(List<MultipartFile> files, List<Long> tags) {
for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename();
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
String extension = FilenameUtils.getExtension(originalFilename);
if (StringUtils.isBlank(extension) || !vionConfig.getSupportedVideoFormats().contains(extension.toLowerCase())) {
throw new FanXingException("不支持的视频格式:" + extension);
}
String unid = UUID.randomUUID().toString();
String filename = unid + "." + extension;
File video = new File(basePath + filename);
video.getParentFile().mkdirs();
try {
FileUtils.copyToFile(file.getInputStream(), video);
} catch (IOException e) {
throw new RuntimeException(e);
}
long videoLength = video.length();
long mbSize = videoLength / 1024 / 1024;
List<Long> tags = channelVo.getTags();
channelVo.setUnid(unid);
channelVo.setChannelUnid(unid);
channelVo.setDeviceUnid(unid);
channelVo.setName(originalFilename);
channelVo.setStreamPath(video.getPath());
channelVo.setType(ChannelType.FILE.value);
channelVo.setStreamType(ChannelType.STREAM_FILE.value);
channelVo.setPort(Math.toIntExact(mbSize));
Channel channel = this.insertSelective(channelVo);
channel = selectByPrimaryKey(channel.getId());
channelVo = new ChannelVo(channel);
channelVo.setTags(tags);
if (tags != null && tags.size() > 0) {
for (Long tagId : tags) {
ChannelTag channelTag = new ChannelTag();
channelTag.setChannelId(channel.getId());
channelTag.setTagId(tagId);
channelTagService.insertSelective(channelTag);
long videoLength = video.length();
long mbSize = videoLength / 1024 / 1024;
Channel channel = new Channel();
channel.setUnid(unid);
channel.setChannelUnid(unid);
channel.setDeviceUnid(unid);
channel.setName(originalFilename);
channel.setStreamPath(video.getPath());
channel.setType(ChannelType.FILE.value);
channel.setStreamType(ChannelType.STREAM_FILE.value);
channel.setPort(Math.toIntExact(mbSize));
channel = this.insertSelective(channel);
if (tags != null && tags.size() > 0) {
for (Long tagId : tags) {
ChannelTag channelTag = new ChannelTag();
channelTag.setChannelId(channel.getId());
channelTag.setTagId(tagId);
channelTagService.insertSelective(channelTag);
}
}
}
return channelVo;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!