ApplicationUpdateController.java 2.57 KB
package com.ruoyi.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.global.Result;
import com.ruoyi.pojo.request.HeartPackageVo;
import com.ruoyi.service.AppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 管理应用更新
 *
 * @author 20412
 */
@RestController
@Api(tags = "管理应用更新")
@RequestMapping("/app")
public class ApplicationUpdateController {

    @Resource
    private AppService appService;

    /**
     * 校验版本号
     */
    @GetMapping("/version/check/{currentVersion}")
    @ApiOperation("校验版本号")
    public AjaxResult checkVersionNum(@PathVariable("currentVersion") Integer currentVersion, @RequestParam(value = "deviceId", required = false) String deviceId) {
        return AjaxResult.success(appService.checkVersionNum(currentVersion,deviceId));
    }

    /**
     * 下载最新apk 弃用
     */
    @Deprecated
    @PostMapping("/download")
//    @ApiOperation("下载最新apk")
    public void downloadApk(String apkUrl, HttpServletResponse response) {
        try {
            appService.downloadApk(apkUrl, response);
        } catch (IOException e) {
            throw new RuntimeException("下载失败,请联系管理员处理,失败原因 :" + e.getMessage());
        }
    }

    @PostMapping("/uploadApk")
    @ApiOperation("上传apk文件")
    public AjaxResult uploadApk(MultipartFile file) {
        try {
            return appService.uploadApk(file);
        } catch (Exception e) {
            return AjaxResult.error("上传失败,请重试,再次失败请联系管理员,失败原因:" + e.getMessage());
        }
    }


    @PostMapping("/uploadApk/other")
    @ApiOperation("上传apk文件")
    public AjaxResult uploadApkOther(MultipartFile file) {
        try {
            return appService.uploadApkOther(file);
        } catch (Exception e) {
            return AjaxResult.error("上传失败,请重试,再次失败请联系管理员,失败原因:" + e.getMessage());
        }
    }


    @GetMapping("/checkDeviceHeart")
    @ApiOperation("设备心跳检测")
    public Result<?> checkAppHeart(@Validated @ApiParam @ModelAttribute HeartPackageVo vo) {
        appService.checkAppHeart(vo);
        return Result.OK();
    }

}