ソースを参照

档案新增 和 删除

wuheng 1 年間 前
コミット
a1e13f7119

+ 4 - 3
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -294,14 +294,15 @@ public class FileManager {
             int bytesRead;
             byte[] buffer = new byte[1024];
             while ((bytesRead = stream.read(buffer)) != -1){
-                fileOutputStream.write(bytesRead);
+                fileOutputStream.write(buffer, 0, bytesRead);
             }
         } catch (IOException e) {
             return  false;
         } finally {
             try {
-                if (Objects.nonNull(fileOutputStream))
-                fileOutputStream.close();
+                if (Objects.nonNull(fileOutputStream)) {
+                    fileOutputStream.close();
+                }
             }catch (IOException e){}
         }
         return true;

+ 0 - 10
common/src/test/java/com/koobietech/eas/common/utils/PasswordManagerTest.java

@@ -6,15 +6,5 @@ class PasswordManagerTest {
 
     public static void main(String[] args) {
 
-        System.out.println(
-
-
-                (new SnowflakeManager( 12L , 1L)).nextId()
-
-
-        );
-
-
     }
-
 }

+ 26 - 0
controller/src/main/java/com/koobietech/eas/controller/EasSysStuProfileController.java

@@ -5,7 +5,9 @@ import com.github.pagehelper.PageHelper;
 import com.koobietech.eas.common.result.JsonPageResult;
 import com.koobietech.eas.common.result.JsonResult;
 import com.koobietech.eas.common.result.PageDataResult;
+import com.koobietech.eas.dao.dto.ArchivesDto;
 import com.koobietech.eas.dao.dto.EasArcTlsStudentsDto;
+import com.koobietech.eas.mbg.model.EasArcArchives;
 import com.koobietech.eas.mbg.model.EasArcTlsStudents;
 import com.koobietech.eas.mbg.model.EasSysStudent;
 import com.koobietech.eas.service.EasStuProfileService;
@@ -52,6 +54,30 @@ public class EasSysStuProfileController {
         boolean result = easStuProfileService.update(studentDto);
         return JsonResult.bool(result);
     }
+
+    @PostMapping("/upload")
+    @Operation(summary = "上传档案", description = "上传档案")
+    public JsonResult upload(MultipartFile file,
+                             @RequestParam String fileType,
+                             @RequestParam String studentNumber){
+        ArchivesDto upload = easStuProfileService.upload(file, studentNumber, fileType);
+        return JsonResult.data(upload.getPath());
+    }
+
+    @PostMapping("/addArchives")
+    @Operation(summary = "添加学员档案", description = "添加学员档案")
+    public JsonResult addArchives(@RequestBody EasArcArchives arc){
+        boolean res =  easStuProfileService.addArchives(arc);
+        return JsonResult.bool(res);
+    }
+
+    @DeleteMapping("/delArchives/{id}")
+    @Operation(summary = "删除档案", description = "删除档案")
+    public JsonResult addArchives(@PathVariable Integer id){
+        boolean res =  easStuProfileService.delArchives(id);
+        return JsonResult.bool(res);
+    }
+
     @PostMapping("/query")
     @Operation(summary = "查询学员信息", description = "查询学员信息")
     public JsonPageResult query(@RequestBody(required = false) EasArcTlsStudents studentDto,

+ 8 - 0
service/src/main/java/com/koobietech/eas/service/EasStuProfileService.java

@@ -2,8 +2,10 @@ package com.koobietech.eas.service;
 
 import com.koobietech.eas.common.result.PageDataResult;
 import com.koobietech.eas.dao.dto.ArchivesDto;
+import com.koobietech.eas.mbg.model.EasArcArchives;
 import com.koobietech.eas.mbg.model.EasArcTlsStudents;
 import com.koobietech.eas.mbg.model.EasSysStudent;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.InputStream;
 import java.util.List;
@@ -27,4 +29,10 @@ public interface EasStuProfileService {
     List<EasSysStudent> getStudentByKeyword(String keyword);
 
     ArchivesDto saveUserFile(EasArcTlsStudents easArcTlsStudents);
+
+    ArchivesDto upload(MultipartFile file, String studentNumber, String fileType);
+
+    boolean addArchives(EasArcArchives arc);
+
+    boolean delArchives(Integer id);
 }

+ 8 - 1
service/src/main/java/com/koobietech/eas/service/impl/EasArchivesFilesServiceImpl.java

@@ -91,7 +91,7 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
      */
     public ArchivesDto saveArchiveFile(String studentNumber, InputStream stream, String type) {
         String archiveCode = getArchiveCode(studentNumber, String.valueOf(FileType.valueOf(type).getValue()));
-        String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix());
+        String path = getArchivePath(studentNumber, archiveCode, FileType.valueOf(type).getSuffix(), "other");
         boolean status = fileManager.saveFile(stream, path);
         return new ArchivesDto(path, status, archiveCode, type);
     }
@@ -213,7 +213,14 @@ public class EasArchivesFilesServiceImpl implements EasArchivesFilesService {
     }
 
     private String getArchivePath(String studentNumber, String archiveCode, String suffix) {
+        return getArchivePath(studentNumber,  archiveCode, suffix, null);
+    }
+
+    private String getArchivePath(String studentNumber, String archiveCode, String suffix, String level) {
         String path = archivesSavePath + separator + studentNumber;
+        if ( Objects.nonNull(level) ) {
+            path = path + separator + level;
+        }
         fileManager.createPath(path);
         return path + separator + archiveCode + suffix;
     }

+ 71 - 0
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -30,6 +30,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.io.IOException;
@@ -93,6 +94,76 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
         return archivesDto;
     }
 
+    @Override
+    public ArchivesDto upload(MultipartFile file, String studentNumber, String fileType) {
+        InputStream inputStream = null;
+        ArchivesDto archivesDto = null;
+        try {
+            inputStream = file.getInputStream();
+            String type = file.getOriginalFilename().substring(
+                    file.getOriginalFilename().lastIndexOf(".") + 1).toUpperCase();
+            if ( FileType.valueOf(type) != null ) {
+                archivesDto = easArchivesFilesService.saveArchiveFile(studentNumber, inputStream, type);
+            }
+        } catch (IOException ignore) {
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException ignore) {}
+            }
+        }
+        return archivesDto;
+    }
+
+    /**
+     * 判断是否是图片后缀的文件
+     * @param path
+     * @return
+     */
+
+    private boolean isImage(String path) {
+        String filePath = path.toUpperCase();
+        return filePath.endsWith(".JPG") || filePath.endsWith(".JPEG")
+                || filePath.endsWith(".PNG") || filePath.endsWith(".GIF") ||
+                filePath.endsWith(".BMP") || filePath.endsWith(".TIF")
+                 || filePath.endsWith(".TIFF") ||  filePath.endsWith(".ICO");
+    }
+    @Override
+    public boolean addArchives(EasArcArchives arc) {
+        String arctype = "";
+        if ( isImage(arc.getFilePath()) ) {
+            arctype =  "IMAGE";
+        } else {
+            arctype = arc.getFilePath().substring(arc.getFilePath().lastIndexOf(".") + 1).toUpperCase();
+        }
+        String archiveNumber = arc.getFilePath().substring(
+                arc.getFilePath().lastIndexOf("\\") + 1,
+                arc.getFilePath().lastIndexOf("."));
+        arc.setArctype(arctype);
+        arc.setCreateTime(new Date());
+        arc.setModifyTime(new Date());
+        arc.setArchiveNumber( archiveNumber );
+        arc.setManagerId( SecurityManager.getLoginUid().intValue() );
+        arc.setCreateUid( SecurityManager.getLoginUid().intValue() );
+        arc.setCreateDate(new Date());
+        return easArcArchivesMapper.insert(arc) == 1;
+    }
+
+    @Override
+    public boolean delArchives(Integer id) {
+        EasArcArchives easArcArchives = easArcArchivesMapper.selectByPrimaryKey(id);
+        if (
+            easArcArchives.getFiletype().equals("prefile") ||
+            easArcArchives.getFiletype().equals("attendance") ||
+            easArcArchives.getFiletype().equals("scores")
+        ) {
+            return false;
+        }
+        easArchivesFilesService.deleteArchiveFile(easArcArchives.getFilePath());
+        return easArcArchivesMapper.deleteByPrimaryKey(id) == 1;
+    }
+
     @Override
     public boolean add(EasArcTlsStudents easArcTlsStudents) {