wuheng 1 year ago
parent
commit
49f8843317

+ 15 - 0
controller/pom.xml

@@ -77,6 +77,21 @@
     </dependencyManagement>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.png</include>
+                    <include>**/*.jpeg</include>
+                    <include>**/*.xml</include>
+                    <include>**/*.docx</include>
+                    <include>**/*.xlsx</include>
+                    <include>**/*.yaml</include>
+                    <include>**/*.properties</include>
+                </includes>
+            </resource>
+        </resources>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>

+ 2 - 1
controller/src/main/java/com/koobietech/eas/controller/EasStuProfileController.java

@@ -4,6 +4,7 @@ package com.koobietech.eas.controller;
 import com.koobietech.eas.common.result.JsonResult;
 import com.koobietech.eas.mbg.model.EasArcTlsStudents;
 import com.koobietech.eas.service.EasStuProfileService;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -17,7 +18,7 @@ public class EasStuProfileController {
     @Resource
     private EasStuProfileService easStuProfileService;
 
-    @RequestMapping("/StuProfileDownload")
+    @PostMapping("/StuProfileDownload")
     public JsonResult StuProfileDownload(@RequestBody  EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException {
 
         return easStuProfileService.StuProfileDownload(easArcTlsStudents);

BIN
controller/src/main/resources/Temp/StuRegistTemp.docx


BIN
controller/src/main/resources/Temp/kun1.jpeg


BIN
controller/src/main/resources/Temp/~$uRegistTemp.docx


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

@@ -1,5 +1,5 @@
 server:
-  port: 8081
+  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

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

@@ -2,7 +2,7 @@ server:
   port: 8081
 spring:
   profiles:
-    active: local
+    active: wheng
   main:
     allow-circular-references: true
   servlet:

BIN
controller/src/main/resources/temp/kun.jpeg


+ 7 - 8
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -10,6 +10,7 @@ import org.apache.poi.xwpf.usermodel.XWPFTableCell;
 import org.apache.poi.xwpf.usermodel.XWPFTableRow;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.poi.util.Units;
 import org.springframework.stereotype.Service;
 
 import java.io.*;
@@ -20,8 +21,8 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(EasStuProfileServiceImpl.class);
     private static final String TEMPLATE_PATH = "temp/StuRegistTemp.docx";
-    private static final String PHOTO_PATH = "temp/kun1.jpeg";
-    private static final String OUTPUT_PATH = "D:\\myDesk\\test.docx";
+    private static final String PHOTO_PATH = "temp/kun.jpeg";
+    private static final String OUTPUT_PATH = "C:\\Users\\lc\\Desktop\\test.docx";
 
     @Override
     public JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) {
@@ -41,6 +42,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
             map.put("university", easArcTlsStudents.getUniversity());
 
             InputStream photo = getClass().getClassLoader().getResourceAsStream(PHOTO_PATH);
+            System.out.println( photo );
             map.put("avatar", photo);
 
             replacePlaceholders(doc, map);
@@ -76,12 +78,9 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
                                 cell.removeParagraph(0);
                                 if (value instanceof InputStream) {
                                     //如果是放置图片的单元格,在这里添加一个计算图片合适大小的方法,按比例
-
-
-
-
-                                    // 计算合适的宽度和高度
-                                    cell.addParagraph().createRun().addPicture((InputStream) value, XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg", 400000, 400000);
+                                    cell.addParagraph().createRun().addPicture((InputStream) value,
+                                            XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg",
+                                            Units.pixelToEMU(110), Units.pixelToEMU(140));
                                 } else {
                                     cell.setText(cellText.replace(placeholder, value.toString()));
                                 }