fix:1.edit user 2.add freeMemory

This commit is contained in:
nieziyan 2024-02-05 17:25:21 +08:00
parent 9e2a90bb51
commit 25b0cdfadc
11 changed files with 50 additions and 64 deletions

View File

@ -9,6 +9,7 @@ public interface MonitorConstant {
// 监控项名称
String ITEM_CPUUSED = "cpuUtilization";
String ITEM_SWAPUSED = "swapUtilization";
String ITEM_MEMORYFREESIZE = "memoryFreeSize"; // byte
String ITEM_MEMORYUSED = "memoryUtilization";
String ITEM_RUNTIME = "uptime";
String ITEM_RAMSIZE = "totalMemory";

View File

@ -33,13 +33,13 @@ public class ServerDto implements Serializable {
private boolean memoryRed;
private String diskUsage;
private String memoryFree;
private boolean diskRed;
private boolean memoryFreeRed;
public ServerDto() {
this.cpuUutilzation = "--";
this.memoryUsage = "--";
this.diskUsage = "--";
this.memoryFree = "--";
}
}

View File

@ -41,15 +41,15 @@
<groupId>com.netease.qiye</groupId>
<artifactId>open-common</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/open-common-1.0-SNAPSHOT.jar</systemPath>
<!--<scope>system</scope>
<systemPath>${project.basedir}/lib/open-common-1.0-SNAPSHOT.jar</systemPath>-->
</dependency>
<dependency>
<groupId>com.netease.qiye</groupId>
<artifactId>open-sdk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/open-sdk-20211201132528.jar</systemPath>
<!--<scope>system</scope>
<systemPath>${project.basedir}/lib/open-sdk-20211201132528.jar</systemPath>-->
</dependency>
</dependencies>

View File

@ -103,7 +103,7 @@ public class StatusAspect {
try {
databaseService.status2Redis(database);
String token = ManageUtil.getToken();
Page<Host> hostPage = monitorAlarm.dbList(null, 1, 99, token).getResult();
Page<Host> hostPage = monitorAlarm.dbList(MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
if (ObjectUtil.isNull(hostPage) || CollUtil.isEmpty(hostPage.getRecords())) return;
List<Host> hosts = hostPage.getRecords();
String name = database.getName();
@ -139,11 +139,9 @@ public class StatusAspect {
SysServer server = (SysServer) args[0];
String id = server.getId();
String name = server.getName();
String ipAddress = server.getIpAddress();
try {
String token = ManageUtil.getToken();
Page<Host> hostPage = monitorAlarm.listApp(ipAddress, MonitorConstant.SERVER_APP,
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
Page<Host> hostPage = monitorAlarm.listApp(name, MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
if (ObjectUtil.isNull(hostPage) || CollUtil.isEmpty(hostPage.getRecords())){
redisUtil.hset(key, id, new NameValue(name, online));
return;
@ -151,7 +149,7 @@ public class StatusAspect {
List<Host> hosts = hostPage.getRecords();
Host host = null;
for (Host oneHost : hosts) {
if (StrUtil.equals(ipAddress, oneHost.getCode()))
if (StrUtil.equals(name, oneHost.getCode()))
host = oneHost;
}
if (ObjectUtil.isNull(host)){

View File

@ -24,25 +24,16 @@ public interface MonitorAlarm {
// --------------------后端专用-------------------
@GetMapping("/omms/device/monitor/list") // 获取所有 服务器/数据库服务 信息
Result<Page<Host>> listApp(@RequestParam("type") String type,
@RequestParam("pageNo") Integer pageNo,
Result<Page<Host>> listApp(@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/device/monitor/list") // 获取所有 服务器/数据库服务 信息
Result<Page<Host>> listApp(@RequestParam("code") String code,
@RequestParam("type") String type,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/device/monitor/list") // 获取所有在线 服务器/数据库服务 信息
Result<Page<Host>> listOnApp(@RequestParam("status") String status,
@RequestParam("type") String type,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/device/monitor/queryHostDetails") // 获取服务器摘要信息
Result<Host> summary(@RequestParam("hostId") String hostId,
@RequestParam("pageName") String pageName,
@ -116,8 +107,7 @@ public interface MonitorAlarm {
@RequestHeader("X-Access-Token") String token);
@GetMapping("/omms/monitor/db/list")
Result<Page<Host>> dbList(@RequestParam("code") String code,
@RequestParam("pageNo") Integer pageNo,
Result<Page<Host>> dbList(@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestHeader("X-Access-Token") String token);
}

View File

@ -86,7 +86,7 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
Map<String,Host> dbMap = new HashMap<>();
try {
String token = ManageUtil.getToken();
Page<Host> dbPage = monitorAlarm.dbList(null, 1, 99, token).getResult();
Page<Host> dbPage = monitorAlarm.dbList( MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult();
if (ObjectUtil.isNotNull(dbPage) && CollUtil.isNotEmpty(dbPage.getRecords()))
dbMap = dbPage.getRecords().stream().collect(Collectors.toMap(Host::getName, host -> host));
}catch (FeignException.Unauthorized e){
@ -110,11 +110,12 @@ public class SysDatabaseServiceImpl extends ServiceImpl<SysDatabaseMapper, SysDa
String dataBaseType = dataSourceMap.get(type);
databaseDto.setDataBaseType(dataBaseType)
.setAlarmRed(alarmRed).setOnline(online);
// 如果数据库不在线 则不需要查询数据库的使用情况
if (!online) continue;
// 获取数据库指标信息
Host db = dbMap.get(name);
if (ObjectUtil.isNull(db)) continue;
if (!online) continue;
Map<String, Item> itemMap = db.getItems();
if (MapUtil.isEmpty(itemMap)) continue;
// dbMemory kb -> GB

View File

@ -81,8 +81,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
List<Host> hosts = new ArrayList<>();
try {
String token = ManageUtil.getToken();
hosts = monitorAlarm.listOnApp(ON.getValue(), MonitorConstant.SERVER_APP,
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
hosts = monitorAlarm.listApp(MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
}catch (FeignException.Unauthorized e){
ManageUtil.refreshToken();
log.warn("向运管系统查询Hosts信息异常: Token失效,已刷新Token");
@ -105,24 +104,29 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
if (ObjectUtil.isNotNull(nameValue))
value = nameValue.getValue();
boolean online = ObjectUtil.isNotNull(value) && value;
serverDto.setOnline(online);
// 如果机器不在线 则不需要查询机器的硬件使用情况
if (!online) continue;
// 设置服务器的硬件使用情况信息
Host host = hostMap.get(hostId);
if (ObjectUtil.isNull(host))
continue;
if (ObjectUtil.isNull(host)) continue;
Map<String, Item> items = host.getItems();
// CPU利用率
Item cpuItem = items.getOrDefault(MonitorConstant.ITEM_CPUUSED, new Item());
String cpuValue = cpuItem.getLastValue();
String cpu = StrUtil.isBlank(cpuValue) ? "--" :
NumUtil.keepStr(cpuValue, 1) + "%";
Item item = items.getOrDefault(MonitorConstant.ITEM_CPUUSED, new Item());
String cpu = item.getLastValue();
if (StrUtil.isNotBlank(cpu))
serverDto.setCpuUutilzation(NumUtil.keepStr(cpu, 1) + "%");
// 内存使用率
Item memoryItem = items.getOrDefault(MonitorConstant.ITEM_MEMORYUSED, new Item());
String memoryValue = memoryItem.getLastValue();
String memory = StrUtil.isBlank(memoryValue) ? "--" :
NumUtil.keepStr(memoryValue, 1) + "%";
// 磁盘使用率
serverDto.setOnline(online).setCpuUutilzation(cpu)
.setMemoryUsage(memory).setDiskUsage("--");
item = items.getOrDefault(MonitorConstant.ITEM_MEMORYUSED, new Item());
String memory = item.getLastValue();
if (StrUtil.isNotBlank(memory))
serverDto.setMemoryUsage(NumUtil.keepStr(memory, 1) + "%");
// 内存可用空间
item = items.getOrDefault(MonitorConstant.ITEM_MEMORYFREESIZE, new Item());
String memoryFree = item.getLastValue();
if (StrUtil.isNotBlank(memoryFree))
serverDto.setMemoryFree(NumUtil.byte2Gb(memoryFree, 2) + "GB");
}
page.setRecords(serverDtos);
return Result.OK(page);
@ -365,8 +369,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
Map<String, Object> values = new HashMap<>();
try {
String token = ManageUtil.getToken();
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.SERVER_APP,
MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
List<Host> hosts = monitorAlarm.listApp(MonitorConstant.pageNo, MonitorConstant.pageSize, token).getResult().getRecords();
Map<String, Host> hostMap = hosts.stream().collect(Collectors.toMap(Host::getHostId, Host -> Host));
for (SysServer server : sysServers) {
Boolean online = null;

View File

@ -1,10 +1,6 @@
package org.jeecg.modules.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("")
public class AlarmController {

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.system.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -11,6 +12,7 @@ import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
@ -142,22 +144,16 @@ public class SysRoleController {
//@RequiresPermissions("system:role:edit")
@RequestMapping(value = "/edit",method = {RequestMethod.PUT,RequestMethod.POST})
public Result<SysRole> edit(@RequestBody SysRole role) {
Result<SysRole> result = new Result<SysRole>();
SysRole sysrole = sysRoleService.getById(role.getId());
if(sysrole==null) {
result.error500("未找到对应实体");
}else {
role.setUpdateTime(new Date());
boolean ok = sysRoleService.updateById(role);
//TODO 返回false说明什么
if(ok) {
result.success("修改成功!");
}
}
return result;
String roleId = role.getId();
SysRole sysRole = sysRoleService.getById(roleId);
if (ObjectUtil.isNull(sysRole))
return Result.error(Prompt.DATA_NOT_EXITS);
boolean success = sysRoleService.updateById(role);
if (success)
return Result.OK(Prompt.UPDATE_SUCC);
return Result.error(Prompt.UPDATE_ERR);
}
/**
* 通过id删除
* @param id

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.system.mapper.SysUserDepartMapper">
<select id="getUserDepartByUid" parameterType="String" resultType="org.jeecg.modules.base.entity.postgre.SysUserDepart">
SELECT *
SELECT user_id, dep_id
FROM sys_user_depart
WHERE user_id = #{userId, jdbcType=VARCHAR}
</select>

View File

@ -749,7 +749,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
arr = departs.split(",");
}
//查询已关联部门
List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
// List<SysUserDepart> userDepartList = sysUserDepartMapper.selectList(new QueryWrapper<SysUserDepart>().lambda().eq(SysUserDepart::getUserId, user.getId()));
List<SysUserDepart> userDepartList = sysUserDepartMapper.getUserDepartByUid(user.getId());
if(userDepartList != null && userDepartList.size()>0){
for(SysUserDepart depart : userDepartList ){
//修改已关联部门删除部门用户角色关系