首页>代码>spring boot+vue开发前后端分离无限速文件管理系统-兜兜网盘1.0>/兜兜网盘(1.0)/v1.0/后端源码/cloud-disk/src/main/java/cn/novelweb/chart/controller/ChartController.java
package cn.novelweb.chart.controller;

import cn.novelweb.chart.dto.UsageRateDTO;
import cn.novelweb.tool.http.Result;
import cn.novelweb.util.system.SystemInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;

/**
 * <p>各类图表接口</p>
 * <p>2020-04-24 16:47</p>
 *
 * @author Dan
 **/
@Slf4j
@RestController
@EnableSwagger2
@Api(tags = {"图表信息数据"})
@RequiresPermissions({"manager"})
@RequestMapping(value = "/chart", method = {RequestMethod.GET})
public class ChartController {

    @ApiOperation(value = "获取当前服务器信息(注:该接口请求速度可能略微大于其他接口)", notes = "参数:无参")
    @RequestMapping(value = "/system-info", produces = "application/json;charset=UTF-8")
    public Result<SystemInfo> getSystemInfo(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=UTF-8");
        // 获取系统数据信息
        return Result.ok(new SystemInfo());
    }

    @ApiOperation(value = "构建仪表盘相关信息(注:该接口请求速度可能略微大于其他接口)", notes = "参数:无参")
    @RequestMapping(value = "/usage-rate", produces = "application/json;charset=UTF-8")
    public Result<UsageRateDTO> getUsageRate(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=UTF-8");
        // 设置系统等待时间
        SystemInfo.OSHI_WAIT_SECOND = 2000;
        SystemInfo systemInfo = new SystemInfo();
        //设置数据
        double cpu = (100 - systemInfo.getCpuInfo().getFree());
        DecimalFormat format = new DecimalFormat("#.00");

        // 构建返回数据模型
        UsageRateDTO usageRateDTO = new UsageRateDTO();
        usageRateDTO.setCpu(Double.parseDouble(format.format(cpu)));
        usageRateDTO.setJvm(systemInfo.getJvmInfo().getUsage());
        usageRateDTO.setMem(systemInfo.getMemoryInfo().getUsage());
        return Result.ok(usageRateDTO);
    }
}
最近下载更多
1098992849  LV1 2023年3月13日
81013466  LV1 2023年2月10日
testuser1234567  LV24 2023年1月15日
清横白川玉  LV6 2023年1月3日
SZEPEZS  LV8 2022年6月9日
wwwwwjiawen  LV1 2022年5月3日
a273580046  LV1 2022年4月27日
591231555  LV20 2022年4月18日
yangctz  LV24 2022年3月22日
HappierLee  LV1 2022年3月21日
最近浏览更多
LXQ666666 4月8日
暂无贡献等级
泓鼎168  LV19 3月27日
jc121140  LV3 3月22日
Boss绝  LV8 2月26日
罗清晨  LV11 2月21日
Anzhui  LV2 1月12日
zcwmmd  LV20 1月8日
cesdsa 2023年12月29日
暂无贡献等级
263648  LV7 2023年12月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友