|
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.file.mapper.FileSequenceMapper;
|
|
|
import com.ruoyi.file.mapper.FilesMapper;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.system.model.LoginUser;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -18,7 +20,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
@Service
|
|
|
-public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements FilesService {
|
|
|
+public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> implements FilesService {
|
|
|
@Value("${file.path}")
|
|
|
private String filesUploadPath;
|
|
|
|
|
@@ -35,6 +37,11 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
@Override
|
|
|
public FileUploadResponse upload(MultipartFile file) {
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ String userName = SecurityUtils.getUsername();
|
|
|
+ System.out.println("当前登录用户昵称:" + userName);
|
|
|
+
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
|
@@ -74,7 +81,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
String url = filesUploadDomain + filesPrefix + "/" + yearMonth + "/" + fileUuid;
|
|
|
|
|
|
|
|
|
- Files saveFile = new Files();
|
|
|
+ FilesUpload saveFile = new FilesUpload();
|
|
|
saveFile.setFilesName(originalFilename);
|
|
|
saveFile.setName(fileUuid);
|
|
|
saveFile.setPath(destPath);
|
|
@@ -83,7 +90,9 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
saveFile.setUrl(url);
|
|
|
saveFile.setEnable(true);
|
|
|
saveFile.setIsDelete(0);
|
|
|
+ saveFile.setCreateBy(userName);
|
|
|
saveFile.setCreateTime(LocalDateTime.now());
|
|
|
+ saveFile.setUpdateBy(null);
|
|
|
saveFile.setUpdateTime(null);
|
|
|
|
|
|
save(saveFile);
|
|
@@ -164,7 +173,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
try {
|
|
|
|
|
|
|
|
|
- Files file = getOne(new QueryWrapper<Files>().eq("name", filesUUID));
|
|
|
+ FilesUpload file = getOne(new QueryWrapper<FilesUpload>().eq("name", filesUUID));
|
|
|
|
|
|
if (file == null) {
|
|
|
throw new RuntimeException("文件不存在,无法删除");
|
|
@@ -180,7 +189,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
}
|
|
|
|
|
|
|
|
|
- Files updateFile = new Files();
|
|
|
+ FilesUpload updateFile = new FilesUpload();
|
|
|
updateFile.setId(file.getId());
|
|
|
updateFile.setFilesName(file.getFilesName());
|
|
|
updateFile.setName(file.getName());
|
|
@@ -190,7 +199,9 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
updateFile.setUrl(file.getUrl());
|
|
|
updateFile.setEnable(false);
|
|
|
updateFile.setIsDelete(1);
|
|
|
+ updateFile.setCreateBy(file.getCreateBy());
|
|
|
updateFile.setCreateTime(file.getCreateTime());
|
|
|
+ updateFile.setUpdateBy(file.getUpdateBy());
|
|
|
updateFile.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
@@ -201,8 +212,8 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<Files> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, Page<Files> page) {
|
|
|
- QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
|
|
|
+ public Page<FilesUpload> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, Page<FilesUpload> page) {
|
|
|
+ QueryWrapper<FilesUpload> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
|
|
|
|
if (isDeleted == null) {
|
|
@@ -230,4 +241,15 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|
|
|
|
|
return page(page, queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ private String getUserNameFromSecurityContext() {
|
|
|
+ try {
|
|
|
+ return SecurityUtils.getUsername();
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ log.error("无法获取用户信息");
|
|
|
+ System.out.println("无法获取用户信息");
|
|
|
+ return "未知用户";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|