添加排序问题
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cms.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.common.core.domain.entity.FileJobUpload;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,4 +27,6 @@ public interface FileJobUploadMapper extends BaseMapper<FileJobUpload>
|
||||
public List<FileJobUpload> selectFileListByBussinessIds(@Param("longs") List<Long> longs);
|
||||
|
||||
public int updateIds(@Param("longs") List<Long> longs,@Param("newBussinessid") Long bussinessid);
|
||||
|
||||
Integer selectMaxSortNum();
|
||||
}
|
||||
|
||||
@@ -39,14 +39,6 @@ public interface IFileJobUploadService
|
||||
*/
|
||||
public int insertFile(FileJobUpload file);
|
||||
|
||||
/**
|
||||
* 修改文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateFile(FileJobUpload file);
|
||||
|
||||
/**
|
||||
* 批量删除文件
|
||||
*
|
||||
@@ -56,6 +48,4 @@ public interface IFileJobUploadService
|
||||
public int deleteFileByIds(Long[] ids);
|
||||
|
||||
AjaxResult upload(MultipartFile file,HttpServletRequest request);
|
||||
|
||||
AjaxResult uploadFile(MultipartFile file, HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -69,18 +69,6 @@ public class FileJobUploadServiceImpl extends ServiceImpl<FileJobUploadMapper, F
|
||||
return fileJobUploadMapper.insert(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateFile(FileJobUpload file)
|
||||
{
|
||||
return fileJobUploadMapper.updateById(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件
|
||||
*
|
||||
@@ -124,8 +112,13 @@ public class FileJobUploadServiceImpl extends ServiceImpl<FileJobUploadMapper, F
|
||||
destFile.setWritable(false); // 禁止写入
|
||||
destFile.setExecutable(false);
|
||||
|
||||
FileJobUpload fileJobUpload=new FileJobUpload();
|
||||
fileJobUpload.setFileName(fileName);
|
||||
fileJobUpload.setFileUrl(StringUtil.getVedioFilePath(request)+fileName);
|
||||
Integer sortNum=fileJobUploadMapper.selectMaxSortNum();
|
||||
fileJobUpload.setSortNum(sortNum);
|
||||
// 保存文件信息到数据库
|
||||
saveFileInfo(StringUtil.getVedioFilePath(request)+fileName);
|
||||
saveFileInfo(fileJobUpload);
|
||||
|
||||
return AjaxResult.success(StringUtil.PATH_PROXY_50+fileName);
|
||||
} catch (IOException e) {
|
||||
@@ -134,58 +127,8 @@ public class FileJobUploadServiceImpl extends ServiceImpl<FileJobUploadMapper, F
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加返回bussinessid的接口,新增时使用
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult uploadFile(MultipartFile file, HttpServletRequest request) {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("文件为空,请选择文件上传");
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建上传目录
|
||||
java.io.File dir = new java.io.File(uploadDir).getCanonicalFile();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
// 生成唯一的文件名
|
||||
String fileName = UUID.randomUUID().toString() + "_" + file.getOriginalFilename();
|
||||
|
||||
Path basePath = Paths.get(getCanonicalPath(uploadDir)).normalize();
|
||||
Path filePath = basePath.resolve(fileName).normalize();
|
||||
|
||||
if (!filePath.startsWith(basePath)) {
|
||||
throw new SecurityException("非法路径,禁止访问");
|
||||
}
|
||||
|
||||
// 保存文件到服务器
|
||||
Files.copy(file.getInputStream(), filePath);
|
||||
|
||||
java.io.File destFile = filePath.toFile();
|
||||
destFile.setReadable(true, false); // 所有用户可读
|
||||
destFile.setWritable(false); // 禁止写入
|
||||
destFile.setExecutable(false);
|
||||
|
||||
// 保存文件信息到数据库
|
||||
FileJobUpload svFile=saveFileInfo(fileName);
|
||||
AjaxResult ajaxResult=AjaxResult.success();
|
||||
ajaxResult.put("filePath", StringUtil.getFilePath(request)+fileName);
|
||||
ajaxResult.put("id",String.valueOf(svFile.getId()));
|
||||
return ajaxResult;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("文件上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
private FileJobUpload saveFileInfo(String fileName) {
|
||||
private FileJobUpload saveFileInfo(FileJobUpload file) {
|
||||
// 这里假设你已经有了一个FileService来处理数据库操作
|
||||
FileJobUpload file = new FileJobUpload();
|
||||
file.setFileUrl(fileName);
|
||||
this.save(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user