weich 3 년 전
부모
커밋
69db66d20d

+ 23 - 0
catch/hydraulic/HydraulicService.php

@@ -0,0 +1,23 @@
+<?php
+// +----------------------------------------------------------------------
+// | CatchAdmin [Just Like ~ ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
+// +----------------------------------------------------------------------
+// | Author: JaguarJack [ njphper@gmail.com ]
+// +----------------------------------------------------------------------
+
+namespace catchAdmin\hydraulic;
+
+use catcher\ModuleService;
+
+class HydraulicService extends ModuleService
+{
+    public function loadRouteFrom()
+    {
+        // TODO: Implement loadRouteFrom() method.
+        return __DIR__ . DIRECTORY_SEPARATOR . 'route.php';
+    }
+}

+ 73 - 0
catch/hydraulic/controller/Hydraulic.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace catchAdmin\hydraulic\controller;
+
+use catcher\base\CatchRequest as Request;
+use catcher\CatchResponse;
+use catcher\base\CatchController;
+use catchAdmin\hydraulic\model\Hydraulic as hydraulicModel;
+
+class Hydraulic extends CatchController
+{
+    protected $hydraulicModel;
+    
+    public function __construct(HydraulicModel $hydraulicModel)
+    {
+        $this->hydraulicModel = $hydraulicModel;
+    }
+    
+    /**
+     * 列表
+     * @time 2022年03月03日 14:28
+     * @param Request $request 
+     */
+    public function index(Request $request) : \think\Response
+    {
+        return CatchResponse::paginate($this->hydraulicModel->getList());
+    }
+    
+    /**
+     * 保存信息
+     * @time 2022年03月03日 14:28
+     * @param Request $request 
+     */
+    public function save(Request $request) : \think\Response
+    {
+        $data = $request->post();
+        $data['out_date'] = date('Y-m-d H:i:s',$data['out_date']);
+        return CatchResponse::success($this->hydraulicModel->storeBy($data));
+    }
+    
+    /**
+     * 读取
+     * @time 2022年03月03日 14:28
+     * @param $id 
+     */
+    public function read($id) : \think\Response
+    {
+        return CatchResponse::success($this->hydraulicModel->findBy($id));
+    }
+    
+    /**
+     * 更新
+     * @time 2022年03月03日 14:28
+     * @param Request $request 
+     * @param $id
+     */
+    public function update(Request $request, $id) : \think\Response
+    {
+        $data = $request->post();
+        $data['out_date'] = date('Y-m-d H:i:s',$data['out_date']);
+        return CatchResponse::success($this->hydraulicModel->updateBy($id, $data));
+    }
+    
+    /**
+     * 删除
+     * @time 2022年03月03日 14:28
+     * @param $id
+     */
+    public function delete($id) : \think\Response
+    {
+        return CatchResponse::success($this->hydraulicModel->deleteBy($id,true));
+    }
+}

+ 62 - 0
catch/hydraulic/database/migrations/20220303142809_hydraulic.php

@@ -0,0 +1,62 @@
+<?php
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+use Phinx\Db\Adapter\MysqlAdapter;
+
+class Hydraulic extends Migrator
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
+     *
+     * The following commands can be used in this method and Phinx will
+     * automatically reverse them when rolling back:
+     *
+     *    createTable
+     *    renameTable
+     *    addColumn
+     *    renameColumn
+     *    addIndex
+     *    addForeignKey
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change()
+    {
+        $table = $this->table('hydraulic', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
+        //基础信息
+        $table->addColumn('number', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '编号',])
+			->addColumn('model', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '型号',])
+			->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '所属部门',])
+			->addColumn('name', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '名称',])
+			->addColumn('is_used', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '使用状态',])
+			->addColumn('brand', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '品牌',])
+			->addColumn('supplier', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '供应商',])
+			->addColumn('out_date', 'date', ['null' => true,'signed' => true,'comment' => '出厂日期',])
+            ->addColumn('remark', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '备注',])
+            ->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '设备类型',])
+			->addColumn('alarm_state', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '告警状态',])
+			->addColumn('net_state', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '网络状态',])
+			->addColumn('online_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'default' => null,'signed' => true,'comment' => '在线时间',])
+			->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' => '软删除',])
+
+        //液压泵规格信息
+            ->addColumn('pressure_range', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '压力范围(PSI)',])
+        //液压扳手实时维保信息
+            ->addColumn('coefficient_a', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '校准系数a',])
+            ->addColumn('coefficient_b', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '校准系数b',])
+            ->addColumn('checked_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '校验时间',])
+            ->addColumn('checked_no', 'string', ['limit' => 50,'null' => true,'default' => null,'signed' => false,'comment' => '校验台编号',])
+            ->addColumn('checked_res', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '校验结果',])
+            ->create();
+    }
+}

+ 124 - 0
catch/hydraulic/model/Hydraulic.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace catchAdmin\hydraulic\model;
+
+use catcher\base\CatchModel as Model;
+use \think\facade\Db;
+use catchAdmin\permissions\model\DataRangScopeTrait;
+class Hydraulic extends Model
+{
+    use DataRangScopeTrait;
+    // 表名
+    public $name = 'hydraulic';
+    // 数据库字段映射
+    public $field = array(
+        'id',
+        // 编号
+        'number',
+        // 型号
+        'model',
+        // 所属部门
+        'department_id',
+        // 名称
+        'name',
+        // 使用状态
+        'is_used',
+        // 品牌
+        'brand',
+        // 供应商
+        'supplier',
+        // 出厂日期
+        'out_date',
+        // 告警状态
+        'alarm_state',
+        // 网络状态
+        'net_state',
+        // 在线时间
+        'online_time',
+        //备注
+        'remark',
+        // 创建人ID
+        'creator_id',
+        // 创建时间
+        'created_at',
+        // 更新时间
+        'updated_at',
+        // 软删除
+        'deleted_at',
+    );
+     /**
+     * 获取列表
+     */
+    public function getList()
+    {
+        $res =  $this->dataRange()
+            ->catchSearch()
+            ->append(['depart_name', 'alarm_state_text','creator_user'])
+            ->order($this->aliasField('id'), 'desc')
+            ->paginate();
+        return $res;
+    }
+     /**
+     * 获取导入用户(文本)
+     */
+    public function getCreatorUserAttr($value)
+    {
+
+        $uid = $this->creator_id;
+        return Db::table('users')->where('id', $uid)->value('username') ?: '';
+    }
+    /**
+     * 获取部门名称(文本)
+     */
+    public function getDepartNameAttr()
+    {
+        $id = $this->getData('department_id');
+        return Db::table('departments')->where('id', $id)->value('department_name');
+    }
+    /**
+     * 获取告警状态文本
+     */
+    public function getAlarmStateTextAttr($value)
+    {
+      $alarm_state = $this->getData('alarm_state');
+      return  $alarm_state ? '告警' : '正常';
+    }
+     /**
+     * 根据部门搜索
+     */
+    public function searchDepartmentIdAttr($query, $value, $data)
+    {
+        if ($value) {
+            $id = end($value);
+            return $query->where('department_id', '=', $id);
+        }
+    }
+     /**
+     * 根据number搜索
+     */
+    public function searchNumberAttr($query, $value, $data)
+    {
+            return $query->where('number', 'like', '%'.$value.'%');
+    }
+     /**
+     * 根据name搜索
+     */
+    public function searchNameAttr($query, $value, $data)
+    {
+            return $query->where('name', 'like', '%'.$value.'%');
+    }
+     /**
+     * 根据model搜索
+     */
+    public function searchModelAttr($query, $value, $data)
+    {
+            return $query->where('model', 'like', '%'.$value.'%');
+    }
+     /**
+     * 根据name搜索
+     */
+    public function searchIsUsedAttr($query, $value, $data)
+    {
+            return $query->where('is_used', $value);
+    }
+}

+ 15 - 0
catch/hydraulic/module.json

@@ -0,0 +1,15 @@
+{
+    "name": "hydraulic",
+    "alias": "hydraulic",
+    "description": "液压泵",
+    "version": "1.0.0",
+    "keywords": [""],
+    "order": 0,
+    "services": [
+        "\\catchAdmin\\hydraulic\\HydraulicService"
+    ],
+    "aliases": {},
+    "files": [],
+    "requires": [],
+    "enable": true
+}

+ 16 - 0
catch/hydraulic/route.php

@@ -0,0 +1,16 @@
+<?php
+// +----------------------------------------------------------------------
+// | CatchAdmin [Just Like ~ ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
+// +----------------------------------------------------------------------
+// | Author: JaguarJack [ njphper@gmail.com ]
+// +----------------------------------------------------------------------
+
+// you should use `$router`
+$router->group(function () use ($router){
+	// hydraulic路由
+	$router->resource('hydraulic', '\catchAdmin\hydraulic\controller\Hydraulic');
+})->middleware('auth');