重新编排.gitignnore规则

This commit is contained in:
柳清爽
2025-03-17 11:47:42 +08:00
parent 083813dd5e
commit 0c259b413c
1781 changed files with 113 additions and 941 deletions

View File

@@ -2,14 +2,32 @@
namespace app\devices\controller;
use think\Controller;
use app\devices\model\Device;
use app\devices\model\Device as DeviceModel;
use think\facade\Request;
use app\common\util\JwtUtil;
/**
* 设备管理控制器
*/
class Index extends Controller
class Device extends Controller
{
/**
* 用户信息
* @var object
*/
protected $user;
/**
* 初始化
*/
protected function initialize()
{
parent::initialize();
// 设置时区
date_default_timezone_set('Asia/Shanghai');
}
/**
* 获取设备总数
* @return \think\response\Json
@@ -20,38 +38,20 @@ class Index extends Controller
// 获取查询条件
$where = [];
// 设备品牌
$brand = Request::param('brand');
if (!empty($brand)) {
$where['brand'] = $brand;
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 设备型号
$model = Request::param('model');
if (!empty($model)) {
$where['model'] = $model;
}
// 设备在线状态
$alive = Request::param('alive');
if (is_numeric($alive)) {
$where['alive'] = $alive;
}
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 分组ID
$groupId = Request::param('group_id');
if (is_numeric($groupId)) {
$where['groupId'] = $groupId;
}
// 获取设备总数
$count = Device::getDeviceCount($where);
$count = DeviceModel::getDeviceCount($where);
return json([
'code' => 200,
@@ -78,58 +78,34 @@ class Index extends Controller
// 获取查询条件
$where = [];
// 设备名称
$userName = Request::param('user_name');
if (!empty($userName)) {
$where['userName'] = ['like', "%{$userName}%"];
}
// 设备IMEI
$imei = Request::param('imei');
if (!empty($imei)) {
$where['imei'] = ['like', "%{$imei}%"];
}
// 设备品牌
$brand = Request::param('brand');
if (!empty($brand)) {
$where['brand'] = $brand;
// 设备备注
$memo = Request::param('memo');
if (!empty($memo)) {
$where['memo'] = ['like', "%{$memo}%"];
}
// 设备型号
$model = Request::param('model');
if (!empty($model)) {
$where['model'] = $model;
}
// 设备在线状态
$alive = Request::param('alive');
if (is_numeric($alive)) {
$where['alive'] = $alive;
}
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 分组ID
$groupId = Request::param('group_id');
if (is_numeric($groupId)) {
$where['groupId'] = $groupId;
}
// 获取分页参数
$page = Request::param('page/d', 1);
$limit = Request::param('limit/d', 10);
$page = (int)Request::param('page', 1);
$limit = (int)Request::param('limit', 10);
// 获取排序参数
$sort = Request::param('sort', 'id');
$order = Request::param('order', 'desc');
// 获取设备列表
$list = Device::getDeviceList($where, "{$sort} {$order}", $page, $limit);
$list = DeviceModel::getDeviceList($where, "{$sort} {$order}", $page, $limit);
return json([
'code' => 200,
@@ -164,7 +140,7 @@ class Index extends Controller
}
// 获取设备详情
$info = Device::getDeviceInfo($id);
$info = DeviceModel::getDeviceInfo($id);
if (empty($info)) {
return json([
'code' => 404,
@@ -184,6 +160,27 @@ class Index extends Controller
]);
}
}
/**
* 刷新设备
* @return \think\response\Json
*/
public function refresh()
{
try {
return json([
'code' => 200,
'msg' => '刷新成功',
'data' => []
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
/**
* 添加设备
@@ -204,7 +201,7 @@ class Index extends Controller
}
// 验证IMEI是否已存在
$exists = Device::where('imei', $data['imei'])->where('isDeleted', 0)->find();
$exists = DeviceModel::where('imei', $data['imei'])->where('isDeleted', 0)->find();
if ($exists) {
return json([
'code' => 400,
@@ -213,7 +210,7 @@ class Index extends Controller
}
// 添加设备
$id = Device::addDevice($data);
$id = DeviceModel::addDevice($data);
return json([
'code' => 200,
@@ -229,64 +226,7 @@ class Index extends Controller
]);
}
}
/**
* 更新设备
* @return \think\response\Json
*/
public function update()
{
try {
// 获取设备ID
$id = Request::param('id/d');
if (empty($id)) {
return json([
'code' => 400,
'msg' => '参数错误'
]);
}
// 获取设备数据
$data = Request::put();
// 验证设备是否存在
$exists = Device::where('id', $id)->where('isDeleted', 0)->find();
if (!$exists) {
return json([
'code' => 404,
'msg' => '设备不存在'
]);
}
// 如果更新IMEI验证IMEI是否已存在
if (!empty($data['imei']) && $data['imei'] != $exists['imei']) {
$imeiExists = Device::where('imei', $data['imei'])->where('isDeleted', 0)->where('id', '<>', $id)->find();
if ($imeiExists) {
return json([
'code' => 400,
'msg' => '设备IMEI已存在'
]);
}
}
// 更新设备
$result = Device::updateDevice($id, $data);
return json([
'code' => 200,
'msg' => '更新成功',
'data' => [
'result' => $result
]
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '更新失败:' . $e->getMessage()
]);
}
}
/**
* 删除设备
* @return \think\response\Json
@@ -304,7 +244,7 @@ class Index extends Controller
}
// 验证设备是否存在
$exists = Device::where('id', $id)->where('isDeleted', 0)->find();
$exists = DeviceModel::where('id', $id)->where('isDeleted', 0)->find();
if (!$exists) {
return json([
'code' => 404,
@@ -313,7 +253,7 @@ class Index extends Controller
}
// 删除设备
$result = Device::deleteDevice($id);
$result = DeviceModel::deleteDevice($id);
return json([
'code' => 200,
@@ -329,50 +269,4 @@ class Index extends Controller
]);
}
}
/**
* 按设备品牌统计数量
* @return \think\response\Json
*/
public function countByBrand()
{
try {
// 获取统计数据
$data = Device::countByBrand();
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $data
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
/**
* 按设备在线状态统计数量
* @return \think\response\Json
*/
public function countByStatus()
{
try {
// 获取统计数据
$data = Device::countByStatus();
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $data
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
}