Explorar el Código

解决导入文件未替换值的问题

superb hace 1 año
padre
commit
e347f3de3c

+ 42 - 48
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -34,7 +34,6 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
 
     private static final String TEMPLATE_PATH = "temp/StuRegistTemp.docx";
     private static final String PHOTO_PATH = "temp/kun.jpeg";
-
     @Resource
     private EasArcTlsStudentsMapper easArcTlsStudentsMapper;
     @Resource
@@ -45,10 +44,11 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
     private EasArcArchivesMapper easArcArchivesMapper;
     @Resource
     private EasArchivesFilesService easArchivesFilesService;
-    @Override
 
+    @Override
     public boolean StuProfileDownload(EasArcTlsStudents easArcTlsStudents, Integer manager_id) {
 
+        //使用try-with-resources 语句 保证流的关闭
         try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
             assert wordStream != null;
             try (XWPFDocument doc = new XWPFDocument(wordStream)) {
@@ -67,7 +67,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
                     throw new EasException("EasSysStudents保存失败", 8001);
                 }
                 //这里会生成一个学生档案保存本地 目前这里有bug保存不成功 而且文件后缀有错误
-                boolean isEasArcArchives = insertEasArcArchives(easArcTlsStudents, studentNumber, manager_id);
+                boolean isEasArcArchives = insertEasArcArchives(easArcTlsStudents, studentNumber, manager_id, doc);
                 if (!isEasArcArchives) {
                     throw new EasException("EasArcArchives保存失败", 8002);
                 }
@@ -78,7 +78,6 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
         return true;
     }
 
-
     private Map<String, Object> generateDataMap(EasArcTlsStudents easArcTlsStudents, String studentNumber) {
         Map<String, Object> map = new HashMap<>();
         map.put("student_name", easArcTlsStudents.getStudentName());
@@ -94,49 +93,42 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
         return map;
     }
 
-    public boolean insertEasArcArchives(EasArcTlsStudents easArcTlsStudents, String studentNumber, Integer managerId) {
-        try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
-            assert wordStream != null;
-            try (XWPFDocument doc = new XWPFDocument(wordStream)) {
-                // 生成档案号
-                String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX));
-
-                // 保存学员档案文件
-                ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
-                String filePath = archivesDto.getPath();
-                String arcType = archivesDto.getFileType();
-
-                // 设置时间和有效期
-                Date createTime = DateUtils.convertToYearMonthDayToDate(new Date());
-                Date modifyTime = new Date();
-                Calendar calendar = Calendar.getInstance();
-                assert createTime != null;
-                calendar.setTime(createTime);
-                calendar.add(Calendar.YEAR, 1);
-                Date validityTime = calendar.getTime();
-
-                // 创建 EasArcArchives 对象并设置属性
-                EasArcArchives easArcArchives = new EasArcArchives();
-                easArcArchives.setArchiveNumber(archiveCode);
-                easArcArchives.setStudentNumber(studentNumber);
-                easArcArchives.setFilePath(filePath);
-                easArcArchives.setArctype(arcType);
-                easArcArchives.setCreateTime(createTime);
-                easArcArchives.setModifyTime(modifyTime);
-                easArcArchives.setValidityTime(validityTime);
-                easArcArchives.setManagerId(managerId);
-                easArcArchives.setCreateUid(1);
-                easArcArchives.setCreateDate(new Date());
-
-                // 插入到数据库
-                int result = easArcArchivesMapper.insert(easArcArchives);
-
-                // 返回是否成功插入数据库
-                return result > 0;
-            }
-        } catch (IOException e) {
-            return false;
-        }
+    public boolean insertEasArcArchives(EasArcTlsStudents easArcTlsStudents, String studentNumber, Integer managerId, XWPFDocument doc) {
+        // 生成档案号
+        String archiveCode = StudentArchiveGenerator.generateArchiveCode(studentNumber, String.valueOf(FileType.DOCX));
+
+        // 保存学员档案文件
+        ArchivesDto archivesDto = easArchivesFilesService.saveArchiveStudentsFile(easArcTlsStudents.getStudentIdnumber(), doc);
+        String filePath = archivesDto.getPath();
+        String arcType = archivesDto.getFileType();
+
+        // 设置时间和有效期
+        Date createTime = DateUtils.convertToYearMonthDayToDate(new Date());
+        Date modifyTime = new Date();
+        Calendar calendar = Calendar.getInstance();
+        assert createTime != null;
+        calendar.setTime(createTime);
+        calendar.add(Calendar.YEAR, 1);
+        Date validityTime = calendar.getTime();
+
+        // 创建 EasArcArchives 对象并设置属性
+        EasArcArchives easArcArchives = new EasArcArchives();
+        easArcArchives.setArchiveNumber(archiveCode);
+        easArcArchives.setStudentNumber(studentNumber);
+        easArcArchives.setFilePath(filePath);
+        easArcArchives.setArctype(arcType);
+        easArcArchives.setCreateTime(createTime);
+        easArcArchives.setModifyTime(modifyTime);
+        easArcArchives.setValidityTime(validityTime);
+        easArcArchives.setManagerId(managerId);
+        easArcArchives.setCreateUid(1);
+        easArcArchives.setCreateDate(new Date());
+
+        // 插入到数据库
+        int result = easArcArchivesMapper.insert(easArcArchives);
+
+        // 返回是否成功插入数据库
+        return result > 0;
     }
 
 
@@ -198,4 +190,6 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
             }
         }
     }
-}
+}
+
+