瀏覽代碼

下载模版视频

licailing 4 年之前
父節點
當前提交
ea95c48c61

+ 24 - 25
src/main/java/com/izouma/wenlvju/service/performance/ProgrammeService.java

@@ -30,21 +30,16 @@ import lombok.AllArgsConstructor;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.poi.util.TempFile;
-import org.bytedeco.javacv.FFmpegFrameGrabber;
-import org.bytedeco.javacv.Frame;
-import org.bytedeco.javacv.Java2DFrameConverter;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.imageio.ImageIO;
 import javax.persistence.criteria.Predicate;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
 import javax.transaction.Transactional;
-import java.awt.image.BufferedImage;
 import java.io.*;
-import java.net.FileNameMap;
-import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
@@ -252,24 +247,6 @@ public class ProgrammeService {
                                 + RandomStringUtils.randomAlphabetic(8)
                                 + "." + FilenameUtils.getExtension(uploadFile.getName());
                         String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), videoPath);
-
-//                        InputStream is2 = new FileInputStream(uploadFile);
-//
-//                        FFmpegFrameGrabber g = new FFmpegFrameGrabber(is2);
-//                        g.start();
-//
-//                        Frame frame = g.grabKeyFrame();
-//                        Java2DFrameConverter converter = new Java2DFrameConverter();
-//                        BufferedImage image = converter.convert(frame);
-//                        ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
-//                        ImageIO.write(image, "jpeg", baos1);
-//                        String posterPath = String.format("application/image/%s.jpg",
-//                                new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
-//                                        + RandomStringUtils.randomAlphabetic(8));
-//                        String posterUrl = storageService
-//                                .uploadFromInputStream(new ByteArrayInputStream(baos1.toByteArray()), posterPath);
-//                        g.stop();
-
                         VideoObject vo = new VideoObject();
 //                        vo.setPoster(posterUrl);
                         vo.setSrc(url);
@@ -308,6 +285,28 @@ public class ProgrammeService {
         return storageService.uploadFromInputStream(new FileInputStream(uploadFile), path);
     }
 
+    public void excelTemp(HttpServletResponse response) throws IOException {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        File file = new File(this.getClass().getResource("/templates/Programme.xlsx").getFile());
+        InputStream is = new FileInputStream(file);
+
+        byte[] buffer = new byte[1024];
+        int len;
+        while ((len = is.read(buffer)) > -1) {
+            outputStream.write(buffer, 0, len);
+        }
+        outputStream.flush();
+
+        response.setContentType("application/vnd.ms-excel");
+        response.setHeader("Content-Disposition", "attachment; filename=" + "Programme.xlsx");
+
+        ServletOutputStream sos = response.getOutputStream();
+        sos.write(outputStream.toByteArray());
+
+        sos.flush();
+        outputStream.close();
+    }
+
     @Transactional(rollbackOn = Exception.class)
     public Map<String, String> group(Arrange arrange) {
         boolean flag = true;

+ 0 - 1
src/main/java/com/izouma/wenlvju/web/RateController.java

@@ -38,7 +38,6 @@ public class RateController extends BaseController {
     private final OrganizationRepo        organizationRepo;
     private final UserRepo                userRepo;
     private final GradingOrganizationRepo gradingOrganizationRepo;
-    private final RateAuditRepo           rateAuditRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")

+ 9 - 1
src/main/java/com/izouma/wenlvju/web/performance/ProgrammeController.java

@@ -22,7 +22,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.List;
 
 @Slf4j
@@ -73,6 +72,15 @@ public class ProgrammeController extends BaseController {
         ExcelUtils.export(response, data);
     }
 
+    @GetMapping(value = "/excelTemp", produces = "application/vnd.ms-excel;charset=utf-8")
+    public void excelTemp(HttpServletResponse response) {
+        try {
+            programmeService.excelTemp(response);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
     @PostMapping("/upload")
     public void uploadFile(@RequestParam("file") MultipartFile file) {
         try {

二進制
src/main/resources/templates/Programme.xlsx


+ 23 - 0
src/main/vue/src/views/performance/ProgrammeOrgList.vue

@@ -150,6 +150,9 @@
                         :disabled="totalElements < 1"
                         >导出
                     </el-button>
+                    <el-button @click="downloadTemp" type="primary" icon="el-icon-tickets" :loading="downloading"
+                        >模版
+                    </el-button>
                 </el-form-item>
             </el-form>
         </div>
@@ -520,6 +523,26 @@ export default {
                     this.$message.error(e.error);
                 });
         },
+        downloadTemp() {
+            this.$axios
+                .get('/programme/excelTemp')
+                .then(res => {
+                    console.log(res);
+                    this.downloading = false;
+                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+                    const link = document.createElement('a');
+                    link.href = downloadUrl;
+                    link.setAttribute('download', '模板.xlsx');
+                    document.body.appendChild(link);
+                    link.click();
+                    link.remove();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    this.$message.error(e.error);
+                });
+        },
         operation1() {
             this.$notify({
                 title: '提示',

+ 2 - 1
src/main/vue/src/views/video/HistoryRoomList.vue

@@ -59,7 +59,8 @@
         <el-dialog title="视频地址" :visible.sync="dialogVideoUrl" width="600px" center="">
             <span style="margin-right: 20px;">输入视频地址</span><el-input style="width: 400px"></el-input>
             <div style="margin: 20px 200px 0">
-                <el-button type="success" size="mini" plain>确定</el-button><el-button size="mini">取消</el-button>
+                <el-button type="success" size="mini" plain>确定</el-button
+                ><el-button @click="dialogVideoUrl = false" size="mini">取消</el-button>
             </div>
         </el-dialog>
     </div>

+ 5 - 6
src/test/java/com/izouma/wenlvju/repo/RepoTest.java

@@ -11,6 +11,8 @@ import com.izouma.wenlvju.service.storage.StorageService;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -173,11 +175,8 @@ public class RepoTest extends ApplicationTests {
 
     @Test
     public void test4(){
-        Organization byUscc = organizationRepo.findByUscc("91320115302475327Q");
-//        if (ObjectUtil.isNotNull(byUscc)) {
-//            if (!byUscc.getId().equals(orig.getId())) {
-//                throw new BusinessException("该统一社会信用代码已被注册");
-//            }
-//        }
+        Path path = Paths.get(System.getProperty("user.dir"), "src", "main", "resources", "templates", "Programme.xlsx");
+        System.out.println(this.getClass().getResource("/templates/Programme.xlsx").getFile());
+        System.out.println(this.getClass().getResource("Programme.xlsx").getPath());
     }
 }