虫情数据
parent
61dc022054
commit
cd9a6bc3d0
|
|
@ -5,7 +5,7 @@ namespace App\Console\Commands\BiAng;
|
||||||
use App\Enums\DeviceStatus;
|
use App\Enums\DeviceStatus;
|
||||||
use App\Enums\DeviceType;
|
use App\Enums\DeviceType;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\WormStatisticsReport;
|
use App\Models\WormReport;
|
||||||
use App\Services\BiAngDeviceService;
|
use App\Services\BiAngDeviceService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
@ -53,7 +53,7 @@ class WormStatisticsSyncCommand extends Command
|
||||||
foreach ($devices as $device) {
|
foreach ($devices as $device) {
|
||||||
$this->info('==================================');
|
$this->info('==================================');
|
||||||
|
|
||||||
$latestReportedAt = WormStatisticsReport::Where('device_id', $device->id)->latest('reported_at')->value('reported_at');
|
$latestReportedAt = WormReport::Where('device_id', $device->id)->latest('reported_at')->value('reported_at');
|
||||||
|
|
||||||
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy()->subDays(179);
|
$start = $latestReportedAt ? $latestReportedAt->copy() : $today->copy()->subDays(179);
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ class WormStatisticsSyncCommand extends Command
|
||||||
foreach (data_get($statistics, 'data.records', []) as $item) {
|
foreach (data_get($statistics, 'data.records', []) as $item) {
|
||||||
$data = collect(Arr::except($item, '日期'))->map(fn ($v, $k) => ['name' => $k, 'num' => $v]);
|
$data = collect(Arr::except($item, '日期'))->map(fn ($v, $k) => ['name' => $k, 'num' => $v]);
|
||||||
|
|
||||||
WormStatisticsReport::updateOrCreate([
|
WormReport::updateOrCreate([
|
||||||
'device_id' => $device->id,
|
'device_id' => $device->id,
|
||||||
'reported_at' => $item['日期'],
|
'reported_at' => $item['日期'],
|
||||||
], [
|
], [
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class WormStatisticsReport extends Model
|
class WormReport extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('worm_statistics_reports', function (Blueprint $table) {
|
Schema::create('worm_reports', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('device_id');
|
$table->unsignedBigInteger('device_id');
|
||||||
$table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID');
|
$table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID');
|
||||||
|
|
@ -31,6 +31,6 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('worm_statistics_reports');
|
Schema::dropIfExists('worm_reports');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue