|
@@ -11,17 +11,24 @@ import com.fjhx.entity.FileInfo;
|
|
|
import com.fjhx.mapper.FileInfoMapper;
|
|
|
import com.fjhx.params.FileInfoParam;
|
|
|
import com.fjhx.service.FileInfoService;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
import org.springblade.core.launch.BladeApplication;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import ws.schild.jave.MultimediaInfo;
|
|
|
+import ws.schild.jave.MultimediaObject;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -36,7 +43,7 @@ import java.util.stream.Collectors;
|
|
|
public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> implements FileInfoService {
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, String> uploadFile(MultipartFile file) {
|
|
|
+ public FileInfo uploadFile(MultipartFile file) {
|
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
String suffix = FileUtil.getSuffix(fileName);
|
|
@@ -79,18 +86,29 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
FileInfo fileInfo = new FileInfo();
|
|
|
fileInfo.setFileName(fileName);
|
|
|
fileInfo.setFileSuffix(suffix);
|
|
|
- fileInfo.setContentType(file.getContentType());
|
|
|
- fileInfo.setFileSize(file.getSize());
|
|
|
+
|
|
|
+ String contentType = file.getContentType();
|
|
|
+ fileInfo.setContentType(contentType);
|
|
|
+ setDuration(contentType, fileInfo, rootPath + filePath);
|
|
|
+
|
|
|
+ fileInfo.setFileSize(file.getSize() / 1024);
|
|
|
fileInfo.setFilePath(filePath);
|
|
|
save(fileInfo);
|
|
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
+ return fileInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FileInfo> getFileList(Map<String, String> condition) {
|
|
|
+ String businessId = condition.get("businessId");
|
|
|
+ Assert.notEmpty(businessId, "业务id不能为空");
|
|
|
|
|
|
- map.put("fileName", fileName);
|
|
|
- map.put("filePath", filePath);
|
|
|
- map.put("id", fileInfo.getId().toString());
|
|
|
+ String businessType = condition.get("businessType");
|
|
|
|
|
|
- return map;
|
|
|
+ return list(Wrappers.<FileInfo>lambdaQuery()
|
|
|
+ .eq(FileInfo::getBusinessId, businessId)
|
|
|
+ .eq(ObjectUtil.isNotEmpty(businessType), FileInfo::getBusinessType, businessType)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public void bindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
|
|
@@ -117,33 +135,19 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
@Override
|
|
|
public void againBindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfoParam> paramList) {
|
|
|
|
|
|
- // 记录排除编辑的文件id
|
|
|
- List<Long> excludeIdList = new ArrayList<>();
|
|
|
+ if (paramList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // 获取需要添加业务id的文件列表
|
|
|
- List<FileInfo> collect = paramList.stream().filter(fileInfo -> {
|
|
|
- if (ObjectUtil.isNotEmpty(fileInfo.getBusinessId())) {
|
|
|
- excludeIdList.add(fileInfo.getId());
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }).map(item -> {
|
|
|
- FileInfo fileInfo = new FileInfo();
|
|
|
- fileInfo.setId(item.getId());
|
|
|
- fileInfo.setBusinessId(businessId);
|
|
|
- fileInfo.setBusinessType(businessType);
|
|
|
- fileInfo.setApplicationName(applicationName);
|
|
|
- return fileInfo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ bindingFile(applicationName, businessId, businessType, paramList);
|
|
|
+
|
|
|
+ List<Long> id = paramList.stream().map(FileInfoParam::getId).collect(Collectors.toList());
|
|
|
|
|
|
- // 如果排除的id数等于提交文件数,则不执行删除逻辑
|
|
|
- int excludeIdSize = excludeIdList.size();
|
|
|
+ // 删除其他文件
|
|
|
remove(Wrappers.<FileInfo>lambdaQuery()
|
|
|
.eq(FileInfo::getBusinessId, businessId)
|
|
|
.eq(FileInfo::getBusinessType, businessType)
|
|
|
- .notIn(excludeIdSize > 0, BaseEntity::getId, excludeIdSize));
|
|
|
-
|
|
|
- updateBatchById(collect);
|
|
|
+ .notIn(BaseEntity::getId, id));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -158,8 +162,28 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
if (businessIdList.size() == 0) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- List<FileInfo> list = lambdaQuery().in(FileInfo::getBusinessId, businessIdList).list();
|
|
|
+ List<FileInfo> list = lambdaQuery().in(FileInfo::getBusinessId, businessIdList).orderByAsc(FileInfo::getSort).list();
|
|
|
return list.stream().map(item -> BeanUtil.toBean(item, FileInfoParam.class)).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 如果是视频,赋值视频时长
|
|
|
+ */
|
|
|
+ private void setDuration(String contentType, FileInfo fileInfo, String path) {
|
|
|
+ try {
|
|
|
+ if (!contentType.startsWith("video")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+ MultimediaObject instance = new MultimediaObject(file);
|
|
|
+ MultimediaInfo result = instance.getInfo();
|
|
|
+ long s = result.getDuration() / 1000;
|
|
|
+ fileInfo.setDuration(s);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("获取视频时长失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|