Browse Source

feat(merge): merge sc

fix: 修改物模型映射
Lind 3 years ago
parent
commit
b3156fa1fa

+ 2 - 1
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -161,6 +161,7 @@ const Status = observer((props: Props) => {
       } else {
         service.queryProductState(InstanceModel.detail?.productId || '').then((resp) => {
           if (resp.status === 200) {
+            DiagnoseStatusModel.product = resp.result;
             if (resp.result.accessId) {
               service.queryGatewayState(resp.result.accessId).then((response: any) => {
                 if (response.status === 200) {
@@ -211,7 +212,7 @@ const Status = observer((props: Props) => {
                                         title="确认启用"
                                         onConfirm={async () => {
                                           const res = await service.startNetwork(
-                                            resp.result?.channelId,
+                                            DiagnoseStatusModel.product?.channelId,
                                           );
                                           if (res.status === 200) {
                                             message.success('操作成功!');

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

@@ -27,6 +27,7 @@ export const DiagnoseStatusModel = model<{
   };
   list: ListProps[];
   model: boolean;
+  product: any;
 }>({
   status: {
     config: {
@@ -87,4 +88,5 @@ export const DiagnoseStatusModel = model<{
     },
   ],
   model: true,
+  product: {},
 });

+ 19 - 8
src/pages/device/Instance/Detail/MetadataMap/EditableTable/index.tsx

@@ -1,7 +1,6 @@
 import React, { useContext, useEffect, useState } from 'react';
 import { Badge, Col, Form, Input, message, Pagination, Row, Select, Table } from 'antd';
 import { service } from '@/pages/device/Instance';
-import _ from 'lodash';
 import './index.less';
 
 const defaultImage = require('/public/images/metadata-map.png');
@@ -48,7 +47,11 @@ const EditableCell = ({
   const save = async () => {
     try {
       const values = await form.validateFields();
-      handleSave({ ...record, originalId: values?.originalId });
+      handleSave({
+        ...record,
+        originalId: values?.originalId,
+        customMapping: values?.originalId !== '',
+      });
     } catch (errInfo) {
       console.log('Save failed:', errInfo);
     }
@@ -75,7 +78,7 @@ const EditableCell = ({
           }
         >
           <Select.Option value={''}>使用物模型属性</Select.Option>
-          {record.originalId !== record.metadataId && (
+          {record.customMapping && (
             <Select.Option value={record.originalId}>
               {temp?.name}({temp?.id})
             </Select.Option>
@@ -153,13 +156,21 @@ const EditableTable = (props: Props) => {
       resp = await service.queryProductMetadata(props.data.id);
     }
     if (resp.status === 200) {
-      const data = resp.result;
       const obj: any = {};
-      data.map((i: any) => {
-        obj[i?.metadataId] = i;
+      const data = (resp?.result || []).map((i: any) => {
+        const t = {
+          ...i,
+          originalId: i.customMapping ? i.originalId : '',
+        };
+        obj[i?.metadataId] = t;
+        return t;
       });
       if (lists.length > 0) {
-        setPmList(lists.filter((i) => !_.map(data, 'originalId').includes(i.id)));
+        const arr = lists.filter((i) => {
+          const t = data.find((item: any) => item?.originalId === i?.id);
+          return !t || (t && !t.customMapping);
+        });
+        setPmList(arr);
       } else {
         setPmList([]);
       }
@@ -205,7 +216,7 @@ const EditableTable = (props: Props) => {
     const newData = [...dataSource.data];
     const index = newData.findIndex((item) => row.id === item.id);
     const item = newData[index];
-    if (item?.originalId !== row?.originalId) {
+    if (item?.originalId !== row?.originalId || row.customMapping !== item.customMapping) {
       const resp = await service[
         props.type === 'device' ? 'saveDeviceMetadata' : 'saveProductMetadata'
       ](props.data?.id, [

+ 40 - 13
src/pages/notice/Config/SyncUser/index.tsx

@@ -14,6 +14,7 @@ const SyncUser = observer(() => {
   const id = (location as any).query?.id;
   const [visible, setVisible] = useState<boolean>(false);
   const [current, setCurrent] = useState<any>({});
+  const [list, setList] = useState<any[]>([]);
 
   const idMap = {
     dingTalk: '钉钉',
@@ -24,19 +25,14 @@ const SyncUser = observer(() => {
 
   const columns: ProColumns<any>[] = [
     {
-      dataIndex: 'id',
+      dataIndex: 'thirdPartyUserName',
       title: `${idMap[id]}用户名`,
-      render: (text: any, record: any) => (
-        <span>
-          {text}({record?.name})
-        </span>
-      ),
     },
     {
       dataIndex: 'userId',
       title: `用户`,
       render: (text: any, record: any) => (
-        <span>{record?.userId ? `${record?.username}(${record?.userName})` : '--'}</span>
+        <span>{record?.userId ? `${record?.userName}(${record?.username})` : '--'}</span>
       ),
     },
     {
@@ -44,8 +40,8 @@ const SyncUser = observer(() => {
       title: '绑定状态',
       render: (text: any, record: any) => (
         <Badge
-          status={record?.userId ? 'success' : 'error'}
-          text={record?.userId ? '已绑定' : '未绑定'}
+          status={record?.status === 1 ? 'success' : 'error'}
+          text={record?.status === 1 ? '已绑定' : '未绑定'}
         />
       ),
     },
@@ -65,13 +61,15 @@ const SyncUser = observer(() => {
           </Button>
         </Tooltip>,
         <Tooltip title={'解绑用户'} key="unbind">
-          {record?.userId && (
+          {record?.status === 1 && (
             <Button type="link">
               <Popconfirm
                 title={'确认解绑'}
                 onConfirm={async () => {
                   if (record?.bindingId) {
-                    const resp = await service.syncUser.unBindUser(record.bindingId);
+                    const resp = await service.syncUser.unBindUser(record.bindingId, {
+                      bindingId: record.bindingId,
+                    });
                     if (resp.status === 200) {
                       message.success('操作成功!');
                       actionRef.current?.reload();
@@ -139,6 +137,7 @@ const SyncUser = observer(() => {
                 title: 'name',
                 key: 'id',
               }}
+              selectedKeys={[dept || '']}
               onSelect={(key) => {
                 setDept(key[0] as string);
               }}
@@ -149,7 +148,7 @@ const SyncUser = observer(() => {
         <Col span={20}>
           {dept && (
             <ProTable
-              rowKey="id"
+              rowKey="thirdPartyUserId"
               actionRef={actionRef}
               search={false}
               columns={columns}
@@ -167,6 +166,7 @@ const SyncUser = observer(() => {
                     params.dept || '',
                   )
                   .then((resp: any) => {
+                    setList(resp);
                     return {
                       code: '',
                       result: {
@@ -179,7 +179,34 @@ const SyncUser = observer(() => {
                     };
                   })
               }
-              headerTitle={<Button>保存</Button>}
+              headerTitle={
+                <Popconfirm
+                  title="确认保存"
+                  onConfirm={async () => {
+                    const arr = list
+                      .filter((item) => item.status === 0)
+                      .map((i) => {
+                        return {
+                          userId: i.userId,
+                          providerName: i.userName,
+                          thirdPartyUserId: i.thirdPartyUserId,
+                        };
+                      });
+                    const resp = await service.syncUser.bindUser(
+                      id,
+                      state.current?.provider || '',
+                      state.current?.id || '',
+                      [...arr],
+                    );
+                    if (resp.status === 200) {
+                      message.success('操作成功!');
+                      actionRef.current?.reload();
+                    }
+                  }}
+                >
+                  <Button type="primary">保存</Button>
+                </Popconfirm>
+              }
             />
           )}
         </Col>

+ 1 - 0
src/pages/notice/Config/index.tsx

@@ -300,6 +300,7 @@ const Config = observer(() => {
                 <PermissionButton
                   key="syncUser"
                   isPermission={true}
+                  type="link"
                   onClick={() => {
                     state.syncUser = true;
                     state.current = record;

+ 24 - 19
src/pages/notice/Config/service.ts

@@ -71,9 +71,10 @@ class Service extends BaseService<ConfigItem> {
       }),
     getUserBindInfo: () =>
       request(`${SystemConst.API_BASE}/user/third-party/me`, { method: 'GET' }),
-    unBindUser: (bindId: string) =>
-      request(`${SystemConst.API_BASE}/user/third-party/me/${bindId}`, {
-        method: 'DELETE',
+    unBindUser: (bindingId: string, data: any) =>
+      request(`${SystemConst.API_BASE}/user/third-party/${bindingId}/_unbind`, {
+        method: 'POST',
+        data,
       }),
   };
 
@@ -93,26 +94,30 @@ class Service extends BaseService<ConfigItem> {
         map((resp) => resp.map((i) => i.result)),
         mergeMap((res) => {
           const [resp1, resp2, resp3] = res;
-          const list = resp1.map((item: { id: string; name: string }) => {
-            const data =
-              resp2.find(
-                (i: { userId: string; providerName: string; thirdPartyUserId: string }) =>
-                  i.thirdPartyUserId === item.id,
-              ) || {};
-            let _user: Partial<UserItem> = {};
-            if (data) {
-              _user = resp3.find((i: UserItem) => i.id === data.userId);
+          // 1.自动匹配
+          // 2.已匹配
+          // status: 1: 已匹配 0: 自动匹配,但是没有保存 -1: 未匹配
+          const arr = resp1.map((item: { id: string; name: string }) => {
+            let user = resp3.find((i: UserItem) => i?.name === item?.name);
+            const thirdPartyUser = resp2.find(
+              (i: { userId: string; providerName: string; thirdPartyUserId: string }) =>
+                i?.thirdPartyUserId === item?.id,
+            );
+            if (thirdPartyUser) {
+              user = resp3.find((i: UserItem) => i?.id === thirdPartyUser?.userId);
             }
+            const status = thirdPartyUser ? 1 : user ? 0 : -1;
             return {
-              ..._user,
-              ...data,
-              ...item,
-              bindingId: data?.id,
-              userId: _user?.id,
-              userName: _user?.name,
+              thirdPartyUserId: item?.id,
+              thirdPartyUserName: item?.name,
+              bindingId: thirdPartyUser?.id,
+              userId: user?.id,
+              userName: user?.name,
+              username: user?.username,
+              status,
             };
           });
-          return list;
+          return arr;
         }),
         toArray(),
       ),