|
@@ -11,23 +11,19 @@ import com.management.platform.controller.AuditWorkflowSettingController;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
|
import com.management.platform.entity.vo.UserRestTimeVO;
|
|
|
-import com.management.platform.exception.FileCheckException;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
|
-import com.management.platform.task.SFTPAsyncUploader;
|
|
|
-import com.management.platform.util.*;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.MessageUtils;
|
|
|
+import com.management.platform.util.WorkDayCalculateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -84,37 +80,9 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SFTPAsyncUploader sftpAsyncUploader;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private LeaveSheetFilesMapper leaveSheetFilesMapper;
|
|
|
-
|
|
|
- public void checkFile(MultipartFile file) throws FileCheckException {
|
|
|
- if(file.isEmpty()){
|
|
|
- throw new FileCheckException("文件大小不能为0");
|
|
|
- }
|
|
|
- if(org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename())){
|
|
|
- throw new FileCheckException("文件名不能为空");
|
|
|
- }
|
|
|
- if(file.getOriginalFilename().split("\\.").length > 2){
|
|
|
- throw new FileCheckException("文件名中.不能出现多个");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public HttpRespMsg add(LeaveSheet sheet, String userId, MultipartFile[] files) {
|
|
|
+ public HttpRespMsg add(LeaveSheet sheet, String userId) {
|
|
|
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;
|
|
|
if (sheet.getId() == null) {
|
|
|
isNew = true;
|
|
@@ -186,55 +154,6 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
|
|
|
if (wxCorpInfo != null) {
|
|
|
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;
|
|
|
}
|
|
@@ -411,18 +330,6 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- if(!CollectionUtils.isEmpty(records)){
|
|
|
- List<Integer> leavesheetIds = records.stream().map(LeaveSheet::getId).collect(Collectors.toList());
|
|
|
- List<LeaveSheetFiles> leaveSheetFiles = leaveSheetFilesMapper.selectList(new LambdaQueryWrapper<LeaveSheetFiles>()
|
|
|
- .select(LeaveSheetFiles::getDocumentName,LeaveSheetFiles::getServerName,LeaveSheetFiles::getUrl)
|
|
|
- .in(LeaveSheetFiles::getLeaveSheetId, leavesheetIds)
|
|
|
- );
|
|
|
- Map<Integer, List<LeaveSheetFiles>> collect = leaveSheetFiles.stream().collect(Collectors.groupingBy(LeaveSheetFiles::getLeaveSheetId));
|
|
|
- for (LeaveSheet record : records) {
|
|
|
- List<LeaveSheetFiles> tmpList = collect.get(record.getId());
|
|
|
- record.setLeaveSheetFiles(tmpList);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
Long total = listIPager.getTotal();
|
|
|
|