|
@@ -1,79 +1,141 @@
|
|
|
package com.koobietech.eas.service.impl;
|
|
|
|
|
|
import com.koobietech.eas.common.constant.FileType;
|
|
|
-import com.koobietech.eas.common.constant.FileTypeExt;
|
|
|
import com.koobietech.eas.common.utils.FileManager;
|
|
|
import com.koobietech.eas.common.utils.StudentArchiveGenerator;
|
|
|
import com.koobietech.eas.dao.dto.ArchivesDto;
|
|
|
+import com.koobietech.eas.mbg.mapper.EasArcTlsStudentsMapper;
|
|
|
+import com.koobietech.eas.mbg.model.EasArcTlsStudents;
|
|
|
+import com.koobietech.eas.mbg.model.EasArcTlsStudentsExample;
|
|
|
import com.koobietech.eas.service.EasArchivesFilesService;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.util.Date;
|
|
|
+import java.io.*;
|
|
|
+import java.util.List;
|
|
|
|
|
|
+/**
|
|
|
+ * @author lc
|
|
|
+ */
|
|
|
@Service
|
|
|
public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
|
|
|
|
|
|
@Value("${project.path}")
|
|
|
String archivesSavePath;
|
|
|
|
|
|
+ final String BAKUP_SUFFIX = ".bak";
|
|
|
+
|
|
|
@Resource
|
|
|
FileManager fileManager;
|
|
|
|
|
|
+ @Resource
|
|
|
+ EasArcTlsStudentsMapper arcTlsStudentsMapper;
|
|
|
+
|
|
|
String separator = File.separator;
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto getArchiveStudentsFile(String studentNumber) {
|
|
|
- return null;
|
|
|
+ public ArchivesDto saveArchiveAttendanceFile(String studentNumber, XWPFDocument document) {
|
|
|
+ return saveArchiveDocumentFile(studentNumber, document, FileType.XLSX.name());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto saveArchiveAttendanceFile(String studentNumber, XWPFDocument document) {
|
|
|
- String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.XLSX.getValue());
|
|
|
- String path = getArchivePath(studentNumber, archiveCode);
|
|
|
- if ( fileManager.isFileExists(path) ) {
|
|
|
- fileManager.moveFile( path, path + (new Date()).getTime() + ".back", true );
|
|
|
- }
|
|
|
- boolean status = fileManager.saveDocument(document, path);
|
|
|
- return new ArchivesDto(path, status, archiveCode, FileType.XLSX.getValue());
|
|
|
+ public ArchivesDto saveArchiveScoresFile(String studentNumber, XWPFDocument document) {
|
|
|
+ return saveArchiveDocumentFile(studentNumber, document, FileType.XLSX.name());
|
|
|
}
|
|
|
|
|
|
- private String getArchivePath(String studentNumber, String archiveCode) {
|
|
|
- String path = archivesSavePath + separator + studentNumber;
|
|
|
- fileManager.createPath(path);
|
|
|
- return path + separator + archiveCode + FileTypeExt.DOCX.getValue();
|
|
|
+ @Override
|
|
|
+ public ArchivesDto saveArchiveStudentsFile(String studentNumber, XWPFDocument document) {
|
|
|
+ return saveArchiveDocumentFile(studentNumber, document, FileType.DOCX.name());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto saveArchiveScoresFile(String studentNumber, XWPFDocument document) {
|
|
|
- return null;
|
|
|
+ public ArchivesDto saveArchiveFile(String studentNumber, Workbook workbook) {
|
|
|
+ return saveArchiveWorkbookFile(studentNumber, workbook, FileType.XLSX.name());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto saveArchiveStudentsFile(String studentNumber, XWPFDocument document) {
|
|
|
- String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.DOCX.getValue());
|
|
|
- String path = getArchivePath(studentNumber, archiveCode);
|
|
|
- boolean status = fileManager.saveDocument(document, path);
|
|
|
- return new ArchivesDto(path, status, archiveCode, FileType.DOCX.getValue());
|
|
|
+ public ArchivesDto saveArchiveFile(String studentNumber, InputStream stream, String type) {
|
|
|
+ String archiveCode = getArchiveCode(studentNumber, FileType.valueOf(type).getSuffix());
|
|
|
+ String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
|
|
|
+ boolean status = fileManager.saveFile(stream, path);
|
|
|
+ return new ArchivesDto(path, status, archiveCode, type);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ArchivesDto saveArchiveFile(String studentNumber, InputStream stream, String type) {
|
|
|
- return null;
|
|
|
+ public boolean deleteArchiveFile(String filePath) {
|
|
|
+ return fileManager.deleteFile(filePath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public OutputStream getArchiveFile(String filePath) {
|
|
|
- return null;
|
|
|
+ public FileInputStream getArchiveFile(String filePath) {
|
|
|
+ return fileManager.getArchiveFile(filePath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean deleteArchiveFile(String filePath) {
|
|
|
- return false;
|
|
|
+ public InputStream getResourceStream(String filePath) {
|
|
|
+ InputStream resourceAsStream = null;
|
|
|
+ try {
|
|
|
+ resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ return resourceAsStream;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EasArcTlsStudents getArchiveStudentsFile(String studentNumber) {
|
|
|
+ EasArcTlsStudentsExample easArcTlsStudentsExample = new EasArcTlsStudentsExample();
|
|
|
+ easArcTlsStudentsExample.createCriteria().andStudentNumberEqualTo(studentNumber);
|
|
|
+ List<EasArcTlsStudents> easArcTlsStudents = arcTlsStudentsMapper.selectByExample(easArcTlsStudentsExample);
|
|
|
+ return easArcTlsStudents.stream().findFirst().orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean backupArchiveFile(String filePath) {
|
|
|
+ boolean ret = false;
|
|
|
+ if (filePath == null || filePath.isEmpty()) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ if ( fileManager.isFileExists(filePath) ) {
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ ret = fileManager.moveFile(filePath, filePath + time + BAKUP_SUFFIX, true);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getArchiveUrl(String filePath) {
|
|
|
+ String url = null;
|
|
|
+ if (filePath == null || filePath.isEmpty()) {
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArchivesDto saveArchiveDocumentFile(String studentNumber, XWPFDocument document, String type) {
|
|
|
+ String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.valueOf(type).getSuffix());
|
|
|
+ String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
|
|
|
+ boolean status = fileManager.saveDocument(document, path);
|
|
|
+ return new ArchivesDto(path, status, archiveCode, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArchivesDto saveArchiveWorkbookFile(String studentNumber, Workbook workbook, String type) {
|
|
|
+ String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, FileType.valueOf(type).getSuffix());
|
|
|
+ String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
|
|
|
+ boolean status = fileManager.saveWorkbook(workbook, path);
|
|
|
+ return new ArchivesDto(path, status, archiveCode, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getArchiveCode(String studentNumber, String fileCode) {
|
|
|
+ return StudentArchiveGenerator.generateArchiveCode(studentNumber, fileCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getArchivePath(String studentNumber, String archiveCode, String suffix) {
|
|
|
+ String path = archivesSavePath + separator + studentNumber;
|
|
|
+ fileManager.createPath(path);
|
|
|
+ return path + separator + archiveCode + suffix;
|
|
|
+ }
|
|
|
+
|
|
|
}
|