123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Actions\Post\ImportExcel;
- use App\Http\Controllers\Controller;
- use App\Model\TextLabel;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Controllers\ModelForm;
- use Illuminate\Http\Request;
- use SebastianBergmann\CodeCoverage\Report\Html\Renderer;
- class TextLabelController extends Controller
- {
- use ModelForm;
- public function index()
- {
- return Admin::content(function (Content $content) {
- $content->header('文案标注');
- $content->description('列表');
- $content->body($this->grid());
- });
- }
- // public function create()
- // {
- // return Admin::content(function (Content $content) {
- // $content->header('视频');
- // $content->description('新增');
- // $content->body($this->form());
- // });
- // }
- public function edit($id)
- {
- return Admin::content(function (Content $content) use ($id) {
- $content->header('文案标注');
- $content->description('列表');
- $content->body($this->form($id)->edit($id));
- });
- }
- protected function form($id = '')
- {
- $data = [
- 'symptom' => [],
- 'operation' => [],
- 'medicine' => [],
- 'disease' => [],
- 'inspection' => [],
- 'test' => [],
- 'date' => []
- ];
- self::botLabel($id,$data);
- return Admin::form(TextLabel::class, function (Form $form) use ($data){
- $form->display('id' , '编号');
- $form->display('text' , '文案');
- $form->embeds('symptom','症状',function ($form) use ($data){
- $num = 0;
- foreach ($data['symptom'] as $item){
- $form->text($num,'terms')->default($item);
- $num ++;
- }
- });
- $form->list('add_symptom');
- $form->embeds('disease','疾病',function ($form) use ($data){
- $num = 0;
- foreach ($data['disease'] as $item){
- $form->text($num,'terms')->default($item);
- $num ++;
- }
- });
- $form->list('add_disease');
- $form->embeds('operation','操作',function ($form) use ($data){
- $num = 0;
- foreach ($data['operation'] as $item){
- $form->text($num,'terms')->default($item);
- $num ++;
- }
- });
- $form->list('add_operation');
- $form->embeds('medicine','药品',function ($form) use ($data){
- $num = 0;
- foreach ($data['medicine'] as $item){
- $form->text($num,'terms')->default($item);
- $num ++;
- }
- });
- $form->list('add_medicine');
- $form->table('inspection' , '检查',function ($form){
- $form->text('terms');
- $form->text('tag');
- });
- $form->table('test' , '检验',function ($form){
- $form->text('terms');
- $form->text('tag');
- });
- $form->embeds('date','时间',function ($form) use ($data){
- $num = 0;
- foreach ($data['date'] as $item){
- $form->text($num,'terms')->default($item);
- $num ++;
- }
- });
- $form->list('add_date');
- $form->disableViewCheck();
- $form->disableEditingCheck();
- $form->disableCreatingCheck();
- $form->submitted(function (Form $form){
- $fields = [
- 'inspection',
- 'test',
- 'symptom',
- 'add_symptom',
- 'medicine',
- 'add_medicine',
- 'operation',
- 'add_operation',
- 'disease',
- 'add_disease',
- 'date',
- 'add_date'];
- $form->ignore($fields);
- });
- });
- }
- protected function botLabel($id,&$data){
- $text = TextLabel::query()->where('id',$id)->first(['text as sentence']);
- if ($text){
- $text = $text->toArray();
- }else{
- return;
- }
- $url = 'http://121.36.94.218:10090/disease/ner/predict?'.http_build_query($text);
- $result = file_get_contents($url);
- $result = json_decode($result,true);
- if ($result['code'] == 200){
- $botLabel = $result['data'];
- if (!empty($botLabel['symptom'])){
- $data['symptom'] = array_keys($botLabel['symptom']);
- }
- if (!empty($botLabel['operation'])){
- $data['operation'] = array_keys($botLabel['operation']);
- }
- if (!empty($botLabel['medicine'])){
- $data['medicine'] = array_keys($botLabel['medicine']);
- }
- if (!empty($botLabel['disease'])){
- $data['disease'] = array_keys($botLabel['disease']);
- }
- if (!empty($botLabel['inspection'])){
- $data['inspection'] = array_keys($botLabel['inspection']);
- }
- if (!empty($botLabel['test'])){
- $data['test'] = array_keys($botLabel['test']);
- }
- if (!empty($botLabel['date'])){
- $data['date'] = array_keys($botLabel['date']);
- }
- }
- }
- // Grid
- protected function grid()
- {
- return Admin::grid(TextLabel::class, function (Grid $grid) {
- $grid->id('编号')->sortable();
- $grid->model()->where('status',0)->orderBy('id','desc');
- $grid->text('文案');
- $grid->status('状态')->display(function ($status){
- if(0 == $status) {
- return "<span class='btn btn-success'>未标注</span>";
- } else {
- return "<span class='btn btn-danger'>已标注</span>";
- }
- });
- $grid->created_at('创建时间');
- $grid->updated_at('更新时间');
- $grid->disableCreation();
- $grid->disableExport();;
- $grid->tools(function ($tools) {
- // 禁用批量删除按钮
- $tools->batch(function ($batch) {
- $batch->disableDelete();
- });
- $tools->append(new ImportExcel());
- });
- $grid->actions(function ($actions) {
- $actions->disableView();
- //$actions->disableEdit();
- });
- });
- }
- }
|