package com.qmth.distributed.print.api.admin;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.service.ClientUpgradeService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.clientpackage.ClientPackageEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 客户端升级 前端控制器
 */
@Api(tags = "超管-客户端升级Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SYS + "/client/package")
@Aac(auth = false)
public class ClientUpgradeController {

    @Resource
    private ClientUpgradeService clientUpgradeService;

    @ApiOperation(value = "上传安装包/升级包")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public Result upload(@ApiParam(value = "上传文件", required = true) @RequestParam(value = "file") MultipartFile file,
                        @ApiParam(value = "文件MD5", required = true) @RequestParam(value = "md5") String md5,
                        @ApiParam(value = "上传文件", required = true) @RequestParam(value = "type") ClientPackageEnum type) {
        clientUpgradeService.upload(file, md5, type);
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "升级信息接口")
    @RequestMapping(value = "/external", method = RequestMethod.POST)
    public Result external(@ApiParam(value = "上传文件") @RequestParam(value = "platform", required = false, defaultValue = "WINDOWS") String platform) {
        return ResultUtil.ok(clientUpgradeService.getExternalByPlatform(platform));
    }

}

