重新编排.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

@@ -3,14 +3,17 @@
// | 设备管理模块路由配置
// +----------------------------------------------------------------------
return [
// 设备管理路由
'devices/count' => 'devices/index/count', // 获取设备总数
'devices/list' => 'devices/index/index', // 获取设备列表
'devices/info/:id' => 'devices/index/read', // 获取设备详情
'devices/add' => ['devices/index/save', ['method' => 'post']], // 添加设备
'devices/update/:id' => ['devices/index/update', ['method' => 'put']], // 更新设备
'devices/delete/:id' => ['devices/index/delete', ['method' => 'delete']], // 删除设备
'devices/count_by_brand' => 'devices/index/countByBrand', // 按设备品牌统计数量
'devices/count_by_status' => 'devices/index/countByStatus', // 设备在线状态统计数量
];
use think\facade\Route;
// 定义RESTful风格的API路由 - 设备管理相关
Route::group('v1/devices', function () {
// 设备列表和查询
Route::get('', 'app\\devices\\controller\\Device@index'); // 获取设备列表
Route::get('count', 'app\\devices\\controller\\Device@count'); // 获取设备总数
Route::get(':id', 'app\\devices\\controller\\Device@read'); // 获取设备详情
// 设备管理
Route::post('', 'app\\devices\\controller\\Device@save'); // 添加设备
Route::put('refresh', 'app\\devices\\controller\\Device@refresh'); // 刷新设备状态
Route::delete(':id', 'app\\devices\\controller\\Device@delete'); // 删除设备
})->middleware(['jwt']);

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()
]);
}
}
}

View File

@@ -10,19 +10,31 @@ use think\Db;
class Device extends Model
{
// 设置表名
protected $name = 'tk_device';
protected $name = 'device';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
protected $deleteTime = 'deleteTime';
// 定义字段类型
protected $type = [
'id' => 'integer',
'createTime' => 'integer',
'updateTime' => 'integer',
'deleteTime' => 'integer',
'alive' => 'integer',
'isDeleted' => 'integer',
'tenantId' => 'integer',
'groupId' => 'integer'
];
/**
* 获取设备总数
* @param array $where 查询条件
@@ -105,7 +117,7 @@ class Device extends Model
return self::where('id', $id)
->update([
'isDeleted' => 1,
'deleteTime' => date('Y-m-d H:i:s')
'deleteTime' => date('Y-m-d H:i:s', time())
]);
}