|
@@ -0,0 +1,105 @@
|
|
|
+package com.management.platform.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.UpdatePack;
|
|
|
+import com.management.platform.mapper.UpdatePackMapper;
|
|
|
+import com.management.platform.util.FileUtil;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.ZipUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2024-01-21
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/update-pack")
|
|
|
+public class UpdatePackController {
|
|
|
+
|
|
|
+ @Value(value = "${upload.tempUpdatePath}")
|
|
|
+ private String tempUpdatePath;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UpdatePackMapper updatePackMapper;
|
|
|
+
|
|
|
+ @RequestMapping("/save")
|
|
|
+ public HttpRespMsg save(UpdatePack pack) throws IOException {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ updatePackMapper.insert(pack);
|
|
|
+ //获取地址,进行更新系统
|
|
|
+ String serverPackUrl = pack.getServerPackUrl();
|
|
|
+ if (pack.getH5Url() != null) {
|
|
|
+ File h5File = new File(tempUpdatePath + pack.getH5Url());
|
|
|
+ String h5Target = h5File.getParent() + "\\h5";
|
|
|
+ ZipUtils.unzip(h5File.getAbsolutePath(), h5Target);
|
|
|
+ File targetFile = new File(h5Target);
|
|
|
+ File[] files = targetFile.listFiles();
|
|
|
+ //进入dist目录下
|
|
|
+ File distFile = files[0];
|
|
|
+
|
|
|
+ if (!distFile.getName().equals("dist")) {
|
|
|
+ System.out.println("压缩包内文件结构不正确,应该包含dist目录");
|
|
|
+ msg.setError("压缩包内文件结构不正确,应该包含dist目录");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ File finalTargetDirectory = new File("D:\\www\\staticproject\\workshop_h5");
|
|
|
+ //拷贝文件到目标文件夹进行覆盖
|
|
|
+ FileUtils.copyDirectory(distFile, finalTargetDirectory);
|
|
|
+ System.out.println("H5端文件拷贝完成");
|
|
|
+ }
|
|
|
+ if (pack.getPcUrl() != null) {
|
|
|
+ File pcFile = new File(tempUpdatePath + pack.getPcUrl());
|
|
|
+ String pcTarget = pcFile.getParent() + "\\pc";
|
|
|
+ ZipUtils.unzip(pcFile.getAbsolutePath(), pcTarget);
|
|
|
+
|
|
|
+ File targetFile = new File(pcTarget);
|
|
|
+ File[] files = targetFile.listFiles();
|
|
|
+ //进入dist目录下
|
|
|
+ File distFile = files[0];
|
|
|
+ if (!distFile.getName().equals("dist")) {
|
|
|
+ System.out.println("压缩包内文件结构不正确,应该包含dist目录");
|
|
|
+ msg.setError("压缩包内文件结构不正确,应该包含dist目录");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ File finalTargetDirectory = new File("D:\\www\\staticproject\\workshop_pc");
|
|
|
+ //拷贝文件到目标文件夹进行覆盖
|
|
|
+ FileUtils.copyDirectory(distFile, finalTargetDirectory);
|
|
|
+ System.out.println("PC端文件拷贝完成");
|
|
|
+ }
|
|
|
+ //检查解压后的文件结构目录
|
|
|
+ if (serverPackUrl != null) {
|
|
|
+ File file = new File(tempUpdatePath + serverPackUrl);
|
|
|
+ //拷贝文件到目标目录进行覆盖
|
|
|
+ FileUtils.copyFileToDirectory(file, new File("D:\\www\\webapps\\workshop-lew"));
|
|
|
+ System.out.println("后端文件拷贝完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //执行更新脚本
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/getHistory")
|
|
|
+ public HttpRespMsg getHistory() {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ msg.data = updatePackMapper.selectList(new QueryWrapper<UpdatePack>().orderByDesc("id").last("limit 30"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|