wuheng před 1 rokem
rodič
revize
4942637963

+ 1 - 1
common/src/main/java/com/koobietech/eas/common/utils/ArchiveManager.java

@@ -34,7 +34,7 @@ public class ArchiveManager {
      */
     public static String generateArchiveCode(String generateStudentCode, String fileTypeCode) {
         String studentNum = generateStudentCode.substring(2, STUDENT_NUM_LENGTH + 3);
-        String nowDate = String.valueOf(new SnowflakeManager( Long.valueOf(RandomInt(22)) , 1L).nextId()).substring(0, 13);
+        String nowDate = String.valueOf(new SnowflakeManager( Long.valueOf(RandomInt(22)) , 1L).nextId()).substring(0, 12);
         String archiveCode = ARCHIVE_CODE_PREFIX + studentNum + nowDate + fileTypeCode;
         if (archiveCode.length() < ARCHIVE_CODE_LENGTH) {
             archiveCode += UUID.randomUUID().toString()

+ 17 - 9
controller/src/main/java/com/koobietech/eas/controller/EasArcTlsFileDownloadController.java

@@ -1,33 +1,36 @@
 package com.koobietech.eas.controller;
 
 import com.koobietech.eas.common.result.JsonResult;
+import com.koobietech.eas.mbg.model.EasArcArchives;
+import com.koobietech.eas.service.EasArcArchivesService;
 import com.koobietech.eas.service.EasArchiveFileDownloadService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * @author lc
  */
 @Tag(name = "下载文件模块")
 @RestController
-@RequestMapping("/file")
+@RequestMapping("/archive")
 public class EasArcTlsFileDownloadController {
 
     @Resource
     EasArchiveFileDownloadService easArchiveFileDownloadService;
 
-    @GetMapping("/getTokenById")
+    @Resource
+    EasArcArchivesService easArcArchivesService;
+
+    @GetMapping("/getTokenByArchiveNumber")
     @Operation(summary = "获取下载token", description = "前端传入archiveId,后端返回下载token")
-    public JsonResult getFile(Integer archiveId) {
+    public JsonResult getFile(@RequestParam String archiveNumber) {
 
-        String archiveToken = easArchiveFileDownloadService.getArchiveToken(archiveId);
+        String archiveToken = easArchiveFileDownloadService.getArchiveToken(archiveNumber);
 
         return JsonResult.data(archiveToken);
     }
@@ -40,7 +43,12 @@ public class EasArcTlsFileDownloadController {
         easArchiveFileDownloadService.downloadFileByToken(archiveToken, response);
     }
 
-
+    @PostMapping("/getArchives")
+    @Operation(summary = "获取档案", description = "获取档案")
+    public JsonResult getArchives(@RequestBody EasArcArchives easArcArchives){
+        List<EasArcArchives> res = easArcArchivesService.getArchives(easArcArchives);
+        return JsonResult.data(res);
+    }
 
 
 }

+ 1 - 1
controller/src/main/resources/application-wheng.yaml

@@ -1,5 +1,5 @@
 server:
-  port: 9081
+  port: 8080
 spring:
   datasource:
     url: jdbc:mysql://127.0.0.1:13306/eas?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=true&tinyInt1isBit=false

+ 2 - 3
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -17,9 +17,8 @@ class ControllerApplicationTests {
     @Test
     void test() {
 
-        boolean b = easArchivesFilesService.refreshProfile();
-
-        System.out.println( b );
+//        boolean b = easArchivesFilesService.refreshProfile();
+//        System.out.println( b );
 
     }
 

+ 1 - 1
dao/src/main/java/com/koobietech/eas/dao/dto/GroupStudentsDto.java

@@ -17,5 +17,5 @@ public class GroupStudentsDto {
     private String type;
     private String admissionsName;
     private String managerName;
-    private Integer groupId;
+    private Integer classId;
 }

+ 1 - 0
dao/src/main/java/com/koobietech/eas/dao/pojo/GroupStudentsPojo.java

@@ -30,4 +30,5 @@ public class GroupStudentsPojo {
     private Integer admissionsId;
     private String type;
     private Integer id;
+    private Integer classId;
 }

+ 6 - 1
dao/src/main/resources/com/koobietech/eas/dao/mapper/GroupStudentsMapper.xml

@@ -16,6 +16,7 @@
         <result column="type" property="type"/>
         <result column="admissions_name" property="admissionsName"/>
         <result column="manager_name" property="managerName"/>
+        <result column="class_id" property="classId" />
     </resultMap>
     <select id="getStudents" resultType="com.koobietech.eas.dao.dto.GroupStudentsDto" resultMap="groupStudentResultMap">
         SELECT
@@ -31,6 +32,7 @@
             ss.admissions_id,
             ss.student_number,
             re.type,
+            re.class_id,
             su.relname AS admissions_name,
             suu.relname AS  manager_name
         FROM
@@ -70,6 +72,9 @@
         <if test="managerName != null and managerName != ''">
             AND suu.relname = #{managerName}
         </if>
-        AND re.class_id = #{groupId}
+        <if test="classId != null and classId > 0">
+            AND re.class_id = #{classId}
+        </if>
+
     </select>
 </mapper>

+ 12 - 0
service/src/main/java/com/koobietech/eas/service/EasArcArchivesService.java

@@ -0,0 +1,12 @@
+package com.koobietech.eas.service;
+
+import com.koobietech.eas.mbg.model.EasArcArchives;
+
+import java.util.List;
+
+/**
+ * @author lc
+ */
+public interface  EasArcArchivesService {
+    List<EasArcArchives> getArchives(EasArcArchives easArcArchives);
+}

+ 1 - 1
service/src/main/java/com/koobietech/eas/service/EasArchiveFileDownloadService.java

@@ -3,7 +3,7 @@ package com.koobietech.eas.service;
 import javax.servlet.http.HttpServletResponse;
 
 public interface EasArchiveFileDownloadService {
-    String getArchiveToken(Integer archiveId);
+    String getArchiveToken(String archiveId);
 
     String getFilePathByToken(String archiveToken);
 

+ 41 - 0
service/src/main/java/com/koobietech/eas/service/impl/EasArcArchivesServiceImpl.java

@@ -0,0 +1,41 @@
+package com.koobietech.eas.service.impl;
+
+import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
+import com.koobietech.eas.mbg.model.EasArcArchives;
+import com.koobietech.eas.mbg.model.EasArcArchivesExample;
+import com.koobietech.eas.service.EasArcArchivesService;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@Service
+public class EasArcArchivesServiceImpl implements EasArcArchivesService {
+
+    @Resource
+    EasArcArchivesMapper easArcArchivesMapper;
+
+    @Override
+    public List<EasArcArchives> getArchives(EasArcArchives easArcArchives) {
+        EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
+        EasArcArchivesExample.Criteria criteria = easArcArchivesExample.createCriteria();
+        if ( Objects.isNull(easArcArchives) ) {
+            return Collections.emptyList();
+        }
+        if (StringUtils.hasText(easArcArchives.getStudentNumber())) {
+            criteria.andStudentNumberEqualTo(easArcArchives.getStudentNumber());
+        }
+        List<EasArcArchives> easArcArchivesList = easArcArchivesMapper.selectByExample(easArcArchivesExample);
+
+        List<EasArcArchives> collect = easArcArchivesList.stream().map(arcArchives -> {
+            arcArchives.setFilePath(null);
+            return arcArchives;
+        }).collect(Collectors.toList());
+
+        return collect;
+    }
+}

+ 13 - 10
service/src/main/java/com/koobietech/eas/service/impl/EasArchiveFileDownloadServiceImpl.java

@@ -6,6 +6,7 @@ import com.koobietech.eas.common.exception.EasException;
 import com.koobietech.eas.common.utils.PasswordManager;
 import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
 import com.koobietech.eas.mbg.model.EasArcArchives;
+import com.koobietech.eas.mbg.model.EasArcArchivesExample;
 import com.koobietech.eas.service.EasArcArchiveRedisService;
 import com.koobietech.eas.service.EasArchiveFileDownloadService;
 import org.springframework.stereotype.Service;
@@ -31,19 +32,21 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
 
 
     @Override
-    public String getArchiveToken(Integer archiveId) {
+    public String getArchiveToken(String archiveNumber) {
         //在getArchiveToken中,使用UUID随机生成字符串作为k键,
         // 为了保证每次生成的字符串不同,在生成的时候加上时间戳
         // 使用根据id查询到的所需文件在本机上的地址file_path作为v值
-        // 存入redis,时间设置成三分钟
         // 获取当前时间戳
         long timestamp = System.currentTimeMillis();
         // 使用UUID生成一个唯一标识
         String uniqueId = UUID.randomUUID().toString();
         // 将用户传入的ID与时间戳和唯一标识拼接起来
-        String token = archiveId + "_" + timestamp + "_" + uniqueId;
-        System.out.println("生成的file token 拼接版:"+token);
-        EasArcArchives easArcArchives = archivesMapper.selectByPrimaryKey(archiveId);
+        String token = archiveNumber + "_" + timestamp + "_" + uniqueId;
+
+        EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
+        easArcArchivesExample.createCriteria().andArchiveNumberEqualTo(archiveNumber);
+        EasArcArchives easArcArchives = archivesMapper.selectByExample(easArcArchivesExample)
+                .stream().findFirst().orElse(null);
 
         if (Objects.isNull(easArcArchives)) {
             throw new EasException("文件不存在");
@@ -55,7 +58,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
         archiveRedisService.saveArchiveToken(token,filePath);
         // 将token返回给用户
         String archiveToken = passwordManager.archiveEncryptPassword(token);
-        System.out.println("加密生成的file token 加密版:"+archiveToken);
         return archiveToken;
 
     }
@@ -66,7 +68,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
         // 如果取出的值为空,说明token已经过期,返回null
         // 如果取出的值不为空,说明token没有过期,返回v值
         String token = passwordManager.archiveDecryptPassword(archiveToken);
-        System.out.println("解密后的file token:"+token);
         return archiveRedisService.getFilePathByToken(token);
     }
 
@@ -82,8 +83,12 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
         if (filePath == null) {
             throw new EasException("获取文件超时,请重新获取token", 4003);
         }
+
+        System.out.println( "fileExtension" + filePath );
+
         String fileExtension = getFileExtension(filePath);
-        String archiveFileType = ArchiveFileType.getContentType(fileExtension);
+
+        String archiveFileType = ArchiveFileType.getContentType(fileExtension.toLowerCase());
 
 
         if (archiveFileType != null) {
@@ -130,7 +135,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
         }
 
         String extension = filePath.substring(dotIndex);
-        System.out.println("文件后缀名:" + extension);
 
         return extension;
     }
@@ -147,7 +151,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
         }
 
         String filename = filePath.substring(dotIndex + 1);
-        System.out.println("文件名:" + filename);
 
         return filename;
     }