licailing пре 4 година
родитељ
комит
60adde08ac

+ 7 - 3
src/main/java/com/izouma/wenlvju/dto/ProgrammeDTO.java

@@ -71,12 +71,12 @@ public class ProgrammeDTO {
     @ExcelProperty(value = "考级点")
     private String examPoint;
 
-    @ExcelIgnore
-    private VideoObject video;
-
     @ExcelProperty(value = "参赛人数")
     private int quantity;
 
+    @ExcelProperty(value = "参赛视频")
+    private String video;
+
     @ExcelIgnore
     private int status;
 
@@ -104,6 +104,10 @@ public class ProgrammeDTO {
 
     public ProgrammeDTO(Programme programme) {
         BeanUtil.copyProperties(programme, this);
+        if (programme.getVideo() != null){
+            this.video = programme.getVideo().getSrc();
+        }
+
     }
 
     public void setParticipant(Participant participant) {

+ 50 - 9
src/main/java/com/izouma/wenlvju/service/performance/ProgrammeService.java

@@ -7,10 +7,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.ZipUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSONObject;
-import com.izouma.wenlvju.domain.ArtType;
-import com.izouma.wenlvju.domain.GradingOrganization;
-import com.izouma.wenlvju.domain.Organization;
-import com.izouma.wenlvju.domain.Setting;
+import com.izouma.wenlvju.domain.*;
 import com.izouma.wenlvju.domain.performance.*;
 import com.izouma.wenlvju.dto.ArrangeProgrammeDTO;
 import com.izouma.wenlvju.dto.PageQuery;
@@ -33,14 +30,21 @@ 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.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;
@@ -193,13 +197,16 @@ public class ProgrammeService {
 
         File destDir = TempFile.createTempDirectory("import");
         ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
-//        FileUtils.unzip(file.getInputStream(), destDir);
 
-        Map<String, File> map = FileUtils.findExcel(destDir);
-        if (map == null) return;
+        File xlsxFile = FileUtils.findExcel1(destDir);
+        if (xlsxFile == null) {
+            Map<String, File> map = FileUtils.findExcel(destDir);
+            if (map == null) return;
+
+            xlsxFile = map.get("file");
+            destDir = map.get("destDir");
+        }
 
-        File xlsxFile = map.get("file");
-        destDir = map.get("destDir");
 
         InputStream indicatorStream = new FileInputStream(xlsxFile);
         UploadDataListener<ProgrammeDTO> listener = new UploadDataListener<>();
@@ -236,6 +243,40 @@ public class ProgrammeService {
                 } else if (dto.getCompetitionGroup().equals(CompetitionGroup.COLLECTIVE)) {
                     programme.setLevelSettingId(mapMap.get(4).get(dto.getLevel()));
                 }
+
+                if (dto.getVideo() != null) {
+                    File uploadFile = new File(destDir, dto.getVideo());
+                    if (uploadFile.exists()) {
+                        // 上传
+                        String videoPath = "video/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
+                                + 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);
+                        programme.setVideo(vo);
+                    }
+                }
+
                 pid = programmeRepo.save(programme).getId();
             }
 

+ 13 - 3
src/main/java/com/izouma/wenlvju/utils/FileUtils.java

@@ -1,5 +1,6 @@
 package com.izouma.wenlvju.utils;
 
+import cn.hutool.core.util.ObjectUtil;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.*;
@@ -9,9 +10,7 @@ import java.nio.file.attribute.PosixFileAttributeView;
 import java.nio.file.attribute.PosixFileAttributes;
 import java.nio.file.attribute.PosixFilePermission;
 import java.nio.file.attribute.PosixFilePermissions;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 public class FileUtils {
 
@@ -219,4 +218,15 @@ public class FileUtils {
         return null;
     }
 
+    public static File findExcel1(File dir) {
+        if (!(dir.exists() && dir.isDirectory())) return null;
+        for (File file : dir.listFiles()) {
+            String name = file.getName().toLowerCase();
+            if ((name.endsWith(".xlsx") || name.endsWith(".xls")) && !name.startsWith(".") && !file.isHidden()) {
+                return file;
+            }
+        }
+        return null;
+    }
+
 }

+ 6 - 15
src/main/vue/src/views/performance/ProgrammeOrgList.vue

@@ -223,22 +223,13 @@
             </div>
         </el-dialog>
 
-        <el-dialog
-            class="videoDialog"
-            destroy-on-close
-            center
-            append-to-body
-            :visible.sync="showViedo"
-            @close="closeEvent"
-            width="70%"
-        >
+        <el-dialog class="videoDialog" destroy-on-close center append-to-body :visible.sync="showViedo" width="70%">
             <video
-                :src="videoUrl.src"
+                :src="videoUrl"
                 controlsList="nodownload noremote footbar"
                 controls
                 style="height: 100%; max-width: 100%"
                 oncontextmenu="return false;"
-                onmouseleave="leaveVideo(this)"
                 ref="video"
                 v-if="showViedo"
             >
@@ -591,13 +582,13 @@ export default {
             }
             return result;
         },
-        closeEvent() {
-            document.exitPictureInPicture();
-        },
+        // closeEvent() {
+        //     document.exitPictureInPicture();
+        // },
         playVideo(row) {
             this.showViedo = true;
             this.videoUrl = row.video;
-            console.log(row.video);
+            console.log(this.videoUrl);
         },
         upload() {},
         onfail(e) {