seyason hai 11 meses
pai
achega
aeb8e2274a

+ 105 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/UpdatePackController.java

@@ -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;
+    }
+
+
+}
+

+ 76 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/UpdatePack.java

@@ -0,0 +1,76 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Seyason
+ * @since 2024-01-22
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class UpdatePack extends Model<UpdatePack> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 前端h5的包存储路径
+     */
+    @TableField("h5_url")
+    private String h5Url;
+
+    /**
+     * 前端pc的包存储路径
+     */
+    @TableField("pc_url")
+    private String pcUrl;
+
+    /**
+     * 后端项目工程的包存储路径
+     */
+    @TableField("server_pack_url")
+    private String serverPackUrl;
+
+
+    @TableField("indate")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime indate;
+
+    /**
+     * 0-进行中,1-已完成部署,2-部署失败
+     */
+    @TableField("status")
+    private Integer status;
+
+    /**
+     * 消息
+     */
+    @TableField("message")
+    private String message;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/UpdatePackMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.UpdatePack;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Seyason
+ * @since 2024-01-21
+ */
+public interface UpdatePackMapper extends BaseMapper<UpdatePack> {
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/UpdatePackService.java

@@ -0,0 +1,16 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.UpdatePack;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2024-01-21
+ */
+public interface UpdatePackService extends IService<UpdatePack> {
+
+}

+ 20 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/UpdatePackServiceImpl.java

@@ -0,0 +1,20 @@
+package com.management.platform.service.impl;
+
+import com.management.platform.entity.UpdatePack;
+import com.management.platform.mapper.UpdatePackMapper;
+import com.management.platform.service.UpdatePackService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2024-01-21
+ */
+@Service
+public class UpdatePackServiceImpl extends ServiceImpl<UpdatePackMapper, UpdatePack> implements UpdatePackService {
+
+}

+ 21 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/UpdatePackMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.management.platform.mapper.UpdatePackMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.UpdatePack">
+        <id column="id" property="id" />
+        <result column="h5_url" property="h5Url" />
+        <result column="pc_url" property="pcUrl" />
+        <result column="server_pack_url" property="serverPackUrl" />
+        <result column="indate" property="indate" />
+        <result column="status" property="status" />
+        <result column="message" property="message" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, h5_url, pc_url, server_pack_url, indate, status, message
+    </sql>
+
+</mapper>