合并最新代码
This commit is contained in:
commit
4f7d53aba7
|
@ -25,7 +25,7 @@ public class BusinessDataEntity {
|
||||||
// 父级文件夹
|
// 父级文件夹
|
||||||
private Long parentId = null;
|
private Long parentId = null;
|
||||||
// 创建人
|
// 创建人
|
||||||
private Long creatorId = null;
|
private String creatorId = null;
|
||||||
// 创建时间
|
// 创建时间
|
||||||
private LocalDateTime createTime = null;
|
private LocalDateTime createTime = null;
|
||||||
// 更新时间
|
// 更新时间
|
||||||
|
|
|
@ -30,8 +30,10 @@ public class BusinessDataFileEntity {
|
||||||
//上传时间
|
//上传时间
|
||||||
private Date uploadTime = null;
|
private Date uploadTime = null;
|
||||||
//上传人id
|
//上传人id
|
||||||
private Long uploaderId = null;
|
private String uploaderId = null;
|
||||||
//是否删除
|
//是否删除
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
// //有效日期
|
||||||
|
// private Date validDate = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
package com.dite.znpt.mapper;
|
package com.dite.znpt.mapper;
|
||||||
|
|
||||||
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
||||||
|
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ApiOperation("商务资料文件对象")
|
@ApiOperation("商务资料文件对象")
|
||||||
|
@Mapper
|
||||||
public interface BusinessDataFileMapper {
|
public interface BusinessDataFileMapper {
|
||||||
|
|
||||||
|
// 新增文件预览方法
|
||||||
|
|
||||||
|
|
||||||
public List<BusinessDataFileEntity> List(@Param("folderId") Long folderId, @Param("fileName") String fileName);
|
public List<BusinessDataFileEntity> List(@Param("folderId") Long folderId, @Param("fileName") String fileName);
|
||||||
void delete(@Param("fileId") Long fileId,@Param("folderId") Long folderId);
|
void delete(@Param("fileId") Long fileId,@Param("folderId") Long folderId);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package com.dite.znpt.mapper;
|
package com.dite.znpt.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.injector.methods.SelectList;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +16,7 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("商务资料文件夹对象")
|
@ApiOperation("商务资料文件夹对象")
|
||||||
|
@Mapper
|
||||||
public interface BusinessDataMapper {
|
public interface BusinessDataMapper {
|
||||||
public String getPath(Long parentId);
|
public String getPath(Long parentId);
|
||||||
|
|
||||||
|
|
|
@ -6,22 +6,36 @@ import com.dite.znpt.domain.page.PageBean;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@ApiOperation("商务资料文件service")
|
@ApiOperation("商务资料文件service")
|
||||||
@Service
|
@Service
|
||||||
public interface BusinessDataFileService {
|
public interface BusinessDataFileService {
|
||||||
|
|
||||||
|
@ApiOperation("分页查询文件")
|
||||||
PageBean pageSelect(Integer page, Integer pageSize, Long folderId, String fileName);
|
PageBean pageSelect(Integer page, Integer pageSize, Long folderId, String fileName);
|
||||||
|
|
||||||
|
@ApiOperation("删除文件")
|
||||||
Result delete(@RequestParam(value = "fileId", required = false) Long fileId,@RequestParam(value = "foldelId", required = false) Long folderId);
|
Result delete(@RequestParam(value = "fileId", required = false) Long fileId,@RequestParam(value = "foldelId", required = false) Long folderId);
|
||||||
|
|
||||||
|
@ApiOperation("增加数据库文件信息")
|
||||||
void add(BusinessDataFileEntity businessDataFileEntity);
|
void add(BusinessDataFileEntity businessDataFileEntity);
|
||||||
|
|
||||||
|
@ApiOperation("获取文件路径")
|
||||||
String getPath(Long fileId);
|
String getPath(Long fileId);
|
||||||
|
|
||||||
|
@ApiOperation("删除文件")
|
||||||
// 在接口中添加重命名方法
|
// 在接口中添加重命名方法
|
||||||
Result reName(Long fileId, String newFileName);
|
Result reName(Long fileId, String newFileName);
|
||||||
|
|
||||||
// 在接口中添加预览方法
|
@ApiOperation("下载文件")
|
||||||
// Result preview(Long fileId, HttpServletResponse response);
|
void upload(Long fileId, HttpServletResponse response);
|
||||||
|
|
||||||
|
@ApiOperation("上传文件")
|
||||||
|
Result addfile(MultipartFile file, Long folderId);
|
||||||
|
|
||||||
|
@ApiOperation("预览文件")
|
||||||
|
void preview(Long fileId, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@ApiOperation("商务资料文件夹service")
|
@ApiOperation("商务资料文件夹service")
|
||||||
public interface BusinessDataService {
|
public interface BusinessDataService {
|
||||||
|
|
||||||
|
@ -12,4 +14,5 @@ public interface BusinessDataService {
|
||||||
String getPath(Long parentId);
|
String getPath(Long parentId);
|
||||||
Result delete(Long folderId);
|
Result delete(Long folderId);
|
||||||
Result reName(Long folderId, String newName);
|
Result reName(Long folderId, String newName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,42 @@
|
||||||
package com.dite.znpt.service.impl;
|
package com.dite.znpt.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
//
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
import com.dite.znpt.mapper.BusinessDataFileMapper;
|
import com.dite.znpt.mapper.BusinessDataFileMapper;
|
||||||
|
import com.dite.znpt.mapper.BusinessDataMapper;
|
||||||
import com.dite.znpt.service.BusinessDataFileService;
|
import com.dite.znpt.service.BusinessDataFileService;
|
||||||
|
import com.dite.znpt.service.BusinessDataService;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static jodd.io.FileUtil.deleteFile;
|
import static jodd.io.FileUtil.deleteFile;
|
||||||
|
@ -27,6 +48,8 @@ import static org.apache.tomcat.util.http.fileupload.FileUtils.deleteDirectory;
|
||||||
public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
@Resource
|
@Resource
|
||||||
private BusinessDataFileMapper businessDataFileMapper;
|
private BusinessDataFileMapper businessDataFileMapper;
|
||||||
|
@Resource
|
||||||
|
private BusinessDataService businessDataService;
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("分页查询文件")
|
@ApiOperation("分页查询文件")
|
||||||
|
@ -43,9 +66,7 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
//删除数据库数据
|
//删除数据库数据
|
||||||
if (folderId != null){
|
if (folderId != null){
|
||||||
businessDataFileMapper.delete(null,folderId);
|
businessDataFileMapper.delete(null,folderId);
|
||||||
System.out.println("888888888走对了");
|
return Result.okM("删除成功");
|
||||||
|
|
||||||
return Result.okM("删除,走对了,成功");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文件
|
//删除文件
|
||||||
|
@ -76,8 +97,6 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("增加文件")
|
@ApiOperation("增加文件")
|
||||||
|
@ -158,6 +177,354 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("下载文件")
|
||||||
|
@Override
|
||||||
|
public void upload(Long fileId, HttpServletResponse response) {
|
||||||
|
String path = getPath(fileId);
|
||||||
|
try {
|
||||||
|
// path是指想要下载的文件的路径
|
||||||
|
File file = new File(path);
|
||||||
|
// 获取文件名
|
||||||
|
String filename = file.getName();
|
||||||
|
// 获取文件后缀名
|
||||||
|
String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
|
||||||
|
// 将文件写入输入流
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(file);
|
||||||
|
InputStream fis = new BufferedInputStream(fileInputStream);
|
||||||
|
byte[] buffer = new byte[fis.available()];
|
||||||
|
fis.read(buffer);
|
||||||
|
fis.close();
|
||||||
|
|
||||||
|
// 清空response
|
||||||
|
response.reset();
|
||||||
|
// 设置response的Header
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
|
||||||
|
// 告知浏览器文件的大小
|
||||||
|
response.addHeader("Content-Length", "" + file.length());
|
||||||
|
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
outputStream.write(buffer);
|
||||||
|
outputStream.flush();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("上传文件")
|
||||||
|
@Override
|
||||||
|
public Result addfile(MultipartFile file, Long folderId) {
|
||||||
|
String loginIdAsLong = "未登录用户";
|
||||||
|
if(StpUtil.isLogin()){
|
||||||
|
loginIdAsLong = StpUtil.getLoginIdAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
return Result.error("上传文件为空");
|
||||||
|
}
|
||||||
|
// TODO 以后可以优化,就算文件名一样,加个(1),(2)这种
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] bytes = file.getBytes();
|
||||||
|
String uploadDir = businessDataService.getPath(folderId);
|
||||||
|
|
||||||
|
File uploadedFile = new File(uploadDir + "\\" + file.getOriginalFilename());
|
||||||
|
if (uploadedFile.exists()) {
|
||||||
|
return Result.error("文件已存在");
|
||||||
|
}
|
||||||
|
file.transferTo(uploadedFile);
|
||||||
|
|
||||||
|
// 保存文件信息到数据
|
||||||
|
BusinessDataFileEntity fileEntity = new BusinessDataFileEntity();
|
||||||
|
fileEntity.setFolderId(folderId);
|
||||||
|
fileEntity.setFileName(file.getOriginalFilename());
|
||||||
|
fileEntity.setFilePath(uploadDir + "\\" + file.getOriginalFilename());
|
||||||
|
fileEntity.setFileType(file.getContentType());
|
||||||
|
fileEntity.setFileSize(file.getSize()/1024);
|
||||||
|
fileEntity.setUploadTime(new Date());
|
||||||
|
fileEntity.setUploaderId(loginIdAsLong);
|
||||||
|
System.out.println(uploadDir + "\\" + file.getOriginalFilename());
|
||||||
|
add(fileEntity);
|
||||||
|
|
||||||
|
return Result.okM("上传成功");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("上传失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("文件预览")
|
||||||
|
public void preview(Long fileId, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
// 获取文件路径
|
||||||
|
String filePath = businessDataFileMapper.getPath(fileId);
|
||||||
|
if (filePath == null || filePath.isEmpty()) {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"文件不存在\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"文件不存在\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件扩展名
|
||||||
|
String extension = getFileExtension(filePath);
|
||||||
|
// ... 后续 switch 语句
|
||||||
|
|
||||||
|
// 根据文件类型处理预览
|
||||||
|
switch (extension) {
|
||||||
|
case "pdf":
|
||||||
|
previewPdf(file, response);
|
||||||
|
break;
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
case "png":
|
||||||
|
case "gif":
|
||||||
|
case "bmp":
|
||||||
|
case "webp":
|
||||||
|
previewImage(file, response);
|
||||||
|
break;
|
||||||
|
case "txt":
|
||||||
|
case "md":
|
||||||
|
case "log":
|
||||||
|
previewText(file, response);
|
||||||
|
break;
|
||||||
|
case "doc":
|
||||||
|
case "docx":
|
||||||
|
case "xls":
|
||||||
|
case "xlsx":
|
||||||
|
case "ppt":
|
||||||
|
case "pptx":
|
||||||
|
previewOffice(file, response);
|
||||||
|
break;
|
||||||
|
case "mp4":
|
||||||
|
case "avi":
|
||||||
|
case "mov":
|
||||||
|
case "wmv":
|
||||||
|
case "flv":
|
||||||
|
previewVideo(file, response);
|
||||||
|
break;
|
||||||
|
case "mp3":
|
||||||
|
case "wav":
|
||||||
|
case "flac":
|
||||||
|
case "aac":
|
||||||
|
previewAudio(file, response);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"暂不支持该文件类型的预览\"}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"文件预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFileExtension(String filePath) {
|
||||||
|
if (filePath == null || filePath.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// 从路径中提取文件名
|
||||||
|
String fileName = new File(filePath).getName();
|
||||||
|
int lastDotIndex = fileName.lastIndexOf('.');
|
||||||
|
if (lastDotIndex == -1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return fileName.substring(lastDotIndex + 1).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewPdf(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/pdf");
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"PDF预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewImage(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getImageContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"图片预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewText(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
response.setContentType("text/plain; charset=UTF-8");
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"文本预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewOffice(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"Office文件预览功能暂未实现,请下载后查看\"}");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewVideo(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getVideoContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"视频预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void previewAudio(File file, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
String contentType = getAudioContentType(file.getName());
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
response.setContentType("application/json; charset=UTF-8");
|
||||||
|
response.getWriter().write("{\"status\":500,\"msg\":\"音频预览失败: " + e.getMessage() + "\"}");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getImageContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
return "image/jpeg";
|
||||||
|
case "png":
|
||||||
|
return "image/png";
|
||||||
|
case "gif":
|
||||||
|
return "image/gif";
|
||||||
|
case "bmp":
|
||||||
|
return "image/bmp";
|
||||||
|
case "webp":
|
||||||
|
return "image/webp";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getVideoContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "mp4":
|
||||||
|
return "video/mp4";
|
||||||
|
case "avi":
|
||||||
|
return "video/x-msvideo";
|
||||||
|
case "mov":
|
||||||
|
return "video/quicktime";
|
||||||
|
case "wmv":
|
||||||
|
return "video/x-ms-wmv";
|
||||||
|
case "flv":
|
||||||
|
return "video/x-flv";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAudioContentType(String fileName) {
|
||||||
|
String extension = getFileExtension(fileName);
|
||||||
|
switch (extension) {
|
||||||
|
case "mp3":
|
||||||
|
return "audio/mpeg";
|
||||||
|
case "wav":
|
||||||
|
return "audio/wav";
|
||||||
|
case "flac":
|
||||||
|
return "audio/flac";
|
||||||
|
case "aac":
|
||||||
|
return "audio/aac";
|
||||||
|
default:
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dite.znpt.service.impl;
|
package com.dite.znpt.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
|
@ -54,12 +55,13 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
@ApiOperation(value = "创建文件夹")
|
@ApiOperation(value = "创建文件夹")
|
||||||
@Override
|
@Override
|
||||||
public Result createFolder(String folderName, Long parentId) {
|
public Result createFolder(String folderName, Long parentId) {
|
||||||
//获取ID
|
// 获取ID
|
||||||
Long loginIdAsLong = 888L;
|
String loginIdAsLong = "未登录用户";
|
||||||
// loginIdAsLong = StpUtil.getLoginIdAsLong();
|
if(StpUtil.isLogin()){
|
||||||
//
|
loginIdAsLong = StpUtil.getLoginIdAsString();
|
||||||
|
}
|
||||||
// 文件夹名称不能为空
|
// 文件夹名称不能为空
|
||||||
//TODO: 添加文件夹名称校验,后续最好更规范些,写个工具类专门校验,用正则表达式
|
// TODO: 添加文件夹名称校验,后续最好更规范些,写个工具类专门校验,用正则表达式
|
||||||
if (folderName == null || folderName.trim().isEmpty()) {
|
if (folderName == null || folderName.trim().isEmpty()) {
|
||||||
return Result.error("文件夹名称不能为空");
|
return Result.error("文件夹名称不能为空");
|
||||||
}
|
}
|
||||||
|
@ -70,10 +72,19 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
// 文件夹名称前置一个/
|
// 文件夹名称前置一个/
|
||||||
String folderName1 = "/" + folderName;
|
String folderName1 = "/" + folderName;
|
||||||
// 目标文件夹
|
// 目标文件夹
|
||||||
File targetDir=Paths.get(businessDataPath, folderName1).toFile();
|
File targetDir = Paths.get(businessDataPath, folderName1).toFile();
|
||||||
if(parentId != 0L){
|
if (parentId != 0L) {
|
||||||
// 获取父文件夹路径
|
// 获取父文件夹路径
|
||||||
targetDir = Paths.get(businessDataMapper.getPath(parentId), folderName1).toFile();
|
targetDir = Paths.get(businessDataMapper.getPath(parentId), folderName1).toFile();
|
||||||
|
} else {
|
||||||
|
// 如果是根目录,检查默认路径是否存在,不存在则创建
|
||||||
|
File defaultPathDir = new File(businessDataPath);
|
||||||
|
if (!defaultPathDir.exists()) {
|
||||||
|
boolean created = defaultPathDir.mkdirs();
|
||||||
|
if (!created) {
|
||||||
|
return Result.error("默认路径创建失败: " + businessDataPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 创建文件夹和新增文件夹路径
|
// 创建文件夹和新增文件夹路径
|
||||||
if (!targetDir.exists()) {
|
if (!targetDir.exists()) {
|
||||||
|
@ -82,7 +93,7 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
if (!created) {
|
if (!created) {
|
||||||
throw new RuntimeException("文件夹创建失败: " + targetDir.getAbsolutePath());
|
throw new RuntimeException("文件夹创建失败: " + targetDir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
//上面是新增文件夹功能,但没有往数据库插入文件夹相关数据,所以下面新增
|
// 上面是新增文件夹功能,但没有往数据库插入文件夹相关数据,所以下面新增
|
||||||
// 创建BusinessDataEntity对象并设置属性
|
// 创建BusinessDataEntity对象并设置属性
|
||||||
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
||||||
null,
|
null,
|
||||||
|
@ -92,11 +103,10 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
LocalDateTime.now(),
|
LocalDateTime.now(),
|
||||||
LocalDateTime.now(),
|
LocalDateTime.now(),
|
||||||
false,
|
false,
|
||||||
targetDir.getAbsolutePath()
|
targetDir.getAbsolutePath());
|
||||||
);
|
|
||||||
// 插入到数据库
|
// 插入到数据库
|
||||||
businessDataMapper.insert(businessDataEntity);
|
businessDataMapper.insert(businessDataEntity);
|
||||||
return Result.okM( "文件夹创建成功");
|
return Result.okM("文件夹创建成功");
|
||||||
} else {
|
} else {
|
||||||
return Result.error("文件夹已存在: ");
|
return Result.error("文件夹已存在: ");
|
||||||
}
|
}
|
||||||
|
@ -107,31 +117,6 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
return businessDataMapper.getPath(parentId);
|
return businessDataMapper.getPath(parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ApiOperation("删除文件夹")
|
|
||||||
// @Override
|
|
||||||
// public Result delete(Long folderId) {
|
|
||||||
// // 获取文件夹路径
|
|
||||||
// String folderPath = businessDataMapper.getPath(folderId);
|
|
||||||
//
|
|
||||||
// // 创建File对象并删除文件夹
|
|
||||||
// File folder = new File(folderPath);
|
|
||||||
// if (folder.exists()) {
|
|
||||||
// boolean deleted = folder.delete();
|
|
||||||
// if (!deleted) {
|
|
||||||
// // throw new RuntimeException("文件夹删除失败: " + folderPath);
|
|
||||||
// // TODO: 以后可以用全局异常处理器捕获,或者用try catch捕获
|
|
||||||
// return Result.error("文件夹删除失败: " + folderPath);
|
|
||||||
// }
|
|
||||||
// //删除数据库中文件夹的数据
|
|
||||||
// businessDataMapper.delete(folderId);
|
|
||||||
// //删除文件夹下文件的数据
|
|
||||||
// businessDataFileService.delete(folderId);
|
|
||||||
// return Result.okM("删除成功");
|
|
||||||
// } else {
|
|
||||||
// // throw new RuntimeException("文件夹不存在: " + folderPath);
|
|
||||||
// return Result.error("文件夹不存在: " + folderPath);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@ApiOperation("删除文件夹")
|
@ApiOperation("删除文件夹")
|
||||||
@Override
|
@Override
|
||||||
public Result delete(Long folderId) {
|
public Result delete(Long folderId) {
|
||||||
|
@ -149,10 +134,10 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
.forEach(File::delete);
|
.forEach(File::delete);
|
||||||
filePaths.close();
|
filePaths.close();
|
||||||
|
|
||||||
//删除数据库中文件夹的数据
|
// 删除数据库中文件夹的数据
|
||||||
businessDataMapper.delete(folderId);
|
businessDataMapper.delete(folderId);
|
||||||
//删除文件夹下文件的数据
|
// 删除文件夹下文件的数据
|
||||||
businessDataFileService.delete(null , folderId);
|
businessDataFileService.delete(null, folderId);
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
|
@ -161,21 +146,21 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
return Result.error("文件夹不存在: " + folderPath);
|
return Result.error("文件夹不存在: " + folderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("重命名文件夹")
|
@ApiOperation("重命名文件夹")
|
||||||
@Override
|
@Override
|
||||||
public Result reName(Long folderId, String newName) {
|
public Result reName(Long folderId, String newName) {
|
||||||
// 获取文件夹路径
|
// 获取文件夹路径
|
||||||
String folderPath = businessDataMapper.getPath(folderId);
|
String folderPath = businessDataMapper.getPath(folderId);
|
||||||
String newPath = folderPath.substring(0, folderPath.lastIndexOf('\\'))+"\\" + newName;
|
String newPath = folderPath.substring(0, folderPath.lastIndexOf('\\')) + "\\" + newName;
|
||||||
System.out.printf("7777777"+newPath);
|
//
|
||||||
//
|
// //想命名的原文件的路径
|
||||||
// //想命名的原文件的路径
|
// File file = new File("f:/a/a.xlsx");
|
||||||
// File file = new File("f:/a/a.xlsx");
|
// //将原文件更改为f:\a\b.xlsx,其中路径是必要的。注意
|
||||||
// //将原文件更改为f:\a\b.xlsx,其中路径是必要的。注意
|
// file.renameTo(new File("f:/a/b.xlsx"));
|
||||||
// file.renameTo(new File("f:/a/b.xlsx"));
|
// 想命名的原文件夹的路径
|
||||||
//想命名的原文件夹的路径
|
|
||||||
File file1 = new File(folderPath);
|
File file1 = new File(folderPath);
|
||||||
//将原文件夹更改为A,其中路径是必要的。注意
|
// 将原文件夹更改为A,其中路径是必要的。注意
|
||||||
file1.renameTo(new File(newPath));
|
file1.renameTo(new File(newPath));
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
@ -187,11 +172,8 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
null,
|
null,
|
||||||
now,
|
now,
|
||||||
null,
|
null,
|
||||||
newPath
|
newPath);
|
||||||
);
|
|
||||||
System.out.println(businessDataEntity);
|
|
||||||
businessDataMapper.reName(businessDataEntity);
|
businessDataMapper.reName(businessDataEntity);
|
||||||
return Result.okM("重命名成功");
|
return Result.okM("重命名成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -50,11 +51,22 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
// 查询团队成员列表
|
// 查询团队成员列表
|
||||||
List<ProjectMemberResp> list = this.baseMapper.queryTeamMembers(query);
|
List<ProjectMemberResp> list = this.baseMapper.queryTeamMembers(query);
|
||||||
|
|
||||||
|
// 按用户ID去重,保留第一个记录
|
||||||
|
Map<String, ProjectMemberResp> uniqueMembers = list.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
ProjectMemberResp::getUserId,
|
||||||
|
member -> member,
|
||||||
|
(existing, replacement) -> existing // 如果有重复,保留第一个
|
||||||
|
));
|
||||||
|
|
||||||
|
// 转换为列表
|
||||||
|
List<ProjectMemberResp> uniqueList = new ArrayList<>(uniqueMembers.values());
|
||||||
|
|
||||||
// 丰富成员信息
|
// 丰富成员信息
|
||||||
enrichMemberInfo(list);
|
enrichMemberInfo(uniqueList);
|
||||||
|
|
||||||
// 返回分页结果
|
// 返回分页结果
|
||||||
return PageResult.ok(list);
|
return PageResult.ok(uniqueList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,22 +98,53 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
UserEntity user = userMap.get(member.getUserId());
|
UserEntity user = userMap.get(member.getUserId());
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
// 映射前端需要的字段
|
// 映射前端需要的字段
|
||||||
member.setName(user.getName());
|
member.setName(user.getName() != null ? user.getName() : "");
|
||||||
member.setPhone(user.getMobile());
|
member.setPhone(user.getMobile() != null ? user.getMobile() : "");
|
||||||
member.setEmail(user.getEmail());
|
member.setEmail(user.getEmail() != null ? user.getEmail() : "");
|
||||||
|
|
||||||
// 保留原有字段用于内部处理
|
// 保留原有字段用于内部处理
|
||||||
member.setUserAccount(user.getAccount());
|
member.setUserAccount(user.getAccount() != null ? user.getAccount() : "");
|
||||||
member.setUserAvatar(user.getAvatar());
|
member.setUserAvatar(user.getAvatar() != null ? user.getAvatar() : "");
|
||||||
|
} else {
|
||||||
|
// 如果用户信息不存在,设置默认值
|
||||||
|
member.setName("");
|
||||||
|
member.setPhone("");
|
||||||
|
member.setEmail("");
|
||||||
|
member.setUserAccount("");
|
||||||
|
member.setUserAvatar("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 映射岗位信息 - 使用角色类型描述作为岗位
|
// 映射岗位信息 - 使用角色类型描述作为岗位
|
||||||
member.setPosition(member.getRoleTypeDesc());
|
member.setPosition(member.getRoleTypeDesc() != null ? member.getRoleTypeDesc() : "");
|
||||||
|
|
||||||
// 映射技能标签 - 暂时设为空,因为数据库中没有这个字段
|
// 映射技能标签 - 暂时设为空,因为数据库中没有这个字段
|
||||||
member.setSkills("");
|
member.setSkills("");
|
||||||
|
|
||||||
|
// 处理其他可能为NULL的字段
|
||||||
|
if (member.getTurbineId() == null) {
|
||||||
|
member.setTurbineId("");
|
||||||
|
}
|
||||||
|
if (member.getTurbineName() == null) {
|
||||||
|
member.setTurbineName("");
|
||||||
|
}
|
||||||
|
if (member.getTaskGroupId() == null) {
|
||||||
|
member.setTaskGroupId("");
|
||||||
|
}
|
||||||
|
if (member.getTaskGroupName() == null) {
|
||||||
|
member.setTaskGroupName("");
|
||||||
|
}
|
||||||
|
if (member.getTaskId() == null) {
|
||||||
|
member.setTaskId("");
|
||||||
|
}
|
||||||
|
if (member.getTaskName() == null) {
|
||||||
|
member.setTaskName("");
|
||||||
|
}
|
||||||
|
if (member.getRemark() == null) {
|
||||||
|
member.setRemark("");
|
||||||
|
}
|
||||||
|
|
||||||
// 设置状态描述
|
// 设置状态描述
|
||||||
|
if (member.getStatus() != null) {
|
||||||
if ("ACTIVE".equals(member.getStatus())) {
|
if ("ACTIVE".equals(member.getStatus())) {
|
||||||
member.setStatusDesc("在职");
|
member.setStatusDesc("在职");
|
||||||
} else if ("INACTIVE".equals(member.getStatus())) {
|
} else if ("INACTIVE".equals(member.getStatus())) {
|
||||||
|
@ -111,8 +154,12 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
} else {
|
} else {
|
||||||
member.setStatusDesc("未知");
|
member.setStatusDesc("未知");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
member.setStatusDesc("未知");
|
||||||
|
}
|
||||||
|
|
||||||
// 设置角色类型描述
|
// 设置角色类型描述
|
||||||
|
if (member.getRoleType() != null) {
|
||||||
if ("PROJECT_MANAGER".equals(member.getRoleType())) {
|
if ("PROJECT_MANAGER".equals(member.getRoleType())) {
|
||||||
member.setRoleTypeDesc("项目经理");
|
member.setRoleTypeDesc("项目经理");
|
||||||
} else if ("SAFETY_OFFICER".equals(member.getRoleType())) {
|
} else if ("SAFETY_OFFICER".equals(member.getRoleType())) {
|
||||||
|
@ -126,46 +173,16 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
} else {
|
} else {
|
||||||
member.setRoleTypeDesc("其他");
|
member.setRoleTypeDesc("其他");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
member.setRoleTypeDesc("其他");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectMemberResp createTeamMember(TeamMemberReq req) {
|
public ProjectMemberResp createTeamMember(TeamMemberReq req) {
|
||||||
// 验证项目是否存在
|
// 验证请求参数
|
||||||
ProjectEntity project = projectService.getById(req.getProjectId());
|
validateTeamMemberRequest(req);
|
||||||
if (project == null) {
|
|
||||||
throw new ServiceException(Message.PROJECT_ID_IS_NOT_EXIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证用户是否存在
|
|
||||||
UserEntity user = userService.getById(req.getUserId());
|
|
||||||
if (user == null) {
|
|
||||||
throw new ServiceException("用户不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证机组是否存在(如果指定了机组)
|
|
||||||
if (StrUtil.isNotBlank(req.getTurbineId())) {
|
|
||||||
TurbineEntity turbine = turbineService.getById(req.getTurbineId());
|
|
||||||
if (turbine == null) {
|
|
||||||
throw new ServiceException("机组不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证任务组是否存在(如果指定了任务组)
|
|
||||||
if (StrUtil.isNotBlank(req.getTaskGroupId())) {
|
|
||||||
ProjectTaskGroupEntity taskGroup = projectTaskGroupService.getById(req.getTaskGroupId());
|
|
||||||
if (taskGroup == null) {
|
|
||||||
throw new ServiceException("任务组不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证任务是否存在(如果指定了任务)
|
|
||||||
if (StrUtil.isNotBlank(req.getTaskId())) {
|
|
||||||
ProjectTaskEntity task = projectTaskService.getById(req.getTaskId());
|
|
||||||
if (task == null) {
|
|
||||||
throw new ServiceException("任务不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建项目成员实体
|
// 创建项目成员实体
|
||||||
ProjectMemberEntity entity = new ProjectMemberEntity();
|
ProjectMemberEntity entity = new ProjectMemberEntity();
|
||||||
|
@ -186,41 +203,8 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
throw new ServiceException("项目成员不存在");
|
throw new ServiceException("项目成员不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证项目是否存在
|
// 验证请求参数
|
||||||
ProjectEntity project = projectService.getById(req.getProjectId());
|
validateTeamMemberRequest(req);
|
||||||
if (project == null) {
|
|
||||||
throw new ServiceException(Message.PROJECT_ID_IS_NOT_EXIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证用户是否存在
|
|
||||||
UserEntity user = userService.getById(req.getUserId());
|
|
||||||
if (user == null) {
|
|
||||||
throw new ServiceException("用户不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证机组是否存在(如果指定了机组)
|
|
||||||
if (StrUtil.isNotBlank(req.getTurbineId())) {
|
|
||||||
TurbineEntity turbine = turbineService.getById(req.getTurbineId());
|
|
||||||
if (turbine == null) {
|
|
||||||
throw new ServiceException("机组不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证任务组是否存在(如果指定了任务组)
|
|
||||||
if (StrUtil.isNotBlank(req.getTaskGroupId())) {
|
|
||||||
ProjectTaskGroupEntity taskGroup = projectTaskGroupService.getById(req.getTaskGroupId());
|
|
||||||
if (taskGroup == null) {
|
|
||||||
throw new ServiceException("任务组不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证任务是否存在(如果指定了任务)
|
|
||||||
if (StrUtil.isNotBlank(req.getTaskId())) {
|
|
||||||
ProjectTaskEntity task = projectTaskService.getById(req.getTaskId());
|
|
||||||
if (task == null) {
|
|
||||||
throw new ServiceException("任务不存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新成员信息
|
// 更新成员信息
|
||||||
BeanUtil.copyProperties(req, existingMember);
|
BeanUtil.copyProperties(req, existingMember);
|
||||||
|
@ -246,6 +230,47 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
return this.removeByIds(CollUtil.toList(memberIds));
|
return this.removeByIds(CollUtil.toList(memberIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证团队成员请求参数
|
||||||
|
*/
|
||||||
|
private void validateTeamMemberRequest(TeamMemberReq req) {
|
||||||
|
// 验证项目是否存在
|
||||||
|
ProjectEntity project = projectService.getById(req.getProjectId());
|
||||||
|
if (project == null) {
|
||||||
|
throw new ServiceException(Message.PROJECT_ID_IS_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证用户是否存在
|
||||||
|
UserEntity user = userService.getById(req.getUserId());
|
||||||
|
if (user == null) {
|
||||||
|
throw new ServiceException("用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证机组是否存在(如果指定了机组)
|
||||||
|
if (StrUtil.isNotBlank(req.getTurbineId())) {
|
||||||
|
TurbineEntity turbine = turbineService.getById(req.getTurbineId());
|
||||||
|
if (turbine == null) {
|
||||||
|
throw new ServiceException("机组不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证任务组是否存在(如果指定了任务组)
|
||||||
|
if (StrUtil.isNotBlank(req.getTaskGroupId())) {
|
||||||
|
ProjectTaskGroupEntity taskGroup = projectTaskGroupService.getById(req.getTaskGroupId());
|
||||||
|
if (taskGroup == null) {
|
||||||
|
throw new ServiceException("任务组不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证任务是否存在(如果指定了任务)
|
||||||
|
if (StrUtil.isNotBlank(req.getTaskId())) {
|
||||||
|
ProjectTaskEntity task = projectTaskService.getById(req.getTaskId());
|
||||||
|
if (task == null) {
|
||||||
|
throw new ServiceException("任务不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据成员ID获取成员信息
|
* 根据成员ID获取成员信息
|
||||||
*/
|
*/
|
||||||
|
@ -468,19 +493,28 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
|
||||||
// 设置项目经理
|
// 设置项目经理
|
||||||
item.setManager(memberNames.get("PROJECT_MANAGER"));
|
item.setManager(memberNames.get("PROJECT_MANAGER"));
|
||||||
|
|
||||||
// 设置团队规模
|
// 设置团队规模 - 使用去重后的数量
|
||||||
item.setTeamSize(members.size());
|
item.setTeamSize((int) members.stream()
|
||||||
|
.map(ProjectMemberResp::getUserId)
|
||||||
|
.distinct()
|
||||||
|
.count());
|
||||||
|
|
||||||
// 转换为团队成员列表
|
// 转换为团队成员列表 - 按用户ID去重
|
||||||
List<ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp> teamMembers = members.stream()
|
List<ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp> teamMembers = members.stream()
|
||||||
.map(member -> {
|
.collect(Collectors.toMap(
|
||||||
|
ProjectMemberResp::getUserId, // 按用户ID去重
|
||||||
|
member -> {
|
||||||
ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp teamMember = new ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp();
|
ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp teamMember = new ProjectKanbanDataResp.ProjectKanbanItem.TeamMemberResp();
|
||||||
// 先复制所有同名字段
|
// 先复制所有同名字段
|
||||||
BeanUtil.copyProperties(member, teamMember);
|
BeanUtil.copyProperties(member, teamMember);
|
||||||
// 手动处理字段名不一致的字段
|
// 手动处理字段名不一致的字段
|
||||||
teamMember.setUserName(member.getName()); // name -> userName
|
teamMember.setUserName(member.getName()); // name -> userName
|
||||||
return teamMember;
|
return teamMember;
|
||||||
})
|
},
|
||||||
|
(existing, replacement) -> existing // 如果有重复,保留第一个
|
||||||
|
))
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
item.setTeamMembers(teamMembers);
|
item.setTeamMembers(teamMembers);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<!-- 获取项目团队成员列表(支持筛选、分页、搜索) -->
|
<!-- 获取项目团队成员列表(支持筛选、分页、搜索) -->
|
||||||
<select id="queryTeamMembers" resultType="com.dite.znpt.domain.vo.ProjectMemberResp">
|
<select id="queryTeamMembers" resultType="com.dite.znpt.domain.vo.ProjectMemberResp">
|
||||||
SELECT DISTINCT
|
SELECT
|
||||||
pm.member_id,
|
pm.member_id,
|
||||||
pm.project_id,
|
pm.project_id,
|
||||||
p.project_name,
|
p.project_name,
|
||||||
|
|
|
@ -1,25 +1,33 @@
|
||||||
package com.dite.znpt.web.controller;
|
package com.dite.znpt.web.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
import com.dite.znpt.mapper.BusinessDataFileMapper;
|
import com.dite.znpt.mapper.BusinessDataFileMapper;
|
||||||
|
import com.dite.znpt.mapper.BusinessDataMapper;
|
||||||
|
|
||||||
import com.dite.znpt.service.BusinessDataFileService;
|
import com.dite.znpt.service.BusinessDataFileService;
|
||||||
import com.dite.znpt.service.BusinessDataService;
|
import com.dite.znpt.service.BusinessDataService;
|
||||||
|
import com.dite.znpt.service.impl.BusinessDataFileServiceImpl;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Description: 商务资料管理,文件夹层
|
* @Description: 商务资料管理,文件夹层
|
||||||
|
* 袁彬彬写的,其他人合并的时候,不允许改我的部分。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Api(tags = "文件接口")
|
@Api(tags = "文件接口")
|
||||||
|
@ -49,39 +57,7 @@ public class BusinessDataFileController {
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public Result add(@RequestParam("file") MultipartFile file,
|
public Result add(@RequestParam("file") MultipartFile file,
|
||||||
@RequestParam Long folderId) {
|
@RequestParam Long folderId) {
|
||||||
|
return businessDataFileService.addfile(file, folderId);
|
||||||
if (file.isEmpty()) {
|
|
||||||
return Result.error("上传文件为空");
|
|
||||||
}
|
|
||||||
// TODO 以后可以优化,就算文件名一样,加个(1),(2)这种
|
|
||||||
|
|
||||||
try {
|
|
||||||
byte[] bytes = file.getBytes();
|
|
||||||
String uploadDir = businessDataService.getPath(folderId);
|
|
||||||
|
|
||||||
File uploadedFile = new File(uploadDir + "\\" + file.getOriginalFilename());
|
|
||||||
if (uploadedFile.exists()) {
|
|
||||||
return Result.error("文件已存在");
|
|
||||||
}
|
|
||||||
file.transferTo(uploadedFile);
|
|
||||||
|
|
||||||
// 保存文件信息到数据
|
|
||||||
BusinessDataFileEntity fileEntity = new BusinessDataFileEntity();
|
|
||||||
fileEntity.setFolderId(folderId);
|
|
||||||
fileEntity.setFileName(file.getOriginalFilename());
|
|
||||||
fileEntity.setFilePath(uploadDir + "\\" + file.getOriginalFilename());
|
|
||||||
fileEntity.setFileType(file.getContentType());
|
|
||||||
fileEntity.setFileSize(file.getSize());
|
|
||||||
fileEntity.setUploadTime(new Date());
|
|
||||||
fileEntity.setUploaderId(0L);
|
|
||||||
System.out.println(uploadDir + "\\" + file.getOriginalFilename());
|
|
||||||
businessDataFileService.add(fileEntity);
|
|
||||||
|
|
||||||
return Result.okM("上传成功");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return Result.error("上传失败");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "删除文件")
|
@ApiOperation(value = "删除文件")
|
||||||
|
@ -94,38 +70,7 @@ public class BusinessDataFileController {
|
||||||
@ApiOperation(value = "下载文件")
|
@ApiOperation(value = "下载文件")
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
public void download(@RequestParam("fileId") Long fileId, HttpServletResponse response) {
|
public void download(@RequestParam("fileId") Long fileId, HttpServletResponse response) {
|
||||||
String path = businessDataFileService.getPath(fileId);
|
businessDataFileService.upload(fileId, response);
|
||||||
try {
|
|
||||||
// path是指想要下载的文件的路径
|
|
||||||
File file = new File(path);
|
|
||||||
log.info(file.getPath());
|
|
||||||
// 获取文件名
|
|
||||||
String filename = file.getName();
|
|
||||||
// 获取文件后缀名
|
|
||||||
String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
|
|
||||||
log.info("文件后缀名:" + ext);
|
|
||||||
|
|
||||||
// 将文件写入输入流
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(file);
|
|
||||||
InputStream fis = new BufferedInputStream(fileInputStream);
|
|
||||||
byte[] buffer = new byte[fis.available()];
|
|
||||||
fis.read(buffer);
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
// 清空response
|
|
||||||
response.reset();
|
|
||||||
// 设置response的Header
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
|
|
||||||
// 告知浏览器文件的大小
|
|
||||||
response.addHeader("Content-Length", "" + file.length());
|
|
||||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
|
||||||
response.setContentType("application/octet-stream");
|
|
||||||
outputStream.write(buffer);
|
|
||||||
outputStream.flush();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "重命名文件", httpMethod = "PUT")
|
@ApiOperation(value = "重命名文件", httpMethod = "PUT")
|
||||||
|
@ -134,4 +79,11 @@ public class BusinessDataFileController {
|
||||||
return businessDataFileService.reName(fileId, newFileName);
|
return businessDataFileService.reName(fileId, newFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "文件预览")
|
||||||
|
@GetMapping("/preview")
|
||||||
|
public void preview(@RequestParam("fileId") Long fileId, HttpServletResponse response) {
|
||||||
|
businessDataFileService.preview(fileId, response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ spring:
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://39.99.201.243:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
url: jdbc:mysql://39.99.201.243:3306/test01?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: root
|
username: root
|
||||||
password: BUw8YW6%@^8q
|
password: BUw8YW6%@^8q
|
||||||
druid:
|
druid:
|
||||||
|
|
|
@ -10,9 +10,9 @@ spring:
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
# 单个文件大小
|
# 单个文件大小
|
||||||
max-file-size: 100MB
|
max-file-size: 1000MB
|
||||||
# 设置总上传的文件大小
|
# 设置总上传的文件大小
|
||||||
max-request-size: 200MB
|
max-request-size: 2000MB
|
||||||
application:
|
application:
|
||||||
name: znpt
|
name: znpt
|
||||||
mvc:
|
mvc:
|
||||||
|
|
Loading…
Reference in New Issue