Bläddra i källkod

fix: 设备诊断

sun-chaochao 3 år sedan
förälder
incheckning
8eb7b85ba3

+ 16 - 3
src/pages/device/Instance/Detail/Diagnose/Message/index.tsx

@@ -23,6 +23,21 @@ import Log from './Log';
 import { DiagnoseStatusModel, messageStatusMap, messageStyleMap } from '../Status/model';
 import { observer } from '@formily/reactive-react';
 
+// const DataTypeComponent = (value: string) => {
+//   switch (value) {
+//     case 'array':
+//       return <div>{value}array</div>
+//     // case 'enum':
+//     //   return <div>{value}</div>
+//     case 'geo':
+//       return <div>{value}geo</div>
+//     case 'file':
+//       return <div>{value}file</div>
+//     default:
+//       return <div>{value}</div>
+//   }
+// }
+
 const DatePicker1: any = DatePicker;
 
 const Message = observer(() => {
@@ -287,6 +302,7 @@ const Message = observer(() => {
       FSelect,
       FDatePicker,
       NumberPicker,
+      DataTypeComponent,
     },
   });
 
@@ -328,9 +344,6 @@ const Message = observer(() => {
                   type: 'string',
                   'x-decorator': 'FormItem',
                   'x-component': 'PreviewText.Input',
-                  // 'x-decorator-props': {
-                  //   tooltip: '使用固定的通知配置来发送此通知模版',
-                  // },
                 },
               },
             },

+ 191 - 39
src/pages/device/Instance/Detail/Diagnose/Status/ManualInspection.tsx

@@ -2,8 +2,9 @@ import { Button, Descriptions, Modal } from 'antd';
 import styles from './index.less';
 import { InfoCircleOutlined } from '@ant-design/icons';
 import { useHistory } from 'umi';
-import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
+import { getMenuPathByCode, getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
 import { InstanceModel } from '@/pages/device/Instance';
+import { randomString } from '@/utils/util';
 interface Props {
   close: () => void;
   data: any;
@@ -19,6 +20,187 @@ const ManualInspection = (props: Props) => {
     props.save(data);
   };
 
+  const dataRender = () => {
+    if (data.type === 'device' || data.type === 'product') {
+      return (
+        <>
+          <div style={{ flex: 1 }}>
+            <div className={styles.alert}>
+              <InfoCircleOutlined style={{ marginRight: 10 }} />
+              请检查配置项是否填写正确,若您确定该项无需诊断可
+              <a
+                onClick={() => {
+                  okBtn();
+                }}
+              >
+                忽略
+              </a>
+            </div>
+            <div style={{ marginTop: 10 }}>
+              <Descriptions title={data?.data?.name} layout="vertical" bordered>
+                {(data?.data?.properties || []).map((item: any) => (
+                  <Descriptions.Item
+                    key={item.property}
+                    label={`${item.name}${item?.description ? `(${item.description})` : ''}`}
+                  >
+                    {data?.configuration[item.property] || ''}
+                  </Descriptions.Item>
+                ))}
+              </Descriptions>
+            </div>
+          </div>
+          {data?.data?.description ? (
+            <div
+              style={{ width: '50%', border: '1px solid #f0f0f0', padding: 10, borderLeft: 'none' }}
+            >
+              <h4>诊断项说明</h4>
+              <p>{data?.data?.description}</p>
+            </div>
+          ) : (
+            ''
+          )}
+        </>
+      );
+    } else if (data.type === 'cloud') {
+      return (
+        <>
+          <div style={{ flex: 1 }}>
+            <div className={styles.alert}>
+              <InfoCircleOutlined style={{ marginRight: 10 }} />
+              请检查配置项是否填写正确,若您确定该项无需诊断可
+              <a
+                onClick={() => {
+                  okBtn();
+                }}
+              >
+                忽略
+              </a>
+            </div>
+            <div style={{ marginTop: 10 }}>
+              <Descriptions title={data?.data?.name} layout="vertical" bordered>
+                {data.configuration?.provider === 'OneNet' ? (
+                  <>
+                    <Descriptions.Item label={'接口地址'}>
+                      {data?.configuration?.configuration?.apiAddress || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'apiKey'}>
+                      {data?.configuration?.configuration?.apiKey || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'通知Token'}>
+                      {data?.configuration?.configuration?.validateToken || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'aesKey'}>
+                      {data?.configuration?.configuration?.aesKey || ''}
+                    </Descriptions.Item>
+                  </>
+                ) : (
+                  <>
+                    <Descriptions.Item label={'接口地址'}>
+                      {data?.configuration?.configuration?.apiAddress || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'appKey'}>
+                      {data?.configuration?.configuration?.appKey || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'appSecret'}>
+                      {data?.configuration?.configuration?.appSecret || ''}
+                    </Descriptions.Item>
+                  </>
+                )}
+              </Descriptions>
+            </div>
+          </div>
+          {data?.configuration?.configuration?.description ? (
+            <div
+              style={{ width: '50%', border: '1px solid #f0f0f0', padding: 10, borderLeft: 'none' }}
+            >
+              <h4>诊断项说明</h4>
+              <p>{data?.configuration?.configuration?.description}</p>
+            </div>
+          ) : (
+            ''
+          )}
+        </>
+      );
+    } else if (data.type === 'media') {
+      return (
+        <>
+          <div style={{ flex: 1 }}>
+            <div className={styles.alert}>
+              <InfoCircleOutlined style={{ marginRight: 10 }} />
+              请检查配置项是否填写正确,若您确定该项无需诊断可
+              <a
+                onClick={() => {
+                  okBtn();
+                }}
+              >
+                忽略
+              </a>
+            </div>
+            <div style={{ marginTop: 10 }}>
+              <Descriptions title={data?.data?.name} layout="vertical" bordered>
+                {data?.configuration?.configuration?.shareCluster ? (
+                  <>
+                    <Descriptions.Item label={'SIP 域'}>
+                      {data?.configuration?.configuration?.domain || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'SIP ID'}>
+                      {data?.configuration?.configuration?.sipId || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'集群'}>
+                      {data?.configuration?.configuration?.shareCluster ? '共享配置' : '独立配置'}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'SIP 地址'}>
+                      {`${data?.configuration?.configuration?.hostPort?.host}:${data?.configuration?.configuration?.hostPort?.port}`}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'公网 Host'}>
+                      {`${data?.configuration?.configuration?.hostPort?.publicHost}:${data?.configuration?.configuration?.hostPort?.publicPort}`}
+                    </Descriptions.Item>
+                  </>
+                ) : (
+                  <>
+                    <Descriptions.Item label={'SIP 域'}>
+                      {data?.configuration?.configuration?.domain || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'SIP ID'}>
+                      {data?.configuration?.configuration?.sipId || ''}
+                    </Descriptions.Item>
+                    <Descriptions.Item label={'集群'}>
+                      {data?.configuration?.configuration?.shareCluster ? '共享配置' : '独立配置'}
+                    </Descriptions.Item>
+                    {data?.configuration?.configuration?.cluster.map((i: any, it: number) => (
+                      <div key={randomString()}>
+                        <div>节点{it + 1}</div>
+                        <Descriptions.Item label={'节点名称'}>
+                          {i?.clusterNodeId || ''}
+                        </Descriptions.Item>
+                        <Descriptions.Item label={'SIP 地址'}>
+                          {`${i.host}:${i?.port}`}
+                        </Descriptions.Item>
+                        <Descriptions.Item label={'公网 Host'}>
+                          {`${i?.publicHost}:${i?.publicPort}`}
+                        </Descriptions.Item>
+                      </div>
+                    ))}
+                  </>
+                )}
+              </Descriptions>
+            </div>
+          </div>
+          {data?.configuration?.configuration.description ? (
+            <div
+              style={{ width: '50%', border: '1px solid #f0f0f0', padding: 10, borderLeft: 'none' }}
+            >
+              <h4>诊断项说明</h4>
+              <p>{data?.configuration?.description}</p>
+            </div>
+          ) : (
+            ''
+          )}
+        </>
+      );
+    }
+  };
+
   return (
     <Modal
       title="人工检查"
@@ -32,13 +214,19 @@ const ManualInspection = (props: Props) => {
           onClick={() => {
             if (data.type === 'device') {
               InstanceModel.active = 'detail';
-            } else {
+            } else if (data.type === 'product') {
               history.push(
                 `${getMenuPathByParams(MENUS_CODE['device/Product/Detail'], data.productId)}`,
                 {
                   tab: 'access',
                 },
               );
+            } else {
+              history.push(
+                `${getMenuPathByCode(MENUS_CODE['link/AccessConfig/Detail'])}?id=${
+                  data.configuration?.id
+                }`,
+              );
             }
             props.close();
           }}
@@ -56,43 +244,7 @@ const ManualInspection = (props: Props) => {
       ]}
       visible
     >
-      <div style={{ display: 'flex' }}>
-        <div style={{ flex: 1 }}>
-          <div className={styles.alert}>
-            <InfoCircleOutlined style={{ marginRight: 10 }} />
-            请检查配置项是否填写正确,若您确定该项无需诊断可
-            <a
-              onClick={() => {
-                okBtn();
-              }}
-            >
-              忽略
-            </a>
-          </div>
-          <div style={{ marginTop: 10 }}>
-            <Descriptions title={data?.data?.name} layout="vertical" bordered>
-              {(data?.data?.properties || []).map((item: any) => (
-                <Descriptions.Item
-                  key={item.property}
-                  label={`${item.name}${item?.description ? `(${item.description})` : ''}`}
-                >
-                  {data?.configuration[item.property] || ''}
-                </Descriptions.Item>
-              ))}
-            </Descriptions>
-          </div>
-        </div>
-        {data?.data?.description ? (
-          <div
-            style={{ width: '50%', border: '1px solid #f0f0f0', padding: 10, borderLeft: 'none' }}
-          >
-            <h4>诊断项说明</h4>
-            <p>{data?.data?.description}</p>
-          </div>
-        ) : (
-          ''
-        )}
-      </div>
+      <div style={{ display: 'flex' }}>{dataRender()}</div>
     </Modal>
   );
 };

+ 153 - 32
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -208,16 +208,19 @@ const Status = observer((props: Props) => {
         }
       }
     });
-
   // 设备接入网关
   const diagnoseGateway = () =>
     new Promise((resolve) => {
+      const desc =
+        providerType && ['child-device', 'cloud'].includes(providerType)
+          ? '诊断设备接入网关状态是否正常,网关配置是否正确'
+          : '诊断设备接入网关状态是否正常,禁用状态将导致连接失败';
       if (device.state?.value === 'online') {
         setTimeout(() => {
           DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
             key: 'gateway',
             name: '设备接入网关',
-            desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
+            desc: desc,
             status: 'success',
             text: '正常',
             info: null,
@@ -233,19 +236,81 @@ const Status = observer((props: Props) => {
               if (response.status === 200) {
                 DiagnoseStatusModel.gateway = response.result;
                 if (response.result?.state?.value === 'enabled') {
-                  item = {
-                    key: 'gateway',
-                    name: '设备接入网关',
-                    desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
-                    status: 'success',
-                    text: '正常',
-                    info: null,
-                  };
+                  if (providerType === 'cloud' || device?.accessProvider === 'gb28181-2016') {
+                    item = {
+                      key: 'gateway',
+                      name: '设备接入网关',
+                      desc: desc,
+                      status: 'error',
+                      text: '可能存在异常',
+                      info: (
+                        <div>
+                          <div className={styles.infoItem}>
+                            <Badge
+                              status="default"
+                              text={
+                                <span>
+                                  请
+                                  <a
+                                    onClick={async () => {
+                                      const config = await service.getGatewayDetail(
+                                        response.result?.id || '',
+                                      );
+                                      if (config.status === 200) {
+                                        manualInspection({
+                                          type: providerType,
+                                          key: `gateway`,
+                                          name: `设备接入网关`,
+                                          desc: desc,
+                                          data: { name: `${device?.accessProvider}配置` },
+                                          configuration: { ...config.result },
+                                        });
+                                      }
+                                    }}
+                                  >
+                                    人工检查
+                                  </a>
+                                  网关配置是否已填写正确,若您确定该项无需诊断可
+                                  <Popconfirm
+                                    title="确认忽略?"
+                                    onConfirm={() => {
+                                      DiagnoseStatusModel.list = modifyArrayList(
+                                        DiagnoseStatusModel.list,
+                                        {
+                                          key: 'gateway',
+                                          name: '设备接入网关',
+                                          desc: desc,
+                                          status: 'success',
+                                          text: '正常',
+                                          info: null,
+                                        },
+                                      );
+                                    }}
+                                  >
+                                    <a>忽略</a>
+                                  </Popconfirm>
+                                </span>
+                              }
+                            />
+                          </div>
+                        </div>
+                      ),
+                    };
+                  } else {
+                    item = {
+                      key: 'gateway',
+                      name: '设备接入网关',
+                      desc: desc,
+                      status: 'success',
+                      text: '正常',
+                      info: null,
+                    };
+                  }
                 } else {
                   item = {
                     key: 'gateway',
                     name: '设备接入网关',
-                    desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
+                    desc: desc,
                     status: 'error',
                     text: '异常',
                     info: (
@@ -270,7 +335,7 @@ const Status = observer((props: Props) => {
                                           {
                                             key: 'gateway',
                                             name: '设备接入网关',
-                                            desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
+                                            desc: desc,
                                             status: 'success',
                                             text: '正常',
                                             info: null,
@@ -306,19 +371,81 @@ const Status = observer((props: Props) => {
           }
         } else {
           if (DiagnoseStatusModel.gateway?.state?.value === 'enabled') {
-            item = {
-              key: 'gateway',
-              name: '设备接入网关',
-              desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
-              status: 'success',
-              text: '正常',
-              info: null,
-            };
+            if (providerType === 'cloud' || device?.accessProvider === 'gb28181-2016') {
+              item = {
+                key: 'gateway',
+                name: '设备接入网关',
+                desc: desc,
+                status: 'error',
+                text: '可能存在异常',
+                info: (
+                  <div>
+                    <div className={styles.infoItem}>
+                      <Badge
+                        status="default"
+                        text={
+                          <span>
+                            请
+                            <a
+                              onClick={async () => {
+                                const config = await service.getGatewayDetail(
+                                  DiagnoseStatusModel.gateway?.id || '',
+                                );
+                                if (config.status === 200) {
+                                  manualInspection({
+                                    type: providerType,
+                                    key: `gateway`,
+                                    name: `设备接入网关`,
+                                    desc: desc,
+                                    data: { name: `${device?.accessProvider}配置` },
+                                    configuration: { ...config.result },
+                                  });
+                                }
+                              }}
+                            >
+                              人工检查
+                            </a>
+                            网关配置是否已填写正确,若您确定该项无需诊断可
+                            <Popconfirm
+                              title="确认忽略?"
+                              onConfirm={() => {
+                                DiagnoseStatusModel.list = modifyArrayList(
+                                  DiagnoseStatusModel.list,
+                                  {
+                                    key: 'gateway',
+                                    name: '设备接入网关',
+                                    desc: desc,
+                                    status: 'success',
+                                    text: '正常',
+                                    info: null,
+                                  },
+                                );
+                              }}
+                            >
+                              <a>忽略</a>
+                            </Popconfirm>
+                          </span>
+                        }
+                      />
+                    </div>
+                  </div>
+                ),
+              };
+            } else {
+              item = {
+                key: 'gateway',
+                name: '设备接入网关',
+                desc: desc,
+                status: 'success',
+                text: '正常',
+                info: null,
+              };
+            }
           } else {
             item = {
               key: 'gateway',
               name: '设备接入网关',
-              desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
+              desc: desc,
               status: 'error',
               text: '异常',
               info: (
@@ -341,7 +468,7 @@ const Status = observer((props: Props) => {
                                     {
                                       key: 'gateway',
                                       name: '设备接入网关',
-                                      desc: '诊断设备接入网关状态是否正常,禁用状态将导致连接失败',
+                                      desc: desc,
                                       status: 'success',
                                       text: '正常',
                                       info: null,
@@ -428,7 +555,7 @@ const Status = observer((props: Props) => {
         } else {
           let item: ListProps | undefined = undefined;
           const response = await service.detail(device?.parentId);
-          DiagnoseStatusModel.parent = resp.result;
+          DiagnoseStatusModel.parent = response.result;
           if (response.status === 200) {
             if (response?.result?.state?.value === 'notActive') {
               item = {
@@ -704,7 +831,7 @@ const Status = observer((props: Props) => {
   const diagnoseProductAuthConfig = () =>
     new Promise(async (resolve) => {
       if (device?.productId) {
-        const response = await service.queryDeviceConfig(device.productId);
+        const response = await service.queryProductConfig(device.productId);
         if (response.status === 200 && response.result.length > 0) {
           DiagnoseStatusModel.configuration.product = response.result;
           const list = [...DiagnoseStatusModel.list];
@@ -1758,21 +1885,15 @@ const Status = observer((props: Props) => {
       await diagnoseDeviceAuthConfig();
     } else if (providerType === 'child-device') {
       DiagnoseStatusModel.list = [...childInitList];
-      await diagnoseNetwork();
       await diagnoseGateway();
       DiagnoseStatusModel.percent = 20;
       await diagnoseParentDevice();
       await diagnoseProduct();
-      await diagnoseDevice();
       DiagnoseStatusModel.percent = 40;
+      await diagnoseDevice();
+      DiagnoseStatusModel.percent = 60;
       await diagnoseProductAuthConfig();
       await diagnoseDeviceAuthConfig();
-      DiagnoseStatusModel.percent = 60;
-      // await diagnoseModbus();
-      // await diagnoseOpcua();
-      // await diagnoseModbusState();
-      // await diagnoseOpcuaState();
-      // await diagnoseDataPointBind();
       DiagnoseStatusModel.percent = 80;
     } else if (providerType === 'media') {
       DiagnoseStatusModel.list = [...mediaInitList];

+ 8 - 8
src/pages/device/Instance/Detail/Diagnose/Status/model.ts

@@ -81,14 +81,14 @@ export const childInitList: ListProps[] = [
   //   text: '正在诊断中...',
   //   info: null,
   // },
-  {
-    key: 'network',
-    name: '网络组件',
-    desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
-    status: 'loading',
-    text: '正在诊断中...',
-    info: null,
-  },
+  // {
+  //   key: 'network',
+  //   name: '网络组件',
+  //   desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
+  //   status: 'loading',
+  //   text: '正在诊断中...',
+  //   info: null,
+  // },
   {
     key: 'gateway',
     name: '设备接入网关',

+ 4 - 0
src/pages/device/Instance/service.ts

@@ -361,6 +361,10 @@ class Service extends BaseService<DeviceInstance> {
       method: 'POST',
       data,
     });
+  public getGatewayDetail = (id: string) =>
+    request(`/${SystemConst.API_BASE}/gateway/device/${id}`, {
+      method: 'GET',
+    });
 }
 
 export default Service;

+ 17 - 3
src/pages/system/Role/Detail/Permission/Allocate/MenuPermission.tsx

@@ -27,10 +27,14 @@ const MenuPermission = (props: Props) => {
     setIndeterminate(props.value?.check === 2);
     const val =
       (props.value?.assetAccesses || []).filter((i: any) => i?.granted)[0]?.supportId || '';
+    // if (!val && props.value?.check === 1) {
+    //   setCheckValue('creator');
+    // } else {
     setCheckValue(val);
+    // }
   }, [props.value]);
 
-  const checkAllData: any = (data: any[], check: boolean) => {
+  const checkAllData: any = (data: any[], check: boolean, cvalue?: any) => {
     if (Array.isArray(data) && data.length > 0) {
       return data.map((item) => {
         const buttons = (item?.buttons || []).map((i: any) => {
@@ -41,9 +45,15 @@ const MenuPermission = (props: Props) => {
         });
         return {
           ...item,
+          assetAccesses: (item?.assetAccesses || []).map((i: any) => {
+            return {
+              ...i,
+              granted: !cvalue ? false : !i.granted ? i.supportId === cvalue : i.granted,
+            };
+          }),
           check: check ? 1 : 3, // 1: 全选 2: 只选了部分 3: 一个都没选
           buttons: [...buttons],
-          children: item?.children ? checkAllData(item?.children || [], check) : [],
+          children: item?.children ? checkAllData(item?.children || [], check, cvalue) : [],
         };
       });
     }
@@ -100,8 +110,10 @@ const MenuPermission = (props: Props) => {
               }}
               onChange={(e) => {
                 let access: any[] = [];
+                let cvalue: any = checkValue;
                 if (e.target.checked && !checkValue) {
                   setCheckValue('creator');
+                  cvalue = 'creator';
                   access = (value?.assetAccesses || []).map((i: any) => {
                     return {
                       ...i,
@@ -110,6 +122,7 @@ const MenuPermission = (props: Props) => {
                   });
                 } else if (!e.target.checked) {
                   setCheckValue('');
+                  cvalue = '';
                   access = (value?.assetAccesses || []).map((i: any) => {
                     return {
                       ...i,
@@ -117,6 +130,7 @@ const MenuPermission = (props: Props) => {
                     };
                   });
                 } else {
+                  cvalue = checkValue;
                   access = value?.assetAccesses || [];
                 }
                 setCheckAll(e.target.checked);
@@ -132,7 +146,7 @@ const MenuPermission = (props: Props) => {
                   assetAccesses: [...access],
                   check: e.target.checked ? 1 : 3, // 1: 全选 2: 只选了部分 3: 一个都没选
                   buttons: [...buttons],
-                  children: checkAllData(value.children || [], e.target.checked),
+                  children: checkAllData(value.children || [], e.target.checked, cvalue),
                 });
               }}
             >