feat: 加载最近连接的主机.
This commit is contained in:
@@ -17,5 +17,15 @@ Authorization: {{token}}
|
||||
]
|
||||
}
|
||||
|
||||
### 查询用户最近连接的 ssh 主机
|
||||
POST {{baseUrl}}/asset/host-connect-log/latest-connect
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"limit": 10,
|
||||
"type": "SSH"
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机连接日志 api
|
||||
@@ -47,5 +48,12 @@ public class HostConnectLogController {
|
||||
return hostConnectLogService.getHostConnectLogPage(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/latest-connect")
|
||||
@Operation(summary = "查询用户最近连接的主机")
|
||||
public List<Long> getLatestConnectHostId(@RequestBody HostConnectLogQueryRequest request) {
|
||||
return hostConnectLogService.getLatestConnectHostId(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.orion.ops.module.asset.dao;
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机连接日志 Mapper 接口
|
||||
@@ -14,4 +17,14 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface HostConnectLogDAO extends IMapper<HostConnectLogDO> {
|
||||
|
||||
/**
|
||||
* 查询最近连接的 hostId
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param limit limit
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> selectLatestConnectHostId(@Param("userId") Long userId, @Param("type") String type, @Param("limit") Integer limit);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.orion.ops.module.asset.entity.vo.HostConnectLogVO;
|
||||
import com.orion.ops.module.asset.enums.HostConnectStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConnectTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机连接日志 服务类
|
||||
*
|
||||
@@ -40,4 +42,12 @@ public interface HostConnectLogService {
|
||||
*/
|
||||
void updateStatusByToken(String token, HostConnectStatusEnum status);
|
||||
|
||||
/**
|
||||
* 查询用户最近连接的主机
|
||||
*
|
||||
* @param request request
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> getLatestConnectHostId(HostConnectLogQueryRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.Arrays1;
|
||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.convert.HostConnectLogConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConnectLogDAO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
||||
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机连接日志 服务实现类
|
||||
@@ -68,6 +70,11 @@ public class HostConnectLogServiceImpl implements HostConnectLogService {
|
||||
hostConnectLogDAO.update(update, Conditions.eq(HostConnectLogDO::getToken, token));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getLatestConnectHostId(HostConnectLogQueryRequest request) {
|
||||
return hostConnectLogDAO.selectLatestConnectHostId(SecurityUtils.getLoginUserId(), request.getType(), request.getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询 wrapper
|
||||
*
|
||||
|
||||
@@ -26,4 +26,14 @@
|
||||
id, user_id, username, host_id, host_name, host_address, type, token, status, start_time, end_time, extra_info, create_time, update_time, deleted
|
||||
</sql>
|
||||
|
||||
<select id="selectLatestConnectHostId" resultType="java.lang.Long">
|
||||
SELECT DISTINCT host_id
|
||||
FROM host_connect_log
|
||||
WHERE deleted = 0
|
||||
AND type = #{type}
|
||||
AND user_id = #{userId}
|
||||
ORDER BY id DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user