|
@@ -85,6 +85,131 @@ public class TaskFilesController {
|
|
|
@Resource
|
|
|
private TaskFilesService taskFilesService;
|
|
|
|
|
|
+ @PostMapping("/reUploadFile")
|
|
|
+ public HttpRespMsg reUploadFile(@RequestParam Integer projectId,
|
|
|
+ @RequestParam Integer taskId,
|
|
|
+ @RequestParam Integer taskFileId,
|
|
|
+ @RequestParam("file") MultipartFile file,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(user.getCompanyId());
|
|
|
+ Department department = departmentMapper.selectById(user.getDepartmentId());
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
+ TaskFiles oldTaskFile = taskFilesMapper.selectById(taskFileId);
|
|
|
+
|
|
|
+ if(!oldTaskFile.getCreatorId().equals(user.getId())){
|
|
|
+ msg.setError("您非文件上传人,无法重新上传");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (oldTaskFile.getDocumentId() == null) {
|
|
|
+ //仅当前任务上传的,需要把文件删掉
|
|
|
+ File dir = new File(uploadPath);
|
|
|
+ File targetFile = new File(dir, oldTaskFile.getServerName());
|
|
|
+ if (targetFile.exists()) {
|
|
|
+ targetFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// StringBuilder fileNames = new StringBuilder();
|
|
|
+ TaskFiles record = new TaskFiles();
|
|
|
+ record.setId(taskFileId);
|
|
|
+ record.setCreatorId(user.getId());
|
|
|
+ record.setCreatorName(user.getName());
|
|
|
+ record.setDocumentName(file.getOriginalFilename());
|
|
|
+ record.setTaskId(taskId);
|
|
|
+ record.setProjectId(projectId);
|
|
|
+ if(1 == timeType.getTaskFileCharge()){
|
|
|
+ record.setNeedFileCharge(1);
|
|
|
+ if(org.apache.commons.lang3.StringUtils.isBlank(department.getManagerId())){
|
|
|
+ msg.setError("员工所在部门无负责人,请重新设置");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(org.apache.commons.lang3.StringUtils.isBlank(project.getInchargerId())){
|
|
|
+ msg.setError("该项目未设置项目经理,请重新设置");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ record.setChargeOneId(department.getManagerId());
|
|
|
+ record.setChargeTwoId(project.getInchargerId());
|
|
|
+ //根据老阶段重置任务状态
|
|
|
+ record.setFinalChargeStatus(0);
|
|
|
+ if(1 == oldTaskFile.getChargeStage()){
|
|
|
+ record.setChargeOneStatus(0);
|
|
|
+ }else if(2 == oldTaskFile.getChargeStage()){
|
|
|
+ record.setChargeTwoStatus(0);
|
|
|
+ } else if (3 == oldTaskFile.getChargeStage()) {
|
|
|
+ record.setChargeStage(1);
|
|
|
+ record.setChargeOneStatus(0);
|
|
|
+ record.setChargeTwoStatus(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (file != null && !file.isEmpty()) {
|
|
|
+ //截取文件后缀
|
|
|
+ String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ record.setDocumentType(DocumentTypeUtil.DocumentType(fileSuffix));
|
|
|
+ //处理文件
|
|
|
+ File dir = new File(uploadPath);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ String fileName= "";
|
|
|
+ if (file!=null && !file.isEmpty()) {
|
|
|
+ fileName = file.getOriginalFilename();
|
|
|
+
|
|
|
+ int pos = fileName.lastIndexOf(".");
|
|
|
+ String suffix = fileName.substring(pos).toLowerCase();
|
|
|
+ //用uuid替换原始的文件名
|
|
|
+ String purFName = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ fileName = purFName + suffix;
|
|
|
+ File saveFile = new File(dir, fileName);
|
|
|
+ try {
|
|
|
+ saveFile.createNewFile();
|
|
|
+ file.transferTo(saveFile);
|
|
|
+ //异步上传到备份服务器
|
|
|
+ sftpAsyncUploader.uploadFileAsync(saveFile);
|
|
|
+ //计算文件大小
|
|
|
+ long fileSize = saveFile.length();
|
|
|
+ String fileLength = FileUtil.getReadableFileSize(fileSize);
|
|
|
+ record.setServerName(uploadPath + fileName);
|
|
|
+ record.setSize(fileLength);
|
|
|
+ String pathPrefix = "/upload/";
|
|
|
+ record.setUrl(pathPrefix + fileName);
|
|
|
+
|
|
|
+ taskFilesMapper.updateById(record);
|
|
|
+ //生成原文件名称与服务器文件名称对应
|
|
|
+ msg.data = record;
|
|
|
+
|
|
|
+
|
|
|
+ //添加动态消息
|
|
|
+ Task task = taskMapper.selectById(taskId);
|
|
|
+ String content = user.getName()+"在任务【"+task.getName()+"】中重新上传了文件【"+file.getOriginalFilename()+"】";
|
|
|
+ TaskComment comment = new TaskComment();
|
|
|
+ comment.setTaskId(taskId);
|
|
|
+ comment.setUserId(user.getId());
|
|
|
+ comment.setContent(content);
|
|
|
+ comment.setCreateTime(LocalDateTime.now());
|
|
|
+ comment.setUserColor(user.getColor());
|
|
|
+ comment.setUserName(user.getName());
|
|
|
+ taskCommentMapper.insert(comment);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ fileName = null;
|
|
|
+ msg.setError(e.getMessage()+", path="+dir.getAbsolutePath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ fileName = null;
|
|
|
+ msg.setError(e.getMessage()+", path="+dir.getAbsolutePath());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //msg.setError("文件不存在");
|
|
|
+ msg.setError(MessageUtils.message("file.nonExistentError"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@PostMapping("/approveFile")
|
|
|
public HttpRespMsg approveFile(@RequestParam("taskFileIds")String taskFileIds
|
|
@@ -163,7 +288,7 @@ public class TaskFilesController {
|
|
|
|
|
|
//添加动态消息
|
|
|
Task task = taskMapper.selectById(taskId);
|
|
|
- String content = user.getName()+"在任务:"+task.getName()+"中关联了文件:"+document.getDocumentName();
|
|
|
+ String content = user.getName()+"在任务【"+task.getName()+"】中关联了文件【"+document.getDocumentName()+"】";
|
|
|
TaskComment comment = new TaskComment();
|
|
|
comment.setTaskId(taskId);
|
|
|
comment.setUserId(user.getId());
|
|
@@ -308,7 +433,7 @@ public class TaskFilesController {
|
|
|
//添加动态消息
|
|
|
String resFileNames = fileNames.deleteCharAt(fileNames.length() - 1).toString();
|
|
|
Task task = taskMapper.selectById(taskId);
|
|
|
- String content = user.getName()+"在任务:"+task.getName()+"中上传了文件:"+resFileNames;
|
|
|
+ String content = user.getName()+"在任务【"+task.getName()+"】中上传了文件【"+resFileNames+"】";
|
|
|
TaskComment comment = new TaskComment();
|
|
|
comment.setTaskId(taskId);
|
|
|
comment.setUserId(user.getId());
|
|
@@ -357,7 +482,7 @@ public class TaskFilesController {
|
|
|
|
|
|
//添加动态消息
|
|
|
Task task = taskMapper.selectById(taskFiles.getTaskId());
|
|
|
- String content = user.getName()+"删除了任务:"+task.getName()+"中的文件:"+taskFiles.getDocumentName();
|
|
|
+ String content = user.getName()+"删除了任务【"+task.getName()+"】中的文件【"+taskFiles.getDocumentName()+"】";
|
|
|
TaskComment comment = new TaskComment();
|
|
|
comment.setTaskId(taskFiles.getTaskId());
|
|
|
comment.setUserId(user.getId());
|