Переглянути джерело

feat: gs错误日志增加重试功能

xyh 2 роки тому
батько
коміт
969aa52e61

+ 12 - 1
packages/app/src/apis/gs.ts

@@ -5,8 +5,10 @@ import {
   AddReportingParams,
   AddSellParams,
   AddUnProductionRequisitionParams,
+  BaseResult,
+  ReSendErrorParams,
 } from '@models';
-import {gsRequest} from './request';
+import {gsRequest, request} from './request';
 
 /** 新增质检单 */
 export function addQuality(data: AddQualityParams) {
@@ -39,3 +41,12 @@ export function addSell(data: AddSellParams) {
 export function addRelcation(data: AddRelcationParams) {
   return gsRequest('/transferNotice', data);
 }
+
+/** 重新上传 */
+export function retryErrorInterface(data: ReSendErrorParams): BaseResult {
+  return request({
+    method: 'POST',
+    url: '/gsPlugOut/anew',
+    data,
+  });
+}

+ 11 - 0
packages/app/src/models/request/gs.ts

@@ -201,3 +201,14 @@ export type AddRelcationParams = [
     ];
   },
 ];
+
+/** gs错误信息重传 */
+export type ReSendErrorParams = {
+  id: string;
+  /** 请求地址 */
+  url: string;
+  /** 错误信息 */
+  errorInfo: string;
+  /** 数据 */
+  dataVal: string;
+};

+ 2 - 0
packages/app/src/models/response/queryList.ts

@@ -316,4 +316,6 @@ export type GSErrorListData = {
   dataVal: string;
   /** 日期 */
   scrq: string;
+  /** 是否重传 1未重传 0重传 */
+  transmissionType: 0 | 1;
 };

+ 68 - 0
packages/app/src/pages/gs-error-log/table/hooks.tsx

@@ -0,0 +1,68 @@
+import {retryErrorInterface} from '@apis';
+import {GSErrorListData} from '@models';
+import {useMutation} from '@tanstack/react-query';
+import {NORMAL_TABLE_WIDTH, HUGE_TABLE_WIDTH, SMALL_TABLE_WIDTH} from '@utils';
+import {Button, message} from 'antd';
+import {ColumnsType} from 'antd/es/table';
+import {useState} from 'react';
+
+const columns: ColumnsType<GSErrorListData> = [
+  {title: '请求地址', dataIndex: 'url', width: NORMAL_TABLE_WIDTH},
+  {title: '错误信息', dataIndex: 'errorInfo', width: HUGE_TABLE_WIDTH},
+  {title: '请求内容', dataIndex: 'dataVal', width: HUGE_TABLE_WIDTH},
+];
+
+function useRetry(refetch: () => void) {
+  const [pendingId, setPendingId] = useState('');
+
+  const {mutate} = useMutation({
+    mutationFn: retryErrorInterface,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        message.success('已重试');
+        setPendingId('');
+        refetch();
+      }
+    },
+  });
+
+  function onRetry(data: GSErrorListData) {
+    return function () {
+      const {id} = data;
+      setPendingId(id);
+      mutate(data);
+    };
+  }
+
+  return [pendingId, onRetry] as const;
+}
+
+export function useColumns(fetch: () => void) {
+  const [retryId, onRetry] = useRetry(fetch);
+
+  const tableColumns: ColumnsType<GSErrorListData> = [
+    ...columns,
+    {
+      title: '操作',
+      width: SMALL_TABLE_WIDTH,
+      fixed: 'right',
+      render(_, data) {
+        const {transmissionType, id} = data;
+
+        return (
+          <Button
+            type='text'
+            className='ant-text-btn-color-primary'
+            disabled={transmissionType === 0}
+            loading={retryId === id}
+            onClick={onRetry(data)}
+          >
+            {transmissionType === 0 ? '已重试' : '重试'}
+          </Button>
+        );
+      },
+    },
+  ];
+
+  return tableColumns;
+}

+ 3 - 9
packages/app/src/pages/gs-error-log/table/index.tsx

@@ -3,20 +3,13 @@ import {
   useQueryTableList,
   useTableExportEvent,
 } from '@hooks';
-import {GSErrorListData} from '@models';
-import {HUGE_TABLE_WIDTH, NORMAL_TABLE_WIDTH} from '@utils';
-import {ColumnsType} from 'antd/es/table';
+
 import {FC} from 'react';
 import {context, pageContext, searchContext} from '../context';
 import {exportGSErrorInterface, getGSErrorInterface} from '@apis';
 import {Card} from 'antd';
 import {Table, TableTools} from '@components';
-
-const columns: ColumnsType<GSErrorListData> = [
-  {title: '请求地址', dataIndex: 'url', width: NORMAL_TABLE_WIDTH},
-  {title: '错误信息', dataIndex: 'errorInfo', width: HUGE_TABLE_WIDTH},
-  {title: '请求内容', dataIndex: 'dataVal', width: HUGE_TABLE_WIDTH},
-];
+import {useColumns} from './hooks';
 
 const TableList: FC = function () {
   const params = useContextSection(context, state => state[0]);
@@ -31,6 +24,7 @@ const TableList: FC = function () {
     context,
     fn: exportGSErrorInterface,
   });
+  const columns = useColumns(refetch);
 
   return (
     <Card className='table-wrapper'>