Selaa lähdekoodia

增加app更新功能

chenminghua 4 vuotta sitten
vanhempi
commit
535bbc0e6d

+ 2 - 2
src/main/java/com/gyee/MpGenerator.java

@@ -29,7 +29,7 @@ public class MpGenerator {
     //作者
     private static String authorName = "chenmh";
     //要生成的表名
-    private static String[] tables = {"GYEEPERMISSION","GYEECONTACTS"};
+    private static String[] tables = {"GYEEVERSION"};
     //table前缀
     private static String prefix = "";
 
@@ -145,7 +145,7 @@ public class MpGenerator {
                 .setMapper("mapper.ticket") // 设置Mapper包名,默认mapper
                 .setService("service.ticket") // 设置Service包名,默认service
                 .setServiceImpl("service.impl.ticket") // 设置Service Impl包名,默认service.impl
-//                .setXml("mapper") // 设置Mapper XML包名,默认mapper.xml
+                .setXml("mapper") // 设置Mapper XML包名,默认mapper.xml
         );
 
         /**

+ 69 - 0
src/main/java/com/gyee/frame/controller/AnonController.java

@@ -0,0 +1,69 @@
+package com.gyee.frame.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.frame.common.dataSources.DataSource;
+import com.gyee.frame.common.dataSources.DataSourceType;
+import com.gyee.frame.common.domain.AjaxResult;
+import com.gyee.frame.mapper.ticket.GyeeversionMapper;
+import com.gyee.frame.model.ticket.Gyeeversion;
+import com.gyee.frame.service.ticket.FileService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+@RestController
+@RequestMapping("sys")
+public class AnonController {
+
+    @Autowired
+    FileService fileService;
+    @Autowired
+    GyeeversionMapper gyeeversionMapper;
+
+    @DataSource(value = DataSourceType.TICKET)
+    @GetMapping("version")
+    public AjaxResult version(){
+        QueryWrapper<Gyeeversion> wrapper = new QueryWrapper<>();
+        wrapper.eq("TYPE", "android");
+
+        Gyeeversion gyeeversion = gyeeversionMapper.selectOne(wrapper);
+        if (gyeeversion != null)
+            return AjaxResult.successData(gyeeversion.getVersion());
+
+        return AjaxResult.error();
+    }
+
+    @GetMapping("/downloadFile")
+    public ResponseEntity<Resource> downloadFile( HttpServletRequest request) {
+        // Load file as Resource
+        Resource resource = fileService.loadFileAsResource("D://sisphone.apk");
+
+        // Try to determine file's content type
+        String contentType = null;
+        try {
+            contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath());
+        } catch (IOException ex) {
+
+        }
+
+        // Fallback to the default content type if type could not be determined
+        if(contentType == null) {
+            contentType = "application/octet-stream";
+        }
+
+        return ResponseEntity.ok()
+                .contentType(MediaType.parseMediaType(contentType))
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
+                .body(resource);
+    }
+
+}

+ 1 - 1
src/main/java/com/gyee/frame/controller/ticket/LaborController.java

@@ -71,7 +71,7 @@ public class LaborController {
         Double instId = jsonObject.getDouble("instid");
         String role = jsonObject.getString("role");
 
-        List<Labor> labors = new ArrayList<>();
+        List<Labor> labors;
         if (role.contains("流程启动者") || role.contains("流程人员变更"))
             labors = laborService.getFlowStarter(instId);
         else

+ 16 - 0
src/main/java/com/gyee/frame/mapper/ticket/GyeeversionMapper.java

@@ -0,0 +1,16 @@
+package com.gyee.frame.mapper.ticket;
+
+import com.gyee.frame.model.ticket.Gyeeversion;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author chenmh
+ * @since 2020-10-16
+ */
+public interface GyeeversionMapper extends BaseMapper<Gyeeversion> {
+
+}

+ 41 - 0
src/main/java/com/gyee/frame/model/ticket/Gyeeversion.java

@@ -0,0 +1,41 @@
+package com.gyee.frame.model.ticket;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author chenmh
+ * @since 2020-10-16
+ */
+@Data
+  @EqualsAndHashCode(callSuper = false)
+    @TableName("GYEEVERSION")
+public class Gyeeversion extends Model<Gyeeversion> {
+
+    private static final long serialVersionUID=1L;
+
+      @TableId("ID")
+      private Integer id;
+
+    @TableField("VERSION")
+    private String version;
+
+    @TableField("TYPE")
+    private String type;
+
+
+    @Override
+    protected Serializable pkVal() {
+          return this.id;
+      }
+
+}

+ 77 - 0
src/main/java/com/gyee/frame/service/ticket/FileService.java

@@ -0,0 +1,77 @@
+package com.gyee.frame.service.ticket;
+
+import com.gyee.frame.common.exception.TicketException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+
+@Service
+public class FileService {
+
+    private final Path fileStorageLocation; // 文件在本地存储的地址
+
+    @Autowired
+    public FileService() {
+        this.fileStorageLocation = Paths.get("D://").toAbsolutePath().normalize();
+        try {
+            Files.createDirectories(this.fileStorageLocation);
+        } catch (Exception ex) {
+
+        }
+    }
+
+    /**
+     * 存储文件到系统
+     *
+     * @param file 文件
+     * @return 文件名
+     */
+    public String storeFile(MultipartFile file) {
+        // Normalize file name
+        String fileName = StringUtils.cleanPath(file.getOriginalFilename());
+
+        try {
+            // Check if the file's name contains invalid characters
+            if(fileName.contains("..")) {
+                throw new TicketException("Sorry! Filename contains invalid path sequence " + fileName);
+            }
+
+            // Copy file to the target location (Replacing existing file with the same name)
+            Path targetLocation = this.fileStorageLocation.resolve(fileName);
+            Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
+
+            return fileName;
+        } catch (IOException ex) {
+            throw new TicketException("Could not store file " + fileName + ". Please try again!");
+        }
+    }
+
+    /**
+     * 加载文件
+     * @param fileName 文件名
+     * @return 文件
+     */
+    public Resource loadFileAsResource(String fileName) {
+        try {
+            Path filePath = this.fileStorageLocation.resolve(fileName).normalize();
+            Resource resource = new UrlResource(filePath.toUri());
+            if(resource.exists()) {
+                return resource;
+            } else {
+                throw new TicketException("File not found " + fileName);
+            }
+        } catch (MalformedURLException ex) {
+            throw new TicketException("File not found " + fileName);
+        }
+    }
+}

+ 17 - 0
src/main/resources/mybatis/ticket/GyeeversionMapper.xml

@@ -0,0 +1,17 @@
+<?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.gyee.frame.mapper.ticket.GyeeversionMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.gyee.frame.model.ticket.Gyeeversion">
+        <id column="ID" property="id" />
+        <result column="VERSION" property="version" />
+        <result column="TYPE" property="type" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        ID, VERSION, TYPE
+    </sql>
+
+</mapper>