diff --git a/app/Admin/Controllers/CustomRegionController.php b/app/Admin/Controllers/CustomRegionController.php index 9a4b06e..4df28ef 100644 --- a/app/Admin/Controllers/CustomRegionController.php +++ b/app/Admin/Controllers/CustomRegionController.php @@ -17,7 +17,6 @@ class CustomRegionController extends AdminController public function regionIndex($type) { - switch($type){ case 'yuyang': // $this->pageTitle = '育秧列表'; diff --git a/app/Models/WarningNotice.php b/app/Models/WarningNotice.php index 67e98d1..e7ea0d4 100644 --- a/app/Models/WarningNotice.php +++ b/app/Models/WarningNotice.php @@ -23,6 +23,10 @@ class WarningNotice extends Model ]; } + public function loggable(){ + return $this->morphTo(); + } + public function device(){ return $this->belongsTo(Device::class, 'device_id'); } diff --git a/app/Services/DeviceWarningService.php b/app/Services/DeviceWarningService.php index 189d7e0..1f962dc 100644 --- a/app/Services/DeviceWarningService.php +++ b/app/Services/DeviceWarningService.php @@ -48,8 +48,16 @@ class DeviceWarningService foreach($rule['children'] as $child){ $cRes = $this->verifyRule($child, $log); if($cRes && $cRes['status']){ - $res['status'] = true; - $res['keys'] = array_merge($res['keys'], $cRes['keys']); + if($log->wasChanged($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; } } - $res['status'] = true; - $res['keys'][] = implode(',', $_keys); + if($log->wasChanged($_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; } @@ -134,6 +150,8 @@ class DeviceWarningService 'reported_at' => $reportedAt, 'created_at' => now(), 'updated_at' => now(), + 'loggable_type' => $log::class, + 'loggable_id' => $log->id, ]; } count($notices) > 0 && WarningNotice::insert($notices); diff --git a/database/migrations/2023_04_13_151822_create_warning_notices_table.php b/database/migrations/2023_04_13_151822_create_warning_notices_table.php index afda8ec..9cab918 100644 --- a/database/migrations/2023_04_13_151822_create_warning_notices_table.php +++ b/database/migrations/2023_04_13_151822_create_warning_notices_table.php @@ -21,6 +21,7 @@ return new class extends Migration $table->unsignedTinyInteger('status')->default(0)->comment('状态:0未处理,1已处理,2已忽略'); $table->string('remarks')->nullable()->comment('备注'); $table->timestamp('reported_at'); + $table->nullableMorphs('loggable'); $table->timestamps(); }); }