【私域操盘手】设备管理
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
NODE_ENV=development
|
||||
VUE_APP_PREVIEW=false
|
||||
# 应用名称
|
||||
VUE_APP_WEBSITE_NAME=医师管理系统
|
||||
VUE_APP_WEBSITE_NAME=艺施管理系统
|
||||
|
||||
# API基础URL
|
||||
VUE_APP_API_BASE_URL=http://yishi.com
|
||||
|
||||
18919
Backend/package-lock.json
generated
18919
Backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@
|
||||
"axios": "^0.21.1",
|
||||
"babel-plugin-prismjs": "^2.0.1",
|
||||
"core-js": "^3.6.5",
|
||||
"crypto-js": "^4.1.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"element-ui": "^2.15.6",
|
||||
"js-audio-recorder": "^1.0.6",
|
||||
"js-base64": "^2.5.1",
|
||||
|
||||
16
Server/application/devices/config/route.php
Normal file
16
Server/application/devices/config/route.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 设备管理模块路由配置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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', // 按设备在线状态统计数量
|
||||
];
|
||||
378
Server/application/devices/controller/Index.php
Normal file
378
Server/application/devices/controller/Index.php
Normal file
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
namespace app\devices\controller;
|
||||
|
||||
use think\Controller;
|
||||
use app\devices\model\Device;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
*/
|
||||
class Index extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取设备总数
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
try {
|
||||
// 获取查询条件
|
||||
$where = [];
|
||||
|
||||
// 设备品牌
|
||||
$brand = Request::param('brand');
|
||||
if (!empty($brand)) {
|
||||
$where['brand'] = $brand;
|
||||
}
|
||||
|
||||
// 设备型号
|
||||
$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);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'count' => $count
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '获取失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
// 获取查询条件
|
||||
$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;
|
||||
}
|
||||
|
||||
// 设备型号
|
||||
$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);
|
||||
|
||||
// 获取排序参数
|
||||
$sort = Request::param('sort', 'id');
|
||||
$order = Request::param('order', 'desc');
|
||||
|
||||
// 获取设备列表
|
||||
$list = Device::getDeviceList($where, "{$sort} {$order}", $page, $limit);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'total' => $list->total(),
|
||||
'list' => $list->items()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '获取失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
try {
|
||||
// 获取设备ID
|
||||
$id = Request::param('id/d');
|
||||
if (empty($id)) {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '参数错误'
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取设备详情
|
||||
$info = Device::getDeviceInfo($id);
|
||||
if (empty($info)) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '设备不存在'
|
||||
]);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $info
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '获取失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
try {
|
||||
// 获取设备数据
|
||||
$data = Request::post();
|
||||
|
||||
// 验证IMEI是否为空
|
||||
if (empty($data['imei'])) {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '设备IMEI不能为空'
|
||||
]);
|
||||
}
|
||||
|
||||
// 验证IMEI是否已存在
|
||||
$exists = Device::where('imei', $data['imei'])->where('isDeleted', 0)->find();
|
||||
if ($exists) {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '设备IMEI已存在'
|
||||
]);
|
||||
}
|
||||
|
||||
// 添加设备
|
||||
$id = Device::addDevice($data);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功',
|
||||
'data' => [
|
||||
'id' => $id
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '添加失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备
|
||||
* @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
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
try {
|
||||
// 获取设备ID
|
||||
$id = Request::param('id/d');
|
||||
if (empty($id)) {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '参数错误'
|
||||
]);
|
||||
}
|
||||
|
||||
// 验证设备是否存在
|
||||
$exists = Device::where('id', $id)->where('isDeleted', 0)->find();
|
||||
if (!$exists) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '设备不存在'
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除设备
|
||||
$result = Device::deleteDevice($id);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '删除成功',
|
||||
'data' => [
|
||||
'result' => $result
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '删除失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按设备品牌统计数量
|
||||
* @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()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
135
Server/application/devices/model/Device.php
Normal file
135
Server/application/devices/model/Device.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace app\devices\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 设备模型类
|
||||
*/
|
||||
class Device extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'tk_device';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
protected $deleteTime = 'deleteTime';
|
||||
|
||||
/**
|
||||
* 获取设备总数
|
||||
* @param array $where 查询条件
|
||||
* @return int 设备总数
|
||||
*/
|
||||
public static function getDeviceCount($where = [])
|
||||
{
|
||||
// 默认只统计未删除的设备
|
||||
if (!isset($where['isDeleted'])) {
|
||||
$where['isDeleted'] = 0;
|
||||
}
|
||||
|
||||
return self::where($where)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param array $where 查询条件
|
||||
* @param string $order 排序方式
|
||||
* @param int $page 页码
|
||||
* @param int $limit 每页数量
|
||||
* @return \think\Paginator 分页对象
|
||||
*/
|
||||
public static function getDeviceList($where = [], $order = 'id desc', $page = 1, $limit = 10)
|
||||
{
|
||||
// 默认只查询未删除的设备
|
||||
if (!isset($where['isDeleted'])) {
|
||||
$where['isDeleted'] = 0;
|
||||
}
|
||||
|
||||
return self::where($where)
|
||||
->order($order)
|
||||
->paginate($limit, false, ['page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
* @param int $id 设备ID
|
||||
* @return array|null 设备信息
|
||||
*/
|
||||
public static function getDeviceInfo($id)
|
||||
{
|
||||
return self::where('id', $id)
|
||||
->where('isDeleted', 0)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @param array $data 设备数据
|
||||
* @return int 新增设备ID
|
||||
*/
|
||||
public static function addDevice($data)
|
||||
{
|
||||
$device = new self();
|
||||
$device->allowField(true)->save($data);
|
||||
return $device->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备
|
||||
* @param int $id 设备ID
|
||||
* @param array $data 设备数据
|
||||
* @return bool 更新结果
|
||||
*/
|
||||
public static function updateDevice($id, $data)
|
||||
{
|
||||
return self::where('id', $id)
|
||||
->where('isDeleted', 0)
|
||||
->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备(软删除)
|
||||
* @param int $id 设备ID
|
||||
* @return bool 删除结果
|
||||
*/
|
||||
public static function deleteDevice($id)
|
||||
{
|
||||
return self::where('id', $id)
|
||||
->update([
|
||||
'isDeleted' => 1,
|
||||
'deleteTime' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按设备品牌统计数量
|
||||
* @return array 统计结果
|
||||
*/
|
||||
public static function countByBrand()
|
||||
{
|
||||
return self::where('isDeleted', 0)
|
||||
->group('brand')
|
||||
->field('brand, count(*) as count')
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按设备在线状态统计数量
|
||||
* @return array 统计结果
|
||||
*/
|
||||
public static function countByStatus()
|
||||
{
|
||||
return self::where('isDeleted', 0)
|
||||
->group('alive')
|
||||
->field('alive, count(*) as count')
|
||||
->select();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user