Pārlūkot izejas kodu

车间增加版本更新功能

seyason 1 gadu atpakaļ
vecāks
revīzija
31f39d10d3

+ 5 - 1
fhKeeper/formulahousekeeper/management-workshop/pom.xml

@@ -226,7 +226,11 @@
             <artifactId>spring-boot-devtools</artifactId>
             <version>2.0.1.RELEASE</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.18</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 39 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/CommonUploadController.java

@@ -23,6 +23,9 @@ public class CommonUploadController {
     @Value(value = "${upload.path}")
     private String path;
 
+    @Value(value = "${upload.tempUpdatePath}")
+    private String tempUpdatePath;
+
     @RequestMapping(value="uploadFile")
     public HttpRespMsg uploadFile(MultipartFile multipartFile) {
         HttpRespMsg msg = new HttpRespMsg();
@@ -58,4 +61,40 @@ public class CommonUploadController {
 
         return msg;
     }
+
+    @RequestMapping(value="uploadUpdateFile")
+    public HttpRespMsg uploadUpdateFile(MultipartFile multipartFile) {
+        HttpRespMsg msg = new HttpRespMsg();
+
+        //然后处理文件
+        String fileName = multipartFile.getOriginalFilename();
+        String[] split = fileName.split("\\.");
+        String serverName = UUID.randomUUID().toString().replaceAll("-", "") + "."+split[split.length-1];
+
+        //检查目录
+        File dir = new File(tempUpdatePath);
+        if (!dir.exists()) {
+            dir.mkdir();
+        }
+        File file = new File(dir, serverName);
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            inputStream = multipartFile.getInputStream();
+            outputStream = new FileOutputStream(file);
+            byte[] buffer = new byte[4096];
+            int temp = 0;
+            while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
+                outputStream.write(buffer, 0, temp);
+            }
+            inputStream.close();
+            outputStream.close();
+            msg.data = serverName;
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            logger.error(exception.getMessage());
+        }
+
+        return msg;
+    }
 }

+ 12 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/FileUtil.java

@@ -1,9 +1,11 @@
 package com.management.platform.util;
 
 import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+import org.apache.commons.io.FileUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
+import java.util.Arrays;
 
 /**
  * 文件读取工具类
@@ -138,4 +140,14 @@ public class FileUtil {
             }
         }
     }
+
+    public static void main(String[] args) {
+        String file = "C:\\gitproject\\manHourHousekeeper\\fhKeeper\\formulahousekeeper\\timesheet-workshop-h5\\dist";
+        String target = "D:\\www\\staticproject\\workshop_h5";
+        try {
+            FileUtils.copyDirectory(new File(file), new File(target));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

+ 150 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/ZipUtils.java

@@ -0,0 +1,150 @@
+package com.management.platform.util;
+
+import com.alibaba.excel.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.zip.*;
+
+/**
+ * @Description 压缩与解压工具
+ * @Author      yanghanwei
+ * @Date        18:42 2019-11-20
+ * @Version     v1
+ **/
+public class ZipUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger(ZipUtils.class);
+
+    /**
+     * 压缩 zip
+     * @param filePath  文件夹 全路径
+     * @param fileName  文件夹名称
+     * @param outPath   压缩文件保存路径
+     */
+    public static void zipFile(String filePath, String fileName, String outPath) {
+        logger.info("filePath:{}, fileName:{}, outPath:{}", filePath, fileName, outPath);
+        try {
+            //创建Test.zip文件
+            OutputStream is = new FileOutputStream(outPath);
+            //检查输出流,采用CRC32算法,保证文件的一致性
+            CheckedOutputStream cos = new CheckedOutputStream(is, new CRC32());
+            //创建zip文件的输出流
+            ZipOutputStream zos = new ZipOutputStream(cos);
+            //需要压缩的文件或文件夹对象
+            File file = new File(filePath);
+            //压缩文件的具体实现函数
+            zipFilePost(zos,file,filePath,fileName,outPath);
+            zos.close();
+            cos.close();
+            is.close();
+            System.out.println("压缩完成");
+        } catch (Exception e) {
+            logger.error("压缩失败zipFile,Exception:" + e);
+        }
+    }
+
+    /**
+     * 压缩文件
+     * @param zos       zip文件的输出流
+     * @param file      需要压缩的文件或文件夹对象
+     * @param filePath  压缩的文件路径
+     * @param fileName  需要压缩的文件夹名
+     * @param outPath   缩完成后保存为Test.zip文件
+     */
+    private static void zipFilePost(ZipOutputStream zos, File file, String filePath, String fileName, String outPath){
+
+        try{
+            String path = file.getPath();
+            String zosName = "";
+            if(!StringUtils.isEmpty(path)){
+                zosName = path.substring(path.indexOf(fileName));
+            }
+            File[] files = file.listFiles();
+            if(file.isDirectory() && files != null && files.length > 0) {
+                // 创建压缩文件的目录结构
+                zos.putNextEntry(new ZipEntry(zosName + File.separator));
+                for(File f : files) {
+                    zipFilePost(zos, f, filePath, fileName, outPath);
+                }
+            } else {
+                logger.info("正在压缩文件:{}",file.getName());
+                // 创建压缩文件
+                zos.putNextEntry(new ZipEntry(zosName));
+                // 用字节方式读取源文件
+                InputStream is = new FileInputStream(file.getPath());
+                // 创建一个缓存区
+                BufferedInputStream bis = new BufferedInputStream(is);
+                // 字节数组,每次读取1024个字节
+                byte [] b = new byte[1024];
+                // 循环读取,边读边写
+                while(bis.read(b)!=-1) {
+                    // 写入压缩文件
+                    zos.write(b);
+                }
+                //关闭流
+                bis.close();
+                is.close();
+            }
+        } catch (Exception e) {
+            logger.error("压缩文件失败zipFilePost,Exception:" + e);
+        }
+    }
+
+    public static void unzip(String sourcePath, String targetPath) {
+        //targetPath输出文件路径
+        File targetFile = new File(targetPath);
+        // 如果目录不存在,则创建
+        if (!targetFile.exists()) {
+            targetFile.mkdirs();
+        }
+        //sourcePath压缩包文件路径
+        try (ZipFile zipFile = new ZipFile(new File(sourcePath))) {
+            System.out.println("file nums:" + zipFile.size());
+            Enumeration enumeration = zipFile.entries();
+            while (enumeration.hasMoreElements()) {
+                //依次获取压缩包内的文件实体对象
+                ZipEntry entry = (ZipEntry) enumeration.nextElement();
+                String name = entry.getName();
+                if (entry.isDirectory()) {
+                    continue;
+                }
+                try (BufferedInputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) {
+                    // 需要判断文件所在的目录是否存在,处理压缩包里面有文件夹的情况
+                    String outName = targetPath + "/" + name;
+                    File outFile = new File(outName);
+                    File tempFile = new File(outName.substring(0, outName.lastIndexOf("/")));
+                    if (!tempFile.exists()) {
+                        tempFile.mkdirs();
+                    }
+                    try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile))) {
+                        int len;
+                        byte[] buffer = new byte[1024];
+                        while ((len = inputStream.read(buffer)) > 0) {
+                            outputStream.write(buffer, 0, len);
+                        }
+                    }
+
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    public static void main(String[] args) throws Exception{
+//        String filePath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/201908月小微平台消耗-1574300435525/";
+//        // 需要压缩的文件夹名
+//        String fileName = "201908月小微平台消耗-1574300435525";
+//        // 压缩完成后保存为Test.zip文件,名字随意
+//        String outPath = "/var/folders/88/jh37h0fj59l1f302jdryz4780000gn/T/Test3.zip";
+//        zipFile(filePath, fileName, outPath);
+
+        String sourcePath = "C:\\gitproject\\manHourHousekeeper\\fhKeeper\\formulahousekeeper\\timesheet-workshop\\distPC.zip";
+        String targetPath = "C:\\文档资料\\distPC";
+        unzip(sourcePath, targetPath);
+    }
+}

+ 3 - 2
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/application.yml

@@ -10,8 +10,8 @@ spring:
       # 配置上传文件的大小设置
 
       # Single file max size  即单个文件大小
-      max-file-size: 100MB
-      max-request-size: 100MB
+      max-file-size: 200MB
+      max-request-size: 200MB
       location: C:/upload/
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
@@ -86,6 +86,7 @@ mybatis:
 #####配置图片上传路径####
 upload:
   path: C:/upload/
+  tempUpdatePath: C:/tempUpdate/
 picrecongnize:
   browser: C:/picrecongnize/browser/
   develop: C:/picrecongnize/develop/

+ 177 - 0
fhKeeper/formulahousekeeper/timesheet-workshop/src/views/settings/settings.vue

@@ -30,6 +30,31 @@
         <div style="width:80px;margin:0 auto;padding:20px;">
             <el-button  type="primary" @click="submitInsert" :loading="addLoading">{{ $t('save') }}</el-button>
         </div>
+        <el-divider ></el-divider>
+        <div style="width:400px;margin:0 auto;padding:20px;">
+            <h3>系统部署</h3>
+            <el-form style="padding:35px;">
+                <el-form-item label="前端H5安装包" >
+                    <span>{{ param.h5Url }}</span>
+                    <el-upload ref="upload" action="#" :limit="1" :http-request="importH5" :show-file-list="false">
+                        <el-button type="primary" :underline="false" style="width:100%;" :loading="loadingExport" size="small">{{ $t('uoloadFiles') }}</el-button>
+                    </el-upload>
+                </el-form-item>
+                <el-form-item label="前端PC安装包" >
+                    <span>{{ param.pcUrl }}</span>
+                    <el-upload ref="upload2" action="#" :limit="1" :http-request="importPC" :show-file-list="false">
+                        <el-button type="primary" :underline="false" style="width:100%;" :loading="loadingExport2" size="small">{{ $t('uoloadFiles') }}</el-button>
+                    </el-upload>
+                </el-form-item>
+                <el-form-item label="后端jar安装包" >
+                    <span>{{ param.serverPackUrl }}</span>
+                    <el-upload ref="upload3" action="#" :limit="1" :http-request="importServer" :show-file-list="false">
+                        <el-button type="primary" :underline="false" style="width:100%;" :loading="loadingExport3" size="small">{{ $t('uoloadFiles') }}</el-button>
+                    </el-upload>
+                </el-form-item>
+            </el-form>
+        </div>
+        <div style="width:80px;margin:0 auto;padding:20px;"><el-button  type="primary" @click="startDeploy" :loading="startDeployLoading" >开始部署</el-button></div>
     </section>
 </template>
 <script>
@@ -43,6 +68,12 @@
         },
         data() {
             return {
+                param:{},
+                startDeployLoading: false,
+                loadingExport: false,
+                loadingExport2: false,
+                loadingExport3: false,
+                fileList:[],
                 appName: null,
                 appLogo: null,
             };
@@ -64,6 +95,152 @@
             this.getSettings();
         },
          methods: {
+            importH5(item) {
+                this.loadingExport = true;
+                let str = item.file.name.split(".");
+                let format = str[str.length - 1];
+                if (format != "zip") {
+                    this.loadingExport = false
+                    this.$message({
+                        message: '请上传zip文件',
+                        type: "error"
+                    });
+                } else {
+                    let formData = new FormData();
+                    formData.append("multipartFile", item.file);
+                    this.http.uploadFile('/common/uploadUpdateFile', formData,
+                    res => {
+                        this.loadingExport = false
+                        this.$refs.upload.clearFiles();
+                        if (res.code == "ok") {
+                            this.$message({
+                                message:'上传成功',
+                                type: "success"
+                            });
+                            this.param.h5Url=res.data;
+                        } else {
+                            this.$message({
+                                message: res.msg,
+                                type: "error"
+                            });
+                        }
+                    },
+                    error => {
+                        this.$refs.upload.clearFiles();
+                        this.loadingExport = false
+                        this.$message({
+                            message: error,
+                            type: "error"
+                        });
+                    });
+                }
+            },
+            importPC(item) {
+                this.loadingExport2 = true;
+                let str = item.file.name.split(".");
+                let format = str[str.length - 1];
+                if (format != "zip") {
+                    this.loadingExport2 = false
+                    this.$message({
+                        message: '请上传zip文件',
+                        type: "error"
+                    });
+                } else {
+                    let formData = new FormData();
+                    formData.append("multipartFile", item.file);
+                    this.http.uploadFile('/common/uploadUpdateFile', formData,
+                    res => {
+                        this.loadingExport2 = false
+                        this.$refs.upload2.clearFiles();
+                        if (res.code == "ok") {
+                            this.$message({
+                                message:'上传成功',
+                                type: "success"
+                            });
+                            this.param.pcUrl=res.data;
+                        } else {
+                            this.$message({
+                                message: res.msg,
+                                type: "error"
+                            });
+                        }
+                    },
+                    error => {
+                        this.$refs.upload.clearFiles();
+                        this.loadingExport = false
+                        this.$message({
+                            message: error,
+                            type: "error"
+                        });
+                    });
+                }
+            },
+            importServer(item) {
+                this.loadingExport3 = true;
+                let str = item.file.name.split(".");
+                let format = str[str.length - 1];
+                if (format != "jar") {
+                    this.loadingExport3 = false
+                    this.$message({
+                        message: '请上传jar文件',
+                        type: "error"
+                    });
+                } else {
+                    let formData = new FormData();
+                    formData.append("multipartFile", item.file);
+                    this.http.uploadFile('/common/uploadUpdateFile', formData,
+                    res => {
+                        this.loadingExport3 = false
+                        this.$refs.upload3.clearFiles();
+                        if (res.code == "ok") {
+                            this.$message({
+                                message:'上传成功',
+                                type: "success"
+                            });
+                            this.param.serverPackUrl=res.data;
+                        } else {
+                            this.$message({
+                                message: res.msg,
+                                type: "error"
+                            });
+                        }
+                    },
+                    error => {
+                        this.$refs.upload.clearFiles();
+                        this.loadingExport = false
+                        this.$message({
+                            message: error,
+                            type: "error"
+                        });
+                    });
+                }
+            },
+            startDeploy() {
+                //开始部署
+                this.startDeployLoading = true;
+                this.http.post('/update-pack/save', this.param,
+                res => {
+                    if (res.code == "ok") {
+                        //上传中
+                        this.startDeployLoading = false;
+                        this.$message({
+                            message: res,
+                            type: "success"
+                        });
+                    } else {
+                        this.$message({
+                            message: res.msg,
+                            type: "error"
+                        });
+                    }
+                },
+                error => {
+                    this.$message({
+                        message: error,
+                        type: "error"
+                    });
+                });
+            },
             addImg(e) {
                 let formData = new FormData()
                 formData.append('multipartFile', e.file)