This commit is contained in:
wong
2025-04-30 11:15:37 +08:00
3 changed files with 69 additions and 12 deletions

View File

@@ -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'],

View File

@@ -45,31 +45,32 @@ class GetAddResultedDevicesController extends Controller
protected function migrateData(int $accountId): void
{
$companyId = $this->getCompanyIdByAccountId($accountId);
$ids = $this->getAllDevicesIdWithInCompany($companyId);
$deviceIds = $this->getAllDevicesIdWithInCompany($companyId) ?: [0];
// 从 s2_device 导入数据。
$this->getNewDeviceFromS2_device($ids);
$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);
}
/**
@@ -90,12 +91,12 @@ class GetAddResultedDevicesController extends Controller
);
$result = json_decode($result, true);
$result = $result['data']['results'][0];
$result = $result['data']['results'][0] ?? false;
return (
return $result ? (
// 125是前端延迟5秒 + 轮询120次 1次/s
time() - strtotime($result['lastUpdateTime']) <= 125
);
time() - strtotime($result['lastUpdateTime']) <= 65
) : false;
}
/**

View File

@@ -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 <div className="flex items-center justify-center min-h-screen">...</div>
}