1
0
Fork 0

处理重复报警问题

develop
vine_liutk 2023-05-26 18:44:43 +08:00
parent cf78e26df7
commit 8840e75eb2
4 changed files with 27 additions and 5 deletions

View File

@ -17,7 +17,6 @@ class CustomRegionController extends AdminController
public function regionIndex($type) public function regionIndex($type)
{ {
switch($type){ switch($type){
case 'yuyang': case 'yuyang':
// $this->pageTitle = '育秧列表'; // $this->pageTitle = '育秧列表';

View File

@ -23,6 +23,10 @@ class WarningNotice extends Model
]; ];
} }
public function loggable(){
return $this->morphTo();
}
public function device(){ public function device(){
return $this->belongsTo(Device::class, 'device_id'); return $this->belongsTo(Device::class, 'device_id');
} }

View File

@ -48,8 +48,16 @@ class DeviceWarningService
foreach($rule['children'] as $child){ foreach($rule['children'] as $child){
$cRes = $this->verifyRule($child, $log); $cRes = $this->verifyRule($child, $log);
if($cRes && $cRes['status']){ if($cRes && $cRes['status']){
$res['status'] = true; if($log->wasChanged($cRes['keys'])){
$res['keys'] = array_merge($res['keys'], $cRes['keys']); $res['status'] = true;
$res['keys'] = array_merge($res['keys'], $cRes['keys']);
}elseif(WarningNotice::where([
'loggable_type' => $log::class,
'loggable_id' => $log->id,
])->count() == 0){
$res['status'] = true;
$res['keys'] = array_merge($res['keys'], $cRes['keys']);
}
} }
} }
} }
@ -66,8 +74,16 @@ class DeviceWarningService
break; break;
} }
} }
$res['status'] = true; if($log->wasChanged($_keys)){
$res['keys'][] = implode(',', $_keys); $res['status'] = true;
$res['keys'][] = implode(',', $_keys);
}elseif(WarningNotice::where([
'loggable_type' => $log::class,
'loggable_id' => $log->id,
])->count() == 0){
$res['status'] = true;
$res['keys'][] = implode(',', $_keys);
}
} }
break; break;
} }
@ -134,6 +150,8 @@ class DeviceWarningService
'reported_at' => $reportedAt, 'reported_at' => $reportedAt,
'created_at' => now(), 'created_at' => now(),
'updated_at' => now(), 'updated_at' => now(),
'loggable_type' => $log::class,
'loggable_id' => $log->id,
]; ];
} }
count($notices) > 0 && WarningNotice::insert($notices); count($notices) > 0 && WarningNotice::insert($notices);

View File

@ -21,6 +21,7 @@ return new class extends Migration
$table->unsignedTinyInteger('status')->default(0)->comment('状态0未处理1已处理2已忽略'); $table->unsignedTinyInteger('status')->default(0)->comment('状态0未处理1已处理2已忽略');
$table->string('remarks')->nullable()->comment('备注'); $table->string('remarks')->nullable()->comment('备注');
$table->timestamp('reported_at'); $table->timestamp('reported_at');
$table->nullableMorphs('loggable');
$table->timestamps(); $table->timestamps();
}); });
} }