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 org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主机连接日志 api
|
* 主机连接日志 api
|
||||||
@@ -47,5 +48,12 @@ public class HostConnectLogController {
|
|||||||
return hostConnectLogService.getHostConnectLogPage(request);
|
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.framework.mybatis.core.mapper.IMapper;
|
||||||
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主机连接日志 Mapper 接口
|
* 主机连接日志 Mapper 接口
|
||||||
@@ -14,4 +17,14 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface HostConnectLogDAO extends IMapper<HostConnectLogDO> {
|
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.HostConnectStatusEnum;
|
||||||
import com.orion.ops.module.asset.enums.HostConnectTypeEnum;
|
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);
|
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.define.wrapper.DataGrid;
|
||||||
import com.orion.lang.utils.Arrays1;
|
import com.orion.lang.utils.Arrays1;
|
||||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
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.convert.HostConnectLogConvert;
|
||||||
import com.orion.ops.module.asset.dao.HostConnectLogDAO;
|
import com.orion.ops.module.asset.dao.HostConnectLogDAO;
|
||||||
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
import com.orion.ops.module.asset.entity.domain.HostConnectLogDO;
|
||||||
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
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));
|
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
|
* 构建查询 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
|
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>
|
</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>
|
</mapper>
|
||||||
|
|||||||
@@ -42,3 +42,13 @@ export interface HostConnectLogQueryResponse extends TableData {
|
|||||||
export function getHostConnectLogPage(request: HostConnectLogQueryRequest) {
|
export function getHostConnectLogPage(request: HostConnectLogQueryRequest) {
|
||||||
return axios.post<DataGrid<HostConnectLogQueryResponse>>('/asset/host-connect-log/query', request);
|
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<{
|
const props = defineProps<{
|
||||||
hosts: AuthorizedHostQueryResponse,
|
hosts: AuthorizedHostQueryResponse,
|
||||||
filterValue: string,
|
filterValue: string,
|
||||||
newConnectionType: string
|
newConnectionType: string,
|
||||||
|
latestHosts: Array<number>
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const hostList = ref<Array<HostQueryResponse>>([]);
|
const hostList = ref<Array<HostQueryResponse>>([]);
|
||||||
@@ -93,7 +94,7 @@
|
|||||||
list = list.filter(item => item.favorite);
|
list = list.filter(item => item.favorite);
|
||||||
} else if (NewConnectionType.LATEST === props.newConnectionType) {
|
} else if (NewConnectionType.LATEST === props.newConnectionType) {
|
||||||
// 过滤-最近连接
|
// 过滤-最近连接
|
||||||
// todo
|
list = list.filter(s => props.latestHosts.includes(s.id));
|
||||||
}
|
}
|
||||||
// 排序
|
// 排序
|
||||||
hostList.value = list?.sort((o1, o2) => {
|
hostList.value = list?.sort((o1, o2) => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<a-radio-group v-model="newConnectionType"
|
<a-radio-group v-model="newConnectionType"
|
||||||
type="button"
|
type="button"
|
||||||
class="usn"
|
class="usn"
|
||||||
:options="toOptions(NewConnectionTypeKey)"
|
:options="toOptions(newConnectionTypeKey)"
|
||||||
@change="changeNewConnectionType" />
|
@change="changeNewConnectionType" />
|
||||||
<!-- 过滤 -->
|
<!-- 过滤 -->
|
||||||
<a-auto-complete v-model="filterValue"
|
<a-auto-complete v-model="filterValue"
|
||||||
@@ -60,7 +60,8 @@
|
|||||||
class="host-view-container"
|
class="host-view-container"
|
||||||
:hosts="hosts"
|
:hosts="hosts"
|
||||||
:filter-value="filterValue"
|
:filter-value="filterValue"
|
||||||
:new-connection-type="newConnectionType" />
|
:new-connection-type="newConnectionType"
|
||||||
|
:latest-hosts="latestHosts" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,12 +79,13 @@
|
|||||||
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
||||||
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
|
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
|
||||||
import { onBeforeMount, ref } from 'vue';
|
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 useLoading from '@/hooks/loading';
|
||||||
import { useDictStore, useTerminalStore } from '@/store';
|
import { useAppStore, useDictStore, useTerminalStore } from '@/store';
|
||||||
import { dataColor } from '@/utils';
|
import { dataColor } from '@/utils';
|
||||||
import { tagColor } from '@/views/asset/host-list/types/const';
|
import { tagColor } from '@/views/asset/host-list/types/const';
|
||||||
import HostsView from './hosts-view.vue';
|
import HostsView from './hosts-view.vue';
|
||||||
|
import { getLatestConnectHostId } from '@/api/asset/host-connect-log';
|
||||||
|
|
||||||
const { loading, setLoading } = useLoading();
|
const { loading, setLoading } = useLoading();
|
||||||
const { toOptions } = useDictStore();
|
const { toOptions } = useDictStore();
|
||||||
@@ -93,6 +95,7 @@
|
|||||||
const filterValue = ref('');
|
const filterValue = ref('');
|
||||||
const filterOptions = ref<Array<SelectOptionData>>([]);
|
const filterOptions = ref<Array<SelectOptionData>>([]);
|
||||||
const hosts = ref<AuthorizedHostQueryResponse>({} as AuthorizedHostQueryResponse);
|
const hosts = ref<AuthorizedHostQueryResponse>({} as AuthorizedHostQueryResponse);
|
||||||
|
const latestHosts = ref<Array<number>>([]);
|
||||||
|
|
||||||
// 过滤输入
|
// 过滤输入
|
||||||
const searchFilter = (searchValue: string, option: SelectOptionData) => {
|
const searchFilter = (searchValue: string, option: SelectOptionData) => {
|
||||||
@@ -125,10 +128,11 @@
|
|||||||
}).forEach(s => filterOptions.value.push(s));
|
}).forEach(s => filterOptions.value.push(s));
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化
|
// 加载主机信息
|
||||||
const init = async () => {
|
const initHosts = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
// 加载主机信息
|
||||||
const { data } = await getCurrentAuthorizedHost();
|
const { data } = await getCurrentAuthorizedHost();
|
||||||
hosts.value = data;
|
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user