操盘手端 - 更新设备任务配置返工
This commit is contained in:
@@ -8,4 +8,9 @@ class Attachment extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'attachments';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
}
|
||||
@@ -11,4 +11,9 @@ class Device extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'device';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
}
|
||||
34
Server/application/common/model/DeviceHandleLog.php
Normal file
34
Server/application/common/model/DeviceHandleLog.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 设备操作日志模型类
|
||||
*/
|
||||
class DeviceHandleLog extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'device_handle_log';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
/**
|
||||
* 添加设备操作日志
|
||||
*
|
||||
* @param array $data 日志数据
|
||||
* @return int 新增日志ID
|
||||
*/
|
||||
public static function addLog(array $data): int
|
||||
{
|
||||
$log = new self();
|
||||
|
||||
$log->allowField(true)->save($data);
|
||||
|
||||
return $log->id;
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,9 @@ class DeviceTaskconf extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'device_taskconf';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
@@ -14,144 +15,12 @@ class DeviceUser extends Model
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'device_user';
|
||||
|
||||
/**
|
||||
* 设置主键
|
||||
* 由于该表是多字段联合主键,这里不设置主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = '';
|
||||
|
||||
/**
|
||||
* 自动时间戳
|
||||
* 该表不需要时间戳
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
/**
|
||||
* 字段类型
|
||||
* @var array
|
||||
*/
|
||||
protected $type = [
|
||||
'companyId' => 'integer',
|
||||
'userId' => 'integer',
|
||||
'deviceId' => 'integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取指定用户的所有设备ID
|
||||
* @param int $userId 用户ID
|
||||
* @param int $companyId 公司ID
|
||||
* @return array 设备ID数组
|
||||
*/
|
||||
public static function getUserDeviceIds($userId, $companyId = null)
|
||||
{
|
||||
$where = ['userId' => $userId];
|
||||
|
||||
if (!is_null($companyId)) {
|
||||
$where['companyId'] = $companyId;
|
||||
}
|
||||
|
||||
return self::where($where)
|
||||
->column('deviceId');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定设备的所有用户ID
|
||||
* @param int $deviceId 设备ID
|
||||
* @param int $companyId 公司ID
|
||||
* @return array 用户ID数组
|
||||
*/
|
||||
public static function getDeviceUserIds($deviceId, $companyId = null)
|
||||
{
|
||||
$where = ['deviceId' => $deviceId];
|
||||
|
||||
if (!is_null($companyId)) {
|
||||
$where['companyId'] = $companyId;
|
||||
}
|
||||
|
||||
return self::where($where)
|
||||
->column('userId');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备与用户的关联
|
||||
* @param int $companyId 公司ID
|
||||
* @param int $userId 用户ID
|
||||
* @param int $deviceId 设备ID
|
||||
* @return bool 是否添加成功
|
||||
*/
|
||||
public static function addRelation($companyId, $userId, $deviceId)
|
||||
{
|
||||
// 检查关联是否已存在
|
||||
$exists = self::where([
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'deviceId' => $deviceId
|
||||
])->find();
|
||||
|
||||
if ($exists) {
|
||||
return true; // 已存在,视为添加成功
|
||||
}
|
||||
|
||||
// 添加新关联
|
||||
return self::create([
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'deviceId' => $deviceId
|
||||
]) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加设备与用户的关联
|
||||
* @param int $companyId 公司ID
|
||||
* @param int $userId 用户ID
|
||||
* @param array $deviceIds 设备ID数组
|
||||
* @return int 成功添加的记录数
|
||||
*/
|
||||
public static function batchAddRelations($companyId, $userId, array $deviceIds)
|
||||
{
|
||||
if (empty($deviceIds)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($deviceIds as $deviceId) {
|
||||
$data[] = [
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'deviceId' => $deviceId
|
||||
];
|
||||
}
|
||||
|
||||
// 批量添加前先删除已存在的关联,避免主键冲突
|
||||
self::where('userId', $userId)
|
||||
->where('companyId', $companyId)
|
||||
->whereIn('deviceId', $deviceIds)
|
||||
->delete();
|
||||
|
||||
return self::insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备与用户的关联
|
||||
* @param int $companyId 公司ID
|
||||
* @param int $userId 用户ID
|
||||
* @param int $deviceId 设备ID
|
||||
* @return bool 是否删除成功
|
||||
*/
|
||||
public static function removeDeviceUserRelation($companyId, $userId, $deviceId)
|
||||
{
|
||||
return self::where([
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'deviceId' => $deviceId
|
||||
])->delete() !== false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
/**
|
||||
* 关联用户模型
|
||||
* @return \think\model\relation\BelongsTo
|
||||
@@ -160,22 +29,22 @@ class DeviceUser extends Model
|
||||
{
|
||||
return $this->belongsTo('User', 'userId', 'id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联设备模型
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function device()
|
||||
{
|
||||
return $this->belongsTo('app\devices\model\Device', 'deviceId', 'id');
|
||||
return $this->belongsTo('app\common\model\Device', 'deviceId', 'id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联公司模型
|
||||
* @return \think\model\relation\BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('Company', 'companyId', 'id');
|
||||
return $this->belongsTo('app\common\model\Company', 'companyId', 'id');
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,10 @@ class DeviceWechatLogin extends Model
|
||||
{
|
||||
// 登录日志最新登录 alive = 1,旧数据全部设置0
|
||||
protected $name = 'device_wechat_login';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
}
|
||||
@@ -14,6 +14,11 @@ class User extends Model
|
||||
*/
|
||||
protected $table = 'ck_users';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
/**
|
||||
* 主键
|
||||
* @var string
|
||||
|
||||
@@ -11,4 +11,10 @@ class WechatAccount extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_account';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
}
|
||||
@@ -11,4 +11,9 @@ class WechatFriend extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
}
|
||||
Reference in New Issue
Block a user