likang %!s(int64=2) %!d(string=hai) anos
pai
achega
6e61d032fb

+ 0 - 73
app/common.php

@@ -361,76 +361,3 @@ function optimize_json($tempResult)
 {
     return mb_convert_encoding($tempResult, 'UTF-8', 'UTF-8');;
 }
-
-/**
- * 导入excel表  公用方法
- * 
- */
-/**
- * @Descripttion: 
- * @name: likang
- * @param {CatchRequest} $request
- * @param {*} $map [[key=>'e','value'=>'属性']]
- * @param  $model 数据库模型
- * @return {*}
- */
-function importExcel(CatchRequest $request, $map, $model, $func)
-{
-    $url = $request->post('url');
-    if (!$url) {
-        return CatchResponse::fail('请上传文件');
-    }
-
-    $creator_id = $request->post('creator_id');
-    //解析地址
-    $parse_url = parse_url($url)['path'];
-    //载入excel表格 
-    $objPHPExcel = IOFactory::load(public_path() . $parse_url);
-    // var_dump($objPHPExcel);
-    //获取表名,一维数组,值是表名。如:array('sheet1', 'sheet2', 'sheet3')
-    // $nameArr = $objPHPExcel->getSheetNames();
-    // var_dump($nameArr);
-    //获取表的数量
-    $sheetCount = $objPHPExcel->getSheetCount();
-    $fail = 0; //失败条数
-    $success = 0; //成功条数
-    $total = 0; //总导入数
-    $excel_data = [];
-    //循环读取每一张表
-    for ($index = 0; $index < $sheetCount; $index++) {
-        //设置当前要读取的表
-        $sheet = $objPHPExcel->getSheet($index);   //excel中的第一张sheet
-        // var_dump($sheet);exit;
-        $highestRow  = $sheet->getHighestRow();       // 取得总行数
-        // var_dump($highestRow);
-        if ($highestRow <= 2) {
-            continue;
-        }
-        $total += $highestRow - 3;
-        for ($j = 4; $j <= $highestRow - 1; $j++) {
-
-            $data = array(); //每条门店信息
-
-            foreach ($map as $item) {
-
-                $data[$item['value']] = trim($sheet->getCell($item['key'] . $j)->getFormattedValue());
-            }
-            $data = $func($data);
-            //校验数据是否重复
-            if (!$data) {
-                continue;
-            }
-            array_push($excel_data, $data);
-        }
-    }
-
-    // var_dump($excel_data);
-    // return CatchResponse::success();
-    //防止Excel有重复,去重
-    array_unique($excel_data, SORT_REGULAR);
-    if ($count = $model->limit(100)->insertAll($excel_data)) {
-        return CatchResponse::success('共' . $total . '条数据,成功' . $count . '条,失败' . $fail . '条');
-    }
-    return CatchResponse::success(['error' => true, 'msg' => '导入失败']);
-    // return CatchResponse::success('共' . $total . '条数据,成功' . $success . '条,失败' . $fail . '条');
-}

+ 1 - 1
catch/api/Directive.php

@@ -5,7 +5,7 @@
  * @Author: likang
  * @Date: 2022-07-28 14:39:11
  * @LastEditors: likang
- * @LastEditTime: 2022-07-28 16:28:16
+ * @LastEditTime: 2022-08-08 20:30:23
  */
 
 namespace catchAdmin\api;

+ 0 - 39
catch/api/controller/Base.php

@@ -1,39 +0,0 @@
-<?php
-/*
- * @Descripttion: 
- * @version: 
- * @Author: wei
- * @Date: 2022-06-09 14:39:53
- * @LastEditors: wei
- * @LastEditTime: 2022-06-09 15:43:08
- */
-/*
- * @Descripttion: 
- * @version: 
- * @Author: wei
- * @Date: 2022-06-09 14:39:53
- * @LastEditors: wei
- * @LastEditTime: 2022-06-09 15:35:57
- */
-
-namespace catchAdmin\api\controller;
-use catchAdmin\permissions\model\Roles;
-use catchAdmin\permissions\model\Users as ModelUsers;
-use catcher\base\CatchRequest as Request;
-use catcher\CatchResponse;
-use catcher\base\CatchController;
-use think\Db;
-
-class Base extends CatchController
-{ 
-  
-   public function __initialize()
-   {
-       var_dump('我测试一下');
-   }
-   
-   public function test()
-   {
-
-   }
-}

+ 0 - 40
catch/api/controller/MaintenanceRecord.php

@@ -1,40 +0,0 @@
-<?php
-/*
- * @Descripttion: 维保记录
- * @version: 1.0.0
- * @Author: likang
- * @Date: 2022-06-09 16:27:35
- * @LastEditors: likang
- * @LastEditTime: 2022-06-09 19:09:54
- */
-
-namespace catchAdmin\api\controller;
-
-use catchAdmin\worklocation\model\Worklocation;
-use catcher\base\CatchRequest as Request;
-use catcher\CatchResponse;
-use catcher\base\CatchController;
-use think\facade\Db;
-
-class MaintenanceRecord extends Base
-{
-    /**
-     * @Descripttion: 接收维保记录  
-     * 维保记录可能是多条数据
-     * @name: likang
-     * @return {*}
-     */    
-    public function SaveMaintenanceRecord()
-    {
-        $data =  json_decode($_POST['data'],true);
-        foreach($data as $item)
-        {
-
-            Db::name('work_location')->data($item)->install();
-        }
-
-    }
-
-
-    
-}

+ 4 - 4
catch/api/controller/Tool.php

@@ -15,7 +15,7 @@ use Workerman\Worker;
 use Wrench;
 
 error_reporting(0);
-class Tool extends Base
+class Tool extends CatchController
 {
     /**
      * @Descripttion: 下发设备   携带的参数 imei号  版本号  上传心跳包
@@ -36,6 +36,7 @@ class Tool extends Base
         }
         //校验imei是否存在
         if (!isset($param['IMEI']) ||  $param['IMEI'] == '') {
+
             json_fail('缺少设备IMEI号参数');
         }
         $Imei = $param['IMEI'];
@@ -67,6 +68,7 @@ class Tool extends Base
             var_dump(optimize_json(hex2bin(file_get_contents("php://input"))));
             $param = json_decode(optimize_json(hex2bin(file_get_contents("php://input"))), true);
             var_dump($param);
+            echo $param['IMEI'];
         } else {
             $param = json_decode(optimize_json(file_get_contents("php://input")), true);
         }
@@ -75,9 +77,6 @@ class Tool extends Base
         if (json_last_error() != 0) {
             json_fail('解析异常', json_last_error_msg());
         }
-
-
-
         //校验imei是否存在
         $where = [];
         if (!isset($param['Imei']) || $param['Imei'] == '') {
@@ -85,6 +84,7 @@ class Tool extends Base
             json_fail('缺少设备IMEI号参数');
         }
         $Imei = $param['Imei'];
+
         //校验Imei是否存在
         if (!$this->IsImei($Imei)) {
             json_fail('该Imei号不存在');

+ 1 - 1
catch/api/route.php

@@ -5,7 +5,7 @@
  * @Author: likang
  * @Date: 2022-06-09 10:11:32
  * @LastEditors: likang
- * @LastEditTime: 2022-07-21 19:06:52
+ * @LastEditTime: 2022-08-07 16:21:11
  */
 // +----------------------------------------------------------------------
 // | CatchAdmin [Just Like ~ ]

+ 24 - 16
catch/hydraulic/controller/DeviceMold.php

@@ -1,4 +1,12 @@
 <?php
+/*
+ * @Descripttion: 
+ * @version: 1.0.0
+ * @Author: likang
+ * @Date: 2022-05-27 13:34:31
+ * @LastEditors: likang
+ * @LastEditTime: 2022-08-05 09:26:09
+ */
 
 namespace catchAdmin\hydraulic\controller;
 
@@ -10,70 +18,70 @@ use catchAdmin\hydraulic\model\DeviceMold as deviceMoldModel;
 class DeviceMold extends CatchController
 {
     protected $deviceMoldModel;
-    
+
     public function __construct(DeviceMoldModel $deviceMoldModel)
     {
         $this->deviceMoldModel = $deviceMoldModel;
     }
-    
+
     /**
      * 列表
      * @time 2022年05月06日 10:22
      * @param Request $request 
      */
-    public function index(Request $request) : \think\Response
+    public function index(Request $request): \think\Response
     {
         return CatchResponse::paginate($this->deviceMoldModel->getList());
     }
-    
+
     /**
      * 保存信息
      * @time 2022年05月06日 10:22
      * @param Request $request 
      */
-    public function save(Request $request) : \think\Response
+    public function save(Request $request): \think\Response
     {
         return CatchResponse::success($this->deviceMoldModel->storeBy($request->post()));
     }
-    
+
     /**
      * 读取
      * @time 2022年05月06日 10:22
      * @param $id 
      */
-    public function read($id) : \think\Response
+    public function read($id): \think\Response
     {
         return CatchResponse::success($this->deviceMoldModel->findBy($id));
     }
-    
+
     /**
      * 更新
      * @time 2022年05月06日 10:22
      * @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->deviceMoldModel->updateBy($id, $request->post()));
     }
-    
+
     /**
      * 删除
      * @time 2022年05月06日 10:22
      * @param $id
      */
-    public function delete($id) : \think\Response
+    public function delete($id): \think\Response
     {
-        return CatchResponse::success($this->deviceMoldModel->deleteBy($id,true));
+        return CatchResponse::success($this->deviceMoldModel->deleteBy($id, true));
     }
-      /**
+    /**
      * 根据设备类型获取设备型号
      * @time 2022年05月06日 10:22
      * @param $id
      */
-    public function getDeviceMold(Request $request) : \think\Response
+    public function getDeviceMold(Request $request): \think\Response
     {
         $type = $request->get('type');
-        return CatchResponse::success($this->deviceMoldModel->where('device_type',$type)->field('id as value,name as text')->select());
+        return CatchResponse::success($this->deviceMoldModel->where('device_type', $type)->field('id as value,name as text')->select());
     }
-}
+}

+ 38 - 9
catch/hydraulic/controller/HydEquipment.php

@@ -12,8 +12,11 @@ use catcher\base\CatchController;
 use catchAdmin\hydraulic\model\HydEquipment as hydEquipmentModel;
 use catchAdmin\hydraulic\model\Hydraulic;
 use catchAdmin\hydraulic\model\Wrench;
+use catchAdmin\hydraulic\server\ExcelServer;
 use catchAdmin\system\model\SysDictData;
 use catcher\base\CatchRequest;
+use catcher\Code;
+use catcher\library\excel\ExcelContract;
 use PhpOffice\PhpSpreadsheet\IOFactory;
 use PhpParser\Node\Stmt\Catch_;
 use think\facade\Db;
@@ -321,7 +324,6 @@ class HydEquipment extends CatchController
     {
         $data = $request->get();
         $type = $data['type'];
-
         $list =  $this->hydEquipmentModel->where('equipment_type', $type)->field('id as value,name as text')->select();
         return CatchResponse::success($list);
     }
@@ -360,7 +362,6 @@ class HydEquipment extends CatchController
             } else {
                 $data['check_status'] = 1;
             }
-
             if ($data['status'] = '使用中') {
                 $data['status'] = 4;
             } else if ($data['status'] == '待维修') {
@@ -372,12 +373,26 @@ class HydEquipment extends CatchController
             } else if ($data['status'] == '备用') {
                 $data['status'] = 3;
             }
-
-
             return $data;
         };
-        return importExcel($request, $map, $this->hydEquipmentModel, $func);
+        $install = function ($data) {
+            $id = $this->hydEquipmentModel->save($data);
+        };
+        $server =  ExcelServer::getInterface();
+        return  $server->importExcel($request, $map, $func, $install);
+    }
+    /**
+     * @Descripttion: 导出excel 
+     * @name: likang
+     * @param {Request} $request
+     * @return {*}
+     */
+    public function exportExcel(Request $request)
+    {
     }
+
+
+
     /**
      * @Descripttion: 查看上传的日志
      * @name: likang
@@ -388,14 +403,30 @@ class HydEquipment extends CatchController
         //获取设备的imei号
         $imei = $request->get('imei');
         $pub_ack  = new PublishAck();
+        $limit = 10;
+        $page = 1;
+        if ($request->get('page')) {
+            $page = $request->get('page');
+        }
+        if ($request->get('limit')) {
+            $limit = $request->get('limit');
+        }
 
-        $list =  Db::name('publish_ack')->where('Imei', $imei)->field('id,PublishVersion,AddTime,Succ,AckTime,Imei')->order('PublishVersion', 'desc')->select()->toArray();
+        $list =  Db::name('publish_ack')->where('Imei', $imei)->limit($limit)->page($page)
+            ->field('id,PublishVersion,AddTime,Succ,AckTime,Imei')->order('PublishVersion', 'desc')->select()->toArray();
         foreach ($list as $key => $item) {
             //时间
             $list[$key]['AddTime'] = date('Y-m-d H:i:s', substr($item['AddTime'], 0, 10));
             $list[$key]['AckTime'] = date('Y-m-d H:i:s', substr($item['AckTime'], 0, 10));
         }
-        return CatchResponse::success($list);
+        return json([
+            'code'    => Code::SUCCESS,
+            'message' => 'success',
+            'count'   => Db::name('publish_ack')->where('Imei', $imei)->count(),
+            'current' => $page,
+            'limit'   => $limit,
+            'data'    => $list,
+        ]);
     }
     /**
      * @Descripttion: 获取日志详情
@@ -419,8 +450,6 @@ class HydEquipment extends CatchController
             $data = Db::name('publish_ack')->where('id', $id)->value('Extra');
             $data = optimize_json($data);
         }
-
-
         return CatchResponse::success($data);
     }
 }

+ 4 - 1
catch/hydraulic/route.php

@@ -5,7 +5,7 @@
  * @Author: likang
  * @Date: 2022-05-27 13:34:31
  * @LastEditors: likang
- * @LastEditTime: 2022-08-03 10:56:38
+ * @LastEditTime: 2022-08-04 20:14:27
  */
 // +----------------------------------------------------------------------
 // | CatchAdmin [Just Like ~ ]
@@ -36,6 +36,9 @@ $router->group(function () use ($router) {
 	$router->resource('hydEquipment', '\catchAdmin\hydraulic\controller\HydEquipment');
 	//导入设备列表
 	$router->post('importHydExcel', '\catchAdmin\hydraulic\controller\HydEquipment@importExcel');
+	//导出设备列表exportHydExcel
+	$router->get('exportHydExcel', '\catchAdmin\hydraulic\controller\HydEquipment@exportHydExcel');
+
 	//查看上传日志列表SelectLogByImei
 	$router->get('selectLogByImei', '\catchAdmin\hydraulic\controller\HydEquipment@SelectLogByImei');
 	//查看日志详情

+ 123 - 0
catch/hydraulic/server/ExcelServer.php

@@ -0,0 +1,123 @@
+<?php
+/*
+ * @Descripttion: 
+ * @version: 1.0.0
+ * @Author: likang
+ * @Date: 2022-08-05 10:48:47
+ * @LastEditors: likang
+ * @LastEditTime: 2022-08-08 16:17:18
+ */
+
+namespace catchAdmin\hydraulic\server;
+
+use catcher\base\CatchRequest;
+use catcher\CatchResponse;
+use catcher\library\excel\ExcelContract;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+use think\facade\Db;
+
+class ExcelServer implements ExcelContract
+{
+
+
+    //私有对象
+    private function __construct()
+    {
+    }
+
+    public static function getInterface()
+    {
+
+        return new ExcelServer();
+    }
+
+    /**
+     * @Descripttion: 
+     * @name: likang
+     * @param {CatchRequest} $request
+     * @param {*} $map [[key=>'e','value'=>'属性']]
+     * @param  $model 数据库模型
+     * @return {*}
+     */
+    function importExcel(CatchRequest $request, $map, $func, $install)
+    {
+        $url = $request->post('url');
+        if (!$url) {
+            return CatchResponse::fail('请上传文件');
+        }
+
+        $creator_id = $request->post('creator_id');
+        //解析地址
+        $parse_url = parse_url($url)['path'];
+        //载入excel表格 
+        $objPHPExcel = IOFactory::load(public_path() . $parse_url);
+        $sheetCount = $objPHPExcel->getSheetCount();
+        $fail = 0; //失败条数
+        $success = 0; //成功条数
+        $total = 0; //总导入数
+        $excel_data = [];
+        //循环读取每一张表
+        for ($index = 0; $index < $sheetCount; $index++) {
+            //设置当前要读取的表
+            $sheet = $objPHPExcel->getSheet($index);   //excel中的第一张sheet
+            // var_dump($sheet);exit;
+            $highestRow  = $sheet->getHighestRow();       // 取得总行数
+            // var_dump($highestRow);
+            if ($highestRow <= 2) {
+                continue;
+            }
+            $total += $highestRow - 3;
+            for ($j = 4; $j <= $highestRow - 1; $j++) {
+
+                $data = array(); //每条门店信息
+
+                foreach ($map as $item) {
+
+                    $data[$item['value']] = trim($sheet->getCell($item['key'] . $j)->getFormattedValue());
+                }
+                $data = $func($data);
+                //校验数据是否重复
+                if (!$data) {
+                    continue;
+                }
+                array_push($excel_data, $data);
+            }
+        }
+
+        // var_dump($excel_data);
+        // return CatchResponse::success();
+        //防止Excel有重复,去重
+        array_unique($excel_data, SORT_REGULAR);
+        $count = 0;
+        Db::startTrans();
+        try {
+            foreach ($excel_data as $item) {
+                $install($item);
+                $count++;
+            }
+        } catch (\Exception $e) {
+            Db::rollback();
+            return CatchResponse::success(['error' => true, 'msg' => $e->getMessage()]);
+        }
+        //提交事务
+        Db::commit();
+        return CatchResponse::success('共' . $total . '条数据,成功' . $count . '条,失败' . $fail . '条');
+    }
+
+
+    //导出
+    public function sheets()
+    {
+        // TODO: Implement sheets() method.
+        return Db::name('user')->field(['username', 'email'])->limit(100)->cursor();
+    }
+    //设置头部
+    public function headers(): array
+    {
+        // TODO: Implement headers() method.
+        return [
+            '物料号', '液压工具', '设备类别', '工具名称', '设备型号(智能)', '发放单位', '固定资产编号', '类固资产编号', '序列号', '出厂编号', '上次检验日期', '下次检验日期', '状态
+(已校验、待校验、已报废)', '状态'
+        ];
+    }
+}

+ 12 - 1
catch/wind/controller/Fan.php

@@ -6,8 +6,10 @@ use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
 use catchAdmin\wind\model\Fan as fanModel;
+use catchAdmin\worklocation\model\Workplan;
 use catcher\base\CatchRequest;
 use think\facade\Db;
+use Workerman\Worker;
 
 class Fan extends CatchController
 {
@@ -130,12 +132,21 @@ class Fan extends CatchController
      */
     public function delete($id): \think\Response
     {
-        if (is_array($id)) {
 
+
+        if (!is_array($id)) {
+            $count = Workplan::where('fan_id', $id)->count();
+            if ($count > 0) {
+                return CatchResponse::fail('存在工作计划,无法删除');
+            }
             $data = $this->fanModel->findBy($id);
             $this->fanModel->deleteBy($id, true);
             $this->fanModel->IssuedFanModel($data['wind_id']);
         } else {
+            $count = Workplan::where('fan_id', 'in', $id)->count();
+            if ($count > 0) {
+                return CatchResponse::fail('存在工作计划,无法删除');
+            }
             $where[] = ['id', 'in', $id];
             $list =  $this->fanModel->where($where)->group('wind_id')->column('wind_id');
             $this->fanModel->deleteBy($id, true);

+ 21 - 1
catch/wind/controller/Wind.php

@@ -2,10 +2,13 @@
 
 namespace catchAdmin\wind\controller;
 
+use catchAdmin\wind\model\Fan;
 use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
 use catchAdmin\wind\model\Wind as windModel;
+use catchAdmin\worklocation\model\Workplan;
+use catcher\Utils;
 
 class Wind extends CatchController
 {
@@ -71,6 +74,9 @@ class Wind extends CatchController
         if ($this->windModel->where('name', $post['name'])->count()) {
             return CatchResponse::fail('风场名称已存在');
         }
+        if ($this->windModel->where('number', $post['number'])->count()) {
+            return CatchResponse::fail('风场编号已存在');
+        }
         $post['wind_info'] = json_encode($post['wind_info']);
         $post['department_id'] = array_pop($post['department_id']);
 
@@ -104,11 +110,17 @@ class Wind extends CatchController
                 return CatchResponse::fail('风场名称已存在');
             }
         }
+        if (isset($post['number'])) {
+            // 检测名称重复
+            $n_id = $this->windModel->where('number', $post['number'])->value('id');
+            if ($n_id && ($n_id != $id)) {
+                return CatchResponse::fail('风场编号已存在');
+            }
+        }
         if (isset($post['department_id']) && is_array($post['department_id'])) {
             $post['department_id'] = array_pop($post['department_id']);
         }
         $post['wind_info'] = json_encode($post['wind_info']);
-
         return CatchResponse::success($this->windModel->updateBy($id, $post));
     }
 
@@ -119,6 +131,14 @@ class Wind extends CatchController
      */
     public function delete($id): \think\Response
     {
+        $count =  Fan::where('wind_id', $id)->count();
+        if ($count > 0) {
+            return CatchResponse::fail('存在所属风场的风机');
+        }
+        $plan_count = Workplan::where('wind_id', $id)->count();
+        if ($plan_count > 0) {
+            return CatchResponse::fail('存在所属风场的工作计划');
+        }
         return CatchResponse::success($this->windModel->deleteBy($id, true));
     }
     /**