修改无分类数据面板bug和搜索问题
This commit is contained in:
parent
9828397dd9
commit
c69984929a
|
|
@ -57,7 +57,7 @@ export class GenDevService {
|
|||
this.logger.log('初始化设备分类');
|
||||
// 创建网系类型分类
|
||||
let systemTypeTaxonomy = await db.taxonomy.findFirst({
|
||||
where: { slug: 'network_type' }, // 改名为 network_type
|
||||
where: { slug: 'network_type' },
|
||||
});
|
||||
if (!systemTypeTaxonomy) {
|
||||
systemTypeTaxonomy = await db.taxonomy.create({
|
||||
|
|
@ -97,112 +97,7 @@ export class GenDevService {
|
|||
});
|
||||
}
|
||||
|
||||
this.logger.log('创建三层分类记录');
|
||||
|
||||
// 定义三层分类结构
|
||||
const networkTypes = [
|
||||
{
|
||||
name: '办公网络',
|
||||
systemTypes: [
|
||||
{
|
||||
name: '文印系统',
|
||||
faultTypes: ['电源故障', '主板故障', '内存故障', '硬盘故障'],
|
||||
},
|
||||
{
|
||||
name: '内网系统',
|
||||
faultTypes: ['系统崩溃', '应用程序错误', '病毒感染', '驱动问题'],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: '安全网络',
|
||||
systemTypes: [
|
||||
{
|
||||
name: '监控系统',
|
||||
faultTypes: ['摄像头故障', '录像异常', '存储故障', '网络断开'],
|
||||
},
|
||||
{
|
||||
name: '门禁系统',
|
||||
faultTypes: ['读卡器故障', '门锁故障', '系统异常', '网络故障'],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 创建三层分类结构
|
||||
for (const networkTypeData of networkTypes) {
|
||||
// 创建网系类型
|
||||
const networkType = await db.term.findFirst({
|
||||
where: {
|
||||
name: networkTypeData.name,
|
||||
taxonomyId: systemTypeTaxonomy.id,
|
||||
},
|
||||
});
|
||||
|
||||
let networkTypeId;
|
||||
if (!networkType) {
|
||||
const newNetworkType = await db.term.create({
|
||||
data: {
|
||||
name: networkTypeData.name,
|
||||
taxonomyId: systemTypeTaxonomy.id,
|
||||
hasChildren: true,
|
||||
},
|
||||
});
|
||||
networkTypeId = newNetworkType.id;
|
||||
} else {
|
||||
networkTypeId = networkType.id;
|
||||
}
|
||||
|
||||
// 为每个网系类型创建系统类型
|
||||
for (const systemTypeData of networkTypeData.systemTypes) {
|
||||
const systemType = await db.term.findFirst({
|
||||
where: {
|
||||
name: systemTypeData.name,
|
||||
taxonomyId: systemSubTypeTaxonomy.id,
|
||||
parentId: networkTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
let systemTypeId;
|
||||
if (!systemType) {
|
||||
const newSystemType = await db.term.create({
|
||||
data: {
|
||||
name: systemTypeData.name,
|
||||
taxonomyId: systemSubTypeTaxonomy.id,
|
||||
parentId: networkTypeId,
|
||||
hasChildren: true,
|
||||
},
|
||||
});
|
||||
systemTypeId = newSystemType.id;
|
||||
} else {
|
||||
systemTypeId = systemType.id;
|
||||
}
|
||||
|
||||
// 为每个系统类型创建故障类型
|
||||
for (const faultTypeName of systemTypeData.faultTypes) {
|
||||
const faultType = await db.term.findFirst({
|
||||
where: {
|
||||
name: faultTypeName,
|
||||
taxonomyId: deviceTypeTaxonomy.id,
|
||||
parentId: systemTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!faultType) {
|
||||
await db.term.create({
|
||||
data: {
|
||||
name: faultTypeName,
|
||||
taxonomyId: deviceTypeTaxonomy.id,
|
||||
parentId: systemTypeId,
|
||||
hasChildren: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log('初始化三层设备分类完成');
|
||||
this.logger.log('初始化设备分类完成');
|
||||
}
|
||||
private async calculateCounts() {
|
||||
this.counts = await getCounts();
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ const DashboardPage = () => {
|
|||
|
||||
// 初始化选中的网系和系统类型(选择故障最多的)
|
||||
useEffect(() => {
|
||||
if (devices && networkTypeTerms && systemTypeTerms && !selectedNetworkType) {
|
||||
if (devices && networkTypeTerms && systemTypeTerms && networkTypeTerms.length > 0 && !selectedNetworkType) {
|
||||
// 找到故障最多的网系类型
|
||||
const networkCounts = {};
|
||||
networkTypeTerms.forEach(type => {
|
||||
|
|
@ -93,33 +93,37 @@ const DashboardPage = () => {
|
|||
}
|
||||
});
|
||||
|
||||
const maxNetworkTypeId = Object.keys(networkCounts).reduce((a, b) =>
|
||||
networkCounts[a] > networkCounts[b] ? a : b
|
||||
);
|
||||
|
||||
setSelectedNetworkType(maxNetworkTypeId);
|
||||
|
||||
// 找到该网系下故障最多的系统类型
|
||||
const systemCounts = {};
|
||||
const relevantSystemTypes = systemTypeTerms.filter(st => st.parentId === maxNetworkTypeId);
|
||||
|
||||
relevantSystemTypes.forEach(type => {
|
||||
systemCounts[type.id] = 0;
|
||||
});
|
||||
|
||||
devices.forEach(device => {
|
||||
const deviceTerms = getDeviceTerms(device);
|
||||
const systemType = systemTypeTerms.find(t => t.name === deviceTerms.systemType);
|
||||
if (systemType && Object.prototype.hasOwnProperty.call(systemCounts, systemType.id)) {
|
||||
systemCounts[systemType.id]++;
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(systemCounts).length > 0) {
|
||||
const maxSystemTypeId = Object.keys(systemCounts).reduce((a, b) =>
|
||||
systemCounts[a] > systemCounts[b] ? a : b
|
||||
const networkCountKeys = Object.keys(networkCounts);
|
||||
if (networkCountKeys.length > 0) {
|
||||
const maxNetworkTypeId = networkCountKeys.reduce((a, b) =>
|
||||
networkCounts[a] > networkCounts[b] ? a : b
|
||||
);
|
||||
setSelectedSystemType(maxSystemTypeId);
|
||||
|
||||
setSelectedNetworkType(maxNetworkTypeId);
|
||||
|
||||
// 找到该网系下故障最多的系统类型
|
||||
const systemCounts = {};
|
||||
const relevantSystemTypes = systemTypeTerms.filter(st => st.parentId === maxNetworkTypeId);
|
||||
|
||||
relevantSystemTypes.forEach(type => {
|
||||
systemCounts[type.id] = 0;
|
||||
});
|
||||
|
||||
devices.forEach(device => {
|
||||
const deviceTerms = getDeviceTerms(device);
|
||||
const systemType = systemTypeTerms.find(t => t.name === deviceTerms.systemType);
|
||||
if (systemType && Object.prototype.hasOwnProperty.call(systemCounts, systemType.id)) {
|
||||
systemCounts[systemType.id]++;
|
||||
}
|
||||
});
|
||||
|
||||
const systemCountKeys = Object.keys(systemCounts);
|
||||
if (systemCountKeys.length > 0) {
|
||||
const maxSystemTypeId = systemCountKeys.reduce((a, b) =>
|
||||
systemCounts[a] > systemCounts[b] ? a : b
|
||||
);
|
||||
setSelectedSystemType(maxSystemTypeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [devices, networkTypeTerms, systemTypeTerms, selectedNetworkType]);
|
||||
|
|
@ -233,7 +237,9 @@ const DashboardPage = () => {
|
|||
|
||||
// 准备三层分类统计数据
|
||||
const prepareHierarchicalFaultData = () => {
|
||||
if (!devices || !networkTypeTerms) return { names: [], values: [] };
|
||||
if (!devices || !networkTypeTerms || networkTypeTerms.length === 0) {
|
||||
return { names: [], values: [] };
|
||||
}
|
||||
|
||||
const hierarchicalCounts = {};
|
||||
const totalDevices = devices.length;
|
||||
|
|
@ -263,7 +269,10 @@ const DashboardPage = () => {
|
|||
|
||||
// 修改系统类型分布数据(基于选中的网系类型,支持交互)
|
||||
const prepareGroupedSystemTypeDistribution = () => {
|
||||
if (!devices || !systemTypeTerms || !networkTypeTerms) return { groups: [], values: [] };
|
||||
if (!devices || !systemTypeTerms || !networkTypeTerms ||
|
||||
systemTypeTerms.length === 0 || networkTypeTerms.length === 0) {
|
||||
return { groups: [], values: [] };
|
||||
}
|
||||
|
||||
const networkGroups: Record<string, string[]> = {};
|
||||
const systemTypeCounts: Record<string, number> = {};
|
||||
|
|
@ -273,6 +282,11 @@ const DashboardPage = () => {
|
|||
? [networkTypeTerms.find(t => t.id === selectedNetworkType)].filter(Boolean)
|
||||
: networkTypeTerms;
|
||||
|
||||
// 如果没有找到目标网系类型,返回空数据
|
||||
if (targetNetworkTypes.length === 0) {
|
||||
return { groups: [], values: [] };
|
||||
}
|
||||
|
||||
// 初始化网系分组
|
||||
targetNetworkTypes.forEach(networkType => {
|
||||
networkGroups[networkType.name] = [];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Select, Spin } from "antd";
|
||||
import { api } from "@nice/client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import React from "react";
|
||||
|
||||
interface DeviceTypeSelectProps {
|
||||
|
|
@ -40,6 +40,19 @@ export default function DeviceTypeSelect({
|
|||
orderBy: { order: "asc" },
|
||||
});
|
||||
|
||||
// 使用 useRef 来跟踪之前的 systemTypeId
|
||||
const prevSystemTypeIdRef = useRef<string | undefined>(systemTypeId);
|
||||
|
||||
// 当系统类型改变时,清空当前选择
|
||||
useEffect(() => {
|
||||
if (prevSystemTypeIdRef.current !== systemTypeId) {
|
||||
prevSystemTypeIdRef.current = systemTypeId;
|
||||
if (onChange && value) {
|
||||
onChange(undefined);
|
||||
}
|
||||
}
|
||||
}, [systemTypeId]);
|
||||
|
||||
// 处理选项数据
|
||||
useEffect(() => {
|
||||
if (deviceTypes) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ server {
|
|||
# 监听80端口
|
||||
listen 80;
|
||||
# 服务器域名/IP地址,使用环境变量
|
||||
server_name 192.168.122.194;
|
||||
server_name 192.168.77.194;
|
||||
|
||||
# 基础性能优化配置
|
||||
# 启用tcp_nopush以优化数据发送
|
||||
|
|
@ -100,7 +100,7 @@ server {
|
|||
# 仅供内部使用
|
||||
internal;
|
||||
# 代理到认证服务
|
||||
proxy_pass http://192.168.122.194:3000/auth/file;
|
||||
proxy_pass http://192.168.77.194:3000/auth/file;
|
||||
|
||||
# 请求优化:不传递请求体
|
||||
proxy_pass_request_body off;
|
||||
|
|
|
|||
Loading…
Reference in New Issue