Browse Source

大屏数据调整提交

user5 1 year ago
parent
commit
08acf56d6c

+ 15 - 3
jeeplus-modules/jeeplus-test/src/main/java/com/jeeplus/test/wdt/merchantCompany/controller/MerchantDetailsController.java

@@ -91,10 +91,10 @@ public class MerchantDetailsController {
     @ApiLog("保存大屏名称")
     @ApiOperation(value = "保存大屏名称")
     @PostMapping("screenSave")
-    public  ResponseEntity <String> screenSave(String screenName) {
+    public  ResponseEntity <String> screenSave(String screenName,String filePath) {
         //新增或编辑表单保存
-        merchantDetailsService.screenSave (screenName);
-        return ResponseEntity.ok ( "保存大屏名称成功" );
+        merchantDetailsService.screenSave (screenName,filePath);
+        return ResponseEntity.ok ( "保存大屏信息成功" );
     }
 
 
@@ -124,5 +124,17 @@ public class MerchantDetailsController {
     }
 
 
+    /**
+     * 查询入驻信息数据(大屏数据)
+     */
+    @ApiLog("查询大屏视频播放url")
+    @ApiOperation(value = "查询大屏视频播放url")
+    @GetMapping("getFilePathUrl")
+    public Map<String,String> getFilePathUrl() {
+        Map<String,String> map = merchantDetailsService.getFilePathUrl ();
+        return map;
+    }
+
+
 
 }

+ 2 - 2
jeeplus-modules/jeeplus-test/src/main/java/com/jeeplus/test/wdt/merchantCompany/controller/MerchantProductController.java

@@ -129,7 +129,7 @@ public class MerchantProductController {
             categories.add(info.getName());
             data.add(info.getMonthlySalesVolume());
         }
-        map1.put("name","月销售额(元)");
+        //map1.put("name","月销售额(元)");
         map1.put("data",data);
         series.add(map1);
         map.put("categories",categories);
@@ -150,7 +150,7 @@ public class MerchantProductController {
         for (MerchantProductDTO info : listJson) {
             Map<String,String> mapInfo = new HashMap<>();
             mapInfo.put("name",info.getName());
-            mapInfo.put("value",info.getSalesVolume());
+            mapInfo.put("value",info.getSaleroom());
             mapInfo.put("url","");
             mapList.add(mapInfo);
         }

+ 99 - 1
jeeplus-modules/jeeplus-test/src/main/java/com/jeeplus/test/wdt/merchantCompany/service/MerchantDetailsService.java

@@ -16,9 +16,11 @@ import com.jeeplus.test.wdt.merchantCompany.service.dto.MerchantDetailsDTO;
 import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.MerchantDetailsWrapper;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.File;
 import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
@@ -42,6 +44,9 @@ public class MerchantDetailsService extends ServiceImpl<MerchantDetailsMapper, M
     @Autowired
     private DictTypeService dictTypeService;
 
+    @Value("${merchantFilePath}")
+    private String merchantFilePath;
+
 
     /**
      * 查询详情
@@ -71,6 +76,18 @@ public class MerchantDetailsService extends ServiceImpl<MerchantDetailsMapper, M
                 }
             }
         }
+
+        //查询字典中 大屏视频路径
+        List<DictValueDTO> merchantFilePathList = DictUtils.getDictDTOList("merchant_file_path");
+        if(merchantFilePathList.size()>0){
+            for (DictValueDTO dictValueDTO : merchantFilePathList) {
+                if("name".equals(dictValueDTO.getLabel())){
+                    if(null != limit1){
+                        limit1.setPath(dictValueDTO.getValue());
+                    }
+                }
+            }
+        }
         return limit1;
     }
 
@@ -112,7 +129,7 @@ public class MerchantDetailsService extends ServiceImpl<MerchantDetailsMapper, M
      *
      * @param screenName
      */
-    public void screenSave(String screenName) {
+    public void screenSave(String screenName, String filePath) {
 
 
         //查询字典中数据获取方式并修改
@@ -126,6 +143,54 @@ public class MerchantDetailsService extends ServiceImpl<MerchantDetailsMapper, M
                 }
             }
         }
+
+        //查询字典中数据获取方式并修改
+        List<DictValueDTO> merchantFilePathList = DictUtils.getDictDTOList("merchant_file_path");
+        if(merchantFilePathList.size()>0){
+            String newFilePath = filePath;
+            filePath = filePath.replace("/file/download?path=","");
+            filePath = filePath.replace("&name=","");
+            //对视频路径进行解析
+
+            String fileName = "";
+            String fileAbsolutePath = "";
+            int lastIndex = filePath.lastIndexOf('/');
+            if (lastIndex != -1) {
+                fileName = filePath.substring(lastIndex + 1);
+                fileAbsolutePath = filePath.substring(0,lastIndex);
+            } else {
+            }
+            for (DictValueDTO dictValueDTO : merchantFilePathList) {
+                if("name".equals(dictValueDTO.getLabel())){
+                    dictValueDTO.setValue(newFilePath);
+                    DictValue dictValue = dictValueWrapper.toEntity ( dictValueDTO );
+                    dictTypeService.saveDictValue(dictValue);
+                    //数据处理完成后将原有的视频文件也进行删除
+
+                    File folder = new File(fileAbsolutePath); // 替换为你的文件夹路径
+                    deleteFiles(folder,fileName);
+                }
+            }
+        }
+    }
+
+    public static void deleteFiles(File folder,String newFileName) {
+        File[] files = folder.listFiles();
+        if (files != null) { // 确保文件数组不为空
+            for (File file : files) {
+                if (file.isFile()) {
+                    String fileName = file.getName();
+                    if (!fileName.equals(newFileName)) {
+                        boolean deleted = file.delete();
+                        if (deleted) {
+                            System.out.println("File deleted: " + file.getAbsolutePath());
+                        } else {
+                            System.out.println("Failed to delete file: " + file.getAbsolutePath());
+                        }
+                    }
+                }
+            }
+        }
     }
 
     /**
@@ -228,4 +293,37 @@ public class MerchantDetailsService extends ServiceImpl<MerchantDetailsMapper, M
         return map;
     }
 
+
+    /**
+     * 获取大屏视频url
+     * @return
+     */
+    public Map<String,String> getFilePathUrl(){
+        Map<String,String> map = new HashMap<>();
+        map.put("value","");
+        //查询字典中 大屏名称信息
+        List<DictValueDTO> screenNameList = DictUtils.getDictDTOList("merchant_file_path");
+        if(screenNameList.size()>0){
+            for (DictValueDTO dictValueDTO : screenNameList) {
+                if("name".equals(dictValueDTO.getLabel())){
+
+                    //视频文件地址
+                    String filePath = dictValueDTO.getValue();
+                    filePath = filePath.replace("/file/download?path=","");
+                    filePath = filePath.replace("&name=","");
+                    //对视频路径进行解析
+
+                    String fileName = "";
+                    int lastIndex = filePath.lastIndexOf('/');
+                    if (lastIndex != -1) {
+                        fileName = filePath.substring(lastIndex + 1);
+                    }
+                    String url = merchantFilePath + "/img/video/" + fileName;
+                    map.put("value",url);
+                }
+            }
+        }
+        return map;
+    }
+
 }

+ 5 - 0
jeeplus-modules/jeeplus-test/src/main/java/com/jeeplus/test/wdt/merchantCompany/service/dto/MerchantDetailsDTO.java

@@ -78,4 +78,9 @@ public class MerchantDetailsDTO extends BaseDTO {
      * 大屏名称
      */
     private String screenName;
+
+    /**
+     * 大屏视频路径
+     */
+    private String path;
 }

+ 4 - 0
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/config/FileProperties.java

@@ -46,6 +46,10 @@ public class FileProperties {
         return false;
     }
 
+    public boolean isVideoAvailable(String fileName) {
+        return isContain ( videoExtensions, fileName );
+    }
+
     public boolean isImage(String fileName) {
         return isContain ( imageExtensions, fileName );
     }

+ 152 - 9
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/controller/FileController.java

@@ -13,6 +13,7 @@ import org.springframework.core.io.InputStreamResource;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.StreamUtils;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -21,10 +22,7 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.Calendar;
 
 /**
@@ -68,6 +66,35 @@ public class FileController {
     }
 
     /**
+     * 获取文件网络地址
+     *
+     * @return
+     * @throws IOException
+     * @throws IllegalStateException
+     */
+    @GetMapping("videoDownload")
+    public void videoDownload(String uploadPath, String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        String url = "";
+        if(null == uploadPath || "".equals(uploadPath)){
+            if(System.getProperty("os.name").toLowerCase().contains("win")){
+                uploadPath = "D:/java_project/wdt_ERP_new/wdt_ERP_process_vue/public/img/video/";;
+            }else{
+                uploadPath = "/etc/nginx/html/img/video/";
+            }
+            url = accessoryRepository.getVideoURL ( uploadPath, name ,request, response);
+        }else{
+            url = accessoryRepository.getURL ( uploadPath, name ,request, response);
+        }
+        if( StrUtil.isNotEmpty ( url ) ){
+            try {
+                response.sendRedirect ( url );
+            } catch (IOException e) {
+                throw new Exception ( "文件不存在!" );
+            }
+        }
+    }
+
+    /**
      * 上传文件
      *
      * @return
@@ -86,7 +113,7 @@ public class FileController {
             if ( fileProperties.isAvailable ( name ) ) {
                 // 文件保存路径
                 // 转存文件
-                accessoryRepository.save ( file, uploadPath, name );
+                //accessoryRepository.save ( file, uploadPath, name );
                 return ResponseEntity.ok ( FILE_SERVER + "/download?uploadPath=" + uploadPath + "&name=" + name );
 
             } else {
@@ -97,6 +124,112 @@ public class FileController {
         }
     }
 
+    /**
+     * 上传文件
+     *
+     * @return
+     * @throws IOException
+     */
+    @RequestMapping("videoUpload")
+    public ResponseEntity videoUpload(HttpServletRequest request, MultipartFile file, String uploadPath) {
+
+        Calendar cal = Calendar.getInstance ( );
+        int year = cal.get ( Calendar.YEAR );
+        int month = cal.get ( Calendar.MONTH ) + 1;
+        String path = "";
+        if(System.getProperty("os.name").toLowerCase().contains("win")){
+            path = "D:/java_project/wdt_ERP_new/wdt_ERP_process_vue/public/img/video/";;
+        }else{
+            path = "/etc/nginx/html/img/video/";
+        }
+        // 判断文件是否为空
+        if ( !file.isEmpty ( ) ) {
+            String name = file.getOriginalFilename ( );
+            if ( fileProperties.isVideoAvailable ( name ) ) {
+                saveMultipartFile(file,path);
+                // 文件保存路径
+                // 转存文件
+                //accessoryRepository.save ( file, path, name );
+                return ResponseEntity.ok ( FILE_SERVER + "/videoDownload?path=" + path + "&name=" + name );
+
+            } else {
+                return ResponseEntity.badRequest ( ).body ( "请勿上传非法文件!" );
+            }
+        } else {
+            return ResponseEntity.badRequest ( ).body ( "文件不存在!" );
+        }
+    }
+
+    /**
+     * @param file
+     * @param targetDirPath 存储MultipartFile文件的目标文件夹
+     * @return 文件的存储的绝对路径
+     */
+    public static String saveMultipartFile(MultipartFile file, String targetDirPath) {
+
+        File toFile = null;
+        if (file.equals("") || file.getSize() <= 0) {
+            return null;
+        } else {
+
+            /*获取文件原名称*/
+            String originalFilename = file.getOriginalFilename();
+            /*获取文件格式*/
+            String fileFormat = originalFilename.substring(originalFilename.lastIndexOf("."));
+
+            toFile = new File(targetDirPath + File.separator + originalFilename);
+
+            String absolutePath = null;
+            try {
+                absolutePath = toFile.getCanonicalPath();
+
+                /*判断路径中的文件夹是否存在,如果不存在,先创建文件夹*/
+                String dirPath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
+                File dir = new File(dirPath);
+                if (!dir.exists()) {
+                    dir.mkdirs();
+                }
+
+                InputStream ins = file.getInputStream();
+
+                inputStreamToFile(ins, toFile);
+                ins.close();
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            return absolutePath;
+        }
+
+    }
+
+    //获取流文件
+    private static void inputStreamToFile(InputStream ins, File file) {
+        try {
+            OutputStream os = new FileOutputStream(file);
+            int bytesRead = 0;
+            byte[] buffer = new byte[8192];
+            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
+                os.write(buffer, 0, bytesRead);
+            }
+            os.close();
+            ins.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 删除本地临时文件
+     *
+     * @param file
+     */
+    public static void deleteTempFile(File file) {
+        if (file != null) {
+            File del = new File(file.toURI());
+            del.delete();
+        }
+    }
 
 
     /**
@@ -133,16 +266,26 @@ public class FileController {
         Calendar cal = Calendar.getInstance ( );
         int year = cal.get ( Calendar.YEAR );
         int month = cal.get ( Calendar.MONTH ) + 1;
-        String uploadPath = request.getParameter ( "uploadPath" ) + "/" + year + "/" + month + "/";
-        ;
+
+        String path = "";
+        if(System.getProperty("os.name").toLowerCase().contains("win")){
+            path = "D:/java_project/wdt_ERP_new/wdt_ERP_process_vue/public/img/video/";;
+        }else{
+            path = "/etc/nginx/html/img/video/";
+        }
+
+        //String uploadPath = request.getParameter ( "uploadPath" ) + "/" + year + "/" + month + "/";
+
         // 判断文件是否为空
         if ( !file.isEmpty ( ) ) {
             String name = file.getOriginalFilename ( );
             if ( fileProperties.isAvailable ( name ) ) {
+                saveMultipartFile(file,path);
                 // 文件保存路径
                 // 转存文件
-                accessoryRepository.save ( file, uploadPath, name );
-                return ResponseEntity.ok ( FILE_SERVER + "/downloadFile?uploadPath=" + uploadPath + "&name=" + name );
+                //accessoryRepository.save ( file, uploadPath, name );
+                //return ResponseEntity.ok ( FILE_SERVER + "/downloadFile?uploadPath=" + uploadPath + "&name=" + name );
+                return ResponseEntity.ok ( FILE_SERVER + "/downloadFile?path=" + path + "&name=" + name );
 
             } else {
                 return ResponseEntity.badRequest ( ).body ( "请勿上传非法文件!" );

+ 2 - 0
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/repository/AccessoryRepository.java

@@ -26,6 +26,8 @@ public interface AccessoryRepository {
 
     String getURL(String path, String fileName, HttpServletRequest request, HttpServletResponse response) throws FunctionNotSupportedException, FileNotFoundException;
 
+    String getVideoURL(String path, String fileName, HttpServletRequest request, HttpServletResponse response) throws FunctionNotSupportedException, FileNotFoundException;
+
     /**
      * 根据保存的相对路径获取可下载文件的完整http路径
      *

+ 6 - 0
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/repository/AliyunOSSRepository.java

@@ -6,6 +6,7 @@ import com.aliyun.oss.OSSException;
 import com.aliyun.oss.model.OSSObject;
 import com.aliyun.oss.model.ObjectMetadata;
 import com.aliyun.oss.model.PutObjectRequest;
+import com.jeeplus.file.repository.Exception.FunctionNotSupportedException;
 import com.jeeplus.file.utils.FileUtils;
 import org.apache.commons.lang3.time.DateUtils;
 import org.slf4j.Logger;
@@ -102,6 +103,11 @@ public class AliyunOSSRepository implements AccessoryRepository {
         }
     }
 
+    @Override
+    public String getVideoURL(String path, String fileName, HttpServletRequest request, HttpServletResponse response) throws FunctionNotSupportedException, FileNotFoundException {
+        return null;
+    }
+
 
     /**
      * 保存文件对象

+ 18 - 0
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/repository/LocalRepository.java

@@ -1,6 +1,7 @@
 package com.jeeplus.file.repository;
 
 import cn.hutool.core.util.StrUtil;
+import com.jeeplus.file.repository.Exception.FunctionNotSupportedException;
 import com.jeeplus.file.utils.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,6 +84,23 @@ public class LocalRepository implements AccessoryRepository {
         return null;
     }
 
+    @Override
+    public String getVideoURL(String path, String fileName, HttpServletRequest request, HttpServletResponse response) throws FunctionNotSupportedException, FileNotFoundException {
+        logger.debug ( "开始从本地存储获取文件: {}{}{}", location + File.separator + accessoryBaseDir + File.separator + path, File.separator, fileName );
+        long begin = System.currentTimeMillis ( );
+        File fileDir = new File (path );
+        if ( !fileDir.exists ( ) || !fileDir.isDirectory ( ) ) {
+            throw new FileNotFoundException ( "指定的目录不存在" );
+        }
+        File srcFile = new File ( fileDir, fileName );
+        if ( !srcFile.exists ( ) || !srcFile.isFile ( ) ) {
+            throw new FileNotFoundException ( "指定的文件不存在" );
+        }
+        this.downRangeFile (srcFile, request, response );
+        logger.debug ( "完成从本地存储获取文件: {}", System.currentTimeMillis ( ) - begin );
+        return null;
+    }
+
     public void downRangeFile(File downloadFile, HttpServletRequest request, HttpServletResponse response) {
 
         // 文件不存在

+ 6 - 0
jeeplus-plugins/jeeplus-file/src/main/java/com/jeeplus/file/repository/MinIORepository.java

@@ -2,6 +2,7 @@ package com.jeeplus.file.repository;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
+import com.jeeplus.file.repository.Exception.FunctionNotSupportedException;
 import com.jeeplus.file.utils.CommonUtils;
 import com.jeeplus.file.utils.FileUtils;
 import io.minio.*;
@@ -101,6 +102,11 @@ public class MinIORepository implements AccessoryRepository {
         }
     }
 
+    @Override
+    public String getVideoURL(String path, String fileName, HttpServletRequest request, HttpServletResponse response) throws FunctionNotSupportedException, FileNotFoundException {
+        return null;
+    }
+
 
     /**
      * 保存文件对象

+ 4 - 3
jeeplus-web/src/main/resources/application-development.yml

@@ -25,8 +25,8 @@ logging:
 spring:
   servlet:
     multipart:
-      maxFileSize:  1000MB
-      maxRequestSize: 1000MB
+      maxFileSize:  2048MB
+      maxRequestSize: 2048MB
   devtools:
     restart:
       enabled: true
@@ -192,7 +192,7 @@ file:
     file: 7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip       # 只允许上传安全文件(linux系统非可执行)
     image: gif,jpg,jpeg,bmp,png     # 只允许上传图片
     audio: CD,OGG,MP3,ASF,WMA,WAV,MP3PRO,RM,REAL,APE,MODULE,MIDI,VQF    # 只允许上传音频
-    video: AVI,WMV,RM,RMVB,MPEG1,MPEG2,MPEG4(MP4),3GP,ASF,SWF,VOB,DAT,MOV,M4V,FLV,F4V,MKV,MTS,TS     # 只允许上传视频
+    video: AVI,WMV,RM,RMVB,MPEG1,MPEG2,MPEG4(MP4),3GP,ASF,SWF,VOB,DAT,MOV,M4V,FLV,F4V,MKV,MTS,TS,avi,wmv,rm,rmvb,mpeg1,mpeg2,mpeg4(mp4),3gp,asf,swf,vob,dat,mov,m4v,flv,f4v,mkv,mts,ts,MP4,mp4     # 只允许上传视频
     office: txt,xls,xlsx,xlsm,xltx,xltm,xlsb,xlam,doc,docx,docm,dotx,dotm,ppt,pptx,pptm,ppsx,ppsm,potx,potm,ppam     # 只允许上传office文件
 
 #token过期时间
@@ -214,6 +214,7 @@ productId: Y20221228521
 license: 311B824D79A418AE3AB54AB16327659EAFAA9188049FFB6ED5A62658E884A677B70162FA76FF6E7DD78AF7332D8A323D432518CBEC58ACC6396CA8CA13D4BFA55150AFC7180CC9DE9A9BDFDB5590DD47B88A588DC6C42A0A233BB1723047BCC660840D1A97A43F91D02CC42FC808A886F49F03B958BB222B3A66FDF0AF23CF50
 
 
+merchantFilePath: http://localhost:2800