<?php

namespace Home\Controller;

use Think\Controller;


class DistributingController extends Controller
{

    //配电图基础信息查询
    public function getBasicLabel()
    {
        header("Access-Control-Allow-Origin:*");
        header('Access-Control-Allow-Methods:POST');
        header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
        $Data = I('');
        if (empty($Data['site_id'])){
            echo "站点ID错误";
            exit();
        }
        $res = M()->query("SELECT a.*,b.variable_coding FROM hookup_component_complete as a join device_analog_variable_list as b on a.variable_id=b.id where a.site_id=" . $Data['site_id']);
        $res2 = M()->query("SELECT b.id,b.variable_coding,c.device_code,c.device_type,b.data_area FROM hookup_component_complete AS a
                            JOIN device_analog_variable_list AS b ON a.variable_id = b.id
                            JOIN device AS c ON b.communication_equipment = c.id  where a.site_id =". $Data['site_id']." group by b.variable_coding");
        $variable_173_analog = "";
        $variable_171_analog = "";
        $variable_183_analog = "";
        $variable_158_analog = "";
        $variable_176_analog = "";
        $variable_173_switch = "";
        $variable_171_switch = "";
        $variable_183_switch = "";
        $variable_176_switch = "";
        foreach ($res2 as $key=>$value ){
            if ($res2[$key]['data_area']==2){
                if ($res2[$key]['device_type']==3){
                    $variable_171_switch[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==4){
                    $variable_173_switch[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==7){
                    $variable_176_switch[] = $res2[$key]['id'];
                }else{
                    $variable_183_switch[] = $res2[$key]['id'];
                }
            }else{
                if ($res2[$key]['device_type']==3){
                    $variable_171_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==4){
                    $variable_173_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==5){
                    $variable_158_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==7){
                    $variable_176_analog[] = $res2[$key]['id'];
                }else{
                    $variable_183_analog[] = $res2[$key]['id'];
                }
            }
        }
//        print_r($variable_183_analog);

        if (!empty($variable_173_analog)){
            $variable_173_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_173_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(". implode(",",$variable_173_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_171_analog)){
            $variable_171_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_171_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_171_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_183_analog)){
            $variable_183_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_183_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_158_analog)){
            $variable_158_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_158_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_158_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_176_analog)){
            $variable_176_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_176_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_176_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_173_switch)){
            $variable_173_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_173_data     as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_173_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_171_switch)){
            $variable_171_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_171_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_171_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_183_switch)){
            $variable_183_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_183_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_176_switch)){
            $variable_176_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_176_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_176_switch).") GROUP BY a.variable_coding");
        }

        $array1 = array();
        $a = count($array1);
        if (!empty($variable_173_analog_data)){
            foreach ($variable_173_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_173_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_173_analog_data[$key][explode('_', $variable_173_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_171_analog_data)){
            foreach ($variable_171_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_171_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_171_analog_data[$key][explode('_', $variable_171_analog_data[$key]['variable_coding'])[1]];
            }
        }
//        print_r($variable_183_analog_data);
        $a = count($array1);
        if (!empty($variable_183_analog_data)){
            foreach ($variable_183_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_183_analog_data[$key]['variable_coding'];
//                print_r("测试".$variable_183_analog_data[$key][explode('_', $variable_183_analog_data[$key]['variable_coding'])[1]]);
                $array1[$a]['variable_value'] = $variable_183_analog_data[$key][explode('_', $variable_183_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_158_analog_data)){
            foreach ($variable_158_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_158_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_158_analog_data[$key][explode('_', $variable_158_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_176_analog_data)){
            foreach ($variable_176_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_176_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_176_analog_data[$key][explode('_', $variable_176_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_173_switch_data)){
            foreach ($variable_173_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_173_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_173_switch_data[$key][explode('_', $variable_173_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_171_switch_data)){
            foreach ($variable_171_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_171_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_171_switch_data[$key][explode('_', $variable_171_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_183_switch_data)){
            foreach ($variable_183_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_183_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_183_switch_data[$key][explode('_', $variable_183_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_176_switch_data)){
            foreach ($variable_176_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_176_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_176_switch_data[$key][explode('_', $variable_176_switch_data[$key]['variable_coding'])[1]];
            }
        }

//        print_r($array1);
//        print_r($res);
        if (!empty($res)) {
            $array = array();
            foreach ($res as $key => $value) {
                $array[$key]['id'] = $res[$key]['id'];
                $array[$key]['title'] = $res[$key]['title'];
                $array[$key]['type'] = $res[$key]['innerType'];
                $array[$key]['typeName'] = $res[$key]['typeName'];
                $array[$key]['svgColor'] = $res[$key]['svgColor'];
                $array[$key]['createType'] = $res[$key]['createType'];
                $array[$key]['svgPositionX'] = (int)$res[$key]['svgPositionX'];
                $array[$key]['svgPositionY'] = (int)$res[$key]['svgPositionY'];
                if (!empty($res[$key]['mPoint'])){
                    $array[$key]['mPoint'] = json_decode($res[$key]['mPoint'], true);
                }else{
                    $array[$key]['mPoint'] = "";
                }
                if (!empty($res[$key]['echartsOption'])){
                    $array[$key]['echartsOption'] = json_decode($res[$key]['echartsOption'], true);
                }else{
                    $array[$key]['echartsOption'] = "";
                }
                $array[$key]['size'] = (int)$res[$key]['size'];
                $array[$key]['angle'] = (int)$res[$key]['angle'];
                $array[$key]['elementBool'] = explode(',', $res[$key]['elementBool']);
                $array[$key]['svgLineSelectval'] = $res[$key]['svgLineSelectval'];
                $array[$key]['siteId'] = (int)$res[$key]['site_id'];
                $array[$key]['deviceId'] = (int)$res[$key]['device_id'];
                $array[$key]['variableId'] = (int)$res[$key]['variable_id'];
                if (!empty($array1)){
                    foreach ($array1 as $key1=>$value1){
//                        print_r("variable_coding1=" . $res[$key]['variable_coding'] . "---variable_coding2=" . $array1[$key1]['variable_coding']);
                        if ($res[$key]['variable_coding']==$array1[$key1]['variable_coding']){
//                            print_r("++++++++++++".$array1[$key1]['variable_value']."++++++");
                            $array[$key]['variableValue'] = $array1[$key1]['variable_value'];
                        }
                    }
                    if (empty($array[$key]['variableValue'])&&$array[$key]['variable_value']!=0){
                        $array[$key]['variableValue'] = "";
                    }
                }else{
                    $array[$key]['variableValue'] = "";
                }
            }
            echo json_encode($array);
        } else {
            echo '';
        }
    }

    public function getBasicLabel1()
    {
        header("Access-Control-Allow-Origin:*");
        header('Access-Control-Allow-Methods:POST');
        header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
        $Data = I('');
        if (empty($Data['site_id'])){
            echo "站点ID错误";
            exit();
        }
        $res = M()->query("SELECT a.*,b.variable_coding FROM hookup_component_complete as a join device_analog_variable_list as b on a.variable_id=b.id where a.site_id=" . $Data['site_id']);
        $res2 = M()->query("SELECT b.id,b.variable_coding,c.device_code,c.device_type,b.data_area FROM hookup_component_complete AS a
                            JOIN device_analog_variable_list AS b ON a.variable_id = b.id
                            JOIN device AS c ON b.communication_equipment = c.id  where a.site_id =". $Data['site_id']." group by b.variable_coding");
        $variable_173_analog = "";
        $variable_171_analog = "";
        $variable_183_analog = "";
        $variable_158_analog = "";
        $variable_176_analog = "";
        $variable_173_switch = "";
        $variable_171_switch = "";
        $variable_183_switch = "";
        $variable_176_switch = "";
        foreach ($res2 as $key=>$value ){
            if ($res2[$key]['data_area']==2){
                if ($res2[$key]['device_type']==3){
                    $variable_171_switch[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==4){
                    $variable_173_switch[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==7){
                    $variable_176_switch[] = $res2[$key]['id'];
                }else{
                    $variable_183_switch[] = $res2[$key]['id'];
                }
            }else{
                if ($res2[$key]['device_type']==3){
                    $variable_171_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==4){
                    $variable_173_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==5){
                    $variable_158_analog[] = $res2[$key]['id'];
                }else if ($res2[$key]['device_type']==7){
                    $variable_176_analog[] = $res2[$key]['id'];
                }else{
                    $variable_183_analog[] = $res2[$key]['id'];
                }
            }
        }
//        print_r($variable_183_analog);
//        exit();


        if (!empty($variable_173_analog)){
            $variable_173_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_173_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(". implode(",",$variable_173_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_171_analog)){
            $variable_171_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_171_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_171_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_183_analog)){
            $variable_183_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_183_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_158_analog)){
            $variable_158_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_158_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_158_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_176_analog)){
            $variable_176_analog_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_analog_176_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_176_analog).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_173_switch)){
            $variable_173_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_173_data     as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_173_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_171_switch)){
            $variable_171_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_171_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_171_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_183_switch)){
            $variable_183_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_183_switch).") GROUP BY a.variable_coding");
        }
        if (!empty($variable_176_switch)){
            $variable_176_switch_data = M()->query("SELECT a.id as idd,a.variable_coding,c.* FROM device_analog_variable_list as a 
                                join device as b ON a.communication_equipment=b.id 
                                LEFT JOIN rt_switch_176_data as c ON a.device_code = c.deviceName
                                WHERE a.id in(".implode(",",$variable_176_switch).") GROUP BY a.variable_coding");
        }

        $array1 = array();
        $a = count($array1);
        if (!empty($variable_173_analog_data)){
            foreach ($variable_173_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_173_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_173_analog_data[$key][explode('_', $variable_173_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_171_analog_data)){
            foreach ($variable_171_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_171_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_171_analog_data[$key][explode('_', $variable_171_analog_data[$key]['variable_coding'])[1]];
            }
        }
//        print_r($variable_183_analog_data);
//        exit();
        $a = count($array1);
        if (!empty($variable_183_analog_data)){
            foreach ($variable_183_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_183_analog_data[$key]['variable_coding'];
//                print_r("测试".$variable_183_analog_data[$key][explode('_', $variable_183_analog_data[$key]['variable_coding'])[1]]);
                $array1[$a]['variable_value'] = $variable_183_analog_data[$key][explode('_', $variable_183_analog_data[$key]['variable_coding'])[1]];
            }
        }
//
//        exit();
        $a = count($array1);
        if (!empty($variable_158_analog_data)){
            foreach ($variable_158_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_158_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_158_analog_data[$key][explode('_', $variable_158_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_176_analog_data)){
            foreach ($variable_176_analog_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_176_analog_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_176_analog_data[$key][explode('_', $variable_176_analog_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_173_switch_data)){
            foreach ($variable_173_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_173_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_173_switch_data[$key][explode('_', $variable_173_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_171_switch_data)){
            foreach ($variable_171_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_171_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_171_switch_data[$key][explode('_', $variable_171_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_183_switch_data)){
            foreach ($variable_183_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_183_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_183_switch_data[$key][explode('_', $variable_183_switch_data[$key]['variable_coding'])[1]];
            }
        }
        $a = count($array1);
        if (!empty($variable_176_switch_data)){
            foreach ($variable_176_switch_data as $key=>$value){
                $a = $a+1;
                $array1[$a]['variable_coding'] = $variable_176_switch_data[$key]['variable_coding'];
                $array1[$a]['variable_value'] = $variable_176_switch_data[$key][explode('_', $variable_176_switch_data[$key]['variable_coding'])[1]];
            }
        }

        print_r($array1);
        print_r($res);
        exit();
        if (!empty($res)) {
            $array = array();
            foreach ($res as $key => $value) {
                $array[$key]['id'] = $res[$key]['id'];
                $array[$key]['title'] = $res[$key]['title'];
                $array[$key]['type'] = $res[$key]['innerType'];
                $array[$key]['typeName'] = $res[$key]['typeName'];
                $array[$key]['svgColor'] = $res[$key]['svgColor'];
                $array[$key]['createType'] = $res[$key]['createType'];
                $array[$key]['svgPositionX'] = (int)$res[$key]['svgPositionX'];
                $array[$key]['svgPositionY'] = (int)$res[$key]['svgPositionY'];
                if (!empty($res[$key]['mPoint'])){
                    $array[$key]['mPoint'] = json_decode($res[$key]['mPoint'], true);
                }else{
                    $array[$key]['mPoint'] = "";
                }
                if (!empty($res[$key]['echartsOption'])){
                    $array[$key]['echartsOption'] = json_decode($res[$key]['echartsOption'], true);
                }else{
                    $array[$key]['echartsOption'] = "";
                }
                $array[$key]['size'] = (int)$res[$key]['size'];
                $array[$key]['angle'] = (int)$res[$key]['angle'];
                $array[$key]['elementBool'] = explode(',', $res[$key]['elementBool']);
                $array[$key]['svgLineSelectval'] = $res[$key]['svgLineSelectval'];
                $array[$key]['siteId'] = (int)$res[$key]['site_id'];
                $array[$key]['deviceId'] = (int)$res[$key]['device_id'];
                $array[$key]['variableId'] = (int)$res[$key]['variable_id'];
                if (!empty($array1)){
                    foreach ($array1 as $key1=>$value1){
//                        print_r("variable_coding1=" . $res[$key]['variable_coding'] . "---variable_coding2=" . $array1[$key1]['variable_coding']);
                        if ($res[$key]['variable_coding']==$array1[$key1]['variable_coding']){
//                            print_r("++++++++++++".$array1[$key1]['variable_value']."++++++");
                            $array[$key]['variableValue'] = $array1[$key1]['variable_value'];
                        }
                    }
                    if (empty($array[$key]['variableValue'])&&$array[$key]['variable_value']!=0){
                        $array[$key]['variableValue'] = "";
                    }
                }else{
                    $array[$key]['variableValue'] = "";
                }
            }
            echo json_encode($array);
        } else {
            echo '';
        }
    }


    public function getSeatDistributing(){
        header("Access-Control-Allow-Origin:*");
        header('Access-Control-Allow-Methods:POST');
        header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
        $res = M()->query("select * from hookup");
        $array = array();
        if (!empty($res)){
            foreach ($res as $key=>$value){
                $array[$key]['type'] = $res[$key]['outerType'];
                $array[$key]['title'] = $res[$key]['title'];
                $array[$key]['template'] = $res[$key]['template'];
                if (!empty($res[$key]['props'])){
                    $array[$key]['props'] = explode(',', $res[$key]['props']);
                }else{
                    $array[$key]['props'] ="";
                }

                $array[$key]['defaultColor'] = $res[$key]['default_color'];
                $array[$key]['dataType'] = $res[$key]['dataType'];
                $array[$key]['createType'] = $res[$key]['createType'];
                $array[$key]['priviewImg'] = $res[$key]['priview_img'];
                $array[$key]['echartsOption'] = $res[$key]['echartsOption'];
                $array[$key]['elementBool'] = explode(',', $res[$key]['elementBool']);
                $array[$key]['svgLineSelectval'] = $res[$key]['svgLineSelectval'];
            }
        }
        echo json_encode($array);
    }

    //配电图数据插入
    public function geta()
    {
        $json = '';
        $data = json_decode($json, true);
        foreach ($data as $key => $value) {
            $cs = array();
            $cs['id'] = $data[$key]['id'];
            $cs['sort'] = $data[$key]['sort'];
            $cs['title'] = $data[$key]['title'];
            $cs['innerType'] = $data[$key]['type'];
            $cs['typeName'] = $data[$key]['typeName'];
            $cs['svgColor'] = $data[$key]['svgColor'];
            $cs['svgPositionX'] = $data[$key]['svgPositionX'];
            $cs['svgPositionY'] = $data[$key]['svgPositionY'];
            $cs['size'] = $data[$key]['size'];
            $cs['height'] = $data[$key]['height'];
            $cs['width'] = $data[$key]['width'];
            $cs['fontSize'] = $data[$key]['fontSize'];
            $cs['svgText'] = $data[$key]['svgText'];
            $cs['angle'] = $data[$key]['angle'];
            $cs['tableRowCount'] = $data[$key]['tableRowCount'];
            $cs['tableColCount'] = $data[$key]['tableColCount'];
            $cs['tableData'] = $data[$key]['tableData'];
            $cs['elementBool'] = implode(",", $data[$key]['elementBool']);
            $cs['site_id'] = 1;
            $cs['device_id'] = 316;
            $cs['variable_id'] = 26553;
            $cs['creator'] = 'admin';
            $cs['create_time'] = date("Y-m-d H:i:s");

            $res = M('hookup_component_complete')->add($cs);
//            sleep(1);
            if ($res){

            }else{
                print_r($cs['id']."-----");
            }

        }
    }

//    public function transformation1(fieldValue){
//        switch (fieldValue) {
//            case "Busot":
//                return Busot;
//            case "COS":
//                return COS;
//            case "COSa":
//                return COSa;
//            case "COSb":
//                return COSb;
//            case "COSc":
//                return COSc;
//            case "Demand":
//                return Demand;
//            case "DevResetTimes":
//                return contextualDataVo.getDevResetTimes();
//            case "DeviceTemp":
//                return contextualDataVo.getDeviceTemp();
//            case "Epn":
//                return contextualDataVo.getEpn();
//            case "Epn1":
//                return contextualDataVo.getEpn1();
//            case "Epn2":
//                return contextualDataVo.getEpn2();
//            case "Epn3":
//                return contextualDataVo.getEpn3();
//            case "Epn4":
//                return contextualDataVo.getEpn4();
//            case "Epp":
//                return contextualDataVo.getEpp();
//            case "Epp1":
//                return contextualDataVo.getEpp1();
//            case "Epp2":
//                return contextualDataVo.getEpp2();
//            case "Epp3":
//                return contextualDataVo.getEpp3();
//            case "Epp4":
//                return contextualDataVo.getEpp4();
//            case "Eqn":
//                return contextualDataVo.getEqn();
//            case "Eqp":
//                return contextualDataVo.getEqp();
//            case "F":
//                return contextualDataVo.getF();
//            case "I0":
//                return contextualDataVo.getI0();
//            case "I2":
//                return contextualDataVo.getI2();
//            case "IHa":
//                return contextualDataVo.getIHa();
//            case "IHb":
//                return contextualDataVo.getIHb();
//            case "IHc":
//                return contextualDataVo.getIHc();
//            case "Ia":
//                return contextualDataVo.getIa();
//            case "Ib":
//                return contextualDataVo.getIb();
//            case "Ic":
//                return contextualDataVo.getIc();
//            case "Ir":
//                return contextualDataVo.getIr();
//            case "LastDayMD":
//                return contextualDataVo.getLastDayMD();
//            case "LastDayMDt":
//                return contextualDataVo.getLastDayMDt();
//            case "P":
//                return contextualDataVo.getP();
//            case "Pa":
//                return contextualDataVo.getPa();
//            case "Pb":
//                return contextualDataVo.getPb();
//            case "Pc":
//                return contextualDataVo.getPc();
//            case "Q":
//                return contextualDataVo.getQ();
//            case "Qa":
//                return contextualDataVo.getQa();
//            case "Qb":
//                return contextualDataVo.getQb();
//            case "Qc":
//                return contextualDataVo.getQc();
//            case "SignalIntensity":
//                return contextualDataVo.getSignalIntensity();
//            case "T1":
//                return contextualDataVo.getT1();
//            case "T2":
//                return contextualDataVo.getT2();
//            case "T3":
//                return contextualDataVo.getT3();
//            case "T4":
//                return contextualDataVo.getT4();
//            case "THDUa":
//                return contextualDataVo.getTHDUa();
//            case "THDUb":
//                return contextualDataVo.getTHDUb();
//            case "THDUc":
//                return contextualDataVo.getTHDUc();
//            case "Ua":
//                return contextualDataVo.getUa();
//            case "Uab":
//                return contextualDataVo.getUab();
//            case "Ub":
//                return contextualDataVo.getUb();
//            case "Ubc":
//                return contextualDataVo.getUbc();
//            case "UblU0":
//                return contextualDataVo.getUblU0();
//            case "UblU2":
//                return contextualDataVo.getUblU2();
//            case "Uc":
//                return contextualDataVo.getUc();
//            case "Uca":
//                return contextualDataVo.getUca();
//            case "Udt":
//                return contextualDataVo.getUdt();
//            case "Ul":
//                return contextualDataVo.getUl();
//            case "Upt":
//                return contextualDataVo.getUpt();
//            case "Ust":
//                return contextualDataVo.getUst();
//            case "voltageA":
//                return contextualDataVo.getVoltageA();
//            case "voltageB":
//                return contextualDataVo.getVoltageB();
//            case "voltageC":
//                return contextualDataVo.getVoltageC();
//            case "voltageAB":
//                return contextualDataVo.getVoltageAB();
//            case "voltageBC":
//                return contextualDataVo.getVoltageBC();
//            case "voltageCA":
//                return contextualDataVo.getVoltageCA();
//            case "frequency":
//                return contextualDataVo.getFrequency();
//            case "analog1":
//                return contextualDataVo.getAnalog1();
//            case "analog2":
//                return contextualDataVo.getAnalog2();
//            case "analog3":
//                return contextualDataVo.getAnalog3();
//            case "analog4":
//                return contextualDataVo.getAnalog4();
//            case "analog5":
//                return contextualDataVo.getAnalog5();
//            case "voltageATHD":
//                return contextualDataVo.getVoltageATHD();
//            case "voltageBTHD":
//                return contextualDataVo.getVoltageATHD();
//            case "voltageCTHD":
//                return contextualDataVo.getVoltageCTHD();
//            case "voltageSagTimes":
//                return contextualDataVo.getVoltageSagTimes();
//            case "voltageSwellTimes":
//                return contextualDataVo.getVoltageSwellTimes();
//            case "voltageInterruptionTimes":
//                return contextualDataVo.getVoltageInterruptionTimes();
//            case "voltageUnbalanceFactor":
//                return contextualDataVo.getVoltageUnbalanceFactor();
//            case "analogReserved":
//                return contextualDataVo.getAnalogReserved();
//            case "freezingTime":
//                return contextualDataVo.getFreezingTime();
//            case "unbalanceCurrent":
//                return contextualDataVo.getUnbalanceCurrent();
//            case "unbalanceVoltage":
//                return contextualDataVo.getUnbalanceVoltage();
//            case "analogReserved1":
//                return contextualDataVo.getAnalogReserved1();
//            case "analogReserved2":
//                return contextualDataVo.getAnalogReserved2();
//            case "analogReserved3":
//                return contextualDataVo.getAnalogReserved3();
//            case "analogReserved4":
//                return contextualDataVo.getAnalogReserved4();
//            default:
//                return null;
//        }
//}

}

















