package com.license.controller;

import com.license.entity.dto.LicenseCheckModel;
import com.license.service.LicenseService;
import com.zhgd.jeecg.common.api.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 邱平毅
 * @ClassName LicenseController
 * @date 2022/9/20 14:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/license")
public class LicenseController {
    /**
     * 获取服务器硬件信息
     *
     * @param osName 操作系统类型，如果为空则自动判断
     * @return com.ccx.models.license.LicenseCheckModel
     * @author zifangsky
     * @date 2018/4/26 13:13
     * @since 1.0.0
     */
    @RequestMapping(value = "/getServerInfos", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Result<LicenseCheckModel> getServerInfos(@RequestParam(value = "osName", required = false) String osName) {
        return Result.success(licenseService.getServerInfos());
    }

    @Autowired
    LicenseService licenseService;

    /**
     * 上传文件
     *
     * @return
     */
    @ApiOperation(value = "上传license文件", notes = "上传license文件")
    @PostMapping(value = "/upload")
    public Result upload(@RequestBody Map fileBaseMap) throws Exception {
        licenseService.upload(fileBaseMap);
        return Result.ok();
    }

    /**
     * 取消授权
     *
     * @return
     */
    @ApiOperation(value = "取消授权", notes = "取消授权")
    @GetMapping(value = "/removeLicense")
    public Result removeLicense() {
        licenseService.removeLicense();
        return Result.ok();
    }
}
