6 changed files with 202 additions and 76 deletions
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Admin\Forms\CloneEquipResourceRecordForm; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class CloneEquipResourceRecordAction extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '克隆'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
return $this->response() |
||||
|
->success('Processed successfully: '.$this->getKey()) |
||||
|
->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
// 实例化表单类并传递自定义参数 |
||||
|
$form = CloneEquipResourceRecordForm::make()->payload($this->getRow()->getAttributes()); |
||||
|
|
||||
|
return Modal::make() |
||||
|
->lg() |
||||
|
->title($this->title) |
||||
|
->body($form) |
||||
|
->button($this->title); |
||||
|
} |
||||
|
} |
@ -0,0 +1,86 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms; |
||||
|
|
||||
|
use App\Admin\Services\EquipResourceRecordService; |
||||
|
use App\Models\EquipResourceRecord as EquipResourceRecordModel; |
||||
|
use Dcat\Admin\Contracts\LazyRenderable; |
||||
|
use Dcat\Admin\Traits\LazyWidget; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
|
||||
|
class CloneEquipResourceRecordForm extends Form implements LazyRenderable |
||||
|
{ |
||||
|
use LazyWidget; |
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
$equip_resource_service = new EquipResourceRecordService(); |
||||
|
|
||||
|
$res = $equip_resource_service->writeCache($input); |
||||
|
|
||||
|
if (!empty($res['errno'])){ |
||||
|
if ($res['errno'] === 0) { |
||||
|
$equip_resource_model = new EquipResourceRecordModel(); |
||||
|
$equip_resource_model['imei'] = $input['imei']; |
||||
|
$equip_resource_model['obj_id'] = $input['obj_id']; |
||||
|
$equip_resource_model['obj_inst_id'] = $input['obj_inst_id']; |
||||
|
$equip_resource_model['mode'] = $input['mode']; |
||||
|
$equip_resource_model['expired_time'] = $input['expired_time']; |
||||
|
$equip_resource_model['trigger_msg'] = $input['trigger_msg']; |
||||
|
$equip_resource_model['api-key'] = $input['api-key']; |
||||
|
$equip_resource_model['res_id'] = $input['res_id']; |
||||
|
$equip_resource_model['val'] = $input['val']; |
||||
|
$equip_resource_model->save(); |
||||
|
|
||||
|
return $this->response()->success('提交成功')->refresh();; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->error($res['error']); |
||||
|
} |
||||
|
|
||||
|
return $this->response()->error('提交失败'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$this->text('imei'); |
||||
|
$this->text('obj_id'); |
||||
|
$this->text('obj_inst_id'); |
||||
|
$this->text('mode'); |
||||
|
$this->text('expired_time'); |
||||
|
$this->text('trigger_msg'); |
||||
|
$this->text('api-key'); |
||||
|
$this->text('res_id'); |
||||
|
$this->text('val'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
'imei' => $this->payload['imei'], |
||||
|
'obj_id' => $this->payload['obj_id'], |
||||
|
'obj_inst_id' => $this->payload['obj_inst_id'], |
||||
|
'mode' => $this->payload['mode'], |
||||
|
'expired_time' => $this->payload['expired_time'], |
||||
|
'trigger_msg' => $this->payload['trigger_msg'], |
||||
|
'api-key' => $this->payload['api-key'], |
||||
|
'res_id' => $this->payload['res_id'], |
||||
|
'val' => $this->payload['val'], |
||||
|
]; |
||||
|
} |
||||
|
} |
@ -1,37 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use Illuminate\Support\Facades\Schema; |
|
||||
use Illuminate\Database\Schema\Blueprint; |
|
||||
use Illuminate\Database\Migrations\Migration; |
|
||||
|
|
||||
class CreateRecordEquipResourceWriteTable extends Migration |
|
||||
{ |
|
||||
/** |
|
||||
* Run the migrations. |
|
||||
* |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function up() |
|
||||
{ |
|
||||
Schema::create('record_equip_resource_write', function (Blueprint $table) { |
|
||||
$table->increments('id'); |
|
||||
$table->string('imei')->default('')->comment('nbiot设备的身份码'); |
|
||||
$table->string('obj_id')->default('')->comment('设备的object id , 对应到平台模型中为数据流id,必填'); |
|
||||
$table->string('obj_inst_id')->default('0')->comment('nbiot设备object下具体一个instance的id ,对应到平台模型中数据点key值的一部分,必填'); |
|
||||
$table->string('mode')->default('')->comment('write的写模式,只能是1或者2'); |
|
||||
$table->string('expired_time')->default('')->comment('命令过期时间戳,必填且大于valid_time'); |
|
||||
$table->string('trigger_msg')->default('')->comment('命令触发的上行消息类型,填写时必须在[1,7]之间;不填写默认为7'); |
|
||||
$table->timestamps(); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Reverse the migrations. |
|
||||
* |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function down() |
|
||||
{ |
|
||||
Schema::dropIfExists('record_equip_resource_write'); |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue