|
@@ -11,11 +11,12 @@ import com.management.platform.controller.AuditWorkflowSettingController;
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.entity.vo.UserRestTimeVO;
|
|
import com.management.platform.entity.vo.UserRestTimeVO;
|
|
|
|
+import com.management.platform.exception.FileCheckException;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.service.*;
|
|
import com.management.platform.service.*;
|
|
-import com.management.platform.util.HttpRespMsg;
|
|
|
|
-import com.management.platform.util.MessageUtils;
|
|
|
|
-import com.management.platform.util.WorkDayCalculateUtils;
|
|
|
|
|
|
+import com.management.platform.task.SFTPAsyncUploader;
|
|
|
|
+import com.management.platform.util.*;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -25,6 +26,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -81,26 +84,37 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
|
|
@Value(value = "${upload.path}")
|
|
@Value(value = "${upload.path}")
|
|
private String path;
|
|
private String path;
|
|
|
|
|
|
- public void checkFile(MultipartFile file){
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SFTPAsyncUploader sftpAsyncUploader;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private LeaveSheetFilesMapper leaveSheetFilesMapper;
|
|
|
|
+
|
|
|
|
+ public void checkFile(MultipartFile file) throws FileCheckException {
|
|
if(file.isEmpty()){
|
|
if(file.isEmpty()){
|
|
- throw new RuntimeException("文件大小不能为0");
|
|
|
|
|
|
+ throw new FileCheckException("文件大小不能为0");
|
|
}
|
|
}
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename())){
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename())){
|
|
- throw new RuntimeException("文件名不能为空");
|
|
|
|
|
|
+ throw new FileCheckException("文件名不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(file.getOriginalFilename().split("\\.").length > 2){
|
|
|
|
+ throw new FileCheckException("文件名中.不能出现多个");
|
|
}
|
|
}
|
|
-// if(file.getOriginalFilename().){
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg add(LeaveSheet sheet, String userId, MultipartFile[] files) {
|
|
public HttpRespMsg add(LeaveSheet sheet, String userId, MultipartFile[] files) {
|
|
-// if(null != files && files.length > 0){
|
|
|
|
-// for (MultipartFile file : files) {
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ if(null != files && files.length > 0){
|
|
|
|
+ try {
|
|
|
|
+ for (MultipartFile file : files) {
|
|
|
|
+ checkFile(file);
|
|
|
|
+ }
|
|
|
|
+ } catch (FileCheckException e) {
|
|
|
|
+ msg.setError(e.getMessage());
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
boolean isNew = false;
|
|
boolean isNew = false;
|
|
if (sheet.getId() == null) {
|
|
if (sheet.getId() == null) {
|
|
isNew = true;
|
|
isNew = true;
|
|
@@ -172,6 +186,56 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
|
|
if (wxCorpInfo != null) {
|
|
if (wxCorpInfo != null) {
|
|
sendAuditNotifyMsg(wxCorpInfo, user, sheet);
|
|
sendAuditNotifyMsg(wxCorpInfo, user, sheet);
|
|
}
|
|
}
|
|
|
|
+ if(null != files && files.length > 0){
|
|
|
|
+ for (MultipartFile file : files) {
|
|
|
|
+ LeaveSheetFiles leaveSheetFiles = new LeaveSheetFiles();
|
|
|
|
+ leaveSheetFiles.setDocumentName(file.getOriginalFilename());
|
|
|
|
+ leaveSheetFiles.setLeaveSheetId(sheet.getId());
|
|
|
|
+ leaveSheetFiles.setCreatorId(userId);
|
|
|
|
+ leaveSheetFiles.setCreatorName(user.getName());
|
|
|
|
+ String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
|
+ leaveSheetFiles.setDocumentType(DocumentTypeUtil.DocumentType(fileSuffix));
|
|
|
|
+ //处理文件
|
|
|
|
+ File dir = new File(path);
|
|
|
|
+ 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);
|
|
|
|
+ leaveSheetFiles.setServerName(path + fileName);
|
|
|
|
+ leaveSheetFiles.setSize(fileLength);
|
|
|
|
+ String pathPrefix = "/upload/";
|
|
|
|
+ leaveSheetFiles.setUrl(pathPrefix + fileName);
|
|
|
|
+ leaveSheetFilesMapper.insert(leaveSheetFiles);
|
|
|
|
+ } 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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|