| /** | 
|  * Copyright (c) 2018 人人开源 All rights reserved. | 
|  * | 
|  * https://www.renren.io | 
|  * | 
|  * 版权所有,侵权必究! | 
|  */ | 
|   | 
| package com.zt.modules.sys.controller; | 
|   | 
| import com.sun.management.OperatingSystemMXBean; | 
| import com.zt.common.servlet.Result; | 
| import com.zt.modules.sys.dto.ConfigDto; | 
| import com.zt.modules.sys.dto.SystemDto; | 
| import com.zt.modules.sys.service.SysParamsService; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiOperation; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.GetMapping; | 
| import org.springframework.web.bind.annotation.RestController; | 
|   | 
| import java.lang.management.ManagementFactory; | 
| import java.math.BigDecimal; | 
| import java.math.RoundingMode; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 系统接口 | 
|  * | 
|  * @author hehz | 
|  */ | 
| @RestController | 
| @Api(tags = "系统接口") | 
| public class SystemController { | 
|     @Autowired | 
|     private SysParamsService sysParamsService; | 
|   | 
|     @GetMapping("sys/config") | 
|     @ApiOperation("系统信息") | 
|     public Result<List<ConfigDto>> configs() { | 
|         return Result.ok(sysParamsService.getConfigs()); | 
|     } | 
|   | 
|     @GetMapping("sys/info") | 
|     @ApiOperation("系统信息") | 
|     public Result<SystemDto> info() { | 
|         OperatingSystemMXBean osmx = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); | 
|   | 
|         SystemDto dto = new SystemDto(); | 
|         dto.setSysTime(System.currentTimeMillis()); | 
|         dto.setOsName(System.getProperty("os.name")); | 
|         dto.setOsArch(System.getProperty("os.arch")); | 
|         dto.setOsVersion(System.getProperty("os.version")); | 
|         dto.setUserLanguage(System.getProperty("user.language")); | 
|         dto.setUserDir(System.getProperty("user.dir")); | 
|         dto.setTotalPhysical(osmx.getTotalPhysicalMemorySize() / 1024 / 1024); | 
|         dto.setFreePhysical(osmx.getFreePhysicalMemorySize() / 1024 / 1024); | 
|         dto.setMemoryRate(BigDecimal.valueOf( | 
|                 (1 - osmx.getFreePhysicalMemorySize() * 1.0 / osmx.getTotalPhysicalMemorySize()) * 100).setScale(2, | 
|                 RoundingMode.HALF_UP)); | 
|         dto.setProcessors(osmx.getAvailableProcessors()); | 
|         dto.setJvmName(System.getProperty("java.vm.name")); | 
|         dto.setJavaVersion(System.getProperty("java.version")); | 
|         dto.setJavaHome(System.getProperty("java.home")); | 
|         dto.setJavaTotalMemory(Runtime.getRuntime().totalMemory() / 1024 / 1024); | 
|         dto.setJavaFreeMemory(Runtime.getRuntime().freeMemory() / 1024 / 1024); | 
|         dto.setJavaMaxMemory(Runtime.getRuntime().maxMemory() / 1024 / 1024); | 
|         dto.setUserName(System.getProperty("user.name")); | 
|         dto.setSystemCpuLoad(BigDecimal.valueOf(osmx.getSystemCpuLoad() * 100).setScale(2, RoundingMode.HALF_UP)); | 
|         dto.setUserTimezone(System.getProperty("user.timezone")); | 
|   | 
|         return Result.ok(dto); | 
|     } | 
|   | 
| } |