From 0baec3b3ab426eaba3f49edaa8429baa51f2cdca Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Thu, 14 Dec 2023 15:08:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maintain/dl/index.php | 5 +- maintain/index.php | 4 ++ maintain/web/api/cmd.inc.php | 11 ++-- maintain/web/api/delUpgrade.php | 37 ------------- maintain/web/api/doAction.php | 15 ++++-- maintain/web/api/queryActivity.php | 48 +++++++++++++++++ maintain/web/api/queryCmds.php | 2 +- maintain/web/api/queryProtocol.php | 19 +++++++ maintain/web/api/queryTerms.php | 31 ++++++++--- maintain/web/api/updActivity.php | 85 ++++++++++++++++++++++++++++++ maintain/web/api/updUpgrade.php | 53 +++++++++++++++++++ maintain/web/api/uploadFile.php | 2 +- 12 files changed, 258 insertions(+), 54 deletions(-) delete mode 100644 maintain/web/api/delUpgrade.php create mode 100644 maintain/web/api/queryActivity.php create mode 100644 maintain/web/api/queryProtocol.php create mode 100644 maintain/web/api/updActivity.php create mode 100644 maintain/web/api/updUpgrade.php diff --git a/maintain/dl/index.php b/maintain/dl/index.php index e735bc8..3ea96be 100644 --- a/maintain/dl/index.php +++ b/maintain/dl/index.php @@ -39,10 +39,13 @@ if (!file_exists($dest)) die; } +$parts = pathinfo($row['file_name']); +$fileName = $parts['filename'] . '_' . str_replace(array('-', ' ', ':'), '', $row['create_time']) . '.' . $parts['extension']; + Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: " . $row['file_size']); -Header("Content-Disposition: attachment; filename=" . $row['file_name']); +Header("Content-Disposition: attachment; filename=" . $fileName); readfile($dest); exit(); \ No newline at end of file diff --git a/maintain/index.php b/maintain/index.php index 28c416b..c78dfba 100644 --- a/maintain/index.php +++ b/maintain/index.php @@ -75,6 +75,9 @@ if (!$rows || count($rows) == 0) exit(); } +$sql = "INSERT INTO mntn_cmd_history(`id`,term_id,`name`,`cmd`,`desc`,`status`,`create_time`,`publish_time`) SELECT `id`,`term_id`,`name`,`cmd`,`desc`,1,create_time,NOW() FROM mntn_cmds WHERE `id`=:id"; +$stmt2 = $db->prepare($sql); + $sql = "DELETE FROM mntn_cmds WHERE id=:id"; $stmt = $db->prepare($sql); @@ -119,6 +122,7 @@ foreach ($rows as $row) if (!$debugMode) { + $stmt2->execute(array('id' => $row['id'])); $stmt->execute(array('id' => $row['id'])); } } diff --git a/maintain/web/api/cmd.inc.php b/maintain/web/api/cmd.inc.php index 9308437..8070dc6 100644 --- a/maintain/web/api/cmd.inc.php +++ b/maintain/web/api/cmd.inc.php @@ -1,8 +1,9 @@ 'cma', '心跳间隔' => 'heartbeatDuration', 'i1' => 'i1Version', 'yw' => 'maintainVersion', '电池' => 'battery', '系统重启' => 'rebootTimes', - 'i1重启' => 'i1RebootTimes', '收' => 'recv', '拍' => 'photoTimes', '成' => 'success', '败' => 'failure', '传' => 'uploads', '心跳累计' => 'numberOfHb', - '网络异常' => 'networkError', '信号1' => 'signature1', '信号2' => 'signature2', '卡1' => 'simcard1', '卡2' => 'simcard2', 'mcu' => 'mcu', 'ai' => 'aiVersion', 'cam' => 'cameraService'); + '重启' => 'rebootTimes', 'i1重启' => 'i1RebootTimes', 'i1启' => 'i1RebootTimes', '收' => 'recv', '拍' => 'photoTimes', '成' => 'success', '败' => 'failure', + '传' => 'uploads', '心跳累计' => 'numberOfHb', '心跳' => 'numberOfHb', '网络异常' => 'networkError', '网络' => 'networkError', '信号1' => 'signature1', '信号2' => 'signature2', + '卡1' => 'simcard1', '卡2' => 'simcard2', 'mcu' => 'mcu', 'ai' => 'aiVersion', 'cam' => 'cameraService', '主板温度' => 'mainBoardTmp', '电池温度' => 'batteryTmp'); function parseCmd($content) { @@ -22,7 +23,11 @@ function parseCmd($content) } $key = trim(substr($item, 0, $pos)); - if (isset($keyMapper[$key])) + if ($key == 'i1' && strpos($item, ':', $pos + 1) !== false) + { + $key = 'cma'; + } + else if (isset($keyMapper[$key])) { $key = $keyMapper[$key]; } diff --git a/maintain/web/api/delUpgrade.php b/maintain/web/api/delUpgrade.php deleted file mode 100644 index 076cda0..0000000 --- a/maintain/web/api/delUpgrade.php +++ /dev/null @@ -1,37 +0,0 @@ - \PDO::FETCH_ASSOC, - \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" - ]); - -$result = array('res' => 0, 'data' => array()); - -$id = empty($_GET['id']) ? 0 : intval($_GET['id']); -$values = array('id' => $id); -$sql = "SELECT `id`,`path` FROM mntn_upgrades WHERE `id`=:id"; -$stmt = $db->prepare($sql); -$stmt->execute($values); - -$rows = $stmt->fetchAll(); -$stmt = null; - -$sql = "DELETE FROM mntn_upgrades WHERE `id`=:id LIMIT 1"; -$stmt = $db->prepare($sql); - -foreach ($rows as $row) -{ - $dest = $config['upgrade_file_path'] . $row['path']; - if (unlink($dest)) - { - $stmt->execute(array('id' => $row['id'])); - $result['data'][] = $row['id']; - } -} -unset($item); - -header ('Access-Control-Allow-Origin: *'); -header ('Content-type: application/json; charset=utf-8'); -echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/doAction.php b/maintain/web/api/doAction.php index a1e8db8..4572fbc 100644 --- a/maintain/web/api/doAction.php +++ b/maintain/web/api/doAction.php @@ -33,12 +33,16 @@ if ($action == 'cancel') { $id = isset($_GET['id']) ? intval($_GET['id']) : 0; - $sql = "DELETE FROM mntn_cmds WHERE `id`=:cid LIMIT 1"; + $sql = "DELETE FROM mntn_cmds WHERE `id`=:id LIMIT 1"; $stmt1 = $db->prepare($sql); - $res = $stmt1->execute(array('cid' => $id)); + $sql = "INSERT INTO mntn_cmd_history(`id`,term_id,`name`,`cmd`,`desc`,`status`,`create_time`,`publish_time`) SELECT `id`,`term_id`,`name`,`cmd`,`desc`,2,create_time,NOW() FROM mntn_cmds WHERE `id`=:id"; + $stmt2 = $db->prepare($sql); + + $res2 = $stmt2->execute(array('id' => $id)); + $res1 = $stmt1->execute(array('id' => $id)); header ('Sql: ' . $sql . $id); - if (!$res) + if (!$res2 || !$res1) { print_r($stmt1->errorInfo()); } @@ -132,8 +136,9 @@ else else if ($action == 'upgrade') { $values['cmdName'] = 'upgrade'; - $md5 = empty($_GET['md5']) ? '' : $_GET['md5']; - $values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5)); + $md5 = empty($_GET['md5']) ? '' : $_GET['md5']; + $fileName = empty($_GET['fn']) ? '' : $_GET['fn']; + $values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5, 'fileName' => $fileName)); } else if ($action == 'start-frpc') { diff --git a/maintain/web/api/queryActivity.php b/maintain/web/api/queryActivity.php new file mode 100644 index 0000000..9f609bb --- /dev/null +++ b/maintain/web/api/queryActivity.php @@ -0,0 +1,48 @@ + \PDO::FETCH_ASSOC, + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" + ]); + +$result = array('res' => 0, 'data' => array()); + +$action = empty($_GET['act']) ? '' : $_GET['act']; + +if ($action == 'list') +{ + $sql = "SELECT `id`,`title`,term_count AS termCount,create_time AS createTime,update_time AS updateTime"; + $sql .= " FROM mntn_activities"; + $sql .= " WHERE `status`=1 ORDER BY `id` DESC"; + $stmt = $db->prepare($sql); + $stmt->execute(); + + $result['data'] = $stmt->fetchAll(); + $stmt = null; +} +else if ($action == 'detail') +{ + $sql = "SELECT `id`,`title`,term_count AS termCount,create_time AS createTime,update_time AS updateTime"; + $sql .= " FROM mntn_activities"; + $sql .= " WHERE `id`=:id ORDER BY `id` DESC"; + $stmt = $db->prepare($sql); + $stmt->execute(array('id' => $id)); + + $result['data']['activity'] = $stmt->fetch(); + $stmt = null; + + $sql = "SELECT t1.`id` AS termId,t1.cmdid,t1.`display_name` AS displayName,t1.`protocol`,t2.`name` AS towerName,t3.`name` AS lineName"; + $sql .= " FROM terminals AS t1 JOIN mntn_activity_terminals AS t2 ON t1.id=t2.term_id"; + $sql .= " WHERE t2.activity_id=:id"; + $stmt = $db->prepare($sql); + $stmt->execute(array('id' => $id)); + + $result['data']['terms'] = $stmt->fetchAll(); + $stmt = null; +} + +header ('Access-Control-Allow-Origin: *'); +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/queryCmds.php b/maintain/web/api/queryCmds.php index fc4bf65..48d2744 100644 --- a/maintain/web/api/queryCmds.php +++ b/maintain/web/api/queryCmds.php @@ -42,7 +42,7 @@ if ($queryType == 'pending') } else { - $sql = 'SELECT t1.cmdid,t1.`display_name` AS displayName,t2.`name` AS cmdName,t2.`cmd`,t2.`create_time` AS createTime,t2.publish_time AS publishTime, t2.term_id AS termId,t2.`id` FROM ' . $tableName . ' AS t2 JOIN terminals AS t1 ON t2.term_id=t1.`id` ORDER BY t2.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize; + $sql = 'SELECT t1.cmdid,t1.`display_name` AS displayName,t2.`name` AS cmdName,t2.`cmd`,t2.`status`,t2.`create_time` AS createTime,t2.publish_time AS publishTime, t2.term_id AS termId,t2.`id` FROM ' . $tableName . ' AS t2 JOIN terminals AS t1 ON t2.term_id=t1.`id` ORDER BY t2.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize; } $stmt = $db->prepare($sql); $res = $stmt->execute(); diff --git a/maintain/web/api/queryProtocol.php b/maintain/web/api/queryProtocol.php new file mode 100644 index 0000000..f695933 --- /dev/null +++ b/maintain/web/api/queryProtocol.php @@ -0,0 +1,19 @@ + \PDO::FETCH_ASSOC, + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" + ]); + +$result = array('res' => 0, 'data' => array()); + +$stmt = $db->prepare("SELECT * FROM `protocols`"); +$stmt->execute(); +$result['data'] = $stmt->fetchAll(); +$stmt = null; + +header ('Access-Control-Allow-Origin: *'); +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/queryTerms.php b/maintain/web/api/queryTerms.php index 5874f4c..2f91ef7 100644 --- a/maintain/web/api/queryTerms.php +++ b/maintain/web/api/queryTerms.php @@ -14,7 +14,8 @@ $values = array(); $orderField = ''; // 筛选接口 与的关系 查询的字段分别是出厂ID(oid)、装置编号(cmdid)、CMA服务器(cma)、版本信息(aiVersion、i1Version、maintainVersion、cameraService),并且每个筛选条件后面都带checbox框 勾选上定义的值为1 未勾选定义的为0, 然后点击搜索筛选 -$filterFields = array('cmdid', 'oid', 'cma', 'version'); +// true: if value is not set, will ignored +$filterFields = array('cmdid', 'oid', 'cma', 'version', 'activity', 'protocol', 'mntned'); $filters = array(); if (isset($_GET['fc']) && $_GET['fc'] == intval($_GET['fc'])) @@ -22,7 +23,7 @@ if (isset($_GET['fc']) && $_GET['fc'] == intval($_GET['fc'])) $numberOfFilters = intval($_GET['fc']); for ($idx = 1; $idx <= $numberOfFilters; $idx++) { - if (empty($_GET['fn' . $idx]) || empty($_GET['fv' . $idx]) || !in_array($_GET['fn' . $idx], $filterFields)) + if (empty($_GET['fn' . $idx]) || !isset($_GET['fv' . $idx]) || $_GET['fv' . $idx] == '' || !in_array($_GET['fn' . $idx], $filterFields)) { continue; } @@ -58,8 +59,25 @@ if (isset($filters['cmdid'])) $values['cmdid'] = '%' . $filters['cmdid']['val'] . '%'; } +if (isset($filters['activity']) && !empty($filters['activity']['val'])) +{ + $notClause = $filters['activity']['rev'] ? ' NOT ' : ''; + $conditions[] = 't1.`id` ' . $notClause . ' IN (SELECT term_id FROM mntn_activity_terminals WHERE `activity_id`=:activityId)'; + $values['activityId'] = $filters['activity']['val']; +} +if (isset($filters['protocol']) && !empty($filters['protocol']['val'])) +{ + $notClause = $filters['protocol']['rev'] ? '<>' : '='; + $conditions[] = 't1.`protocol`' . $notClause . ':protocol'; + $values['protocol'] = $filters['protocol']['val']; +} -$conditions[] = "t4.`raw_report_time`<>0"; +if (isset($filters['mntned']) && !empty($filters['mntned']['val'])) +{ + $notClause = (intval($filters['mntned']['val']) == 1) ? '<>' : '='; + $conditions[] = 't4.`raw_report_time`' . $notClause . '0'; +} +// $conditions[] = "t4.`term_id` IN (SELECT term_id FROM mntn_activity_terminals WHERE `activity_id`=10001)"; $conditionStr = ''; if (count($conditions) > 0) { @@ -89,7 +107,7 @@ foreach($rows as &$row) $row['last_heartbeat_time'] = empty($row['last_heartbeat']) ? '' : substr($row['last_heartbeat'], 11); if (empty($row['raw_report'])) { - $row['raw_report'] = $obj; + $row['raw_report'] = array(); } else { @@ -100,7 +118,7 @@ foreach($rows as &$row) } } - if (!empty($row['raw_report']['oid']) && empty($row['oid'])) + if (!is_object($row['raw_report']) && !empty($row['raw_report']['oid']) && empty($row['oid'])) { $row['oid'] = $row['raw_report']['oid']; } @@ -150,7 +168,7 @@ unset($row); $desc = false; if (isset($_GET['asc'])) { - $desc = ($_GET['desc'] != 0); + $desc = ($_GET['asc'] != 0); } function cmp($a, $b) @@ -191,6 +209,7 @@ if (!empty($orderField)) usort($result['data'], 'cmp'); } +$result['termCount'] = count($result['data']); header ('Access-Control-Allow-Origin: *'); header ('Content-type: application/json; charset=utf-8'); diff --git a/maintain/web/api/updActivity.php b/maintain/web/api/updActivity.php new file mode 100644 index 0000000..76f35d0 --- /dev/null +++ b/maintain/web/api/updActivity.php @@ -0,0 +1,85 @@ + \PDO::FETCH_ASSOC, + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" + ]); + +$result = array('res' => 0, 'data' => array()); + +$id = empty($_REQUEST['id']) ? 0 : intval($_REQUEST['id']); +$action = empty($_REQUEST['act']) ? '' : $_REQUEST['act']; + +if ($action == 'del') +{ + $values = array('id' => $id); + $sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id"; + $stmt = $db->prepare($sql); + $stmt->execute($values); + $stmt = null; + + $sql = "DELETE FROM mntn_activities WHERE `id`=:id LIMIT 1"; + $stmt = $db->prepare($sql); + + $stmt->execute(array('id' => $id)); +} +else if ($action == 'edt') +{ + $title = empty($_POST['title']) ? '' : $_POST['title']; + $id = empty($_POST['id']) ? 0 : intval($_POST['id']); + $termIds = empty($_POST['termIds']) ? array() : $_POST['termIds']; + + $values = array('id' => $id, 'title' => $title); + + $sql = "UPDATE mntn_activities SET `title`=:title,`term_count`=:termCount WHERE `id`=:id LIMIT 1"; + $stmt = $db->prepare($sql); + + $stmt->execute(array('id' => $id, 'title' => $title, 'termCount' => count($termIds))); + + $sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id"; + $stmt = $db->prepare($sql); + $stmt->execute(array('id' => $id)); + + $sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) VALUES(:id,:termId)"; + $stmt = $db->prepare($sql); + + foreach ($termIds as $termId) + { + $stmt->closeCursor(); + $stmt->execute(array('id' => $id, 'termId' => $termId)); + } + + $result['data'][] = $id; +} +else if ($action == 'new') +{ + $title = empty($_POST['title']) ? '' : $_POST['title']; + $id = empty($_POST['id']) ? 0 : intval($_POST['id']); + $cmdids = isset($_POST['cmdids']) ? $_POST['cmdids'] : ''; + + $contents = str_replace("\r\n", "\n", $cmdids); + $contents = str_replace("\n\r", "\n", $contents); + $contents = str_replace("\r", "\n", $contents); + $cmdids = explode("\n", $contents); + + $sql = "INSERT INTO mntn_activities(`title`,`term_count`) VALUES(:title,:termCount)"; + $stmt = $db->prepare($sql); + + $stmt->execute(array('title' => $title, 'termCount' => count($cmdids))); + + $id = $db->lastInsertId(); + if (!empty($cmdids)) + { + $sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) SELECT :id,`id` FROM terminals WHERE `cmdid` IN('" . implode("','", $cmdids) . "')"; + $stmt = $db->prepare($sql); + $stmt->execute(array('id' => $id)); + } + + $result['data'][] = $id; +} + +header ('Access-Control-Allow-Origin: *'); +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/updUpgrade.php b/maintain/web/api/updUpgrade.php new file mode 100644 index 0000000..1207164 --- /dev/null +++ b/maintain/web/api/updUpgrade.php @@ -0,0 +1,53 @@ + \PDO::FETCH_ASSOC, + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" + ]); + +$result = array('res' => 0, 'data' => array()); + +$id = empty($_GET['id']) ? 0 : intval($_GET['id']); +$action = empty($_GET['act']) ? '' : $_GET['act']; + +if ($action == 'del') +{ + $values = array('id' => $id); + $sql = "SELECT `id`,`path` FROM mntn_upgrades WHERE `id`=:id"; + $stmt = $db->prepare($sql); + $stmt->execute($values); + + $rows = $stmt->fetchAll(); + $stmt = null; + + $sql = "DELETE FROM mntn_upgrades WHERE `id`=:id LIMIT 1"; + $stmt = $db->prepare($sql); + + foreach ($rows as $row) + { + $dest = $config['upgrade_file_path'] . $row['path']; + if (unlink($dest)) + { + $stmt->execute(array('id' => $row['id'])); + $result['data'][] = $row['id']; + } + } + unset($item); +} +else if ($action == 'edt') +{ + $title = empty($_GET['title']) ? '' : $_GET['title']; + $values = array('id' => $id, 'title' => $title); + + $sql = "UPDATE mntn_upgrades SET `title`=:title WHERE `id`=:id LIMIT 1"; + $stmt = $db->prepare($sql); + + $stmt->execute($values); + $result['data'][] = $id; +} + +header ('Access-Control-Allow-Origin: *'); +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/uploadFile.php b/maintain/web/api/uploadFile.php index baf53c4..994978d 100644 --- a/maintain/web/api/uploadFile.php +++ b/maintain/web/api/uploadFile.php @@ -22,7 +22,7 @@ if (isset($_FILES)) foreach ($_FILES as $file) { $extension = pathinfo($file['name'], PATHINFO_EXTENSION); - $fileName = date('Ymd') . '_' . uniqid('log_'); + $fileName = date('Ymd') . '_' . uniqid('upd_'); if (!empty($extension)) { $fileName .= '.' . $extension;