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>
|
||||
|
||||
@@ -42,3 +42,13 @@ export interface HostConnectLogQueryResponse extends TableData {
|
||||
export function getHostConnectLogPage(request: HostConnectLogQueryRequest) {
|
||||
return axios.post<DataGrid<HostConnectLogQueryResponse>>('/asset/host-connect-log/query', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户最近连接的主机
|
||||
*/
|
||||
export function getLatestConnectHostId(type: string, limit: number) {
|
||||
return axios.post<Array<number>>('/asset/host-connect-log/latest-connect', {
|
||||
type,
|
||||
limit
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
const props = defineProps<{
|
||||
hosts: AuthorizedHostQueryResponse,
|
||||
filterValue: string,
|
||||
newConnectionType: string
|
||||
newConnectionType: string,
|
||||
latestHosts: Array<number>
|
||||
}>();
|
||||
|
||||
const hostList = ref<Array<HostQueryResponse>>([]);
|
||||
@@ -93,7 +94,7 @@
|
||||
list = list.filter(item => item.favorite);
|
||||
} else if (NewConnectionType.LATEST === props.newConnectionType) {
|
||||
// 过滤-最近连接
|
||||
// todo
|
||||
list = list.filter(s => props.latestHosts.includes(s.id));
|
||||
}
|
||||
// 排序
|
||||
hostList.value = list?.sort((o1, o2) => {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<a-radio-group v-model="newConnectionType"
|
||||
type="button"
|
||||
class="usn"
|
||||
:options="toOptions(NewConnectionTypeKey)"
|
||||
:options="toOptions(newConnectionTypeKey)"
|
||||
@change="changeNewConnectionType" />
|
||||
<!-- 过滤 -->
|
||||
<a-auto-complete v-model="filterValue"
|
||||
@@ -60,7 +60,8 @@
|
||||
class="host-view-container"
|
||||
:hosts="hosts"
|
||||
:filter-value="filterValue"
|
||||
:new-connection-type="newConnectionType" />
|
||||
:new-connection-type="newConnectionType"
|
||||
:latest-hosts="latestHosts" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -78,12 +79,13 @@
|
||||
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
||||
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
|
||||
import { onBeforeMount, ref } from 'vue';
|
||||
import { NewConnectionType, NewConnectionTypeKey } from '../../types/terminal.const';
|
||||
import { NewConnectionType, newConnectionTypeKey } from '../../types/terminal.const';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import { useDictStore, useTerminalStore } from '@/store';
|
||||
import { useAppStore, useDictStore, useTerminalStore } from '@/store';
|
||||
import { dataColor } from '@/utils';
|
||||
import { tagColor } from '@/views/asset/host-list/types/const';
|
||||
import HostsView from './hosts-view.vue';
|
||||
import { getLatestConnectHostId } from '@/api/asset/host-connect-log';
|
||||
|
||||
const { loading, setLoading } = useLoading();
|
||||
const { toOptions } = useDictStore();
|
||||
@@ -93,6 +95,7 @@
|
||||
const filterValue = ref('');
|
||||
const filterOptions = ref<Array<SelectOptionData>>([]);
|
||||
const hosts = ref<AuthorizedHostQueryResponse>({} as AuthorizedHostQueryResponse);
|
||||
const latestHosts = ref<Array<number>>([]);
|
||||
|
||||
// 过滤输入
|
||||
const searchFilter = (searchValue: string, option: SelectOptionData) => {
|
||||
@@ -125,10 +128,11 @@
|
||||
}).forEach(s => filterOptions.value.push(s));
|
||||
};
|
||||
|
||||
// 初始化
|
||||
const init = async () => {
|
||||
// 加载主机信息
|
||||
const initHosts = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
// 加载主机信息
|
||||
const { data } = await getCurrentAuthorizedHost();
|
||||
hosts.value = data;
|
||||
// 初始化过滤项
|
||||
@@ -138,8 +142,23 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 加载最近连接主机
|
||||
const loadLatestConnectHost = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
// 加载最近连接主机
|
||||
const { data } = await getLatestConnectHostId('SSH', useAppStore().defaultTablePageSize);
|
||||
latestHosts.value = data;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载主机信息
|
||||
onBeforeMount(init);
|
||||
onBeforeMount(initHosts);
|
||||
|
||||
// 加载最近连接主机
|
||||
onBeforeMount(loadLatestConnectHost);
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user