Advertisement
eqeqwan21

ods_api.php

Jun 18th, 2025
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. private function get_states() {
  2.     $whr = [];
  3.     $arg=[];
  4.     $mapfilter = $this->mapfilter("d");
  5.     $lines = '';
  6.    
  7.     foreach(['Town_id','Location','District','Type','Sip','Ip','Smart','Devices_id','Name', 'Station', 'DimProfile_id'] as $gv) {
  8.         if(isset($_GET[$gv])) {
  9.             $alias = '';
  10.             if($gv=='Devices_id')
  11.                 $alias = 'StatusReg.';
  12.             if($gv=='DimProfile_id' || $gv=='Type')
  13.                 $alias = 'd.';
  14.             $whr[] = "($alias`$gv`=?)";
  15.             $arg[] = $_GET[$gv];
  16.         }
  17.     }
  18.  
  19.     if(isset($_GET['Mode'])) {
  20.         $whr[] = "(StatusReg.`Mode`in (?))";
  21.         $arg[] = $_GET['Mode'];
  22.     }
  23.  
  24.     if(isset($_GET['box'])) {
  25.         $whr[] = "(`Lines`.Devices_id =?)";
  26.         $arg[] = $_GET['box'];
  27.         $lines = 'left join `Lines` on `Lines`.id = d.Lines_id';
  28.     }
  29.  
  30.     if(isset($_GET['Trouble'])) {
  31.         $whr[] = '(`Trouble`' . ($_GET['Trouble']>0?'>':'=') . '0)';
  32.     }
  33.  
  34.     if(isset($_GET['State'])) {
  35.         $whr[] = '(`State`' . ($_GET['State']>0?'>':'=') . '0)';
  36.     }
  37.    
  38.     if(isset($_GET['Power'])) {
  39.         $whr[] = '('.($_GET['Power']>0?'`Power`>=7 or (d.`Type`=2 and `Power`>0)':'`Power`=0 or (d.`Type`=1 and `Power`<7)').')';
  40.     }
  41.  
  42.  
  43.     if(isset($_GET['mapfilter']))
  44.         $whr[]=$mapfilter;
  45.    
  46.     $where = join($whr, " AND ");
  47.    
  48.     if(count($arg)==0)
  49.         $arg=null;
  50.    
  51.     if($where !== "")
  52.         $where = 'AND '.$where;
  53.    
  54.     $order = '';
  55.     if(isset($_GET['order'])) {
  56.         $order = "order by d.`type`, LPAD(d.CustomNum,10,'0')";
  57.     }
  58. //V11_Phase
  59. //Anton_30day  
  60. //  StatusReg.Timestamp >= date_sub(now(), INTERVAL 30 DAY)
  61. //  AND
  62.  
  63. //V11_Phase_30 day_++Anton
  64.     $sql =
  65.     "
  66.     SELECT d.id, d.Name, d.CustomNum, d.Location, d.District, d.Type, d.lat, d.lng, d.Smart, d.sn,
  67.     StatusReg.id as StatusReg_id, Power, Trouble, Sip, Ip, StatusReg.Mode, State, Timeallert, Controller, Door, Ous, Voltage,
  68.         json_extract(StatusReg.Phase,\"$.v\") as PhaseV,
  69.         StatusReg.Timestamp, StatusReg.Devices_id, IncomingLog_id, StatusReg.DimProfile_id, OutgoingLog_id,
  70.         UNIX_TIMESTAMP(StatusReg.Timestamp) as unixtime,
  71.          (
  72.          SELECT COUNT(DISTINCT `Switch`)
  73.          FROM `Lines`
  74.          WHERE `Devices_id` = d.id
  75.            AND `Switch` > 0
  76.        ) AS num_contactors
  77.     from StatusReg
  78.     inner join Devices as d on Devices_id=d.id
  79.     $lines
  80.     inner join (select max(id) as id from StatusReg group by Devices_id) as ssr on ssr.id = StatusReg.id
  81.     where
  82.     (d.OffTime >= curdate() OR isnull(d.OffTime)) and not isnull(d.OnTime)
  83.     $where
  84.     $order
  85.     ";
  86.  
  87.     //echo $sql;
  88.     $this->run_query($sql, $arg, ['Devices', 'IncomingLog', 'OutgoingLog', 'StatusReg'],false,'id');
  89.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement