From e098ff8c46de4d6e52d16f4772fc88139293ed4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 29 Apr 2025 16:12:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=B0=E5=A2=9E=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../company/CreateCompanyController.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Server/application/superadmin/controller/company/CreateCompanyController.php b/Server/application/superadmin/controller/company/CreateCompanyController.php index 2c623a4a..bc49921b 100644 --- a/Server/application/superadmin/controller/company/CreateCompanyController.php +++ b/Server/application/superadmin/controller/company/CreateCompanyController.php @@ -2,6 +2,7 @@ namespace app\superadmin\controller\company; +use app\api\controller\DeviceController; use app\common\model\Company as CompanyModel; use app\common\model\User as UsersModel; use app\superadmin\controller\BaseController; @@ -105,6 +106,23 @@ class CreateCompanyController extends BaseController return $this; } + /** + * 设备创建分组 + * + * @param array $params + * @return void + * @throws \Exception + */ + protected function s2CreateDeviceGroup(array $params): void + { + $respon = (new DeviceController())->createGroup($params, true); + $respon = json_decode($respon, true); + + if ($respon['code'] != 200) { + throw new \Exception('设备分组添加错误', 210 . $respon['code']); + } + } + /** * S2 部分 * @@ -120,6 +138,9 @@ class CreateCompanyController extends BaseController throw new \Exception('S2返参异常', 210402); } + // 设备创建分组 + $this->s2CreateDeviceGroup(['groupName' => $params['name']]); + return array_merge($params, [ 'companyId' => $department['departmentId'], 's2_accountId' => $department['id'], From 79718d36c5a284eaa2e48b117abf540a6ca3a1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 29 Apr 2025 16:35:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=20-=20?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetAddResultedDevicesController.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php index 71c85f51..cb266391 100644 --- a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php +++ b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php @@ -45,31 +45,34 @@ class GetAddResultedDevicesController extends Controller protected function migrateData(int $accountId): void { $companyId = $this->getCompanyIdByAccountId($accountId); - $ids = $this->getAllDevicesIdWithInCompany($companyId); + $deviceIds = $this->getAllDevicesIdWithInCompany($companyId); - // 从 s2_device 导入数据。 - $this->getNewDeviceFromS2_device($ids); + if ($deviceIds) { + // 从 s2_device 导入数据。 + $this->getNewDeviceFromS2_device($deviceIds, $companyId); + } } /** * 从 s2_device 导入数据。 * * @param array $ids - * @return array + * @param int $companyId + * @return void */ - protected function getNewDeviceFromS2_device(array $ids): array + protected function getNewDeviceFromS2_device(array $ids, int $companyId): void { + $ids = implode(',', $ids); + $sql = "insert into ck_device(`id`, `imei`, `model`, phone, operatingSystem,memo,alive,brand,rooted,xPosed,softwareVersion,extra,createTime,updateTime,deleteTime,companyId) select d.id,d.imei,d.model,d.phone,d.operatingSystem,d.memo,d.alive,d.brand,d.rooted,d.xPosed,d.softwareVersion,d.extra,d.createTime,d.lastUpdateTime,d.deleteTime,a.departmentId companyId from s2_device d join s2_company_account a on d.currentAccountId = a.id - where isDeleted = 0 and deletedAndStop = 0 and d.id not in (:ids) + where isDeleted = 0 and deletedAndStop = 0 and d.id not in ({$ids}) and a.departmentId = {$companyId} "; - dd($sql); - - Db::query($sql, ['ids' => implode(',', $ids)]); + Db::query($sql); } /** @@ -92,6 +95,8 @@ class GetAddResultedDevicesController extends Controller $result = json_decode($result, true); $result = $result['data']['results'][0]; + return true; + return ( // 125是前端延迟5秒 + 轮询120次 1次/s time() - strtotime($result['lastUpdateTime']) <= 125 From bd4f9185bd2760d659a316ea01ae774f3fb8d32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 29 Apr 2025 16:48:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=20-=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E8=AE=BE=E5=A4=87=E7=9A=84=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=97=B6=E9=97=B4=E7=94=B1120=E7=A7=92=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=BA60=E7=A7=92=EF=BC=8C=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E5=BE=85=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetAddResultedDevicesController.php | 18 ++++------ .../app/dashboard/projects/[id]/page.tsx | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php index cb266391..9232ebf5 100644 --- a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php +++ b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php @@ -45,12 +45,10 @@ class GetAddResultedDevicesController extends Controller protected function migrateData(int $accountId): void { $companyId = $this->getCompanyIdByAccountId($accountId); - $deviceIds = $this->getAllDevicesIdWithInCompany($companyId); + $deviceIds = $this->getAllDevicesIdWithInCompany($companyId) ?: [0]; - if ($deviceIds) { - // 从 s2_device 导入数据。 - $this->getNewDeviceFromS2_device($deviceIds, $companyId); - } + // 从 s2_device 导入数据。 + $this->getNewDeviceFromS2_device($deviceIds, $companyId); } /** @@ -93,14 +91,12 @@ class GetAddResultedDevicesController extends Controller ); $result = json_decode($result, true); - $result = $result['data']['results'][0]; + $result = $result['data']['results'][0] ?? false; - return true; - - return ( + return $result ? ( // 125是前端延迟5秒 + 轮询120次 1次/s - time() - strtotime($result['lastUpdateTime']) <= 125 - ); + time() - strtotime($result['lastUpdateTime']) <= 65 + ) : false; } /** diff --git a/SuperAdmin/app/dashboard/projects/[id]/page.tsx b/SuperAdmin/app/dashboard/projects/[id]/page.tsx index 6296f8d4..e1a5f875 100644 --- a/SuperAdmin/app/dashboard/projects/[id]/page.tsx +++ b/SuperAdmin/app/dashboard/projects/[id]/page.tsx @@ -76,6 +76,11 @@ export default function ProjectDetailPage({ params }: ProjectDetailPageProps) { const [wechatStatusFilter, setWechatStatusFilter] = useState<'all' | 'loggedIn' | 'loggedOut' | 'notLogged'>('all') const [userStatusFilter, setUserStatusFilter] = useState<'all' | 'enabled' | 'disabled'>('all') const [userTypeFilter, setUserTypeFilter] = useState<'all' | 'system' | 'operator' | 'consultant'>('all') + const [pollingCount, setPollingCount] = useState(0) + const [isPolling, setIsPolling] = useState(false) + const [qrCode, setQrCode] = useState("") + const [showQrCode, setShowQrCode] = useState(false) + const maxPollingCount = 60 // 修改为60次 const fetchProject = async () => { try { @@ -201,6 +206,36 @@ export default function ProjectDetailPage({ params }: ProjectDetailPageProps) { }) } + const startPolling = () => { + setPollingCount(0) + setIsPolling(true) + const timer = setInterval(async () => { + if (pollingCount >= maxPollingCount) { + clearInterval(timer) + setIsPolling(false) + toast.error("轮询超时,请重试") + return + } + + try { + const result = await apiRequest(`/company/device/query?accountId=${profile?.s2_accountId}`) + if (result.code === 200 && result.data) { + clearInterval(timer) + setIsPolling(false) + setShowQrCode(false) + toast.success("设备添加成功") + fetchDevices() // 刷新设备列表 + } + } catch (error) { + console.error("轮询失败:", error) + } + + setPollingCount(prev => prev + 1) + }, 1000) + + return timer + } + if (isLoading) { return
加载中...
}