Project.php 7.9 KB
<?php


namespace app\api\controller\v7\screen;


use app\common\controller\Api;
use think\Db;

/**
 * 工程运行监测
 * Class Project
 * @package app\api\controller\v7\screen
 */
class Project extends Api
{
    public $noNeedLogin = ['*'];
    public $noNeedRight = ['*'];

    protected $projectStatusList = [
        1 => '待开始',
        2 => '进行中',
        3 => '完成',
    ];
    protected $warningStatusList = [
        1 => '待处理',
        2 => '处理中',
        3 => '处理完成',
    ];
    protected $warningTypesList = [
        1 => '管道腐蚀',
        2 => '管道裂口',
        3 => '管道变形',
    ];
    public function _initialize()
    {
        parent::_initialize();

    }
    //工程运行事项任务
    public function mission(){
        $list = Db::name('pipes_project')->select();
        foreach ($list as &$item){
            $item['createtime'] = date('Y-m-d', $item['createtime']);
            $item['status_text'] = $this->projectStatusList[$item['status']];
        }
        $this->success('成功', $list);
    }

    //实时管道监测
    public function monitor(){
        $result = [
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ],
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ],
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ],
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ],
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ],
            [
                'images' => full_image_kevin('/uploads/20231224/FoN06J19nMnSf0KXoPQYMLkK8MbH.jpg'),
            ]
        ];
        $this->success('成功', $result);
    }

    //输水管道监测
    public function trans(){
        $list = Db::name('pipes_transmission')->select();
        $status1 = 0;
        $status2 = 0;
        $status3 = 0;
        $status4 = 0;

        $types1 = 0;
        $types2 = 0;
        $types3 = 0;
        foreach ($list as $item){
            switch (intval($item['status'])){
                case 1:
                    $status1++;
                    break;
                case 2:
                    $status2++;
                    break;
                case 3:
                    $status3++;
                    break;
                case 4:
                    $status4++;
                    break;
            }
            switch (intval($item['types'])){
                case 1:
                    $types1++;
                    break;
                case 2:
                    $types2++;
                    break;
                case 3:
                    $types3++;
                    break;
            }
        }
        $result = [
            'total' => count($list),
            'status_1' => $status1,
            'status_2' => $status2,
            'status_3' => $status3,
            'status_4' => $status4,
            'types_1' => $types1,
            'types_2' => $types2,
            'types_3' => $types3,
        ];
        $this->success('成功', $result);
    }

    //坝体安全监测
    public function dam(){
        $list = Db::name('pipes_dam')->select();
        $result = [
            [
                'title' => '设备一',
                'displacement_x' => '0.2',
                'displacement_y' => '0.2',
                'displacement_z' => '0.2',
                'status' => 1,
                'status_text' => '正常',
                'normal_num' => 10,
                'total_num' => 10,
            ],
            [
                'title' => '设备二',
                'displacement_x' => '0.2',
                'displacement_y' => '0.2',
                'displacement_z' => '0.2',
                'status' => 2,
                'status_text' => '预警',
                'normal_num' => 5,
                'total_num' => 10,
            ],
            [
                'title' => '设备三',
                'displacement_x' => '0.2',
                'displacement_y' => '0.2',
                'displacement_z' => '0.2',
                'status' => 2,
                'status_text' => '预警',
                'normal_num' => 7,
                'total_num' => 10,
            ],
        ];
        $result = [
            'month' => $result,
            'quarter' => $result,
            'year' => $result,
        ];
        $this->success('成功', $result);
    }

    protected $pressureTypesList = [
        1 => '压力异常',
        2 => '压力突变',
    ];
    //管网漏损报警
    public function warning(){
        $list = Db::name('pipes_warning')->select();
        foreach ($list as &$item){
            $item['createtime'] = date('Y-m-d H:i', $item['createtime']);
            $item['dealtime'] = date('Y-m-d H:i', $item['dealtime']);
            $item['status_text'] = $this->warningStatusList[$item['status']];
            $item['types_text'] = $this->warningTypesList[$item['types']];
            $item['staff_info'] = Db::name('inspection_staff')->field('staff_name,mobile')->where('id',$item['staff_id'])->find();
            $item['pressure_type_text'] = $this->pressureTypesList[$item['pressure_type']];
        }
        $result = [
            'seven_statics' => [
                'today' => [
                    'x' => [
                        date('H:i', strtotime("-6 hour")),
                        date('H:i', strtotime("-5 hour")),
                        date('H:i', strtotime("-4 hour")),
                        date('H:i', strtotime("-3 hour")),
                        date('H:i', strtotime("-2 hour")),
                        date('H:i', strtotime("-1 hour")),
                        date('H:i'),
                    ],
                    'y' =>[
                        3,
                        4,
                        6,
                        5,
                        4,
                        3,
                        2,
                    ]
                ],
                'seven' => [
                    'x' => [
                        date('m-d', strtotime("-6 day")),
                        date('m-d', strtotime("-5 day")),
                        date('m-d', strtotime("-4 day")),
                        date('m-d', strtotime("-3 day")),
                        date('m-d', strtotime("-2 day")),
                        date('m-d', strtotime("-1 day")),
                        date('m-d'),
                    ],
                    'y' =>[
                        3,
                        4,
                        6,
                        5,
                        4,
                        3,
                        2,
                    ]
                ]
            ],
            'today' => $list,
            'seven' => $list,
        ];
        $this->success('成功', $result);
    }

    //管网漏损报警详情
    public function warningDetail(){
        $id = $this->request->param('id');
        if (empty($id)){
            $this->error('id必须');
        }
        $list = Db::name('pipes_warning')->where('id', $id)->find();
        if (!$list){
            $this->error('数据不存在');
        }
        $list['createtime'] = date('Y-m-d H:i', $list['createtime']);
        $list['dealtime'] = date('Y-m-d H:i', $list['dealtime']);
        $list['status_text'] = $this->warningStatusList[$list['status']];
        $list['types_text'] = $this->warningTypesList[$list['types']];
        $list['staff_info'] = Db::name('inspection_staff')->field('staff_name,mobile')->where('id',$list['staff_id'])->find();
        $imagesArr = explode(',',trim($list['images'],','));
        foreach ($imagesArr as &$image){
            $image = full_image_kevin($image);
        }
        unset($image);
        $list['images_arr'] = $imagesArr;
        $this->success('成功', $list);
    }
}