虫情统计
parent
d6f424a38a
commit
f365898601
|
|
@ -18,6 +18,7 @@ use App\Models\SoilMonitoringDailyLog;
|
|||
use App\Models\SoilMonitoringLog;
|
||||
use App\Models\WaterQualityMonitoringDailyLog;
|
||||
use App\Models\WaterQualityMonitoringLog;
|
||||
use App\Models\WormReport;
|
||||
use App\Services\BiAngDeviceService;
|
||||
use App\Services\OperationLogService;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -637,6 +638,43 @@ class DeviceController extends Controller
|
|||
return $this->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 虫情统计
|
||||
*/
|
||||
public function wormStatics($id, Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'start_time' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
'end_time' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
]);
|
||||
|
||||
$startAt = Carbon::parse($request->input('start_time'));
|
||||
|
||||
$endAt = Carbon::parse($request->input('end_time'));
|
||||
|
||||
if ($startAt->gt($endAt)) {
|
||||
throw ValidationException::withMessages([
|
||||
'start_time' => ['开始时间不能大于结束时间'],
|
||||
]);
|
||||
}
|
||||
|
||||
$device = Device::findOrFail($id);
|
||||
|
||||
$wormReports = WormReport::where('device_id', $device->id)
|
||||
->whereBetween('reported_at', [$startAt->toDateString(), $endAt->toDateString()])
|
||||
->pluck('worm_num', 'reported_at');
|
||||
|
||||
$data = [];
|
||||
|
||||
do {
|
||||
$key = $startAt->toDateString();
|
||||
$data[$key] = $wormReports->get($key);
|
||||
$startAt->addDay();
|
||||
} while ($startAt->lte($endAt));
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 虫情图片
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WormPhoto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'uploaded_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'device_id', 'url', 'uploaded_at',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('worm_photos', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('device_id');
|
||||
$table->text('url')->nullable();
|
||||
$table->timestamp('uploaded_at')->comment('上传时间');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('worm_photos');
|
||||
}
|
||||
};
|
||||
|
|
@ -56,6 +56,7 @@ Route::group([
|
|||
Route::apiResource('crop-flows', CropFlowController::class)->names('crops_flow');
|
||||
//设备管理
|
||||
Route::apiResource('devices', DeviceController::class)->names('device');
|
||||
Route::get('devices/{device}/worm-statics', [DeviceController::class, 'wormStatics']);
|
||||
Route::get('devices/{device}/worm-photos', [DeviceController::class, 'wormPhotos']);
|
||||
Route::put('devices-update-recommend/{device}', [DeviceController::class, 'updateRecommendStatus']);
|
||||
Route::get('devices-num', [DeviceController::class, 'typeStatusNum'])->name('device.type_status_num');
|
||||
|
|
|
|||
Loading…
Reference in New Issue