likang vor 2 Jahren
Ursprung
Commit
efddc7945b

+ 19 - 12
catch/wind/model/Fan.php

@@ -7,6 +7,7 @@ use think\facade\Db;
 use catchAdmin\wind\model\get\FanGet;
 use catchAdmin\wind\model\search\FanSearch;
 use catchAdmin\permissions\model\DataRangScopeTrait;
+
 class Fan extends Model
 {
 
@@ -37,24 +38,30 @@ class Fan extends Model
         'updated_at',
         // 软删除
         'deleted_at',
- 
+
     );
     public function getList()
     {
         return $this->dataRange()
-        ->catchSearch()
-        ->append(['wind_name','model_name'])
-        ->field('*')
-        ->catchOrder()
-        ->creator()
-        ->paginate();
+            ->catchSearch()
+            ->append(['wind_name', 'model_name'])
+            ->field('*')
+            ->catchOrder()
+            ->creator()
+            ->paginate();
     }
     public function getFanList()
     {
         return $this->dataRange()
-        ->catchSearch()
-        ->field('id as value,number as name')
-        ->catchOrder()
-        ->select();
+            ->catchSearch()
+            ->field('id as value,number as name')
+            ->catchOrder()
+            ->select();
+    }
+    //根据风场的id,获取风机的机位号
+    public function getFanListByWindId($wind_id)
+    {
+        $data = $this->where('wind_id', $wind_id)->select();
+        return $data;
     }
-}
+}

+ 17 - 16
catch/wind/model/Wind.php

@@ -5,6 +5,7 @@ namespace catchAdmin\wind\model;
 use catcher\base\CatchModel as Model;
 use catchAdmin\permissions\model\DataRangScopeTrait;
 use \think\facade\Db;
+
 class Wind extends Model
 {
     use DataRangScopeTrait;
@@ -46,27 +47,28 @@ class Wind extends Model
     );
     public function getList()
     {
-        
+
         // 分页列表
         return $this->dataRange()
             ->catchSearch()
             ->field('*')
             ->catchOrder()
-            ->append(['type_name','depart_name'])
+            ->append(['type_name', 'depart_name'])
             ->creator()
             ->paginate();
     }
-    public function getWindList(){
+    public function getWindList()
+    {
         // 不分页
         return $this->dataRange()
-        ->catchSearch()
-        ->field('*')
-        ->catchOrder()
-        ->append(['type_name','depart_name'])
-        ->creator()
-        ->select();
+            ->catchSearch()
+            ->field('*')
+            ->catchOrder()
+            ->append(['type_name', 'depart_name'])
+            ->creator()
+            ->select();
     }
-       /**
+    /**
      * 获取风场类型(文本)
      */
     public function getTypeNameAttr($value)
@@ -75,11 +77,11 @@ class Wind extends Model
             'circle' => '圆形围栏',
             'polygon' => '多边形围栏',
         ];
-        return $type_arr[$this->getData('wind_shape')] ? : '未知';     
+        return $type_arr[$this->getData('wind_shape')] ?: '未知';
     }
     public function getDepartmentIdAttr($value)
     {
-        return json_decode($value,true);
+        return json_decode($value, true);
     }
     public function getWindInfoAttr($value)
     {
@@ -87,12 +89,11 @@ class Wind extends Model
     }
     public function getDepartNameAttr($value)
     {
-        $id=$this->department_id;
+        $id = $this->department_id;
         return Db::table('departments')->where('id', $id)->value('department_name');
     }
     public function searchNameAttr($query, $value, $data)
     {
-        return $query->where('name','like','%'.$value.'%');
+        return $query->where('name', 'like', '%' . $value . '%');
     }
-    
-}
+}

+ 22 - 13
catch/worklocation/controller/Workplan.php

@@ -2,6 +2,7 @@
 
 namespace catchAdmin\worklocation\controller;
 
+use catchAdmin\wind\model\Fan;
 use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
@@ -10,60 +11,68 @@ use catchAdmin\worklocation\model\Workplan as workplanModel;
 class Workplan extends CatchController
 {
     protected $workplanModel;
-    
+
     public function __construct(WorkplanModel $workplanModel)
     {
         $this->workplanModel = $workplanModel;
     }
-    
+
     /**
      * 列表
      * @time 2022年06月28日 09:51
      * @param Request $request 
      */
-    public function index(Request $request) : \think\Response
+    public function index(Request $request): \think\Response
     {
         return CatchResponse::paginate($this->workplanModel->getList());
     }
-    
+
     /**
      * 保存信息
      * @time 2022年06月28日 09:51
      * @param Request $request 
      */
-    public function save(Request $request) : \think\Response
+    public function save(Request $request): \think\Response
     {
         return CatchResponse::success($this->workplanModel->storeBy($request->post()));
     }
-    
+
     /**
      * 读取
      * @time 2022年06月28日 09:51
      * @param $id 
      */
-    public function read($id) : \think\Response
+    public function read($id): \think\Response
     {
         return CatchResponse::success($this->workplanModel->findBy($id));
     }
-    
+
     /**
      * 更新
      * @time 2022年06月28日 09:51
      * @param Request $request 
      * @param $id
      */
-    public function update(Request $request, $id) : \think\Response
+    public function update(Request $request, $id): \think\Response
     {
         return CatchResponse::success($this->workplanModel->updateBy($id, $request->post()));
     }
-    
+
     /**
      * 删除
      * @time 2022年06月28日 09:51
      * @param $id
      */
-    public function delete($id) : \think\Response
+    public function delete($id): \think\Response
+    {
+        return CatchResponse::success($this->workplanModel->deleteBy($id, true));
+    }
+    public function getFanIdByWindId(Request $request)
     {
-        return CatchResponse::success($this->workplanModel->deleteBy($id));
+        $fan = new Fan();
+        $data = $request->get();
+        $list = [];
+        $list = $fan->getFanListByWindId($data['id']);
+        return  CatchResponse::success($list);
     }
-}
+}

+ 13 - 13
catch/worklocation/database/migrations/20220628095201_work_plan.php

@@ -29,19 +29,19 @@ class WorkPlan extends Migrator
      */
     public function change()
     {
-        $table = $this->table('work_plan', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '计划表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
-        $table->addColumn('wind_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '风场id',])
-			->addColumn('fan_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '风机id',])
-			->addColumn('work_sign', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '工作位置',])
-			->addColumn('parts_sign', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '部件类型',])
-			->addColumn('boit_type_sign', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '螺栓型号',])
-			->addColumn('plan_name', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '计划名称',])
-			->addColumn('info', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '详情',])
-			->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '状态  1 启用,-1 失效',])
-			->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
-			->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
-			->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
-			->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
+        $table = $this->table('work_plan', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '计划表', 'id' => 'id', 'signed' => true, 'primary_key' => ['id']]);
+        $table->addColumn('wind_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '风场id',])
+            ->addColumn('fan_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '风机id',])
+            ->addColumn('work_sign', 'string', ['limit' => 12, 'null' => true, 'signed' => true, 'comment' => '工作位置',])
+            ->addColumn('parts_sign', 'string', ['limit' => 12, 'null' => true, 'signed' => true, 'comment' => '部件类型',])
+            ->addColumn('boit_type_sign', 'string', ['limit' => 12, 'null' => true, 'signed' => true, 'comment' => '螺栓型号',])
+            ->addColumn('plan_name', 'string', ['limit' => 255, 'null' => true, 'signed' => true, 'comment' => '计划名称',])
+            ->addColumn('info', 'string', ['limit' => 255, 'null' => true, 'signed' => true, 'comment' => '详情',])
+            ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '状态  1 启用,-1 失效',])
+            ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => false, 'comment' => '创建人ID',])
+            ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => false, 'comment' => '创建时间',])
+            ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => false, 'comment' => '更新时间',])
+            ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => false, 'comment' => '软删除',])
             ->create();
     }
 }

+ 39 - 34
catch/worklocation/model/Workplan.php

@@ -1,8 +1,10 @@
 <?php
+
 namespace catchAdmin\worklocation\model;
 
 use catchAdmin\hydraulic\model\maintenancemapper as ModelMaintenancemapper;
 use catchAdmin\permissions\model\DataRangScopeTrait;
+use catchAdmin\permissions\model\Users;
 use catchAdmin\wind\model\Fan;
 use catchAdmin\wind\model\Wind;
 use catcher\base\CatchModel as Model;
@@ -43,48 +45,51 @@ class Workplan extends Model
     );
     public function getList()
     {
-            return $this->dataRange()
+        return $this->dataRange()
             ->catchSearch()
-            ->append(['wind_name','fan_number','work_sign_name','parts_sign_name','boit_type_sign_name','status_name'])
+            ->append(['wind_name', 'fan_number', 'work_sign_name', 'parts_sign_name', 'boit_type_sign_name', 'status_name', 'creat_name'])
             ->field('*')
             ->catchOrder()
             ->creator()
             ->paginate();
     }
     //获取风场名称
-   public function getWindNameAttr()
-   {
-       $wind_id = $this->wind_id;
-       $name =  Wind::where('id',$wind_id)->value('name');
-       return $name;
-   }
-   //获取风机机位号
-   public function getFanNumberAttr()
-   {
+    public function getWindNameAttr()
+    {
+        $wind_id = $this->wind_id;
+        $name =  Wind::where('id', $wind_id)->value('name');
+        return $name;
+    }
+    //获取风机机位号
+    public function getFanNumberAttr()
+    {
         $fan_id = $this->fan_id;
-        $number =  Fan::where('id',$fan_id)->value('number');
+        $number =  Fan::where('id', $fan_id)->value('number');
         return $number;
-   }
-   //获取工作位置
-   public function getWorkSignNameAttr()
-   {
-     
-     $name =  ModelMaintenancemapper::where('device_type',2)->where('value',$this->work_sign)->value('name');
-     return $name;
+    }
+    //获取工作位置
+    public function getWorkSignNameAttr()
+    {
 
-   }
-   //获取部件
-   public function getPartsSignNameAttr()
-   {
-        $name =  ModelMaintenancemapper::where('device_type',1)->where('value',$this->work_sign)->value('name');
+        $name =  ModelMaintenancemapper::where('device_type', 2)->where('value', $this->work_sign)->value('name');
         return $name;
-   }
-   //获取螺栓型号
-   public function getBoitTypeSignNameAttr()
-   {
-    $name =  ModelMaintenancemapper::where('device_type',4)->where('value',$this->boit_type_sign_name)->value('name');
-    return $name;
-   }
-
-
-}
+    }
+    //获取部件
+    public function getPartsSignNameAttr()
+    {
+        $name =  ModelMaintenancemapper::where('device_type', 1)->where('value', $this->parts_sign)->value('name');
+        return $name;
+    }
+    //获取螺栓型号
+    public function getBoitTypeSignNameAttr()
+    {
+        $name =  ModelMaintenancemapper::where('device_type', 4)->where('value', $this->boit_type_sign)->value('name');
+        return $name;
+    }
+    public function getCreatNameAttr()
+    {
+        $name = null;
+        $name =  Users::where('id', $this->creator_id)->value('realname');
+        return $name;
+    }
+}

+ 8 - 8
catch/worklocation/route.php

@@ -10,15 +10,15 @@
 // +----------------------------------------------------------------------
 
 // you should use `$router`
-$router->group(function () use ($router){
+$router->group(function () use ($router) {
 	// workLocation路由
 	$router->resource('worklocation', '\catchAdmin\worklocation\controller\WorkLocation');
-		// workplan路由
-	 $router->resource('workplan', '\catchAdmin\worklocation\controller\workplan');
+	// workplan路由
+	$router->resource('workplan', '\catchAdmin\worklocation\controller\workplan');
+	$router->get('queryFanByWindId', '\catchAdmin\worklocation\controller\workplan@getFanIdByWindId');
 })->middleware('auth');
 //维保记录统计图标
-$router->group('WorkLocationChart', function () use ($router){
-    //维保记录 
-    $router->get('total','\catchAdmin\worklocation\controller\WorkLocation@getTotal'); 
-    
-})->middleware('auth');
+$router->group('WorkLocationChart', function () use ($router) {
+	//维保记录 
+	$router->get('total', '\catchAdmin\worklocation\controller\WorkLocation@getTotal');
+})->middleware('auth');